Skip to content

Commit c44cdc5

Browse files
committed
use list as an annotation value for Alt_id
1 parent 2cc46f8 commit c44cdc5

3 files changed

Lines changed: 54 additions & 42 deletions

File tree

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,37 @@
3333
*/
3434
public interface OboFileEventListener {
3535

36-
/** starting to parse a new OBO file
37-
*
38-
*
36+
/**
37+
* starting to parse a new OBO file
3938
*/
40-
public void documentStart();
39+
void documentStart();
4140

42-
/** end of parsing a new OBO file
43-
*
44-
*
41+
/**
42+
* end of parsing a new OBO file
4543
*/
46-
public void documentEnd();
44+
void documentEnd();
4745

48-
/** parsed a new OBO file header
49-
*
50-
*
46+
/**
47+
* parsed a new OBO file header
5148
*/
52-
public void newOboFileHeader();
49+
void newOboFileHeader();
5350

54-
/** parsed a new stanza in the file
55-
*
51+
/**
52+
* parsed a new stanza in the file
5653
* @param stanza
5754
*/
58-
public void newStanza(String stanza);
55+
void newStanza(String stanza);
5956

60-
/**found a new key in the file
61-
*
57+
/**
58+
* found a new key in the file
6259
* @param key
6360
* @param value
6461
*/
65-
public void newKey(String key, String value );
62+
void newKey(String key, String value );
6663

6764
/** a new synonym has been found
6865
*
6966
* @param synonym
7067
*/
71-
public void newSynonym(Synonym synonym);
68+
void newSynonym(Synonym synonym);
7269
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ public OboFileHandler(Ontology ontology){
8080

8181
//Term isa = onto.importTerm(OntoTools.IS_A, null);
8282
//Term partof = onto.importTerm(OntoTools.PART_OF, null);;
83-
8483
}
8584

8685
@Override
@@ -108,7 +107,6 @@ public void newStanza(String stanza) {
108107
} else {
109108
isTerm = false;
110109
}
111-
112110
}
113111

114112
@Override
@@ -174,8 +172,16 @@ else if (key.equals(NAME)){
174172
Annotation anno = currentTerm.getAnnotation();
175173
anno.setProperty(COMMENT, value);
176174
} else if (key.equals(ALT_ID)){
175+
// #964
177176
Annotation anno = currentTerm.getAnnotation();
178-
anno.setProperty(ALT_ID, value);
177+
if (anno.containsProperty(ALT_ID)) {
178+
List<String> alts = (List<String>) anno.getProperty(ALT_ID);
179+
alts.add(value);
180+
} else {
181+
List<String> alts = new ArrayList<>();
182+
alts.add(value);
183+
anno.setProperty(ALT_ID, alts);
184+
}
179185
}
180186
else if (key.equals(REPLACED_BY)) {
181187
Annotation anno = currentTerm.getAnnotation();

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,44 +23,53 @@
2323
package org.biojava.nbio.ontology;
2424

2525
import org.biojava.nbio.ontology.io.OboParser;
26-
import org.junit.Assert;
26+
import org.biojava.nbio.ontology.utils.Annotation;
2727
import org.junit.Test;
2828

2929
import java.io.*;
3030
import java.text.ParseException;
31+
import java.util.List;
3132
import java.util.Set;
3233

3334
import static org.biojava.nbio.ontology.obo.OboFileHandler.NAMESPACE;
35+
import static org.biojava.nbio.ontology.obo.OboFileHandler.ALT_ID;
36+
import static org.junit.Assert.assertEquals;
37+
import static org.junit.Assert.assertNotNull;
38+
import static org.junit.Assert.assertTrue;
3439

3540
public class TestParseOBO {
3641

3742
@Test
3843
public void testNamespace() throws IOException, ParseException {
3944

40-
String testTermEntry = "\n[Term]\n" +
41-
"id: SO:0000691\n" +
42-
"name: cleaved_initiator_methionine \n" +
43-
"namespace: sequence\n" +
44-
"alt_id: BS:00067\n" +
45-
"def: \"The initiator methionine that has been cleaved from a mature polypeptide sequence.\" [EBIBS:GAR]\n" +
46-
"subset: biosapiens\n" +
47-
"synonym: \"cleaved initiator methionine\" EXACT []\n" +
48-
"synonym: \"init_met\" RELATED [uniprot:feature_type]\n" +
49-
"synonym: \"initiator methionine\" RELATED []\n" +
50-
"is_a: SO:0100011 ! cleaved_peptide_region\n\n";
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";
5153

52-
OboParser parser = new OboParser();
53-
InputStream inStream = new ByteArrayInputStream(testTermEntry.getBytes());
54+
OboParser parser = new OboParser();
55+
InputStream inStream = new ByteArrayInputStream(testTermEntry.getBytes());
5456

55-
Assert.assertNotNull(inStream);
57+
assertNotNull(inStream);
5658

57-
BufferedReader oboFile = new BufferedReader ( new InputStreamReader ( inStream ) );
59+
BufferedReader oboFile = new BufferedReader(new InputStreamReader(inStream));
5860
Ontology ontology = parser.parseOBO(oboFile, "so-xp/subsets/biosapiens",
59-
"snippet from biosapiens protein feature ontology");
61+
"snippet from biosapiens protein feature ontology");
62+
6063
Set<Term> keys = ontology.getTerms();
6164

62-
Assert.assertTrue(keys.size() > 1);
63-
Assert.assertTrue(ontology.getTerm("SO:0000691").getAnnotation().containsProperty(NAMESPACE));
64-
Assert.assertEquals("sequence", ontology.getTerm("SO:0000691").getAnnotation().getProperty(NAMESPACE));
65+
assertTrue(keys.size() > 1);
66+
assertTrue(getAnnotationForTerm(ontology).containsProperty(NAMESPACE));
67+
assertEquals("sequence", getAnnotationForTerm(ontology).getProperty(NAMESPACE));
68+
assertTrue( getAnnotationForTerm(ontology).getProperty(ALT_ID) instanceof List);
69+
70+
}
71+
72+
private Annotation getAnnotationForTerm(Ontology ontology) {
73+
return ontology.getTerm("SO:0000691").getAnnotation();
6574
}
6675
}

0 commit comments

Comments
 (0)