htsjdk.samtools.metrics.Header Java Examples

The following examples show how to use htsjdk.samtools.metrics.Header. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CollectMultipleMetricsSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public MetricsCollectorSpark<? extends MetricsArgumentCollection> createCollector(
        final String outputBaseName,
        final Set<MetricAccumulationLevel> metricAccumulationLevel,
        final List<Header> defaultHeaders,
        final SAMFileHeader samHeader)
{
    // disambiguate this collector's output files from the other collectors
    final String localBaseName = outputBaseName + "." + QualityYieldMetrics.getUniqueNameSuffix();

    final QualityYieldMetricsArgumentCollection qyArgs = new QualityYieldMetricsArgumentCollection();
    qyArgs.output = localBaseName + ".txt";

    final QualityYieldMetricsCollectorSpark collector = new QualityYieldMetricsCollectorSpark();
    collector.initialize(qyArgs, samHeader, defaultHeaders);

    return collector;
}
 
Example #2
Source File: CollectMultipleMetricsSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public MetricsCollectorSpark<? extends MetricsArgumentCollection> createCollector(
        final String outputBaseName,
        final Set<MetricAccumulationLevel> metricAccumulationLevel,
        final List<Header> defaultHeaders,
        final SAMFileHeader samHeader)
{
    // disambiguate this collector's output files from the other collectors
    final String localBaseName = outputBaseName + "." + InsertSizeMetrics.getUniqueNameSuffix();

    final InsertSizeMetricsArgumentCollection isArgs = new InsertSizeMetricsArgumentCollection();
    isArgs.output = localBaseName + ".txt";
    isArgs.histogramPlotFile = localBaseName + ".pdf";
    isArgs.metricAccumulationLevel.accumulationLevels = metricAccumulationLevel;

    final InsertSizeMetricsCollectorSpark collector = new InsertSizeMetricsCollectorSpark();
    collector.initialize(isArgs, samHeader, defaultHeaders);

    return collector;
}
 
Example #3
Source File: CollectMultipleMetricsSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * For each collector type, provide a type-safe, collector-specific method
 * that creates and populates an instance of the  collector's input argument
 * class; creates an instance of the collector; initializes the collector
 * with the arguments, and returns the initialized collector.
 */
MetricsCollectorSpark<? extends MetricsArgumentCollection> createCollector(
        final String outputBaseName,
        final Set<MetricAccumulationLevel> metricAccumulationLevel,
        final List<Header> defaultHeaders,
        final SAMFileHeader samHeader
);
 
Example #4
Source File: CollectMultipleMetricsSparkIntegrationTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(dataProvider="metricsTestFiles", groups = "spark")
public void testCustomCollectorAPI(
    final String fileName,
    final String referenceName,
    final String expectedInsertSizeResults,
    final String expectedQualityYieldResults) throws IOException
{
    // Test CollectMultipleMetricsSpark with a custom collector
    final TestCustomCollector testCollector = new TestCustomCollector();

    ArgumentsBuilder args = new ArgumentsBuilder();
    setupMultipleCollector(args, fileName, referenceName);

    // CollectMultipleMetricsSpark provider that creates an initializes a custom
    // collector
    CollectMultipleMetricsSpark.SparkCollectorProvider customProvider =
        new CollectMultipleMetricsSpark.SparkCollectorProvider() {
            @Override
            public MetricsCollectorSpark<? extends MetricsArgumentCollection> createCollector(
                final String outputBaseName,
                final Set<MetricAccumulationLevel> metricAccumulationLevel,
                final List<Header> defaultHeaders,
                final SAMFileHeader samHeader)
            {
                return testCollector;
            }
    };

    // Manually create a tool and programmatically set the custome collector as the one
    // to run
    CollectMultipleMetricsSpark multipleCollectorTool = new CollectMultipleMetricsSpark();
    multipleCollectorTool.setCollectorsToRun(Collections.singletonList(customProvider));
    multipleCollectorTool.instanceMain(args.getArgsArray());

    Assert.assertEquals(testCollector.count, 52L);
}
 
