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;
036import java.net.URL;
037import java.util.Iterator;
038import java.util.Set;
039
040public class ParseGO {
041
042        private static final Logger logger = LoggerFactory.getLogger(ParseGO.class);
043
044        public static void main(String[] args){
045
046                String u = "http://sourceforge.net/p/song/svn/HEAD/tree/trunk/subsets/biosapiens.obo?format=raw";
047
048                try {
049                        URL url = new URL(u);
050
051                        OboParser parser = new OboParser();
052                        InputStream inStream = url.openStream();
053
054                        BufferedReader oboFile = new BufferedReader ( new InputStreamReader ( inStream ) );
055
056                        Ontology ontology = parser.parseOBO(oboFile, "BioSapiens", "the BioSapiens ontology");
057
058                        Set<Term> keys = ontology.getTerms();
059                        Iterator<Term> iter = keys.iterator();
060                        while (iter.hasNext()){
061                                Term t = iter.next();
062                                logger.info("{} [{}]", t.getName(), t.getDescription());
063                        }
064                } catch (Exception e){
065                        logger.error("Exception: ", e);
066                }
067        }
068}