예제 #1
0
        private static SilacLabel AssignValidHeavyCharacter(SilacLabel originalLabel, char heavyLabel)
        {
            double massDifference = Convert.ToDouble(originalLabel.MassDifference.Substring(1));

            if (originalLabel.MassDifference[0] == '-')
            {
                massDifference *= -1;
            }
            //Add the silac residues to the dictionary
            Residue.AddNewResiduesToDictionary(new List <Residue> {
                new Residue(originalLabel.MassDifference, heavyLabel, heavyLabel.ToString(), Chemistry.ChemicalFormula.ParseFormula(originalLabel.LabelChemicalFormula), ModificationSites.All)
            });

            return(new SilacLabel(originalLabel.OriginalAminoAcid, heavyLabel, originalLabel.LabelChemicalFormula, massDifference));
        }
예제 #2
0
        public static void RefreshAminoAcidDictionary()
        {
            //read in all the amino acids (they already exist in mzlib, but there might be synthetic amino acids that need to be included)
            string aminoAcidPath = Path.Combine(DataDir, @"CustomAminoAcids", @"CustomAminoAcids.txt");

            if (File.Exists(aminoAcidPath)) //if it already exists
            {
                string[]       aminoAcidLines = File.ReadAllLines(aminoAcidPath);
                List <Residue> residuesToAdd  = new List <Residue>();
                for (int i = 1; i < aminoAcidLines.Length; i++)
                {
                    string[] line = aminoAcidLines[i].Split('\t').ToArray(); //tsv Name, one letter, monoisotopic, chemical formula
                    if (line.Length >= 4)                                    //check something is there (not a blank line)
                    {
                        char letter = line[1][0];
                        if (InvalidAminoAcids.Contains(letter))
                        {
                            throw new ProteaseGuruException("Error while reading 'CustomAminoAcids.txt'. Line " + (i + 1).ToString() + " contains an invalid amino acid. (Ex: " + string.Join(", ", InvalidAminoAcids.Select(x => x.ToString())) + ")");
                        }
                        try
                        {
                            ChemicalFormula formula = ChemicalFormula.ParseFormula(line[3]);

                            //if it doesn't already exist or it does exist but has a different mass, add the entry
                            if (!(Residue.TryGetResidue(letter, out Residue residue)) ||
                                !(formula.Formula.Equals(residue.ThisChemicalFormula.Formula)))
                            {
                                residuesToAdd.Add(new Residue(line[0], letter, line[1], formula, ModificationSites.Any));
                            }
                        }
                        catch
                        {
                            throw new ProteaseGuruException("Error while reading 'CustomAminoAcids.txt'. Line " + (i + 1).ToString() + " was not in the correct format.");
                        }
                    }
                }
                Residue.AddNewResiduesToDictionary(residuesToAdd);
            }
            else //create it so that it can be manipulated
            {
                WriteAminoAcidsFile();
            }
        }
        private void SaveCustomAminoAcid_Click(object sender, RoutedEventArgs e)
        {
            //VALIDATE INPUT
            if (AminoAcidTextBox.Text.Length == 0)
            {
                MessageBox.Show("Please specify the character that represents a synthetic amino acid in the database");
                return;
            }
            char aminoAcidLetter = AminoAcidTextBox.Text.First();

            ChemicalFormula formula;

            try
            {
                formula = ChemicalFormula.ParseFormula(ChemicalFormulaTextBox.Text);
            }
            catch
            {
                MessageBox.Show("The checmical formula '" + ChemicalFormulaTextBox.Text + "' could not be parsed. Please try again.");
                return;
            }

            if (GlobalVariables.InvalidAminoAcids.Contains(aminoAcidLetter))
            {
                MessageBox.Show("The amino acid '" + aminoAcidLetter + "' cannot be assigned. " +
                                "\nThis character is used for modification motifs or as result delimiters. " +
                                "\nThe following amino acids are not allowed:" +
                                string.Join(", ", GlobalVariables.InvalidAminoAcids.Select(x => x.ToString())) + ")");
                return;
            }

            //check if the specified amino acid already exists
            if (Residue.TryGetResidue(aminoAcidLetter, out Residue residue))
            {
                MessageBox.Show("The amino acid '" + aminoAcidLetter + "' already exists." +
                                "\nMonoisotopic Mass: " + residue.MonoisotopicMass +
                                "\nChemical Formula: " + residue.ThisChemicalFormula.Formula +

                                "\n\nYou may overwrite this amino acid by manually deleting/modifying the current entry. " +
                                "\nThis can be done in MetaMorpheus by navigating to 'Data' in the top-left corner, " +
                                "selecting 'Open folder with mods/data files' from the drop down menu, " +
                                "opening the folder 'CustomAminoAcids', and opening the file 'CustomAminoAcids.txt." +
                                "\nMetaMorpheus will need to be restarted for these changes to take effect." +

                                "\n\nAmino acids can be reset to their default values by deleting the file 'CustomAminoAcids.txt' and restarting MetaMorpheus.");
                return;
            }

            //Alright, the entry is valid
            //Append the entry to the CustomAminoAcids.txt file
            string aminoAcidDirectory  = Path.Combine(GlobalVariables.DataDir, @"CustomAminoAcids");
            string customAminoAcidPath = Path.Combine(aminoAcidDirectory, @"CustomAminoAcids.txt");

            //check that the file exists and create it if it doesn't
            if (!File.Exists(customAminoAcidPath))
            {
                GlobalVariables.WriteAminoAcidsFile();
            }

            //save it in the amino acid file
            List <string> customAminoAcidsText = File.ReadAllLines(customAminoAcidPath).ToList();

            customAminoAcidsText.Add(AminoAcidTextBox.Text + '\t' + aminoAcidLetter + '\t' + formula.MonoisotopicMass.ToString() + '\t' + formula.Formula); //tsv Name, one letter, monoisotopic, chemical formula
            File.WriteAllLines(customAminoAcidPath, customAminoAcidsText);

            //add the mod to the residue dictionary
            Residue.AddNewResiduesToDictionary(new List <Residue> {
                new Residue(AminoAcidTextBox.Text, aminoAcidLetter, AminoAcidTextBox.Text, formula, ModificationSites.Any)
            });
            MessageBox.Show("Success! Amino Acid '" + aminoAcidLetter + "' has been added to the dictionary." +
                            "\nMonoisotopic Mass: " + formula.MonoisotopicMass.ToString() +
                            "\nChemical Formula: " + formula.Formula);
            DialogResult = true;
        }
