/// <summary>
 /// Makes the string representing a detected sequence variation, including any modifications on a variant amino acid.
 /// takes in the variant as well as the bool value of wheter the peptid eintersects the variant. (this allows for identified
 /// variants that cause the cleavage site for the peptide.
 /// </summary>
 /// <param name="p"></param>
 /// <param name="d"></param>
 /// <returns></returns>
 public string SequenceVariantString(SequenceVariation applied, bool intersects)
 {
     if (intersects == true)
     {
         bool startAtNTerm            = applied.OneBasedBeginPosition == 1 && OneBasedStartResidueInProtein == 1;
         bool onlyPeptideStartAtNTerm = OneBasedStartResidueInProtein == 1 && applied.OneBasedBeginPosition != 1;
         int  modResidueScale         = 0;
         if (startAtNTerm)
         {
             modResidueScale = 1;
         }
         else if (onlyPeptideStartAtNTerm)
         {
             modResidueScale = 2;
         }
         else
         {
             modResidueScale = 3;
         }
         int lengthDiff = applied.VariantSequence.Length - applied.OriginalSequence.Length;
         var modsOnVariantOneIsNTerm = AllModsOneIsNterminus
                                       .Where(kv => kv.Key == 1 && applied.OneBasedBeginPosition == 1 || applied.OneBasedBeginPosition <= kv.Key - 2 + OneBasedStartResidueInProtein && kv.Key - 2 + OneBasedStartResidueInProtein <= applied.OneBasedEndPosition)
                                       .ToDictionary(kv => kv.Key - applied.OneBasedBeginPosition + (modResidueScale), kv => kv.Value);
         PeptideWithSetModifications variantWithAnyMods = new PeptideWithSetModifications(Protein, DigestionParams, applied.OneBasedBeginPosition == 1 ? applied.OneBasedBeginPosition : applied.OneBasedBeginPosition - 1, applied.OneBasedEndPosition, CleavageSpecificityForFdrCategory, PeptideDescription, MissedCleavages, modsOnVariantOneIsNTerm, NumFixedMods);
         return($"{applied.OriginalSequence}{applied.OneBasedBeginPosition}{variantWithAnyMods.FullSequence.Substring(applied.OneBasedBeginPosition == 1 ? 0 : 1)}");
     }
     //if the variant caused a cleavage site leading the the peptide sequence (variant does not intersect but is identified)
     else
     {
         return($"{applied.OriginalSequence}{ applied.OneBasedBeginPosition}{applied.VariantSequence}");
     }
 }
示例#2
0
        public void TestHashAndEqualsSequenceVariation()
        {
            SequenceVariation sv1 = new SequenceVariation(1, "MAA", "MAA", "description", new Dictionary <int, List <Modification> > {
                { 2, new[] { new Modification("mod") }.ToList() }
            });
            SequenceVariation sv2 = new SequenceVariation(1, "MAA", "MAA", "description", new Dictionary <int, List <Modification> > {
                { 2, new[] { new Modification("mod") }.ToList() }
            });
            SequenceVariation sv22 = new SequenceVariation(1, "MAA", "MAA", "description", new Dictionary <int, List <Modification> > {
                { 3, new[] { new Modification("mod") }.ToList() }
            });
            SequenceVariation sv222 = new SequenceVariation(1, "MAA", "MAA", "description", new Dictionary <int, List <Modification> > {
                { 2, new[] { new Modification("another") }.ToList() }
            });
            SequenceVariation sv3 = new SequenceVariation(1, "MAA", "MAA", "description", null);
            SequenceVariation sv4 = new SequenceVariation(1, "MAA", "MAA", null, new Dictionary <int, List <Modification> > {
                { 2, new[] { new Modification("mod") }.ToList() }
            });
            SequenceVariation sv5 = new SequenceVariation(1, null, null, "description", new Dictionary <int, List <Modification> > {
                { 2, new[] { new Modification("mod") }.ToList() }
            });
            SequenceVariation sv6 = new SequenceVariation(2, "MAA", "MAA", "description", new Dictionary <int, List <Modification> > {
                { 2, new[] { new Modification("mod") }.ToList() }
            });

            Assert.AreEqual(sv1, sv2);
            Assert.AreNotEqual(sv1, sv22);
            Assert.AreNotEqual(sv1, sv222);
            Assert.AreNotEqual(sv1, sv3);
            Assert.AreNotEqual(sv1, sv4);
            Assert.AreNotEqual(sv1, sv5);
            Assert.AreNotEqual(sv1, sv6);
        }