Example #5
Source File: CommandLineProgram.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Gets a MetricsFile with default headers already written into it. */
protected <A extends MetricBase,B extends Comparable<?>> MetricsFile<A,B> getMetricsFile() {
    final MetricsFile<A,B> file = new MetricsFile<>();
    for (final Header h : this.defaultHeaders) {
        file.addHeader(h);
    }

    return file;
}
 
Example #6
Source File: InsertSizeMetricsCollectorSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize the collector with input arguments;
 */
@Override
public void initialize(
        final InsertSizeMetricsArgumentCollection inputArgs,
        final SAMFileHeader samHeader,
        final List<Header> defaultHeaders)
{
    this.inputArgs = inputArgs;
    collector.initialize(inputArgs, samHeader);
    metricsFile = new MetricsFile<>();
    if (defaultHeaders != null) {
        defaultHeaders.stream().forEach(h -> metricsFile.addHeader(h));
    }
}
 
Example #7
Source File: QualityYieldMetricsCollectorSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize the collector with input arguments;
 */
@Override
public void initialize(
        final QualityYieldMetricsArgumentCollection inputArgs,
        final SAMFileHeader samHeader,
        final List<Header> defaultHeaders) {
    metricsFile = new MetricsFile<QualityYieldMetrics, Integer>();
    defaultHeaders.stream().forEach(h -> metricsFile.addHeader(h));
    this.args = inputArgs;
}
 
Example #8
Source File: CollectInsertSizeMetricsSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initialize(
        final InsertSizeMetricsArgumentCollection inputArgs,
        final SAMFileHeader samHeader,
        final List<Header> defaultHeaders)
{
    insertSizeCollector.initialize(inputArgs, samHeader, defaultHeaders);
}
 
Example #9
Source File: MetricsUtils.java    From Drop-seq with MIT License 5 votes vote down vote up
public static Header getMergedMetricsHeader(List<File> inputMetricsList, File outputMetrics) {
    List<String> header = new ArrayList<>();
    for (File file : inputMetricsList)
        header.add("INPUT="+ file.getAbsolutePath());
    header.add("OUTPUT="+ outputMetrics.getAbsolutePath());

    return new StringHeader(StringUtils.join(header, "\t"));
}
 
Example #10
Source File: CollectQualityYieldMetricsSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void initialize(
        final QualityYieldMetricsArgumentCollection inputArgs,
        final SAMFileHeader samHeader,
        final List<Header> defaultHeaders) {
    qualityYieldCollector.initialize(inputArgs, samHeader, defaultHeaders);
}
 
Example #11
Source File: ExampleMultiMetricsCollectorSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize the collector with input arguments.
 */
@Override
public void initialize(
        final ExampleMultiMetricsArgumentCollection inputArgs,
        final SAMFileHeader samHeader,
        final List<Header> defaultHeaders)
{
    this.inputArgs = inputArgs;
    collector.initialize(inputArgs, samHeader);
    metricsFile = new MetricsFile<>();
    if (defaultHeaders != null) {
        defaultHeaders.stream().forEach(h -> metricsFile.addHeader(h));
    }
}
 
