private bool IsNotRawfile(string fileName) { bool returnvar = false; try { //IXRawfile5 raw = (IXRawfile5) new MSFileReader_XRawfile(); RawFileName rawfile = new RawFileName(fileName); raw.Open(rawfile.FullName); raw.SetCurrentController(0, 1); int lastScanNumber = -1; raw.GetLastSpectrumNumber(ref lastScanNumber); if (lastScanNumber < 10) { returnvar = true; } if (raw != null) { raw.Close(); } } catch//can add specific exception here { return(true); } finally { //if (raw != null) // raw.Close(); } return(returnvar); }
//add log here public void Analyze(RawFileName rawfile, UIsettings fixedSettings, SettingsForAnalysis fixedSettingsForAnalysis, IProgress <DataRow> resultRow) { if (IsFileLocked(rawfile.FullName)) { Log.Error("[" + rawfile.FullName + "] CRITICAL problem: file locked by another process! Skipping file"); } else if (IsNotRawfile(rawfile.FullName)) { Log.Error("[" + rawfile.FullName + "] CRITICAL problem: raw file corrupt! Skipping file"); } else { Log.Information("[" + rawfile.FullName + "] Main analysis started"); rawfile.SetCategories(fixedSettings.UserList, fixedSettings.LcList, fixedSettings.MsList, fixedSettings.SamplesList); SetRawFileHistory(rawfile, fixedSettings);//This is a mess with the class lines if (rawfile.SomethingWrongWithFileName) { Log.Warning("[" + rawfile.FullName + "] Please check file naming convention: parse rules and filename do not align."); } using (ResultItems results = new ResultItems()) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); MainAnalysisThreadedTask(rawfile, fixedSettingsForAnalysis, fixedSettings, results); Log.Information("[" + rawfile.FullName + "] Main analysis finished in " + stopwatch.Elapsed.TotalMinutes.ToString("0.00") + " minutes"); DoEmailResults(rawfile, fixedSettings, results); DoSqlUpdateResults(rawfile, fixedSettings, results); DoSaveResultsToFile(fixedSettings, results); AddResultRowToDataTable(results.Names, results.Results, results.Types, fixedSettings, resultRow); } } }
public string TryParseRawFile(UIsettings uisettings) { RawFileName rawfile = new RawFileName(uisettings.RawFileTestName); rawfile.SetCategories(uisettings.UserList, uisettings.LcList, uisettings.MsList, uisettings.SamplesList); return(rawfile.ReadCategories()); }
private static void DoEmailResults(RawFileName rawfile, UIsettings fixedSettings, ResultItems results) { if (fixedSettings.UseEmail) { using (EmailSystem emailSystem = new EmailSystem(fixedSettings.Mailserveradress, fixedSettings.Mailportname, fixedSettings.Mailusername, fixedSettings.Mailpassword)) { if (emailSystem.Enabled) { if (!emailSystem.CheckEmailAdress(rawfile.UserEmail, rawfile.User)) { Log.Error("[" + rawfile.FullName + "] " + "Email can't be sent, email >" + rawfile.UserEmail + "< not correct for user: "******""); string[] compareSymbols = fixedSettings.CompareSymbols; foreach (InformationKey ik in fixedSettings.informationKey) { bool addMessage; if (ik.Message != "") { addMessage = CustomCompare(ik.Name, ik.ComparisonText1, results.Types[ik.ResultItemIndex1], results.Results[ik.ResultItemIndex1], compareSymbols[ik.ComparisonIndex1]); addMessage = addMessage && CustomCompare(ik.Name, ik.ComparisonText2, results.Types[ik.ResultItemIndex2], results.Results[ik.ResultItemIndex2], compareSymbols[ik.ComparisonIndex2]); addMessage = addMessage && CustomCompare(ik.Name, ik.ComparisonText3, results.Types[ik.ResultItemIndex3], results.Results[ik.ResultItemIndex3], compareSymbols[ik.ComparisonIndex3]); addMessage = addMessage && CustomCompare(ik.Name, ik.ComparisonText4, results.Types[ik.ResultItemIndex4], results.Results[ik.ResultItemIndex4], compareSymbols[ik.ComparisonIndex4]); addMessage = addMessage && CustomCompare(ik.Name, ik.ComparisonText5, results.Types[ik.ResultItemIndex5], results.Results[ik.ResultItemIndex5], compareSymbols[ik.ComparisonIndex5]); if (addMessage) { messageContent.Append(ik.Name); messageContent.Append(": "); messageContent.Append(ik.Message); messageContent.Append("<br />"); } } } StringBuilder bodyContent = new StringBuilder("<table>"); for (int i = 0; i < results.Count; i++) { bodyContent.Append("<tr><td>"); bodyContent.Append(results.Names[i]); bodyContent.Append("</td><td>"); bodyContent.Append(results.Results[i]); bodyContent.Append("</td></tr>"); } bodyContent.Append("</table>"); string mailresult = emailSystem.SendMail(rawfile.UserEmail, rawfile.User, rawfile.BaseName, bodyContent.ToString(), messageContent.ToString(), rawfile.CcEmails); Log.Information("[" + rawfile.FullName + "] " + "UseEmail system reported " + mailresult); } } else { Log.Error("[" + rawfile.FullName + "] " + "UseEmail system couldn't initialize, is the server configured correctly?"); } } } }
private static void DoSqlUpdateResults(RawFileName rawfile, UIsettings fixedSettings, ResultItems results) { if (fixedSettings.UseSql) { Log.Information("[" + rawfile.FullName + "] Uploading results to database"); using (SQL newsql = new SQL(fixedSettings.Sqlserveradress, fixedSettings.Sqldatabase, fixedSettings.Sqltable, fixedSettings.Sqlusername, fixedSettings.Sqlpassword)) { newsql.Insert(results.Names, results.ResultsWithMaxLength(255)); } } }
private static void SetRawFileHistory(RawFileName rawfile, UIsettings fixedSettings) { if (fixedSettings.UseSql) { List <double> totalusagetime = new List <double>(); List <double> totalmstime = new List <double>(); List <double> totalnonqcmstime = new List <double>(); using (SQL newsql = new SQL(fixedSettings.Sqlserveradress, fixedSettings.Sqldatabase, fixedSettings.Sqltable, fixedSettings.Sqlusername, fixedSettings.Sqlpassword)) { newsql.GetTime(rawfile.daysToGoBack, rawfile.MsInstrument, rawfile.MsInstrumentDetails, out totalusagetime, out totalmstime, out totalnonqcmstime); } rawfile.SetUsageTimes(totalusagetime, totalmstime, totalnonqcmstime); } }
private static void MainAnalysisThreadedTask(RawFileName rawfile, SettingsForAnalysis fixedSettingsForAnalysis, UIsettings fixedSettings, ResultItems results) { //ResultItems results = new ResultItems(); //this can now be done threaded List <Task <ResultItems> > taskList = new List <Task <ResultItems> >(); taskList.Add(Task.Run(() => { ResultItems results1 = new ResultItems(); using (AnalysisTemplate curMethod = new AnalysisMorpheus()) { results1 = curMethod.Analyze(rawfile, fixedSettingsForAnalysis, fixedSettings); } GC.Collect();//ugly but this solves problem with memory not released return(results1); })); taskList.Add(Task.Run(() => { ResultItems results2 = new ResultItems(); using (AnalysisTemplate curMethod = new AnalysisBase()) { results2 = curMethod.Analyze(rawfile, fixedSettingsForAnalysis, fixedSettings); } return(results2); })); taskList.Add(Task.Run(() => { ResultItems results3 = new ResultItems(); using (AnalysisTemplate curMethod = new AnalysisExternal1()) { results3 = curMethod.Analyze(rawfile, fixedSettingsForAnalysis, fixedSettings); } return(results3); })); Task.WaitAll(taskList.ToArray()); foreach (Task <ResultItems> resultTask in taskList) { results.Add(resultTask.Result); } //return results; }
public override ResultItems Analyze(RawFileName rawfile, SettingsForAnalysis settingName, UIsettings fixedSettings) { //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); ResultItems results = GetResultItems(fixedSettings); //MsScanParameters msScanParameters = new MsScanParameters(settingName); //progress.Report("[" + rawfile.FullName + "] Start at " + stopwatch.Elapsed.TotalMinutes.ToString("0.00") + " minutes"); results.SetValue("RawFile", rawfile.BaseName); results.SetValue("User", rawfile.User); results.SetValue("MS instrument", rawfile.MsInstrument); results.SetValue("MS instrument number", rawfile.MsInstrumentDetails); results.SetValue("LC instrument", rawfile.LcInstrument); results.SetValue("LC instrument number", rawfile.LcInstrumentDetails); results.SetValue("Sample type", rawfile.SampleType); results.SetValue("Sample type details", rawfile.SampleTypeDetails); results.SetValue("File name convention followed", (!rawfile.SomethingWrongWithFileName).ToString()); // shitty hack, should be bool results.SetValue("File size (MiB)", rawfile.FileSizeMiB, 1); results.SetValue("Storage space left (GiB)", rawfile.SpaceLeftGiB, 1); if (settingName.UseBaseAnalysis) { StatusLog statusLog; using (RawFileProcessing rawfileResults = new RawFileProcessing(raw, rawfile.FullName, settingName)) { rawfile.SetDates(rawfileResults._filecreation, rawfileResults._msStart, rawfileResults._msEnd); statusLog = rawfileResults.statusLog; results.SetValue("Warning log", rawfileResults.WarningMessage); results.SetValue("MS count", rawfileResults.MsCount, 0); results.SetValue("MS TIC", rawfileResults.MsTic, 0); results.SetValue("MS TIC (high percentile)", rawfileResults.MsTicHigh, 0); results.SetValue("MS signal to noise", rawfileResults.MsS2N, 2); results.SetValue("MS ion count", rawfileResults.MsIonCount, 0); results.SetValue("CTCD or PrOSA minimum", rawfileResults.CtcdMin, 3); results.SetValue("CTCD or PrOSA maximum", rawfileResults.CtcdMax, 3); results.SetValue("Lock mass correction maximum absolute (ppm)", rawfileResults.LockMassCorrectionMaxAbsolute, 2); results.SetValue("Large injection time fluctuations", rawfileResults.LargeFluctuations, 1); //set as parameter from usrcontrol results.SetValue("Polymer01", rawfileResults.Polymer1, 1); results.SetValue("Polymer02", rawfileResults.Polymer2, 1); results.SetValue("Polymer03", rawfileResults.Polymer3, 1); results.SetValue("Polymer04", rawfileResults.Polymer4, 1); results.SetValue("Polymer05", rawfileResults.Polymer5, 1); results.SetValue("AdductNa", rawfileResults.AdductNa, 1); results.SetValue("AdductCa", rawfileResults.AdductCa, 1); results.SetValue("AdductFe", rawfileResults.AdductFe, 1); results.SetValue("AdductK", rawfileResults.AdductK, 1); results.SetValue("AdductFA", rawfileResults.AdductFA, 1); results.SetValue("AdductNH3", rawfileResults.AdductNH3, 1); results.SetValue("AdductACN", rawfileResults.AdductACN, 1); results.SetValue("Precursor 5 percent mass quantile", rawfileResults.PrecursorMass5percent, 1); results.SetValue("Precursor 95 percent mass quantile", rawfileResults.PrecursorMass95percent, 1); results.SetValue("MS2 topN", rawfileResults.TopN, 2); results.SetValue("MS2 count", rawfileResults.Ms2Count, 0); results.SetValue("MS2 TIC", rawfileResults.Ms2Tic, 0); results.SetValue("MS2 signal to noise", rawfileResults.Ms2S2N, 2); results.SetValue("MS2 ion count", rawfileResults.Ms2IonCount, 0); results.SetValue("MS2 precursor isolation width TIC", rawfileResults.Ms2IsolationWindowTic, 0); results.SetValue("MS2TIC / MS2 precursor isolation width TIC", rawfileResults.Ms2IsolationWindowTicRelative, 3); results.SetValue("MS2 count above ion threshold", rawfileResults.Ms2ScansAboveIonThreshold, 0); results.SetValue("MS2 with charge 2 in percent", rawfileResults.Ms2charge2, 2); results.SetValue("MS2 with charge 3 in percent", rawfileResults.Ms2charge3, 2); results.SetValue("MS2 with charge 4 or higher in percent", rawfileResults.Ms2charge4orMore, 2); results.SetValue("MS2 scans XIC above precursor percentage", rawfileResults.Ms2ScansAbovePrecursorPercent, 2); results.SetValue("MS2 count above ion threshold percentage", rawfileResults.Ms2ScansAboveIonThresholdPercent, 1); results.SetValue("MS2 scans with precursor as BP percentage", rawfileResults.Ms2ScansWithPrecursorBasePeakPercent, 2); } results.SetValue("LCMS start", rawfile.GetDates(0)); results.SetValue("MS start", rawfile.GetDates(1)); results.SetValue("LCMS end", rawfile.GetDates(2)); results.SetValue("MS time in minutes", rawfile.MsTime, 2); results.SetValue("LC time in minutes", rawfile.LcTime, 2); Dictionary <int, Tuple <double, double, double> > usage = rawfile.GetUsagePercent(); foreach (int day in usage.Keys) { results.SetValue("Last " + day.ToString() + " day(s) LCMS usage percent", usage[day].Item1, 1); results.SetValue("Last " + day.ToString() + " day(s) MS usage percent", usage[day].Item2, 1); results.SetValue("Last " + day.ToString() + " day(s) MS excl QC usage percent", usage[day].Item3, 1); } //status log entries foreach (StatusLogItem item in fixedSettings.statusLogItems) { if (item.CalculateMedian) { results.SetValue(item.Name, statusLog.GetMedianOf(item.Name)); } if (item.CalculateMin) { results.SetValue(item.Name + " min", statusLog.GetMinOf(item.Name)); } if (item.CalculateMax) { results.SetValue(item.Name + " max", statusLog.GetMaxOf(item.Name)); } if (item.CalculateIQR) { results.SetValue(item.Name + " IQR", statusLog.GetIqrOf(item.Name)); } } } results.SetValue("Analysis tool version", "0.0.1.21"); return(results); }
public override ResultItems Analyze(RawFileName rawfile, SettingsForAnalysis settingName, UIsettings fixedSettings) { ResultItems results = GetResultItems(fixedSettings); List <double> resultlist = new List <double>(); if (settingName.UseExternal1Analysis) { Log.Information("Started external1"); string filename = rawfile.FullName;//"f:/temp2/20190114_QE99_Evo1_DBJ_E7_LFQprot_QC4_HELA_PAC_250ng_7500_01.raw"; //get list of files and column/row names List <string> resultfiles = new List <string>(); List <string> resultnames = new List <string>(); foreach (ExternalResultParseSetting settings in fixedSettings.ExternalResults) { string resultfile = settings.ResultFile; resultfile = resultfile.Replace("{FILE}", rawfile.FullName); resultfiles.Add(resultfile); resultnames.Add(settings.Resultname); } //maybe add option to delete resultfile? try { string arguments = fixedSettings.Arguments; arguments = arguments.Replace("{FILE}", rawfile.FullName); resultlist = ExecuteProgram.GetResultsFromExternalProgram( fixedSettings.Executable, //raw.exe arguments, //"parse -x -f " + filename resultfiles.ToArray(), resultnames.ToArray(), fixedSettings.Timeout, fixedSettings.ExternalToolSepChar, !fixedSettings.AsRow); if (resultlist.Count != fixedSettings.ExternalResults.Count) { resultlist.Clear(); for (int i = 0; i < fixedSettings.ExternalResults.Count; i++) { resultlist.Add(0.0); } Log.Error("External1 result was not parsed correctly (are headers correct?)"); } Log.Information("Finished external1"); } catch { //something went wrong, adding 0s as filler and reporting error Log.Error("External1 failed"); for (int i = 0; i < fixedSettings.ExternalResults.Count; i++) { resultlist.Add(0.0); } } } else { //no analysis requested, adding 0s as filler for (int i = 0; i < fixedSettings.ExternalResults.Count; i++) { resultlist.Add(0.0); } } //set results for (int i = 0; i < fixedSettings.ExternalResults.Count; i++) { results.SetValue(fixedSettings.ExternalResults[i].Resultname, resultlist[i]); } return(results); }
public virtual ResultItems Analyze(RawFileName rawfile, SettingsForAnalysis settingName, UIsettings settings) { return(GetResultItems(settings)); }