|
24 | 24 |
|
25 | 25 | import org.biojava.nbio.ontology.io.OboParser; |
26 | 26 | import org.biojava.nbio.ontology.utils.Annotation; |
| 27 | +import org.junit.Before; |
27 | 28 | import org.junit.Test; |
28 | 29 |
|
29 | 30 | import java.io.*; |
|
39 | 40 |
|
40 | 41 | public class TestParseOBO { |
41 | 42 |
|
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; |
53 | 44 |
|
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; |
56 | 52 |
|
| 53 | + public Ontology readObo(String input) throws ParseException, IOException { |
| 54 | + parser = new OboParser(); |
| 55 | + InputStream inStream = new ByteArrayInputStream(input.getBytes()); |
57 | 56 | 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", |
61 | 59 | "snippet from biosapiens protein feature ontology"); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testNamespace() throws IOException, ParseException { |
| 64 | + Ontology ontology = readObo(testTermEntry); |
62 | 65 |
|
63 | 66 | Set<Term> keys = ontology.getTerms(); |
64 | 67 |
|
65 | 68 | assertTrue(keys.size() > 1); |
66 | 69 | assertTrue(getAnnotationForTerm(ontology).containsProperty(NAMESPACE)); |
67 | 70 | 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 | + } |
69 | 73 |
|
| 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)); |
70 | 83 | } |
71 | 84 |
|
72 | 85 | private Annotation getAnnotationForTerm(Ontology ontology) { |
73 | 86 | return ontology.getTerm("SO:0000691").getAnnotation(); |
| 87 | + |
74 | 88 | } |
75 | 89 | } |
0 commit comments