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