Search in sources :

Example 1 with FittedPurity

use of com.hartwig.hmftools.common.purple.purity.FittedPurity in project hmftools by hartwigmedical.

the class PDFWriterTest method canGenerateSequenceReport.

@Test
public void canGenerateSequenceReport() throws DRException, IOException {
    final double pathologyTumorPercentage = 0.6;
    final double impliedTumorPurity = 0.58;
    final int mutationalLoad = 361;
    final double microsatelliteIndicator = 2.1;
    final HmfReporterData reporterData = testHmfReporterData();
    final BaseReporterData baseReporterData = testBaseReporterData();
    final FittedPurity fittedPurity = createFittedPurity(impliedTumorPurity);
    final List<VariantReport> variants = createTestVariants(new PurityAdjuster(Gender.MALE, fittedPurity));
    final List<GeneCopyNumber> copyNumbers = createTestCopyNumbers();
    final List<GeneDisruptionData> disruptions = createTestDisruptions();
    final List<GeneFusionData> fusions = createTestFusions();
    final SampleReport sampleReport = testSampleReport(pathologyTumorPercentage);
    final List<Alteration> alterations = RUN_CIVIC_ANALYSIS ? PatientReporterTestUtil.runCivicAnalysis(variants, copyNumbers, disruptions, fusions, reporterData.panelGeneModel(), sampleReport.cancerType()) : mockedAlterations();
    final SequencedPatientReport patientReport = ImmutableSequencedPatientReport.of(sampleReport, variants, mutationalLoad, microsatelliteIndicator, copyNumbers, disruptions, fusions, PatientReportFormat.formatPercent(impliedTumorPurity), alterations, Resources.getResource("circos" + File.separator + "circos_example.png").getPath(), Optional.of("this is a test report and does not relate to any real CPCT patient"), baseReporterData.signaturePath());
    final JasperReportBuilder mainReport = PDFWriter.generatePatientReport(patientReport, reporterData);
    assertNotNull(mainReport);
    final JasperReportBuilder evidenceReport = EvidenceReport.generate(patientReport);
    assertNotNull(evidenceReport);
    if (SHOW_AND_PRINT) {
        mainReport.show().print();
    }
    if (WRITE_TO_PDF) {
        mainReport.toPdf(new FileOutputStream(REPORT_BASE_DIR + File.separator + "test_report.pdf"));
        evidenceReport.toPdf(new FileOutputStream(REPORT_BASE_DIR + File.separator + "test_evidence_report.pdf"));
    }
}
Also used : PurityAdjuster(com.hartwig.hmftools.common.purple.PurityAdjuster) ImmutableSequencedPatientReport(com.hartwig.hmftools.patientreporter.ImmutableSequencedPatientReport) SequencedPatientReport(com.hartwig.hmftools.patientreporter.SequencedPatientReport) NotSequencedPatientReport(com.hartwig.hmftools.patientreporter.NotSequencedPatientReport) ImmutableNotSequencedPatientReport(com.hartwig.hmftools.patientreporter.ImmutableNotSequencedPatientReport) PatientReporterTestUtil.testBaseReporterData(com.hartwig.hmftools.patientreporter.PatientReporterTestUtil.testBaseReporterData) BaseReporterData(com.hartwig.hmftools.patientreporter.BaseReporterData) ImmutableSampleReport(com.hartwig.hmftools.patientreporter.ImmutableSampleReport) SampleReport(com.hartwig.hmftools.patientreporter.SampleReport) GeneDisruptionData(com.hartwig.hmftools.patientreporter.report.data.GeneDisruptionData) ImmutableGeneDisruptionData(com.hartwig.hmftools.patientreporter.report.data.ImmutableGeneDisruptionData) VariantReport(com.hartwig.hmftools.patientreporter.variants.VariantReport) ImmutableVariantReport(com.hartwig.hmftools.patientreporter.variants.ImmutableVariantReport) Alteration(com.hartwig.hmftools.patientreporter.report.data.Alteration) JasperReportBuilder(net.sf.dynamicreports.jasper.builder.JasperReportBuilder) HmfReporterData(com.hartwig.hmftools.patientreporter.HmfReporterData) PatientReporterTestUtil.testHmfReporterData(com.hartwig.hmftools.patientreporter.PatientReporterTestUtil.testHmfReporterData) GeneFusionData(com.hartwig.hmftools.patientreporter.report.data.GeneFusionData) ImmutableGeneFusionData(com.hartwig.hmftools.patientreporter.report.data.ImmutableGeneFusionData) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) ImmutableGeneCopyNumber(com.hartwig.hmftools.common.gene.ImmutableGeneCopyNumber) FileOutputStream(java.io.FileOutputStream) ImmutableFittedPurity(com.hartwig.hmftools.common.purple.purity.ImmutableFittedPurity) FittedPurity(com.hartwig.hmftools.common.purple.purity.FittedPurity) Test(org.junit.Test)

