public void Process() { myQuantPkgs = new List <QuantPackage2>(); SignalGenerator isotopicSignal = new SignalGenerator(); foreach (SEProFileInfo sfi in SEProFiles) { foreach (string file in sfi.MyFilesFullPath) { Console.WriteLine("Processing for " + file); ResultPackage rp = ResultPackage.Load(file); List <string> filesInSEPro = (from sqt in rp.MyProteins.AllSQTScans select sqt.FileName).Distinct().ToList(); FileInfo fi = new FileInfo(file); foreach (string msFile in filesInSEPro) { QuantPackage2 qp = new QuantPackage2(msFile, fi.Directory.FullName, sfi.ClassLabel); Console.WriteLine("\t" + msFile); List <string> ms1OrRawOrmzMLFiles = fi.Directory.GetFiles("*.ms1").ToList().Concat(fi.Directory.GetFiles("*.RAW")).Concat(fi.Directory.GetFiles("*.mzML")).ToList().Select(a => a.Name).ToList(); int fileToRead = ms1OrRawOrmzMLFiles.FindIndex(a => RemoveExtension(a).Equals(RemoveExtension(msFile))); XICGet5 xic = new XICGet5(fi.DirectoryName + "/" + ms1OrRawOrmzMLFiles[fileToRead]); List <SQTScan> scansTMP = rp.MyProteins.AllSQTScans.FindAll(a => a.FileName.Equals(msFile)); if (MyClusterParams.OnlyUniquePeptides) { int removedForNotUnique = scansTMP.RemoveAll(a => a.IsUnique); Console.WriteLine("Scans removed for not dealing with unique peptides: " + removedForNotUnique); } List <SQTLight> scans = scansTMP.Select(a => new SQTLight(a)).ToList(); int counter = 0; for (int i = 0; i < scans.Count; i++) { Dictionary <string, List <Quant> > theseQuants = Core35.Quant(xic, scans[i], scans[i].TheoreticalMH, isotopicSignal, scans[i].ScanNumber, MyClusterParams); foreach (var kvp in theseQuants) { kvp.Value.RemoveAll(a => a.MyIons.GetLength(1) < MyClusterParams.MinMS1Counts); if (kvp.Value.Count > 0) { if (qp.MyQuants.ContainsKey(kvp.Key)) { qp.MyQuants[kvp.Key].AddRange(kvp.Value); } else { qp.MyQuants.Add(kvp.Key, kvp.Value); } } } counter++; Console.Write("\rScans Processed: " + counter + "/" + scans.Count); } //Store them myQuantPkgs.Add(qp); Console.WriteLine("\nTotal quants stored so far = " + myQuantPkgs.Sum(a => a.MyQuants.Count)); Console.WriteLine("Total files analyzed so far = " + myQuantPkgs.Count); Console.WriteLine("Done procesing :" + msFile); System.GC.Collect(); System.GC.WaitForPendingFinalizers(); System.GC.Collect(); } } } GenerateAssociationItems(); }
/// <summary> /// We recomend runing this after retaining optimal signal. This will revisit other MS1s to try and find a XIC to reuce the undersampling problem /// </summary> public void FillInTheGaps(List <string> peptideWithCharges) { //We need to know the acceptable comaprisons. List <int> groups = MyAssociationItems.Select(a => a.Assosication).Distinct().ToList(); foreach (int group in groups) { //Get the stuff from this group List <AssociationItem> items = MyAssociationItems.FindAll(a => a.Assosication == group); List <string> seproFiles = items.Select(a => a.Directory + "\\" + a.Directory + ".sepr").ToList(); //Now get all peptides from the group List <QuantPackage2> relevantQuantPackages = (from qpackg in myQuantPkgs where items.Exists(a => qpackg.FullDirPath.Contains(a.Directory) && a.FileName.Equals(qpackg.FileName)) select qpackg).ToList(); //Load all MS1s to RAM List <XICGet5> myGetters = new List <XICGet5>(items.Count); foreach (AssociationItem ai in items) { //Find out the full directory string dtmp = @"\" + ai.Directory; List <string> seprof = (from s in SEProFiles from d in s.MyFilesFullPath where d.Contains(dtmp + "\\") select d).ToList(); foreach (string s in seprof) { FileInfo f = new FileInfo(s); //We need to find out if we are dealing with .ms2, .RAW or .mzML string theExtension = GetExtension(f); string fileName = f.Directory.FullName + @"\" + Regex.Replace(ai.FileName, ".sqt", theExtension); myGetters.Add(new XICGet5(fileName)); } } peptideWithCharges.Sort(); foreach (string peptideWithZ in peptideWithCharges) { string[] cols = Regex.Split(peptideWithZ, "::"); string peptide = cols[0]; int z = int.Parse(cols[1]); //Find out which one has the greatest XIC List <QuantPackage2> qpSearch = relevantQuantPackages.FindAll(a => a.MyQuants.ContainsKey(peptide)); List <Quant> refQuants = (from qpckg in qpSearch from quant in qpckg.MyQuants[peptide] where quant.Z == z && quant.QuantArea > 0 select quant).OrderByDescending(a => a.QuantArea).ToList(); if (refQuants.Count == 0) { continue; } List <IonLight> MyIonsLight = refQuants[0].GetIonsLight(); List <string> fileNames = (from qpckg in qpSearch from quant in qpckg.MyQuants[peptide] where quant.Z == z && quant.QuantArea > 0 select qpckg.FullDirPath + @"\" + qpckg.FileName).Distinct().ToList(); //Find out the tolerance i.e., the XIC above +- the tolerance double lowerBound = MyIonsLight.Min(a => a.RetentionTime) - (double)ChromeAssociationTolerance; double upperBound = MyIonsLight.Max(a => a.RetentionTime) + (double)ChromeAssociationTolerance; //Extract the XICs of this peptide in the not found ones and add them //Find the missing getters List <string> fileGetters = myGetters.Select(a => a.MyFile.FullName).ToList(); List <string> fileQuants = new List <string>(); string theExtension = null; foreach (string fName in fileNames) { theExtension = GetExtension(new FileInfo(fName)); fileQuants.Add(Regex.Replace(fName, ".sqt", theExtension)); } List <string> missing = fileGetters.FindAll(a => !fileQuants.Contains(a)).ToList(); List <XICGet5> gettersToUse = myGetters.FindAll(a => missing.Contains(a.MyFile.FullName)); foreach (XICGet5 xg in gettersToUse) { //The problem is it is getting the reference mass of onw charge when it is supposed to be the other double mz = refQuants[0].PrecursorMZ; double ppmTol = MyClusterParams.ClusteringPPM; double minCurrent = MyClusterParams.MinMaxSignal; double minGapForItemsInCluster = MyClusterParams.MinTimeGapFromItemsInCluster; //Find out a good scan number double maxInt = MyIonsLight.Max(a => a.Intensity); IonLight maxIntIon = MyIonsLight.Find(a => a.Intensity == maxInt); double Ctolerance = (double)ChromeAssociationTolerance; double[,] cluster = xg.GetXIC3(mz, ppmTol, maxIntIon.RetentionTime); if (cluster != null) { string tmpf = xg.MyFile.Name; tmpf = Regex.Replace(tmpf, theExtension, ".sqt"); tmpf = Regex.Replace(tmpf, theExtension, ".sqt"); QuantPackage2 qp = myQuantPkgs.Find(a => a.FullDirPath.Equals(xg.MyFile.Directory.FullName) && a.FileName.Equals(tmpf)); Quant q = new Quants.Quant(cluster, -1, z, mz); if (qp.MyQuants.ContainsKey(peptide)) { qp.MyQuants[peptide].Add(q); } else { qp.MyQuants.Add(peptide, new List <Quant>() { q }); } } } Console.WriteLine(peptide); } } }