Search in sources :

Example 11 with FourLinesFastqReader

use of com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader in project jvarkit by lindenb.

the class FastqJavascript method doWork.

@Override
public int doWork(List<String> args) {
    if ((this.R1FileOut == null && this.R2FileOut != null) || (this.R1FileOut != null && this.R2FileOut == null)) {
        LOG.error("Option OPTION_R1FILEOUT  / OPTION_R2FILEOUT must be both defined");
        return -1;
    }
    try {
        this.script = super.compileJavascript(this.javascriptExpr, this.javascriptFile);
        if (args.isEmpty()) {
            final FastqReader in = new FourLinesFastqReader(stdin());
            doWork(in);
            in.close();
        } else if (args.size() == 2) {
            LOG.info("2 fastqs: Reading as interleavel fastqs");
            final FastqReader in1 = new FourLinesFastqReader(new File(args.get(0)));
            final FastqReader in2 = new FourLinesFastqReader(new File(args.get(1)));
            final FastqReader in = new InterleavedFastqReader(in1, in2);
            this.interleaved = true;
            doWork(in);
            in.close();
        } else if (args.size() == 1) {
            final FastqReader in = new FourLinesFastqReader(new File(args.get(0)));
            doWork(in);
            in.close();
        } else {
            LOG.error("Illegal number of arguments");
            return -1;
        }
        return RETURN_OK;
    } catch (final Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(failingReadsWriter);
    }
}
Also used : FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqReader(com.github.lindenb.jvarkit.util.picard.FastqReader) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) File(java.io.File) IOException(java.io.IOException) ScriptException(javax.script.ScriptException)

Example 12 with FourLinesFastqReader

use of com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader in project jvarkit by lindenb.

the class FastqShuffle method doWork.

@Override
public int doWork(final List<String> args) {
    FastqReader r1 = null;
    FastqReader r2 = null;
    FastqWriter w = null;
    try {
        if (fileout == null) {
            w = new BasicFastqWriter(stdout());
        } else {
            w = new BasicFastqWriter(this.fileout);
        }
        if (args.isEmpty()) {
            LOG.info("Reading from stdin");
            r1 = new FourLinesFastqReader(stdin());
            if (interleaved_input) {
                runPaired(r1, null, w);
            } else {
                runSingle(r1, w);
            }
        } else if (args.size() == 1) {
            r1 = new FourLinesFastqReader(new File(args.get(0)));
            if (interleaved_input) {
                runPaired(r1, null, w);
            } else {
                runSingle(r1, w);
            }
        } else if (args.size() == 2) {
            r1 = new FourLinesFastqReader(new File(args.get(0)));
            r2 = new FourLinesFastqReader(new File(args.get(1)));
            runPaired(r1, r2, w);
        } else {
            LOG.error("illegal.number.of.arguments");
            return -1;
        }
        return 0;
    } catch (final Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(r1);
        CloserUtil.close(r2);
        CloserUtil.close(w);
    }
}
Also used : FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqReader(com.github.lindenb.jvarkit.util.picard.FastqReader) BasicFastqWriter(htsjdk.samtools.fastq.BasicFastqWriter) FastqWriter(htsjdk.samtools.fastq.FastqWriter) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) BasicFastqWriter(htsjdk.samtools.fastq.BasicFastqWriter) File(java.io.File) IOException(java.io.IOException)

Example 13 with FourLinesFastqReader

use of com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader in project jvarkit by lindenb.

the class BioAlcidae method execute_fastq.

private int execute_fastq(String source) throws IOException {
    InputStream in = null;
    FourLinesFastqReader iter = null;
    try {
        if (source == null) {
            in = stdin();
        } else {
            in = IOUtils.openURIForReading(source);
        }
        iter = new FourLinesFastqReader(in);
        bindings.put("iter", in);
        bindings.put("format", "fastq");
        this.script.eval(bindings);
        this.writer.flush();
        return RETURN_OK;
    } catch (Exception e) {
        LOG.error(e);
        return -1;
    } finally {
        CloserUtil.close(iter);
        CloserUtil.close(in);
        bindings.remove("header");
        bindings.remove("iter");
        bindings.remove("format");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) RuntimeIOException(htsjdk.samtools.util.RuntimeIOException) XMLStreamException(javax.xml.stream.XMLStreamException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

FourLinesFastqReader (com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader)13 FastqReader (com.github.lindenb.jvarkit.util.picard.FastqReader)12 File (java.io.File)8 IOException (java.io.IOException)8 BasicFastqWriter (htsjdk.samtools.fastq.BasicFastqWriter)4 FastqWriter (htsjdk.samtools.fastq.FastqWriter)4 FastqRecord (htsjdk.samtools.fastq.FastqRecord)3 PrintStream (java.io.PrintStream)3 InputStream (java.io.InputStream)2 ScriptException (javax.script.ScriptException)2 NullOuputStream (com.github.lindenb.jvarkit.io.NullOuputStream)1 FastqWriterFactory (htsjdk.samtools.fastq.FastqWriterFactory)1 RuntimeIOException (htsjdk.samtools.util.RuntimeIOException)1 TribbleException (htsjdk.tribble.TribbleException)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 JAXBException (javax.xml.bind.JAXBException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1