Search in sources :

Example 1 with Covariate

use of org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate in project gatk by broadinstitute.

the class RecalUtils method generateReportTables.

public static List<GATKReportTable> generateReportTables(final RecalibrationTables recalibrationTables, final StandardCovariateList covariates) {
    final List<GATKReportTable> result = new LinkedList<>();
    int rowIndex = 0;
    GATKReportTable allCovsReportTable = null;
    for (NestedIntegerArray<RecalDatum> table : recalibrationTables) {
        // initialize the array to hold the column names
        final ArrayList<Pair<String, String>> columnNames = new ArrayList<>();
        // save the required covariate name so we can reference it in the future
        columnNames.add(new MutablePair<>(covariates.getReadGroupCovariate().parseNameForReport(), "%s"));
        if (!recalibrationTables.isReadGroupTable(table)) {
            // save the required covariate name so we can reference it in the future
            columnNames.add(new MutablePair<>(covariates.getQualityScoreCovariate().parseNameForReport(), "%d"));
            if (recalibrationTables.isAdditionalCovariateTable(table)) {
                columnNames.add(covariateValue);
                columnNames.add(covariateName);
            }
        }
        // the order of these column names is important here
        columnNames.add(eventType);
        columnNames.add(empiricalQuality);
        if (recalibrationTables.isReadGroupTable(table)) {
            // only the read group table needs the estimated Q reported
            columnNames.add(estimatedQReported);
        }
        columnNames.add(nObservations);
        columnNames.add(nErrors);
        final String reportTableName = getReportTableName(recalibrationTables, table);
        final GATKReportTable.Sorting sort = GATKReportTable.Sorting.SORT_BY_COLUMN;
        final GATKReportTable reportTable;
        final boolean addToList;
        //XXX this "if" implicitly uses the knowledge about the ordering of tables.
        if (!recalibrationTables.isAdditionalCovariateTable(table)) {
            reportTable = makeNewTableWithColumns(columnNames, reportTableName, sort);
            // reset the row index since we're starting with a new table
            rowIndex = 0;
            addToList = true;
        } else if (allCovsReportTable == null && recalibrationTables.isAdditionalCovariateTable(table)) {
            reportTable = makeNewTableWithColumns(columnNames, reportTableName, sort);
            // reset the row index since we're starting with a new table
            rowIndex = 0;
            allCovsReportTable = reportTable;
            addToList = true;
        } else {
            reportTable = allCovsReportTable;
            addToList = false;
        }
        for (final NestedIntegerArray.Leaf<RecalDatum> row : table.getAllLeaves()) {
            final RecalDatum datum = row.value;
            final int[] keys = row.keys;
            int columnIndex = 0;
            int keyIndex = 0;
            reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariates.getReadGroupCovariate().formatKey(keys[keyIndex++]));
            if (!recalibrationTables.isReadGroupTable(table)) {
                reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariates.getQualityScoreCovariate().formatKey(keys[keyIndex++]));
                if (recalibrationTables.isAdditionalCovariateTable(table)) {
                    final Covariate covariate = recalibrationTables.getCovariateForTable(table);
                    reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariate.formatKey(keys[keyIndex++]));
                    reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariate.parseNameForReport());
                }
            }
            final EventType event = EventType.eventFrom(keys[keyIndex]);
            reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), event.toString());
            reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getEmpiricalQuality());
            if (recalibrationTables.isReadGroupTable(table)) {
                // we only add the estimated Q reported in the RG table
                reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getEstimatedQReported());
            }
            reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getNumObservations());
            reportTable.set(rowIndex, columnNames.get(columnIndex).getLeft(), datum.getNumMismatches());
            rowIndex++;
        }
        if (addToList) {
            //XXX using a set would be slow because the equals method on GATKReportTable is expensive.
            result.add(reportTable);
        }
    }
    return result;
}
Also used : Covariate(org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate) GATKReportTable(org.broadinstitute.hellbender.utils.report.GATKReportTable) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) NestedIntegerArray(org.broadinstitute.hellbender.utils.collections.NestedIntegerArray)

Example 2 with Covariate

use of org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate in project gatk by broadinstitute.

the class RecalUtils method generateValuesFromKeys.