Example 2 with FittedPurity

use of com.hartwig.hmftools.common.purple.purity.FittedPurity in project hmftools by hartwigmedical.

the class LoadPurpleData method main.

public static void main(@NotNull final String[] args) throws ParseException, IOException, SQLException {
    final Options options = createBasicOptions();
    final CommandLine cmd = createCommandLine(args, options);
    final DatabaseAccess dbAccess = databaseAccess(cmd);
    final String tumorSample = cmd.getOptionValue(SAMPLE);
    final String purplePath = cmd.getOptionValue(PURPLE_DIR);
    LOGGER.info("Persisting purity data");
    final PurpleQC purpleQC = PurpleQCFile.read(PurpleQCFile.generateFilename(purplePath, tumorSample));
    final PurityContext purityContext = FittedPurityFile.read(purplePath, tumorSample);
    final List<FittedPurity> bestFitPerPurity = FittedPurityRangeFile.read(purplePath, tumorSample);
    dbAccess.writePurity(tumorSample, purityContext, purpleQC);
    dbAccess.writeBestFitPerPurity(tumorSample, bestFitPerPurity);
    LOGGER.info("Persisting copy numbers");
    final List<PurpleCopyNumber> copyNumbers = PurpleCopyNumberFile.read(purplePath, tumorSample);
    dbAccess.writeCopynumbers(tumorSample, copyNumbers);
    LOGGER.info("Persisting gene copy numbers");
    final List<GeneCopyNumber> geneCopyNumbers = GeneCopyNumberFile.read(GeneCopyNumberFile.generateFilename(purplePath, tumorSample));
    dbAccess.writeGeneCopynumberRegions(tumorSample, geneCopyNumbers);
    LOGGER.info("Complete");
}
Also used : Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) PurpleQC(com.hartwig.hmftools.common.purple.qc.PurpleQC) DatabaseAccess(com.hartwig.hmftools.patientdb.dao.DatabaseAccess) PurityContext(com.hartwig.hmftools.common.purple.purity.PurityContext) FittedPurity(com.hartwig.hmftools.common.purple.purity.FittedPurity) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber)

Example 3 with FittedPurity

use of com.hartwig.hmftools.common.purple.purity.FittedPurity in project hmftools by hartwigmedical.

the class PurityDAO method write.

void write(@NotNull final String sample, @NotNull final PurityContext purity, @NotNull final PurpleQC checks) {
    final FittedPurity bestFit = purity.bestFit();
    final FittedPurityScore score = purity.score();
    Timestamp timestamp = new Timestamp(new Date().getTime());
    context.delete(PURITY).where(PURITY.SAMPLEID.eq(sample)).execute();
    context.insertInto(PURITY, PURITY.VERSION, PURITY.SAMPLEID, PURITY.PURITY_, PURITY.GENDER, PURITY.STATUS, PURITY.QCSTATUS, PURITY.NORMFACTOR, PURITY.SCORE, PURITY.PLOIDY, PURITY.DIPLOIDPROPORTION, PURITY.MINDIPLOIDPROPORTION, PURITY.MAXDIPLOIDPROPORTION, PURITY.MINPURITY, PURITY.MAXPURITY, PURITY.MINPLOIDY, PURITY.MAXPLOIDY, PURITY.POLYCLONALPROPORTION, PURITY.MODIFIED).values(purity.version(), sample, bestFit.purity(), purity.gender().toString(), purity.status().toString(), checks.status().toString(), bestFit.normFactor(), bestFit.score(), bestFit.ploidy(), bestFit.diploidProportion(), score.minDiploidProportion(), score.maxDiploidProportion(), score.minPurity(), score.maxPurity(), score.minPloidy(), score.maxPloidy(), purity.polyClonalProportion(), timestamp).execute();
}
Also used : ImmutableFittedPurity(com.hartwig.hmftools.common.purple.purity.ImmutableFittedPurity) FittedPurity(com.hartwig.hmftools.common.purple.purity.FittedPurity) FittedPurityScore(com.hartwig.hmftools.common.purple.purity.FittedPurityScore) ImmutableFittedPurityScore(com.hartwig.hmftools.common.purple.purity.ImmutableFittedPurityScore) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 4 with FittedPurity

