use of com.hartwig.hmftools.common.variant.SomaticVariant in project hmftools by hartwigmedical.
the class ConsequenceDeterminerTest method worksAsExpected.
@Test
public void worksAsExpected() {
final SortedSetMultimap<String, GenomeRegion> regionMap = TreeMultimap.create();
GenomeRegion testRegion = GenomeRegionFactory.create(CHROMOSOME, POSITION - 10, POSITION + 10);
regionMap.put(testRegion.chromosome(), testRegion);
final Slicer slicer = SlicerFactory.fromRegions(regionMap);
final Map<String, HmfGenomeRegion> transcriptMap = Maps.newHashMap();
transcriptMap.put(TRANSCRIPT, hmfRegion());
final ConsequenceDeterminer determiner = new ConsequenceDeterminer(slicer, transcriptMap);
final VariantConsequence rightConsequence = VariantConsequence.MISSENSE_VARIANT;
final VariantConsequence wrongConsequence = VariantConsequence.OTHER;
final ImmutableVariantAnnotation.Builder annotationBuilder = createVariantAnnotationBuilder().featureID(TRANSCRIPT).featureType(ConsequenceDeterminer.FEATURE_TYPE_TRANSCRIPT).gene(GENE).hgvsCoding(HGVS_CODING).hgvsProtein(HGVS_PROTEIN);
final VariantAnnotation rightAnnotation = annotationBuilder.consequences(Lists.newArrayList(rightConsequence)).build();
final VariantAnnotation wrongAnnotation = annotationBuilder.consequences(Lists.newArrayList(wrongConsequence)).build();
final ImmutableSomaticVariantImpl.Builder variantBuilder = SomaticVariantTestBuilderFactory.create().chromosome(CHROMOSOME).ref(REF).alt(ALT).cosmicID(COSMIC_ID).totalReadCount(TOTAL_READ_COUNT).alleleReadCount(ALLELE_READ_COUNT);
final SomaticVariant rightVariant = variantBuilder.position(POSITION).annotations(Lists.newArrayList(rightAnnotation)).build();
final SomaticVariant wrongConsequenceVariant = variantBuilder.position(POSITION).annotations(Lists.newArrayList(wrongAnnotation)).build();
final SomaticVariant wrongPositionVariant = variantBuilder.position(WRONG_POSITION).annotations(Lists.newArrayList(rightAnnotation)).build();
final List<VariantReport> findings = determiner.run(Lists.newArrayList(rightVariant, wrongConsequenceVariant, wrongPositionVariant)).findings();
assertEquals(1, findings.size());
final VariantReport report = findings.get(0);
assertEquals(GENE, report.gene());
assertEquals(CHROMOSOME + ":" + POSITION, report.variant().chromosomePosition());
assertEquals(REF, report.variant().ref());
assertEquals(ALT, report.variant().alt());
assertEquals(TRANSCRIPT + "." + TRANSCRIPT_VERSION, report.transcript());
assertEquals(HGVS_CODING, report.hgvsCoding());
assertEquals(HGVS_PROTEIN, report.hgvsProtein());
assertEquals(rightConsequence.readableSequenceOntologyTerm(), report.consequence());
assertEquals(COSMIC_ID, report.cosmicID());
assertEquals(TOTAL_READ_COUNT, report.totalReadCount());
assertEquals(ALLELE_READ_COUNT, report.alleleReadCount());
}
use of com.hartwig.hmftools.common.variant.SomaticVariant in project hmftools by hartwigmedical.
the class VariantAnalyzerTest method realCaseWorks.
@Test
public void realCaseWorks() {
final GeneModel geneModel = new GeneModel(hmfRegions());
final VariantAnalyzer analyzer = VariantAnalyzer.of(geneModel, testMicrosatelliteAnalyzer());
final VariantAnnotation rightAnnotation = createVariantAnnotationBuilder(VariantConsequence.MISSENSE_VARIANT).featureType(RIGHT_FEATURE_TYPE).featureID(RIGHT_TRANSCRIPT).build();
final VariantAnnotation wrongTranscript = createVariantAnnotationBuilder(VariantConsequence.MISSENSE_VARIANT).featureType(RIGHT_FEATURE_TYPE).featureID(WRONG_TRANSCRIPT).build();
final VariantAnnotation wrongFeatureType = createVariantAnnotationBuilder(VariantConsequence.MISSENSE_VARIANT).featureType(WRONG_FEATURE_TYPE).featureID(RIGHT_TRANSCRIPT).build();
final VariantAnnotation wrongConsequence = createVariantAnnotationBuilder(VariantConsequence.OTHER).featureType(RIGHT_FEATURE_TYPE).featureID(RIGHT_TRANSCRIPT).build();
final List<SomaticVariant> variants = Lists.newArrayList(builder().position(420).annotations(Lists.newArrayList(rightAnnotation, wrongTranscript)).build(), builder().position(430).annotations(Lists.newArrayList(wrongConsequence)).build(), builder().position(440).annotations(Lists.newArrayList(wrongFeatureType)).build(), builder().position(460).annotations(Lists.newArrayList(rightAnnotation)).build());
final VariantAnalysis analysis = analyzer.run(variants);
assertEquals(4, analysis.passedVariants().size());
assertEquals(3, analysis.mutationalLoad());
assertEquals(1, analysis.findings().size());
}
use of com.hartwig.hmftools.common.variant.SomaticVariant in project hmftools by hartwigmedical.
the class ConsequenceDeterminer method toVariantReport.
@NotNull
private List<VariantReport> toVariantReport(@NotNull final List<SomaticVariant> variants) {
final List<VariantReport> reports = Lists.newArrayList();
for (final SomaticVariant variant : variants) {
final ImmutableVariantReport.Builder builder = ImmutableVariantReport.builder();
final VariantAnnotation variantAnnotation = findPrimaryRelevantAnnotation(variant, relevantTranscriptMap.keySet());
// KODU: Variants with no relevant annotations should be filtered out by now.
assert variantAnnotation != null;
final HmfGenomeRegion hmfGenomeRegion = relevantTranscriptMap.get(variantAnnotation.featureID());
assert hmfGenomeRegion != null;
if (!variantAnnotation.gene().equals(hmfGenomeRegion.gene())) {
LOGGER.warn("Annotated gene does not match gene expected from slicing annotation for " + variant);
}
if (!variantAnnotation.allele().equals(variant.alt())) {
LOGGER.warn("Annotated allele does not match alt from variant for " + variant);
}
builder.variant(variant);
builder.gene(variantAnnotation.gene());
builder.transcript(hmfGenomeRegion.transcript());
builder.hgvsCoding(variantAnnotation.hgvsCoding());
builder.hgvsProtein(variantAnnotation.hgvsProtein());
builder.consequence(variantAnnotation.consequenceString());
final String cosmicID = variant.cosmicID();
if (cosmicID != null) {
builder.cosmicID(cosmicID);
}
builder.totalReadCount(variant.totalReadCount());
builder.alleleReadCount(variant.alleleReadCount());
reports.add(builder.build());
}
return reports;
}
use of com.hartwig.hmftools.common.variant.SomaticVariant 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.variant.SomaticVariant 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);
}
Aggregations