|
| 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 | +import org.slf4j.Logger; |
| 28 | +import org.slf4j.LoggerFactory; |
| 29 | + |
| 30 | +import java.io.BufferedReader; |
| 31 | +import java.io.ByteArrayInputStream; |
| 32 | +import java.io.InputStream; |
| 33 | +import java.io.InputStreamReader; |
| 34 | +import java.util.Set; |
| 35 | + |
| 36 | +import static org.biojava.nbio.ontology.obo.OboFileHandler.NAMESPACE; |
| 37 | + |
| 38 | +public class TestParseOBO extends TestCase { |
| 39 | + |
| 40 | + private static final Logger logger = LoggerFactory.getLogger(TestParseOBO.class); |
| 41 | + |
| 42 | + public void testNamespace(){ |
| 43 | + |
| 44 | + String testTermEntry = "\n[Term]\n" + |
| 45 | + "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" + |
| 51 | + "synonym: \"cleaved initiator methionine\" EXACT []\n" + |
| 52 | + "synonym: \"init_met\" RELATED [uniprot:feature_type]\n" + |
| 53 | + "synonym: \"initiator methionine\" RELATED []\n" + |
| 54 | + "is_a: SO:0100011 ! cleaved_peptide_region\n\n"; |
| 55 | + |
| 56 | + OboParser parser = new OboParser(); |
| 57 | + |
| 58 | + try { |
| 59 | + |
| 60 | + |
| 61 | + InputStream inStream = new ByteArrayInputStream(testTermEntry.getBytes()); |
| 62 | + |
| 63 | + assertNotNull(inStream); |
| 64 | + |
| 65 | + BufferedReader oboFile = new BufferedReader ( new InputStreamReader ( inStream ) ); |
| 66 | + |
| 67 | + Ontology ontology; |
| 68 | + |
| 69 | + ontology = parser.parseOBO(oboFile, "so-xp/subsets/biosapiens", |
| 70 | + "snippet from biosapiens protein feature ontology"); |
| 71 | + Set<Term> keys = ontology.getTerms(); |
| 72 | + |
| 73 | + assertTrue(keys.size() > 1); |
| 74 | + assertTrue(ontology.getTerm("SO:0000691").getAnnotation().containsProperty(NAMESPACE)); |
| 75 | + assertEquals("sequence",ontology.getTerm("SO:0000691").getAnnotation().getProperty(NAMESPACE)); |
| 76 | + |
| 77 | + } catch (Exception e) { |
| 78 | + // TODO Auto-generated catch block |
| 79 | + logger.error("Exception: ", e); |
| 80 | + fail(e.getMessage()); |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments