Exemplo n.º 1
0
        public VariantEffect(TranscriptPositionalEffect transcriptEffect, ISimpleVariant variant, ITranscript transcript,
                             string referenAminoAcids, string alternateAminoAcids, string referenceCodons, string alternateCodons,
                             int?proteinBegin, string coveredReferenceAminoAcids, string coveredAlternateAminoAcids, VariantEffectCache cache = null)
        {
            _transcript = transcript;
            _variant    = variant;

            _preCache = transcriptEffect;

            _cache = cache ?? new VariantEffectCache();

            _referenceAminoAcids    = referenAminoAcids;
            _alternateAminoAcids    = alternateAminoAcids;
            _referenceAminoAcidsLen = _referenceAminoAcids?.Length ?? 0;
            _alternateAminoAcidsLen = _alternateAminoAcids?.Length ?? 0;

            _coveredReferenceAminoAcids = coveredReferenceAminoAcids;
            _coveredAlternateAminoAcids = coveredAlternateAminoAcids;

            _referenceCodons    = referenceCodons;
            _alternateCodons    = alternateCodons;
            _referenceCodonsLen = _referenceCodons?.Length ?? 0;
            _alternateCodonsLen = _alternateCodons?.Length ?? 0;

            _isInsertion = variant.AltAllele.Length > variant.RefAllele.Length;
            _isDeletion  = variant.AltAllele.Length < variant.RefAllele.Length;

            _proteinBegin = proteinBegin ?? -1;
        }
Exemplo n.º 2
0
        private static string GetRotatingBases(ISimpleVariant simpleVariant, bool onReverseStrand)
        {
            string rotatingBases = simpleVariant.Type == VariantType.insertion ? simpleVariant.AltAllele : simpleVariant.RefAllele;

            rotatingBases = onReverseStrand ? SequenceUtilities.GetReverseComplement(rotatingBases) : rotatingBases;
            return(rotatingBases);
        }
Exemplo n.º 3
0
        public static string GetHgvscAnnotation(ITranscript transcript, ISimpleVariant variant, ISequence refSequence,
                                                int regionStart, int regionEnd)
        {
            // sanity check: don't try to handle odd characters, make sure this is not a reference allele,
            //               and make sure that we have protein coordinates
            if (variant.Type == VariantType.reference || SequenceUtilities.HasNonCanonicalBase(variant.AltAllele))
            {
                return(null);
            }

            var onReverseStrand = transcript.Gene.OnReverseStrand;

            var refAllele = onReverseStrand ? SequenceUtilities.GetReverseComplement(variant.RefAllele) : variant.RefAllele;
            var altAllele = onReverseStrand ? SequenceUtilities.GetReverseComplement(variant.AltAllele) : variant.AltAllele;

            // decide event type from HGVS nomenclature
            var genomicChange = GetGenomicChange(transcript, onReverseStrand, refSequence, variant);

            var variantStart = variant.Start;
            var variantEnd   = variant.End;

            if (genomicChange == GenomicChange.Duplication)
            {
                (variantStart, variantEnd, refAllele, regionStart, regionEnd) = transcript.TranscriptRegions.ShiftDuplication(variantStart, altAllele, onReverseStrand);
            }

            var startPositionOffset = HgvsUtilities.GetCdnaPositionOffset(transcript, variantStart, regionStart);
            var endPositionOffset   = variantStart == variantEnd
                ? startPositionOffset
                : HgvsUtilities.GetCdnaPositionOffset(transcript, variantEnd, regionEnd);

            if (onReverseStrand)
            {
                var tmp = startPositionOffset;
                startPositionOffset = endPositionOffset;
                endPositionOffset   = tmp;
            }

            // sanity check: make sure we have coordinates
            if (startPositionOffset == null || endPositionOffset == null)
            {
                return(null);
            }

            var transcriptLen = transcript.End - transcript.Start + 1;

            //_hgvs notation past the transcript
            if (startPositionOffset.Position > transcriptLen || endPositionOffset.Position > transcriptLen)
            {
                return(null);
            }

            var hgvsNotation = new HgvscNotation(refAllele, altAllele, transcript.Id.WithVersion, genomicChange,
                                                 startPositionOffset, endPositionOffset, transcript.Translation != null);

            // generic formatting
            return(hgvsNotation.ToString());
        }
