use of gov.nih.nlm.ncbi.blast.Iteration in project jvarkit by lindenb.
the class BlastToSam method run_single.
private void run_single(final SAMFileWriter w, final XMLEventReader r, final SAMFileHeader header) throws XMLStreamException, JAXBException {
final List<Iteration> stack = new ArrayList<Iteration>();
String prev = null;
for (; ; ) {
final Iteration iter1 = peekIteration(r);
if (iter1 == null || !(iter1.getIterationQueryDef().equals(prev))) {
final SequenceIteration si = convertIterationToSequenceIteration(stack, header);
dumpSingle(w, si);
if (iter1 == null)
break;
stack.clear();
prev = iter1.getIterationQueryDef();
}
stack.add(iter1);
}
}
use of gov.nih.nlm.ncbi.blast.Iteration in project jvarkit by lindenb.
the class BlastToSam method run_paired.
private void run_paired(SAMFileWriter w, XMLEventReader r, SAMFileHeader header) throws XMLStreamException, JAXBException {
List<Iteration> stack1 = new ArrayList<Iteration>();
Iteration iter = null;
for (; ; ) {
String prev_name = null;
if (iter == null) {
iter = peekIteration(r);
if (iter == null)
break;
}
stack1.add(iter);
List<Iteration> stack2 = new ArrayList<Iteration>();
prev_name = iter.getIterationQueryDef();
// pileup first of pair
for (; ; ) {
iter = peekIteration(r);
if (iter == null) {
throw new RuntimeException("Illegal number of read forward/reverse");
} else if (iter.getIterationQueryDef().equals(prev_name)) {
stack1.add(iter);
} else {
stack2.add(iter);
prev_name = iter.getIterationQueryDef();
break;
}
}
// pileup second of pair
for (; ; ) {
iter = peekIteration(r);
if (iter == null || !iter.getIterationQueryDef().equals(prev_name)) {
SequenceIteration si1 = convertIterationToSequenceIteration(stack1, header);
SequenceIteration si2 = convertIterationToSequenceIteration(stack2, header);
dumpPaired(w, si1, si2);
stack1.clear();
stack2.clear();
break;
} else {
stack2.add(iter);
}
}
if (iter == null)
break;
}
}
use of gov.nih.nlm.ncbi.blast.Iteration in project jvarkit by lindenb.
the class BlastMapAnnotations method printUniprot.
private void printUniprot(Uniprot uniprotSet) {
if (uniprotSet.getEntry().isEmpty()) {
LOG.warn("empty uniprot entry.");
return;
}
if (uniprotSet.getEntry().size() > 1) {
LOG.warn("entry contains more than one sequence.");
}
for (Entry entry : uniprotSet.getEntry()) {
BlastOutputIterations iterations = this.blastOutput.getBlastOutputIterations();
for (Iteration iteration : iterations.getIteration()) {
for (FeatureType feature : entry.getFeature()) {
if (!acceptfeature(feature.getType()))
continue;
for (Hit hit : iteration.getIterationHits().getHit()) {
for (Hsp hsp : hit.getHitHsps().getHsp()) {
UniprotInterval bi = new UniprotInterval();
bi.entry = entry;
bi.featureType = feature;
bi.hit = hit;
bi.hsp = hsp;
LOG.debug("interval " + bi);
if (!bi.isFeatureOverlapHsp()) {
continue;
}
stdout().println(bi.toBedString());
}
}
}
break;
}
break;
}
// System.err.println("OK");
}
use of gov.nih.nlm.ncbi.blast.Iteration in project jvarkit by lindenb.
the class BlastNToSnp method peekIteration.
private Iteration peekIteration(final XMLEventReader r) throws XMLStreamException, JAXBException {
while (r.hasNext()) {
final XMLEvent evt = r.peek();
if (!(evt.isStartElement())) {
r.next();
continue;
}
final String name = evt.asStartElement().getName().getLocalPart();
if (name.equals("BlastOutput_program")) {
r.next();
String prog = r.getElementText();
if (!"blastn".equals(prog)) {
throw new XMLStreamException("Not a blastn input:" + prog);
}
continue;
}
if (!name.equals("Iteration")) {
r.next();
continue;
}
return this.unmarshaller.unmarshal(r, Iteration.class).getValue();
}
return null;
}
use of gov.nih.nlm.ncbi.blast.Iteration in project jvarkit by lindenb.
the class MergeSplittedBlast method run.
private void run(XMLEventReader r, XMLEventWriter w) throws XMLStreamException, JAXBException {
while (r.hasNext()) {
XMLEvent evt = r.peek();
if (!(evt.isStartElement())) {
w.add(r.nextEvent());
continue;
}
String name = evt.asStartElement().getName().getLocalPart();
if (name.equals("BlastOutput_program")) {
w.add(r.nextEvent());
// TEXT
evt = r.nextEvent();
if (!evt.isCharacters())
throw new XMLStreamException("Expected a string after " + name);
String prog = evt.asCharacters().getData();
if (!"blastn".equals(prog)) {
throw new XMLStreamException("Not a blastn input:" + prog);
}
w.add(evt);
continue;
}
if (!name.equals("Iteration")) {
w.add(r.nextEvent());
continue;
}
Iteration iter = this.unmarshaller.unmarshal(r, Iteration.class).getValue();
iter = merge(iter);
this.marshaller.marshal(iter, w);
}
}
Aggregations