Search in sources :

Example 1 with GeneAnnotation

use of com.hartwig.hmftools.svannotation.annotations.GeneAnnotation in project hmftools by hartwigmedical.

the class MySQLAnnotator method annotateBreakend.

@NotNull
private List<GeneAnnotation> annotateBreakend(@NotNull EnrichedStructuralVariant variant, final boolean isStart, @NotNull String chromosome, final long position) {
    final List<GeneAnnotation> result = Lists.newArrayList();
    final Result<?> genes = queryGenesOnChromosomeAndPosition(chromosome, position);
    for (final Record gene : genes) {
        final UInteger geneId = gene.get(GENE.GENE_ID);
        final String geneName = gene.get(XREF.DISPLAY_LABEL);
        final String geneStableId = gene.get(GENE.STABLE_ID);
        final UInteger canonicalTranscriptId = gene.get(GENE.CANONICAL_TRANSCRIPT_ID);
        final int geneStrand = gene.get(GENE.SEQ_REGION_STRAND);
        final List<Integer> entrezIds = Arrays.stream(gene.get(ENTREZ_IDS, String.class).split(",")).map(Integer::parseInt).collect(Collectors.toList());
        final String karyotypeBand = gene.get(KARYOTYPE_BAND, String.class);
        final List<String> synonyms = context.select(XREF.DBPRIMARY_ACC).from(XREF).innerJoin(OBJECT_XREF).on(OBJECT_XREF.XREF_ID.eq(XREF.XREF_ID)).and(OBJECT_XREF.ENSEMBL_ID.eq(geneId)).and(OBJECT_XREF.ENSEMBL_OBJECT_TYPE.eq(ObjectXrefEnsemblObjectType.Gene)).fetch().stream().map(r -> r.get(XREF.DBPRIMARY_ACC)).collect(Collectors.toList());
        final GeneAnnotation geneAnnotation = new GeneAnnotation(variant, isStart, geneName, geneStableId, geneStrand, synonyms, entrezIds, karyotypeBand);
        final Result<?> transcripts = context.select(TRANSCRIPT.TRANSCRIPT_ID, TRANSCRIPT.STABLE_ID).from(TRANSCRIPT).where(TRANSCRIPT.GENE_ID.eq(geneId)).fetch();
        for (final Record transcriptRecord : transcripts) {
            Transcript transcript = buildTranscript(geneAnnotation, transcriptRecord, position, canonicalTranscriptId, geneStrand > 0);
            if (transcript != null) {
                geneAnnotation.addTranscript(transcript);
            }
        }
        if (!geneAnnotation.transcripts().isEmpty()) {
            result.add(geneAnnotation);
        }
    }
    return result;
}
Also used : UInteger(org.jooq.types.UInteger) EXON_TRANSCRIPT(org.ensembl.database.homo_sapiens_core.Tables.EXON_TRANSCRIPT) Arrays(java.util.Arrays) Connection(java.sql.Connection) DSL(org.jooq.impl.DSL) Xref(org.ensembl.database.homo_sapiens_core.tables.Xref) StructuralVariantAnnotation(com.hartwig.hmftools.svannotation.annotations.StructuralVariantAnnotation) SEQ_REGION(org.ensembl.database.homo_sapiens_core.Tables.SEQ_REGION) DSL.decode(org.jooq.impl.DSL.decode) ObjectXrefEnsemblObjectType(org.ensembl.database.homo_sapiens_core.enums.ObjectXrefEnsemblObjectType) TRANSCRIPT(org.ensembl.database.homo_sapiens_core.Tables.TRANSCRIPT) Condition(org.jooq.Condition) SQLException(java.sql.SQLException) Lists(com.google.common.collect.Lists) KARYOTYPE(org.ensembl.database.homo_sapiens_core.Tables.KARYOTYPE) UInteger(org.jooq.types.UInteger) GeneStatus(org.ensembl.database.homo_sapiens_core.enums.GeneStatus) DSLContext(org.jooq.DSLContext) SQLDialect(org.jooq.SQLDialect) EnrichedStructuralVariant(com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant) Record(org.jooq.Record) GeneAnnotation(com.hartwig.hmftools.svannotation.annotations.GeneAnnotation) OBJECT_XREF(org.ensembl.database.homo_sapiens_core.Tables.OBJECT_XREF) Result(org.jooq.Result) Collectors(java.util.stream.Collectors) Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) XREF(org.ensembl.database.homo_sapiens_core.Tables.XREF) COORD_SYSTEM(org.ensembl.database.homo_sapiens_core.Tables.COORD_SYSTEM) Nullable(org.jetbrains.annotations.Nullable) EXON(org.ensembl.database.homo_sapiens_core.Tables.EXON) List(java.util.List) DSL.groupConcatDistinct(org.jooq.impl.DSL.groupConcatDistinct) GENE(org.ensembl.database.homo_sapiens_core.Tables.GENE) NotNull(org.jetbrains.annotations.NotNull) DriverManager(java.sql.DriverManager) GeneAnnotation(com.hartwig.hmftools.svannotation.annotations.GeneAnnotation) Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) UInteger(org.jooq.types.UInteger) Record(org.jooq.Record) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GeneAnnotation