Exemplo n.º 4
0
        private static VariantEffect GetVariantEffect(ITranscript transcript, ISimpleVariant variant, IMappedPositions mappedPositions, string refAminoAcids, string altAminoAcids, string refCodons, string altCodons, bool insertionInStartAndNoImpact)
        {
            var positionalEffect = new TranscriptPositionalEffect();

            positionalEffect.DetermineIntronicEffect(transcript.Introns, variant, variant.Type);
            positionalEffect.DetermineExonicEffect(transcript, variant, mappedPositions, variant.AltAllele, insertionInStartAndNoImpact);

            var variantEffect = new VariantEffect(positionalEffect, variant, transcript, refAminoAcids,
                                                  altAminoAcids,
                                                  refCodons, altCodons, mappedPositions.ProteinInterval.Start);

            return(variantEffect);
        }
Exemplo n.º 5
0
        private static string GetDownstreamSeq(ISimpleVariant simpleVariant, IInterval rotateRegion,
                                               ISequence refSequence, bool onReverseStrand, string rotatingBases)
        {
            var basesToEnd       = onReverseStrand ? simpleVariant.Start - rotateRegion.Start : rotateRegion.End - simpleVariant.End;
            var downStreamLength =
                Math.Min(basesToEnd,
                         Math.Max(rotatingBases.Length,
                                  MaxDownstreamLength)); // for large rotatingBases, we need to factor in its length but still make sure that we do not go past the end of transcript

            var downStreamSeq = onReverseStrand
                ? SequenceUtilities.GetReverseComplement(
                refSequence.Substring(simpleVariant.Start - 1 - downStreamLength, downStreamLength))
                : refSequence.Substring(simpleVariant.End, downStreamLength);

            return(downStreamSeq);
        }
Exemplo n.º 6
0
        public static string GetNotation(string refseqAccession, ISimpleVariant variant, ISequence refSequence,
                                         IInterval referenceInterval)
        {
            var rotatedVariant = VariantRotator.Right(variant, referenceInterval, refSequence, false);
            var start          = Math.Min(rotatedVariant.Start, rotatedVariant.End);
            var end            = Math.Max(rotatedVariant.Start, rotatedVariant.End);
            var referenceBases = rotatedVariant.RefAllele;
            var alternateBases = rotatedVariant.AltAllele;
            var type           = HgvsCodingNomenclature.GetGenomicChange(referenceInterval, false, refSequence, rotatedVariant);

            if (type == GenomicChange.Duplication && variant.Type == VariantType.insertion)
            {
                referenceBases = alternateBases;
                end            = start;
                start          = end - referenceBases.Length + 1;
            }

            return(HgvsUtilities.FormatDnaNotation(start.ToString(), end.ToString(), refseqAccession, referenceBases, alternateBases, type, NotationType));
        }
Exemplo n.º 7
0
        private static BreakEndAdjacency[] ConvertTranslocation(ISimpleVariant variant, Regex regex,
                                                                bool onReverseStrand, int partnerBracketIndex, IDictionary <string, IChromosome> refNameToChromosome)
        {
            var match = regex.Match(variant.AltAllele);

            if (!match.Success)
            {
                throw new InvalidDataException($"Unable to successfully parse the complex rearrangements for the following allele: {variant.AltAllele}");
            }

            bool   partnerOnReverseStrand = match.Groups[partnerBracketIndex].Value == ReverseBracket;
            var    partnerPosition        = Convert.ToInt32(match.Groups[3].Value);
            string partnerReferenceName   = match.Groups[2].Value;
            var    partnerChromosome      = ReferenceNameUtilities.GetChromosome(refNameToChromosome, partnerReferenceName);

            var origin  = new BreakPoint(variant.Chromosome, variant.Start, onReverseStrand);
            var partner = new BreakPoint(partnerChromosome, partnerPosition, partnerOnReverseStrand);

            return(new[] { new BreakEndAdjacency(origin, partner) });
        }
        private static IEnumerable <ConsequenceTag> GetConsequences(IInterval transcript, ISimpleVariant variant,
                                                                    bool hasGeneFusionAnnotation)
        {
            var featureEffect = new FeatureVariantEffects(transcript, variant.Type, variant, true);
            var consequence   = new Consequences(null, featureEffect);

            consequence.DetermineStructuralVariantEffect(variant.Type, hasGeneFusionAnnotation);
            return(consequence.GetConsequences());
        }
                        AltAminoAcids, string RefCodons, string AltCodons, string TranscriptAltAllele) 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);

            string transcriptAltAllele = HgvsUtilities.GetTranscriptAllele(variant.AltAllele, onReverseStrand);
            var    codingSequence      = GetCodingSequence(transcript, refSequence);
            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);

            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);
        }
