Skip to content

Commit a32f209

Browse files
committed
add test for multiple altids
1 parent c44cdc5 commit a32f209

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

biojava-ontology/src/test/java/org/biojava/nbio/ontology/TestParseOBO.java

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.biojava.nbio.ontology.io.OboParser;
2626
import org.biojava.nbio.ontology.utils.Annotation;
27+
import org.junit.Before;
2728
import org.junit.Test;
2829

2930
import java.io.*;
@@ -39,37 +40,50 @@
3940

4041
public class TestParseOBO {
4142

42-
@Test
43-
public void testNamespace() throws IOException, ParseException {
44-
45-
String testTermEntry = "\n[Term]\n" + "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" + "synonym: \"cleaved initiator methionine\" EXACT []\n"
51-
+ "synonym: \"init_met\" RELATED [uniprot:feature_type]\n"
52-
+ "synonym: \"initiator methionine\" RELATED []\n" + "is_a: SO:0100011 ! cleaved_peptide_region\n\n";
43+
private OboParser parser;
5344

54-
OboParser parser = new OboParser();
55-
InputStream inStream = new ByteArrayInputStream(testTermEntry.getBytes());
45+
final String testTermEntry = "\n[Term]\n" + "id: SO:0000691\n" + "name: cleaved_initiator_methionine \n"
46+
+ "namespace: sequence\n" + "alt_id: BS:00067\n"
47+
+ "def: \"The initiator methionine that has been cleaved from a mature polypeptide sequence.\" [EBIBS:GAR]\n"
48+
+ "subset: biosapiens\n" + "synonym: \"cleaved initiator methionine\" EXACT []\n"
49+
+ "synonym: \"init_met\" RELATED [uniprot:feature_type]\n"
50+
+ "synonym: \"initiator methionine\" RELATED []\n" + "is_a: SO:0100011 ! cleaved_peptide_region\n\n";
51+
private String replace;
5652

53+
public Ontology readObo(String input) throws ParseException, IOException {
54+
parser = new OboParser();
55+
InputStream inStream = new ByteArrayInputStream(input.getBytes());
5756
assertNotNull(inStream);
58-
59-
BufferedReader oboFile = new BufferedReader(new InputStreamReader(inStream));
60-
Ontology ontology = parser.parseOBO(oboFile, "so-xp/subsets/biosapiens",
57+
BufferedReader oboFile = new BufferedReader(new InputStreamReader(inStream));
58+
return parser.parseOBO(oboFile, "so-xp/subsets/biosapiens",
6159
"snippet from biosapiens protein feature ontology");
60+
}
61+
62+
@Test
63+
public void testNamespace() throws IOException, ParseException {
64+
Ontology ontology = readObo(testTermEntry);
6265

6366
Set<Term> keys = ontology.getTerms();
6467

6568
assertTrue(keys.size() > 1);
6669
assertTrue(getAnnotationForTerm(ontology).containsProperty(NAMESPACE));
6770
assertEquals("sequence", getAnnotationForTerm(ontology).getProperty(NAMESPACE));
68-
assertTrue( getAnnotationForTerm(ontology).getProperty(ALT_ID) instanceof List);
71+
assertTrue(getAnnotationForTerm(ontology).getProperty(ALT_ID) instanceof List);
72+
}
6973

74+
@Test
75+
public void testMultipleAltIds() throws IOException, ParseException {
76+
77+
String replace = testTermEntry.replace("BS:00067", "BS:00067\nalt_id: BS:00068");
78+
Ontology ontology = readObo(replace);
79+
List<String> altIds = (List<String>) getAnnotationForTerm(ontology).getProperty(ALT_ID);
80+
assertEquals(2, altIds.size());
81+
assertEquals("BS:00067", altIds.get(0));
82+
assertEquals("BS:00068", altIds.get(1));
7083
}
7184

7285
private Annotation getAnnotationForTerm(Ontology ontology) {
7386
return ontology.getTerm("SO:0000691").getAnnotation();
87+
7488
}
7589
}

0 commit comments

Comments
 (0)