Example #12
Source File: ExampleCollectSingleMetricsSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize the collector with it's input arguments.
 *
 * @param inputArgs The input arguments for this collector. The {@link MetricsCollectorSparkTool} base class
 *                  will have previously obtained these through a call to {@link #getInputArguments},
 *                  and passes them back here to be forwarded to the embedded collector.
 * @param samHeader SAMFileHeader for the input
 * @param defaultHeaders Default headers for this tool to optionally be used in any resulting metrics file.
 */
@Override
protected void initialize(
        final ExampleSingleMetricsArgumentCollection inputArgs,
        final SAMFileHeader samHeader,
        final List<Header> defaultHeaders)
{
    // Initialize the collector with it's input arguments
    exampleSingleCollector.initialize(inputArgs, samHeader, defaultHeaders);
}
 
Example #13
Source File: ExampleSingleMetricsCollectorSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Initialize the collector with input arguments;
 */
@Override
public void initialize(
        final ExampleSingleMetricsArgumentCollection inputArgs,
        final SAMFileHeader samHeader,
        final List<Header> defaultHeaders) {
    metricsFile = new MetricsFile<ExampleSingleMetrics, Integer>();
    defaultHeaders.stream().forEach(h -> metricsFile.addHeader(h));
    this.args = inputArgs;
}
 
Example #14
Source File: CommandLineProgram.java    From picard with MIT License 5 votes vote down vote up
/** Gets a MetricsFile with default headers already written into it. */
protected <A extends MetricBase,B extends Comparable<?>> MetricsFile<A,B> getMetricsFile() {
    final MetricsFile<A,B> file = new MetricsFile<>();
    for (final Header h : this.defaultHeaders) {
        file.addHeader(h);
    }

    return file;
}
 
Example #15
Source File: SamComparison.java    From picard with MIT License 5 votes vote down vote up
public void writeReport(final File output, final List<Header> headers) {
    final MetricsFile<SamComparisonMetric, ?> comparisonMetricFile = new MetricsFile<>();

    headers.forEach(comparisonMetricFile::addHeader);
    comparisonMetricFile.addAllMetrics(Collections.singletonList(comparisonMetric));
    comparisonMetricFile.write(output);
}
 
Example #16
Source File: CommandLineProgram.java    From picard with MIT License 4 votes vote down vote up
public List<Header> getDefaultHeaders() {
    return this.defaultHeaders;
}
 
Example #17
Source File: CommandLineProgram.java    From picard with MIT License 4 votes vote down vote up
public void setDefaultHeaders(final List<Header> headers) {
    this.defaultHeaders.clear();
    this.defaultHeaders.addAll(headers);
}
 
Example #18
Source File: CommandLineProgram.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Replaces the set of default metrics headers by the given argument.
 * The given list is copied.
 */
public final void setDefaultHeaders(final List<Header> headers) {
    Utils.nonNull(headers);
    this.defaultHeaders.clear();
    this.defaultHeaders.addAll(headers);
}
 
Example #19
Source File: CommandLineProgram.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Returns the (live) list of default metrics headers used by this tool.
 */
public final List<Header> getDefaultHeaders() {
    return this.defaultHeaders;
}
 
Example #20
Source File: CollectMultipleMetricsSparkIntegrationTest.java    From gatk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void initialize(
        MetricsArgumentCollection inputArgs, SAMFileHeader samHeader, List<Header> defaultHeaders) {}
 
Example #21
Source File: ExampleCollectMultiMetricsSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Initialize the collector with it's input arguments.
 *
 * @param inputArgs The input arguments for this collector. The {@link MetricsCollectorSparkTool} base class
 *                  will have previously obtained these through a call to {@link #getInputArguments},
 *                  and passes them back here to be forwarded to the embedded collector.
 * @param samHeader SAMFileHeader for the input
 * @param defaultHeaders Default headers for this tool to optionally be used in any resulting metrics file.
 */
@Override
protected void initialize(
        final ExampleMultiMetricsArgumentCollection inputArgs,
        final SAMFileHeader samHeader,
        final List<Header> defaultHeaders)
{
    exampleMultiCollector.initialize(inputArgs, samHeader, defaultHeaders);
}
 
Example #22
Source File: MetricsCollectorSpark.java    From gatk with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Give the collector's input arguments to the collector (if the collector
 * is being driven by a standalone tool. This method will always be called
 * before either getReadFilter (so the collector can use the arguments to
 * initialize the readFilter) or collectMetrics.
 * @param inputArgs an object that contains the argument values to be used for
 *                  the collector
 * @param samHeader the SAMFileHeader for the input
 * @param defaultMetricsHeaders default metrics headers from the containing tool
 */
void initialize(T inputArgs, SAMFileHeader samHeader, List<Header> defaultMetricsHeaders);
 
Example #23
Source File: MetricsCollectorSparkTool.java    From gatk with BSD 3-Clause "New" or "Revised" License votes vote down vote up
abstract protected void initialize(T inputArgs, SAMFileHeader samHeader, List<Header> defaultHeaders);