public static void GlyTest_ModificationSites() { PeptideWithSetModifications pep = new PeptideWithSetModifications("ELNPTPNVEVNVECR", null); string[] motifs = new string[] { "Nxs", "Nxt" }; var sites = GlycoSpectralMatch.GetPossibleModSites(pep, motifs); Assert.That(sites.Count() == 1 && sites[0] == 4); ModificationMotif.TryGetMotif("C", out ModificationMotif motif1); Modification mod1 = new Modification(_originalId: "Carbamidomethyl of C", _modificationType: "Common Fixed", _target: motif1, _locationRestriction: "Anywhere.", _monoisotopicMass: 57.02146372068994); ModificationMotif.TryGetMotif("N", out ModificationMotif motif2); Modification mod2 = new Modification(_originalId: "Test of N", _modificationType: "Common Fixed", _target: motif2, _locationRestriction: "Anywhere."); var testN = new PeptideWithSetModifications("C[Common Fixed:Carbamidomethyl of C]N[Common Fixed:Test of N]SSDQPKL[Common Fixed:Carbamidomethyl of C]NLSGIETP", new Dictionary <string, Modification> { { "Carbamidomethyl of C", mod1 }, { "Test of N", mod2 } }); var testSites = GlycoSpectralMatch.GetPossibleModSites(testN, motifs); Assert.That(testSites.Count() == 1 && testSites[0] == 11); var testC = new PeptideWithSetModifications("TELAAYLSC[Common Fixed:Carbamidomethyl of C]NATK", new Dictionary <string, Modification> { { "Carbamidomethyl of C", mod1 } }); var testCSites = GlycoSpectralMatch.GetPossibleModSites(testC, motifs); Assert.That(testCSites.Count() == 1 && testSites[0] == 11); }
public static void GlycoTest_MotifExist() { string baseSeq = "AFGQFFSPGEVIYNKTDRAG"; var exist = GlycoSpectralMatch.MotifExist(baseSeq, new string[] { "Nxt", "Nxs" }); Assert.That(exist); }
public static void WritePsmGlycoToTsv(List <GlycoSpectralMatch> items, string filePath, int writeType) { if (items.Count == 0) { return; } using (StreamWriter output = new StreamWriter(filePath)) { string header = ""; switch (writeType) { case 1: header = GlycoSpectralMatch.GetTabSepHeaderSingle(); break; case 2: header = GlycoSpectralMatch.GetTabSepHeaderOGlyco(); break; case 3: header = GlycoSpectralMatch.GetTabSepHeaderNGlyco(); break; default: break; } output.WriteLine(header); foreach (var heh in items) { output.WriteLine(heh.ToString()); } } }
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_FragmentIonsHash() { //Get glycanBox var glycanBox = OGlycanBoxes[8]; Protein protein = new Protein("PTLFKNVSLYK", ""); var peptide = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).First(); List <int> modPos = GlycoSpectralMatch.GetPossibleModSites(peptide, new string[] { "S", "T" }); var peptideWithMod = GlycoPeptides.OGlyGetTheoreticalPeptide(modPos.ToArray(), peptide, glycanBox); Assert.That(peptideWithMod.FullSequence == "PT[O-Glycosylation:N1A1 on X]LFKNVS[O-Glycosylation:N1 on X]LYK"); //The following code prove that the default Fragment method doesn't work for O-glycopeptide due to neutral losses. var fragments_hcd = new List <Product>(); peptide.Fragment(DissociationType.HCD, FragmentationTerminus.Both, fragments_hcd); var fragmentsMod_hcd = new List <Product>(); peptideWithMod.Fragment(DissociationType.HCD, FragmentationTerminus.Both, fragmentsMod_hcd); Assert.That(fragments_hcd.Count() == 20); Assert.That(fragmentsMod_hcd.Count() == 61); //The Fragments also contain neutral loss ions. var frag_ments_etd = new List <Product>(); peptide.Fragment(DissociationType.ETD, FragmentationTerminus.Both, frag_ments_etd); var fragmentsMod_etd = new List <Product>(); peptideWithMod.Fragment(DissociationType.ETD, FragmentationTerminus.Both, fragmentsMod_etd); //Tuple<int, int[]> keyValuePair represents: <glycanBoxId, glycanModPositions> Tuple <int, int[]> keyValuePairs = new Tuple <int, int[]>(8, modPos.ToArray()); var fragments_etd_origin = GlycoPeptides.GetFragmentHash(frag_ments_etd, new Tuple <int, int[]>(0, null), OGlycanBoxes, 1000); var fragmentsHash_etd = GlycoPeptides.GetFragmentHash(frag_ments_etd, keyValuePairs, OGlycanBoxes, 1000); var fragmentsMod_etd_origin = GlycoPeptides.GetFragmentHash(fragmentsMod_etd, new Tuple <int, int[]>(0, null), OGlycanBoxes, 1000); var overlap = fragmentsHash_etd.Intersect(fragments_etd_origin).Count(); Assert.That(overlap == 14); var overlap2 = fragmentsHash_etd.Intersect(fragmentsMod_etd_origin).Count(); //ETD didn't change y ions. Assert.That(overlap2 == 23); }
public static void OGlycoTest_FragmentIons() { //This test is to test ETD on proline. As proline didn't have proline related product ions. //Get glycanBox var glycanBox = OGlycanBoxes[8]; Protein protein = new Protein("PTLFKNVSLYK", ""); var peptide = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).First(); List <int> modPos = GlycoSpectralMatch.GetPossibleModSites(peptide, new string[] { "S", "T" }); var peptideWithMod = GlycoPeptides.OGlyGetTheoreticalPeptide(modPos.ToArray(), peptide, OGlycanBoxes[8]); Assert.That(peptideWithMod.FullSequence == "PT[O-Glycosylation:N1A1 on X]LFKNVS[O-Glycosylation:N1 on X]LYK"); var fragments_hcd = GlycoPeptides.OGlyGetTheoreticalFragments(DissociationType.HCD, peptide, peptideWithMod); var fragments_ethcd = GlycoPeptides.OGlyGetTheoreticalFragments(DissociationType.EThcD, peptide, peptideWithMod); }
public static void OGlycoTest_Localization2() { //There may have a bug that MM cannot identify Peptide modified with (HexNAc), This is to test and find the bug. //Get glycanBox var glycanBox = OGlycanBoxes[0]; //Get unmodified peptide, products, allPossible modPos and all boxes. Protein protein = new Protein("AATVGSLAGQPLQER", "P16150"); var peptide = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).First(); List <Product> products = new List <Product>(); peptide.Fragment(DissociationType.ETD, FragmentationTerminus.Both, products); int[] modPos = GlycoSpectralMatch.GetPossibleModSites(peptide, new string[] { "S", "T" }).OrderBy(p => p).ToArray(); var boxes = GlycanBox.BuildChildOGlycanBoxes(glycanBox.NumberOfMods, glycanBox.ModIds).ToArray(); //Load scan. CommonParameters commonParameters = new CommonParameters(dissociationType: DissociationType.ETD, trimMsMsPeaks: false); string spectraFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"GlycoTestData\181217_Fusion_(LC2)_NewObj_Serum_deSA_Jacalin_HRM_4h_ETD_HCD_DDA_mz(400_1200)_21707.mgf"); var file = new MyFileManager(true).LoadFile(spectraFile, commonParameters); var scans = MetaMorpheusTask.GetMs2Scans(file, spectraFile, commonParameters).ToArray(); //Known peptideWithMod match. var peptideWithMod = GlycoPeptides.OGlyGetTheoreticalPeptide(new int[1] { 4 }, peptide, glycanBox); Assert.That(peptideWithMod.FullSequence == "AAT[O-Glycosylation:N1 on X]VGSLAGQPLQER"); //List<Product> knownProducts = peptideWithMod.Fragment(DissociationType.EThcD, FragmentationTerminus.Both).ToList(); List <Product> knownProducts = GlycoPeptides.OGlyGetTheoreticalFragments(DissociationType.ETD, peptide, peptideWithMod); var matchedKnownFragmentIons = MetaMorpheusEngine.MatchFragmentIons(scans.First(), knownProducts, commonParameters); //Get hashset int int obsPreviousFragmentCeilingMz = 0; List <int> binsToSearch = new List <int>(); foreach (var envelope in scans.First().ExperimentalFragments) { // assume charge state 1 to calculate mass tolerance double experimentalFragmentMass = envelope.MonoisotopicMass; // get theoretical fragment bins within mass tolerance int obsFragmentFloorMass = (int)Math.Floor((commonParameters.ProductMassTolerance.GetMinimumValue(experimentalFragmentMass)) * 1000); int obsFragmentCeilingMass = (int)Math.Ceiling((commonParameters.ProductMassTolerance.GetMaximumValue(experimentalFragmentMass)) * 1000); // prevents double-counting peaks close in m/z and lower-bound out of range exceptions if (obsFragmentFloorMass < obsPreviousFragmentCeilingMz) { obsFragmentFloorMass = obsPreviousFragmentCeilingMz; } obsPreviousFragmentCeilingMz = obsFragmentCeilingMass + 1; // search mass bins within a tolerance for (int fragmentBin = obsFragmentFloorMass; fragmentBin <= obsFragmentCeilingMass; fragmentBin++) { binsToSearch.Add(fragmentBin); } } HashSet <int> allPeaks = new HashSet <int>(binsToSearch); //Graph Localization LocalizationGraph localizationGraph = new LocalizationGraph(modPos, glycanBox, boxes, -1); LocalizationGraph.LocalizeOGlycan(localizationGraph, scans.First(), commonParameters.ProductMassTolerance, products); var allPaths = LocalizationGraph.GetAllHighestScorePaths(localizationGraph.array, localizationGraph.ChildModBoxes); var knowPath = new int[2] { 1, 1 }; Assert.That(Enumerable.SequenceEqual(knowPath, allPaths[0])); var local = LocalizationGraph.GetLocalizedPath(localizationGraph, allPaths.First()); Assert.That(Enumerable.SequenceEqual(local.Mods.Select(p => p.Item1), new List <int> { 4 })); Assert.That(Enumerable.SequenceEqual(local.Mods.Select(p => p.Item2), new List <int> { 0 })); }
public static void OGlycoTest_Localization() { //Get glycanBox var glycanBox = OGlycanBoxes[19]; //Get unmodified peptide, products, allPossible modPos and all boxes. Protein protein = new Protein("TTGSLEPSSGASGPQVSSVK", "P16150"); var peptide = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).First(); List <Product> products = new List <Product>(); peptide.Fragment(DissociationType.ETD, FragmentationTerminus.Both, products); int[] modPos = GlycoSpectralMatch.GetPossibleModSites(peptide, new string[] { "S", "T" }).OrderBy(v => v).ToArray(); var boxes = GlycanBox.BuildChildOGlycanBoxes(3, glycanBox.ModIds).ToArray(); Assert.That(boxes.Count() == 6); //Get Unlocal Fragment var unlocalCost = GlycoPeptides.GetUnlocalFragment(products, modPos, glycanBox); Assert.That(unlocalCost.Count == 4); //Basicly, the unlocal are c/z ions that don't localize glycosylation. //Get scan CommonParameters commonParameters = new CommonParameters(dissociationType: DissociationType.EThcD, trimMsMsPeaks: false); string spectraFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"GlycoTestData\2019_09_16_StcEmix_35trig_EThcD25_rep1_4565.mgf"); var file = new MyFileManager(true).LoadFile(spectraFile, commonParameters); var scans = MetaMorpheusTask.GetMs2Scans(file, spectraFile, commonParameters).ToArray(); //Known peptideWithMod match. var peptideWithMod = GlycoPeptides.OGlyGetTheoreticalPeptide(new int[3] { 10, 2, 3 }, peptide, glycanBox); Assert.That(peptideWithMod.FullSequence == "T[O-Glycosylation:H1N1 on X]T[O-Glycosylation:H1N1 on X]GSLEPSS[O-Glycosylation:N1 on X]GASGPQVSSVK"); List <Product> knownProducts = GlycoPeptides.OGlyGetTheoreticalFragments(DissociationType.EThcD, peptide, peptideWithMod); var matchedKnownFragmentIons = MetaMorpheusEngine.MatchFragmentIons(scans.First(), knownProducts, commonParameters); //Graph Localization LocalizationGraph localizationGraph = new LocalizationGraph(modPos, glycanBox, boxes, -1); LocalizationGraph.LocalizeOGlycan(localizationGraph, scans.First(), commonParameters.ProductMassTolerance, products); var allPaths = LocalizationGraph.GetAllHighestScorePaths(localizationGraph.array, localizationGraph.ChildModBoxes); var knowPath = new int[8] { 2, 4, 4, 4, 5, 5, 5, 5 }; Assert.That(Enumerable.SequenceEqual(knowPath, allPaths[0])); //Get localized Route var local = LocalizationGraph.GetLocalizedPath(localizationGraph, allPaths.First()); Assert.That(Enumerable.SequenceEqual(local.Mods.Select(v => v.Item1), new List <int> { 2, 3, 10 })); Assert.That(Enumerable.SequenceEqual(local.Mods.Select(v => v.Item2), new List <int> { 1, 1, 0 })); //Get all paths, calculate PScore and calculate position probability. var p = scans.First().TheScan.MassSpectrum.Size *commonParameters.ProductMassTolerance.GetRange(1000).Width / scans.First().TheScan.MassSpectrum.Range.Width; var n = knownProducts.Where(v => v.ProductType == ProductType.c || v.ProductType == ProductType.zDot).Count(); var allPathWithWeights = LocalizationGraph.GetAllPaths_CalP(localizationGraph, p, n); Assert.That(allPathWithWeights.Count == 168); //Calculate Site Specific Localization Probability var y = LocalizationGraph.CalSiteSpecificLocalizationProbability(allPathWithWeights, localizationGraph.ModPos); Assert.That(y.Count == 8); Assert.That(y.First().Value[1].Item2 > 0.99); }
protected override MyTaskResults RunSpecific(string OutputFolder, List <DbForTask> dbFilenameList, List <string> currentRawFileList, string taskId, FileSpecificParameters[] fileSettingsList) { MyTaskResults = new MyTaskResults(this); List <List <GlycoSpectralMatch> > ListOfGsmsPerMS2Scan = new List <List <GlycoSpectralMatch> >(); LoadModifications(taskId, out var variableModifications, out var fixedModifications, out var localizeableModificationTypes); // load proteins List <Protein> proteinList = LoadProteins(taskId, dbFilenameList, true, _glycoSearchParameters.DecoyType, localizeableModificationTypes, CommonParameters); MyFileManager myFileManager = new MyFileManager(true); int completedFiles = 0; Status("Searching files...", taskId); ProseCreatedWhileRunning.Append("\n"); ProseCreatedWhileRunning.Append("protease = " + CommonParameters.DigestionParams.Protease + "; \n"); ProseCreatedWhileRunning.Append("maximum missed cleavages = " + CommonParameters.DigestionParams.MaxMissedCleavages + "; \n"); ProseCreatedWhileRunning.Append("minimum peptide length = " + CommonParameters.DigestionParams.MinPeptideLength + "; \n"); ProseCreatedWhileRunning.Append(CommonParameters.DigestionParams.MaxPeptideLength == int.MaxValue ? "maximum peptide length = unspecified; " : "maximum peptide length = " + CommonParameters.DigestionParams.MaxPeptideLength + "; \n"); ProseCreatedWhileRunning.Append("initiator methionine behavior = " + CommonParameters.DigestionParams.InitiatorMethionineBehavior + "; \n"); ProseCreatedWhileRunning.Append("max modification isoforms = " + CommonParameters.DigestionParams.MaxModificationIsoforms + "; \n"); ProseCreatedWhileRunning.Append("fixed modifications = " + string.Join(", ", fixedModifications.Select(m => m.IdWithMotif)) + "; \n"); ProseCreatedWhileRunning.Append("variable modifications = " + string.Join(", ", variableModifications.Select(m => m.IdWithMotif)) + "; \n"); ProseCreatedWhileRunning.Append("parent mass tolerance(s) = " + CommonParameters.PrecursorMassTolerance + "; \n"); ProseCreatedWhileRunning.Append("product mass tolerance = " + CommonParameters.ProductMassTolerance + "; \n"); ProseCreatedWhileRunning.Append("The combined search database contained " + proteinList.Count + " total entries including " + proteinList.Where(p => p.IsContaminant).Count() + " contaminant sequences. \n"); if (_glycoSearchParameters.GlycoSearchType == GlycoSearchType.OGlycanSearch) { ProseCreatedWhileRunning.Append("The O-glycan database: " + _glycoSearchParameters.OGlycanDatabasefile + "\n"); } else if (_glycoSearchParameters.GlycoSearchType == GlycoSearchType.NGlycanSearch) { ProseCreatedWhileRunning.Append("The N-glycan database: " + _glycoSearchParameters.OGlycanDatabasefile + "\n"); } else { ProseCreatedWhileRunning.Append("The O-glycan database: " + _glycoSearchParameters.OGlycanDatabasefile + "\n"); ProseCreatedWhileRunning.Append("The N-glycan database: " + _glycoSearchParameters.NGlycanDatabasefile + "\n"); } ProseCreatedWhileRunning.Append("\n"); for (int spectraFileIndex = 0; spectraFileIndex < currentRawFileList.Count; spectraFileIndex++) { var origDataFile = currentRawFileList[spectraFileIndex]; CommonParameters combinedParams = SetAllFileSpecificCommonParams(CommonParameters, fileSettingsList[spectraFileIndex]); var thisId = new List <string> { taskId, "Individual Spectra Files", origDataFile }; NewCollection(Path.GetFileName(origDataFile), thisId); Status("Loading spectra file...", thisId); MsDataFile myMsDataFile = myFileManager.LoadFile(origDataFile, combinedParams); Status("Getting ms2 scans...", thisId); Ms2ScanWithSpecificMass[] arrayOfMs2ScansSortedByMass = GetMs2Scans(myMsDataFile, origDataFile, combinedParams).OrderBy(b => b.PrecursorMass).ToArray(); List <GlycoSpectralMatch>[] newCsmsPerMS2ScanPerFile = new List <GlycoSpectralMatch> [arrayOfMs2ScansSortedByMass.Length]; myFileManager.DoneWithFile(origDataFile); for (int currentPartition = 0; currentPartition < CommonParameters.TotalPartitions; currentPartition++) { List <PeptideWithSetModifications> peptideIndex = null; //When partition, the proteinList will be split for each Thread. List <Protein> proteinListSubset = proteinList.GetRange(currentPartition * proteinList.Count() / combinedParams.TotalPartitions, ((currentPartition + 1) * proteinList.Count() / combinedParams.TotalPartitions) - (currentPartition * proteinList.Count() / combinedParams.TotalPartitions)); Status("Getting fragment dictionary...", new List <string> { taskId }); //Only reverse Decoy for glyco search has been tested and are set as fixed parameter. var indexEngine = new IndexingEngine(proteinListSubset, variableModifications, fixedModifications, null, null, null, currentPartition, _glycoSearchParameters.DecoyType, combinedParams, this.FileSpecificParameters, 30000.0, false, dbFilenameList.Select(p => new FileInfo(p.FilePath)).ToList(), TargetContaminantAmbiguity.RemoveContaminant, new List <string> { taskId }); List <int>[] fragmentIndex = null; List <int>[] precursorIndex = null; GenerateIndexes(indexEngine, dbFilenameList, ref peptideIndex, ref fragmentIndex, ref precursorIndex, proteinList, taskId); //The second Fragment index is for 'MS1-HCD_MS1-ETD_MS2s' type of data. If LowCID is used for MS1, ion-index is not allowed to use. List <int>[] secondFragmentIndex = null; //if (combinedParams.MS2ChildScanDissociationType != DissociationType.LowCID //&& !CrosslinkSearchEngine.DissociationTypeGenerateSameTypeOfIons(combinedParams.DissociationType, combinedParams.MS2ChildScanDissociationType)) //{ // //Becuase two different type of dissociation methods are used, the parameters are changed with different dissociation type. // var secondCombinedParams = CommonParameters.CloneWithNewDissociationType(combinedParams.MS2ChildScanDissociationType); // var secondIndexEngine = new IndexingEngine(proteinListSubset, variableModifications, fixedModifications, null, null, null, currentPartition, _glycoSearchParameters.DecoyType, secondCombinedParams, this.FileSpecificParameters, 30000.0, false, dbFilenameList.Select(p => new FileInfo(p.FilePath)).ToList(), new List<string> { taskId }); // GenerateSecondIndexes(indexEngine, secondIndexEngine, dbFilenameList, ref secondFragmentIndex, proteinList, taskId); //} Status("Searching files...", taskId); new GlycoSearchEngine(newCsmsPerMS2ScanPerFile, arrayOfMs2ScansSortedByMass, peptideIndex, fragmentIndex, secondFragmentIndex, currentPartition, combinedParams, this.FileSpecificParameters, _glycoSearchParameters.OGlycanDatabasefile, _glycoSearchParameters.NGlycanDatabasefile, _glycoSearchParameters.GlycoSearchType, _glycoSearchParameters.GlycoSearchTopNum, _glycoSearchParameters.MaximumOGlycanAllowed, _glycoSearchParameters.OxoniumIonFilt, thisId).Run(); ReportProgress(new ProgressEventArgs(100, "Done with search " + (currentPartition + 1) + "/" + CommonParameters.TotalPartitions + "!", thisId)); if (GlobalVariables.StopLoops) { break; } } ListOfGsmsPerMS2Scan.AddRange(newCsmsPerMS2ScanPerFile.Where(p => p != null).ToList()); completedFiles++; ReportProgress(new ProgressEventArgs(completedFiles / currentRawFileList.Count, "Searching...", new List <string> { taskId, "Individual Spectra Files" })); } ReportProgress(new ProgressEventArgs(100, "Done with all searches!", new List <string> { taskId, "Individual Spectra Files" })); //For every Ms2Scans, each have a list of candidates psms. The allPsms from GlycoSearchEngine is the list (all ms2scans) of list (each ms2scan) of psm (all candidate psm). //Currently, only keep the first scan for consideration. List <GlycoSpectralMatch> GsmPerScans = ListOfGsmsPerMS2Scan.Select(p => p.First()).ToList(); var filteredAllPsms = new List <GlycoSpectralMatch>(); //For each ms2scan, try to find the best candidate psm from the psms list. Do the localizaiton analysis. Add it into filteredAllPsms. foreach (var gsmsPerScan in GsmPerScans.GroupBy(p => p.ScanNumber)) { var glycos = RemoveSimilarSequenceDuplicates(gsmsPerScan.OrderByDescending(p => p.Score).ToList()); foreach (var glycoSpectralMatch in glycos) { if (glycoSpectralMatch.LocalizationGraphs != null) { List <Route> localizationCandidates = new List <Route>(); for (int i = 0; i < glycoSpectralMatch.LocalizationGraphs.Count; i++) { var allPathWithMaxScore = LocalizationGraph.GetAllHighestScorePaths(glycoSpectralMatch.LocalizationGraphs[i].array, glycoSpectralMatch.LocalizationGraphs[i].ChildModBoxes); foreach (var path in allPathWithMaxScore) { var local = LocalizationGraph.GetLocalizedPath(glycoSpectralMatch.LocalizationGraphs[i], path); local.ModBoxId = glycoSpectralMatch.LocalizationGraphs[i].ModBoxId; localizationCandidates.Add(local); } } glycoSpectralMatch.Routes = localizationCandidates; } if (glycoSpectralMatch.Routes != null) { LocalizationLevel localLevel; glycoSpectralMatch.LocalizedGlycan = GlycoSpectralMatch.GetLocalizedGlycan(glycoSpectralMatch.Routes, out localLevel); glycoSpectralMatch.LocalizationLevel = localLevel; //Localization PValue. if (localLevel == LocalizationLevel.Level1 || localLevel == LocalizationLevel.Level2) { List <Route> allRoutes = new List <Route>(); foreach (var graph in glycoSpectralMatch.LocalizationGraphs) { allRoutes.AddRange(LocalizationGraph.GetAllPaths_CalP(graph, glycoSpectralMatch.ScanInfo_p, glycoSpectralMatch.Thero_n)); } glycoSpectralMatch.SiteSpeciLocalProb = LocalizationGraph.CalSiteSpecificLocalizationProbability(allRoutes, glycoSpectralMatch.LocalizationGraphs.First().ModPos); } } filteredAllPsms.Add(glycoSpectralMatch); } } PostGlycoSearchAnalysisTask postGlycoSearchAnalysisTask = new PostGlycoSearchAnalysisTask(); postGlycoSearchAnalysisTask.FileSpecificParameters = this.FileSpecificParameters; return(postGlycoSearchAnalysisTask.Run(OutputFolder, dbFilenameList, currentRawFileList, taskId, fileSettingsList, filteredAllPsms.OrderByDescending(p => p.Score).ToList(), CommonParameters, _glycoSearchParameters, proteinList, variableModifications, fixedModifications, localizeableModificationTypes, MyTaskResults)); }