Search in sources :

Example 31 with ProgressLogger

use of org.broadinstitute.hellbender.utils.runtime.ProgressLogger in project gatk by broadinstitute.

the class CollectQualityYieldMetrics method doWork.

/**
     * Main method for the program.  Checks that all input files are present and
     * readable and that the output file can be written to.  Then iterates through
     * all the records accumulating metrics.  Finally writes metrics file
     */
@Override
protected Object doWork() {
    final ProgressLogger progress = new ProgressLogger(logger);
    File output = new File(qualityYieldMetricsArgs.output);
    // Some quick parameter checking
    IOUtil.assertFileIsReadable(INPUT);
    IOUtil.assertFileIsWritable(output);
    logger.info("Reading input file and calculating metrics.");
    final SamReader sam = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT);
    final MetricsFile<QualityYieldMetrics, Integer> metricsFile = getMetricsFile();
    final QualityYieldMetrics metrics = new QualityYieldMetrics();
    metrics.setUseOriginalQualities(qualityYieldMetricsArgs.useOriginalQualities);
    for (final SAMRecord rec : sam) {
        metrics.addRead(new SAMRecordToGATKReadAdapter(rec));
        progress.record(rec);
    }
    metrics.finish();
    metricsFile.addMetric(metrics);
    metricsFile.write(output);
    return null;
}
Also used : SamReader(htsjdk.samtools.SamReader) QualityYieldMetrics(org.broadinstitute.hellbender.metrics.QualityYieldMetrics) SAMRecordToGATKReadAdapter(org.broadinstitute.hellbender.utils.read.SAMRecordToGATKReadAdapter) SAMRecord(htsjdk.samtools.SAMRecord) ProgressLogger(org.broadinstitute.hellbender.utils.runtime.ProgressLogger) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File)

Aggregations

ProgressLogger (org.broadinstitute.hellbender.utils.runtime.ProgressLogger)31 SamReader (htsjdk.samtools.SamReader)13 SAMRecord (htsjdk.samtools.SAMRecord)12 UserException (org.broadinstitute.hellbender.exceptions.UserException)11 VariantContext (htsjdk.variant.variantcontext.VariantContext)7 File (java.io.File)7 ArrayList (java.util.ArrayList)7 SAMFileWriter (htsjdk.samtools.SAMFileWriter)6 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)6 VariantContextWriterBuilder (htsjdk.variant.variantcontext.writer.VariantContextWriterBuilder)6 SAMFileHeader (htsjdk.samtools.SAMFileHeader)5 VCFFileReader (htsjdk.variant.vcf.VCFFileReader)5 VCFHeader (htsjdk.variant.vcf.VCFHeader)5 HashMap (java.util.HashMap)5 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)4 MetricsFile (htsjdk.samtools.metrics.MetricsFile)4 ReferenceSequenceFileWalker (htsjdk.samtools.reference.ReferenceSequenceFileWalker)4 BAMRecordCodec (htsjdk.samtools.BAMRecordCodec)3 SAMReadGroupRecord (htsjdk.samtools.SAMReadGroupRecord)3 SAMRecordQueryNameComparator (htsjdk.samtools.SAMRecordQueryNameComparator)3