Search in sources :

Example 6 with Iteration

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);
    }
}
Also used : ArrayList(java.util.ArrayList) Iteration(gov.nih.nlm.ncbi.blast.Iteration)

Example 7 with Iteration

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;
    }
}
Also used : ArrayList(java.util.ArrayList) Iteration(gov.nih.nlm.ncbi.blast.Iteration)

Example 8 with Iteration

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");
}
Also used : BlastOutputIterations(gov.nih.nlm.ncbi.blast.BlastOutputIterations) FeatureType(org.uniprot.FeatureType) Entry(org.uniprot.Entry) Hit(gov.nih.nlm.ncbi.blast.Hit) Hsp(gov.nih.nlm.ncbi.blast.Hsp) Iteration(gov.nih.nlm.ncbi.blast.Iteration)

Example 9 with Iteration

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;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLEvent(javax.xml.stream.events.XMLEvent) Iteration(gov.nih.nlm.ncbi.blast.Iteration)

Example 10 with Iteration

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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLEvent(javax.xml.stream.events.XMLEvent) Iteration(gov.nih.nlm.ncbi.blast.Iteration)

Aggregations

Iteration (gov.nih.nlm.ncbi.blast.Iteration)12 Hit (gov.nih.nlm.ncbi.blast.Hit)5 XMLEvent (javax.xml.stream.events.XMLEvent)5 Hsp (gov.nih.nlm.ncbi.blast.Hsp)4 ArrayList (java.util.ArrayList)4 XMLStreamException (javax.xml.stream.XMLStreamException)3 BlastOutputIterations (gov.nih.nlm.ncbi.blast.BlastOutputIterations)2 IOException (java.io.IOException)2 List (java.util.List)2 QName (javax.xml.namespace.QName)2 Parameter (com.beust.jcommander.Parameter)1 IOUtils (com.github.lindenb.jvarkit.io.IOUtils)1 BlastHspAlignment (com.github.lindenb.jvarkit.util.bio.blast.BlastHspAlignment)1 EqualRangeIterator (com.github.lindenb.jvarkit.util.iterator.EqualRangeIterator)1 Launcher (com.github.lindenb.jvarkit.util.jcommander.Launcher)1 Program (com.github.lindenb.jvarkit.util.jcommander.Program)1 Logger (com.github.lindenb.jvarkit.util.log.Logger)1 AbstractDataCodec (com.github.lindenb.jvarkit.util.picard.AbstractDataCodec)1 IterationHits (gov.nih.nlm.ncbi.blast.IterationHits)1 GBFeature (gov.nih.nlm.ncbi.gb.GBFeature)1