Beispiel #1
0
        public void FindRegion_Forward_Insertion()
        {
            var observedStart = MappedPositionUtilities.FindRegion(_forwardTranscriptRegions, ForwardVariantStart);
            var observedEnd   = MappedPositionUtilities.FindRegion(_forwardTranscriptRegions, ForwardVariantEnd);

            Assert.Equal(4, observedStart.Index);
            Assert.Equal(4, observedEnd.Index);
            Assert.NotNull(observedStart.Region);
            Assert.NotNull(observedEnd.Region);
        }
Beispiel #2
0
        public void FindRegion_Reverse_Deletion()
        {
            var observedStart = MappedPositionUtilities.FindRegion(_reverseTranscriptRegions, ReverseVariantStart);
            var observedEnd   = MappedPositionUtilities.FindRegion(_reverseTranscriptRegions, ReverseVariantEnd);

            Assert.Equal(6, observedStart.Index);
            Assert.Equal(7, observedEnd.Index);
            Assert.NotNull(observedStart.Region);
            Assert.NotNull(observedEnd.Region);
        }
        private static IMappedPosition GetMappedPosition(ITranscriptRegion[] regions, IInterval variant)
        {
            (int startIndex, _) = MappedPositionUtilities.FindRegion(regions, variant.Start);
            (int endIndex, _)   = MappedPositionUtilities.FindRegion(regions, variant.End);

            (int exonStart, int exonEnd, int intronStart, int intronEnd) = regions.GetExonsAndIntrons(startIndex, endIndex);

            return(new MappedPosition(-1, -1, -1, -1, -1, -1, exonStart, exonEnd, intronStart, intronEnd, startIndex,
                                      endIndex));
        }
Beispiel #4
0
        /// <summary>
        /// Adjust positions by alt allele length
        /// </summary>
        internal static (int Start, int End, string RefAllele, int RegionStart, int RegionEnd) ShiftDuplication(
            this ITranscriptRegion[] regions, int start, string altAllele, bool onReverseStrand)
        {
            int incrementLength = altAllele.Length;
            int dupStart        = onReverseStrand ? start + incrementLength - 1    : start - incrementLength;
            int dupEnd          = onReverseStrand ? dupStart - incrementLength + 1 : dupStart + incrementLength - 1;

            (int regionStart, _) = MappedPositionUtilities.FindRegion(regions, dupStart);
            (int regionEnd, _)   = MappedPositionUtilities.FindRegion(regions, dupEnd);

            return(dupStart, dupEnd, altAllele, regionStart, regionEnd);
        }
Beispiel #5
0
        public void GetHgvscAnnotation_in_intron_gap_substitution(int variantStart, int variantEnd, string reference, string alt,
                                                                  string transcriptRef, VariantType variantType, string expectedHgvsc)
        {
            var(startIndex, _) =
                MappedPositionUtilities.FindRegion(_gapTranscript.TranscriptRegions, variantStart);
            var(endIndex, _) =
                MappedPositionUtilities.FindRegion(_gapTranscript.TranscriptRegions, variantEnd);
            var variant       = new SimpleVariant(ChromosomeUtilities.Chr10, variantStart, variantEnd, reference, alt, variantType);
            var observedHgvsc =
                HgvsCodingNomenclature.GetHgvscAnnotation(_gapTranscript, variant, null, startIndex, endIndex, transcriptRef, null);

            Assert.Equal(expectedHgvsc, observedHgvsc);
        }
        internal static void GetGeneFusionsByTranscript(this Dictionary <string, IAnnotatedGeneFusion> transcriptIdToGeneFusions,
                                                        BreakEndAdjacency adjacency, ITranscript[] originTranscripts, ITranscript[] partnerTranscripts)
        {
            var geneFusions = new List <IGeneFusion>();

            foreach (var originTranscript in originTranscripts)
            {
                geneFusions.Clear();
                bool originOnReverseStrand = originTranscript.Gene.OnReverseStrand ^ adjacency.Origin.OnReverseStrand;
                (int originIndex, ITranscriptRegion originRegion) = MappedPositionUtilities.FindRegion(originTranscript.TranscriptRegions, adjacency.Origin.Position);

                int?originExon   = originRegion.Type == TranscriptRegionType.Exon ? (int?)originRegion.Id : null;
                int?originIntron = originRegion.Type == TranscriptRegionType.Intron ? (int?)originRegion.Id : null;

                foreach (var partnerTranscript in partnerTranscripts)
                {
                    bool partnerOnReverseStrand      = partnerTranscript.Gene.OnReverseStrand ^ adjacency.Partner.OnReverseStrand;
                    bool differentStrand             = originOnReverseStrand != partnerOnReverseStrand;
                    bool differentTranscriptSource   = originTranscript.Source != partnerTranscript.Source;
                    bool sameGeneSymbol              = originTranscript.Gene.Symbol == partnerTranscript.Gene.Symbol;
                    bool codingRegionAlreadyOverlaps = originTranscript.Translation.CodingRegion.Overlaps(partnerTranscript.Translation.CodingRegion);

                    if (differentStrand || differentTranscriptSource || sameGeneSymbol || codingRegionAlreadyOverlaps)
                    {
                        continue;
                    }

                    (int partnerIndex, ITranscriptRegion partnerRegion) = MappedPositionUtilities.FindRegion(partnerTranscript.TranscriptRegions, adjacency.Partner.Position);

                    int?partnerExon   = partnerRegion.Type == TranscriptRegionType.Exon ? (int?)partnerRegion.Id : null;
                    int?partnerIntron = partnerRegion.Type == TranscriptRegionType.Intron ? (int?)partnerRegion.Id : null;

                    BreakPointTranscript origin  = new BreakPointTranscript(originTranscript, adjacency.Origin.Position, originIndex);
                    BreakPointTranscript partner = new BreakPointTranscript(partnerTranscript, adjacency.Partner.Position, partnerIndex);
                    (BreakPointTranscript first, BreakPointTranscript second) = originOnReverseStrand ? (partner, origin) : (origin, partner);

                    string hgvsCoding = GetHgvsCoding(first, second);

                    geneFusions.Add(new GeneFusion(partnerExon, partnerIntron, hgvsCoding));
                }

                if (geneFusions.Count == 0)
                {
                    continue;
                }
                var annotatedGeneFusion = new AnnotatedGeneFusion(originExon, originIntron, geneFusions.ToArray());
                transcriptIdToGeneFusions[originTranscript.Id.WithVersion] = annotatedGeneFusion;
            }
        }
