Search in sources :

Example 1 with GATKReport

use of org.broadinstitute.hellbender.utils.report.GATKReport in project gatk by broadinstitute.

the class RecalUtils method createRecalibrationGATKReport.

/**
     * Creates a consolidated GATK report from the tables. Report can then be written to a stream via GATKReport.print(PrintStream).
     *
     * @param argumentTable Argument table
     * @param quantizationTable Quantization Table
     * @param recalTables Other recal tables
     * @return GATK report
     */
public static GATKReport createRecalibrationGATKReport(final GATKReportTable argumentTable, final GATKReportTable quantizationTable, final List<GATKReportTable> recalTables) {
    final GATKReport report = new GATKReport();
    report.addTable(argumentTable);
    report.addTable(quantizationTable);
    report.addTables(recalTables);
    return report;
}
Also used : GATKReport(org.broadinstitute.hellbender.utils.report.GATKReport)

Example 2 with GATKReport

use of org.broadinstitute.hellbender.utils.report.GATKReport in project gatk by broadinstitute.

the class RecalUtils method outputRecalibrationReport.

/**
     * Outputs the GATK report to RAC.RECAL_TABLE.
     *
     * @param RAC The list of shared command line arguments
     * @param quantizationInfo Quantization info
     * @param recalibrationTables Recalibration tables
     * @param covariates The list of requested covariates
     */
public static void outputRecalibrationReport(final PrintStream recalTableStream, final RecalibrationArgumentCollection RAC, final QuantizationInfo quantizationInfo, final RecalibrationTables recalibrationTables, final StandardCovariateList covariates) {
    final GATKReport report = createRecalibrationGATKReport(RAC.generateReportTable(covariates.covariateNames()), quantizationInfo.generateReportTable(), generateReportTables(recalibrationTables, covariates));
    report.print(recalTableStream);
}
Also used : GATKReport(org.broadinstitute.hellbender.utils.report.GATKReport)

Example 3 with GATKReport

use of org.broadinstitute.hellbender.utils.report.GATKReport in project gatk by broadinstitute.

the class VariantRecalibratorModelOutputUnitTest method testVQSRModelOutput.

