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