Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,37 @@
*/
public interface OboFileEventListener {

/** starting to parse a new OBO file
*
*
/**
* starting to parse a new OBO file
*/
public void documentStart();
void documentStart();

/** end of parsing a new OBO file
*
*
/**
* end of parsing a new OBO file
*/
public void documentEnd();
void documentEnd();

/** parsed a new OBO file header
*
*
/**
* parsed a new OBO file header
*/
public void newOboFileHeader();
void newOboFileHeader();

/** parsed a new stanza in the file
*
/**
* parsed a new stanza in the file
* @param stanza
*/
public void newStanza(String stanza);
void newStanza(String stanza);

/**found a new key in the file
*
/**
* found a new key in the file
* @param key
* @param value
*/
public void newKey(String key, String value );
void newKey(String key, String value );

/** a new synonym has been found
*
* @param synonym
*/
public void newSynonym(Synonym synonym);
void newSynonym(Synonym synonym);
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public OboFileHandler(Ontology ontology){

//Term isa = onto.importTerm(OntoTools.IS_A, null);
//Term partof = onto.importTerm(OntoTools.PART_OF, null);;

}

@Override
Expand Down Expand Up @@ -108,7 +107,6 @@ public void newStanza(String stanza) {
} else {
isTerm = false;
}

}

@Override
Expand Down Expand Up @@ -155,7 +153,7 @@ else if (key.equals(NAME)){
// ignore obsolete Terms...
//logger.info("obsolete: {}", currentTerm);
Annotation anno = currentTerm.getAnnotation();
anno.setProperty(IS_OBSOLETE, new Boolean(true));
anno.setProperty(IS_OBSOLETE, Boolean.TRUE);

} else if (key.equals(IS_A) ||
key.equals(RELATIONSHIP) ||
Expand All @@ -174,8 +172,16 @@ else if (key.equals(NAME)){
Annotation anno = currentTerm.getAnnotation();
anno.setProperty(COMMENT, value);
} else if (key.equals(ALT_ID)){
// #964
Annotation anno = currentTerm.getAnnotation();
anno.setProperty(ALT_ID, value);
if (anno.containsProperty(ALT_ID)) {
List<String> alts = (List<String>) anno.getProperty(ALT_ID);
alts.add(value);
} else {
List<String> alts = new ArrayList<>();
alts.add(value);
anno.setProperty(ALT_ID, alts);
}
}
else if (key.equals(REPLACED_BY)) {
Annotation anno = currentTerm.getAnnotation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,68 @@
package org.biojava.nbio.ontology;

import org.biojava.nbio.ontology.io.OboParser;
import org.junit.Assert;
import org.biojava.nbio.ontology.utils.Annotation;
import org.junit.Test;

import java.io.*;
import java.text.ParseException;
import java.util.List;
import java.util.Set;

import static org.biojava.nbio.ontology.obo.OboFileHandler.NAMESPACE;
import static org.biojava.nbio.ontology.obo.OboFileHandler.ALT_ID;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class TestParseOBO {

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

String testTermEntry = "\n[Term]\n" +
"id: SO:0000691\n" +
"name: cleaved_initiator_methionine \n" +
"namespace: sequence\n" +
"alt_id: BS:00067\n" +
"def: \"The initiator methionine that has been cleaved from a mature polypeptide sequence.\" [EBIBS:GAR]\n" +
"subset: biosapiens\n" +
"synonym: \"cleaved initiator methionine\" EXACT []\n" +
"synonym: \"init_met\" RELATED [uniprot:feature_type]\n" +
"synonym: \"initiator methionine\" RELATED []\n" +
"is_a: SO:0100011 ! cleaved_peptide_region\n\n";
private OboParser parser;

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

Assert.assertNotNull(inStream);
public Ontology readObo(String input) throws ParseException, IOException {
parser = new OboParser();
InputStream inStream = new ByteArrayInputStream(input.getBytes());
assertNotNull(inStream);
BufferedReader oboFile = new BufferedReader(new InputStreamReader(inStream));
return parser.parseOBO(oboFile, "so-xp/subsets/biosapiens",
"snippet from biosapiens protein feature ontology");
}

BufferedReader oboFile = new BufferedReader ( new InputStreamReader ( inStream ) );
Ontology ontology = parser.parseOBO(oboFile, "so-xp/subsets/biosapiens",
"snippet from biosapiens protein feature ontology");
@Test
public void testNamespace() throws IOException, ParseException {
Ontology ontology = readObo(testTermEntry);
Set<Term> keys = ontology.getTerms();
assertTrue(keys.size() > 1);
assertTrue(getAnnotationForTerm(ontology).containsProperty(NAMESPACE));
assertEquals("sequence", getAnnotationForTerm(ontology).getProperty(NAMESPACE));
//#964
assertTrue(getAnnotationForTerm(ontology).getProperty(ALT_ID) instanceof List);
}

@Test
public void testMultipleAltIds() throws IOException, ParseException {

String oboWith2AltIds = testTermEntry.replace("BS:00067", "BS:00067\nalt_id: BS:00068");
Ontology ontology = readObo(oboWith2AltIds);
List<String> altIds = (List<String>) getAnnotationForTerm(ontology).getProperty(ALT_ID);
assertEquals(2, altIds.size());
assertEquals("BS:00067", altIds.get(0));
assertEquals("BS:00068", altIds.get(1));
}

private Annotation getAnnotationForTerm(Ontology ontology) {
return ontology.getTerm("SO:0000691").getAnnotation();

Assert.assertTrue(keys.size() > 1);
Assert.assertTrue(ontology.getTerm("SO:0000691").getAnnotation().containsProperty(NAMESPACE));
Assert.assertEquals("sequence", ontology.getTerm("SO:0000691").getAnnotation().getProperty(NAMESPACE));
}
}