Exemplo n.º 10
0
        private static TranscriptPositionalEffect GetPositionalEffect(ITranscript transcript, ISimpleVariant variant,
                                                                      IMappedPosition position, string refAminoAcid, string altAminoAcid, int coveredCdnaStart,
                                                                      int coveredCdnaEnd, int coveredCdsStart, int coveredCdsEnd)
        {
            bool startCodonInsertionWithNoImpact = variant.Type == VariantType.insertion &&
                                                   position.ProteinStart <= 1 &&
                                                   altAminoAcid.EndsWith(refAminoAcid);

            var positionalEffect = new TranscriptPositionalEffect();

            positionalEffect.DetermineIntronicEffect(transcript.TranscriptRegions, variant, variant.Type);
            positionalEffect.DetermineExonicEffect(transcript, variant, position, coveredCdnaStart, coveredCdnaEnd,
                                                   coveredCdsStart, coveredCdsEnd, variant.AltAllele, startCodonInsertionWithNoImpact);
            return(positionalEffect);
        }
Exemplo n.º 11
0
        public static ISimpleVariant Right(ISimpleVariant simpleVariant, IInterval rotateRegion, ISequence refSequence, bool onReverseStrand)
        {
            if (refSequence == null)
            {
                return(simpleVariant);
            }

            if (simpleVariant.Type != VariantType.deletion && simpleVariant.Type != VariantType.insertion)
            {
                return(simpleVariant);
            }

            if (VariantStartOverlapsRegion(simpleVariant, rotateRegion, onReverseStrand))
            {
                return(simpleVariant);
            }
            // if variant is before the transcript start, do not perform 3 prime shift

            string rotatingBases = GetRotatingBases(simpleVariant, onReverseStrand);

            string downStreamSeq = GetDownstreamSeq(simpleVariant, rotateRegion, refSequence, onReverseStrand, rotatingBases);

            string combinedSequence = rotatingBases + downStreamSeq;

            int shiftStart, shiftEnd;
            var hasShifted = false;

            // probably a VEP bug, just use it for consistency
            int numBases = rotatingBases.Length;

            for (shiftStart = 0, shiftEnd = numBases; shiftEnd < combinedSequence.Length; shiftStart++, shiftEnd++)
            {
                if (combinedSequence[shiftStart] != combinedSequence[shiftEnd])
                {
                    break;
                }
                hasShifted = true;
            }

            if (!hasShifted)
            {
                return(simpleVariant);
            }

            // create a new alternative allele
            string rotatedSequence = combinedSequence.Substring(shiftStart, numBases);
            int    rotatedStart    = simpleVariant.Start + shiftStart;
            int    rotatedEnd      = simpleVariant.End + shiftStart;

            if (onReverseStrand)
            {
                rotatedSequence = SequenceUtilities.GetReverseComplement(rotatedSequence);
                rotatedStart    = simpleVariant.Start - shiftStart;
                rotatedEnd      = simpleVariant.End - shiftStart;
            }

            string rotatedRefAllele = simpleVariant.RefAllele;
            string rotatedAltAllele = simpleVariant.AltAllele;

            if (simpleVariant.Type == VariantType.insertion)
            {
                rotatedAltAllele = rotatedSequence;
            }
            else
            {
                rotatedRefAllele = rotatedSequence;
            }

            return(new SimpleVariant(simpleVariant.Chromosome, rotatedStart, rotatedEnd, rotatedRefAllele,
                                     rotatedAltAllele, simpleVariant.Type));
        }
 private static BreakEndAdjacency[] GetBreakEndAdjacencies(ISimpleVariant variant, IDictionary <string, IChromosome> refNameToChromosome) =>
 variant.Type == VariantType.translocation_breakend
         ? BreakEndUtilities.CreateFromTranslocation(variant, refNameToChromosome)
         : BreakEndUtilities.CreateFromSymbolicAllele(variant, variant.Type);
