use of org.broadinstitute.hellbender.utils.io.Resource in project gatk by broadinstitute.
the class QualityScoreDistribution method finish.
@Override
protected void finish() {
// Built the Histograms out of the long[]s
final Histogram<Byte> qHisto = new Histogram<>("QUALITY", "COUNT_OF_Q");
final Histogram<Byte> oqHisto = new Histogram<>("QUALITY", "COUNT_OF_OQ");
for (int i = 0; i < qCounts.length; ++i) {
if (qCounts[i] > 0)
qHisto.increment((byte) i, (double) qCounts[i]);
if (oqCounts[i] > 0)
oqHisto.increment((byte) i, (double) oqCounts[i]);
}
final MetricsFile<?, Byte> metrics = getMetricsFile();
metrics.addHistogram(qHisto);
if (!oqHisto.isEmpty())
metrics.addHistogram(oqHisto);
metrics.write(OUTPUT);
if (qHisto.isEmpty() && oqHisto.isEmpty()) {
log.warn("No valid bases found in input file. No plot will be produced.");
} else if (PRODUCE_PLOT) {
// Now run R to generate a chart
final RScriptExecutor executor = new RScriptExecutor();
executor.addScript(new Resource(R_SCRIPT, QualityScoreDistribution.class));
executor.addArgs(OUTPUT.getAbsolutePath(), CHART_OUTPUT.getAbsolutePath(), INPUT.getName(), plotSubtitle);
executor.exec();
}
}
use of org.broadinstitute.hellbender.utils.io.Resource in project gatk-protected by broadinstitute.
the class PlotACNVResults method writeSegmentedAlleleFractionPlot.
/**
* @param sampleName Sample name derived from input files
* @param contigNames List containing contig names
* @param contigLengths List containing contig lengths (same order as contigNames)
*/
private void writeSegmentedAlleleFractionPlot(final String sampleName, final List<String> contigNames, final List<Integer> contigLengths) {
//names separated by delimiter
final String contigNamesArg = contigNames.stream().collect(Collectors.joining(CONTIG_DELIMITER));
//lengths separated by delimiter
final String contigLengthsArg = contigLengths.stream().map(Object::toString).collect(Collectors.joining(CONTIG_DELIMITER));
final String outputDirArg = addTrailingSlashIfNecessary(outputDir);
final RScriptExecutor executor = new RScriptExecutor();
//this runs the R statement "source("CNVPlottingLibrary.R")" before the main script runs
executor.addScript(new Resource(CNV_PLOTTING_R_LIBRARY, PlotSegmentedCopyRatio.class));
executor.addScript(new Resource(ACNV_PLOTTING_R_SCRIPT, PlotACNVResults.class));
//--args is needed for Rscript to recognize other arguments properly
executor.addArgs("--args", "--sample_name=" + sampleName, "--snp_counts_file=" + snpCountsFile, "--tangent_file=" + tangentFile, "--segments_file=" + segmentsFile, "--contig_names=" + contigNamesArg, "--contig_lengths=" + contigLengthsArg, "--output_dir=" + outputDirArg, "--output_prefix=" + outputPrefix);
executor.exec();
}
use of org.broadinstitute.hellbender.utils.io.Resource in project gatk-protected by broadinstitute.
the class PlotSegmentedCopyRatio method writeSegmentedCopyRatioPlots.
/**
* @param sampleName Sample name derived from input files
* @param contigNames List containing contig names
* @param contigLengths List containing contig lengths (same order as contigNames)
*/
private void writeSegmentedCopyRatioPlots(final String sampleName, final List<String> contigNames, final List<Integer> contigLengths) {
//names separated by delimiter
final String contigNamesArg = contigNames.stream().collect(Collectors.joining(CONTIG_DELIMITER));
//names separated by delimiter
final String contigLengthsArg = contigLengths.stream().map(Object::toString).collect(Collectors.joining(CONTIG_DELIMITER));
final String outputDirArg = addTrailingSlashIfNecessary(outputDir);
final String isLog2InputArg = isLog2Input ? "TRUE" : "FALSE";
final RScriptExecutor executor = new RScriptExecutor();
//this runs the R statement "source("CNVPlottingLibrary.R")" before the main script runs
executor.addScript(new Resource(CNV_PLOTTING_R_LIBRARY, PlotSegmentedCopyRatio.class));
executor.addScript(new Resource(COPY_RATIO_PLOTTING_R_SCRIPT, PlotSegmentedCopyRatio.class));
//--args is needed for Rscript to recognize other arguments properly
executor.addArgs("--args", "--sample_name=" + sampleName, "--tangent_file=" + tangentFile, "--pre_tangent_file=" + preTangentFile, "--segments_file=" + segmentsFile, "--contig_names=" + contigNamesArg, "--contig_lengths=" + contigLengthsArg, "--output_dir=" + outputDirArg, "--output_prefix=" + outputPrefix, "--is_log2_input=" + isLog2InputArg);
executor.exec();
}
use of org.broadinstitute.hellbender.utils.io.Resource in project gatk by broadinstitute.
the class CollectGcBiasMetrics method finish.
/////////////////////////////////////////////////////////////////////////////
// Synthesize the normalized coverage metrics and write it all out to a file
/////////////////////////////////////////////////////////////////////////////
@Override
protected void finish() {
final MetricsFile<GcBiasDetailMetrics, ?> metricsFile = getMetricsFile();
final double totalWindows = sum(windowsByGc);
final double totalReads = sum(readsByGc);
final double meanReadsPerWindow = totalReads / totalWindows;
final double minimumWindowsToCountInSummary = totalWindows * this.MINIMUM_GENOME_FRACTION;
for (int i = 0; i < windowsByGc.length; ++i) {
if (windowsByGc[i] == 0)
continue;
final GcBiasDetailMetrics m = new GcBiasDetailMetrics();
m.GC = i;
m.WINDOWS = windowsByGc[i];
m.READ_STARTS = readsByGc[i];
if (errorsByGc[i] > 0)
m.MEAN_BASE_QUALITY = QualityUtil.getPhredScoreFromObsAndErrors(basesByGc[i], errorsByGc[i]);
m.NORMALIZED_COVERAGE = (m.READ_STARTS / (double) m.WINDOWS) / meanReadsPerWindow;
m.ERROR_BAR_WIDTH = (Math.sqrt(m.READ_STARTS) / (double) m.WINDOWS) / meanReadsPerWindow;
metricsFile.addMetric(m);
}
metricsFile.write(OUTPUT);
// Synthesize the high level metrics
if (SUMMARY_OUTPUT != null) {
final MetricsFile<GcBiasSummaryMetrics, ?> summaryMetricsFile = getMetricsFile();
final GcBiasSummaryMetrics summary = new GcBiasSummaryMetrics();
summary.WINDOW_SIZE = this.WINDOW_SIZE;
summary.TOTAL_CLUSTERS = this.totalClusters;
summary.ALIGNED_READS = this.totalAlignedReads;
calculateDropoutMetrics(metricsFile.getMetrics(), summary);
summaryMetricsFile.addMetric(summary);
summaryMetricsFile.write(SUMMARY_OUTPUT);
}
// Plot the results
final NumberFormat fmt = NumberFormat.getIntegerInstance();
fmt.setGroupingUsed(true);
final String subtitle = "Total clusters: " + fmt.format(this.totalClusters) + ", Aligned reads: " + fmt.format(this.totalAlignedReads);
String title = INPUT.getName().replace(".duplicates_marked", "").replace(".aligned.bam", "");
title += "." + saveHeader;
if (PRODUCE_PLOT) {
final RScriptExecutor executor = new RScriptExecutor();
executor.addScript(new Resource(R_SCRIPT, CollectGcBiasMetrics.class));
executor.addArgs(OUTPUT.getAbsolutePath(), CHART_OUTPUT.getAbsolutePath(), title, subtitle, String.valueOf(WINDOW_SIZE));
executor.exec();
}
}
use of org.broadinstitute.hellbender.utils.io.Resource in project gatk by broadinstitute.
the class CollectBaseDistributionByCycle method finish.
@Override
protected void finish() {
final MetricsFile<BaseDistributionByCycleMetrics, ?> metrics = getMetricsFile();
hist.addToMetricsFile(metrics);
metrics.write(OUTPUT);
if (hist.isEmpty()) {
log.warn("No valid bases found in input file. No plot will be produced.");
} else if (PRODUCE_PLOT) {
final RScriptExecutor executor = new RScriptExecutor();
executor.addScript(new Resource(R_SCRIPT, CollectBaseDistributionByCycle.class));
executor.addArgs(OUTPUT.getAbsolutePath(), CHART_OUTPUT.getAbsolutePath(), INPUT.getName(), plotSubtitle);
executor.exec();
}
}
Aggregations