Search in sources :

Example 6 with FourLinesFastqReader

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

the class PadEmptyFastq method doWork.

@Override
public int doWork(final List<String> args) {
    FastqWriter fqw = null;
    try {
        if (this.outFile == null) {
            LOG.info("writing to stdout");
            fqw = new BasicFastqWriter(stdout());
        } else {
            LOG.info("writing to " + this.outFile);
            fqw = new FastqWriterFactory().newWriter(this.outFile);
        }
        if (args.isEmpty()) {
            LOG.info("Reading from stdin");
            FastqReader fqr = new FourLinesFastqReader(stdin());
            copyTo(fqr, fqw);
            fqr.close();
        } else {
            for (final String filename : args) {
                LOG.info("Reading from " + filename);
                FastqReader fqr = new FourLinesFastqReader(new File(filename));
                copyTo(fqr, fqw);
                fqr.close();
            }
        }
        return 0;
    } catch (final Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(fqw);
    }
}
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) FastqWriterFactory(htsjdk.samtools.fastq.FastqWriterFactory) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) BasicFastqWriter(htsjdk.samtools.fastq.BasicFastqWriter) File(java.io.File)

Example 7 with FourLinesFastqReader

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

the class FastqRevComp method doWork.

@Override
public int doWork(List<String> args) {
    if (only_R1 && only_R2) {
        LOG.error("Both options -1 && -2 used.");
        return -1;
    }
    PrintStream out = null;
    try {
        out = super.openFileOrStdoutAsPrintStream(outputFile);
        if (args.isEmpty()) {
            LOG.info("Reading from stdin");
            FastqReader fqR = new FourLinesFastqReader(stdin());
            run(fqR, out);
            fqR.close();
        } else
            for (final String fn : args) {
                File f = new File(fn);
                LOG.info("Reading from " + f);
                FastqReader fqR = new FourLinesFastqReader(f);
                run(fqR, out);
                fqR.close();
            }
        out.flush();
    } catch (Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(out);
    }
    return 0;
}
Also used : PrintStream(java.io.PrintStream) 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)

Example 8 with FourLinesFastqReader

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

the class FastqGrep method doWork.

@Override
public int doWork(List<String> args) {
    BufferedReader in = null;
    FastqWriter out = null;
    try {
        if (this.readNameFile != null) {
            in = IOUtils.openFileForBufferedReading(this.readNameFile);
            String line;
            while ((line = in.readLine()) != null) {
                line = line.trim();
                if (line.isEmpty())
                    continue;
                this.readNames.put(getReadName(line), 0);
            }
            in.close();
        }
        for (final String r : this.readNamesInput) {
            this.readNames.put(getReadName(r), 0);
        }
        if (readNames.isEmpty()) {
            LOG.warn("no read name found.");
        }
        if (this.outputFile != null) {
            LOG.info("Writing to " + this.outputFile);
            out = new BasicFastqWriter(this.outputFile);
        } else {
            LOG.info("Writing to stdout");
            out = new BasicFastqWriter(stdout());
        }
        if (args.isEmpty()) {
            LOG.info("Reading from stdin");
            FastqReader fqR = new FourLinesFastqReader(System.in);
            run(fqR, out);
            fqR.close();
        } else
            for (String fname : args) {
                File f = new File(fname);
                LOG.info("Reading from " + f);
                FastqReader fqR = new FourLinesFastqReader(f);
                run(fqR, out);
                fqR.close();
            }
        CloserUtil.close(out);
        return 0;
    } catch (Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(in);
    }
}
Also used : FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FastqReader(com.github.lindenb.jvarkit.util.picard.FastqReader) BufferedReader(java.io.BufferedReader) 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)

Example 9 with FourLinesFastqReader

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

the class FastqToFasta method doWork.

@Override
public int doWork(final List<String> args) {
    PrintStream out = null;
    try {
        out = super.openFileOrStdoutAsPrintStream(outputFile);
        if (args.isEmpty()) {
            LOG.info("Reading from stdin");
            FastqReader fqR = new FourLinesFastqReader(stdin());
            run(fqR, out);
            fqR.close();
        } else
            for (String fname : args) {
                File f = new File(fname);
                LOG.info("Reading from " + f);
                FastqReader fqR = new FourLinesFastqReader(f);
                run(fqR, out);
                fqR.close();
            }
        out.flush();
    } catch (Exception err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(out);
    }
    return 0;
}
Also used : PrintStream(java.io.PrintStream) FastqReader(com.github.lindenb.jvarkit.util.picard.FastqReader) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) FourLinesFastqReader(com.github.lindenb.jvarkit.util.picard.FourLinesFastqReader) File(java.io.File)

Example 10 with FourLinesFastqReader

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

the class FindCorruptedFiles method testFastq.

private void testFastq(File f) {
    long n = 0;
    LOG.fine("Test Fastq for " + f);
    FastqReader r = null;
    try {
        r = new FourLinesFastqReader(f);
        r.setValidationStringency(this.validationStringency);
        while (r.hasNext() && (NUM < 0 || n < NUM)) {
            r.next();
            ++n;
        }
        if (n == 0) {
            emptyFile(f);
        }
    } catch (Exception err) {
        LOG.fine("Cannot read " + f);
        stdout().println(f);
    } finally {
        CloserUtil.close(r);
    }
}
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) TribbleException(htsjdk.tribble.TribbleException) IOException(java.io.IOException)

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