Exemplo n.º 13
0
        public static string GetHgvscAnnotation(ITranscript transcript, ISimpleVariant variant, ISequence refSequence,
                                                int regionStart, int regionEnd, string transcriptRef, string transcriptAlt)
        {
            // sanity check: don't try to handle odd characters, make sure this is not a reference allele,
            //               and make sure that we have protein coordinates
            if (variant.Type == VariantType.reference || SequenceUtilities.HasNonCanonicalBase(variant.AltAllele))
            {
                return(null);
            }

            // do not report HGVSc notation when variant lands inside gap region
            if (regionStart > -1 && regionEnd > -1)
            {
                var startRegion = transcript.TranscriptRegions[regionStart];
                var endRegion   = transcript.TranscriptRegions[regionEnd];
                if (startRegion.Id == endRegion.Id && startRegion.Type == TranscriptRegionType.Gap &&
                    endRegion.Type == TranscriptRegionType.Gap)
                {
                    return(null);
                }
            }

            bool onReverseStrand = transcript.Gene.OnReverseStrand;

            string refAllele = string.IsNullOrEmpty(transcriptRef)? onReverseStrand ? SequenceUtilities.GetReverseComplement(variant.RefAllele) : variant.RefAllele
                : transcriptRef;
            string altAllele = string.IsNullOrEmpty(transcriptAlt)
                ? onReverseStrand ? SequenceUtilities.GetReverseComplement(variant.AltAllele) : variant.AltAllele
                : transcriptAlt;

            // decide event type from HGVS nomenclature
            var genomicChange = GetGenomicChange(transcript, onReverseStrand, refSequence, variant);

            int variantStart = variant.Start;
            int variantEnd   = variant.End;

            if (genomicChange == GenomicChange.Duplication)
            {
                (variantStart, variantEnd, refAllele, regionStart, regionEnd) = transcript.TranscriptRegions.ShiftDuplication(variantStart, altAllele, onReverseStrand);
            }

            var startPositionOffset = HgvsUtilities.GetCdnaPositionOffset(transcript, variantStart, regionStart, true);
            var endPositionOffset   = variantStart == variantEnd
                ? startPositionOffset
                : HgvsUtilities.GetCdnaPositionOffset(transcript, variantEnd, regionEnd, false);

            if (onReverseStrand)
            {
                var tmp = startPositionOffset;
                startPositionOffset = endPositionOffset;
                endPositionOffset   = tmp;
            }

            if (startPositionOffset == null && variant.Type == VariantType.insertion)
            {
                startPositionOffset = new PositionOffset(endPositionOffset.Position + 1, endPositionOffset.Offset, $"{endPositionOffset.Position + 1}", endPositionOffset.HasStopCodonNotation);
            }

            // sanity check: make sure we have coordinates
            if (startPositionOffset == null || endPositionOffset == null)
            {
                return(null);
            }

            var hgvsNotation = new HgvscNotation(refAllele, altAllele, transcript.Id.WithVersion, genomicChange,
                                                 startPositionOffset, endPositionOffset, transcript.Translation != null);

            // generic formatting
            return(hgvsNotation.ToString());
        }
Exemplo n.º 14
0
        public static (double?ReciprocalOverlap, double?AnnotationOverlap) GetOverlapFractions(IChromosomeInterval saInterval, ISimpleVariant variant)
        {
            if (saInterval.Chromosome.Index != variant.Chromosome.Index)
            {
                return(null, null);
            }
            //skip for insertions
            if (saInterval.Start >= saInterval.End || variant.Type == VariantType.insertion)
            {
                return(null, null);
            }
            //skip for break-ends
            if (variant.Type == VariantType.translocation_breakend)
            {
                return(null, null);
            }

            if (!Overlaps(saInterval.Start, saInterval.End, variant.Start, variant.End))
            {
                return(null, null);
            }

            var overlapSize = (double)(Math.Min(saInterval.End, variant.End) - Math.Max(saInterval.Start, variant.Start) + 1);
            int annoSize    = saInterval.End - saInterval.Start + 1;
            int varSize     = variant.End - variant.Start + 1;
            int maxSize     = Math.Max(annoSize, varSize);

            return(overlapSize / maxSize, overlapSize / annoSize);
        }