Beispiel #7
0
                        AltAminoAcids, string RefCodons, string AltCodons, string TranscriptAltAllele, string TranscriptRefAllele) AnnotateTranscript(ITranscript transcript, ISimpleVariant variant, AminoAcids aminoAcids, ISequence refSequence)
        {
            bool onReverseStrand = transcript.Gene.OnReverseStrand;
            var  start           = MappedPositionUtilities.FindRegion(transcript.TranscriptRegions, variant.Start);
            var  end             = MappedPositionUtilities.FindRegion(transcript.TranscriptRegions, variant.End);

            var position = GetMappedPosition(transcript.TranscriptRegions, start.Region, start.Index, end.Region,
                                             end.Index, variant, onReverseStrand, transcript.Translation?.CodingRegion, transcript.StartExonPhase,
                                             variant.Type == VariantType.insertion);

            var codingSequence = GetCodingSequence(transcript, refSequence);
            var cdnaSequence   = GetCdnaSequence(transcript, refSequence);

            string transcriptAltAllele = HgvsUtilities.GetTranscriptAllele(variant.AltAllele, onReverseStrand);
            var    codons = Codons.GetCodons(transcriptAltAllele, position.CdsStart, position.CdsEnd, position.ProteinStart, position.ProteinEnd, codingSequence);

            var aa = aminoAcids.Translate(codons.Reference, codons.Alternate);

            (aa, position.ProteinStart, position.ProteinEnd) = TryTrimAminoAcidsAndUpdateProteinPositions(aa, position.ProteinStart, position.ProteinEnd);

            (position.CoveredCdnaStart, position.CoveredCdnaEnd) = transcript.TranscriptRegions.GetCoveredCdnaPositions(position.CdnaStart, start.Index, position.CdnaEnd, end.Index, onReverseStrand);
            (position.CoveredCdsStart, position.CoveredCdsEnd, position.CoveredProteinStart, position.CoveredProteinEnd) = MappedPositionUtilities.GetCoveredCdsAndProteinPositions(position.CoveredCdnaStart, position.CoveredCdnaEnd, transcript.StartExonPhase, transcript.Translation?.CodingRegion);

            var            transcriptRefAllele = GetTranscriptRefAllele(position, cdnaSequence, variant, onReverseStrand);
            SequenceChange coveredAa;

            // only generate the covered version of ref & alt alleles when CDS start/end is -1
            if (position.CdsStart == -1 || position.CdsEnd == -1)
            {
                coveredAa = GetCoveredAa(aminoAcids, transcriptAltAllele, position.CoveredCdsStart, position.CoveredCdsEnd, position.CoveredProteinStart, position.CoveredProteinEnd, codingSequence);
                (coveredAa, position.CoveredProteinStart, position.CoveredProteinEnd) = TryTrimAminoAcidsAndUpdateProteinPositions(coveredAa, position.CoveredProteinStart, position.CoveredProteinEnd);
            }
            else
            {
                coveredAa = aa;
                position.CoveredProteinStart = position.ProteinStart;
                position.CoveredProteinEnd   = position.ProteinEnd;
            }


            var positionalEffect = GetPositionalEffect(transcript, variant, position, aa.Reference, aa.Alternate,
                                                       position.CoveredCdnaStart, position.CoveredCdnaEnd, position.CoveredCdsStart, position.CoveredCdsEnd);

            var variantEffect = new VariantEffect(positionalEffect, variant, transcript, aa.Reference, aa.Alternate,
                                                  codons.Reference, codons.Alternate, position.ProteinStart, coveredAa.Reference, coveredAa.Alternate);

            return(variantEffect, position, aa.Reference, aa.Alternate, codons.Reference, codons.Alternate, transcriptAltAllele, transcriptRefAllele);
        }
