Search in sources :

Example 6 with GeneCopyNumber

use of com.hartwig.hmftools.common.gene.GeneCopyNumber in project hmftools by hartwigmedical.

the class BachelorEligibility method fromMap.

static BachelorEligibility fromMap(final Map<String, Program> input) {
    final BachelorEligibility result = new BachelorEligibility();
    for (final Program program : input.values()) {
        final Multimap<String, String> geneToEnsemblMap = HashMultimap.create();
        program.getPanel().stream().map(ProgramPanel::getGene).flatMap(Collection::stream).forEach(g -> geneToEnsemblMap.put(g.getName(), g.getEnsembl()));
        // NOTE: copy number and SVs are untested/unverified for now, but leave in support for them
        // process copy number sections
        final List<Predicate<GeneCopyNumber>> cnvPredicates = Lists.newArrayList();
        for (final ProgramPanel panel : program.getPanel()) {
            final List<GeneIdentifier> genes = panel.getGene();
            if (panel.getEffect().contains(OtherEffect.HOMOZYGOUS_DELETION)) {
                final Predicate<GeneCopyNumber> geneCopyNumberPredicate = cnv -> genes.stream().anyMatch(g -> g.getEnsembl().equals(cnv.transcriptID()));
                // TODO: we are matching on transcript ID here but we only have canonical transcripts in our panel file
                cnvPredicates.add(geneCopyNumberPredicate);
            }
        }
        // process structural variant disruptions
        final List<Predicate<HmfGenomeRegion>> disruptionPredicates = Lists.newArrayList();
        for (final ProgramPanel panel : program.getPanel()) {
            final List<GeneIdentifier> genes = panel.getGene();
            if (panel.getEffect().contains(OtherEffect.GENE_DISRUPTION)) {
                final Predicate<HmfGenomeRegion> disruptionPredicate = sv -> genes.stream().anyMatch(g -> g.getEnsembl().equals(sv.transcriptID()));
                // TODO: we are matching on transcript ID here but we only have canonical transcripts in our panel file
                disruptionPredicates.add(disruptionPredicate);
            }
        }
        // process variants from vcf
        final List<Predicate<VariantModel>> panelPredicates = Lists.newArrayList();
        List<String> requiredEffects = Lists.newArrayList();
        List<String> panelTranscripts = Lists.newArrayList();
        for (final ProgramPanel panel : program.getPanel()) {
            final List<GeneIdentifier> genes = panel.getGene();
            // take up a collection of the effects to search for
            requiredEffects = panel.getSnpEffect().stream().map(SnpEffect::value).collect(Collectors.toList());
            panelTranscripts = genes.stream().map(GeneIdentifier::getEnsembl).collect(Collectors.toList());
            final List<String> effects = requiredEffects;
            final Predicate<VariantModel> panelPredicate = v -> genes.stream().anyMatch(p -> v.sampleAnnotations().stream().anyMatch(a -> a.featureID().equals(p.getEnsembl()) && effects.stream().anyMatch(x -> a.effects().contains(x))));
            panelPredicates.add(panelPredicate);
            // update query targets
            for (final GeneIdentifier g : genes) {
                final HmfGenomeRegion region = allTranscriptsMap.get(g.getEnsembl());
                if (region == null) {
                    final HmfGenomeRegion namedRegion = allGenesMap.get(g.getName());
                    if (namedRegion == null) {
                        LOGGER.warn("Program {} gene {} non-canonical transcript {} couldn't find region, transcript will be skipped", program.getName(), g.getName(), g.getEnsembl());
                    // just skip this gene for now
                    } else {
                        result.variantLocationsToQuery.add(namedRegion);
                    }
                } else {
                    result.variantLocationsToQuery.add(region);
                }
            }
        }
        final Predicate<VariantModel> inPanel = v -> panelPredicates.stream().anyMatch(p -> p.test(v));
        final Predicate<VariantModel> inBlacklist = new BlacklistPredicate(geneToEnsemblMap.values(), program.getBlacklist());
        final Predicate<VariantModel> inWhitelist = new WhitelistPredicate(geneToEnsemblMap, program.getWhitelist());
        final Predicate<VariantModel> snvPredicate = v -> inPanel.test(v) ? !inBlacklist.test(v) : inWhitelist.test(v);
        final Predicate<GeneCopyNumber> copyNumberPredicate = cnv -> cnvPredicates.stream().anyMatch(p -> p.test(cnv)) && cnv.minCopyNumber() < MAX_COPY_NUMBER_FOR_LOSS;
        final Predicate<HmfGenomeRegion> disruptionPredicate = disruption -> disruptionPredicates.stream().anyMatch(p -> p.test(disruption));
        BachelorProgram bachelorProgram = new BachelorProgram(program.getName(), snvPredicate, copyNumberPredicate, disruptionPredicate, requiredEffects, panelTranscripts);
        result.programs.add(bachelorProgram);
    }
    return result;
}
Also used : GeneIdentifier(nl.hartwigmedicalfoundation.bachelor.GeneIdentifier) ProgramPanel(nl.hartwigmedicalfoundation.bachelor.ProgramPanel) Genotype(htsjdk.variant.variantcontext.Genotype) CloseableIterator(htsjdk.samtools.util.CloseableIterator) SOMATIC_DELETION(com.hartwig.hmftools.bachelor.EligibilityReport.ReportType.SOMATIC_DELETION) SOMATIC_DISRUPTION(com.hartwig.hmftools.bachelor.EligibilityReport.ReportType.SOMATIC_DISRUPTION) VCFFileReader(htsjdk.variant.vcf.VCFFileReader) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) Multimap(com.google.common.collect.Multimap) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) HmfGenePanelSupplier(com.hartwig.hmftools.genepanel.HmfGenePanelSupplier) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) GenomePosition(com.hartwig.hmftools.common.position.GenomePosition) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation) Map(java.util.Map) StructuralVariantType(com.hartwig.hmftools.common.variant.structural.StructuralVariantType) GenomePositions(com.hartwig.hmftools.common.position.GenomePositions) SnpEffect(nl.hartwigmedicalfoundation.bachelor.SnpEffect) GERMLINE_DELETION(com.hartwig.hmftools.bachelor.EligibilityReport.ReportType.GERMLINE_DELETION) SortedSetMultimap(com.google.common.collect.SortedSetMultimap) OtherEffect(nl.hartwigmedicalfoundation.bachelor.OtherEffect) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Program(nl.hartwigmedicalfoundation.bachelor.Program) Set(java.util.Set) WhitelistPredicate(com.hartwig.hmftools.bachelor.predicates.WhitelistPredicate) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) GeneIdentifier(nl.hartwigmedicalfoundation.bachelor.GeneIdentifier) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) VariantContext(htsjdk.variant.variantcontext.VariantContext) HmfExonRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfExonRegion) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) BlacklistPredicate(com.hartwig.hmftools.bachelor.predicates.BlacklistPredicate) BlacklistPredicate(com.hartwig.hmftools.bachelor.predicates.BlacklistPredicate) Program(nl.hartwigmedicalfoundation.bachelor.Program) WhitelistPredicate(com.hartwig.hmftools.bachelor.predicates.WhitelistPredicate) Predicate(java.util.function.Predicate) WhitelistPredicate(com.hartwig.hmftools.bachelor.predicates.WhitelistPredicate) BlacklistPredicate(com.hartwig.hmftools.bachelor.predicates.BlacklistPredicate) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber) SnpEffect(nl.hartwigmedicalfoundation.bachelor.SnpEffect) ProgramPanel(nl.hartwigmedicalfoundation.bachelor.ProgramPanel) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion)

