Search in sources :

Example 11 with PurpleCopyNumber

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);
}
Also used : ProductionRunContextFactory(com.hartwig.hmftools.common.context.ProductionRunContextFactory) StructuralVariantAnalyzer(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalyzer) ImmutableSampleReport(com.hartwig.hmftools.patientreporter.ImmutableSampleReport) ImmutablePurpleAnalysis(com.hartwig.hmftools.patientreporter.copynumber.ImmutablePurpleAnalysis) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) SampleReport(com.hartwig.hmftools.patientreporter.SampleReport) HmfReporterData(com.hartwig.hmftools.patientreporter.HmfReporterData) AlterationAnalyzer(com.hartwig.hmftools.patientreporter.civic.AlterationAnalyzer) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) GeneFusionData(com.hartwig.hmftools.patientreporter.report.data.GeneFusionData) VariantAnalyzer(com.hartwig.hmftools.patientreporter.variants.VariantAnalyzer) Lims(com.hartwig.hmftools.common.lims.Lims) Value(org.immutables.value.Value) Map(java.util.Map) Alteration(com.hartwig.hmftools.patientreporter.report.data.Alteration) Path(java.nio.file.Path) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) EnrichedStructuralVariant(com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant) GeneDisruptionData(com.hartwig.hmftools.patientreporter.report.data.GeneDisruptionData) GeneDisruption(com.hartwig.hmftools.svannotation.annotations.GeneDisruption) SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) VariantReport(com.hartwig.hmftools.patientreporter.variants.VariantReport) ImmutableSequencedPatientReport(com.hartwig.hmftools.patientreporter.ImmutableSequencedPatientReport) PurpleAnalysis(com.hartwig.hmftools.patientreporter.copynumber.PurpleAnalysis) SequencedPatientReport(com.hartwig.hmftools.patientreporter.SequencedPatientReport) FittedPurityScore(com.hartwig.hmftools.common.purple.purity.FittedPurityScore) IOException(java.io.IOException) VariantAnalysis(com.hartwig.hmftools.patientreporter.variants.VariantAnalysis) BaseReporterData(com.hartwig.hmftools.patientreporter.BaseReporterData) Collectors(java.util.stream.Collectors) Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) RunContext(com.hartwig.hmftools.common.context.RunContext) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) TumorLocationDoidMapping(com.hartwig.hmftools.common.ecrf.doid.TumorLocationDoidMapping) Logger(org.apache.logging.log4j.Logger) PurityContext(com.hartwig.hmftools.common.purple.purity.PurityContext) GeneFusion(com.hartwig.hmftools.svannotation.annotations.GeneFusion) Optional(java.util.Optional) FittedPurity(com.hartwig.hmftools.common.purple.purity.FittedPurity) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) StructuralVariantAnalysis(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalysis) Comparator(java.util.Comparator) StructuralVariantFileLoader(com.hartwig.hmftools.common.variant.structural.StructuralVariantFileLoader) NotNull(org.jetbrains.annotations.NotNull) LogManager(org.apache.logging.log4j.LogManager) FittedPurityStatus(com.hartwig.hmftools.common.purple.purity.FittedPurityStatus) Path(java.nio.file.Path) SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) EnrichedStructuralVariant(com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant) StructuralVariantAnalysis(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalysis) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) EnrichedStructuralVariant(com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) PurityContext(com.hartwig.hmftools.common.purple.purity.PurityContext) ImmutablePurpleAnalysis(com.hartwig.hmftools.patientreporter.copynumber.ImmutablePurpleAnalysis) PurpleAnalysis(com.hartwig.hmftools.patientreporter.copynumber.PurpleAnalysis) VariantAnalysis(com.hartwig.hmftools.patientreporter.variants.VariantAnalysis) StructuralVariantAnalysis(com.hartwig.hmftools.svannotation.analysis.StructuralVariantAnalysis) FittedPurity(com.hartwig.hmftools.common.purple.purity.FittedPurity) FittedPurityScore(com.hartwig.hmftools.common.purple.purity.FittedPurityScore) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with PurpleCopyNumber

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;
}
Also used : PurityAdjuster(com.hartwig.hmftools.common.purple.PurityAdjuster) VariantReport(com.hartwig.hmftools.patientreporter.variants.VariantReport) ImmutableVariantReport(com.hartwig.hmftools.patientreporter.variants.ImmutableVariantReport) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with PurpleCopyNumber

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);
}
Also used : PurityAdjuster(com.hartwig.hmftools.common.purple.PurityAdjuster) PurityContext(com.hartwig.hmftools.common.purple.purity.PurityContext) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with PurpleCopyNumber

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;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) XYDataset(org.jfree.data.xy.XYDataset) CategoryTableXYDataset(org.jfree.data.xy.CategoryTableXYDataset) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) StandardXYBarPainter(org.jfree.chart.renderer.xy.StandardXYBarPainter) JFreeChart(org.jfree.chart.JFreeChart) StackedXYBarRenderer(org.jfree.chart.renderer.xy.StackedXYBarRenderer) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with PurpleCopyNumber

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);
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber)20 NotNull (org.jetbrains.annotations.NotNull)9 PurpleDatamodelTest (com.hartwig.hmftools.common.purple.PurpleDatamodelTest)6 StructuralVariantLeg (com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg)6 Test (org.junit.Test)6 PurityAdjuster (com.hartwig.hmftools.common.purple.PurityAdjuster)5 PurityContext (com.hartwig.hmftools.common.purple.purity.PurityContext)4 ImmutablePurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.ImmutablePurpleCopyNumber)3 GeneCopyNumber (com.hartwig.hmftools.common.gene.GeneCopyNumber)2 FittedPurity (com.hartwig.hmftools.common.purple.purity.FittedPurity)2 SomaticVariant (com.hartwig.hmftools.common.variant.SomaticVariant)2 DatabaseAccess (com.hartwig.hmftools.patientdb.dao.DatabaseAccess)2 VariantReport (com.hartwig.hmftools.patientreporter.variants.VariantReport)2 CommandLine (org.apache.commons.cli.CommandLine)2 Options (org.apache.commons.cli.Options)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ProductionRunContextFactory (com.hartwig.hmftools.common.context.ProductionRunContextFactory)1 RunContext (com.hartwig.hmftools.common.context.RunContext)1 TumorLocationDoidMapping (com.hartwig.hmftools.common.ecrf.doid.TumorLocationDoidMapping)1 Lims (com.hartwig.hmftools.common.lims.Lims)1