use of com.hartwig.hmftools.common.purple.purity.FittedPurity in project hmftools by hartwigmedical.

the class PurityDAO method readPurityContext.

@Nullable
PurityContext readPurityContext(@NotNull final String sample) {
    @Nullable Record result = context.select().from(PURITY).where(PURITY.SAMPLEID.eq(sample)).fetchOne();
    if (result == null) {
        return null;
    }
    final FittedPurity purity = ImmutableFittedPurity.builder().purity(result.getValue(PURITY.PURITY_)).normFactor(result.getValue(PURITY.NORMFACTOR)).score(result.getValue(PURITY.SCORE)).diploidProportion(result.getValue(PURITY.DIPLOIDPROPORTION)).ploidy(result.getValue(PURITY.PLOIDY)).build();
    final FittedPurityScore score = ImmutableFittedPurityScore.builder().minPurity(result.getValue(PURITY.MINPURITY)).maxPurity(result.getValue(PURITY.MAXPURITY)).minPloidy(result.getValue(PURITY.MINPLOIDY)).maxPloidy(result.getValue(PURITY.MAXPLOIDY)).minDiploidProportion(result.getValue(PURITY.MINDIPLOIDPROPORTION)).maxDiploidProportion(result.getValue(PURITY.MAXDIPLOIDPROPORTION)).build();
    return ImmutablePurityContext.builder().bestFit(purity).score(score).version(result.getValue(PURITY.VERSION)).gender(Gender.valueOf(result.getValue(PURITY.GENDER))).polyClonalProportion(result.getValue(PURITY.POLYCLONALPROPORTION)).status(FittedPurityStatus.valueOf(result.getValue(PURITY.STATUS))).build();
}
Also used : Record(org.jooq.Record) ImmutableFittedPurity(com.hartwig.hmftools.common.purple.purity.ImmutableFittedPurity) FittedPurity(com.hartwig.hmftools.common.purple.purity.FittedPurity) FittedPurityScore(com.hartwig.hmftools.common.purple.purity.FittedPurityScore) ImmutableFittedPurityScore(com.hartwig.hmftools.common.purple.purity.ImmutableFittedPurityScore) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with FittedPurity

use of com.hartwig.hmftools.common.purple.purity.FittedPurity 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)

Aggregations

FittedPurity (com.hartwig.hmftools.common.purple.purity.FittedPurity)5 GeneCopyNumber (com.hartwig.hmftools.common.gene.GeneCopyNumber)3 FittedPurityScore (com.hartwig.hmftools.common.purple.purity.FittedPurityScore)3 ImmutableFittedPurity (com.hartwig.hmftools.common.purple.purity.ImmutableFittedPurity)3 PurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber)2 ImmutableFittedPurityScore (com.hartwig.hmftools.common.purple.purity.ImmutableFittedPurityScore)2 PurityContext (com.hartwig.hmftools.common.purple.purity.PurityContext)2 BaseReporterData (com.hartwig.hmftools.patientreporter.BaseReporterData)2 HmfReporterData (com.hartwig.hmftools.patientreporter.HmfReporterData)2 ImmutableSampleReport (com.hartwig.hmftools.patientreporter.ImmutableSampleReport)2 ImmutableSequencedPatientReport (com.hartwig.hmftools.patientreporter.ImmutableSequencedPatientReport)2 SampleReport (com.hartwig.hmftools.patientreporter.SampleReport)2 SequencedPatientReport (com.hartwig.hmftools.patientreporter.SequencedPatientReport)2 Alteration (com.hartwig.hmftools.patientreporter.report.data.Alteration)2 GeneDisruptionData (com.hartwig.hmftools.patientreporter.report.data.GeneDisruptionData)2 GeneFusionData (com.hartwig.hmftools.patientreporter.report.data.GeneFusionData)2 VariantReport (com.hartwig.hmftools.patientreporter.variants.VariantReport)2 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