use of com.hartwig.hmftools.common.purple.region.FittedRegion 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.region.FittedRegion in project hmftools by hartwigmedical.
the class CopyNumberDAO method readCopyNumberRegions.
@NotNull
List<FittedRegion> readCopyNumberRegions(@NotNull final String sample) {
List<FittedRegion> fittedRegions = Lists.newArrayList();
Result<Record> result = context.select().from(COPYNUMBERREGION).where(COPYNUMBERREGION.SAMPLEID.eq(sample)).fetch();
for (Record record : result) {
fittedRegions.add(ImmutableFittedRegion.builder().chromosome(record.getValue(COPYNUMBERREGION.CHROMOSOME)).start(record.getValue(COPYNUMBERREGION.START)).end(record.getValue(COPYNUMBERREGION.END)).status(GermlineStatus.valueOf(record.getValue(COPYNUMBERREGION.GERMLINESTATUS))).svCluster(record.getValue(COPYNUMBERREGION.SVCLUSTER) != 0).ratioSupport(record.getValue(COPYNUMBERREGION.RATIOSUPPORT) != 0).support(SegmentSupport.valueOf(record.getValue(COPYNUMBERREGION.SEGMENTSTARTSUPPORT))).bafCount(record.getValue(COPYNUMBERREGION.BAFCOUNT)).observedBAF(record.getValue(COPYNUMBERREGION.OBSERVEDBAF)).observedTumorRatio(record.getValue(COPYNUMBERREGION.OBSERVEDTUMORRATIO)).observedNormalRatio(record.getValue(COPYNUMBERREGION.OBSERVEDNORMALRATIO)).observedTumorRatioCount(record.getValue(COPYNUMBERREGION.OBSERVEDTUMORRATIOCOUNT)).gcContent(record.getValue(COPYNUMBERREGION.GCCONTENT)).modelPloidy(record.getValue(COPYNUMBERREGION.MODELPLOIDY)).modelBAF(record.getValue(COPYNUMBERREGION.MODELBAF)).modelTumorRatio(record.getValue(COPYNUMBERREGION.MODELTUMORRATIO)).tumorBAF(record.getValue(COPYNUMBERREGION.ACTUALTUMORBAF)).tumorCopyNumber(record.getValue(COPYNUMBERREGION.ACTUALTUMORCOPYNUMBER)).refNormalisedCopyNumber(record.getValue(COPYNUMBERREGION.REFNORMALISEDTUMORCOPYNUMBER)).cnvDeviation(record.getValue(COPYNUMBERREGION.CNVDEVIATION)).bafDeviation(record.getValue(COPYNUMBERREGION.BAFDEVIATION)).deviation(record.getValue(COPYNUMBERREGION.TOTALDEVIATION)).segmentBAF(record.getValue(COPYNUMBERREGION.FITTEDBAF)).segmentTumorCopyNumber(record.getValue(COPYNUMBERREGION.FITTEDCOPYNUMBER)).ploidyPenalty(record.getValue(COPYNUMBERREGION.PLOIDYPENALTY)).build());
}
Collections.sort(fittedRegions);
return fittedRegions;
}
use of com.hartwig.hmftools.common.purple.region.FittedRegion in project hmftools by hartwigmedical.
the class CopyNumberDAO method writeCopyNumberRegions.
void writeCopyNumberRegions(@NotNull final String sample, @NotNull List<FittedRegion> regions) {
Timestamp timestamp = new Timestamp(new Date().getTime());
context.delete(COPYNUMBERREGION).where(COPYNUMBERREGION.SAMPLEID.eq(sample)).execute();
for (List<FittedRegion> splitRegions : Iterables.partition(regions, DB_BATCH_INSERT_SIZE)) {
InsertValuesStepN inserter = context.insertInto(COPYNUMBERREGION, COPYNUMBERREGION.SAMPLEID, COPYNUMBERREGION.CHROMOSOME, COPYNUMBERREGION.START, COPYNUMBERREGION.END, COPYNUMBERREGION.GERMLINESTATUS, COPYNUMBERREGION.SVCLUSTER, COPYNUMBERREGION.RATIOSUPPORT, COPYNUMBERREGION.SEGMENTSTARTSUPPORT, COPYNUMBERREGION.BAFCOUNT, COPYNUMBERREGION.OBSERVEDBAF, COPYNUMBERREGION.OBSERVEDTUMORRATIO, COPYNUMBERREGION.OBSERVEDNORMALRATIO, COPYNUMBERREGION.OBSERVEDTUMORRATIOCOUNT, COPYNUMBERREGION.GCCONTENT, COPYNUMBERREGION.MODELPLOIDY, COPYNUMBERREGION.MODELBAF, COPYNUMBERREGION.MODELTUMORRATIO, COPYNUMBERREGION.ACTUALTUMORBAF, COPYNUMBERREGION.ACTUALTUMORCOPYNUMBER, COPYNUMBERREGION.REFNORMALISEDTUMORCOPYNUMBER, COPYNUMBERREGION.CNVDEVIATION, COPYNUMBERREGION.BAFDEVIATION, COPYNUMBERREGION.TOTALDEVIATION, COPYNUMBERREGION.PLOIDYPENALTY, COPYNUMBERREGION.FITTEDBAF, COPYNUMBERREGION.FITTEDCOPYNUMBER, COPYNUMBERREGION.MODIFIED);
splitRegions.forEach(x -> addCopynumberRecord(timestamp, inserter, sample, x));
inserter.execute();
}
}
use of com.hartwig.hmftools.common.purple.region.FittedRegion in project hmftools by hartwigmedical.
the class CopyNumberDeviationTest method testMaxCopyNumberDeviation.
@Test
public void testMaxCopyNumberDeviation() {
final FittedRegion firstWithSV = create(1, 1000, SegmentSupport.MULTIPLE);
final FittedRegion firstWithoutSV = create(1, 1000, SegmentSupport.NONE);
final FittedRegion secondWithSV = create(1001, 2000, SegmentSupport.MULTIPLE);
final FittedRegion secondWithoutSV = create(1001, 2000, SegmentSupport.NONE);
final FittedRegion thirdWithSV = create(2001, 3000, SegmentSupport.MULTIPLE);
final FittedRegion thirdWithoutSV = create(2001, 3000, SegmentSupport.NONE);
assertEquals(HC_MAX_COPY_NUMBER_TOLERANCE, CopyNumberDeviation.maxCopyNumberDeviation(secondWithSV, firstWithSV), EPSILON);
assertEquals(HC_MAX_COPY_NUMBER_TOLERANCE, CopyNumberDeviation.maxCopyNumberDeviation(secondWithSV, firstWithoutSV), EPSILON);
assertEquals(HC_MAX_COPY_NUMBER_TOLERANCE, CopyNumberDeviation.maxCopyNumberDeviation(secondWithSV, thirdWithSV), EPSILON);
assertEquals(LC_MAX_COPY_NUMBER_TOLERANCE, CopyNumberDeviation.maxCopyNumberDeviation(secondWithSV, thirdWithoutSV), EPSILON);
assertEquals(LC_MAX_COPY_NUMBER_TOLERANCE, CopyNumberDeviation.maxCopyNumberDeviation(secondWithoutSV, firstWithSV), EPSILON);
assertEquals(LC_MAX_COPY_NUMBER_TOLERANCE, CopyNumberDeviation.maxCopyNumberDeviation(secondWithoutSV, firstWithoutSV), EPSILON);
assertEquals(HC_MAX_COPY_NUMBER_TOLERANCE, CopyNumberDeviation.maxCopyNumberDeviation(secondWithoutSV, thirdWithSV), EPSILON);
assertEquals(LC_MAX_COPY_NUMBER_TOLERANCE, CopyNumberDeviation.maxCopyNumberDeviation(secondWithoutSV, thirdWithoutSV), EPSILON);
}
use of com.hartwig.hmftools.common.purple.region.FittedRegion in project hmftools by hartwigmedical.
the class ExtendDiploidTest method testDubiousRegionGetsIncludedFromLeft.
@Test
public void testDubiousRegionGetsIncludedFromLeft() {
final FittedRegion somaticLeft = createValidSomatic(1, 10000, 3.0, 50, SegmentSupport.BND);
final FittedRegion dubious = createDubiousRegion(10001, 20000, 2.0, 10);
final FittedRegion somaticRight = createValidSomatic(20001, 30000, 3.0, 40, SegmentSupport.NONE);
final List<CombinedRegion> result = PURE_VICTIM.extendDiploid(Lists.newArrayList(somaticLeft, dubious, somaticRight));
assertEquals(1, result.size());
assertRegion(1, 30000, 3, result.get(0));
}
Aggregations