001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 * Created on Mar 19, 2014 021 * Author: andreas 022 * 023 */ 024 025package demo; 026 027import org.biojava.nbio.ontology.Ontology; 028import org.biojava.nbio.ontology.Term; 029import org.biojava.nbio.ontology.io.OboParser; 030import org.slf4j.Logger; 031import org.slf4j.LoggerFactory; 032 033import java.io.BufferedReader; 034import java.io.InputStream; 035import java.io.InputStreamReader; 036 037import java.util.Iterator; 038import java.util.Set; 039 040public class ParseGO { 041 042 static final Logger logger = LoggerFactory.getLogger(ParseGO.class); 043 044 /** 045 * Parses Biosapiens OBO file and logs name/description at INFO level 046 * 047 * @param args 048 */ 049 public static void main(String[] args) { 050 051 OboParser parser = new OboParser(); 052 try (InputStream inStream = OboParser.class.getResourceAsStream("/ontology/bio sapiens.obo"); 053 BufferedReader oboFile = new BufferedReader(new InputStreamReader(inStream))) { 054 Ontology ontology = parser.parseOBO(oboFile, "BioSapiens", "the BioSapiens ontology"); 055 Set<Term> keys = ontology.getTerms(); 056 Iterator<Term> iter = keys.iterator(); 057 while (iter.hasNext()) { 058 Term t = iter.next(); 059 logger.info("{} [{}]", t.getName(), t.getDescription()); 060 } 061 062 } catch (Exception e) { 063 logger.error("Exception: " + e); 064 System.exit(1); 065 } 066 } 067}