use of com.hartwig.hmftools.svannotation.annotations.GeneAnnotation in project hmftools by hartwigmedical.

the class GeneDisruptionData method from.

@NotNull
public static GeneDisruptionData from(@NotNull final GeneDisruption disruption) {
    final Transcript transcript = disruption.linkedAnnotation();
    final GeneAnnotation gene = transcript.parent();
    // TODO (KODU): Add upstream/downstream annotation
    // final boolean upstream = gene.variant().orientation(gene.isStart()) > 0;
    // + (upstream ? " Upstream" : " Downstream");
    final String geneContext = exonDescription(transcript);
    return ImmutableGeneDisruptionData.builder().chromosome(gene.variant().chromosome(gene.isStart())).gene(gene.geneName()).geneContext(geneContext).type(gene.variant().type().name()).copies(ploidyToCopiesString(gene.variant().ploidy())).chromosomeBand(gene.karyotypeBand()).build();
}
Also used : Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) GeneAnnotation(com.hartwig.hmftools.svannotation.annotations.GeneAnnotation) PatientReportFormat.ploidyToCopiesString(com.hartwig.hmftools.patientreporter.util.PatientReportFormat.ploidyToCopiesString) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GeneAnnotation

use of com.hartwig.hmftools.svannotation.annotations.GeneAnnotation in project hmftools by hartwigmedical.

the class StructuralVariantAnalyzer method processFusions.

@NotNull
private List<GeneFusion> processFusions(final List<StructuralVariantAnnotation> annotations) {
    // NERA: left is upstream, right is downstream
    final List<List<Pair<Transcript, Transcript>>> fusionsPerVariant = Lists.newArrayList();
    for (final StructuralVariantAnnotation annotation : annotations) {
        final List<Pair<Transcript, Transcript>> fusions = Lists.newArrayList();
        for (final GeneAnnotation startGene : annotation.start()) {
            final boolean startUpstream = isUpstream(startGene);
            for (final GeneAnnotation endGene : annotation.end()) {
                final boolean endUpstream = isUpstream(endGene);
                if (startUpstream == endUpstream) {
                    continue;
                }
                for (final Transcript t1 : intronic(startGene.transcripts())) {
                    for (final Transcript t2 : intronic(endGene.transcripts())) {
                        if (!isPotentiallyRelevantFusion(t1, t2)) {
                            continue;
                        }
                        if (startUpstream && t1.exonUpstreamPhase() == t2.exonDownstreamPhase()) {
                            fusions.add(Pair.of(t1, t2));
                        } else if (!startUpstream && t2.exonUpstreamPhase() == t1.exonDownstreamPhase()) {
                            fusions.add(Pair.of(t2, t1));
                        }
                    }
                }
            }
        }
        fusionsPerVariant.add(fusions);
    }
    return toReportableGeneFusions(fusionsPerVariant);
}
Also used : Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) GeneAnnotation(com.hartwig.hmftools.svannotation.annotations.GeneAnnotation) StructuralVariantAnnotation(com.hartwig.hmftools.svannotation.annotations.StructuralVariantAnnotation) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GeneAnnotation

use of com.hartwig.hmftools.svannotation.annotations.GeneAnnotation in project hmftools by hartwigmedical.

the class StructuralVariantAnalyzer method processDisruptions.