Example 7 with GeneCopyNumber

use of com.hartwig.hmftools.common.gene.GeneCopyNumber 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 8 with GeneCopyNumber

use of com.hartwig.hmftools.common.gene.GeneCopyNumber in project hmftools by hartwigmedical.

the class GeneCopyNumberDAO method writeCopyNumber.

void writeCopyNumber(@NotNull final String sample, @NotNull List<GeneCopyNumber> copyNumbers) {
    Timestamp timestamp = new Timestamp(new Date().getTime());
    context.delete(GENECOPYNUMBER).where(GENECOPYNUMBER.SAMPLEID.eq(sample)).execute();
    for (List<GeneCopyNumber> splitCopyNumbers : Iterables.partition(copyNumbers, DB_BATCH_INSERT_SIZE)) {
        InsertValuesStepN inserter = context.insertInto(GENECOPYNUMBER, GENECOPYNUMBER.SAMPLEID, GENECOPYNUMBER.CHROMOSOME, GENECOPYNUMBER.START, GENECOPYNUMBER.END, GENECOPYNUMBER.GENE, GENECOPYNUMBER.MINCOPYNUMBER, GENECOPYNUMBER.MAXCOPYNUMBER, GENECOPYNUMBER.SOMATICREGIONS, GENECOPYNUMBER.GERMLINEHOMREGIONS, GENECOPYNUMBER.GERMLINEHETREGIONS, GENECOPYNUMBER.TRANSCRIPTID, GENECOPYNUMBER.TRANSCRIPTVERSION, GENECOPYNUMBER.CHROMOSOMEBAND, GENECOPYNUMBER.MINREGIONS, GENECOPYNUMBER.MINREGIONSTART, GENECOPYNUMBER.MINREGIONEND, GENECOPYNUMBER.MINREGIONSTARTSUPPORT, GENECOPYNUMBER.MINREGIONENDSUPPORT, GENECOPYNUMBER.MINREGIONMETHOD, GENECOPYNUMBER.NONSENSEBIALLELICVARIANTS, GENECOPYNUMBER.NONSENSENONBIALLELICVARIANTS, GENECOPYNUMBER.NONSENSENONBIALLELICPLOIDY, GENECOPYNUMBER.SPLICEBIALLELICVARIANTS, GENECOPYNUMBER.SPLICENONBIALLELICVARIANTS, GENECOPYNUMBER.SPLICENONBIALLELICPLOIDY, GENECOPYNUMBER.MISSENSEBIALLELICVARIANTS, GENECOPYNUMBER.MISSENSENONBIALLELICVARIANTS, GENECOPYNUMBER.MISSENSENONBIALLELICPLOIDY, GENECOPYNUMBER.MINMINORALLELEPLOIDY, COPYNUMBER.MODIFIED);
        splitCopyNumbers.forEach(x -> addCopynumberRecord(timestamp, inserter, sample, x));
        inserter.execute();
    }
}
Also used : InsertValuesStepN(org.jooq.InsertValuesStepN) Timestamp(java.sql.Timestamp) Date(java.util.Date) GeneCopyNumber(com.hartwig.hmftools.common.gene.GeneCopyNumber)

Aggregations

GeneCopyNumber (com.hartwig.hmftools.common.gene.GeneCopyNumber)8 HmfGenomeRegion (com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion)4 NotNull (org.jetbrains.annotations.NotNull)4 Lists (com.google.common.collect.Lists)3 Sets (com.google.common.collect.Sets)3 FittedPurity (com.hartwig.hmftools.common.purple.purity.FittedPurity)3 StructuralVariant (com.hartwig.hmftools.common.variant.structural.StructuralVariant)3 Alteration (com.hartwig.hmftools.patientreporter.report.data.Alteration)3 GeneDisruptionData (com.hartwig.hmftools.patientreporter.report.data.GeneDisruptionData)3 GeneFusionData (com.hartwig.hmftools.patientreporter.report.data.GeneFusionData)3 VariantReport (com.hartwig.hmftools.patientreporter.variants.VariantReport)3 Collection (java.util.Collection)3 List (java.util.List)3 Set (java.util.Set)3 Predicate (java.util.function.Predicate)3 Collectors (java.util.stream.Collectors)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 HashMultimap (com.google.common.collect.HashMultimap)2 Maps (com.google.common.collect.Maps)2