示例#3
0
        /// <summary>
        /// Checks for an intersection between a peptide and applied variant that shows a sequence change.
        /// </summary>
        /// <param name="pep"></param>
        /// <param name="appliedVariation"></param>
        /// <returns></returns>
        private static bool IntersectsWithVariation(PeptideWithSetModifications pep, SequenceVariation appliedVariation, bool checkUnique)
        {
            // does it intersect?
            int intersectOneBasedStart = Math.Max(pep.OneBasedStartResidueInProtein, appliedVariation.OneBasedBeginPosition);
            int intersectOneBasedEnd   = Math.Min(pep.OneBasedEndResidueInProtein, appliedVariation.OneBasedEndPosition);

            if (intersectOneBasedEnd < intersectOneBasedStart)
            {
                return(false);
            }
            else if (!checkUnique)
            {
                return(true);
            }
            else
            {
                // if the original sequence is too short or long, the intersect of the peptide and variant is unique
                int  intersectSize         = intersectOneBasedEnd - intersectOneBasedStart + 1;
                int  variantZeroBasedStart = intersectOneBasedStart - appliedVariation.OneBasedBeginPosition;
                bool origSeqIsShort        = appliedVariation.OriginalSequence.Length - variantZeroBasedStart < intersectSize;
                bool origSeqIsLong         = appliedVariation.OriginalSequence.Length > intersectSize && pep.OneBasedEndResidueInProtein > intersectOneBasedEnd;
                if (origSeqIsShort || origSeqIsLong)
                {
                    return(true);
                }

                // is the variant sequence intersecting the peptide different than the original sequence?
                string originalAtIntersect = appliedVariation.OriginalSequence.Substring(intersectOneBasedStart - appliedVariation.OneBasedBeginPosition, intersectSize);
                string variantAtIntersect  = appliedVariation.VariantSequence.Substring(intersectOneBasedStart - appliedVariation.OneBasedBeginPosition, intersectSize);
                return(originalAtIntersect != variantAtIntersect);
            }
        }
示例#4
0
        /// <summary>
        /// Makes the string representing a detected sequence variation, including any modifications on a variant amino acid
        /// </summary>
        /// <param name="p"></param>
        /// <param name="d"></param>
        /// <returns></returns>
        private static string SequenceVariantString(PeptideWithSetModifications p, SequenceVariation applied)
        {
            var modsOnVariantOneIsNTerm = p.AllModsOneIsNterminus
                                          .Where(kv => kv.Key == 1 && applied.OneBasedBeginPosition == 1 || applied.OneBasedBeginPosition <= kv.Key - 2 + p.OneBasedStartResidueInProtein && kv.Key - 2 + p.OneBasedStartResidueInProtein <= applied.OneBasedEndPosition)
                                          .ToDictionary(kv => kv.Key - applied.OneBasedBeginPosition + 1, kv => kv.Value);
            PeptideWithSetModifications variantWithAnyMods = new PeptideWithSetModifications(p.Protein, p.DigestionParams, applied.OneBasedBeginPosition, applied.OneBasedEndPosition, p.CleavageSpecificityForFdrCategory, p.PeptideDescription, p.MissedCleavages, modsOnVariantOneIsNTerm, p.NumFixedMods);

            return($"{applied.OriginalSequence}{applied.OneBasedBeginPosition}{variantWithAnyMods.FullSequence}");
        }