@Test
public void testVQSRModelOutput() {
    final int numAnnotations = 6;
    final double shrinkage = 1.0;
    final double dirichlet = 0.001;
    final double priorCounts = 20.0;
    final double epsilon = 1e-6;
    Random rand = new Random(12878);
    MultivariateGaussian goodGaussian1 = new MultivariateGaussian(1, numAnnotations);
    goodGaussian1.initializeRandomMu(rand);
    goodGaussian1.initializeRandomSigma(rand);
    MultivariateGaussian goodGaussian2 = new MultivariateGaussian(1, numAnnotations);
    goodGaussian2.initializeRandomMu(rand);
    goodGaussian2.initializeRandomSigma(rand);
    MultivariateGaussian badGaussian1 = new MultivariateGaussian(1, numAnnotations);
    badGaussian1.initializeRandomMu(rand);
    badGaussian1.initializeRandomSigma(rand);
    List<MultivariateGaussian> goodGaussianList = new ArrayList<>();
    goodGaussianList.add(goodGaussian1);
    goodGaussianList.add(goodGaussian2);
    List<MultivariateGaussian> badGaussianList = new ArrayList<>();
    badGaussianList.add(badGaussian1);
    GaussianMixtureModel goodModel = new GaussianMixtureModel(goodGaussianList, shrinkage, dirichlet, priorCounts);
    GaussianMixtureModel badModel = new GaussianMixtureModel(badGaussianList, shrinkage, dirichlet, priorCounts);
    if (printTables) {
        logger.info("Good model mean matrix:");
        logger.info(vectorToString(goodGaussian1.mu));
        logger.info(vectorToString(goodGaussian2.mu));
        logger.info("\n\n");
        logger.info("Good model covariance matrices:");
        goodGaussian1.sigma.print(10, 3);
        goodGaussian2.sigma.print(10, 3);
        logger.info("\n\n");
        logger.info("Bad model mean matrix:\n");
        logger.info(vectorToString(badGaussian1.mu));
        logger.info("\n\n");
        logger.info("Bad model covariance matrix:");
        badGaussian1.sigma.print(10, 3);
    }
    VariantRecalibrator vqsr = new VariantRecalibrator();
    List<String> annotationList = new ArrayList<>();
    annotationList.add("QD");
    annotationList.add("MQ");
    annotationList.add("FS");
    annotationList.add("SOR");
    annotationList.add("ReadPosRankSum");
    annotationList.add("MQRankSum");
    GATKReport report = vqsr.writeModelReport(goodModel, badModel, annotationList);
    if (printTables)
        report.print(System.out);
    //Check values for Gaussian means
    GATKReportTable goodMus = report.getTable("PositiveModelMeans");
    for (int i = 0; i < annotationList.size(); i++) {
        Assert.assertEquals(goodGaussian1.mu[i], (Double) goodMus.get(0, annotationList.get(i)), epsilon);
    }
    for (int i = 0; i < annotationList.size(); i++) {
        Assert.assertEquals(goodGaussian2.mu[i], (Double) goodMus.get(1, annotationList.get(i)), epsilon);
    }
    GATKReportTable badMus = report.getTable("NegativeModelMeans");
    for (int i = 0; i < annotationList.size(); i++) {
        Assert.assertEquals(badGaussian1.mu[i], (Double) badMus.get(0, annotationList.get(i)), epsilon);
    }
    //Check values for Gaussian covariances
    GATKReportTable goodSigma = report.getTable("PositiveModelCovariances");
    for (int i = 0; i < annotationList.size(); i++) {
        for (int j = 0; j < annotationList.size(); j++) {
            Assert.assertEquals(goodGaussian1.sigma.get(i, j), (Double) goodSigma.get(i, annotationList.get(j)), epsilon);
        }
    }
    //add annotationList.size() to row indexes for second Gaussian because the matrices are concatenated by row in the report
    for (int i = 0; i < annotationList.size(); i++) {
        for (int j = 0; j < annotationList.size(); j++) {
            Assert.assertEquals(goodGaussian2.sigma.get(i, j), (Double) goodSigma.get(annotationList.size() + i, annotationList.get(j)), epsilon);
        }
    }
    GATKReportTable badSigma = report.getTable("NegativeModelCovariances");
    for (int i = 0; i < annotationList.size(); i++) {
        for (int j = 0; j < annotationList.size(); j++) {
            Assert.assertEquals(badGaussian1.sigma.get(i, j), (Double) badSigma.get(i, annotationList.get(j)), epsilon);
        }
    }
}
Also used : GATKReport(org.broadinstitute.hellbender.utils.report.GATKReport) Random(java.util.Random) ArrayList(java.util.ArrayList) GATKReportTable(org.broadinstitute.hellbender.utils.report.GATKReportTable) Test(org.testng.annotations.Test)

Example 4 with GATKReport

use of org.broadinstitute.hellbender.utils.report.GATKReport in project gatk by broadinstitute.

the class VariantRecalibratorModelOutputUnitTest method testAnnotationNormalizationOutput.

