static void Main(string[] args) { if (args.Length == 0) { MainForm mf = new MainForm(); //mf.ShowDialog(); return; } FileInfo file; file = new FileInfo(args[0]); RawReaderParams readerParams = new RawReaderParams(); readerParams.LoadDefaults(); Reader reader = new Reader(readerParams); List <MSLight> allSpectra = reader.GetSpectra(file.FullName, new List <int>(), false); if (readerParams.ExtractMS1) { List <MSLight> msPrint = allSpectra.FindAll(a => a.ActivationType.Equals("")); SpectraPrinter.PrintFile(file, msPrint, ".ms1", readerParams); } if (readerParams.ExtractMS2) { List <MSLight> msPrint = allSpectra.FindAll(a => !a.ActivationType.Equals("")); SpectraPrinter.PrintFile(file, msPrint, ".ms2", readerParams); } }
private void buttonExtract_Click(object sender, EventArgs e) { richTextBoxMS.Clear(); RawReaderParams myParams = new RawReaderParams(); myParams.LoadDefaults(); Reader r = new Reader(myParams); List <MSLight> theMS = r.GetSpectra(studyFile.FullName, new List <int>() { (int)numericUpDownSpectrumNumber.Value }, false); List <Ion> theIons = new List <Ion>(); for (int i = 0; i < theMS[0].MZ.Count; i++) { theIons.Add(new Ion(theMS[0].MZ[i], theMS[0].Intensity[i], 0, 0)); } foreach (Ion i in theIons) { richTextBoxMS.AppendText(i.MZ + " " + i.Intensity + "\n"); } }
private RawReaderParams CaptureParamsFromScreen() { RawReaderParams theParams = new RawReaderParams(); theParams.ExtractMS1 = checkBoxMS1.Checked; theParams.ExtractMS2 = checkBoxMS2.Checked; theParams.ExtractMS2 = checkBoxMS3.Checked; theParams.UseThermoMonoIsotopicPrediction = checkBoxUseThermosMonoIsotopicInference.Checked; theParams.ActivateSpectraCleaner = checkBoxSpectraCleaner.Checked; theParams.SpectraCleanerWindowSize = (int)numericUpDownWindowSize.Value; theParams.SpectraCleanerMaxPeaksPerWindow = (int)numericUpDownMaxPeaksPerWindow.Value; theParams.SpectraCleanerMaxSpectraPerFile = (int)numericUpDownSpectraPerFile.Value; return(theParams); }
private void buttonGO_Click(object sender, EventArgs e) { if (!Directory.Exists(textBoxInputDirectory.Text)) { MessageBox.Show("Please enter a valid directory"); return; } if (!checkBoxMS1.Checked && !checkBoxMS2.Checked && !checkBoxMGF.Checked) { MessageBox.Show("Please enter at least one valid output format."); return; } buttonGO.Text = "Working"; this.Update(); DirectoryInfo di = new DirectoryInfo(textBoxInputDirectory.Text); List <FileInfo> rawFiles = di.GetFiles("*.raw").ToList(); progressBar1.Value = 0; this.Update(); RawReaderParams rawReaderParams = CaptureParamsFromScreen(); double fileCounter = 0; foreach (FileInfo rawFile in rawFiles) { try { Console.WriteLine("Processing file " + rawFile.Name); Reader r = new Reader(rawReaderParams); List <MSLight> theSpectra = r.GetSpectra(rawFile.FullName, new List <int>(), false); if (theSpectra.Count == 0) { WriteMessageToLog(di, "No mass spectra found in file : " + rawFile.Name); } else { if (rawReaderParams.ExtractMS1) { List <MSLight> ms2Print = theSpectra.FindAll(a => a.ZLines.Count == 0); SpectraPrinter.PrintFile(rawFile, ms2Print, ".ms1", rawReaderParams); } //MS2 and MS3 need to be revised to work with MS3. if (rawReaderParams.ExtractMS2) { List <MSLight> ms2Print = theSpectra.FindAll(a => a.ZLines.Count > 0); SpectraPrinter.PrintFile(rawFile, ms2Print, ".ms2", rawReaderParams); } if (rawReaderParams.ExtractMS3) { List <MSLight> ms3Print = theSpectra.FindAll(a => a.ZLines.Count > 0); SpectraPrinter.PrintFile(rawFile, ms3Print, ".ms3", rawReaderParams); } if (checkBoxMGF.Checked) { List <MSLight> ms2Print = theSpectra.FindAll(a => a.ZLines.Count > 0); List <MSUltraLight> ms22 = ms2Print.Select(a => new MSUltraLight(a, -1)).ToList(); WriteAsMGF(ms22, rawFile.FullName + ".mgf"); } } fileCounter++; progressBar1.Value = (int)((fileCounter / (double)rawFiles.Count()) * 100); this.Update(); } catch (Exception e2) { Console.WriteLine("Problem on file : " + rawFile.Name + "\n" + e2.Message); WriteMessageToLog(di, "Problem on file : " + rawFile.Name + "\n" + e2.Message); } } buttonGO.Text = "GO !"; this.Update(); }
public static void PrintFile(FileInfo rawFile, List <MSLight> ms2Print, string ext, RawReaderParams readerParams) { string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(rawFile.FullName); string outputFileName = rawFile.Directory.FullName + "/" + fileNameWithoutExtension + ext; if (readerParams.ActivateSpectraCleaner) { int fileCounter = 0; List <MSLight> tmpSpectraList = new List <MSLight>(); foreach (MSLight mslight in ms2Print) { tmpSpectraList.Add(mslight); if (tmpSpectraList.Count == readerParams.SpectraCleanerMaxSpectraPerFile) { fileCounter++; Print(tmpSpectraList, outputFileName + "_" + fileCounter + ext); tmpSpectraList.Clear(); } } if (tmpSpectraList.Count > 0) { fileCounter++; Print(ms2Print, outputFileName + "_" + fileCounter + ext); tmpSpectraList.Clear(); } } else { Print(ms2Print, outputFileName); } }