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;
}
}
Aggregations