use of com.hartwig.hmftools.common.purple.PurityAdjuster 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.PurityAdjuster in project hmftools by hartwigmedical.
the class PurpleAnalysis method enrichStructuralVariants.
@NotNull
public List<EnrichedStructuralVariant> enrichStructuralVariants(@NotNull final List<StructuralVariant> structuralVariants) {
final PurityAdjuster purityAdjuster = new PurityAdjuster(gender(), fittedPurity());
final Multimap<String, PurpleCopyNumber> copyNumberMap = Multimaps.index(copyNumbers(), PurpleCopyNumber::chromosome);
return EnrichedStructuralVariantFactory.enrich(structuralVariants, purityAdjuster, copyNumberMap);
}
use of com.hartwig.hmftools.common.purple.PurityAdjuster in project hmftools by hartwigmedical.
the class LoadSomaticVariants 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 String vcfFileLocation = cmd.getOptionValue(VCF_FILE);
final String highConfidenceBed = cmd.getOptionValue(HIGH_CONFIDENCE_BED);
final String fastaFileLocation = cmd.getOptionValue(REF_GENOME);
final String sample = cmd.getOptionValue(SAMPLE);
final DatabaseAccess dbAccess = databaseAccess(cmd);
final CompoundFilter filter = new CompoundFilter(true);
if (cmd.hasOption(PASS_FILTER)) {
filter.add(new PassingVariantFilter());
}
if (cmd.hasOption(SOMATIC_FILTER)) {
filter.add(new SomaticFilter());
}
LOGGER.info("Reading somatic VCF File");
final List<SomaticVariant> variants = SomaticVariantFactory.filteredInstance(filter).fromVCFFile(sample, vcfFileLocation);
LOGGER.info("Reading high confidence bed file");
final Multimap<String, GenomeRegion> highConfidenceRegions = BEDFileLoader.fromBedFile(highConfidenceBed);
LOGGER.info("Loading indexed fasta reference file");
IndexedFastaSequenceFile indexedFastaSequenceFile = new IndexedFastaSequenceFile(new File(fastaFileLocation));
LOGGER.info("Querying purple database");
final PurityContext purityContext = dbAccess.readPurityContext(sample);
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 Multimap<String, PurpleCopyNumber> copyNumbers = Multimaps.index(dbAccess.readCopynumbers(sample), PurpleCopyNumber::chromosome);
final Multimap<String, FittedRegion> copyNumberRegions = Multimaps.index(dbAccess.readCopyNumberRegions(sample), FittedRegion::chromosome);
LOGGER.info("Incorporating purple purity");
final PurityAdjustedSomaticVariantFactory purityAdjustmentFactory = new PurityAdjustedSomaticVariantFactory(purityAdjuster, copyNumbers, copyNumberRegions);
final List<PurityAdjustedSomaticVariant> purityAdjustedVariants = purityAdjustmentFactory.create(variants);
final double clonalPloidy = ClonalityCutoffKernel.clonalCutoff(purityAdjustedVariants);
LOGGER.info("Enriching variants");
final EnrichedSomaticVariantFactory enrichedSomaticVariantFactory = new EnrichedSomaticVariantFactory(highConfidenceRegions, indexedFastaSequenceFile, new ClonalityFactory(purityAdjuster, clonalPloidy), CanonicalTranscriptFactory.create(HmfGenePanelSupplier.allGeneList()));
final List<EnrichedSomaticVariant> enrichedVariants = enrichedSomaticVariantFactory.enrich(purityAdjustedVariants);
LOGGER.info("Persisting variants to database");
dbAccess.writeSomaticVariants(sample, enrichedVariants);
LOGGER.info("Complete");
}
use of com.hartwig.hmftools.common.purple.PurityAdjuster in project hmftools by hartwigmedical.
the class FittedRegionFactory method fitRegion.
@NotNull
public FittedRegion fitRegion(final double purity, final double normFactor, @NotNull final ObservedRegion observedRegion) {
final PurityAdjuster purityAdjuster = new PurityAdjuster(gender, purity, normFactor);
double minDeviation = 0;
double observedBAF = observedRegion.observedBAF();
double observedTumorRatio = observedRegion.observedTumorRatio();
double purityAdjustedCopyNumber = purityAdjuster.purityAdjustedCopyNumber(observedRegion.chromosome(), observedTumorRatio);
double refNormalisedCopyNumber = purityAdjuster.purityAdjustedCopyNumber(observedTumorRatio, observedRegion.observedNormalRatio());
double tumorBAF = bafUtils.purityAdjustedBAF(purityAdjuster, observedRegion.chromosome(), purityAdjustedCopyNumber, observedBAF);
ImmutableFittedRegion.Builder builder = ImmutableFittedRegion.builder().from(observedRegion).segmentBAF(0).segmentTumorCopyNumber(0).tumorCopyNumber(purityAdjustedCopyNumber).tumorBAF(tumorBAF).refNormalisedCopyNumber(Doubles.replaceNaNWithZero(refNormalisedCopyNumber));
for (int ploidy = 0; ploidy <= maxPloidy; ploidy++) {
double modelRatio = modelRatio(purity, normFactor, ploidy);
double cnvDeviation = cnvDeviation(cnvRatioWeightFactor, modelRatio, observedTumorRatio);
double[] modelBAFWithDeviation = observedRegion.bafCount() == 0 ? new double[] { 0, 0, 0 } : bafUtils.modelBAFToMinimizeDeviation(purity, ploidy, observedBAF);
double modelBAF = modelBAFWithDeviation[0];
double bafDeviation = modelBAFWithDeviation[1];
double ploidyPenalty = PloidyPenalty.penalty(ploidy, (int) modelBAFWithDeviation[2]);
double deviation = (bafDeviation + cnvDeviation) * Math.pow(observedBAF, observedBafExponent);
if (ploidy == 1 || deviation < minDeviation) {
builder.modelPloidy(ploidy).modelBAF(modelBAF).modelTumorRatio(modelRatio).bafDeviation(bafDeviation).cnvDeviation(cnvDeviation).ploidyPenalty(ploidyPenalty).deviation(deviation);
minDeviation = deviation;
}
}
return builder.build();
}
use of com.hartwig.hmftools.common.purple.PurityAdjuster 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;
}
Aggregations