use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber in project hmftools by hartwigmedical.
the class PatientReporter method analyseGenomeData.
@NotNull
private GenomeAnalysis analyseGenomeData(@NotNull final String sample, @NotNull final String runDirectory) throws IOException {
LOGGER.info(" Loading somatic snv and indels...");
final List<SomaticVariant> variants = PatientReporterHelper.loadPassedSomaticVariants(sample, runDirectory);
LOGGER.info(" " + variants.size() + " somatic passed snps, mnps and indels loaded for sample " + sample);
LOGGER.info(" Analyzing somatic snp/mnp and indels....");
final VariantAnalysis variantAnalysis = variantAnalyzer().run(variants);
LOGGER.info(" Loading purity numbers...");
final PurityContext context = PatientReporterHelper.loadPurity(runDirectory, sample);
if (context.status().equals(FittedPurityStatus.NO_TUMOR)) {
LOGGER.warn("PURPLE DID NOT DETECT A TUMOR. Proceed with utmost caution!");
}
final FittedPurity purity = context.bestFit();
final FittedPurityScore purityScore = context.score();
final List<PurpleCopyNumber> purpleCopyNumbers = PatientReporterHelper.loadPurpleCopyNumbers(runDirectory, sample);
final List<GeneCopyNumber> panelGeneCopyNumbers = PatientReporterHelper.loadPurpleGeneCopyNumbers(runDirectory, sample).stream().filter(x -> reporterData().panelGeneModel().panel().contains(x.gene())).collect(Collectors.toList());
LOGGER.info(" " + purpleCopyNumbers.size() + " purple copy number regions loaded for sample " + sample);
LOGGER.info(" Analyzing purple somatic copy numbers...");
final PurpleAnalysis purpleAnalysis = ImmutablePurpleAnalysis.builder().gender(context.gender()).status(context.status()).fittedPurity(purity).fittedScorePurity(purityScore).copyNumbers(purpleCopyNumbers).panelGeneCopyNumbers(panelGeneCopyNumbers).build();
final Path structuralVariantVCF = PatientReporterHelper.findStructuralVariantVCF(runDirectory);
LOGGER.info(" Loading structural variants...");
final List<StructuralVariant> structuralVariants = StructuralVariantFileLoader.fromFile(structuralVariantVCF.toString(), true);
LOGGER.info(" Enriching structural variants with purple data.");
final List<EnrichedStructuralVariant> enrichedStructuralVariants = purpleAnalysis.enrichStructuralVariants(structuralVariants);
LOGGER.info(" Analysing structural variants...");
final StructuralVariantAnalysis structuralVariantAnalysis = structuralVariantAnalyzer().run(enrichedStructuralVariants, false);
return ImmutableGenomeAnalysis.of(sample, variantAnalysis, purpleAnalysis, structuralVariantAnalysis);
}
use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber in project hmftools by hartwigmedical.
the class PurpleAnalysis method enrichSomaticVariants.
@NotNull
public List<VariantReport> enrichSomaticVariants(@NotNull final List<VariantReport> variants) {
final List<VariantReport> result = Lists.newArrayList();
final PurityAdjuster purityAdjuster = new PurityAdjuster(gender(), fittedPurity());
final GenomeRegionSelector<PurpleCopyNumber> copyNumberSelector = GenomeRegionSelectorFactory.create(copyNumbers());
for (final VariantReport variantReport : variants) {
final Optional<PurpleCopyNumber> optionalCopyNumber = copyNumberSelector.select(variantReport.variant());
if (optionalCopyNumber.isPresent()) {
final PurpleCopyNumber copyNumber = optionalCopyNumber.get();
double adjustedVAF = Math.min(1, purityAdjuster.purityAdjustedVAF(copyNumber.chromosome(), copyNumber.averageTumorCopyNumber(), variantReport.alleleFrequency()));
result.add(ImmutableVariantReport.builder().from(variantReport).baf(copyNumber.descriptiveBAF()).impliedVAF(adjustedVAF).build());
} else {
result.add(variantReport);
}
}
return result;
}
use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber in project hmftools by hartwigmedical.
the class LoadStructuralVariants method enrichStructuralVariants.
@NotNull
private static List<EnrichedStructuralVariant> enrichStructuralVariants(@NotNull List<StructuralVariant> variants, @NotNull DatabaseAccess dbAccess, @NotNull String tumorSample) {
final PurityContext purityContext = dbAccess.readPurityContext(tumorSample);
if (purityContext == null) {
LOGGER.warn("Unable to retrieve purple data. Enrichment may be incomplete.");
}
final PurityAdjuster purityAdjuster = purityContext == null ? new PurityAdjuster(Gender.FEMALE, 1, 1) : new PurityAdjuster(purityContext.gender(), purityContext.bestFit().purity(), purityContext.bestFit().normFactor());
final List<PurpleCopyNumber> copyNumberList = dbAccess.readCopynumbers(tumorSample);
final Multimap<String, PurpleCopyNumber> copyNumbers = Multimaps.index(copyNumberList, PurpleCopyNumber::chromosome);
return EnrichedStructuralVariantFactory.enrich(variants, purityAdjuster, copyNumbers);
}
use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber in project hmftools by hartwigmedical.
the class CopyNumberCharts method copyNumberPDF.
@NotNull
static JFreeChart copyNumberPDF(@NotNull final List<PurpleCopyNumber> copyNumbers) {
final XYDataset dataset = ploidyPDF(copyNumbers, PurpleCopyNumber::averageTumorCopyNumber, PurpleCopyNumber::bafCount);
JFreeChart chart = ChartFactory.createScatterPlot("Copy Number PDF", "Ploidy", "BAF Count", dataset, PlotOrientation.VERTICAL, false, false, false);
XYBarRenderer renderer = new XYBarRenderer(0.9);
renderer.setShadowVisible(false);
renderer.setBarPainter(new StandardXYBarPainter());
renderer.setSeriesPaint(0, Color.BLUE);
XYPlot xyPlot = (XYPlot) chart.getPlot();
xyPlot.getDomainAxis().setRange(0, 10);
xyPlot.setRenderer(renderer);
return chart;
}
use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber in project hmftools by hartwigmedical.
the class CopyNumberCharts method createDataset.
@NotNull
private static XYDataset createDataset(@NotNull final List<PurpleCopyNumber> copyNumbers) {
final List<PurpleCopyNumber> sortedCopyNumbers = Lists.newArrayList(copyNumbers);
sortedCopyNumbers.sort(Comparator.comparingDouble(PurpleCopyNumber::averageTumorCopyNumber));
int totalCount = copyNumbers.stream().mapToInt(PurpleCopyNumber::bafCount).sum();
XYSeries series = new XYSeries("CDF");
int cumulativeBAFCount = 0;
for (PurpleCopyNumber sortedCopyNumber : sortedCopyNumbers) {
cumulativeBAFCount += sortedCopyNumber.bafCount();
series.add((double) cumulativeBAFCount / totalCount * 100, sortedCopyNumber.averageTumorCopyNumber());
}
return new XYSeriesCollection(series);
}
Aggregations