From e337c04d827a80f4de2b95e8c13dd2fc039d1bcd Mon Sep 17 00:00:00 2001 From: Ondrej Kuda <111736085+ondrej-kuda@users.noreply.github.com> Date: Sat, 27 Jan 2024 22:36:06 +0100 Subject: [PATCH 1/2] Added support for multiple CPU threads in lcmsdda mode. Use 'number of threads:64' in the parameter file to run processing on 64 threads. For efficiency, the actual number of threads is limited to the maximum number of available cores. --- .../Parser/ConfigParser.cs | 3 + .../Process/LcmsDdaProcess.cs | 184 +++++++++++++----- .../Properties/Resources.Designer.cs | 4 +- .../Properties/Resources.resx | 3 +- 4 files changed, 138 insertions(+), 56 deletions(-) diff --git a/src/MSDIAL4/MsdialConsoleAppCore/Parser/ConfigParser.cs b/src/MSDIAL4/MsdialConsoleAppCore/Parser/ConfigParser.cs index b63a2b0fc..db9497026 100644 --- a/src/MSDIAL4/MsdialConsoleAppCore/Parser/ConfigParser.cs +++ b/src/MSDIAL4/MsdialConsoleAppCore/Parser/ConfigParser.cs @@ -177,6 +177,9 @@ private static void lcmsParamUpdate(AnalysisParametersBean param, string method, //Isotope case "maximum charged number": if (int.TryParse(value, out i)) param.MaxChargeNumber = i; return; + // max number of CPU threads + case "number of threads": if (int.TryParse(value, out i)) param.NumThreads = i; Console.WriteLine("Asked for {0} threads", i); return; + //Retentiontime correction case "excute rt correction": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.ExcuteRtCorrection = bool.Parse(value); return; case "rt correction with smoothing for rt diff": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.doSmoothing = bool.Parse(value); return; diff --git a/src/MSDIAL4/MsdialConsoleAppCore/Process/LcmsDdaProcess.cs b/src/MSDIAL4/MsdialConsoleAppCore/Process/LcmsDdaProcess.cs index 3e08fdb7a..06be378bb 100644 --- a/src/MSDIAL4/MsdialConsoleAppCore/Process/LcmsDdaProcess.cs +++ b/src/MSDIAL4/MsdialConsoleAppCore/Process/LcmsDdaProcess.cs @@ -12,6 +12,11 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Collections.Concurrent; +using System.Reflection; + namespace Riken.Metabolomics.MsdialConsoleApp.Process { @@ -19,10 +24,12 @@ public class LcmsDdaProcess { public int Run(string inputFolder, string outputFolder, string methodFile, bool isProjectStore, float targetMz) { - Console.WriteLine("Loading library files.."); + Console.WriteLine("Loading library files..."); + var analysisFiles = AnalysisFilesParser.ReadInput(inputFolder); - if (analysisFiles == null || analysisFiles.Count == 0) { + if (analysisFiles == null || analysisFiles.Count == 0) + { Console.WriteLine("There is no input file to be imported."); return -1; } @@ -49,14 +56,19 @@ public int Run(string inputFolder, string outputFolder, string methodFile, bool var mspDB = new List(); if (projectProp.LibraryFilePath != null && projectProp.LibraryFilePath != string.Empty) { - if (!System.IO.File.Exists(projectProp.LibraryFilePath)) { - return fileNoExistError(projectProp.LibraryFilePath); - } else { - mspDB = DatabaseLcUtility.GetMspDbQueries(projectProp.LibraryFilePath, iupacDB); - if (mspDB != null && mspDB.Count >= 0) { + if (!System.IO.File.Exists(projectProp.LibraryFilePath)) + { + return fileNoExistError(projectProp.LibraryFilePath); + } + else + { + mspDB = DatabaseLcUtility.GetMspDbQueries(projectProp.LibraryFilePath, iupacDB); + if (mspDB != null && mspDB.Count >= 0) + { mspDB = mspDB.OrderBy(n => n.PrecursorMz).ToList(); var counter = 0; - foreach (var query in mspDB) { + foreach (var query in mspDB) + { query.Id = counter; counter++; } } @@ -66,35 +78,46 @@ public int Run(string inputFolder, string outputFolder, string methodFile, bool var txtDB = new List(); if (projectProp.PostIdentificationLibraryFilePath != null && projectProp.PostIdentificationLibraryFilePath != string.Empty) { - if (!System.IO.File.Exists(projectProp.PostIdentificationLibraryFilePath)) { - return fileNoExistError(projectProp.PostIdentificationLibraryFilePath); - } else { - txtDB = DatabaseLcUtility.GetTxtDbQueries(projectProp.PostIdentificationLibraryFilePath); - } + if (!System.IO.File.Exists(projectProp.PostIdentificationLibraryFilePath)) + { + return fileNoExistError(projectProp.PostIdentificationLibraryFilePath); + } + else + { + txtDB = DatabaseLcUtility.GetTxtDbQueries(projectProp.PostIdentificationLibraryFilePath); + } } var error = string.Empty; - if (projectProp.CompoundListInTargetModePath != null && projectProp.CompoundListInTargetModePath != string.Empty) { + if (projectProp.CompoundListInTargetModePath != null && projectProp.CompoundListInTargetModePath != string.Empty) + { if (!System.IO.File.Exists(projectProp.CompoundListInTargetModePath)) return fileNoExistError(projectProp.CompoundListInTargetModePath); lcmsParam.CompoundListInTargetMode = TextLibraryParcer.CompoundListInTargetModeReader(projectProp.CompoundListInTargetModePath, out error); - if (error != string.Empty) { + if (error != string.Empty) + { Console.WriteLine(error); } } - if (targetMz > 0) { - if (lcmsParam.CompoundListInTargetMode == null || lcmsParam.CompoundListInTargetMode.Count == 0) { + if (targetMz > 0) + { + if (lcmsParam.CompoundListInTargetMode == null || lcmsParam.CompoundListInTargetMode.Count == 0) + { lcmsParam.CompoundListInTargetMode = new List(); } lcmsParam.CompoundListInTargetMode.Add(new TextFormatCompoundInformationBean() { MetaboliteName = "Target", AccurateMass = targetMz, AccurateMassTolerance = lcmsParam.MassSliceWidth }); } // iSTDs are added to targeted compound list - if (targetMz > 0 || (lcmsParam.CompoundListInTargetMode != null && lcmsParam.CompoundListInTargetMode.Count > 0)) { - if (lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary != null && lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary.Count > 0 && lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary.Count(x => x.IsTarget == true) > 0) { - foreach (var iSTD in lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary) { - if (iSTD.IsTarget) { + if (targetMz > 0 || (lcmsParam.CompoundListInTargetMode != null && lcmsParam.CompoundListInTargetMode.Count > 0)) + { + if (lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary != null && lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary.Count > 0 && lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary.Count(x => x.IsTarget == true) > 0) + { + foreach (var iSTD in lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary) + { + if (iSTD.IsTarget) + { lcmsParam.CompoundListInTargetMode.Add(new TextFormatCompoundInformationBean() { MetaboliteName = iSTD.MetaboliteName, AccurateMass = iSTD.AccurateMass, AccurateMassTolerance = iSTD.AccurateMassTolerance }); } } @@ -103,17 +126,20 @@ public int Run(string inputFolder, string outputFolder, string methodFile, bool Console.WriteLine("Start processing.."); if (lcmsParam.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.ExcuteRtCorrection == true && lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary != null && - lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary.Count > 0 && lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary.Count(x => x.IsTarget == true) > 0) { + lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary.Count > 0 && lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary.Count(x => x.IsTarget == true) > 0) + { Console.WriteLine("Excute RT correction"); - foreach (var analysisFile in analysisFiles) { + foreach (var analysisFile in analysisFiles) + { Console.WriteLine(analysisFile.AnalysisFilePropertyBean.AnalysisFileName); analysisFile.RetentionTimeCorrectionBean = new Rfx.Riken.OsakaUniv.RetentionTimeCorrection.RetentionTimeCorrectionBean(); Msdial.Lcms.Dataprocess.Algorithm.RetentionTimeCorrection.Execute(projectProp, rdamProperty, analysisFile, lcmsParam, lcmsParam.RetentionTimeCorrectionCommon.StandardLibrary, lcmsParam.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam); } } - return Execute(projectProp, rdamProperty, analysisFiles, lcmsParam, mspDB, - txtDB, iupacDB, alignmentFile, outputFolder, isProjectStore); + // get results, wait for all + int result = Execute(projectProp, rdamProperty, analysisFiles, lcmsParam, mspDB, txtDB, iupacDB, alignmentFile, outputFolder, isProjectStore).GetAwaiter().GetResult(); + return result; // return int, expected 0 } private ProjectPropertyBean getFilePropertyDictionaryFromAnalysisFiles(ProjectPropertyBean projectProp, List analysisFiles) @@ -128,47 +154,98 @@ private ProjectPropertyBean getFilePropertyDictionaryFromAnalysisFiles(ProjectPr return projectProp; } - private int Execute(ProjectPropertyBean projectProp, RdamPropertyBean rdamProperty, List analysisFiles, - AnalysisParametersBean lcmsParam, List mspDB, List txtDB, - IupacReferenceBean iupacDB, AlignmentFileBean alignmentFile, string outputfolder, bool isProjectStore) + private async Task Execute(ProjectPropertyBean projectProp, RdamPropertyBean rdamProperty, List analysisFiles, + AnalysisParametersBean lcmsParam, List mspDB, List txtDB, + IupacReferenceBean iupacDB, AlignmentFileBean alignmentFile, string outputfolder, bool isProjectStore) { - foreach (var file in analysisFiles) { - var error = string.Empty; - ProcessFile.Execute(projectProp, rdamProperty, file, lcmsParam, iupacDB, mspDB, txtDB, out error, null); - if (error != string.Empty) { - Console.WriteLine(error); - } - #region//export - var filepath = file.AnalysisFilePropertyBean.AnalysisFilePath; - var rdamID = rdamProperty.RdamFilePath_RdamFileID[filepath]; - var fileID = file.AnalysisFilePropertyBean.AnalysisFileId; - var measurementID = rdamProperty.RdamFileContentBeanCollection[rdamID].FileID_MeasurementID[fileID]; - - Console.WriteLine("Exporting deconvolution results..."); - using (var rawDataAccess = new RawDataAccess(filepath, measurementID, false, false, true, file.RetentionTimeCorrectionBean.PredictedRt)) { - var raw_measurment = DataAccessLcUtility.GetRawDataMeasurement(rawDataAccess); - var spectrumCollection = DataAccessLcUtility.GetAllSpectrumCollection(raw_measurment); - var accumulatedMs1SpecCollection = DataAccessLcUtility.GetAccumulatedMs1SpectrumCollection(raw_measurment); - ResultExportForLC.ExportMs2DecResult(file, outputfolder, accumulatedMs1SpecCollection, spectrumCollection, mspDB, txtDB, lcmsParam, projectProp); + int cumulativeDelay = 100; // wait to start a thread + int askedThreads = lcmsParam.NumThreads; // parameter file variable, user asks to use this number of threads + var numThreads = 1; //for single thread machines + if (askedThreads > 1) + { + var lp = Environment.ProcessorCount; + if (askedThreads > lp + 1) + { + askedThreads = lp; //use max available threads if possible } - #endregion - Console.WriteLine(file.AnalysisFilePropertyBean.AnalysisFilePath + " finished"); + numThreads = askedThreads; + } + Console.WriteLine("Max threads {0}. Looking for {1} threads...", Environment.ProcessorCount, numThreads); + + var semaphore = new SemaphoreSlim(numThreads); // prepare semaphore, asks for a specific number of threads + var tasks = new List(); + var filesToProcess = new List(analysisFiles); // a copy of analysisFiles + var filesToRemove = new ConcurrentBag(); // list of finished files + + foreach (var file in filesToProcess) + { + await semaphore.WaitAsync(); // acquire a semaphore slot + + tasks.Add(Task.Run(async () => + { + try + { + var error = string.Empty; + await Task.Delay(cumulativeDelay); + cumulativeDelay += 10; // add a mini delay to each subsequent file processing, could be probably removed compeltely + var localFile = file; + int threadId = Thread.CurrentThread.ManagedThreadId; + Console.WriteLine($"Processing file {localFile.AnalysisFilePropertyBean.AnalysisFilePath} on Thread ID: {threadId}"); // keep track on threads used + ProcessFile.Execute(projectProp, rdamProperty, localFile, lcmsParam, iupacDB, mspDB, txtDB, out error, null); // standard Execute for MS-DIAL + if (error != string.Empty) + { + Console.WriteLine(error); + } + Console.WriteLine($"Finished processing {file.AnalysisFilePropertyBean.AnalysisFilePath}, consider 1/2 DONE"); + + // Export logic + var filepath = localFile.AnalysisFilePropertyBean.AnalysisFilePath; + var rdamID = rdamProperty.RdamFilePath_RdamFileID[filepath]; + var fileID = localFile.AnalysisFilePropertyBean.AnalysisFileId; + var measurementID = rdamProperty.RdamFileContentBeanCollection[rdamID].FileID_MeasurementID[fileID]; + + Console.WriteLine("Exporting deconvolution results..."); + + using (var rawDataAccess = new RawDataAccess(filepath, measurementID, false, false, true, localFile.RetentionTimeCorrectionBean.PredictedRt)) + { + var raw_measurment = DataAccessLcUtility.GetRawDataMeasurement(rawDataAccess); + var spectrumCollection = DataAccessLcUtility.GetAllSpectrumCollection(raw_measurment); + var accumulatedMs1SpecCollection = DataAccessLcUtility.GetAccumulatedMs1SpectrumCollection(raw_measurment); + ResultExportForLC.ExportMs2DecResult(localFile, outputfolder, accumulatedMs1SpecCollection, spectrumCollection, mspDB, txtDB, lcmsParam, projectProp); + } + + Console.WriteLine($"Finished {file.AnalysisFilePropertyBean.AnalysisFilePath}, consider DONE"); + + filesToRemove.Add(file); + } + finally + { + semaphore.Release(); // release the semaphore slot + } + })); + } + + await Task.WhenAll(tasks); // wait for all finished + + foreach (var fileToRemove in filesToRemove) // cleaning + { + filesToProcess.Remove(fileToRemove); } AlignmentResultBean alignmentResult = null; if (analysisFiles.Count > 1 && lcmsParam.TogetherWithAlignment) { alignmentResult = new AlignmentResultBean(); - ProcessJointAligner.Execute(rdamProperty, projectProp, new ObservableCollection(analysisFiles), + ProcessJointAligner.Execute(rdamProperty, projectProp, new ObservableCollection(analysisFiles), lcmsParam, alignmentResult, null); Console.WriteLine("Joint aligner finished"); - ProcessGapFilling.Execute(projectProp, rdamProperty, new ObservableCollection(analysisFiles), alignmentFile, lcmsParam, + ProcessGapFilling.Execute(projectProp, rdamProperty, new ObservableCollection(analysisFiles), alignmentFile, lcmsParam, iupacDB, alignmentResult, null); Console.WriteLine("Gap filling finished"); - ProcessAlignmentFinalization.Execute(new ObservableCollection(analysisFiles), alignmentFile.SpectraFilePath, + ProcessAlignmentFinalization.Execute(new ObservableCollection(analysisFiles), alignmentFile.SpectraFilePath, alignmentResult, lcmsParam, projectProp, mspDB, null, null); Console.WriteLine("Finalization finished"); @@ -177,12 +254,13 @@ private int Execute(ProjectPropertyBean projectProp, RdamPropertyBean rdamProper ResultExportForLC.ExportAlignmentResult(outputFile, alignmentFile, alignmentResult, mspDB, txtDB, analysisFiles, lcmsParam); } - if (isProjectStore) { + if (isProjectStore) + { Console.WriteLine("Now saving the project to be used in MSDIAL GUI..."); ProjectSave.SaveForLcmsProject(projectProp, rdamProperty, mspDB, iupacDB, lcmsParam, analysisFiles, alignmentFile, alignmentResult, txtDB, new List()); - + ////just for Hiroshi use #region //var matFolder = outputfolder + "\\Mat files"; diff --git a/src/MSDIAL4/MsdialConsoleAppCore/Properties/Resources.Designer.cs b/src/MSDIAL4/MsdialConsoleAppCore/Properties/Resources.Designer.cs index 3441517fd..9c61f6fcf 100644 --- a/src/MSDIAL4/MsdialConsoleAppCore/Properties/Resources.Designer.cs +++ b/src/MSDIAL4/MsdialConsoleAppCore/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace MsdialConsoleAppCore.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -61,7 +61,7 @@ internal Resources() { } /// - /// Looks up a localized string similar to MS-DIAL console ver. 4.70. + /// Looks up a localized string similar to MS-DIAL console ver. 4.92_27012024. /// internal static string VERSION { get { diff --git a/src/MSDIAL4/MsdialConsoleAppCore/Properties/Resources.resx b/src/MSDIAL4/MsdialConsoleAppCore/Properties/Resources.resx index ad53e4af2..69c28f6c4 100644 --- a/src/MSDIAL4/MsdialConsoleAppCore/Properties/Resources.resx +++ b/src/MSDIAL4/MsdialConsoleAppCore/Properties/Resources.resx @@ -118,6 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - MS-DIAL console ver. 4.70 + MS-DIAL console ver. 4.92_27012024 + multi cpu support for lcmsdda \ No newline at end of file From 190bae728ad829a5a32bee7b3f0dd66d234038e7 Mon Sep 17 00:00:00 2001 From: Ondrej Kuda <111736085+ondrej-kuda@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:21:28 +0100 Subject: [PATCH 2/2] updated text parameter export, v4 --- src/MSDIAL4/MsDial/MainWindow.xaml | 2 +- .../MsDial/Utility/DataExportLcUtility.cs | 188 +++++++++-------- .../Parser/ConfigParser.cs | 190 +++++++++++------- 3 files changed, 229 insertions(+), 151 deletions(-) diff --git a/src/MSDIAL4/MsDial/MainWindow.xaml b/src/MSDIAL4/MsDial/MainWindow.xaml index f26413313..429a0fac1 100644 --- a/src/MSDIAL4/MsDial/MainWindow.xaml +++ b/src/MSDIAL4/MsDial/MainWindow.xaml @@ -400,7 +400,7 @@ - + analys sw.WriteLine(param.MsdialVersionNumber); sw.WriteLine(); sw.WriteLine("#Project"); - sw.WriteLine("MS1 Data type\t" + project.DataType); - sw.WriteLine("MS2 Data type\t" + project.DataTypeMS2); - sw.WriteLine("Ion mode\t" + project.IonMode); - sw.WriteLine("Target\t" + project.TargetOmics); - sw.WriteLine("Mode\t" + project.MethodType); + sw.WriteLine("ms1 data type:" + project.DataType); + sw.WriteLine("ms2 Data type:" + project.DataTypeMS2); + sw.WriteLine("ion mode:" + project.IonMode); + sw.WriteLine("target:" + project.TargetOmics); // typo in public enum TargetOmics { Metablomics, Lipidomics } + sw.WriteLine("mode:" + project.MethodType); + sw.WriteLine("#Note - use command line parameter to define the mode for MsdialConsoleApp."); sw.WriteLine(); sw.WriteLine("#Data collection parameters"); - sw.WriteLine("Retention time begin\t" + param.RetentionTimeBegin); - sw.WriteLine("Retention time end\t" + param.RetentionTimeEnd); - sw.WriteLine("Mass range begin\t" + param.MassRangeBegin); - sw.WriteLine("Mass range end\t" + param.MassRangeEnd); - sw.WriteLine("MS2 mass range begin\t" + param.Ms2MassRangeBegin); - sw.WriteLine("MS2 mass range end\t" + param.Ms2MassRangeEnd); + sw.WriteLine("#Mass accuracy"); + sw.WriteLine("ms1 tolerance for centroid:" + param.CentroidMs1Tolerance); + sw.WriteLine("ms2 tolerance for centroid:" + param.CentroidMs2Tolerance); + sw.WriteLine("retention time begin:" + param.RetentionTimeBegin); + sw.WriteLine("retention time end:" + param.RetentionTimeEnd); + sw.WriteLine("mass range begin:" + param.MassRangeBegin); + sw.WriteLine("mass range end:" + param.MassRangeEnd); + sw.WriteLine("ms2 mass range begin:" + param.Ms2MassRangeBegin); + sw.WriteLine("ms2 mass range end:" + param.Ms2MassRangeEnd); sw.WriteLine(); - sw.WriteLine("#Centroid parameters"); - sw.WriteLine("MS1 tolerance\t" + param.CentroidMs1Tolerance); - sw.WriteLine("MS2 tolerance\t" + param.CentroidMs2Tolerance); - //sw.WriteLine("Peak detection-based\t" + param.PeakDetectionBasedCentroid.ToString()); - sw.WriteLine(); sw.WriteLine("#Isotope recognition"); - sw.WriteLine("Maximum charged number\t" + param.MaxChargeNumber); + sw.WriteLine("maximum charged number:" + param.MaxChargeNumber); + // sw.WriteLine("consider cl and br elements:" + param.isBrClConsideredForIsotopes); // inaccessible + sw.WriteLine("#TODO - export RT corrections parameters"); + try + { + sw.WriteLine("excute rt correction:" + param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.ExcuteRtCorrection); // typo in public bool ExcuteRtCorrection { get; set; } = false; + sw.WriteLine("rt correction with smoothing for rt diff:" + param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.doSmoothing); + sw.WriteLine("user setting intercept:" + param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.UserSettingIntercept); + sw.WriteLine("rt diff calc method:" + param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.RtDiffCalcMethod.ToString()); + sw.WriteLine("interpolation method:" + param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.InterpolationMethod.ToString()); + sw.WriteLine("extrapolation method (begin):" + param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.ExtrapolationMethodBegin); + sw.WriteLine("extrapolation method (end):" + param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.ExtrapolationMethodEnd); + sw.WriteLine("istd file:" + param.RetentionTimeCorrectionCommon.StandardLibrary); + } + catch (Exception e) + { + sw.WriteLine("#No RT correction applied."); + } sw.WriteLine(); - - sw.WriteLine("#Data processing"); - sw.WriteLine("Number of threads\t" + param.NumThreads.ToString()); + sw.WriteLine("#Multithreading"); + sw.WriteLine("number of threads:" + param.NumThreads.ToString()); sw.WriteLine(); sw.WriteLine("#Peak detection parameters"); - sw.WriteLine("Smoothing method\t" + param.SmoothingMethod.ToString()); - sw.WriteLine("Smoothing level\t" + param.SmoothingLevel); - sw.WriteLine("Minimum peak width\t" + param.MinimumDatapoints); - sw.WriteLine("Minimum peak height\t" + param.MinimumAmplitude); - sw.WriteLine(); - - sw.WriteLine("#Peak spotting parameters"); - sw.WriteLine("Mass slice width\t" + param.MassSliceWidth); + sw.WriteLine("minimum peak height:" + param.MinimumAmplitude); + sw.WriteLine("mass slice width:" + param.MassSliceWidth); + sw.WriteLine("smoothing method:" + param.SmoothingMethod.ToString()); + sw.WriteLine("smoothing level:" + param.SmoothingLevel); + sw.WriteLine("minimum peak width:" + param.MinimumDatapoints); sw.WriteLine("Exclusion mass list (mass & tolerance)"); - foreach (var mass in param.ExcludedMassList) { sw.WriteLine(mass.ExcludedMass + "\t" + mass.MassTolerance); } + sw.WriteLine("#TODO - test various inclusion lists for later import"); + try + { + foreach (var mass in param.ExcludedMassList) { sw.WriteLine(mass.ExcludedMass + "\t" + mass.MassTolerance); } + } + catch (Exception e) + { + sw.WriteLine("#No excluded ions."); + } sw.WriteLine(); sw.WriteLine("#Deconvolution parameters"); //sw.WriteLine("Peak consideration\t" + param.DeconvolutionType.ToString()); - sw.WriteLine("Sigma window value\t" + param.SigmaWindowValue); - sw.WriteLine("MS2Dec amplitude cut off\t" + param.AmplitudeCutoff); - sw.WriteLine("Exclude after precursor\t" + param.RemoveAfterPrecursor.ToString()); - sw.WriteLine("Keep isotope until\t" + param.KeptIsotopeRange); - sw.WriteLine("Keep original precursor isotopes\t" + param.KeepOriginalPrecursorIsotopes); - + sw.WriteLine("sigma window value:" + param.SigmaWindowValue); + sw.WriteLine("msms abundance cut off:" + param.AmplitudeCutoff); + sw.WriteLine("exclude after precursor ion:" + param.RemoveAfterPrecursor.ToString()); + sw.WriteLine("keep isotope until:" + param.KeptIsotopeRange); + sw.WriteLine("keep original precursor isotopes:" + param.KeepOriginalPrecursorIsotopes); sw.WriteLine(); + sw.WriteLine("#Identification"); sw.WriteLine("#MSP file and MS/MS identification setting"); - sw.WriteLine("MSP file\t" + project.LibraryFilePath); - sw.WriteLine("Retention time tolerance\t" + param.RetentionTimeLibrarySearchTolerance); - sw.WriteLine("Accurate mass tolerance (MS1)\t" + param.Ms1LibrarySearchTolerance); - sw.WriteLine("Accurate mass tolerance (MS2)\t" + param.Ms2LibrarySearchTolerance); - sw.WriteLine("Identification score cut off\t" + param.IdentificationScoreCutOff); - sw.WriteLine("Using retention time for scoring\t" + param.IsUseRetentionInfoForIdentificationScoring); - sw.WriteLine("Using retention time for filtering\t" + param.IsUseRetentionInfoForIdentificationFiltering); + sw.WriteLine("#check the absolute path or use a relative path like ./lib/NIST20.msp in linux"); + sw.WriteLine("msp file:" + project.LibraryFilePath); + sw.WriteLine("retention time tolerance for identification:" + param.RetentionTimeLibrarySearchTolerance); + sw.WriteLine("accurate ms1 tolerance for identification:" + param.Ms1LibrarySearchTolerance); + sw.WriteLine("accurate ms2 tolerance for identification:" + param.Ms2LibrarySearchTolerance); + sw.WriteLine("identification score cut off:" + param.IdentificationScoreCutOff); + sw.WriteLine("use retention information for identification scoring:" + param.IsUseRetentionInfoForIdentificationScoring); + sw.WriteLine("use retention information for identification filtering:" + param.IsUseRetentionInfoForIdentificationFiltering); if (project.TargetOmics == TargetOmics.Lipidomics) { sw.WriteLine(); sw.WriteLine("#Selected lipid types"); + sw.WriteLine("#Note - not used for MsdialConsoleApp."); foreach (var lQuery in param.LipidQueryBean.LbmQueries) { if (lQuery.IsSelected == true && lQuery.IonMode == project.IonMode) @@ -1815,79 +1838,84 @@ public static void ParameterExport(ObservableCollection analys sw.WriteLine(); sw.WriteLine("#Text file and post identification (retention time and accurate mass based) setting"); - sw.WriteLine("Text file\t" + project.PostIdentificationLibraryFilePath); - sw.WriteLine("Retention time tolerance\t" + param.RetentionTimeToleranceOfPostIdentification); - sw.WriteLine("Accurate mass tolerance\t" + param.AccurateMassToleranceOfPostIdentification); - sw.WriteLine("Identification score cut off\t" + param.PostIdentificationScoreCutOff); + sw.WriteLine("#check the absolute path or use a relative path like ./lib/myRTmz.txt"); + sw.WriteLine("text file:" + project.PostIdentificationLibraryFilePath); + sw.WriteLine("retention time tolerance for post identification:" + param.RetentionTimeToleranceOfPostIdentification); + sw.WriteLine("accurate ms1 tolerance for post identification:" + param.AccurateMassToleranceOfPostIdentification); + sw.WriteLine("post identification score cut off:" + param.PostIdentificationScoreCutOff); sw.WriteLine(); - - sw.WriteLine("#Advanced setting for identification"); - sw.WriteLine("Relative abundance cut off\t" + param.RelativeAbundanceCutOff); - sw.WriteLine("Top candidate report\t" + param.OnlyReportTopHitForPostAnnotation); + sw.WriteLine("#Spectrum cut off and report option"); + sw.WriteLine("relative abundance cut off:" + param.RelativeAbundanceCutOff); + sw.WriteLine("top candidate report:" + param.OnlyReportTopHitForPostAnnotation); sw.WriteLine(); sw.WriteLine("#Adduct ion setting"); + sw.WriteLine("#TODO - custom adduct export > import, list separated by colon or new line"); foreach (var adduct in param.AdductIonInformationBeanList) { if (adduct.Included == true) sw.WriteLine(adduct.AdductName); } sw.WriteLine(); sw.WriteLine("#Alignment parameters setting"); + sw.WriteLine("#Note - for MsdialConsoleApp use an index, e.g. 0 for the first file."); if (analysisFiles != null && analysisFiles.Count > 0) - sw.WriteLine("Reference file\t" + analysisFiles[param.AlignmentReferenceFileID].AnalysisFilePropertyBean.AnalysisFilePath); - sw.WriteLine("Retention time tolerance\t" + param.RetentionTimeAlignmentTolerance); - sw.WriteLine("MS1 tolerance\t" + param.Ms1AlignmentTolerance); - sw.WriteLine("Retention time factor\t" + param.RetentionTimeAlignmentFactor); - sw.WriteLine("MS1 factor\t" + param.Ms1AlignmentFactor); - sw.WriteLine("Peak count filter\t" + param.PeakCountFilter); - sw.WriteLine("N% detected in at least one group\t" + param.NPercentDetectedInOneGroup); + { + sw.WriteLine("reference file:" + analysisFiles[param.AlignmentReferenceFileID].AnalysisFilePropertyBean.AnalysisFilePath); + sw.WriteLine("alignment reference file id: " + analysisFiles.IndexOf(analysisFiles[param.AlignmentReferenceFileID])); + } + sw.WriteLine("retention time tolerance for alignment:" + param.RetentionTimeAlignmentTolerance); + sw.WriteLine("ms1 tolerance for alignment:" + param.Ms1AlignmentTolerance); + sw.WriteLine("retention time factor for alignment:" + param.RetentionTimeAlignmentFactor); + sw.WriteLine("ms1 factor for alignment:" + param.Ms1AlignmentFactor); + sw.WriteLine("peak count filter:" + param.PeakCountFilter); + sw.WriteLine("n% detected in at least one group:" + param.NPercentDetectedInOneGroup); //sw.WriteLine("QC at least filter\t" + param.QcAtLeastFilter.ToString()); - sw.WriteLine("Remove feature based on peak height fold-change\t" + param.IsRemoveFeatureBasedOnPeakHeightFoldChange); - sw.WriteLine("Sample max / blank average\t" + param.SampleMaxOverBlankAverage); - sw.WriteLine("Sample average / blank average\t" + param.SampleAverageOverBlankAverage); - sw.WriteLine("Keep identified and annotated metabolites\t" + param.IsKeepIdentifiedMetaboliteFeatures); - sw.WriteLine("Keep removable features and assign the tag for checking\t" + param.IsKeepRemovableFeaturesAndAssignedTagForChecking); + sw.WriteLine("remove feature based on peak height fold-change:" + param.IsRemoveFeatureBasedOnPeakHeightFoldChange); + sw.WriteLine("sample max / blank average:" + param.SampleMaxOverBlankAverage); + sw.WriteLine("sample average / blank average:" + param.SampleAverageOverBlankAverage); + sw.WriteLine("keep identified and annotated metabolites:" + param.IsKeepIdentifiedMetaboliteFeatures); + sw.WriteLine("keep removable features and assign the tag for checking:" + param.IsKeepRemovableFeaturesAndAssignedTagForChecking); //sw.WriteLine("Replace true zero values with 1/2 of minimum peak height over all samples\t" + param.IsReplaceTrueZeroValuesWithHalfOfMinimumPeakHeightOverAllSamples); - sw.WriteLine("Gap filling by compulsion\t" + param.IsForceInsertForGapFilling); - + sw.WriteLine("gap filling by compulsion:" + param.IsForceInsertForGapFilling); sw.WriteLine(); sw.WriteLine("#Tracking of isotope labels"); if (param.TrackingIsotopeLabels) { - sw.WriteLine("Tracking of isotopic labels\tTRUE"); - sw.WriteLine("Labeled element\t" + param.IsotopeTrackingDictionary.IsotopeElements[param.IsotopeTrackingDictionary.SelectedID].ElementName); + sw.WriteLine("tracking of isotopic labels:TRUE"); + sw.WriteLine("labeled element:" + param.IsotopeTrackingDictionary.IsotopeElements[param.IsotopeTrackingDictionary.SelectedID].ElementName); + sw.WriteLine("#Note - elements could be also assigned by index, e.g. 13C is 0"); if (analysisFiles != null && analysisFiles.Count > 0) - sw.WriteLine("Non labeled reference file\t" + analysisFiles[param.NonLabeledReferenceID].AnalysisFilePropertyBean.AnalysisFilePath); + sw.WriteLine("non labeled reference file:" + analysisFiles[param.NonLabeledReferenceID].AnalysisFilePropertyBean.AnalysisFilePath); else - sw.WriteLine("Non labeled reference file\tNot found"); + sw.WriteLine("non labeled reference file:Not found"); if (param.UseTargetFormulaLibrary) { - sw.WriteLine("Use target formula library\t" + param.UseTargetFormulaLibrary); + sw.WriteLine("use target formula library:" + param.UseTargetFormulaLibrary); if (analysisFiles != null && analysisFiles.Count > 0) - sw.WriteLine("Target formula library file path\t" + project.TargetFormulaLibraryFilePath); + sw.WriteLine("target compound file:" + project.TargetFormulaLibraryFilePath); else - sw.WriteLine("Fully labeled reference file\tNot found"); + sw.WriteLine("Fully labeled reference file:Not found"); } } else { - sw.WriteLine("Tracking of isotopic labels\tFALSE"); + sw.WriteLine("tracking of isotopic labels:FALSE"); } sw.WriteLine(); sw.WriteLine("#Ion mobility"); if (param.IsIonMobility) { - sw.WriteLine("Mobility type\t" + param.IonMobilityType); - sw.WriteLine("Accumulated RT ragne\t" + param.AccumulatedRtRagne); - sw.WriteLine("CCS search Tolerance\t" + param.CcsSearchTolerance); - sw.WriteLine("Use CCS for identification scoring\t" + param.IsUseCcsForIdentificationScoring); - sw.WriteLine("Use CCS for identification filtering\t" + param.IsUseCcsForIdentificationFiltering); - sw.WriteLine("Mobility axis alignment tolerance\t" + param.DriftTimeAlignmentTolerance); + sw.WriteLine("mobility type:" + param.IonMobilityType); + sw.WriteLine("accumulated rt ragne:" + param.AccumulatedRtRagne); // typo in AnalysisParametersBean ragne > range + sw.WriteLine("Cccs search tolerance:" + param.CcsSearchTolerance); + sw.WriteLine("use ccs for identification scoring:" + param.IsUseCcsForIdentificationScoring); + sw.WriteLine("use ccs for identification filtering:" + param.IsUseCcsForIdentificationFiltering); + sw.WriteLine("mobility axis alignment tolerance:" + param.DriftTimeAlignmentTolerance); } else { - sw.WriteLine("Ion mobility data\tFALSE"); + sw.WriteLine("ion mobility data:FALSE"); } } } diff --git a/src/MSDIAL4/MsdialConsoleAppCore/Parser/ConfigParser.cs b/src/MSDIAL4/MsdialConsoleAppCore/Parser/ConfigParser.cs index db9497026..afb2f097c 100644 --- a/src/MSDIAL4/MsdialConsoleAppCore/Parser/ConfigParser.cs +++ b/src/MSDIAL4/MsdialConsoleAppCore/Parser/ConfigParser.cs @@ -53,21 +53,21 @@ private static void gcmsParamUpdate(AnalysisParamOfMsdialGcms param, string meth switch (method) { //Data type - case "data type": - if (value == "Centroid" || value == "Profile") - param.DataType = (DataType)Enum.Parse(typeof(DataType), value, true); - return; - - case "ion mode": - if (value == "Positive" || value == "Negative") - param.IonMode = (IonMode)Enum.Parse(typeof(IonMode), value, true); - return; - - case "accuracy type": - if (value == "IsNominal" || value == "IsAccurate") - param.AccuracyType = (AccuracyType)Enum.Parse(typeof(AccuracyType), value, true); - return; - + case "data type": + if (value == "Centroid" || value == "Profile") + param.DataType = (DataType)Enum.Parse(typeof(DataType), value, true); + return; + + case "ion mode": + if (value == "Positive" || value == "Negative") + param.IonMode = (IonMode)Enum.Parse(typeof(IonMode), value, true); + return; + + case "accuracy type": + if (value == "IsNominal" || value == "IsAccurate") + param.AccuracyType = (AccuracyType)Enum.Parse(typeof(AccuracyType), value, true); + return; + //Data correction case "retention time begin": if (float.TryParse(value, out f)) param.RetentionTimeBegin = f; return; case "retention time end": if (float.TryParse(value, out f)) param.RetentionTimeEnd = f; return; @@ -75,10 +75,10 @@ private static void gcmsParamUpdate(AnalysisParamOfMsdialGcms param, string meth case "mass range end": if (float.TryParse(value, out f)) param.MassRangeEnd = f; return; //Peak detection param - case "smoothing method": + case "smoothing method": if (value == "SimpleMovingAverage" || value == "LinearWeightedMovingAverage" || value == "SavitzkyGolayFilter" || value == "BinomialFilter") - param.SmoothingMethod = (SmoothingMethod)Enum.Parse(typeof(SmoothingMethod), value, true); - return; + param.SmoothingMethod = (SmoothingMethod)Enum.Parse(typeof(SmoothingMethod), value, true); + return; case "smoothing level": if (int.TryParse(value, out i)) param.SmoothingLevel = i; return; case "average peak width": if (int.TryParse(value, out i)) param.AveragePeakWidth = i; return; case "minimum peak height": if (int.TryParse(value, out i)) param.MinimumAmplitude = i; return; @@ -92,14 +92,14 @@ private static void gcmsParamUpdate(AnalysisParamOfMsdialGcms param, string meth //Identification case "msp file": param.MspFilePath = value; return; case "ri index file pathes": param.RiDictionaryFilePath = value; return; - case "retention type": - if (value == "RT" || value == "RI") - param.RetentionType = (RetentionType)Enum.Parse(typeof(RetentionType), value, true); - return; - case "ri compound": - if (value == "Fames" || value == "Alkanes") - param.RiCompoundType = (RiCompoundType)Enum.Parse(typeof(RiCompoundType), value, true); - return; + case "retention type": + if (value == "RT" || value == "RI") + param.RetentionType = (RetentionType)Enum.Parse(typeof(RetentionType), value, true); + return; + case "ri compound": + if (value == "Fames" || value == "Alkanes") + param.RiCompoundType = (RiCompoundType)Enum.Parse(typeof(RiCompoundType), value, true); + return; case "retention time tolerance for identification": if (float.TryParse(value, out f)) param.RetentionTimeLibrarySearchTolerance = f; return; case "retention index tolerance for identification": if (float.TryParse(value, out f)) param.RetentionIndexLibrarySearchTolerance = f; return; @@ -134,7 +134,7 @@ private static void gcmsParamUpdate(AnalysisParamOfMsdialGcms param, string meth #region // to get analysisparam for msdial lcms public static AnalysisParametersBean ReadForLcmsParameter(string filepath) { - var param = new AnalysisParametersBean() { MsdialVersionNumber = Resources.VERSION }; + var param = new AnalysisParametersBean() { MsdialVersionNumber = Resources.VERSION }; using (var sr = new StreamReader(filepath, Encoding.ASCII)) { while (sr.Peek() > -1) @@ -176,15 +176,18 @@ private static void lcmsParamUpdate(AnalysisParametersBean param, string method, //Isotope case "maximum charged number": if (int.TryParse(value, out i)) param.MaxChargeNumber = i; return; + //case "consider cl and br elements": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.isBrClConsideredForIsotopes = bool.Parse(value); return; + // inaccessible due to protection // max number of CPU threads case "number of threads": if (int.TryParse(value, out i)) param.NumThreads = i; Console.WriteLine("Asked for {0} threads", i); return; //Retentiontime correction - case "excute rt correction": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.ExcuteRtCorrection = bool.Parse(value); return; + case "excute rt correction": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.ExcuteRtCorrection = bool.Parse(value); return; // typo in public bool ExcuteRtCorrection { get; set; } = false; case "rt correction with smoothing for rt diff": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.doSmoothing = bool.Parse(value); return; case "user setting intercept": if (float.TryParse(value, out f)) param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.UserSettingIntercept = f; return; - case "rt diff calc method": if (value == "SampleMinusSampleAverage" || value == "SampleMinusReference") + case "rt diff calc method": + if (value == "SampleMinusSampleAverage" || value == "SampleMinusReference") param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.RtDiffCalcMethod = (Rfx.Riken.OsakaUniv.RetentionTimeCorrection.RtDiffCalcMethod)Enum.Parse(typeof(Rfx.Riken.OsakaUniv.RetentionTimeCorrection.RtDiffCalcMethod), value, true); return; case "interpolation method": @@ -200,10 +203,12 @@ private static void lcmsParamUpdate(AnalysisParametersBean param, string method, param.RetentionTimeCorrectionCommon.RetentionTimeCorrectionParam.ExtrapolationMethodEnd = (Rfx.Riken.OsakaUniv.RetentionTimeCorrection.ExtrapolationMethodEnd)Enum.Parse(typeof(Rfx.Riken.OsakaUniv.RetentionTimeCorrection.ExtrapolationMethodEnd), value, true); return; case "istd file": - if (System.IO.File.Exists(value)) { + if (System.IO.File.Exists(value)) + { var error = string.Empty; param.RetentionTimeCorrectionCommon.StandardLibrary = TextLibraryParcer.StandardTextLibraryReader(value, out error); - if (error != string.Empty) { + if (error != string.Empty) + { Console.WriteLine(error); } } @@ -221,8 +226,8 @@ private static void lcmsParamUpdate(AnalysisParametersBean param, string method, //Deconvolution case "sigma window value": if (float.TryParse(value, out f)) param.SigmaWindowValue = f; return; - case "amplitude cut off": if (float.TryParse(value, out f)) param.AmplitudeCutoff = f; return; - case "exclude after precursor": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.RemoveAfterPrecursor = bool.Parse(value); return; + case "msms abundance cut off": if (float.TryParse(value, out f)) param.AmplitudeCutoff = f; return; + case "exclude after precursor ion": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.RemoveAfterPrecursor = bool.Parse(value); return; case "keep isotope until": if (float.TryParse(value, out f)) param.KeptIsotopeRange = f; return; case "keep original precursor isotopes": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.KeepOriginalPrecursorIsotopes = bool.Parse(value); return; @@ -238,6 +243,8 @@ private static void lcmsParamUpdate(AnalysisParametersBean param, string method, case "retention time tolerance for post identification": if (float.TryParse(value, out f)) param.RetentionTimeToleranceOfPostIdentification = f; return; case "accurate ms1 tolerance for post identification": if (float.TryParse(value, out f)) param.AccurateMassToleranceOfPostIdentification = f; return; case "post identification score cut off": if (float.TryParse(value, out f)) param.PostIdentificationScoreCutOff = f; return; + case "relative abundance cut off": if (float.TryParse(value, out f)) param.RelativeAbundanceCutOff = f; return; + case "top candidate report": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.OnlyReportTopHitForPostAnnotation = bool.Parse(value); return; //Alignment parameters setting case "retention time tolerance for alignment": if (float.TryParse(value, out f)) param.RetentionTimeAlignmentTolerance = f; return; @@ -265,12 +272,14 @@ private static void lcmsParamUpdate(AnalysisParametersBean param, string method, //CorrDec settings case "corrdec excute": - if (value.ToUpper() == "FALSE") { + if (value.ToUpper() == "FALSE") + { if (param.AnalysisParamOfMsdialCorrDec == null) param.AnalysisParamOfMsdialCorrDec = new AnalysisParamOfMsdialCorrDec(); param.AnalysisParamOfMsdialCorrDec.CanExcute = false; } - return; - case "corrdec ms2 tolerance": if (param.AnalysisParamOfMsdialCorrDec == null) param.AnalysisParamOfMsdialCorrDec = new AnalysisParamOfMsdialCorrDec(); + return; + case "corrdec ms2 tolerance": + if (param.AnalysisParamOfMsdialCorrDec == null) param.AnalysisParamOfMsdialCorrDec = new AnalysisParamOfMsdialCorrDec(); if (float.TryParse(value, out f)) param.AnalysisParamOfMsdialCorrDec.MS2Tolerance = f; return; case "corrdec minimum ms2 peak height": if (param.AnalysisParamOfMsdialCorrDec == null) param.AnalysisParamOfMsdialCorrDec = new AnalysisParamOfMsdialCorrDec(); @@ -300,8 +309,9 @@ private static void lcmsParamUpdate(AnalysisParametersBean param, string method, if (param.AnalysisParamOfMsdialCorrDec == null) param.AnalysisParamOfMsdialCorrDec = new AnalysisParamOfMsdialCorrDec(); if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.AnalysisParamOfMsdialCorrDec.RemoveAfterPrecursor = bool.Parse(value); return; - // ion mobility setting - case "accumulated rt ragne": if (float.TryParse(value, out f)) param.AccumulatedRtRagne = f; return; + // ion mobility setting, not tested + case "mobility type": if (float.TryParse(value, out f)) param.IonMobilityType = (IonMobilityType)f; return; // { Tims, Dtims, Twims, CCS } + case "accumulated rt ragne": if (float.TryParse(value, out f)) param.AccumulatedRtRagne = f; return; //typo ragne > range case "ccs search tolerance": if (float.TryParse(value, out f)) param.CcsSearchTolerance = f; return; case "mobility axis alignment tolerance": if (float.TryParse(value, out f)) param.DriftTimeAlignmentTolerance = f; return; case "use ccs for identification scoring": if (value.ToUpper() == "TRUE" || value.ToUpper() == "FALSE") param.IsUseCcsForIdentificationScoring = bool.Parse(value); return; @@ -312,8 +322,10 @@ private static void lcmsParamUpdate(AnalysisParametersBean param, string method, public static void ReadAdductIonInfo(List adductList, string filepath) { - using (var sr = new StreamReader(filepath, Encoding.ASCII)) { - while (sr.Peek() > -1) { + using (var sr = new StreamReader(filepath, Encoding.ASCII)) + { + while (sr.Peek() > -1) + { var line = sr.ReadLine(); if (line == string.Empty) continue; if (line.Length < 2) continue; @@ -325,11 +337,15 @@ public static void ReadAdductIonInfo(List adductList, var method = lineArray[0].Trim().ToLower(); var value = line.Substring(line.Split(':')[0].Length + 1).Trim(); - if (method == "adduct list") { + if (method == "adduct list") + { var adductStrings = value.Split(',').ToList(); - foreach (var adduct in adductList) { - foreach (var adductString in adductStrings) { - if (adduct.AdductName == adductString) { + foreach (var adduct in adductList) + { + foreach (var adductString in adductStrings) + { + if (adduct.AdductName == adductString) + { adduct.Included = true; } } @@ -339,7 +355,8 @@ public static void ReadAdductIonInfo(List adductList, } } - public static int FindAlignmentReferenceFileByName(String filepath, List files) { + public static int FindAlignmentReferenceFileByName(String filepath, List files) + { using (var sr = new StreamReader(filepath, Encoding.ASCII)) { @@ -357,9 +374,12 @@ public static int FindAlignmentReferenceFileByName(String filepath, List files, AnalysisParamOfMsdialGcms param) { + public static void SetGCMSAlignmentReferenceFileByFilename(String filepath, List files, AnalysisParamOfMsdialGcms param) + { param.AlignmentReferenceFileID = FindAlignmentReferenceFileByName(filepath, files); } - public static void SetLCMSAlignmentReferenceFileByFilename(String filepath, List files, AnalysisParametersBean param) { + public static void SetLCMSAlignmentReferenceFileByFilename(String filepath, List files, AnalysisParametersBean param) + { param.AlignmentReferenceFileID = FindAlignmentReferenceFileByName(filepath, files); } #endregion @@ -388,8 +410,11 @@ public static ProjectPropertyBean ReadForLcmsProjectProperty(string filepath, st { var dt = DateTime.Now; var projectFile = "Project-" + dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString(); - var projectProp = new ProjectPropertyBean() { - ProjectDate = dt, ProjectFolderPath = inputFolder, ProjectFilePath = Path.Combine(inputFolder, projectFile + ".mtd") + var projectProp = new ProjectPropertyBean() + { + ProjectDate = dt, + ProjectFolderPath = inputFolder, + ProjectFilePath = Path.Combine(inputFolder, projectFile + ".mtd") }; using (var sr = new StreamReader(filepath, Encoding.ASCII)) @@ -416,7 +441,8 @@ public static ProjectPropertyBean ReadForLcmsProjectProperty(string filepath, st private static void projectPropertyUpdate(ProjectPropertyBean projectProp, string method, string value) { - switch (method) { + switch (method) + { //Data type case "ms1 data type": if (value == "Centroid" || value == "Profile") @@ -442,7 +468,7 @@ private static void projectPropertyUpdate(ProjectPropertyBean projectProp, strin // Private version case "is private version of Tada": if (value.ToUpper() == "TRUE") - projectProp.IsLabPrivateVersionTada = true; + projectProp.IsLabPrivateVersionTada = true; return; } } @@ -450,48 +476,72 @@ private static void projectPropertyUpdate(ProjectPropertyBean projectProp, strin #region to obtain ccs calibration data - public static void SetCalibrateInformation(AnalysisParametersBean param, List files) { + public static void SetCalibrateInformation(AnalysisParametersBean param, List files) + { if (param.FileidToCcsCalibrantData != null && param.FileidToCcsCalibrantData.Count > 0) return; param.FileidToCcsCalibrantData = new Dictionary(); var isAllCalibrantImported = true; - foreach (var file in files) { + foreach (var file in files) + { var ibfpath = file.AnalysisFilePropertyBean.AnalysisFilePath; - using (var access = new RawDataAccess(ibfpath, 0, false, false, true)) { + using (var access = new RawDataAccess(ibfpath, 0, false, false, true)) + { var calinfo = access.ReadIonmobilityCalibrationInfo(); var fileid = file.AnalysisFilePropertyBean.AnalysisFileId; CoefficientsForCcsCalculation ccsCalinfo; - if (calinfo == null) { - ccsCalinfo = new CoefficientsForCcsCalculation() { - IsAgilentIM = false, AgilentBeta = -1, AgilentTFix = -1, - IsBrukerIM = false, IsWatersIM = false, WatersCoefficient = -1, WatersExponent = -1, WatersT0 = -1 + if (calinfo == null) + { + ccsCalinfo = new CoefficientsForCcsCalculation() + { + IsAgilentIM = false, + AgilentBeta = -1, + AgilentTFix = -1, + IsBrukerIM = false, + IsWatersIM = false, + WatersCoefficient = -1, + WatersExponent = -1, + WatersT0 = -1 }; } - else { - ccsCalinfo = new CoefficientsForCcsCalculation() { - IsAgilentIM = calinfo.IsAgilentIM, AgilentBeta = calinfo.AgilentBeta, AgilentTFix = calinfo.AgilentTFix, - IsBrukerIM = calinfo.IsBrukerIM, IsWatersIM = calinfo.IsWatersIM, WatersCoefficient = calinfo.WatersCoefficient, WatersExponent = calinfo.WatersExponent, WatersT0 = calinfo.WatersT0 + else + { + ccsCalinfo = new CoefficientsForCcsCalculation() + { + IsAgilentIM = calinfo.IsAgilentIM, + AgilentBeta = calinfo.AgilentBeta, + AgilentTFix = calinfo.AgilentTFix, + IsBrukerIM = calinfo.IsBrukerIM, + IsWatersIM = calinfo.IsWatersIM, + WatersCoefficient = calinfo.WatersCoefficient, + WatersExponent = calinfo.WatersExponent, + WatersT0 = calinfo.WatersT0 }; - if (calinfo.IsAgilentIM) { + if (calinfo.IsAgilentIM) + { param.IonMobilityType = IonMobilityType.Dtims; } - else if (calinfo.IsWatersIM) { + else if (calinfo.IsWatersIM) + { param.IonMobilityType = IonMobilityType.Twims; } - else { + else + { param.IonMobilityType = IonMobilityType.Tims; } } param.FileidToCcsCalibrantData[fileid] = ccsCalinfo; if (ccsCalinfo.AgilentBeta == -1 && ccsCalinfo.AgilentTFix == -1 && - ccsCalinfo.WatersCoefficient == -1 && ccsCalinfo.WatersExponent == -1 && ccsCalinfo.WatersT0 == -1) { + ccsCalinfo.WatersCoefficient == -1 && ccsCalinfo.WatersExponent == -1 && ccsCalinfo.WatersT0 == -1) + { isAllCalibrantImported = false; } } } param.IsAllCalibrantDataImported = isAllCalibrantImported; - if (!isAllCalibrantImported) { + if (!isAllCalibrantImported) + { var errorMessage = param.IonMobilityType == IonMobilityType.Dtims ? "For Agilent single fieled-based CCS calculation, you have to set the coefficients for all files. " : "For Waters CCS calculation, you have to set the coefficients for all files. ";