@Test
public //This is tested separately to avoid setting up a VariantDataManager and populating it with fake data
void testAnnotationNormalizationOutput() {
    final VariantRecalibrator vqsr = new VariantRecalibrator();
    final List<String> annotationList = new ArrayList<>();
    annotationList.add("QD");
    annotationList.add("FS");
    annotationList.add("ReadPosRankSum");
    annotationList.add("MQ");
    annotationList.add("MQRankSum");
    annotationList.add("SOR");
    final double epsilon = 1e-6;
    double[] meanVector = { 16.13, 2.45, 0.37, 59.08, 0.14, 0.91 };
    final String columnName = "Mean";
    final String formatString = "%.3f";
    GATKReportTable vectorTable = vqsr.makeVectorTable("AnnotationMeans", "Mean for each annotation, used to normalize data", annotationList, meanVector, columnName, formatString);
    for (int i = 0; i < annotationList.size(); i++) {
        Assert.assertEquals(meanVector[i], (Double) vectorTable.get(i, columnName), epsilon);
    }
    if (printTables) {
        final GATKReport report = new GATKReport();
        report.addTable(vectorTable);
        report.print(System.out);
    }
}
Also used : GATKReport(org.broadinstitute.hellbender.utils.report.GATKReport) ArrayList(java.util.ArrayList) GATKReportTable(org.broadinstitute.hellbender.utils.report.GATKReportTable) Test(org.testng.annotations.Test)

Example 5 with GATKReport

use of org.broadinstitute.hellbender.utils.report.GATKReport in project gatk by broadinstitute.

the class VariantRecalibrator method writeModelReport.

protected GATKReport writeModelReport(final GaussianMixtureModel goodModel, final GaussianMixtureModel badModel, List<String> annotationList) {
    final String formatString = "%.3f";
    final GATKReport report = new GATKReport();
    if (dataManager != null) {
        //for unit test
        final double[] meanVector = dataManager.getMeanVector();
        GATKReportTable annotationMeans = makeVectorTable("AnnotationMeans", "Mean for each annotation, used to normalize data", dataManager.annotationKeys, meanVector, "Mean", formatString);
        report.addTable(annotationMeans);
        //"varianceVector" is actually stdev
        final double[] varianceVector = dataManager.getVarianceVector();
        GATKReportTable annotationVariances = makeVectorTable("AnnotationStdevs", "Standard deviation for each annotation, used to normalize data", dataManager.annotationKeys, varianceVector, "Standard deviation", formatString);
        report.addTable(annotationVariances);
    }
    //The model and Gaussians don't know what the annotations are, so get them from this class
    //VariantDataManager keeps the annotation in the same order as the argument list
    GATKReportTable positiveMeans = makeMeansTable("PositiveModelMeans", "Vector of annotation values to describe the (normalized) mean for each Gaussian in the positive model", annotationList, goodModel, formatString);
    report.addTable(positiveMeans);
    GATKReportTable positiveCovariance = makeCovariancesTable("PositiveModelCovariances", "Matrix to describe the (normalized) covariance for each Gaussian in the positive model; covariance matrices are joined by row", annotationList, goodModel, formatString);
    report.addTable(positiveCovariance);
    //do the same for the negative model means
    GATKReportTable negativeMeans = makeMeansTable("NegativeModelMeans", "Vector of annotation values to describe the (normalized) mean for each Gaussian in the negative model", annotationList, badModel, formatString);
    report.addTable(negativeMeans);
    GATKReportTable negativeCovariance = makeCovariancesTable("NegativeModelCovariances", "Matrix to describe the (normalized) covariance for each Gaussian in the negative model; covariance matrices are joined by row", annotationList, badModel, formatString);
    report.addTable(negativeCovariance);
    return report;
}
Also used : GATKReport(org.broadinstitute.hellbender.utils.report.GATKReport) GATKReportTable(org.broadinstitute.hellbender.utils.report.GATKReportTable)

Aggregations

GATKReport (org.broadinstitute.hellbender.utils.report.GATKReport)10 File (java.io.File)4 GATKReportTable (org.broadinstitute.hellbender.utils.report.GATKReportTable)4 FileNotFoundException (java.io.FileNotFoundException)3 PrintStream (java.io.PrintStream)3 ArrayList (java.util.ArrayList)3 UserException (org.broadinstitute.hellbender.exceptions.UserException)3 Test (org.testng.annotations.Test)3 InputStream (java.io.InputStream)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 LogManager (org.apache.log4j.LogManager)1