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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations