Search in sources :

Example 11 with FastqReader

use of com.github.lindenb.jvarkit.util.picard.FastqReader 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 FastqReader

use of com.github.lindenb.jvarkit.util.picard.FastqReader 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)

Aggregations

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