001package org.biopax.paxtools.examples;
002
003import org.apache.commons.logging.Log;
004import org.apache.commons.logging.LogFactory;
005import org.biopax.paxtools.io.BioPAXIOHandler;
006import org.biopax.paxtools.io.SimpleIOHandler;
007import org.biopax.paxtools.model.Model;
008import org.biopax.paxtools.model.level2.physicalEntity;
009import org.biopax.paxtools.model.level2.unificationXref;
010import org.biopax.paxtools.util.ClassFilterSet;
011
012import java.io.File;
013import java.io.FileInputStream;
014import java.io.FileNotFoundException;
015import java.lang.reflect.InvocationTargetException;
016import java.util.Set;
017
018/**
019 * A basic example that shows how to list all unification xrefs.
020 *
021 * NOTE: This method is now outdated as it is easier to do this now with the new PathAccessors. I did not remove this
022 * example, however, as it demonstrates many "low-level" operations of Paxtools.
023
024 */
025public class UnificationIDtoRDFIDLister
026{
027        private static Log log = LogFactory.getLog(
028                UnificationIDtoRDFIDLister.class);
029
030        static BioPAXIOHandler handler = new SimpleIOHandler();
031
032        public static void main(String[] args)
033                throws IllegalAccessException, InvocationTargetException
034        {
035
036        for (String arg : args)
037        {
038            log.info(arg);
039            if (arg.toLowerCase().endsWith("owl"))
040            {
041                try
042                {
043                    processXrefs(arg);
044                }
045                catch (FileNotFoundException e)
046                {
047                    e.printStackTrace();
048                }
049            }
050
051        }
052        }
053
054        private static void processXrefs(String arg) throws
055                FileNotFoundException,
056                IllegalAccessException,
057                InvocationTargetException
058        {
059                FileInputStream in =
060                        new FileInputStream(new File(arg));
061                Model level2 = handler.convertFromOWL(in);
062
063                Set<unificationXref> unis =
064                        level2.getObjects(unificationXref.class);
065                for (unificationXref uni : unis)
066                {
067                        ClassFilterSet referrables = new ClassFilterSet(uni.isXREFof(),
068                                physicalEntity.class);
069                        for (Object referrable : referrables)
070                        {
071                                System.out
072                                        .print(uni.getDB() + " : " + uni.getID() + " refers to " +
073                                                ((physicalEntity) referrable).getRDFId());
074                        }
075                }
076        }
077}