예제 #4
0
        public static void TestSilacNoLightProtein()
        {
            //The concern with multiple mods per label is the conversions back and forth between "light" and "heavy" labels
            Residue heavyArginine   = new Residue("c", 'c', "c", Chemistry.ChemicalFormula.ParseFormula("C6H12N{15}4O"), ModificationSites.All);     //+4 arginine
            Residue heavierArginine = new Residue("d", 'd', "d", Chemistry.ChemicalFormula.ParseFormula("C{13}6H12N{15}4O"), ModificationSites.All); //+10 arginine

            Residue.AddNewResiduesToDictionary(new List <Residue> {
                heavyArginine
            });                                                                      //These should be added in the  search task, but we need to add this one earlier so that we can create a heavy pwsm

            Residue lightArginine = Residue.GetResidue('R');

            SilacLabel heavyLabel   = new SilacLabel(lightArginine.Letter, heavyArginine.Letter, heavyArginine.ThisChemicalFormula.Formula, heavyArginine.MonoisotopicMass - lightArginine.MonoisotopicMass);
            SilacLabel heavierLabel = new SilacLabel(lightArginine.Letter, heavierArginine.Letter, heavierArginine.ThisChemicalFormula.Formula, heavierArginine.MonoisotopicMass - lightArginine.MonoisotopicMass);

            SearchTask task = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    SilacLabels = new List <SilacLabel> {
                        heavyLabel, heavierLabel
                    }
                },
                CommonParameters = new CommonParameters(digestionParams: new DigestionParams(generateUnlabeledProteinsForSilac: false)) //this is the important part of the unit test
            };

            PeptideWithSetModifications heavyPeptide = new PeptideWithSetModifications("PEPTIDEc", new Dictionary <string, Modification>());

            List <double> massDifferences = new List <double> {
                heavierArginine.MonoisotopicMass - heavyArginine.MonoisotopicMass
            };
            MsDataFile myMsDataFile1 = new TestDataFile(heavyPeptide, massDifferences);
            string     mzmlName      = @"silac.mzML";

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

            string  xmlName    = "SilacDb.xml";
            Protein theProtein = new Protein("PEPTIDER", "accession1");

            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> {
                theProtein
            }, xmlName);

            string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestSilac");

            Directory.CreateDirectory(outputFolder);
            var theStringResult = task.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(xmlName, false)
            }, new List <string> {
                mzmlName
            }, "taskId1").ToString();

            //test proteins
            string[] output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllProteinGroups.tsv");
            Assert.AreEqual(output.Length, 2);
            Assert.IsTrue(output[0].Contains("Modification Info List\tIntensity_silac(R+3.988)\tIntensity_silac(R+10.008)")); //test that two files were made and no light file
            Assert.IsTrue(output[1].Contains("875000\t437500"));                                                              //test the heavier intensity is half that of the heavy (per the raw file)

            //test peptides
            output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeptides.tsv");
            Assert.AreEqual(output.Length, 2);
            Assert.IsTrue(output[0].Contains("Organism\tIntensity_silac(R+3.988)\tIntensity_silac(R+10.008)")); //test the two files were made and no light file
            Assert.IsTrue(output[1].Contains("875000\t437500"));                                                //test intensity

            //test peaks
            output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeaks.tsv");
            Assert.AreEqual(output.Length, 3);
            Assert.IsTrue(output[1].Contains("silac\t"));             //test the filename was NOT modified (it was for proteins, but we don't want it for peptides)
            Assert.IsTrue(output[2].Contains("silac\t"));             //test the filename was NOT modified (it was for proteins, but we don't want it for peptides)
            Assert.IsTrue(output[1].Contains("PEPTIDER(+3.988)\t"));  //test light sequence was not modified
            Assert.IsTrue(output[2].Contains("PEPTIDER(+10.008)\t")); //test heavy sequence was output correctly (do NOT want "PEPTIDEa")
            Assert.IsTrue(output[1].Contains("959.44"));              //test light mass
            Assert.IsTrue(output[2].Contains("965.46"));              //test heavy mass

            //test PSMs
            output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllPSMs.psmtsv");
            Assert.IsTrue(output[1].Contains("959.44"));           //test the correct monoisotopic mass
            Assert.IsTrue(output[1].Contains("PEPTIDER(+3.988)")); //test the correct psm
            Assert.IsTrue(output[1].Contains("silac\t"));          //test the filename was NOT modified (it was for proteins, but we don't want it for peptides)

            //Clear the old files
            Directory.Delete(outputFolder, true);
            File.Delete(xmlName);
            File.Delete(mzmlName);
        }