示例#5
0
        public override bool Equals(object obj)
        {
            SequenceVariation s = obj as SequenceVariation;

            return(s != null &&
                   OneBasedBeginPosition == s.OneBasedBeginPosition &&
                   OneBasedEndPosition == s.OneBasedEndPosition &&
                   OriginalSequence == s.OriginalSequence &&
                   VariantSequence == s.VariantSequence &&
                   Description == s.Description);
        }
示例#6
0
        private static Dictionary <int, HashSet <string> > GetModsForThisProtein(Protein protein, SequenceVariation seqvar, Dictionary <string, HashSet <Tuple <int, Modification> > > additionalModsToAddToProteins, Dictionary <string, int> newModResEntries)
        {
            var modsToWriteForThisSpecificProtein = new Dictionary <int, HashSet <string> >();

            var primaryModDict = seqvar == null ? protein.OneBasedPossibleLocalizedModifications : seqvar.OneBasedModifications;

            foreach (var mods in primaryModDict)
            {
                foreach (var mod in mods.Value)
                {
                    if (modsToWriteForThisSpecificProtein.TryGetValue(mods.Key, out HashSet <string> val))
                    {
                        val.Add(mod.IdWithMotif);
                    }
                    else
                    {
                        modsToWriteForThisSpecificProtein.Add(mods.Key, new HashSet <string> {
                            mod.IdWithMotif
                        });
                    }
                }
            }

            string accession = seqvar == null ? protein.Accession : VariantApplication.GetAccession(protein, new[] { seqvar });

            if (additionalModsToAddToProteins.ContainsKey(accession))
            {
                foreach (var ye in additionalModsToAddToProteins[accession])
                {
                    int    additionalModResidueIndex = ye.Item1;
                    string additionalModId           = ye.Item2.IdWithMotif;
                    bool   modAdded = false;

                    // If we already have modifications that need to be written to the specific residue, get the hash set of those mods
                    if (modsToWriteForThisSpecificProtein.TryGetValue(additionalModResidueIndex, out HashSet <string> val))
                    {
                        // Try to add the new mod to that hash set. If it's not there, modAdded=true, and it is added.
                        modAdded = val.Add(additionalModId);
                    }

                    // Otherwise, no modifications currently need to be written to the residue at residueIndex, so need to create new hash set for that residue
                    else
                    {
                        modsToWriteForThisSpecificProtein.Add(additionalModResidueIndex, new HashSet <string> {
                            additionalModId
                        });
                        modAdded = true;
                    }

                    // Finally, if a new modification has in fact been deemed worthy of being added to the database, mark that in the output dictionary
                    if (modAdded)
                    {
                        if (newModResEntries.ContainsKey(additionalModId))
                        {
                            newModResEntries[additionalModId]++;
                        }
                        else
                        {
                            newModResEntries.Add(additionalModId, 1);
                        }
                    }
                }
            }
            return(modsToWriteForThisSpecificProtein);
        }
        /// <summary>
        /// Checks if sequence variant and peptide intersect, also checks if the seuqence variatn can be identified whether they intersect
        /// or not (ie if the variant causes a cleavage site generating the peptide). Returns a tuple with item 1 being a bool value
        /// representing if the varaint intersects the peptide and item 2 beign abool that represents if the variatn is identified.
        /// </summary>
        /// <param name="pep"></param>
        /// <param name="appliedVariation"></param>
        /// <returns></returns>
        public (bool intersects, bool identifies) IntersectsAndIdentifiesVariation(SequenceVariation appliedVariation)
        {
            // does it intersect?
            //possible locations for variant start site
            bool VariantStartsBeforePeptide  = appliedVariation.OneBasedBeginPosition < OneBasedStartResidueInProtein;
            bool VariantStartsAtPeptideStart = appliedVariation.OneBasedBeginPosition == OneBasedStartResidueInProtein;
            bool VariantStartsInsidePeptide  = appliedVariation.OneBasedBeginPosition >= OneBasedStartResidueInProtein && appliedVariation.OneBasedBeginPosition < OneBasedEndResidueInProtein;
            bool VariantStartsAtPeptideEnd   = appliedVariation.OneBasedBeginPosition == OneBasedEndResidueInProtein;
            //possibe locations for variant end stite
            bool VariantEndsAtPeptideStart = appliedVariation.OneBasedEndPosition == OneBasedStartResidueInProtein;
            bool VariantEndsInsidePeptide  = appliedVariation.OneBasedEndPosition > OneBasedStartResidueInProtein && appliedVariation.OneBasedEndPosition <= OneBasedEndResidueInProtein;
            bool VariantEndsAtPeptideEnd   = appliedVariation.OneBasedEndPosition == OneBasedEndResidueInProtein;
            bool VariantEndsAfterPeptide   = appliedVariation.OneBasedEndPosition > OneBasedEndResidueInProtein;

            bool intersects = false;
            bool identifies = false;

            //start and end  combinations that lead to variants being intersected by the peptide sequnce
            if (VariantStartsBeforePeptide || VariantStartsAtPeptideStart)
            {
                if (VariantEndsAtPeptideStart || VariantEndsInsidePeptide || VariantEndsAtPeptideEnd || VariantEndsAfterPeptide)
                {
                    intersects = true;
                }
            }
            else if (VariantStartsInsidePeptide)
            {
                if (VariantEndsInsidePeptide || VariantEndsAfterPeptide || VariantEndsAtPeptideEnd)
                {
                    intersects = true;
                }
            }
            else if (VariantStartsAtPeptideEnd)
            {
                if (VariantEndsAfterPeptide || VariantEndsAtPeptideEnd)
                {
                    intersects = true;
                }
            }

            if (intersects == true)
            {
                int lengthDiff             = appliedVariation.VariantSequence.Length - appliedVariation.OriginalSequence.Length;
                int intersectOneBasedStart = Math.Max(OneBasedStartResidueInProtein, appliedVariation.OneBasedBeginPosition);
                int intersectOneBasedEnd   = Math.Min(OneBasedEndResidueInProtein, appliedVariation.OneBasedEndPosition + lengthDiff);
                int intersectSize          = intersectOneBasedEnd - intersectOneBasedStart + 1;

                // if the original sequence within the peptide is shorter or longer than the variant sequence within the peptide, there is a sequence change
                int  variantZeroBasedStartInPeptide = intersectOneBasedStart - appliedVariation.OneBasedBeginPosition;
                bool origSeqIsShort = appliedVariation.OriginalSequence.Length - variantZeroBasedStartInPeptide < intersectSize;
                bool origSeqIsLong  = appliedVariation.OriginalSequence.Length > intersectSize && OneBasedEndResidueInProtein > intersectOneBasedEnd;
                if (origSeqIsShort || origSeqIsLong)
                {
                    identifies = true;
                }
                else
                {
                    // crosses the entire variant sequence (needed to identify truncations and certain deletions, like KAAAAAAAAA -> K, but also catches synonymous variations A -> A)
                    bool crossesEntireVariant = intersectSize == appliedVariation.VariantSequence.Length;

                    if (crossesEntireVariant == true)
                    {
                        // is the variant sequence intersecting the peptide different than the original sequence?
                        string originalAtIntersect = appliedVariation.OriginalSequence.Substring(intersectOneBasedStart - appliedVariation.OneBasedBeginPosition, intersectSize);
                        string variantAtIntersect  = appliedVariation.VariantSequence.Substring(intersectOneBasedStart - appliedVariation.OneBasedBeginPosition, intersectSize);
                        identifies = originalAtIntersect != variantAtIntersect;
                    }
                }
            }
            //checks to see if the variant causes a cleavage event creating the peptide. This is how a variant can be identified without intersecting
            //with the peptide itself
            else
            {
                //We need to account for any variants that occur in the protien prior to the variant in question.
                //This information is used to calculate a scaling factor to calculate the AA that proceeds the peptide seqeunce in the original (variant free) protein
                List <SequenceVariation> VariantsThatAffectPreviousAAPosition = Protein.AppliedSequenceVariations.Where(v => v.OneBasedEndPosition <= OneBasedStartResidueInProtein).ToList();
                int totalLengthDifference = 0;
                foreach (var variant in VariantsThatAffectPreviousAAPosition)
                {
                    totalLengthDifference += variant.VariantSequence.Length - variant.OriginalSequence.Length;
                }

                //need to determine what the cleavage sites are for the protease used (will allow us to determine if new cleavage sites were made by variant)
                List <DigestionMotif> proteasesCleavageSites = DigestionParams.Protease.DigestionMotifs;
                //if the variant ends the AA before the peptide starts then it may have caused c-terminal cleavage
                //see if the protease used for digestion has C-terminal cleavage sites
                List <string> cTerminalResidue = proteasesCleavageSites.Where(dm => dm.CutIndex == 1).Select(d => d.InducingCleavage).ToList();

                if (appliedVariation.OneBasedEndPosition == (OneBasedStartResidueInProtein - 1))
                {
                    if (cTerminalResidue.Count > 0)
                    {
                        // get the AA that proceeds the peptide from the variant protein (AKA the last AA in the variant)
                        PeptideWithSetModifications previousAA_Variant = new PeptideWithSetModifications(Protein, DigestionParams, OneBasedStartResidueInProtein - 1, OneBasedStartResidueInProtein - 1, CleavageSpecificity.Full, "full", 0, AllModsOneIsNterminus, NumFixedMods);

                        // get the AA that proceeds the peptide sequence in the original protein (wihtout any applied variants)
                        PeptideWithSetModifications previousAA_Original = new PeptideWithSetModifications(Protein.NonVariantProtein, DigestionParams, (OneBasedStartResidueInProtein - 1) - totalLengthDifference, (OneBasedStartResidueInProtein - 1) - totalLengthDifference, CleavageSpecificity.Full, "full", 0, AllModsOneIsNterminus, NumFixedMods);
                        bool newSite = cTerminalResidue.Contains(previousAA_Variant.BaseSequence);
                        bool oldSite = cTerminalResidue.Contains(previousAA_Original.BaseSequence);
                        // if the new AA causes a cleavage event, and that cleavage event would not have occurred without the variant then it is identified
                        if (newSite == true && oldSite == false)
                        {
                            identifies = true;
                        }
                    }
                }
                //if the variant begins the AA after the peptide ends then it may have caused n-terminal cleavage
                else if (appliedVariation.OneBasedBeginPosition == (OneBasedEndResidueInProtein + 1))
                {
                    //see if the protease used for digestion has N-terminal cleavage sites
                    List <string> nTerminalResidue = proteasesCleavageSites.Where(dm => dm.CutIndex == 0).Select(d => d.InducingCleavage).ToList();
                    // stop gain variation can create a peptide this checks for this with cTerminal cleavage proteases
                    if (cTerminalResidue.Count > 0)
                    {
                        if (appliedVariation.VariantSequence == "*")
                        {
                            PeptideWithSetModifications lastAAofPeptide = new PeptideWithSetModifications(Protein, DigestionParams, OneBasedEndResidueInProtein, OneBasedEndResidueInProtein, CleavageSpecificity.Full, "full", 0, AllModsOneIsNterminus, NumFixedMods);
                            bool oldSite = cTerminalResidue.Contains(lastAAofPeptide.BaseSequence);
                            if (oldSite == false)
                            {
                                identifies = true;
                            }
                        }
                    }

                    if (nTerminalResidue.Count > 0)
                    {
                        if (Protein.Length >= OneBasedEndResidueInProtein + 1)
                        {
                            //get the AA that follows the peptide sequence fromt he variant protein (AKA the first AA of the varaint)
                            PeptideWithSetModifications nextAA_Variant = new PeptideWithSetModifications(Protein, DigestionParams, OneBasedEndResidueInProtein + 1, OneBasedEndResidueInProtein + 1, CleavageSpecificity.Full, "full", 0, AllModsOneIsNterminus, NumFixedMods);

                            // checks to make sure the original protein has an amino acid following the peptide (an issue with stop loss variants or variatns that add AA after the previous stop residue)
                            // no else statement because if the peptide end residue was the previous protein stop site, there is no way to truly identify the variant.
                            // if the peptide were to extend into the stop loss region then the peptide would intesect the variant and this code block would not be triggered.
                            if (Protein.NonVariantProtein.Length >= OneBasedEndResidueInProtein + 1)
                            {
                                // get the AA that follows the peptide sequence in the original protein (without any applied variants)
                                PeptideWithSetModifications nextAA_Original = new PeptideWithSetModifications(Protein.NonVariantProtein, DigestionParams, (OneBasedEndResidueInProtein + 1) - totalLengthDifference, (OneBasedEndResidueInProtein + 1) - totalLengthDifference, CleavageSpecificity.Full, "full", 0, AllModsOneIsNterminus, NumFixedMods);
                                bool newSite = nTerminalResidue.Contains(nextAA_Variant.BaseSequence);
                                bool oldSite = nTerminalResidue.Contains(nextAA_Original.BaseSequence);
                                // if the new AA causes a cleavage event, and that cleavage event would not have occurred without the variant then it is identified
                                if (newSite == true && oldSite == false)
                                {
                                    identifies = true;
                                }
                            }
                        }
                        //for stop gain varations that cause peptide
                        else
                        {
                            // get the AA that follows the peptide sequence in the original protein (without any applied variants)
                            PeptideWithSetModifications nextAA_Original = new PeptideWithSetModifications(Protein.NonVariantProtein, DigestionParams, (OneBasedEndResidueInProtein + 1) - totalLengthDifference, (OneBasedEndResidueInProtein + 1) - totalLengthDifference, CleavageSpecificity.Full, "full", 0, AllModsOneIsNterminus, NumFixedMods);
                            bool oldSite = nTerminalResidue.Contains(nextAA_Original.BaseSequence);
                            // if the new AA causes a cleavage event, and that cleavage event would not have occurred without the variant then it is identified
                            if (oldSite == false)
                            {
                                identifies = true;
                            }
                        }
                    }
                }
            }

            return(intersects, identifies);
        }