Exemplo n.º 15
0
 /// <inheritdoc />
 public bool Equals(ISimpleVariant other)
 => SimpleVariantEqualityComparer.Instance.Equals(this, other);
Exemplo n.º 16
0
        public static string GetHgvsProteinAnnotation(
            ITranscript transcript,
            string refAminoAcids,
            string altAminoAcids,
            string transcriptAltAllele,
            IMappedPosition position,
            VariantEffect variantEffect,
            ISimpleVariant variant,
            ISequence refSequence,
            string hgvscNotation,
            bool isMitochondrial)
        {
            if (IsHgvspNull(transcriptAltAllele, position.CdsStart, position.CdsEnd, variant, hgvscNotation))
            {
                return(null);
            }

            var peptideSeq = transcript.Translation.PeptideSeq;

            // Amino acid seq should never go past the stop codon
            refAminoAcids = !refAminoAcids.EndsWith(AminoAcids.StopCodon) && refAminoAcids.Contains(AminoAcids.StopCodon)
                ? refAminoAcids.OptimizedSplit(AminoAcids.StopCodon[0])[0] + AminoAcids.StopCodon
                : refAminoAcids;

            int proteinStart = position.ProteinStart;

            HgvsUtilities.ShiftAndRotateAlleles(ref proteinStart, ref refAminoAcids, ref altAminoAcids, peptideSeq);

            var end             = proteinStart + refAminoAcids.Length - 1;
            var refAbbreviation = AminoAcids.GetAbbreviations(refAminoAcids);
            var altAbbreviation = AminoAcids.GetAbbreviations(altAminoAcids);

            var proteinId     = transcript.Translation.ProteinId.WithVersion;
            var proteinChange = GetProteinChange(proteinStart, refAminoAcids, altAminoAcids, peptideSeq, variantEffect);

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (proteinChange)
            {
            case ProteinChange.Substitution:
                return(HgvspNotation.GetSubstitutionNotation(proteinId, proteinStart, refAbbreviation, altAbbreviation));

            case ProteinChange.Unknown:
                return(HgvspNotation.GetUnknownNotation(proteinId, proteinStart, end, refAbbreviation, altAbbreviation));

            case ProteinChange.Deletion:
                return(HgvspNotation.GetDeletionNotation(proteinId, proteinStart, end, refAbbreviation, variantEffect.IsStopGained()));

            case ProteinChange.Duplication:
                proteinStart -= altAminoAcids.Length;
                return(HgvspNotation.GetDuplicationNotation(proteinId, proteinStart, end, altAbbreviation));

            case ProteinChange.Frameshift:
                return(GetHgvsFrameshiftNotation(refSequence, position.CdsStart, position.CdsEnd, transcriptAltAllele,
                                                 transcript, isMitochondrial, proteinId, proteinStart, end));

            case ProteinChange.None:
                return(HgvspNotation.GetSilentNotation(hgvscNotation, proteinStart, refAbbreviation, variantEffect.IsStopRetained()));

            case ProteinChange.DelIns:
                return(HgvspNotation.GetDelInsNotation(proteinId, proteinStart, end, refAbbreviation, altAbbreviation));

            case ProteinChange.Insertion:
                Swap.Int(ref proteinStart, ref end);
                return(HgvspNotation.GetInsertionNotation(proteinId, proteinStart, end, altAbbreviation, peptideSeq));

            case ProteinChange.Extension:
                var altPeptideSequence = HgvsUtilities.GetAltPeptideSequence(refSequence, position.CdsStart, position.CdsEnd,
                                                                             transcriptAltAllele, transcript, isMitochondrial);
                altAbbreviation = proteinStart <= altPeptideSequence.Length ? AminoAcids.ConvertAminoAcidToAbbreviation(altPeptideSequence[proteinStart - 1]): "Ter";
                var countToStop = HgvsUtilities.GetNumAminoAcidsUntilStopCodon(altPeptideSequence, peptideSeq, proteinStart - 1, false);

                return(HgvspNotation.GetExtensionNotation(proteinId, proteinStart, refAbbreviation, altAbbreviation, countToStop));

            case ProteinChange.StartLost:
                return(HgvspNotation.GetStartLostNotation(proteinId, proteinStart, end, refAbbreviation));
            }

            return(null);
        }
