Search in sources :

Example 1 with FastqPairedWriterFactory

use of com.github.lindenb.jvarkit.fastq.FastqPairedWriterFactory in project jvarkit by lindenb.

the class FastqSplitInterleaved method doWork.

@Override
public int doWork(final List<String> args) {
    if (this.fileA.equals(this.fileB)) {
        LOG.error("R1 file==R2.file.");
        return -1;
    }
    CloseableIterator<FastqRecordPair> iter1 = null;
    FastqPairedWriter pairedWriter = null;
    try {
        final String input = oneFileOrNull(args);
        final FastqPairedReaderFactory fqprf = new FastqPairedReaderFactory().setValidateReadNames(this.validate_read_names);
        if (input == null) {
            iter1 = fqprf.open(stdin());
        } else {
            iter1 = fqprf.open(Paths.get(input));
        }
        final FastqPairedWriterFactory fqwf = new FastqPairedWriterFactory().setCreateMd5(this.write_md5).setAsyncIo(this.with_asynio);
        pairedWriter = fqwf.open(fileA, fileB);
        while (iter1.hasNext()) {
            pairedWriter.write(iter1.next());
        }
        iter1.close();
        pairedWriter.close();
        return 0;
    } catch (final Throwable err) {
        LOG.error(err);
        return -1;
    } finally {
        CloserUtil.close(iter1);
        CloserUtil.close(pairedWriter);
    }
}
Also used : FastqRecordPair(com.github.lindenb.jvarkit.fastq.FastqRecordPair) FastqPairedWriter(com.github.lindenb.jvarkit.fastq.FastqPairedWriter) FastqPairedReaderFactory(com.github.lindenb.jvarkit.fastq.FastqPairedReaderFactory) FastqPairedWriterFactory(com.github.lindenb.jvarkit.fastq.FastqPairedWriterFactory)

Example 2 with FastqPairedWriterFactory

use of com.github.lindenb.jvarkit.fastq.FastqPairedWriterFactory in project jvarkit by lindenb.

the class OnePassFastqLauncher method runPairedEnd.

@Override
protected int runPairedEnd(final CloseableIterator<FastqRecordPair> iter) throws IOException {
    int ret = 0;
    FastqPairedWriter fws = null;
    try {
        final FastqPairedWriterFactory fpwf = new FastqPairedWriterFactory();
        fpwf.setCreateMd5(this.write_md5);
        if (outputFile1 != null && outputFile2 != null) {
            fws = fpwf.open(outputFile1, outputFile2);
        } else if (outputFile1 != null && outputFile2 == null) {
            fws = fpwf.open(outputFile1);
        } else if (outputFile1 == null && outputFile2 == null) {
            fws = fpwf.open(new PrintStream(new BufferedOutputStream(stdout())));
        } else {
            getLogger().error("bad output declaration.");
            return -1;
        }
        ret = runPairedEnd(iter, fws);
        fws.close();
        return ret;
    } catch (final Throwable err) {
        getLogger().error(err);
        return -1;
    } finally {
        if (fws != null)
            fws.close();
    }
}
Also used : PrintStream(java.io.PrintStream) FastqPairedWriter(com.github.lindenb.jvarkit.fastq.FastqPairedWriter) FastqPairedWriterFactory(com.github.lindenb.jvarkit.fastq.FastqPairedWriterFactory) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with FastqPairedWriterFactory

use of com.github.lindenb.jvarkit.fastq.FastqPairedWriterFactory in project jvarkit by lindenb.

the class FastqSplit method openPairedWriter.

private FastqPairedWriter openPairedWriter(int i, PrintWriter manifest) throws IOException {
    final FastqPairedWriterFactory fqpwf = new FastqPairedWriterFactory().setCreateMd5(write_md5).setAsyncIo(with_asynio);
    final FastqPairedWriter w;
    if (this.output_is_interleaved) {
        final String tag = String.format("%09d.R12", (i + 1));
        final String filename = this.basename.replace(TAG, tag);
        final File file = new File(filename);
        if (file.getParentFile() != null)
            file.getParentFile().mkdirs();
        w = fqpwf.open(file);
        manifest.println(file);
    } else {
        final File[] files = new File[2];
        for (int j = 0; j < 2; ++j) {
            final String tag = String.format("%09d.R%d", (i + 1), (j + 1));
            final String filename = this.basename.replace(TAG, tag);
            final File file = new File(filename);
            if (file.getParentFile() != null)
                file.getParentFile().mkdirs();
            files[j] = file;
        }
        w = fqpwf.open(files[0], files[1]);
        manifest.print(files[0]);
        manifest.print("\t");
        manifest.println(files[1]);
    }
    return w;
}
Also used : FastqPairedWriter(com.github.lindenb.jvarkit.fastq.FastqPairedWriter) FastqPairedWriterFactory(com.github.lindenb.jvarkit.fastq.FastqPairedWriterFactory) File(java.io.File)

Aggregations

FastqPairedWriter (com.github.lindenb.jvarkit.fastq.FastqPairedWriter)3 FastqPairedWriterFactory (com.github.lindenb.jvarkit.fastq.FastqPairedWriterFactory)3 FastqPairedReaderFactory (com.github.lindenb.jvarkit.fastq.FastqPairedReaderFactory)1 FastqRecordPair (com.github.lindenb.jvarkit.fastq.FastqRecordPair)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1