Search in sources :

Example 1 with PurpleCopyNumber

use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber 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);
}
Also used : PurityAdjuster(com.hartwig.hmftools.common.purple.PurityAdjuster) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PurpleCopyNumber

use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber in project hmftools by hartwigmedical.

the class CopyNumberCharts method minorAllele.

@VisibleForTesting
@NotNull
static CategoryTableXYDataset minorAllele(@NotNull final List<PurpleCopyNumber> copyNumbers) {
    int positivePloidy = 5;
    int positiveBuckets = positivePloidy * 10;
    int negativePloidy = 1;
    int negativeBuckets = negativePloidy * 10;
    int totalBuckets = negativeBuckets + positiveBuckets;
    double[][] buckets = new double[MAX_COPY_NUMBER_SERIES + 1][totalBuckets + 1];
    for (final PurpleCopyNumber copyNumber : copyNumbers) {
        double unboundMinorAllele = (1 - copyNumber.averageActualBAF()) * copyNumber.averageTumorCopyNumber();
        int series = limit(copyNumber.averageTumorCopyNumber(), 0, MAX_COPY_NUMBER_SERIES);
        int column = limit(unboundMinorAllele / 0.1, -negativeBuckets, positiveBuckets) + negativeBuckets;
        buckets[series][column] += copyNumber.bafCount();
    }
    CategoryTableXYDataset result = new CategoryTableXYDataset();
    for (int i = 0; i <= MAX_COPY_NUMBER_SERIES; i++) {
        String seriesName = "CN" + i + (i == MAX_COPY_NUMBER_SERIES ? "+" : "");
        for (int j = 0; j <= totalBuckets; j++) {
            if (!Doubles.isZero(buckets[i][j])) {
                result.add(-1 + (j * 0.1), buckets[i][j], seriesName);
            }
        }
    }
    return result;
}
Also used : CategoryTableXYDataset(org.jfree.data.xy.CategoryTableXYDataset) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with PurpleCopyNumber

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

use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber 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 5 with PurpleCopyNumber

use of com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber in project hmftools by hartwigmedical.

the class CopyNumberDAO method writeGermlineCopyNumber.

void writeGermlineCopyNumber(@NotNull final String sample, @NotNull List<PurpleCopyNumber> copyNumbers) {
    Timestamp timestamp = new Timestamp(new Date().getTime());
    context.delete(COPYNUMBERGERMLINE).where(COPYNUMBERGERMLINE.SAMPLEID.eq(sample)).execute();
    for (List<PurpleCopyNumber> splitCopyNumbers : Iterables.partition(copyNumbers, DB_BATCH_INSERT_SIZE)) {
        InsertValuesStep12 inserter = context.insertInto(COPYNUMBERGERMLINE, COPYNUMBERGERMLINE.SAMPLEID, COPYNUMBERGERMLINE.CHROMOSOME, COPYNUMBERGERMLINE.START, COPYNUMBERGERMLINE.END, COPYNUMBERGERMLINE.COPYNUMBERMETHOD, COPYNUMBERGERMLINE.SEGMENTSTARTSUPPORT, COPYNUMBERGERMLINE.SEGMENTENDSUPPORT, COPYNUMBERGERMLINE.BAFCOUNT, COPYNUMBERGERMLINE.OBSERVEDBAF, COPYNUMBERGERMLINE.ACTUALBAF, COPYNUMBERGERMLINE.COPYNUMBER, COPYNUMBERGERMLINE.MODIFIED);
        splitCopyNumbers.forEach(x -> addCopynumberRecord(timestamp, inserter, sample, x));
        inserter.execute();
    }
}
Also used : InsertValuesStep12(org.jooq.InsertValuesStep12) Timestamp(java.sql.Timestamp) ImmutablePurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.ImmutablePurpleCopyNumber) PurpleCopyNumber(com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber) Date(java.util.Date)

Aggregations

PurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.PurpleCopyNumber)20 NotNull (org.jetbrains.annotations.NotNull)9 PurpleDatamodelTest (com.hartwig.hmftools.common.purple.PurpleDatamodelTest)6 StructuralVariantLeg (com.hartwig.hmftools.common.variant.structural.StructuralVariantLeg)6 Test (org.junit.Test)6 PurityAdjuster (com.hartwig.hmftools.common.purple.PurityAdjuster)5 PurityContext (com.hartwig.hmftools.common.purple.purity.PurityContext)4 ImmutablePurpleCopyNumber (com.hartwig.hmftools.common.purple.copynumber.ImmutablePurpleCopyNumber)3 GeneCopyNumber (com.hartwig.hmftools.common.gene.GeneCopyNumber)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 VariantReport (com.hartwig.hmftools.patientreporter.variants.VariantReport)2 CommandLine (org.apache.commons.cli.CommandLine)2 Options (org.apache.commons.cli.Options)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 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