示例#8
0
        public static void CompareProteinProperties()
        {
            DatabaseReference d = new DatabaseReference("asdf", "asdfg", new List <Tuple <string, string> > {
                new Tuple <string, string>("bbb", "ccc")
            });
            DatabaseReference dd = new DatabaseReference("asdf", "asdfg", new List <Tuple <string, string> > {
                new Tuple <string, string>("bbb", "ccc")
            });
            DatabaseReference de = new DatabaseReference("asdf", "asdefg", new List <Tuple <string, string> > {
                new Tuple <string, string>("bbb", "ccc")
            });
            DatabaseReference df = new DatabaseReference("asddf", "asdfg", new List <Tuple <string, string> > {
                new Tuple <string, string>("bbb", "ccc")
            });
            DatabaseReference dg = new DatabaseReference("asdf", "asdfg", new List <Tuple <string, string> > {
                new Tuple <string, string>("babb", "ccc")
            });
            DatabaseReference dh = new DatabaseReference("asdf", "asdfg", new List <Tuple <string, string> > {
                new Tuple <string, string>("bbb", "cccf")
            });

            Assert.True(dd.Equals(d));
            Assert.False(de.Equals(d));
            Assert.False(df.Equals(d));
            Assert.False(dg.Equals(d));
            Assert.False(dh.Equals(d));
            Assert.AreEqual(5, new HashSet <DatabaseReference> {
                d, dd, de, df, dg, dh
            }.Count);

            SequenceVariation s     = new SequenceVariation(1, "hello", "hey", "hi");
            SequenceVariation sv    = new SequenceVariation(1, "hello", "hey", "hi");
            SequenceVariation sss   = new SequenceVariation(2, "hallo", "hey", "hi");
            SequenceVariation ssss  = new SequenceVariation(1, "hello", "heyy", "hi");
            SequenceVariation sssss = new SequenceVariation(1, "hello", "hey", "hii");

            Assert.True(s.Equals(sv));
            Assert.False(s.Equals(sss));
            Assert.False(s.Equals(ssss));
            Assert.False(s.Equals(sssss));
            Assert.AreEqual(4, new HashSet <SequenceVariation> {
                s, sv, sss, ssss, sssss
            }.Count);

            DisulfideBond b    = new DisulfideBond(1, "hello");
            DisulfideBond bb   = new DisulfideBond(1, "hello");
            DisulfideBond bbb  = new DisulfideBond(1, 2, "hello");
            DisulfideBond bbbb = new DisulfideBond(1, 2, "hello");
            DisulfideBond ba   = new DisulfideBond(1, 3, "hello");
            DisulfideBond baa  = new DisulfideBond(2, 2, "hello");
            DisulfideBond baaa = new DisulfideBond(1, 2, "hallo");

            Assert.AreEqual(b, bb);
            Assert.AreEqual(bbb, bbbb);
            Assert.AreNotEqual(b, bbb);
            Assert.AreNotEqual(ba, bbb);
            Assert.AreNotEqual(baa, bbb);
            Assert.AreNotEqual(baaa, bbb);
            Assert.AreEqual(5, new HashSet <DisulfideBond> {
                b, bb, bbb, bbbb, ba, baa, baaa
            }.Count);

            ProteolysisProduct pp   = new ProteolysisProduct(1, 1, "hello");
            ProteolysisProduct paaa = new ProteolysisProduct(1, 1, "hello");
            ProteolysisProduct p    = new ProteolysisProduct(null, null, "hello");
            ProteolysisProduct ppp  = new ProteolysisProduct(1, 2, "hello");
            ProteolysisProduct pa   = new ProteolysisProduct(2, 1, "hello");
            ProteolysisProduct paa  = new ProteolysisProduct(1, 1, "hallo");

            Assert.AreEqual(pp, paaa);
            Assert.AreNotEqual(p, pp);
            Assert.AreNotEqual(pp, ppp);
            Assert.AreNotEqual(pp, pa);
            Assert.AreNotEqual(pp, paa);
            Assert.AreEqual(5, new HashSet <ProteolysisProduct> {
                p, pp, ppp, pa, paa, paaa
            }.Count);
        }
