Examples of FastqWriter


Examples of htsjdk.samtools.fastq.FastqWriter

                    final SAMRecord read1 =
                            currentRecord.getFirstOfPairFlag() ? currentRecord : firstRecord;
                    final SAMRecord read2 =
                            currentRecord.getFirstOfPairFlag() ? firstRecord : currentRecord;
                    writeRecord(read1, 1, fq.getFirstOfPair(), READ1_TRIM, READ1_MAX_BASES_TO_WRITE);
                    final FastqWriter secondOfPairWriter = fq.getSecondOfPair();
                    if (secondOfPairWriter == null) {
                        throw new PicardException("Input contains paired reads but no SECOND_END_FASTQ specified.");
                    }
                    writeRecord(read2, 2, secondOfPairWriter, READ2_TRIM, READ2_MAX_BASES_TO_WRITE);
                }
View Full Code Here

Examples of htsjdk.samtools.fastq.FastqWriter

        final Map<SAMReadGroupRecord, FastqWriters> writerMap = new HashMap<SAMReadGroupRecord, FastqWriters>();

        final FastqWriters fastqWriters;
        if (!OUTPUT_PER_RG) {
            IOUtil.assertFileIsWritable(FASTQ);
            final FastqWriter firstOfPairWriter = factory.newWriter(FASTQ);

            final FastqWriter secondOfPairWriter;
            if (INTERLEAVE) {
                secondOfPairWriter = firstOfPairWriter;
            } else if (SECOND_END_FASTQ != null) {
                IOUtil.assertFileIsWritable(SECOND_END_FASTQ);
                secondOfPairWriter = factory.newWriter(SECOND_END_FASTQ);
            } else {
                secondOfPairWriter = null;
            }

            /** Prepare the writer that will accept unpaired reads.  If we're emitting a single fastq - and assuming single-ended reads -
             * then this is simply that one fastq writer.  Otherwise, if we're doing paired-end, we emit to a third new writer, since
             * the other two fastqs are accepting only paired end reads. */
            final FastqWriter unpairedWriter = UNPAIRED_FASTQ == null ? firstOfPairWriter : factory.newWriter(UNPAIRED_FASTQ);
            fastqWriters = new FastqWriters(firstOfPairWriter, secondOfPairWriter, unpairedWriter);

            // For all read groups we may find in the bam, register this single set of writers for them.
            writerMap.put(null, fastqWriters);
            for (final SAMReadGroupRecord rg : samReadGroupRecords) {
                writerMap.put(rg, fastqWriters);
            }
        } else {
            // When we're creating a fastq-group per readgroup, by convention we do not emit a special fastq for unpaired reads.
            for (final SAMReadGroupRecord rg : samReadGroupRecords) {
                final FastqWriter firstOfPairWriter = factory.newWriter(makeReadGroupFile(rg, "_1"));
                // Create this writer on-the-fly; if we find no second-of-pair reads, don't bother making a writer (or delegating,
                // if we're interleaving).
                final Lazy<FastqWriter> lazySecondOfPairWriter = new Lazy<FastqWriter>(new Lazy.LazyInitializer<FastqWriter>() {
                    @Override
                    public FastqWriter make() {
View Full Code Here

Examples of net.sf.picard.fastq.FastqWriter

    }

    protected void doUnpaired() {

        final SAMFileReader reader = new SAMFileReader(IoUtil.openFileForReading(INPUT));
        final FastqWriter writer = FastqWriterFactoryInstance().newWriter(FASTQ);

        for (final SAMRecord record : reader ) {
            if (record.getReadFailsVendorQualityCheckFlag() && !INCLUDE_NON_PF_READS) {
                // do nothing
            }
            else {
                writeRecord(record, null, writer);
            }
        }
        reader.close();
        writer.close();
    }
View Full Code Here

Examples of net.sf.picard.fastq.FastqWriter

    protected void doPaired() {
        IoUtil.assertFileIsWritable(SECOND_END_FASTQ);
        IoUtil.assertFileIsWritable(FRAGMENT_FASTQ);

        final SAMFileReader reader = new SAMFileReader(IoUtil.openFileForReading(INPUT));
        final FastqWriter writer1 = FastqWriterFactoryInstance().newWriter(FASTQ);
        final FastqWriter writer2 = FastqWriterFactoryInstance().newWriter(SECOND_END_FASTQ);
        final FastqWriter fragWriter = FastqWriterFactoryInstance().newWriter(FRAGMENT_FASTQ);
        final Map<String,SAMRecord> firstSeenMates = new HashMap<String,SAMRecord>();
        final Set<String> failedReadNames = new HashSet<String>();

        try {

            for (final SAMRecord currentRecord : reader ) {

                final String currentReadName = currentRecord.getReadName() ;
                final SAMRecord firstRecord = firstSeenMates.get(currentReadName);

                // Skip non-PF reads as necessary
                if (currentRecord.getReadFailsVendorQualityCheckFlag() && !INCLUDE_NON_PF_READS) {
                    if (currentRecord.getReadPairedFlag()) {
                        failedReadNames.add(currentReadName);
                        // if this record failed QC, but we were already holding its mate...
                        if (firstRecord != null) {
                            firstSeenMates.remove(currentReadName);
                            notifyOrphan(currentReadName);
                            writeRecord(firstRecord, null, fragWriter);
                        }
                    }
                    continue;
                }

                if (currentRecord.getReadPairedFlag()) {
                    // if this reads mate already failed QC...
                    if (failedReadNames.contains(currentReadName)) {
                        notifyOrphan(currentReadName);
                        writeRecord(currentRecord, null, fragWriter);
                        continue;
                    }

                    if (firstRecord == null) {
                        firstSeenMates.put(currentReadName, currentRecord) ;
                    }
                    else {
                        assertPairedMates(firstRecord, currentRecord);

                        if (currentRecord.getFirstOfPairFlag()) {
                             writeRecord(currentRecord, 1, writer1);
                             writeRecord(firstRecord, 2, writer2);
                        }
                        else {
                             writeRecord(firstRecord, 1, writer1);
                             writeRecord(currentRecord, 2, writer2);
                        }
                        firstSeenMates.remove(currentReadName);
                    }
                } else {
                    writeRecord(currentRecord, null, fragWriter);
                }
            }

            if (firstSeenMates.size() > 0)  {
               
                // are we ignoring these.   
                if (IGNORE_ORPHAN_MATES == false)
                    throw new PicardException("Found "+firstSeenMates.size()+" reads with flags that indicated they were paired, but no mates were seen.");
           
                for (final SAMRecord currentRecord : firstSeenMates.values()) {
                    writeRecord(currentRecord, null, fragWriter);
                }

            }

        } finally {
            // Flush as much as possible.
            writer1.close();
            writer2.close();
            fragWriter.close();
            reader.close();
        }

    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.