Search in sources :

Example 1 with VariantAnnotation

use of com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation 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());
}
Also used : SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) Slicer(com.hartwig.hmftools.common.slicing.Slicer) ImmutableVariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.ImmutableVariantAnnotation) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation) VariantConsequence(com.hartwig.hmftools.common.variant.VariantConsequence) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) ImmutableHmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.ImmutableHmfGenomeRegion) GenomeRegion(com.hartwig.hmftools.common.region.GenomeRegion) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) ImmutableHmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.ImmutableHmfGenomeRegion) ImmutableSomaticVariantImpl(com.hartwig.hmftools.common.variant.ImmutableSomaticVariantImpl) ImmutableVariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.ImmutableVariantAnnotation) Test(org.junit.Test)

Example 2 with VariantAnnotation

use of com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation 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());
}
Also used : SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation) GeneModel(com.hartwig.hmftools.common.gene.GeneModel) Test(org.junit.Test)

Example 3 with VariantAnnotation

use of com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation 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;
}
Also used : SomaticVariant(com.hartwig.hmftools.common.variant.SomaticVariant) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with VariantAnnotation

use of com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation in project hmftools by hartwigmedical.

the class EnrichedSomaticVariantFactory method addCanonicalEffect.

private void addCanonicalEffect(@NotNull final Builder builder, @NotNull final SomaticVariant variant) {
    final Optional<VariantAnnotation> canonicalAnnotation = canonicalAnnotationSelector.canonical(variant.gene(), variant.annotations());
    if (canonicalAnnotation.isPresent()) {
        final VariantAnnotation annotation = canonicalAnnotation.get();
        builder.canonicalEffect(annotation.consequenceString());
        builder.canonicalCodingEffect(CodingEffect.effect(annotation.consequences()).toString());
    } else {
        builder.canonicalEffect(Strings.EMPTY);
        builder.canonicalCodingEffect(Strings.EMPTY);
    }
}
Also used : VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation)

Example 5 with VariantAnnotation

use of com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation in project hmftools by hartwigmedical.

the class SomaticVariantFactory method attachAnnotations.

private void attachAnnotations(@NotNull final ImmutableSomaticVariantImpl.Builder builder, @NotNull VariantContext context) {
    final List<VariantAnnotation> allAnnotations = VariantAnnotationFactory.fromContext(context);
    builder.annotations(allAnnotations);
    final List<VariantAnnotation> transcriptAnnotations = allAnnotations.stream().filter(x -> x.featureType().equals("transcript")).collect(Collectors.toList());
    if (!transcriptAnnotations.isEmpty()) {
        final VariantAnnotation variantAnnotation = transcriptAnnotations.get(0);
        builder.gene(variantAnnotation.gene());
        builder.worstEffect(variantAnnotation.consequenceString());
        builder.worstCodingEffect(CodingEffect.effect(variantAnnotation.consequences()).toString());
        builder.worstEffectTranscript(variantAnnotation.featureID());
    } else {
        builder.gene("");
        builder.worstEffect("");
        builder.worstCodingEffect(CodingEffect.NONE.toString());
        builder.worstEffectTranscript("");
    }
    builder.genesEffected((int) transcriptAnnotations.stream().map(VariantAnnotation::gene).filter(x -> !x.isEmpty()).distinct().count());
}
Also used : Genotype(htsjdk.variant.variantcontext.Genotype) Allele(htsjdk.variant.variantcontext.Allele) Arrays(java.util.Arrays) LineIterator(htsjdk.tribble.readers.LineIterator) VCFHeader(htsjdk.variant.vcf.VCFHeader) PassingVariantFilter(htsjdk.variant.variantcontext.filter.PassingVariantFilter) AbstractFeatureReader(htsjdk.tribble.AbstractFeatureReader) AbstractFeatureReader.getFeatureReader(htsjdk.tribble.AbstractFeatureReader.getFeatureReader) Lists(com.google.common.collect.Lists) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation) CompoundFilter(htsjdk.variant.variantcontext.filter.CompoundFilter) VCFCodec(htsjdk.variant.vcf.VCFCodec) ChromosomeFilter(com.hartwig.hmftools.common.variant.filter.ChromosomeFilter) VariantContextFilter(htsjdk.variant.variantcontext.filter.VariantContextFilter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) VariantAnnotationFactory(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotationFactory) List(java.util.List) StringJoiner(java.util.StringJoiner) HotspotFilter(com.hartwig.hmftools.common.variant.filter.HotspotFilter) Optional(java.util.Optional) VariantContext(htsjdk.variant.variantcontext.VariantContext) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation)

Aggregations

VariantAnnotation (com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation)6 SomaticVariant (com.hartwig.hmftools.common.variant.SomaticVariant)3 NotNull (org.jetbrains.annotations.NotNull)3 HmfGenomeRegion (com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion)2 Genotype (htsjdk.variant.variantcontext.Genotype)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Lists (com.google.common.collect.Lists)1 GeneModel (com.hartwig.hmftools.common.gene.GeneModel)1 GenomeRegion (com.hartwig.hmftools.common.region.GenomeRegion)1 ImmutableHmfGenomeRegion (com.hartwig.hmftools.common.region.hmfslicer.ImmutableHmfGenomeRegion)1 Slicer (com.hartwig.hmftools.common.slicing.Slicer)1 ImmutableSomaticVariantImpl (com.hartwig.hmftools.common.variant.ImmutableSomaticVariantImpl)1 VariantConsequence (com.hartwig.hmftools.common.variant.VariantConsequence)1 ChromosomeFilter (com.hartwig.hmftools.common.variant.filter.ChromosomeFilter)1 HotspotFilter (com.hartwig.hmftools.common.variant.filter.HotspotFilter)1 ImmutableVariantAnnotation (com.hartwig.hmftools.common.variant.snpeff.ImmutableVariantAnnotation)1 VariantAnnotationFactory (com.hartwig.hmftools.common.variant.snpeff.VariantAnnotationFactory)1 AbstractFeatureReader (htsjdk.tribble.AbstractFeatureReader)1