Exemplo n.º 17
0
 private static bool IsHgvspNull(string transcriptAltAllele, int cdsStart, int cdsEnd, ISimpleVariant variant,
                                 string hgvscNotation)
 {
     return(string.IsNullOrEmpty(hgvscNotation) ||
            variant.Type == VariantType.reference ||
            SequenceUtilities.HasNonCanonicalBase(transcriptAltAllele) ||
            cdsStart == -1 ||
            cdsEnd == -1);
 }
Exemplo n.º 18
0
 public static BreakEndAdjacency[] CreateFromTranslocation(ISimpleVariant variant,
                                                           IDictionary <string, IChromosome> refNameToChromosome) => variant.AltAllele.StartsWith(variant.RefAllele)
     ? ConvertTranslocation(variant, ForwardRegex, false, 4, refNameToChromosome)
     : ConvertTranslocation(variant, ReverseRegex, true, 1, refNameToChromosome);
Exemplo n.º 19
0
        public static GenomicChange GetGenomicChange(IInterval interval, bool onReverseStrand, ISequence refSequence, ISimpleVariant variant)
        {
            // length of the reference allele. Negative lengths make no sense
            int refLength = variant.End - variant.Start + 1;

            if (refLength < 0)
            {
                refLength = 0;
            }

            // length of alternative allele
            int altLength = variant.AltAllele.Length;

            // sanity check: make sure that the alleles are different
            if (variant.RefAllele == variant.AltAllele)
            {
                return(GenomicChange.Unknown);
            }

            // deletion
            if (altLength == 0)
            {
                return(GenomicChange.Deletion);
            }

            if (refLength == altLength)
            {
                // substitution
                if (refLength == 1)
                {
                    return(GenomicChange.Substitution);
                }

                // inversion
                string rcRefAllele = SequenceUtilities.GetReverseComplement(variant.RefAllele);
                return(variant.AltAllele == rcRefAllele ? GenomicChange.Inversion : GenomicChange.DelIns);
            }

            // deletion/insertion
            if (refLength != 0)
            {
                return(GenomicChange.DelIns);
            }

            // If this is an insertion, we should check if the preceding reference nucleotides
            // match the insertion. In that case it should be annotated as a multiplication.
            bool isGenomicDuplicate = HgvsUtilities.IsDuplicateWithinInterval(refSequence, variant, interval, onReverseStrand);

            return(isGenomicDuplicate ? GenomicChange.Duplication : GenomicChange.Insertion);
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
0
        private static Tuple <string, string, string, string> GetCodonsAndAminoAcids(ITranscript transcript, ISequence refSequence,
                                                                                     string transcriptRefAllele, string transcriptAltAllele, ISimpleVariant variant,
                                                                                     IMappedPositions mappedPositions, AminoAcids aminoAcidsProvider)
        {
            var codingSequence = transcript.Translation == null
                ? null
                : new CodingSequence(refSequence, transcript.Translation.CodingRegion.Start,
                                     transcript.Translation.CodingRegion.End, transcript.CdnaMaps, transcript.Gene.OnReverseStrand,
                                     transcript.StartExonPhase);

            // compute codons and amino acids
            AssignCodonsAndAminoAcids(transcriptRefAllele, transcriptAltAllele, mappedPositions,
                                      codingSequence, aminoAcidsProvider, out string referenceCodons,
                                      out string alternateCodons, out string referenceAminoAcids, out string alternateAminoAcids);

            return(Tuple.Create(referenceCodons ?? "", alternateCodons ?? "", referenceAminoAcids ?? "",
                                alternateAminoAcids ?? ""));
        }
Exemplo n.º 22
0
        private static string GetTranscriptRefAllele(IMappedPosition position, ISequence cdnaSequence, ISimpleVariant variant,
                                                     bool onReverseStrand)
        {
            var variantRef = HgvsUtilities.GetTranscriptAllele(variant.RefAllele, onReverseStrand);

            if (position == null || cdnaSequence == null)
            {
                return(variantRef);
            }
            var start = position.CoveredCdnaStart;
            var end   = position.CoveredCdnaEnd;

            if (start == -1 && end == -1)
            {
                return(variantRef);
            }
            if (start != -1 && end != -1 && end < start)
            {
                Swap.Int(ref start, ref end);
            }

            return(cdnaSequence.Substring(start - 1, end - start + 1));
        }