Skip to content

Commit e957d07

Browse files
authored
Merge pull request biojava#698 from tulay/obo-namespace
Biojava biojava#695: Stores namespace as annotation
2 parents 0c99ed0 + 565589d commit e957d07

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
28+
import java.io.*;
29+
import java.text.ParseException;
30+
import java.util.Set;
31+
32+
import static org.biojava.nbio.ontology.obo.OboFileHandler.NAMESPACE;
33+
34+
public class TestParseOBO extends TestCase {
35+
36+
public void testNamespace() throws IOException, ParseException {
37+
38+
String testTermEntry = "\n[Term]\n" +
39+
"id: SO:0000691\n" +
40+
"name: cleaved_initiator_methionine \n" +
41+
"namespace: sequence\n" +
42+
"alt_id: BS:00067\n" +
43+
"def: \"The initiator methionine that has been cleaved from a mature polypeptide sequence.\" [EBIBS:GAR]\n" +
44+
"subset: biosapiens\n" +
45+
"synonym: \"cleaved initiator methionine\" EXACT []\n" +
46+
"synonym: \"init_met\" RELATED [uniprot:feature_type]\n" +
47+
"synonym: \"initiator methionine\" RELATED []\n" +
48+
"is_a: SO:0100011 ! cleaved_peptide_region\n\n";
49+
50+
OboParser parser = new OboParser();
51+
InputStream inStream = new ByteArrayInputStream(testTermEntry.getBytes());
52+
53+
assertNotNull(inStream);
54+
55+
BufferedReader oboFile = new BufferedReader ( new InputStreamReader ( inStream ) );
56+
Ontology ontology = parser.parseOBO(oboFile, "so-xp/subsets/biosapiens",
57+
"snippet from biosapiens protein feature ontology");
58+
Set<Term> keys = ontology.getTerms();
59+
60+
assertTrue(keys.size() > 1);
61+
assertTrue(ontology.getTerm("SO:0000691").getAnnotation().containsProperty(NAMESPACE));
62+
assertEquals("sequence",ontology.getTerm("SO:0000691").getAnnotation().getProperty(NAMESPACE));
63+
}
64+
}

0 commit comments

Comments
 (0)