internal void IncrementalBatchSearch(MSParser.MSFull ms, List <PathCandidate> pathCandidates, RegexGeneration.RegexGenerationParams regexParams) { //Handle the precursor stuff double precursor = -1; double precursorCharge = -1; double lowerSearchBound = -1; double upperSearchBound = -1; if (ms.ZLines.Count > 0 && regexParams.UsePrecursorInformation) { string[] zLine = tabSplitterRegex.Split(ms.ZLines[0]); precursorCharge = double.Parse(zLine[1]); precursor = PatternTools.pTools.DechargeMSPeakToPlus1(ms.ChargedPrecursor, precursorCharge); if (precursorCharge <= regexParams.MinTrustedCharge) { lowerSearchBound = precursor - regexParams.PrecursorLowerBound; upperSearchBound = precursor + regexParams.PrecursorUpperBound; } else { lowerSearchBound = PatternTools.pTools.DechargeMSPeakToPlus1(ms.ChargedPrecursor, regexParams.MinTrustedCharge); upperSearchBound = -1; } } else if (regexParams.UsePrecursorInformation && ms.ZLines.Count == 0) { lowerSearchBound = (regexParams.MinTrustedCharge * ms.ChargedPrecursor) - 500; upperSearchBound = -1; } else if (!regexParams.UsePrecursorInformation) { lowerSearchBound = ms.MSData[(int)(ms.MSData.Count * 0.8)].MZ; upperSearchBound = -1; } SearchResult sr = Search(lowerSearchBound, upperSearchBound, pathCandidates, regexParams.MaxRegexes, ms.ScanNumber, ms.ChargedPrecursor, precursorCharge); sr.TheResults.Sort((a, b) => b.Score.CompareTo(a.Score)); if (sr.TheResults.Count > 0) { if (sr.DeltaCN > 0) { mySearchResults.Add(sr); } } }
public List <MSFull> GetNext(int noSpectra) { List <MSFull> myScans = new List <MSFull>(noSpectra); string thisLine = ""; MSFull thisScan; if (cycleCounter == 0) { thisScan = new MSParser.MSFull(); } else { thisScan = bufferScan; } while (true) { thisLine = sr.ReadLine(); if (thisLine == null) { break; } if (thisLine.Length == 0) { continue; } if (isNumber.Match(thisLine, 0, 1).Success) { //We are dealing with MS ion data string[] ionData = mzSeparator.Split(thisLine); Ion ion = new Ion(double.Parse(ionData[0]), double.Parse(ionData[1]), thisScan.CromatographyRetentionTime, thisScan.ScanNumber); //Save our data thisScan.MSData.Add(ion); } else if (thisLine.StartsWith("Z")) { string[] theStrings3 = tabSeparator.Split(thisLine); if (thisScan.Charges == null) { thisScan.Charges = new List <int> { int.Parse(theStrings3[1]) }; thisScan.Precursors = new List <double> { double.Parse(theStrings3[2]) }; } else { thisScan.Charges.Add(int.Parse(theStrings3[1])); if (thisScan.Precursors == null) { thisScan.Precursors = new List <double>(); } thisScan.Precursors.Add(double.Parse(theStrings3[2])); } } else if (thisLine.Contains("ActivationType")) { string[] theStrings2 = tabSeparator.Split(thisLine); thisScan.ActivationType = theStrings2[2]; } else if (thisLine.Contains("InstrumentType")) { string[] theStrings2 = tabSeparator.Split(thisLine); thisScan.InstrumentType = theStrings2[2]; } else if (thisLine.Contains("RetTime")) { string[] theStrings2 = tabSeparator.Split(thisLine); if (theStrings2.Length == 2) { //The retention time is separated with a space so we need to further break it up string[] s = Regex.Split(theStrings2[1], @" "); thisScan.CromatographyRetentionTime = double.Parse(s[1]); } else if (theStrings2.Length == 3) { thisScan.CromatographyRetentionTime = double.Parse(theStrings2[2]); } else { throw new Exception("Problems parsing Retention time Line.\n" + thisLine); } } else if (thisLine.StartsWith("S")) { //Step 1:Save the Old One if (thisScan.MSData.Count > 0) //Make sure we dont have an empty scan! { myScans.Add(thisScan); } //Step 2:Get the new one ready thisScan = new MSParser.MSFull(); string[] theStrings = tabSeparator.Split(thisLine); thisScan.ScanNumber = int.Parse(theStrings[1]); thisScan.MSData = new List <Ion>(); if (theStrings.Length != 3) { //we are dealing with MS1 - the precursor shall be 0 //We are dealing with MS and should save precursor information thisScan.ChargedPrecursor = double.Parse(theStrings[3]); } if (myScans.Count == noSpectra) { bufferScan = thisScan; break; } } } if (thisLine == null) { sr.Close(); } cycleCounter++; return(myScans); }
public void ParseFile(FileInfo file, double minimumIonIntensity) { //Get the file to RAM myScans.Clear(); headerLines.Clear(); ParsedFileInfo = file; StreamReader sr = new StreamReader(file.OpenRead()); string thisLine; MSFile thisFile = new MSFile(); thisFile.FileName = file.Name; int lineCounter = 0; //Helps to debug. MSParser.MSFull thisScan = new MSParser.MSFull(); while ((thisLine = sr.ReadLine()) != null) { lineCounter++; if (thisLine.Length == 0) { continue; } if (isNumber.Match(thisLine, 0, 1).Success) { //We are dealing with MS ion data string[] ionData = mzSeparator.Split(thisLine); Ion ion = new Ion(double.Parse(ionData[0]), double.Parse(ionData[1]), thisScan.CromatographyRetentionTime, thisScan.ScanNumber); //Save our data thisScan.MSData.Add(ion); } else if (thisLine.StartsWith("H")) { headerLines.Add(thisLine); } else if (thisLine.StartsWith("Z")) { string[] theStrings3 = tabSeparator.Split(thisLine); if (thisScan.Charges == null) { thisScan.Charges = new List<int> { int.Parse(theStrings3[1]) }; thisScan.Precursors = new List<double> { double.Parse(theStrings3[2]) }; } else { thisScan.Charges.Add(int.Parse(theStrings3[1])); if (thisScan.Precursors == null) { thisScan.Precursors = new List<double>(); } thisScan.Precursors.Add(double.Parse(theStrings3[2])); } } else if (thisLine.Contains("ActivationType")) { string[] theStrings2 = tabSeparator.Split(thisLine); thisScan.ActivationType = theStrings2[2]; } else if (thisLine.Contains("InstrumentType")) { string[] theStrings2 = tabSeparator.Split(thisLine); thisScan.InstrumentType = theStrings2[2]; } else if (thisLine.Contains("RetTime")) { string[] theStrings2 = tabSeparator.Split(thisLine); if (theStrings2.Length == 2) { //The retention time is separated with a space so we need to further break it up string[] s = Regex.Split(theStrings2[1], @" "); thisScan.CromatographyRetentionTime = double.Parse(s[1]); } else if (theStrings2.Length == 3) { thisScan.CromatographyRetentionTime = double.Parse(theStrings2[2]); } else { throw new Exception("Problems parsing Retention time Line.\n" + thisLine); } } else if (thisLine.StartsWith("S")) { //We have a new spectra // scan //Denoise our scan thisScan.MSData.RemoveAll(p => p.Intensity < minimumIonIntensity); //Compute the ion intensity foreach (var scan in thisScan.MSData) { thisScan.TotalIonIntensity += scan.Intensity; } //Step 1:Save the Old One if (thisScan.MSData.Count > 0) //Make sure we dont have an empty scan! { myScans.Add(thisScan); } //Step 2:Get the new one ready thisScan = new MSParser.MSFull(); thisScan.TotalIonIntensity = 0; string[] theStrings = tabSeparator.Split(thisLine); thisScan.ScanNumber = int.Parse(theStrings[1]); thisScan.MSData = new List<Ion>(); if (theStrings.Length != 3) { //we are dealing with MS1 - the precursor shall be 0 //We are dealing with MS and should save precursor information thisScan.ChargedPrecursor = double.Parse(theStrings[3]); } } } //Save our last scan myScans.Add(thisScan); sr.Close(); }