Beispiel #8
0
                         AltAminoAcids, string RefCodons, string AltCodons, string TranscriptAltAllele) AnnotateTranscript(ITranscript transcript, ISimpleVariant variant, AminoAcids aminoAcids,
                                                                                                                           ISequence refSequence)
        {
            var onReverseStrand = transcript.Gene.OnReverseStrand;
            var start           = MappedPositionUtilities.FindRegion(transcript.TranscriptRegions, variant.Start);
            var end             = MappedPositionUtilities.FindRegion(transcript.TranscriptRegions, variant.End);

            var position = GetMappedPosition(transcript.TranscriptRegions, start.Region, start.Index, end.Region,
                                             end.Index, variant, onReverseStrand, transcript.Translation?.CodingRegion, transcript.StartExonPhase,
                                             variant.Type == VariantType.insertion);

            var transcriptRefAllele = HgvsUtilities.GetTranscriptAllele(variant.RefAllele, onReverseStrand);
            var transcriptAltAllele = HgvsUtilities.GetTranscriptAllele(variant.AltAllele, onReverseStrand);

            var codingSequence = transcript.Translation == null
                ? null
                : new CodingSequence(refSequence, transcript.Translation.CodingRegion, transcript.TranscriptRegions,
                                     transcript.Gene.OnReverseStrand, transcript.StartExonPhase);

            var codons = Codons.GetCodons(transcriptRefAllele, transcriptAltAllele, position.CdsStart, position.CdsEnd,
                                          position.ProteinStart, position.ProteinEnd, codingSequence);

            var coveredCdna = transcript.TranscriptRegions.GetCoveredCdnaPositions(position.CdnaStart, start.Index,
                                                                                   position.CdnaEnd, end.Index, onReverseStrand);

            var coveredCds = MappedPositionUtilities.GetCoveredCdsPositions(coveredCdna.Start, coveredCdna.End,
                                                                            transcript.StartExonPhase, transcript.Translation?.CodingRegion);

            var aa = aminoAcids.Translate(codons.Reference, codons.Alternate);

            var positionalEffect = GetPositionalEffect(transcript, variant, position, aa.Reference, aa.Alternate,
                                                       coveredCdna.Start, coveredCdna.End, coveredCds.Start, coveredCds.End);

            var variantEffect = new VariantEffect(positionalEffect, variant, transcript, aa.Reference, aa.Alternate,
                                                  codons.Reference, codons.Alternate, position.ProteinStart);

            return(variantEffect, position, aa.Reference, aa.Alternate, codons.Reference, codons.Alternate,
                   transcriptAltAllele);
        }
        internal static IGeneFusionAnnotation GetGeneFusionAnnotation(IBreakEnd[] breakEnds, ITranscript transcript,
                                                                      ITranscript[] fusedTranscriptCandidates)
        {
            if (transcript.Translation == null || breakEnds == null || breakEnds.Length == 0)
            {
                return(null);
            }

            var desiredBreakEnd = GetBreakEndWithinCodingRegion(breakEnds, transcript.Chromosome, transcript.Translation.CodingRegion);

            if (desiredBreakEnd == null)
            {
                return(null);
            }

            var piece1 = MappedPositionUtilities.FindRegion(transcript.TranscriptRegions, desiredBreakEnd.Piece1.Position);
            int?exon   = piece1.Region.Type == TranscriptRegionType.Exon   ? (int?)piece1.Region.Id : null;
            int?intron = piece1.Region.Type == TranscriptRegionType.Intron ? (int?)piece1.Region.Id : null;

            var piece1Hgvs = GetBreakEndHgvs(transcript, piece1.Index, desiredBreakEnd.Piece1.Position, desiredBreakEnd.Piece1.IsSuffix);

            var geneFusions = new List <IGeneFusion>();

            foreach (var candidate in fusedTranscriptCandidates)
            {
                var piece2     = MappedPositionUtilities.FindRegion(candidate.TranscriptRegions, desiredBreakEnd.Piece2.Position);
                var geneFusion = GetGeneFusion(transcript, candidate, desiredBreakEnd.Piece2, piece2.Index,
                                               piece1Hgvs.Hgvs, piece1Hgvs.IsTranscriptSuffix);

                if (geneFusion != null)
                {
                    geneFusions.Add(geneFusion);
                }
            }

            return(geneFusions.Count == 0
                ? null
                : new GeneFusionAnnotation(exon, intron, geneFusions.ToArray()));
        }