示例#9
0
        public static void TestSearchPtmVariantDatabase()
        {
            //Create Search Task
            SearchTask task1 = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    SearchTarget         = true,
                    MassDiffAcceptorType = MassDiffAcceptorType.Exact,
                },
                CommonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 5))
            };

            //add task to task list
            var taskList = new List <(string, MetaMorpheusTask)> {
                ("task1", task1)
            };

            //create modification lists
            List <Modification> variableModifications = GlobalVariables.AllModsKnown.OfType <Modification>().Where
                                                            (b => task1.CommonParameters.ListOfModsVariable.Contains((b.ModificationType, b.IdWithMotif))).ToList();

            //protein Creation (One with mod and one without)
            ModificationMotif.TryGetMotif("P", out ModificationMotif motifP);
            ModificationMotif.TryGetMotif("K", out ModificationMotif motifK);
            var     variant            = new SequenceVariation(3, "P", "K", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G|||||||||||||||||||\tGT:AD:DP\t1/1:30,30:30");
            Protein testProteinWithMod = new Protein("PEPTID", "accession1", sequenceVariations: new List <SequenceVariation> {
                variant
            });
            string variantAcc = VariantApplication.GetAccession(testProteinWithMod, new[] { variant });
            //First Write XML Database
            string xmlName = "oblm.xml";

            //Add Mod to list and write XML input database
            var modList = new Dictionary <string, HashSet <Tuple <int, Modification> > >();
            var hash    = new HashSet <Tuple <int, Modification> >
            {
                new Tuple <int, Modification>(1, new Modification(_originalId: "acetyl on P", _modificationType: "type", _target: motifP, _monoisotopicMass: 42, _locationRestriction: "Anywhere.")),
            };
            var hashVar = new HashSet <Tuple <int, Modification> >
            {
                new Tuple <int, Modification>(3, new Modification(_originalId: "acetyl on K", _modificationType: "type", _target: motifK, _monoisotopicMass: 42, _locationRestriction: "Anywhere.")),
            };

            modList.Add(testProteinWithMod.Accession, hash);
            modList.Add(variantAcc, hashVar);
            ProteinDbWriter.WriteXmlDatabase(modList, new List <Protein> {
                testProteinWithMod
            }, xmlName);

            //now write MZML file
            var variantProteins = ProteinDbLoader.LoadProteinXML(xmlName, true, DecoyType.Reverse, null, false, null, out var unknownModifications);
            var variantProtein  = variantProteins[0];
            var variantDecoy    = variantProteins[1];

            Assert.AreEqual(0, unknownModifications.Count);

            Assert.AreEqual(2, variantProteins.Count); // target & decoy
            Assert.AreEqual(2, variantProteins[0].OneBasedPossibleLocalizedModifications.Count);
            List <int> foundResidueIndicies   = variantProtein.OneBasedPossibleLocalizedModifications.Select(k => k.Key).ToList();
            List <int> expectedResidueIndices = new List <int>()
            {
                1, 3
            };

            Assert.That(foundResidueIndicies, Is.EquivalentTo(expectedResidueIndices));
            Assert.AreEqual(2, variantDecoy.OneBasedPossibleLocalizedModifications.Count);
            foundResidueIndicies   = variantDecoy.OneBasedPossibleLocalizedModifications.Select(k => k.Key).ToList();
            expectedResidueIndices = new List <int>()
            {
                4, 6
            };                                                 //originally modified residues are now at the end in the decoy
            Assert.That(foundResidueIndicies, Is.EquivalentTo(expectedResidueIndices));

            var thisOk = unknownModifications;                                    //for debugging
            var commonParamsAtThisPoint = task1.CommonParameters.DigestionParams; //for debugging

            var digestedList = variantProteins[0].GetVariantProteins()[0].Digest(task1.CommonParameters.DigestionParams, new List <Modification>(), variableModifications).ToList();

            Assert.AreEqual(4, digestedList.Count);

            //Set Peptide with 1 mod at position 3
            PeptideWithSetModifications pepWithSetMods1 = digestedList[1];

            //Finally Write MZML file
            Assert.AreEqual("PEK[type:acetyl on K]TID", pepWithSetMods1.FullSequence);//this might be base sequence
            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepWithSetMods1
            });
            string mzmlName = @"hello.mzML";

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlName, false);

            //run!
            var engine = new EverythingRunnerEngine(taskList, new List <string> {
                mzmlName
            },
                                                    new List <DbForTask> {
                new DbForTask(xmlName, false)
            }, Environment.CurrentDirectory);

            engine.Run();
        }
示例#10
0
 /// <summary>
 /// Determines whether this interval overlaps the queried interval
 /// </summary>
 /// <param name="segment"></param>
 /// <returns></returns>
 internal bool Intersects(SequenceVariation segment)
 {
     return(segment.OneBasedEndPosition >= OneBasedBeginPosition && segment.OneBasedBeginPosition <= OneBasedEndPosition);
 }
示例#11
0
 /// <summary>
 /// Determines whether this interval includes the queried interval
 /// </summary>
 /// <param name="segment"></param>
 /// <returns></returns>
 internal bool Includes(SequenceVariation segment)
 {
     return(OneBasedBeginPosition <= segment.OneBasedBeginPosition && OneBasedEndPosition >= segment.OneBasedEndPosition);
 }