static List<Object> generateValuesFromKeys(final int[] keys, final StandardCovariateList covariates) {
    final List<Object> values = new ArrayList<>(4);
    values.add(covariates.getReadGroupCovariate().formatKey(keys[0]));
    final int covariateIndex = keys[1];
    final int covariateKey = keys[2];
    final Covariate covariate = (covariateIndex == covariates.size()) ? covariates.getQualityScoreCovariate() : covariates.get(covariateIndex);
    values.add(covariate.formatKey(covariateKey));
    values.add(covariate.parseNameForReport());
    values.add(EventType.eventFrom(keys[3]).prettyPrint());
    return values;
}
Also used : Covariate(org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate)

Example 3 with Covariate

use of org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate in project gatk by broadinstitute.

the class RecalibrationTablesUnitTest method basicTest.

@Test
public void basicTest() {
    final Covariate qualCov = covariates.getQualityScoreCovariate();
    Assert.assertEquals(tables.numTables(), covariates.size());
    Assert.assertNotNull(tables.getReadGroupTable());
    Assert.assertEquals(tables.getReadGroupTable(), tables.getReadGroupTable());
    testDimensions(tables.getReadGroupTable(), numReadGroups);
    Assert.assertNotNull(tables.getQualityScoreTable());
    Assert.assertEquals(tables.getQualityScoreTable(), tables.getQualityScoreTable());
    testDimensions(tables.getQualityScoreTable(), numReadGroups, qualCov.maximumKeyValue() + 1);
    for (NestedIntegerArray<RecalDatum> table : tables.getAdditionalTables()) {
        Assert.assertNotNull(table);
        Covariate cov = tables.getCovariateForTable(table);
        testDimensions(table, numReadGroups, qualCov.maximumKeyValue() + 1, cov.maximumKeyValue() + 1);
    }
}
Also used : Covariate(org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 4 with Covariate

use of org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate in project gatk by broadinstitute.

the class RecalibrationTablesUnitTest method basicMakeQualityScoreTable.

@Test
public void basicMakeQualityScoreTable() {
    final Covariate qualCov = covariates.getQualityScoreCovariate();
    final NestedIntegerArray<RecalDatum> copy = tables.makeQualityScoreTable();
    testDimensions(copy, numReadGroups, qualCov.maximumKeyValue() + 1);
    Assert.assertEquals(copy.getAllValues().size(), 0);
}
Also used : Covariate(org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 5 with Covariate

use of org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate in project gatk by broadinstitute.

the class RecalibrationReport method parseAllCovariatesTable.

/**
     * Compiles the list of keys for the Covariates table and uses the shared parsing utility to produce the actual table
     *
     * @param reportTable            the GATKReport table containing data for this table
     * @param recalibrationTables    the recalibration tables
     */
private void parseAllCovariatesTable(final GATKReportTable reportTable, final RecalibrationTables recalibrationTables) {
    final int[] tempCOVarray = new int[4];
    for (int i = 0; i < reportTable.getNumRows(); i++) {
        final Object rg = reportTable.get(i, RecalUtils.READGROUP_COLUMN_NAME);
        tempCOVarray[0] = covariates.getReadGroupCovariate().keyFromValue(rg);
        final Object qual = reportTable.get(i, RecalUtils.QUALITY_SCORE_COLUMN_NAME);
        tempCOVarray[1] = covariates.getQualityScoreCovariate().keyFromValue(qual);
        final String covName = (String) reportTable.get(i, RecalUtils.COVARIATE_NAME_COLUMN_NAME);
        final Object covValue = reportTable.get(i, RecalUtils.COVARIATE_VALUE_COLUMN_NAME);
        final Covariate cov = covariates.getCovariateByParsedName(covName);
        tempCOVarray[2] = cov.keyFromValue(covValue);
        final EventType event = EventType.eventFrom((String) reportTable.get(i, RecalUtils.EVENT_TYPE_COLUMN_NAME));
        tempCOVarray[3] = event.ordinal();
        recalibrationTables.getTableForCovariate(cov).put(getRecalDatum(reportTable, i, false), tempCOVarray);
    }
}
Also used : Covariate(org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate)

Aggregations

Covariate (org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)2 Test (org.testng.annotations.Test)2 MutablePair (org.apache.commons.lang3.tuple.MutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1 NestedIntegerArray (org.broadinstitute.hellbender.utils.collections.NestedIntegerArray)1 GATKReportTable (org.broadinstitute.hellbender.utils.report.GATKReportTable)1