Search in sources :

Example 6 with VariantAnnotation

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

the class BachelorEligibility method processVariant.

@NotNull
private Collection<EligibilityReport> processVariant(final VariantContext variant, final String patient, final String sample, final EligibilityReport.ReportType type) {
    if (variant.isFiltered()) {
        return Collections.emptyList();
    }
    // we will skip when an ALT is not present in the sample
    final Genotype genotype = variant.getGenotype(sample);
    if (genotype == null || !(genotype.isHomVar() || genotype.isHet())) {
        return Collections.emptyList();
    }
    // gather up the relevant alleles
    VariantModel sampleVariant = new VariantModel(sample, variant);
    // for(SnpEff snpEff : sampleVariant.SampleAnnotations)
    // {
    // if(snpEff.Transcript.contains("ENST00000357654"))
    // {
    // LOGGER.debug("matched SAMPLED transcriptId: gene({}) allele({}) effects({})",
    // snpEff.GeneName, snpEff.getAllele(), snpEff.AllEffects);
    // 
    // for(String effect : snpEff.Effects)
    // {
    // LOGGER.debug("transcript({}) with effect({})", snpEff.Transcript, effect);
    // }
    // }
    // }
    // apply the all relevant tests to see if this program has been matched
    final List<String> matchingPrograms = programs.stream().filter(program -> program.vcfProcessor().test(sampleVariant)).map(BachelorProgram::name).collect(Collectors.toList());
    List<EligibilityReport> reportList = Lists.newArrayList();
    if (matchingPrograms.size() > 0) {
        // found a match, not collect up the details and write them to the output file
        LOGGER.info("program match found, first entry({}) ", matchingPrograms.get(0));
    }
    // just apply the search criteria once, and create a report for any full match
    for (BachelorProgram program : programs) {
        if (!program.vcfProcessor().test(sampleVariant)) {
            continue;
        }
        String programName = program.name();
        // found a match, not collect up the details and write them to the output file
        LOGGER.info("match found: program({}) ", programName);
        for (VariantAnnotation snpEff : sampleVariant.sampleAnnotations()) {
            // re-check that this variant is one that is relevant
            if (!program.panelTranscripts().contains(snpEff.featureID())) {
                LOGGER.debug("uninteresting transcript({})", snpEff.featureID());
                continue;
            }
            boolean found = false;
            for (String requiredEffect : program.requiredEffects()) {
                if (snpEff.effects().contains(requiredEffect)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                LOGGER.debug("uninteresting effects({})", snpEff.effects());
                continue;
            }
            // now we have the correct allele and transcript ID as required by the XML
            // so write a complete record to the output file
            LOGGER.info("matched allele({}) transcriptId({}) effect({})", snpEff.allele(), snpEff.featureID(), snpEff.effects());
            EligibilityReport report = ImmutableEligibilityReport.builder().patient(patient).source(type).program(programName).id(variant.getID()).genes(snpEff.gene()).transcriptId(snpEff.featureID()).chrom(variant.getContig()).pos(variant.getStart()).ref(variant.getReference().toString()).alts(snpEff.allele()).effects(snpEff.effects()).build();
            reportList.add(report);
        }
    }
    if (!reportList.isEmpty()) {
        LOGGER.info("writing {} matched reports", reportList.size());
    }
    return reportList;
// final String alts = variant.getAlternateAlleles().stream().map(Object::toString).collect(Collectors.joining("|"));
// final String effects = String.join("|", sampleVariant.SampleAnnotations.stream().flatMap(a -> a.Effects.stream()).collect(Collectors.toSet()));
// final String genes = String.join("|", sampleVariant.SampleAnnotations.stream().map(a -> a.GeneName).collect(Collectors.toSet()));
// return matchingPrograms.stream()
// .map(p -> ImmutableEligibilityReport.builder()
// .patient(patient)
// .source(type)
// .program(p)
// .id(variant.getID())
// .genes(genes)
// .transcriptId("TransId")
// .chrom(variant.getContig())
// .pos(variant.getStart())
// .ref(variant.getReference().toString())
// .alts(alts)
// .effects(effects)
// .build())
// .collect(Collectors.toList());
}
Also used : Genotype(htsjdk.variant.variantcontext.Genotype) VariantAnnotation(com.hartwig.hmftools.common.variant.snpeff.VariantAnnotation) NotNull(org.jetbrains.annotations.NotNull)

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