Skip to content

Commit a83dbc9

Browse files
committed
Biojava biojava#695: Stores namespace as annotation
1 parent 0c99ed0 commit a83dbc9

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

biojava-ontology/src/main/java/org/biojava/nbio/ontology/obo/OboFileHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class OboFileHandler implements OboFileEventListener {
6565
public static final String DISJOINT_FROM = "disjoint_from";
6666
public static final String SUBSET = "subset";
6767
public static final String INTERSECTION_OF = "intersection_of";
68+
public static final String NAMESPACE = "namespace";
6869

6970

7071
public static final String ALT_ID = "alt_id";
@@ -171,6 +172,10 @@ else if (key.equals(NAME)){
171172
Annotation anno = currentTerm.getAnnotation();
172173
anno.setProperty(ALT_ID, value);
173174
}
175+
else if (key.equals(NAMESPACE)){
176+
Annotation anno = currentTerm.getAnnotation();
177+
anno.setProperty(NAMESPACE, value);
178+
}
174179

175180
else {
176181
//logger.info("unknown key {}", key);
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* BioJava development code
3+
*
4+
* This code may be freely distributed and modified under the
5+
* terms of the GNU Lesser General Public Licence. This should
6+
* be distributed with the code. If you do not have a copy,
7+
* see:
8+
*
9+
* http://www.gnu.org/copyleft/lesser.html
10+
*
11+
* Copyright for this code is held jointly by the individual
12+
* authors. These should be listed in @author doc comments.
13+
*
14+
* For more information on the BioJava project and its aims,
15+
* or to join the biojava-l mailing list, visit the home page
16+
* at:
17+
*
18+
* http://www.biojava.org/
19+
*
20+
* Created at 08 Aug 2017
21+
*/
22+
23+
package org.biojava.nbio.ontology;
24+
25+
import junit.framework.TestCase;
26+
import org.biojava.nbio.ontology.io.OboParser;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
30+
import java.io.BufferedReader;
31+
import java.io.ByteArrayInputStream;
32+
import java.io.InputStream;
33+
import java.io.InputStreamReader;
34+
import java.util.Set;
35+
36+
import static org.biojava.nbio.ontology.obo.OboFileHandler.NAMESPACE;
37+
38+
public class TestParseOBO extends TestCase {
39+
40+
private static final Logger logger = LoggerFactory.getLogger(TestParseOBO.class);
41+
42+
public void testNamespace(){
43+
44+
String testTermEntry = "\n[Term]\n" +
45+
"id: SO:0000691\n" +
46+
"name: cleaved_initiator_methionine \n" +
47+
"namespace: sequence\n" +
48+
"alt_id: BS:00067\n" +
49+
"def: \"The initiator methionine that has been cleaved from a mature polypeptide sequence.\" [EBIBS:GAR]\n" +
50+
"subset: biosapiens\n" +
51+
"synonym: \"cleaved initiator methionine\" EXACT []\n" +
52+
"synonym: \"init_met\" RELATED [uniprot:feature_type]\n" +
53+
"synonym: \"initiator methionine\" RELATED []\n" +
54+
"is_a: SO:0100011 ! cleaved_peptide_region\n\n";
55+
56+
OboParser parser = new OboParser();
57+
58+
try {
59+
60+
61+
InputStream inStream = new ByteArrayInputStream(testTermEntry.getBytes());
62+
63+
assertNotNull(inStream);
64+
65+
BufferedReader oboFile = new BufferedReader ( new InputStreamReader ( inStream ) );
66+
67+
Ontology ontology;
68+
69+
ontology = parser.parseOBO(oboFile, "so-xp/subsets/biosapiens",
70+
"snippet from biosapiens protein feature ontology");
71+
Set<Term> keys = ontology.getTerms();
72+
73+
assertTrue(keys.size() > 1);
74+
assertTrue(ontology.getTerm("SO:0000691").getAnnotation().containsProperty(NAMESPACE));
75+
assertEquals("sequence",ontology.getTerm("SO:0000691").getAnnotation().getProperty(NAMESPACE));
76+
77+
} catch (Exception e) {
78+
// TODO Auto-generated catch block
79+
logger.error("Exception: ", e);
80+
fail(e.getMessage());
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)