@NotNull
private List<GeneDisruption> processDisruptions(final List<StructuralVariantAnnotation> annotations) {
    final List<GeneAnnotation> geneAnnotations = Lists.newArrayList();
    for (final StructuralVariantAnnotation annotation : annotations) {
        @SuppressWarnings("ConstantConditions") final boolean pureIntronicDisruptionCanonical = annotation.start().stream().filter(gene -> gene.canonical() != null).anyMatch(gene -> annotation.end().stream().filter(other -> other.canonical() != null).anyMatch(other -> intronicDisruptionOnSameTranscript(gene.canonical(), other.canonical())));
        if (pureIntronicDisruptionCanonical && annotation.variant().type() != StructuralVariantType.INV) {
            continue;
        }
        geneAnnotations.addAll(annotation.annotations());
    }
    final Multimap<String, GeneAnnotation> geneMap = ArrayListMultimap.create();
    geneAnnotations.forEach(g -> geneMap.put(g.geneName(), g));
    final List<GeneDisruption> disruptions = Lists.newArrayList();
    for (final String geneName : geneMap.keySet()) {
        for (final GeneAnnotation gene : geneMap.get(geneName)) {
            for (final Transcript transcript : gene.transcripts()) {
                final GeneDisruption disruption = ImmutableGeneDisruption.builder().reportable(inHmfPanel(gene) && transcript.isCanonical()).linkedAnnotation(transcript).build();
                disruptions.add(disruption);
            }
        }
    }
    return disruptions;
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) StructuralVariantAnnotation(com.hartwig.hmftools.svannotation.annotations.StructuralVariantAnnotation) ImmutableGeneDisruption(com.hartwig.hmftools.svannotation.annotations.ImmutableGeneDisruption) HmfGenomeRegion(com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion) Multimap(com.google.common.collect.Multimap) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) StructuralVariantType(com.hartwig.hmftools.common.variant.structural.StructuralVariantType) CosmicFusionData(com.hartwig.hmftools.common.cosmic.fusions.CosmicFusionData) EnrichedStructuralVariant(com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant) GeneDisruption(com.hartwig.hmftools.svannotation.annotations.GeneDisruption) GeneAnnotation(com.hartwig.hmftools.svannotation.annotations.GeneAnnotation) VariantAnnotator(com.hartwig.hmftools.svannotation.VariantAnnotator) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Logger(org.apache.logging.log4j.Logger) GeneFusion(com.hartwig.hmftools.svannotation.annotations.GeneFusion) CosmicFusionModel(com.hartwig.hmftools.common.cosmic.fusions.CosmicFusionModel) Optional(java.util.Optional) ImmutableGeneFusion(com.hartwig.hmftools.svannotation.annotations.ImmutableGeneFusion) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull) LogManager(org.apache.logging.log4j.LogManager) GeneAnnotation(com.hartwig.hmftools.svannotation.annotations.GeneAnnotation) Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) StructuralVariantAnnotation(com.hartwig.hmftools.svannotation.annotations.StructuralVariantAnnotation) ImmutableGeneDisruption(com.hartwig.hmftools.svannotation.annotations.ImmutableGeneDisruption) GeneDisruption(com.hartwig.hmftools.svannotation.annotations.GeneDisruption) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GeneAnnotation

use of com.hartwig.hmftools.svannotation.annotations.GeneAnnotation in project hmftools by hartwigmedical.

the class StructuralVariantAnnotationDAO method write.

