/// <summary> /// Get alternative codons /// </summary> /// <returns></returns> protected override string CodonsAlt() { if (NetCodingSequenceChange == "") { return(""); } int after = NetCodingSequenceChange.Length + CodonStartIndex; string prefix = CodonsReference.Length >= CodonStartIndex?CodonsReference.Substring(0, CodonStartIndex) : CodonsReference; string suffix = CodonsReference.Length > after?CodonsReference.Substring(after) : ""; string codonsAlt = prefix + suffix; return(codonsAlt); }
/// <summary> /// Get new (modified) codons /// </summary> /// <returns></returns> protected override string CodonsAlt() { // Inserts BEFORE base: // - In positive strand that is BEFORE pos // - In negative strand, that is AFTER pos int idx = CodonStartIndex + (Transcript.IsStrandMinus() ? 1 : 0); // Insertion: Concatenate... string prefix = CodonsReference.Length >= idx?CodonsReference.Substring(0, idx) : CodonsReference; // First part of the codon string netChange = Variant.NetChange(Transcript.IsStrandMinus()); // Insertion string suffix = CodonsReference.Length >= idx?CodonsReference.Substring(idx) : ""; // last part of the codon // New codon string codonsNew = prefix + netChange + suffix; return(codonsNew); }
/// <summary> /// Calculate codons old / codons new /// </summary> protected void codonOldNew() { if (!Transcript.Intersects(Variant)) { return; } // CDS coordinates cdsStart = Transcript.IsStrandPlus() ? Transcript.CdsOneBasedStart : Transcript.CdsOneBasedEnd; cdsEnd = Transcript.IsStrandPlus() ? Transcript.CdsOneBasedEnd : Transcript.CdsOneBasedStart; // Does it intersect CDS? if (cdsStart > Variant.OneBasedEnd) { return; } if (cdsEnd < Variant.OneBasedStart) { return; } // Base number relative to CDS start long scStart, scEnd; if (Transcript.IsStrandPlus()) { scStart = cdsBaseNumber(Variant.OneBasedStart, false); scEnd = cdsBaseNumber(Variant.OneBasedEnd, true); } else { scEnd = cdsBaseNumber(Variant.OneBasedStart, true); scStart = cdsBaseNumber(Variant.OneBasedEnd, false); } // Update coordinates CodonStartNumber = (int)(scStart / CODON_SIZE); CodonStartIndex = (int)(scStart % CODON_SIZE); // MNP overlap in coding part long scLen = scEnd - scStart; if (scLen < 0) { return; } // Round to codon position long scStart3 = round3(scStart, false); long scEnd3 = round3(scEnd, true); long scLen3 = scEnd3 - scStart3; if (scEnd3 == scStart3) { scEnd3 += 3; } // At least one codon // Append 'N' string padN = ""; long diff = scEnd3 - (Transcript.RetrieveCodingSequence().Count - 1); if (diff > 0) { scEnd3 = Transcript.RetrieveCodingSequence().Count - 1; // Pad with 'N' switch (diff) { case 1: padN = "N"; break; case 2: padN = "NN"; break; default: throw new ArgumentOutOfRangeException("Sanity check failed. Number of 'N' pading is :" + diff + ". This should not happen!"); } } // Get old codon (reference) CodonsReference = SequenceExtensions.ConvertToString(Transcript.RetrieveCodingSequence().GetSubSequence(scStart3, scLen3)); // Get new codon (change) string prepend = CodonsReference.Substring(0, (int)(scStart - scStart3)); string append = scEnd3 > scEnd?CodonsReference.Substring(CodonsReference.Length - (int)(scEnd3 - scEnd)) : ""; CodonsAlternate = prepend + NetCdsChange() + append; // Pad codons with 'N' if required CodonsReference += padN; CodonsAlternate += padN; //--- // Can we simplify codons? //--- if ((CodonsReference != null) && (CodonsAlternate != null)) { while ((CodonsReference.Length >= 3) && (CodonsAlternate.Length >= 3)) { // First codon string cold = CodonsReference.Substring(0, 3); string cnew = CodonsAlternate.Substring(0, 3); // Are codons equal? => Simplify if (cold.Equals(cnew, StringComparison.InvariantCultureIgnoreCase)) { CodonsReference = CodonsReference.Substring(3); CodonsAlternate = CodonsAlternate.Substring(3); CodonStartNumber++; } else { break; } } } }