public static void GlyTest_GetKindString() { byte[] kind = new byte[] { 3, 4, 0, 0, 1, 0, 0, 0, 0, 0 }; string kindString = Glycan.GetKindString(kind); Assert.AreEqual("H3N4F1", kindString); }
public static List <Product> GetGlycanYIons(double precursorMass, Glycan glycan) { List <Product> YIons = new List <Product>(); YIons.Add(new Product(ProductType.M, FragmentationTerminus.Both, precursorMass - (double)glycan.Mass / 1E5, 0, 0, (double)glycan.Mass / 1E5)); //Y0 ion. Glycan totally loss. foreach (var ion in glycan.Ions) { Product product = new Product(ProductType.M, FragmentationTerminus.Both, precursorMass - (double)ion.LossIonMass / 1E5, 0, 0, (double)ion.LossIonMass / 1E5); YIons.Add(product); } return(YIons); }
public static void GlyTest_GlyGetTheoreticalFragments() { Protein pep = new Protein("TKPREEQYNSTYR", "accession"); DigestionParams digestionParams = new DigestionParams(minPeptideLength: 7); var aPeptideWithSetModifications = pep.Digest(digestionParams, new List <Modification>(), new List <Modification>()); string[] motifs = new string[] { "Nxs", "Nxt" }; var sites = GlycoSpectralMatch.GetPossibleModSites(aPeptideWithSetModifications.Last(), motifs); Glycan glycan = Glycan.Struct2Glycan("(N(F)(N(H(H(N))(H(N)))))", 0); //using (StreamWriter output = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "GlycanFragmentions.txt"))) //{ // foreach (var product in fragmentIons) // { // foreach (var ion in product.Item2) // { // output.WriteLine(ion.Annotation + "\t" + ion.NeutralLoss.ToString() + "\t" + ion.NeutralMass.ToString()); // } // } //} CommonParameters commonParameters = new CommonParameters(deconvolutionMassTolerance: new PpmTolerance(20), trimMsMsPeaks: false); string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"GlycoTestData/Glyco_3383.mgf"); //"25170.mgf" MyFileManager myFileManager = new MyFileManager(true); var msDataFile = myFileManager.LoadFile(filePath, commonParameters); var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(msDataFile, filePath, commonParameters).ToArray(); var glycanMod = Glycan.NGlycanToModification(glycan); var glycopep = GlycoPeptides.GenerateGlycopeptide(sites[0], aPeptideWithSetModifications.Last(), glycan); List <Product> fragmentIons = new List <Product>(); glycopep.Fragment(DissociationType.HCD, FragmentationTerminus.Both, fragmentIons); var glycanYIons = GlycoPeptides.GetGlycanYIons(listOfSortedms2Scans[0].PrecursorMass, glycan); var matchedGlycanYIons = MetaMorpheusEngine.MatchFragmentIons(listOfSortedms2Scans[0], glycanYIons, commonParameters); Assert.AreEqual(matchedGlycanYIons.Count, 14); //TO DO: The neutroloss is not annotated well. var matchedFragmentIons = MetaMorpheusEngine.MatchFragmentIons(listOfSortedms2Scans[0], fragmentIons, commonParameters); var coreIons = GlycoPeptides.ScanGetTrimannosylCore(matchedFragmentIons, glycan); Assert.AreEqual(coreIons.Count, 6); var filter = GlycoPeptides.ScanTrimannosylCoreFilter(matchedFragmentIons, glycan); Assert.AreEqual(filter, true); var NGlycans = GlycanDatabase.LoadGlycan(GlobalVariables.NGlycanLocations[0], true, false); var bestGlycans = GlycoPeptides.MatchBestGlycan(listOfSortedms2Scans[0], NGlycans.ToArray(), commonParameters).Where(p => p != null && p.Item2 >= 2).OrderByDescending(p => p.Item2).Take(100).OrderBy(p => p.Item3).ToArray();; }
public static void OGlycoTest_GetKPerWithDuplicate() { List <int> input = new List <int> { 3, 5, 2, 7 }; int[] ids = new int[3] { 2, 2, 3 }; var perWithDuplicate = GlycoPeptides.GetPermutations(input, ids); var allPermutation = Glycan.GetPermutations(input, ids.Length); Assert.That(perWithDuplicate.Count() == allPermutation.Count() / 2); }
//The function here is to calculate permutation localization which could be used to compare with Graph-Localization. public static List <int[]> GetPermutations(List <int> allModPos, int[] glycanBoxId) { var length = glycanBoxId.Length; var indexes = Enumerable.Range(0, length).ToArray(); int[] orderGlycan = new int[length]; List <int[]> permutateModPositions = new List <int[]>(); var combinations = Glycan.GetKCombs(allModPos, length); foreach (var com in combinations) { var permutation = Glycan.GetPermutations(com, length); HashSet <string> keys = new HashSet <string>(); foreach (var per in permutation) { Array.Sort(indexes); var orderedPer = per.ToArray(); Array.Sort(orderedPer, indexes); for (int i = 0; i < length; i++) { orderGlycan[i] = glycanBoxId[indexes[i]]; } var key = string.Join(",", orderGlycan.Select(p => p.ToString())); if (!keys.Contains(key)) { keys.Add(key); permutateModPositions.Add(per.ToArray()); } } } return(permutateModPositions); }
public static PeptideWithSetModifications GenerateGlycopeptide(int position, PeptideWithSetModifications peptide, Glycan glycan) { Modification modification = Glycan.NGlycanToModification(glycan); Dictionary <int, Modification> testMods = new Dictionary <int, Modification> { { position, modification } }; if (!peptide.AllModsOneIsNterminus.Keys.Contains(position)) { foreach (var mod in peptide.AllModsOneIsNterminus) { testMods.Add(mod.Key, mod.Value); } } var testPeptide = new PeptideWithSetModifications(peptide.Protein, peptide.DigestionParams, peptide.OneBasedStartResidueInProtein, peptide.OneBasedEndResidueInProtein, peptide.CleavageSpecificityForFdrCategory, peptide.PeptideDescription, peptide.MissedCleavages, testMods, peptide.NumFixedMods); return(testPeptide); }
public static void OGlycoTest_GetK() { List <int> input = new List <int> { 1, 2, 3, 4, 5 }; //Combination test var kcombs = Glycan.GetKCombs(input, 3); Assert.AreEqual(kcombs.Count(), 10); var allcombs = Glycan.GetKCombs(input, 5); Assert.AreEqual(allcombs.Count(), 1); //Combination test with repetition var kcombs_rep = Glycan.GetKCombsWithRept(input, 3); Assert.AreEqual(kcombs_rep.Count(), 35); var allcombs_rep = Glycan.GetKCombsWithRept(input, 5); Assert.AreEqual(allcombs_rep.Count(), 126); //Permutation test var kperm = Glycan.GetPermutations(input, 3); Assert.AreEqual(kperm.Count(), 60); var allperm = Glycan.GetPermutations(input, 5).ToList(); Assert.AreEqual(allperm.Count(), 120); //Permutation test with repetition var kperm_rep = Glycan.GetPermutationsWithRept(input, 3); Assert.AreEqual(kperm_rep.Count(), 125); }
public override string ToString() { var sb = new StringBuilder(); sb.Append(FullFilePath + "\t"); sb.Append(ScanNumber + "\t"); sb.Append(ScanRetentionTime + "\t"); sb.Append(PrecursorScanNumber + "\t"); sb.Append(ScanPrecursorMonoisotopicPeakMz + "\t"); sb.Append(ScanPrecursorCharge + "\t"); sb.Append(ScanPrecursorMass + "\t"); var proteinAccessionString = ProteinAccession ?? PsmTsvWriter.Resolve(BestMatchingPeptides.Select(p => p.Peptide.Protein.Accession), FullSequence).ResolvedString; sb.Append(proteinAccessionString + "\t"); sb.Append(Organism + "\t"); sb.Append(PsmTsvWriter.Resolve(BestMatchingPeptides.Select(b => b.Peptide.Protein.FullName), FullSequence).ResolvedString + "\t"); int _FirstOneBasedStartResidueInProtein = OneBasedStartResidueInProtein.HasValue ? OneBasedStartResidueInProtein.Value : BestMatchingPeptides.First().Peptide.OneBasedStartResidueInProtein; int _FirstOneBasedEndResidueInProtein = OneBasedEndResidueInProtein.HasValue ? OneBasedEndResidueInProtein.Value : BestMatchingPeptides.First().Peptide.OneBasedEndResidueInProtein;; if (OneBasedStartResidueInProtein.HasValue) { sb.Append("[" + OneBasedStartResidueInProtein.Value.ToString() + " to " + OneBasedEndResidueInProtein.Value.ToString() + "]" + '\t'); } else { sb.Append("\t"); } sb.Append(BaseSequence + "\t"); sb.Append(BestMatchingPeptides.First().Peptide.PreviousAminoAcid + "," + BestMatchingPeptides.First().Peptide.NextAminoAcid + "\t"); sb.Append(FullSequence + "\t"); sb.Append(BestMatchingPeptides.First().Peptide.AllModsOneIsNterminus.Count + "\t"); sb.Append((PeptideMonisotopicMass.HasValue ? PeptideMonisotopicMass.Value.ToString() : "---")); sb.Append("\t"); sb.Append(Score + "\t"); sb.Append(Rank + "\t"); if (ChildMatchedFragmentIons == null) { foreach (var mid in MatchedIonDataDictionary(this.MatchedFragmentIons)) { sb.Append(mid.Value); sb.Append("\t"); } } else { StringBuilder[] scanFragmentStringbuilder = new StringBuilder[6]; int i = 0; foreach (var mid in MatchedIonDataDictionary(this.MatchedFragmentIons)) { scanFragmentStringbuilder[i] = new StringBuilder(); scanFragmentStringbuilder[i].Append("{" + ScanNumber + "@" + mid.Value + "}"); i++; } foreach (var childScan in ChildMatchedFragmentIons) { int j = 0; int oneBasedScan = childScan.Key; foreach (var mid in MatchedIonDataDictionary(childScan.Value)) { scanFragmentStringbuilder[j].Append("{" + oneBasedScan + "@" + mid.Value + "}"); j++; } } foreach (var s in scanFragmentStringbuilder) { sb.Append(s.ToString() + "\t"); } } sb.Append((IsDecoy) ? "D" : (IsContaminant) ? "C" : "T"); sb.Append("\t"); sb.Append(FdrInfo != null? FdrInfo.QValue.ToString() : "-1"); sb.Append("\t"); sb.Append("0" + "\t"); sb.Append("0" + "\t"); if (NGlycan != null) { sb.Append(PeptideScore + "\t"); sb.Append(GlycanScore + "\t"); sb.Append(DiagnosticIonScore + "\t"); sb.Append((double)NGlycan.First().Mass / 1E5); sb.Append("\t"); sb.Append(Glycan.GetKindString(NGlycan.First().Kind)); sb.Append("\t"); sb.Append(R138vs144.ToString()); sb.Append("\t"); if (NGlycan.First().Struc != null) { sb.Append(NGlycan.First().Struc); sb.Append("\t"); } } if (Routes != null) { sb.Append(LocalizationGraphs.First().TotalScore + "\t"); sb.Append(GlycanScore + "\t"); sb.Append(DiagnosticIonScore + "\t"); var glycanBox = GlycanBox.OGlycanBoxes[Routes.First().ModBoxId]; sb.Append(glycanBox.NumberOfMods + "\t"); sb.Append(LocalizationGraphs.First().ModPos.Length + "\t"); sb.Append(glycanBox.Mass + "\t"); sb.Append(Glycan.GetKindString(glycanBox.Kind)); sb.Append("\t"); var NSiteExist = MotifExist(BaseSequence, new string[] { "Nxt", "Nxs" }); sb.Append(NSiteExist); sb.Append("\t"); sb.Append(R138vs144.ToString()); sb.Append("\t"); //Get glycans var glycans = new Glycan[glycanBox.NumberOfMods]; for (int i = 0; i < glycanBox.NumberOfMods; i++) { glycans[i] = GlycanBox.GlobalOGlycans[glycanBox.ModIds[i]]; } if (glycans.First().Struc != null) { sb.Append(string.Join(",", glycans.Select(p => p.Struc.ToString()).ToArray())); } sb.Append("\t"); sb.Append(CorrectLocalizationLevel(SiteSpeciLocalProb, LocalizationGraphs.First(), Routes.First(), LocalizedGlycan, LocalizationLevel)); sb.Append("\t"); //string localizedGlycan = LocalizedGlycan.Where(p=>p.Item3).Count() > 0 ? "[" + string.Join(",", LocalizedGlycan.Where(p => p.Item3).Select(p => p.Item1.ToString() + "-" + p.Item2.ToString())) + "]" : ""; //sb.Append(localizedGlycan); sb.Append("\t"); string local_peptide = ""; string local_protein = ""; LocalizedSiteSpeciLocalInfo(SiteSpeciLocalProb, LocalizedGlycan, OneBasedStartResidueInProtein, ref local_peptide, ref local_protein); sb.Append(local_peptide); sb.Append("\t"); sb.Append(local_protein); sb.Append("\t"); sb.Append(AllLocalizationInfo(Routes)); sb.Append("\t"); sb.Append(SiteSpeciLocalInfo(SiteSpeciLocalProb)); } return(sb.ToString()); }
public static List <Product> GetGlycanYIons(PeptideWithSetModifications peptide, Glycan glycan) { double possiblePeptideMass = peptide.MonoisotopicMass; List <Product> YIons = new List <Product>(); YIons.Add(new Product(ProductType.M, FragmentationTerminus.Both, possiblePeptideMass + (double)glycan.Mass / 1E5, 0, 0, (double)glycan.Mass / 1E5)); foreach (var ion in glycan.Ions) { Product product = new Product(ProductType.M, FragmentationTerminus.Both, possiblePeptideMass + (double)glycan.Mass / 1E5, 0, 0, (double)ion.LossIonMass / 1E5); YIons.Add(product); } return(YIons); }
public static bool ScanTrimannosylCoreFilter(List <MatchedFragmentIon> matchedFragmentIons, Glycan glycan) { Dictionary <int, double> cores = ScanGetTrimannosylCore(matchedFragmentIons, glycan); if (cores.Count > 2) { return(true); } else if (cores.Keys.Contains(83) && cores.Keys.Contains(203)) { return(true); } return(false); }
public static Dictionary <int, double> ScanGetTrimannosylCore(List <MatchedFragmentIon> matchedFragmentIons, Glycan glycan) { Dictionary <int, double> cores = new Dictionary <int, double>(); foreach (var fragment in matchedFragmentIons.Where(p => p.NeutralTheoreticalProduct.ProductType == ProductType.M)) { if (Glycan.TrimannosylCores.ContainsKey((int)((double)glycan.Mass / 1E5 - fragment.NeutralTheoreticalProduct.NeutralLoss))) { var pair = Glycan.TrimannosylCores.Where(p => p.Key == (int)((double)glycan.Mass / 1E5 - fragment.NeutralTheoreticalProduct.NeutralLoss)).FirstOrDefault(); if (!cores.ContainsKey(pair.Key)) { cores.Add(pair.Key, pair.Value); } } } return(cores); }