@SuppressWarnings("unchecked")
public void write(final StructuralVariantAnalysis analysis) {
    final Timestamp timestamp = new Timestamp(new Date().getTime());
    final Map<Transcript, Integer> id = Maps.newHashMap();
    // NERA: load transcript annotations
    for (final StructuralVariantAnnotation annotation : analysis.annotations()) {
        for (final GeneAnnotation geneAnnotation : annotation.annotations()) {
            final InsertValuesStep13 inserter = context.insertInto(STRUCTURALVARIANTBREAKEND, STRUCTURALVARIANTBREAKEND.MODIFIED, STRUCTURALVARIANTBREAKEND.ISSTARTEND, STRUCTURALVARIANTBREAKEND.STRUCTURALVARIANTID, STRUCTURALVARIANTBREAKEND.GENE, STRUCTURALVARIANTBREAKEND.GENEID, STRUCTURALVARIANTBREAKEND.TRANSCRIPTID, STRUCTURALVARIANTBREAKEND.ISCANONICALTRANSCRIPT, STRUCTURALVARIANTBREAKEND.STRAND, STRUCTURALVARIANTBREAKEND.EXONRANKUPSTREAM, STRUCTURALVARIANTBREAKEND.EXONPHASEUPSTREAM, STRUCTURALVARIANTBREAKEND.EXONRANKDOWNSTREAM, STRUCTURALVARIANTBREAKEND.EXONPHASEDOWNSTREAM, STRUCTURALVARIANTBREAKEND.EXONMAX);
            for (final Transcript transcript : geneAnnotation.transcripts()) {
                inserter.values(timestamp, geneAnnotation.isStart(), transcript.parent().variant().primaryKey(), geneAnnotation.geneName(), geneAnnotation.stableId(), transcript.transcriptId(), transcript.isCanonical(), geneAnnotation.strand(), transcript.exonUpstream(), transcript.exonUpstreamPhase(), transcript.exonDownstream(), transcript.exonDownstreamPhase(), transcript.exonMax());
            }
            final List<UInteger> ids = inserter.returning(STRUCTURALVARIANTBREAKEND.ID).fetch().getValues(0, UInteger.class);
            if (ids.size() != geneAnnotation.transcripts().size()) {
                throw new RuntimeException("not all transcripts were inserted successfully");
            }
            for (int i = 0; i < ids.size(); i++) {
                id.put(geneAnnotation.transcripts().get(i), ids.get(i).intValue());
            }
        }
    }
    // NERA: load fusions
    final InsertValuesStep3 fusionInserter = context.insertInto(STRUCTURALVARIANTFUSION, STRUCTURALVARIANTFUSION.ISREPORTED, STRUCTURALVARIANTFUSION.FIVEPRIMEBREAKENDID, STRUCTURALVARIANTFUSION.THREEPRIMEBREAKENDID);
    for (final GeneFusion fusion : analysis.fusions()) {
        fusionInserter.values(fusion.reportable(), id.get(fusion.upstreamLinkedAnnotation()), id.get(fusion.downstreamLinkedAnnotation()));
    }
    fusionInserter.execute();
    // NERA: load disruptions
    final InsertValuesStep2 disruptionInserter = context.insertInto(STRUCTURALVARIANTDISRUPTION, STRUCTURALVARIANTDISRUPTION.ISREPORTED, STRUCTURALVARIANTDISRUPTION.BREAKENDID);
    for (final GeneDisruption disruption : analysis.disruptions()) {
        disruptionInserter.values(disruption.reportable(), id.get(disruption.linkedAnnotation()));
    }
    disruptionInserter.execute();
}
Also used : Transcript(com.hartwig.hmftools.svannotation.annotations.Transcript) GeneAnnotation(com.hartwig.hmftools.svannotation.annotations.GeneAnnotation) StructuralVariantAnnotation(com.hartwig.hmftools.svannotation.annotations.StructuralVariantAnnotation) GeneDisruption(com.hartwig.hmftools.svannotation.annotations.GeneDisruption) InsertValuesStep13(org.jooq.InsertValuesStep13) Timestamp(java.sql.Timestamp) Date(java.util.Date) UInteger(org.jooq.types.UInteger) GeneFusion(com.hartwig.hmftools.svannotation.annotations.GeneFusion) UInteger(org.jooq.types.UInteger) InsertValuesStep2(org.jooq.InsertValuesStep2) InsertValuesStep3(org.jooq.InsertValuesStep3)

Aggregations

GeneAnnotation (com.hartwig.hmftools.svannotation.annotations.GeneAnnotation)5 Transcript (com.hartwig.hmftools.svannotation.annotations.Transcript)5 StructuralVariantAnnotation (com.hartwig.hmftools.svannotation.annotations.StructuralVariantAnnotation)4 NotNull (org.jetbrains.annotations.NotNull)4 List (java.util.List)3 Lists (com.google.common.collect.Lists)2 EnrichedStructuralVariant (com.hartwig.hmftools.common.variant.structural.EnrichedStructuralVariant)2 GeneDisruption (com.hartwig.hmftools.svannotation.annotations.GeneDisruption)2 GeneFusion (com.hartwig.hmftools.svannotation.annotations.GeneFusion)2 Collectors (java.util.stream.Collectors)2 Pair (org.apache.commons.lang3.tuple.Pair)2 Nullable (org.jetbrains.annotations.Nullable)2 UInteger (org.jooq.types.UInteger)2 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Multimap (com.google.common.collect.Multimap)1 CosmicFusionData (com.hartwig.hmftools.common.cosmic.fusions.CosmicFusionData)1 CosmicFusionModel (com.hartwig.hmftools.common.cosmic.fusions.CosmicFusionModel)1 HmfGenomeRegion (com.hartwig.hmftools.common.region.hmfslicer.HmfGenomeRegion)1 StructuralVariantType (com.hartwig.hmftools.common.variant.structural.StructuralVariantType)1 PatientReportFormat.ploidyToCopiesString (com.hartwig.hmftools.patientreporter.util.PatientReportFormat.ploidyToCopiesString)1