Search in sources :

Example 1 with CategoryTableXYDataset

use of org.jfree.data.xy.CategoryTableXYDataset in project hmftools by hartwigmedical.

the class CopyNumberCharts method somaticPloidyPDF.

@NotNull
static JFreeChart somaticPloidyPDF(@NotNull final List<PurityAdjustedSomaticVariant> variants) {
    final CategoryTableXYDataset dataset = variants(variants);
    final JFreeChart chart = ChartFactory.createXYBarChart("Somatic Variant Ploidy PDF", "Ploidy", false, "Count", dataset, PlotOrientation.VERTICAL, true, false, false);
    StackedXYBarRenderer renderer = new StackedXYBarRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setRenderer(renderer);
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        renderer.setSeriesPaint(i, copyNumberColor(String.valueOf(dataset.getSeriesKey(i))));
    }
    return chart;
}
Also used : CategoryTableXYDataset(org.jfree.data.xy.CategoryTableXYDataset) XYPlot(org.jfree.chart.plot.XYPlot) StackedXYBarRenderer(org.jfree.chart.renderer.xy.StackedXYBarRenderer) StandardXYBarPainter(org.jfree.chart.renderer.xy.StandardXYBarPainter) JFreeChart(org.jfree.chart.JFreeChart) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CategoryTableXYDataset

use of org.jfree.data.xy.CategoryTableXYDataset in project hmftools by hartwigmedical.

the class CopyNumberCharts method minorAllele.

@VisibleForTesting
@NotNull
static CategoryTableXYDataset minorAllele(@NotNull final List<PurpleCopyNumber> copyNumbers) {
    int positivePloidy = 5;
    int positiveBuckets = positivePloidy * 10;
    int negativePloidy = 1;
    int negativeBuckets = negativePloidy * 10;
    int totalBuckets = negativeBuckets + positiveBuckets;
    double[][] buckets = new double[MAX_COPY_NUMBER_SERIES + 1][totalBuckets + 1];
    for (final PurpleCopyNumber copyNumber : copyNumbers) {
        double unboundMinorAllele = (1 - copyNumber.averageActualBAF()) * copyNumber.averageTumorCopyNumber();
        int series = limit(copyNumber.averageTumorCopyNumber(), 0, MAX_COPY_NUMBER_SERIES);
        int column = limit(unboundMinorAllele / 0.1, -negativeBuckets, positiveBuckets) + negativeBuckets;
        buckets[series][column] += copyNumber.bafCount();
    }
    CategoryTableXYDataset result = new CategoryTableXYDataset();
    for (int i = 0; i <= MAX_COPY_NUMBER_SERIES; i++) {
        String seriesName = "CN" + i + (i == MAX_COPY_NUMBER_SERIES ? "+" : "");
        for (int j = 0; j <= totalBuckets; j++) {
            if (!Doubles.isZero(buckets[i][j])) {
                result.add(-1 + (j * 0.1), buckets[i][j], seriesName);
            }
        }
    }
    return result;
}
Also used : CategoryTableXYDataset(org.jfree.data.xy.CategoryTableXYDataset) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CategoryTableXYDataset

use of org.jfree.data.xy.CategoryTableXYDataset in project hmftools by hartwigmedical.

the class CopyNumberCharts method variants.

@NotNull
private static CategoryTableXYDataset variants(@NotNull final List<PurityAdjustedSomaticVariant> variants) {
    int maxPloidy = 6;
    int maxBuckets = maxPloidy * 10;
    double[][] buckets = new double[MAX_COPY_NUMBER_SERIES + 1][maxBuckets];
    for (final PurityAdjustedSomaticVariant variant : variants) {
        double value = variant.adjustedVAF() * variant.adjustedCopyNumber();
        int series = (int) Math.max(0, Math.min(MAX_COPY_NUMBER_SERIES, Math.round(variant.adjustedCopyNumber())));
        int column = Math.min(maxBuckets - 1, Math.max(0, (int) Math.round(value / 0.1)));
        buckets[series][column] += 1;
    }
    CategoryTableXYDataset result = new CategoryTableXYDataset();
    for (int i = 0; i <= MAX_COPY_NUMBER_SERIES; i++) {
        String seriesName = "CN" + i + (i == MAX_COPY_NUMBER_SERIES ? "+" : "");
        for (int j = 0; j < maxBuckets; j++) {
            if (!Doubles.isZero(buckets[i][j])) {
                result.add(j * 0.1, buckets[i][j], seriesName);
            }
        }
    }
    return result;
}
Also used : CategoryTableXYDataset(org.jfree.data.xy.CategoryTableXYDataset) PurityAdjustedSomaticVariant(com.hartwig.hmftools.common.variant.PurityAdjustedSomaticVariant) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CategoryTableXYDataset

use of org.jfree.data.xy.CategoryTableXYDataset in project hmftools by hartwigmedical.

the class CopyNumberCharts method minorAllelePDF.

@NotNull
static JFreeChart minorAllelePDF(@NotNull final List<PurpleCopyNumber> variants) {
    final CategoryTableXYDataset dataset = minorAllele(variants);
    final JFreeChart chart = ChartFactory.createXYBarChart("Minor Allele Ploidy PDF", "Ploidy", false, "BAF Count", dataset, PlotOrientation.VERTICAL, true, false, false);
    StackedXYBarRenderer renderer = new StackedXYBarRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setShadowVisible(false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setRenderer(renderer);
    xyPlot.getDomainAxis().setRange(-1.1, 5.1);
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        renderer.setSeriesPaint(i, copyNumberColor(String.valueOf(dataset.getSeriesKey(i))));
    }
    return chart;
}
Also used : CategoryTableXYDataset(org.jfree.data.xy.CategoryTableXYDataset) XYPlot(org.jfree.chart.plot.XYPlot) StackedXYBarRenderer(org.jfree.chart.renderer.xy.StackedXYBarRenderer) StandardXYBarPainter(org.jfree.chart.renderer.xy.StandardXYBarPainter) JFreeChart(org.jfree.chart.JFreeChart) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CategoryTableXYDataset

use of org.jfree.data.xy.CategoryTableXYDataset in project hmftools by hartwigmedical.

the class CopyNumberChartsTest method testLowerBoundary.

@Test
public void testLowerBoundary() {
    CategoryTableXYDataset dataset = minorAllele(newArrayList(createCopyNumber(2, 1)));
    assertEquals(-1, dataset.getX(0, 0).doubleValue(), EPSILON);
    assertEquals(10, dataset.getY(0, 0).doubleValue(), EPSILON);
    dataset = minorAllele(newArrayList(createCopyNumber(3, 1)));
    assertEquals(-1, dataset.getX(0, 0).doubleValue(), EPSILON);
    assertEquals(10, dataset.getY(0, 0).doubleValue(), EPSILON);
}
Also used : CategoryTableXYDataset(org.jfree.data.xy.CategoryTableXYDataset) Test(org.junit.Test)

Aggregations

CategoryTableXYDataset (org.jfree.data.xy.CategoryTableXYDataset)7 NotNull (org.jetbrains.annotations.NotNull)4 Test (org.junit.Test)3 JFreeChart (org.jfree.chart.JFreeChart)2 XYPlot (org.jfree.chart.plot.XYPlot)2 StackedXYBarRenderer (org.jfree.chart.renderer.xy.StackedXYBarRenderer)2 StandardXYBarPainter (org.jfree.chart.renderer.xy.StandardXYBarPainter)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 PurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber)1 PurityAdjustedSomaticVariant (com.hartwig.hmftools.common.variant.PurityAdjustedSomaticVariant)1