Search in sources :

Example 1 with PurityContext

use of com.hartwig.hmftools.common.purple.purity.PurityContext 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 2 with PurityContext

use of com.hartwig.hmftools.common.purple.purity.PurityContext 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");
}
Also used : Options(org.apache.commons.cli.Options) EnrichedSomaticVariant(com.hartwig.hmftools.common.variant.EnrichedSomaticVariant) PassingVariantFilter(htsjdk.variant.variantcontext.filter.PassingVariantFilter) FittedRegion(com.hartwig.hmftools.common.purple.region.FittedRegion) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) DatabaseAccess(com.hartwig.hmftools.patientdb.dao.DatabaseAccess) SomaticFilter(com.hartwig.hmftools.common.variant.filter.SomaticFilter) PurityAdjuster(com.hartwig.hmftools.common.purple.PurityAdjuster) PurityAdjustedSomaticVariant(com.hartwig.hmftools.common.variant.PurityAdjustedSomaticVariant) SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) EnrichedSomaticVariant(com.hartwig.hmftools.common.variant.EnrichedSomaticVariant) PurityAdjustedSomaticVariantFactory(com.hartwig.hmftools.common.variant.PurityAdjustedSomaticVariantFactory) CompoundFilter(htsjdk.variant.variantcontext.filter.CompoundFilter) PurityAdjustedSomaticVariant(com.hartwig.hmftools.common.variant.PurityAdjustedSomaticVariant) CommandLine(org.apache.commons.cli.CommandLine) GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) PurityContext(com.hartwig.hmftools.common.purple.purity.PurityContext) EnrichedSomaticVariantFactory(com.hartwig.hmftools.common.variant.EnrichedSomaticVariantFactory) ClonalityFactory(com.hartwig.hmftools.common.variant.ClonalityFactory) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile)

Example 3 with PurityContext

use of com.hartwig.hmftools.common.purple.purity.PurityContext 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 4 with PurityContext

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

Aggregations

PurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber)4 PurityContext (com.hartwig.hmftools.common.purple.purity.PurityContext)4 GeneCopyNumber (com.hartwig.hmftools.common.gene.GeneCopyNumber)2 PurityAdjuster (com.hartwig.hmftools.common.purple.PurityAdjuster)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 CommandLine (org.apache.commons.cli.CommandLine)2 Options (org.apache.commons.cli.Options)2 NotNull (org.jetbrains.annotations.NotNull)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 Lims (com.hartwig.hmftools.common.lims.Lims)1 FittedPurityScore (com.hartwig.hmftools.common.purple.purity.FittedPurityScore)1 FittedPurityStatus (com.hartwig.hmftools.common.purple.purity.FittedPurityStatus)1 PurpleQC (com.hartwig.hmftools.common.purple.qc.PurpleQC)1 FittedRegion (com.hartwig.hmftools.common.purple.region.FittedRegion)1 GenomeRegion (com.hartwig.hmftools.common.region.GenomeRegion)1 HmfGenomeRegion (com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion)1