private Ion GetPrecursor(string filter, MSLight lastMS1) { Match precursorM = capturePrecursor.Match(filter); double chargedPrecursor = double.Parse(precursorM.Groups[1].ToString()); double intensity = -1; double mz = -1; //now we need to get the closest peak to the MS1 peaks for (int i = 0; i < lastMS1.MZ.Count; i++) { if (Math.Abs(PatternTools.pTools.PPM(lastMS1.MZ[i], chargedPrecursor)) <= MyParams.PPMToleranceForInferingPrecursorMZ) { if (lastMS1.Intensity[i] > intensity) { intensity = lastMS1.Intensity[i]; mz = lastMS1.MZ[i]; } } } if (mz == -1) { mz = chargedPrecursor; intensity = 0; } return(new Ion(mz, intensity, lastMS1.CromatographyRetentionTime, lastMS1.ScanNumber)); }
private void ButtonLoadExample_Click(object sender, RoutedEventArgs e) { string peptide = TextBoxPeptide.Text; //Get the experimental string[] lines = Regex.Split(SpectrumViewer2.Properties.Resources.ExampleSpectrum, "\n"); MSLight msExperimental = new MSLight(); List <double> mz = new List <double>(); List <double> intensities = new List <double>(); foreach (string l in lines) { string[] mzI = Regex.Split(l, "\t"); mz.Add(double.Parse(mzI[0])); intensities.Add(double.Parse(mzI[1])); } msExperimental.MZ = mz; msExperimental.Intensity = intensities; MainViewer1.PlotAnotatedSpectrum(msExperimental, 500, peptide); }
public MultiNotchMS3Item(MSLight scn) { string precursorScan = scn.ILines.Find(a => a.Contains("PrecursorScan")); string[] cols = Regex.Split(precursorScan, "\t"); MyIons = scn.Ions; MS2PrecursorScan = int.Parse(cols[2]); }
public static string PrintSpectrumMS2(MSLight ms) { StringBuilder sw = new StringBuilder(); bool isFullScan = false; if (ms.ActivationType.Equals("")) { isFullScan = true; } sw.Append("S\t" + ms.ScanNumber.ToString("000000") + "\t" + ms.ScanNumber.ToString("000000")); if (isFullScan) { sw.Append("\n"); } else { sw.Append("\t" + ms.ChargedPrecursor + "\n"); } sw.Append("I\tRetTime\t" + ms.CromatographyRetentionTime + "\n"); sw.Append("I\tIonInjectionTime\t" + ms.IonInjectionTime + "\n"); if (!isFullScan) { sw.Append("I\tActivationType\t" + ms.ActivationType + "\n"); } sw.Append("I\tInstrumentType\t" + ms.InstrumentType + "\n"); if (!isFullScan) { foreach (string s in ms.ILines) { sw.Append(s + "\n"); } foreach (string zLine in ms.ZLines) { //Write the Z Lines sw.Append(zLine + "\n"); } } List <Ion> myIons = ms.Ions; myIons.Sort((a, b) => a.MZ.CompareTo(b.MZ)); for (int i = 0; i < myIons.Count; i++) { sw.Append(myIons[i].MZ + " " + myIons[i].Intensity + "\n"); } return(sw.ToString()); }
private List <Ion> GetIonsFromSpectrum(MSLight ms) { List <Ion> theIons = new List <Ion>(ms.MZ.Count); for (int i = 0; i < ms.MZ.Count; i++) { theIons.Add(new Ion(ms.MZ[i], ms.Intensity[i], 0, 0)); } return(theIons); }
public void PlotAnotatedSpectrum(MSLight msExperimental, double ppm, string peptide) { //Predict the spectrum //Find PTMs List <ModificationItem> mods = SpectraPredictor.GetVMods(peptide); SpectralPredictionParameters spp = new SpectralPredictionParameters(false, true, false, false, true, false, true, true, 2, true, mods); SpectraPredictor sp = new SpectraPredictor(spp); List <PredictedIon> theoreticalSpectrum = sp.PredictPeaks(peptide, 2, 1950, msExperimental, 500); DataGridResultTable.ItemsSource = theoreticalSpectrum; SpectrumEye1.Plot(msExperimental.Ions, msExperimental.Ions[0].MZ, msExperimental.Ions.Last().MZ, ppm, theoreticalSpectrum); }
/// <summary> /// /// </summary> /// <param name="rawFile">The Thermo RAW File</param> /// <param name="scanNumbers">If no scan numbers are in the array the filter will search for all scan numbers</param> /// <returns></returns> public List <MSLight> GetSpectra(string rawFile, List <int> scanNumbers, bool onlyMS1) { Console.WriteLine("Parsing " + rawFile); MSFileReaderLib.MSFileReader_XRawfile m2 = new MSFileReaderLib.MSFileReader_XRawfile(); m2.Open(rawFile); m2.SetCurrentController(0, 1); //string filter2 = ""; //m2.GetFilterForScanNum(50, ref filter2); int noSpectra = 0; m2.GetNumSpectra(ref noSpectra); MSLight lastMS1 = new MSLight(); List <MSLight> mySpectra = new List <MSLight>(noSpectra); for (int i = 1; i <= noSpectra; i++) { string filter = null; if (scanNumbers.Count == 0 || scanNumbers.Contains(i)) { m2.GetFilterForScanNum(i, ref filter); MSLight thisMS = new MSLight(); Ion precursor = new Ion(-1, -1, -1, -1); if (isMS1.IsMatch(filter)) { lastMS1 = thisMS; } else { if (onlyMS1) { continue; } if (!MyParams.UseThermoMonoIsotopicPrediction) { precursor = GetPrecursor(filter, lastMS1); } } //------------- double retentionTime = 0; m2.RTFromScanNum(i, ref retentionTime); string thisFilter = null; m2.GetFilterForScanNum(i, ref thisFilter); string flags = null; m2.GetFlags(ref flags); //------------ double scanCentroidPeakWidth = 0.005; int arraySize = maxNoPeaks; object massList = null; object peakFlags = null; m2.GetMassListFromScanNum( ref i, filter, scanIntensityCutoffType, scanIntensityCutoffValue, maxNoPeaks, scanCentroidResult, ref scanCentroidPeakWidth, ref massList, ref peakFlags, ref arraySize); thisMS.ScanNumber = i; object trailerLabels = null; object trailerValues = null; int cc = 0; m2.GetTrailerExtraForScanNum(i, ref trailerLabels, ref trailerValues, ref cc); object chargeStateObject = null; m2.GetTrailerExtraValueForScanNum(i, "Charge State:", ref chargeStateObject); double chargeState = double.Parse(chargeStateObject.ToString()); string[] theStringValues = (string[])trailerValues; if (theStringValues[1].Contains("=")) { string [] split = Regex.Split(theStringValues[1], "="); string [] correction = Regex.Split(split[1], ";"); thisMS.IonInjectionTime = double.Parse(correction[0]); } else { thisMS.IonInjectionTime = double.Parse(theStringValues[2]); } Match instrument = captureInstrumentType.Match(filter); thisMS.InstrumentType = instrument.Groups[1].ToString(); thisMS.ILines.Add("I\tFilter\t" + filter); Match activationType = captureActivationType.Match(filter); thisMS.ActivationType = activationType.Groups[1].ToString().ToUpper(); if (!thisMS.ActivationType.Equals("")) { if (MyParams.UseThermoMonoIsotopicPrediction) { object monoisotopicObject = null; m2.GetTrailerExtraValueForScanNum(i, "Monoisotopic M/Z:", ref monoisotopicObject); double objectValue = Math.Round(double.Parse(monoisotopicObject.ToString()), 4); if (objectValue == 0) { //Thermo was unable to determine precursor so we will try to get it. precursor = GetPrecursor(filter, lastMS1); thisMS.ChargedPrecursor = precursor.MZ; } else { precursor = new Ion(objectValue, 1, 1, i); //Console.WriteLine("Monoisotopic Thermo: " + precursor.MZ); thisMS.ChargedPrecursor = precursor.MZ; } } else { thisMS.ChargedPrecursor = precursor.MZ; } if (chargeState == 0) { thisMS.ZLines.Add("Z\t2\t" + Math.Round(PatternTools.pTools.DechargeMSPeakToPlus1(precursor.MZ, 2), 4)); thisMS.ZLines.Add("Z\t3\t" + Math.Round(PatternTools.pTools.DechargeMSPeakToPlus1(precursor.MZ, 3), 4)); } else { thisMS.ZLines.Add("Z\t" + int.Parse(chargeState.ToString()).ToString() + "\t" + Math.Round(PatternTools.pTools.DechargeMSPeakToPlus1(precursor.MZ, chargeState), 4)); } thisMS.ILines.Add("I\tPrecursorScan\t" + lastMS1.ScanNumber); thisMS.ILines.Add("I\tPrecursorInt\t" + precursor.Intensity); } double[,] thisMassList = (double[, ])massList; int l = thisMassList.GetLength(1); double[] mz = new double[thisMassList.GetLength(1)]; double[] intensity = new double[thisMassList.GetLength(1)]; for (int counter = 0; counter < thisMassList.GetLength(1); counter++) { if (thisMassList[1, counter] > 0.5) //check if we have a minimum intensity { mz[counter] = Math.Round(thisMassList[0, counter], 5); intensity[counter] = Math.Round(thisMassList[1, counter], 1); //thisMS.MZ.Add(Math.Round(thisMassList[0, counter], 5)); //thisMS.Intensity.Add(Math.Round(thisMassList[1, counter], 1)); } } if (mz.Length == 0) //There is no use in saving an empty MS { continue; } thisMS.MZ = mz.ToList(); thisMS.Intensity = intensity.ToList(); thisMS.CromatographyRetentionTime = Math.Round(retentionTime, 3); //---------------------------- mySpectra.Add(thisMS); } } Console.WriteLine("."); m2.Close(); //Some final cleanup mySpectra.RemoveAll(a => a.MZ.Count < 5); if (MyParams.ActivateSpectraCleaner) { CleanSpectra(mySpectra); } return(mySpectra); }
public List <PredictedIon> PredictPeaks(string iPeptide, double precursorCharge, double theoreticalMassMH, MSLight ms, double ppm) { List <PredictedIon> result = PredictPeaks(iPeptide, precursorCharge, theoreticalMassMH); foreach (PredictedIon pi in result) { if (ms.MZ.Exists(a => Math.Abs(PatternTools.pTools.PPM(a, pi.MZ)) <= ppm)) { pi.Matched = true; } } return(result); }
public void PlotSpectrum(MSLight msExperimental) { SpectrumEye1.Plot(msExperimental.Ions, msExperimental.Ions[0].MZ, msExperimental.Ions.Last().MZ, 0); }
static void Main(string[] args) { // Generate DTA string dtaDir = @"C:\Users\pcarvalho\Desktop\Juli_fosfo\DTA\out"; string inputSQT = @"C:\Users\pcarvalho\Desktop\Colaborations\Juli_fosfo\DTA\20140410_JF_HAP50mmmS2.sqt"; string inputMS2 = @"C:\Users\pcarvalho\Desktop\Colaborations\Juli_fosfo\DTA\20140410_jf_hap50mmms2.ms2"; if (true) //Remove MSMS from a file { int targetNoSpectra = 9917; List <MSLight> theMS = PatternTools.MSParserLight.ParserLight.ParseLightMS2(inputMS2); string outputMS2 = @"C:\Users\pcarvalho\Desktop\Colaborations\Juli_fosfo\DTA\Removed3_20140410_jf_hap50mmms2.ms2"; while (theMS.Count > targetNoSpectra) { int scnRemove = PatternTools.pTools.getRandomNumber(theMS.Count - 1); theMS.RemoveAt(scnRemove); } PatternTools.MSParser.MSPrinter.PrintMSListToFile(theMS, outputMS2, "", MSFileFormat.ms2); Console.WriteLine("Done!"); } //Generate a side by side table of XDScores and AScores if (false) //Generate a side by side table of XDScores and AScores { XDScore.XDScore xdScore = new XDScore.XDScore(new List <string>() { inputSQT }, true); SQTParser2 sqtParser = new SQTParser2(); List <SQTScan2> theSQT = sqtParser.Parse(inputSQT); //Parse the aScore File StreamReader sr = new StreamReader(@"C:\Users\pcarvalho\Desktop\Juli_fosfo\DTA\AllResults.txt"); string line; StreamWriter sw = new StreamWriter(@"C:\Users\pcarvalho\Desktop\Juli_fosfo\DTA\AScoreXDScoreGoodScores.txt"); while ((line = sr.ReadLine()) != null) { string[] cols = Regex.Split(line, "[-|\t]"); double aScore = double.Parse(cols[2]); int scanNo = int.Parse(cols[0]); SQTScan2 theScan = theSQT.Find(a => a.ScanNumber == scanNo); if (theScan.Matches[0].PrimaryScore > 2 && theScan.ChargeState == 2) { double xd = xdScore.GetDeltaScore(theScan, false); sw.WriteLine(scanNo + "\t" + aScore + "\t" + xd); } } sr.Close(); sw.Close(); } if (false) { SQTParser2 sqtParser = new SQTParser2(); List <SQTScan2> myScans = sqtParser.Parse(inputSQT); List <MSLight> theMS2 = PatternTools.MSParserLight.ParserLight.ParseLightMS2(inputMS2); myScans.RemoveAll(a => a.Matches.Count == 0); myScans.RemoveAll(a => !a.Matches[0].PeptideSequence.Contains("79")); foreach (SQTScan2 scn in myScans) { try { Console.Write("."); MSLight thems = theMS2.Find(a => a.ScanNumber == (int)scn.ScanNumber); string pepSeq = scn.Matches[0].PeptideSequence; pepSeq = Regex.Replace(pepSeq, @"\(\+79\.966300\)", "Z"); StreamWriter sw = new StreamWriter(dtaDir + "/" + scn.ScanNumber + "-" + pepSeq + ".dta"); sw.WriteLine(thems.MHPrecursor[0] + " " + thems.Zs[0].ToString()); foreach (Ion i in thems.Ions) { sw.WriteLine(i.MZ + " " + i.Intensity); } sw.Close(); } catch { Console.Write("P"); } } } if (false) { DirectoryInfo di = new DirectoryInfo(dtaDir); FileInfo[] theFiles = di.GetFiles("*.dta"); StreamWriter sw = new StreamWriter(@"C:\Users\pcarvalho\Desktop\Juli_fosfo\DTA\result.txt"); foreach (FileInfo fi in theFiles) { // Read file data FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); // Generate post objects Dictionary <string, object> postParameters = new Dictionary <string, object>(); postParameters.Add("fileformat", "txt"); postParameters.Add("userfile", new FormUpload.FileParameter(data, fi.Name, "application/msword")); postParameters.Add("mods", "1"); //Cystein postParameters.Add("MAX_FILE_SIZE", "40000"); string [] cols = Regex.Split(fi.Name, "[-|.]"); string pepS = Regex.Replace(cols[1], "Z", "*"); postParameters.Add("sequence", pepS); postParameters.Add("submit", "Calculate Ascore"); HttpWebResponse webResponse = FormUpload.MultipartFormDataPost(@"http://ascore.med.harvard.edu/trim/trim-single.php", "PhosphoPeptide", postParameters); // Process response StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()); string fullResponse = responseReader.ReadToEnd(); webResponse.Close(); string[] cols2 = Regex.Split(fullResponse, "\n"); Regex getNo = new Regex("[0-9]+.[0-9]+"); try { foreach (var m in getNo.Matches(cols2[39])) { sw.WriteLine(fi.Name + "\t" + m.ToString()); Console.WriteLine(m.ToString()); sw.Flush(); } } catch { Console.Write("f"); } fi.Delete(); } sw.Close(); } if (false) { // Read file data string file = @"C:\Users\pcarvalho\Desktop\Juli_fosfo\ToMSAorNotToMSA\test.txt"; FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); // Generate post objects Dictionary <string, object> postParameters = new Dictionary <string, object>(); //postParameters.Add("fileformat", "txt"); postParameters.Add("userfile", new FormUpload.FileParameter(data, file, "application/msword")); postParameters.Add("mods", "1"); //Cystein postParameters.Add("MAX_FILE_SIZE", "40000"); postParameters.Add("sequence", "IEDVGS*DEEDDSGK"); postParameters.Add("submit", "Calculate Ascore"); HttpWebResponse webResponse = FormUpload.MultipartFormDataPost(@"http://ascore.med.harvard.edu/trim/trim-single.php", "PhosphoPeptide", postParameters); // Process response StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()); string fullResponse = responseReader.ReadToEnd(); webResponse.Close(); string[] cols = Regex.Split(fullResponse, "\n"); Regex getNo = new Regex("[0-9]+.[0-9]+"); foreach (var m in getNo.Matches(cols[39])) { Console.WriteLine(m.ToString()); } Console.WriteLine("Done"); } }