static int Main(string[] args) { //Параметры соответствуют вводу в форму RawtoMGF //args[0] - имя Raw-файла //args[1] - имя MGF-файла //args[2] - minimal MZ //args[3] - maximal MZ //args[4] - minimal RT //args[5] - maximal RT //args[6] - minimal Charge //args[7] - maximal Charge //args[8] - number of top peaks //args[9] - CleanETD:yes / CleanETD:no //args[10] - Instrument:yes / Instrument:no //дополнительно (к версии 2.0.6) //args[11] - CheckSpectra:yes / CheckSpectra:no try{ Console.ReadLine(); //Thread.Sleep(30000); string InFileName = args[0]; string OutFileName = args[1]; double MinMZ = Convert.ToDouble(args[2]); double MaxMZ = Convert.ToDouble(args[3]); double MinRT = Convert.ToDouble(args[4]); double MaxRT = Convert.ToDouble(args[5]); int MinCharge = Convert.ToInt32(args[6]); int MaxCharge = Convert.ToInt32(args[7]); int MaxPeakNumber = Convert.ToInt32(args[8]); bool CleanETD = args[9].Contains("CleanETD:yes"); bool MarkInstrtument = args[10].Contains("Instrument:yes"); bool CheckSpectra = args[11].Contains("CheckSpectra:yes"); bool RTApex = args[12].Contains("RTApex:yes"); string[] Refs = {"@cid","@hcd","@etd","@ecd","FTMS","ITMS"}; MSFileReader_XRawfile RawFile; int Spectra,LocalCount = 0; string Filter; MGFFile MGF; MGFSpectrum ms; Childs ch; ChildbyIntensity ci = new ChildbyIntensity(); ChildbyMass cm = new ChildbyMass(); int ArraySize = 0; Object MassList, EmptyRef; Object Labels,Values; double temp=0.0; int Progress = 0; int MSCount = 0; int MSMSCount = 0; if (RTApex){ MSFileBox = new RawFileBox(); MSFileBox.LoadIndex(InFileName); RawFileBox.RepProgress = RepProgress; RawFile = MSFileBox.RawFile; }else{ RawFile = new MSFileReader_XRawfile(); RawFile.Open(InFileName); RawFile.SetCurrentController(0, 1); } Spectra = 0; RawFile.GetNumSpectra(ref Spectra); if (Spectra == 0) { throw new Exception("Cannot get spectra from the file "+InFileName+", File is invalid, broken or empty"); } MGF = new MGFFile(); for (int j=1 ; j<=Spectra ; j++){ Filter = null; RawFile.GetFilterForScanNum(j, ref Filter); if (Filter.IndexOf("ms2") == -1) { MSCount++; if (!CheckSpectra){ continue; }else{ ArraySize = 0; MassList = null; EmptyRef=null; temp=0.0; try { RawFile.GetMassListFromScanNum(ref j, null, 0, 0, 0, 0, ref temp, ref MassList, ref EmptyRef, ref ArraySize); continue; }catch{ Exception e = new Exception(string.Format("Scan #{0} cannot be loaded, probably RAW file is corrupted!",j)); throw e; } } } MSMSCount++; ms = new MGFSpectrum(); //определяем родительскую массу, заряд и RT Labels = null; Values = null; ArraySize = 0; LocalCount++; RawFile.GetTrailerExtraForScanNum(j, ref Labels, ref Values, ref ArraySize); for (int k = 0 ; k < ArraySize ; k++ ){ if ((Labels as Array).GetValue(k).ToString().Contains("Mono")){ ms.mz = Convert.ToDouble((Values as Array).GetValue(k).ToString()); } if ((Labels as Array).GetValue(k).ToString().Contains("Charge State")){ ms.Charge = Convert.ToInt32((Values as Array).GetValue(k).ToString()); } } //Если не нашли в labels - берем из фильтра if (ms.mz == 0.0) { string part= Filter.Substring(0,Filter.IndexOf('@')); ms.mz = Convert.ToDouble(part.Substring(part.LastIndexOf(' '))); } Labels = null; Values = null; ArraySize = 0; double RT = 0; RawFile.GetStatusLogForScanNum(j,ref RT, ref Labels, ref Values, ref ArraySize); RawFile.RTFromScanNum(j,ref ms.RT); ms.ScanNumber = j; //Фильтры if (ms.Charge < MinCharge) continue; if (ms.Charge > MaxCharge) continue; if (ms.RT < MinRT) continue; if (MaxRT != 0.0 && ms.RT > MaxRT) continue; if (ms.mz < MinMZ) continue; if (MaxMZ != 0.0 && ms.mz > MaxMZ) continue; //забираем сам спектр MassList = null; EmptyRef=null; ArraySize = 0; temp=0.0; try{ if (Filter.IndexOf("FTMS") != -1){ //извлекаем FTMS данные (RawFile as IXRawfile2).GetLabelData(ref MassList, ref EmptyRef, ref j); ArraySize = (MassList as Array).GetLength(1); for (int k = 0 ; k<ArraySize ; k++ ){ ch = new Childs(); ch.Mass = (double)(MassList as Array).GetValue(0, k); ch.Intensity = (double)(MassList as Array).GetValue(1, k); ms.Data.Add(ch); } }else{ //извлекаем ITMS данные RawFile.GetMassListFromScanNum(ref j, null, 0, 0, 0, 1, ref temp, ref MassList, ref EmptyRef, ref ArraySize); ArraySize = (MassList as Array).GetLength(1); for ( int k = 0 ; k<ArraySize ; k++){ ch = new Childs(); ch.Mass = (double)(MassList as Array).GetValue(0, k); ch.Intensity = (double)(MassList as Array).GetValue(1, k); ms.Data.Add(ch); } } }catch{ Exception e = new Exception(string.Format("Scan #{0} cannot be loaded, probably RAW file is corrupted!",j)); throw e; } if (RTApex){ ms.RTApex = CheckRTApex(ms.RT, ms.mz); } if (MarkInstrtument){ if (Filter.Contains("ecd") || Filter.Contains("etd")){ ms.Instrument = "ETD-TRAP"; }else{ ms.Instrument= "ESI-FTICR"; } } //очистить ETD если был такой запрос if ( CleanETD ){ if (Filter.Contains("ecd") || Filter.Contains("etd")){ FilterETD(ref ms, Filter.Contains("FTMS")); } } //сбросить лишние сигналы if (MaxPeakNumber > 0 && ms.Data.Count > MaxPeakNumber){ ms.Data.Sort(ci); ms.Data.RemoveRange(0,ms.Data.Count-MaxPeakNumber); ms.Data.Sort(cm); } //сформировать TITLE if (RTApex){ ms.Title = String.Format("Elution from: {0:f4} to {0:f4} RT Apex: {1:f2} FinneganScanNumber: {2}", ms.RT, ms.RTApex, ms.ScanNumber); }else{ ms.Title = String.Format("Elution from: {0:f4} to {0:f4} FinneganScanNumber: {1}", ms.RT,ms.ScanNumber); } MGF.Spectra.Add(ms); // рапортовать прогресс GC.Collect(2); if ((int)(((double)j/(double)Spectra)*100.0) > Progress){ Progress = (int)(((double)j/(double)Spectra)*100.0); Console.WriteLine("{0}%... {1} {2}",Progress,MSCount,MSMSCount); } //backgroundWorker1.ReportProgress((int)(((double)LocalCount/(double)SpCount)*100.0)); } MGF.MGFComments.Add(String.Format("Created by RawToMGF 2.1.3; Spectra obtained from {0}",InFileName)); MGF.MGFComments.Add(String.Format("Filters: Parent m/z from {0} Th to {1} Th;",MinMZ,MaxMZ)); MGF.MGFComments.Add(String.Format(" RT from {0} min. to {1} min.;",MinRT,MaxRT)); MGF.MGFComments.Add(String.Format(" Charge state of parent ions minimum {0}, maximum {1};",MinCharge,MaxCharge)); MGF.MGFComments.Add(String.Format(" Max number of peaks in MS/MS spectra - {0}",MaxPeakNumber)); if ( CleanETD ) { MGF.MGFComments.Add(" ETD spectra cleaned from precursors and neutral losses"); } MGF.MGFWrite(OutFileName,true); }catch(Exception e){ Console.Write("Error:"); Console.Write(e.Message); Console.WriteLine("STACKINFO:"+e.StackTrace); //Console.ReadKey(); return 1; } Console.WriteLine("Completed"); Console.ReadLine(); return 0; }
static double MZError = 10; //ppm static int Main(string[] args) { //Параметры соответствуют вводу в форму RawtoMGF //args[0] - имя Raw-файла //args[1] - имя MGF-файла //args[2] - minimal MZ //args[3] - maximal MZ //args[4] - minimal RT //args[5] - maximal RT //args[6] - minimal Charge //args[7] - maximal Charge //args[8] - number of top peaks //args[9] - CleanETD:yes / CleanETD:no //args[10] - Instrument:yes / Instrument:no //дополнительно (к версии 2.0.6) //args[11] - CheckSpectra:yes / CheckSpectra:no try{ Console.ReadLine(); //Thread.Sleep(30000); string InFileName = args[0]; string OutFileName = args[1]; double MinMZ = Convert.ToDouble(args[2]); double MaxMZ = Convert.ToDouble(args[3]); double MinRT = Convert.ToDouble(args[4]); double MaxRT = Convert.ToDouble(args[5]); int MinCharge = Convert.ToInt32(args[6]); int MaxCharge = Convert.ToInt32(args[7]); int MaxPeakNumber = Convert.ToInt32(args[8]); bool CleanETD = args[9].Contains("CleanETD:yes"); bool MarkInstrtument = args[10].Contains("Instrument:yes"); bool CheckSpectra = args[11].Contains("CheckSpectra:yes"); bool RTApex = args[12].Contains("RTApex:yes"); string[] Refs = { "@cid", "@hcd", "@etd", "@ecd", "FTMS", "ITMS" }; MSFileReader_XRawfile RawFile; int Spectra, LocalCount = 0; string Filter; MGFFile MGF; MGFSpectrum ms; Childs ch; ChildbyIntensity ci = new ChildbyIntensity(); ChildbyMass cm = new ChildbyMass(); int ArraySize = 0; Object MassList, EmptyRef; Object Labels, Values; double temp = 0.0; int Progress = 0; int MSCount = 0; int MSMSCount = 0; if (RTApex) { MSFileBox = new RawFileBox(); MSFileBox.LoadIndex(InFileName); RawFileBox.RepProgress = RepProgress; RawFile = MSFileBox.RawFile; } else { RawFile = new MSFileReader_XRawfile(); RawFile.Open(InFileName); RawFile.SetCurrentController(0, 1); } Spectra = 0; RawFile.GetNumSpectra(ref Spectra); if (Spectra == 0) { throw new Exception("Cannot get spectra from the file " + InFileName + ", File is invalid, broken or empty"); } MGF = new MGFFile(); for (int j = 1; j <= Spectra; j++) { Filter = null; RawFile.GetFilterForScanNum(j, ref Filter); if (Filter.IndexOf("ms2") == -1) { MSCount++; if (!CheckSpectra) { continue; } else { ArraySize = 0; MassList = null; EmptyRef = null; temp = 0.0; try { RawFile.GetMassListFromScanNum(ref j, null, 0, 0, 0, 0, ref temp, ref MassList, ref EmptyRef, ref ArraySize); continue; }catch { Exception e = new Exception(string.Format("Scan #{0} cannot be loaded, probably RAW file is corrupted!", j)); throw e; } } } MSMSCount++; ms = new MGFSpectrum(); //определяем родительскую массу, заряд и RT Labels = null; Values = null; ArraySize = 0; LocalCount++; RawFile.GetTrailerExtraForScanNum(j, ref Labels, ref Values, ref ArraySize); for (int k = 0; k < ArraySize; k++) { if ((Labels as Array).GetValue(k).ToString().Contains("Mono")) { ms.mz = Convert.ToDouble((Values as Array).GetValue(k).ToString()); } if ((Labels as Array).GetValue(k).ToString().Contains("Charge State")) { ms.Charge = Convert.ToInt32((Values as Array).GetValue(k).ToString()); } } //Если не нашли в labels - берем из фильтра if (ms.mz == 0.0) { string part = Filter.Substring(0, Filter.IndexOf('@')); ms.mz = Convert.ToDouble(part.Substring(part.LastIndexOf(' '))); } Labels = null; Values = null; ArraySize = 0; double RT = 0; RawFile.GetStatusLogForScanNum(j, ref RT, ref Labels, ref Values, ref ArraySize); RawFile.RTFromScanNum(j, ref ms.RT); ms.ScanNumber = j; //Фильтры if (ms.Charge < MinCharge) { continue; } if (ms.Charge > MaxCharge) { continue; } if (ms.RT < MinRT) { continue; } if (MaxRT != 0.0 && ms.RT > MaxRT) { continue; } if (ms.mz < MinMZ) { continue; } if (MaxMZ != 0.0 && ms.mz > MaxMZ) { continue; } //забираем сам спектр MassList = null; EmptyRef = null; ArraySize = 0; temp = 0.0; try{ if (Filter.IndexOf("FTMS") != -1) { //извлекаем FTMS данные (RawFile as IXRawfile2).GetLabelData(ref MassList, ref EmptyRef, ref j); ArraySize = (MassList as Array).GetLength(1); for (int k = 0; k < ArraySize; k++) { ch = new Childs(); ch.Mass = (double)(MassList as Array).GetValue(0, k); ch.Intensity = (double)(MassList as Array).GetValue(1, k); ms.Data.Add(ch); } } else { //извлекаем ITMS данные RawFile.GetMassListFromScanNum(ref j, null, 0, 0, 0, 1, ref temp, ref MassList, ref EmptyRef, ref ArraySize); ArraySize = (MassList as Array).GetLength(1); for (int k = 0; k < ArraySize; k++) { ch = new Childs(); ch.Mass = (double)(MassList as Array).GetValue(0, k); ch.Intensity = (double)(MassList as Array).GetValue(1, k); ms.Data.Add(ch); } } }catch { Exception e = new Exception(string.Format("Scan #{0} cannot be loaded, probably RAW file is corrupted!", j)); throw e; } if (RTApex) { ms.RTApex = CheckRTApex(ms.RT, ms.mz); } if (MarkInstrtument) { if (Filter.Contains("ecd") || Filter.Contains("etd")) { ms.Instrument = "ETD-TRAP"; } else { ms.Instrument = "ESI-FTICR"; } } //очистить ETD если был такой запрос if (CleanETD) { if (Filter.Contains("ecd") || Filter.Contains("etd")) { FilterETD(ref ms, Filter.Contains("FTMS")); } } //сбросить лишние сигналы if (MaxPeakNumber > 0 && ms.Data.Count > MaxPeakNumber) { ms.Data.Sort(ci); ms.Data.RemoveRange(0, ms.Data.Count - MaxPeakNumber); ms.Data.Sort(cm); } //сформировать TITLE if (RTApex) { ms.Title = String.Format("Elution from: {0:f4} to {0:f4} RT Apex: {1:f2} FinneganScanNumber: {2}", ms.RT, ms.RTApex, ms.ScanNumber); } else { ms.Title = String.Format("Elution from: {0:f4} to {0:f4} FinneganScanNumber: {1}", ms.RT, ms.ScanNumber); } MGF.Spectra.Add(ms); // рапортовать прогресс GC.Collect(2); if ((int)(((double)j / (double)Spectra) * 100.0) > Progress) { Progress = (int)(((double)j / (double)Spectra) * 100.0); Console.WriteLine("{0}%... {1} {2}", Progress, MSCount, MSMSCount); } //backgroundWorker1.ReportProgress((int)(((double)LocalCount/(double)SpCount)*100.0)); } MGF.MGFComments.Add(String.Format("Created by RawToMGF 2.1.3; Spectra obtained from {0}", InFileName)); MGF.MGFComments.Add(String.Format("Filters: Parent m/z from {0} Th to {1} Th;", MinMZ, MaxMZ)); MGF.MGFComments.Add(String.Format(" RT from {0} min. to {1} min.;", MinRT, MaxRT)); MGF.MGFComments.Add(String.Format(" Charge state of parent ions minimum {0}, maximum {1};", MinCharge, MaxCharge)); MGF.MGFComments.Add(String.Format(" Max number of peaks in MS/MS spectra - {0}", MaxPeakNumber)); if (CleanETD) { MGF.MGFComments.Add(" ETD spectra cleaned from precursors and neutral losses"); } MGF.MGFWrite(OutFileName, true); }catch (Exception e) { Console.Write("Error:"); Console.Write(e.Message); Console.WriteLine("STACKINFO:" + e.StackTrace); //Console.ReadKey(); return(1); } Console.WriteLine("Completed"); Console.ReadLine(); return(0); }