Search in sources :

Example 1 with Uniprot

use of org.uniprot.Uniprot in project jvarkit by lindenb.

the class BlastMapAnnotations method doWork.

@Override
public int doWork(List<String> args) {
    try {
        /**
         * xml parser
         */
        DocumentBuilder docBuilder;
        /**
         * transforms XML/DOM to GBC entry
         */
        Unmarshaller unmarshaller;
        // create a DOM parser
        DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
        f.setCoalescing(true);
        // f.setNamespaceAware(true); no, why does it break the parsing of uniprot ??
        f.setValidating(false);
        f.setExpandEntityReferences(true);
        docBuilder = f.newDocumentBuilder();
        docBuilder.setEntityResolver(new EntityResolver() {

            @Override
            public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
                return new InputSource(new StringReader(""));
            }
        });
        // create a Unmarshaller for NCBI
        JAXBContext jc = JAXBContext.newInstance("gov.nih.nlm.ncbi.gb:gov.nih.nlm.ncbi.blast:org.uniprot");
        unmarshaller = jc.createUnmarshaller();
        LOG.info("reading entry " + IN);
        Document domEntry = docBuilder.parse(IN);
        GBSet gbSet = null;
        Uniprot uniprotSet = null;
        if ("GBSet".equals(domEntry.getDocumentElement().getNodeName())) {
            LOG.info("parsing as GBSet");
            gbSet = unmarshaller.unmarshal(domEntry, GBSet.class).getValue();
        } else if ("uniprot".equals(domEntry.getDocumentElement().getNodeName())) {
            LOG.info("parsing as Uniprot " + domEntry.getDocumentElement());
            uniprotSet = unmarshaller.unmarshal(domEntry, Uniprot.class).getValue();
        // LOG.info(uniprotSet.getEntry().size());
        // jc.createMarshaller().marshal(uniprotSet, System.err);
        } else {
            LOG.info("unknown root element:" + domEntry.getDocumentElement().getNodeName());
            return -1;
        }
        Document blastDom;
        if (args.size() == 1) {
            LOG.info("reading " + args.get(0));
            blastDom = docBuilder.parse(new File(args.get(0)));
        } else if (args.isEmpty()) {
            LOG.info("reading from stdin");
            blastDom = docBuilder.parse(stdin());
        } else {
            LOG.error("Illegal number of args");
            return -1;
        }
        this.blastOutput = unmarshaller.unmarshal(blastDom, BlastOutput.class).getValue();
        if (uniprotSet != null)
            printUniprot(uniprotSet);
        if (gbSet != null)
            printGB(gbSet);
        return 0;
    } catch (Exception err) {
        LOG.error(err);
        return -1;
    }
}
Also used : GBSet(gov.nih.nlm.ncbi.gb.GBSet) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) JAXBContext(javax.xml.bind.JAXBContext) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) SAXException(org.xml.sax.SAXException) Uniprot(org.uniprot.Uniprot) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Aggregations

GBSet (gov.nih.nlm.ncbi.gb.GBSet)1 File (java.io.File)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Uniprot (org.uniprot.Uniprot)1 Document (org.w3c.dom.Document)1 EntityResolver (org.xml.sax.EntityResolver)1 InputSource (org.xml.sax.InputSource)1 SAXException (org.xml.sax.SAXException)1