예제 #5
0
        public void SilacLabelTest()
        {
            Protein originalProtein = new Protein("ACDEFGHIKAKAK", "TEST");
            List <PeptideWithSetModifications> originalDigest = originalProtein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).ToList();

            //Multiple SILAC labels
            Residue        lysine        = Residue.GetResidue('K');
            Residue        arginine      = Residue.GetResidue('R');
            Residue        heavyLabel    = new Residue("heavy", 'a', "aaa", ChemicalFormula.ParseFormula("C{13}6H12N2O"), ModificationSites.All);       //Lysine +6
            Residue        heavierLabel  = new Residue("heavier", 'b', "bbb", ChemicalFormula.ParseFormula("C{13}6H12N{15}2O"), ModificationSites.All); //Lysine +8
            Residue        heavyArginine = new Residue("heavyR", 'c', "ccc", ChemicalFormula.ParseFormula("C{13}6H5N{15}4O"), ModificationSites.All);   //Arginine +10
            List <Residue> residuesToAdd = new List <Residue> {
                heavyLabel, heavierLabel, heavyArginine
            };

            Residue.AddNewResiduesToDictionary(residuesToAdd);
            List <SilacLabel> silacLabels = new List <SilacLabel>
            {
                new SilacLabel('K', 'a', heavyLabel.ThisChemicalFormula.Formula, heavyLabel.MonoisotopicMass - lysine.MonoisotopicMass),
                new SilacLabel('K', 'b', heavierLabel.ThisChemicalFormula.Formula, heavierLabel.MonoisotopicMass - lysine.MonoisotopicMass)
            };
            List <PeptideWithSetModifications> silacDigest = originalProtein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>(), silacLabels).ToList();

            Assert.IsTrue(originalDigest.Count * 3 == silacDigest.Count); //check that each peptide now has a light, heavy, and heavier compliment

            double silacPeptideLightMonoisotopicMass   = silacDigest.Where(x => x.BaseSequence.Contains("K")).First().MonoisotopicMass;
            double silacPeptideHeavyMonoisotopicMass   = silacDigest.Where(x => x.BaseSequence.Contains("a")).First().MonoisotopicMass;
            double silacPeptideHeavierMonoisotopicMass = silacDigest.Where(x => x.BaseSequence.Contains("b")).First().MonoisotopicMass;

            Assert.IsTrue(silacPeptideLightMonoisotopicMass != double.NaN);                                                                                                                           //if both NaN, then the mass comparison statements will always be true, because NaN + double = NaN
            Assert.IsTrue(silacPeptideHeavyMonoisotopicMass != double.NaN);                                                                                                                           //if both NaN, then the mass comparison statements will always be true, because NaN + double = NaN
            Assert.IsTrue(silacPeptideHeavierMonoisotopicMass != double.NaN);                                                                                                                         //if both NaN, then the mass comparison statements will always be true, because NaN + double = NaN

            Assert.IsTrue(Math.Round(silacPeptideLightMonoisotopicMass + heavyLabel.MonoisotopicMass, 5).Equals(Math.Round(silacPeptideHeavyMonoisotopicMass + lysine.MonoisotopicMass, 5)));         //check that the residue masses were succesfully added
            Assert.IsTrue(Math.Round(silacPeptideHeavyMonoisotopicMass + heavierLabel.MonoisotopicMass, 5).Equals(Math.Round(silacPeptideHeavierMonoisotopicMass + heavyLabel.MonoisotopicMass, 5))); //check that the residue masses were succesfully added

            //code coverage
            SilacLabel testParameterlessConstructorForTomlsWithoutAnyRealTestAndMoreJustForCodeCoverage = new SilacLabel();

            Assert.IsTrue(testParameterlessConstructorForTomlsWithoutAnyRealTestAndMoreJustForCodeCoverage != null);

            Assert.IsTrue(silacLabels[0].AdditionalLabels == null);
            //The zero index label is K to a with a mass diff of 6
            //the one index label is K to b with a mass diff of 8
            silacLabels[0].AddAdditionalSilacLabel(new SilacLabel('D', 'c', heavyLabel.ThisChemicalFormula.Formula, heavyLabel.MonoisotopicMass - lysine.MonoisotopicMass - 1));
            Assert.IsTrue(silacLabels[0].AdditionalLabels.Count == 1);
            silacLabels[0].AddAdditionalSilacLabel(new SilacLabel('E', 'd', heavyLabel.ThisChemicalFormula.Formula, heavyLabel.MonoisotopicMass - lysine.MonoisotopicMass + 1));
            Assert.IsTrue(silacLabels[0].AdditionalLabels.Count == 2);
            silacDigest = originalProtein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>(), silacLabels).ToList();
            Assert.IsTrue(silacDigest.Count == 9);

            //Turnover
            silacLabels = new List <SilacLabel>
            {
                new SilacLabel('K', 'b', heavierLabel.ThisChemicalFormula.Formula, heavierLabel.MonoisotopicMass - lysine.MonoisotopicMass)
            };
            silacDigest = originalProtein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>(), silacLabels, (null, silacLabels[0])).ToList();
            Assert.IsTrue(silacDigest.Count == 14);
            silacDigest = originalProtein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>(), silacLabels, (silacLabels[0], null)).ToList();
            Assert.IsTrue(silacDigest.Count == 14);

            silacLabels = new List <SilacLabel>
            {
                new SilacLabel('K', 'a', heavyLabel.ThisChemicalFormula.Formula, heavyLabel.MonoisotopicMass - lysine.MonoisotopicMass),
                new SilacLabel('K', 'b', heavierLabel.ThisChemicalFormula.Formula, heavierLabel.MonoisotopicMass - lysine.MonoisotopicMass)
            };
            silacDigest = originalProtein.Digest(new DigestionParams(generateUnlabeledProteinsForSilac: false), new List <Modification>(), new List <Modification>(), silacLabels, (silacLabels[1], silacLabels[0])).ToList();
            Assert.IsTrue(silacDigest.Count == 14);

            originalProtein = new Protein("ACDEFGHIKARAK", "TEST");
            silacLabels[1].AddAdditionalSilacLabel(new SilacLabel('R', 'c', heavyArginine.ThisChemicalFormula.Formula, heavyArginine.MonoisotopicMass - arginine.MonoisotopicMass));
            silacDigest = originalProtein.Digest(new DigestionParams(generateUnlabeledProteinsForSilac: false), new List <Modification>(), new List <Modification>(), silacLabels, (silacLabels[1], silacLabels[0])).ToList();
            Assert.IsTrue(silacDigest.Count == 14);

            silacLabels = new List <SilacLabel>
            {
                new SilacLabel('K', 'a', heavyLabel.ThisChemicalFormula.Formula, heavyLabel.MonoisotopicMass - lysine.MonoisotopicMass),
                new SilacLabel('K', 'b', heavierLabel.ThisChemicalFormula.Formula, heavierLabel.MonoisotopicMass - lysine.MonoisotopicMass)
            };
            silacLabels[0].AddAdditionalSilacLabel(new SilacLabel('R', 'c', heavyArginine.ThisChemicalFormula.Formula, heavyArginine.MonoisotopicMass - arginine.MonoisotopicMass));
            silacDigest = originalProtein.Digest(new DigestionParams(generateUnlabeledProteinsForSilac: false), new List <Modification>(), new List <Modification>(), silacLabels, (silacLabels[1], silacLabels[0])).ToList();
            Assert.IsTrue(silacDigest.Count == 14);
        }