public ChromatogramSet(string name, IEnumerable <MsDataFileUri> msDataFileNames, Annotations annotations, OptimizableRegression optimizationFunction) : base(new ChromatogramSetId(), name) { MSDataFileInfos = msDataFileNames.ToList().ConvertAll(path => new ChromFileInfo(path)); OptimizationFunction = optimizationFunction; Annotations = annotations; SampleType = SampleType.DEFAULT; }
public IonAbundances(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo, float mzMatchTolerance, int peakIndex, OptimizableRegression regression) : this() { foreach (var nodeTran in nodeTranGroup.Transitions) { var chromInfoCached = chromGroupInfo.GetTransitionInfo(nodeTran, mzMatchTolerance, regression); if (chromInfoCached == null) { continue; } Add(nodeTran, chromInfoCached.GetPeak(peakIndex).Area); } }
public PeakMatchData(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo, float mzMatchTolerance, int peakIndex, double totalChromArea, OptimizableRegression regression) { Abundances = new IonAbundances(nodeTranGroup, chromGroupInfo, mzMatchTolerance, peakIndex, regression); PercentArea = Abundances.Sum() / totalChromArea; var peak = GetLargestPeak(nodeTranGroup, chromGroupInfo, peakIndex, mzMatchTolerance, regression); RetentionTime = peak.RetentionTime; StartTime = peak.StartTime; EndTime = peak.EndTime; ShiftLeft = 0; ShiftRight = 0; MinTime = chromGroupInfo.TimeIntensitiesGroup.MinTime; MaxTime = chromGroupInfo.TimeIntensitiesGroup.MaxTime; }
private static ChromPeak GetLargestPeak(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo, int peakIndex, float mzMatchTolerance, OptimizableRegression regression) { var largestPeak = ChromPeak.EMPTY; foreach (var peak in from transitionDocNode in nodeTranGroup.Transitions select chromGroupInfo.GetTransitionInfo(transitionDocNode, mzMatchTolerance, regression) into chromInfo where chromInfo != null select chromInfo.GetPeak(peakIndex)) { if (peak.Height > largestPeak.Height) { largestPeak = peak; } } return(largestPeak); }
public bool ImportResultsInDir(string sourceDir, Regex namingPattern, LockMassParameters lockMassParameters, DateTime? importBefore, DateTime? importOnOrAfter, OptimizableRegression optimize, bool disableJoining) { var listNamedPaths = GetDataSources(sourceDir, namingPattern); if (listNamedPaths == null) { return false; } bool hasMultiple = listNamedPaths.SelectMany(pair => pair.Key).Count() > 1; if (hasMultiple || disableJoining) { // Join at the end _doc = _doc.ChangeSettingsNoDiff(_doc.Settings.ChangeIsResultsJoiningDisabled(true)); } // Import files one at a time foreach (var namedPaths in listNamedPaths) { string replicateName = namedPaths.Key; var files = namedPaths.Value; foreach (var file in files) { if (!ImportResultsFile(file.ChangeParameters(_doc, lockMassParameters), replicateName, importBefore, importOnOrAfter, optimize)) return false; } } if (hasMultiple && !disableJoining) { // Allow joining to happen var progressMonitor = new CommandProgressMonitor(_out, new ProgressStatus(string.Empty)); using (var docContainer = new ResultsMemoryDocumentContainer(null, _skylineFile) { ProgressMonitor = progressMonitor }) { _doc = _doc.ChangeSettingsNoDiff(_doc.Settings.ChangeIsResultsJoiningDisabled(false)); if (!_doc.IsLoaded) { docContainer.SetDocument(_doc, null, true); _doc = docContainer.Document; // If not fully loaded now, there must have been an error. if (!_doc.IsLoaded) return false; } } } return true; }
public bool ImportResultsFile(MsDataFileUri replicateFile, string replicateName, DateTime? importBefore, DateTime? importOnOrAfter, OptimizableRegression optimize, bool disableJoining = false) { // Skip if file write time is after importBefore or before importAfter try { var fileLastWriteTime = replicateFile.GetFileLastWriteTime(); if (importBefore != null && importBefore < fileLastWriteTime) { _out.WriteLine(Resources.CommandLine_ImportResultsFile_File_write_date__0__is_after___import_before_date__1___Ignoring___, fileLastWriteTime, importBefore); return true; } else if (importOnOrAfter != null && importOnOrAfter >= fileLastWriteTime) { _out.WriteLine(Resources.CommandLine_ImportResultsFile_File_write_date__0__is_before___import_on_or_after_date__1___Ignoring___, fileLastWriteTime, importOnOrAfter); return true; } } catch (Exception e) { _out.WriteLine(Resources.CommandLine_ImportResultsInDir_Error__Could_not_get_last_write_time_for_file__0__, replicateFile); _out.WriteLine(e); return false; } _out.WriteLine(Resources.CommandLine_ImportResultsFile_Adding_results___); // Hack for un-readable RAW files from Thermo instruments. if(!CanReadFile(replicateFile)) { _out.WriteLine(Resources.CommandLine_ImportResultsFile_Warning__Cannot_read_file__0____Ignoring___, replicateFile); return true; } //This function will also detect whether the replicate exists in the document ProgressStatus status; SrmDocument newDoc; IProgressMonitor progressMonitor = new CommandProgressMonitor(_out, new ProgressStatus(string.Empty)); try { if (disableJoining) _doc = _doc.ChangeSettingsNoDiff(_doc.Settings.ChangeIsResultsJoiningDisabled(true)); newDoc = ImportResults(_doc,_skylineFile, replicateName, replicateFile, optimize, progressMonitor, out status); } catch (Exception x) { _out.WriteLine(Resources.CommandLine_ImportResultsFile_Error__Failed_importing_the_results_file__0__, replicateFile); _out.WriteLine(x.Message); return false; } status = status ?? new ProgressStatus(string.Empty).Complete(); if (status.IsError && status.ErrorException != null) { if (status.ErrorException is MissingDataException) { _out.WriteLine(Resources.CommandLine_ImportResultsFile_Warning__Failed_importing_the_results_file__0____Ignoring___, replicateFile); _out.WriteLine(status.ErrorException.Message); return true; } _out.WriteLine(Resources.CommandLine_ImportResultsFile_Error__Failed_importing_the_results_file__0__, replicateFile); _out.WriteLine(status.ErrorException.Message); return false; } if (!status.IsComplete || ReferenceEquals(_doc, newDoc)) { _out.WriteLine(Resources.CommandLine_ImportResultsFile_Error__Failed_importing_the_results_file__0__, replicateFile); return false; } _doc = newDoc; _out.WriteLine(Resources.CommandLine_ImportResultsFile_Results_added_from__0__to_replicate__1__, replicateFile.GetFileName(), replicateName); //the file was imported successfully _importCount++; return true; }
public bool ImportResultsFile(MsDataFileUri replicateFile, string replicateName, DateTime? importBefore, DateTime? importOnOrAfter, OptimizableRegression optimize, bool append, bool disableJoining) { if (string.IsNullOrEmpty(replicateName)) replicateName = replicateFile.GetFileNameWithoutExtension(); if(_doc.Settings.HasResults && _doc.Settings.MeasuredResults.ContainsChromatogram(replicateName)) { if (!append) { // CONSIDER: Error? Check if the replicate contains the file? // It does not seem right to just continue on to export a report // or new method without the results added. _out.WriteLine(Resources.CommandLine_ImportResultsFile_Warning__The_replicate__0__already_exists_in_the_given_document_and_the___import_append_option_is_not_specified___The_replicate_will_not_be_added_to_the_document_, replicateName); return true; } // If we are appending to an existing replicate in the document // make sure this file is not already in the replicate. ChromatogramSet chromatogram; int index; _doc.Settings.MeasuredResults.TryGetChromatogramSet(replicateName, out chromatogram, out index); string replicateFileString = replicateFile.ToString(); if (chromatogram.MSDataFilePaths.Any(filePath=>StringComparer.OrdinalIgnoreCase.Equals(filePath, replicateFileString))) { _out.WriteLine(Resources.CommandLine_ImportResultsFile__0______1___Note__The_file_has_already_been_imported__Ignoring___, replicateName, replicateFile); return true; } } return ImportResultsFile(replicateFile, replicateName, importBefore, importOnOrAfter, optimize, disableJoining); }
/// <summary> /// This function will add the given replicate, from dataFile, to the given document. If the replicate /// does not exist, it will be added. If it does exist, it will be appended to. /// </summary> public static SrmDocument ImportResults(SrmDocument doc, string docPath, string replicate, MsDataFileUri dataFile, OptimizableRegression optimize, IProgressMonitor progressMonitor, out ProgressStatus status) { using (var docContainer = new ResultsMemoryDocumentContainer(null, docPath) {ProgressMonitor = progressMonitor}) { // Make sure library loading happens, which may not happen, if the doc // parameter is used as the baseline document. docContainer.SetDocument(doc, null); SrmDocument docAdded; do { doc = docContainer.Document; var listChromatograms = new List<ChromatogramSet>(); if (doc.Settings.HasResults) listChromatograms.AddRange(doc.Settings.MeasuredResults.Chromatograms); int indexChrom = listChromatograms.IndexOf(chrom => chrom.Name.Equals(replicate)); if (indexChrom != -1) { var chromatogram = listChromatograms[indexChrom]; var paths = chromatogram.MSDataFilePaths; var listFilePaths = paths.ToList(); listFilePaths.Add(dataFile); listChromatograms[indexChrom] = chromatogram.ChangeMSDataFilePaths(listFilePaths); } else { listChromatograms.Add(new ChromatogramSet(replicate, new[] {dataFile.Normalize()}, Annotations.EMPTY, optimize)); } var results = doc.Settings.HasResults ? doc.Settings.MeasuredResults.ChangeChromatograms(listChromatograms) : new MeasuredResults(listChromatograms, doc.Settings.IsResultsJoiningDisabled); docAdded = doc.ChangeMeasuredResults(results); } while (!docContainer.SetDocument(docAdded, doc, true)); status = docContainer.LastProgress; return docContainer.Document; } }
public ChromatogramSet ChangeOptimizationFunction(OptimizableRegression prop) { return ChangeProp(ImClone(this), im => im.OptimizationFunction = prop); }
public ChromatogramSet(string name, IEnumerable<MsDataFileUri> msDataFileNames, Annotations annotations, OptimizableRegression optimizationFunction) : base(new ChromatogramSetId(), name) { MSDataFileInfos = msDataFileNames.ToList().ConvertAll(path => new ChromFileInfo(path)); OptimizationFunction = optimizationFunction; Annotations = annotations; SampleType = SampleType.DEFAULT; }
public ChromatogramSet ChangeOptimizationFunction(OptimizableRegression prop) { return(ChangeProp(ImClone(this), im => im.OptimizationFunction = prop)); }
private SrmDocument ImportResults(SrmDocument doc, string nameResult, IEnumerable<MsDataFileUri> dataSources, OptimizableRegression optimizationFunction) { var results = doc.Settings.MeasuredResults; var chrom = GetChromatogramByName(nameResult, results); if (chrom == null) { // If the chromatogram, is not in the current set, then delete the cache // file to make sure it is not on disk before starting. FileEx.SafeDelete(ChromatogramCache.FinalPathForName(DocumentFilePath, nameResult), true); chrom = new ChromatogramSet(nameResult, dataSources, Annotations.EMPTY, optimizationFunction); if (results == null) results = new MeasuredResults(new[] {chrom}); else { // Add the new result to the end. var listChrom = new List<ChromatogramSet>(results.Chromatograms) {chrom}; results = results.ChangeChromatograms(listChrom.ToArray()); } } else { // Append to an existing chromatogram set var dataFilePaths = new List<MsDataFileUri>(chrom.MSDataFilePaths); foreach (var sourcePath in dataSources) { if (!dataFilePaths.Contains(sourcePath)) dataFilePaths.Add(sourcePath); } // If no new paths added, just return without changing. if (dataFilePaths.Count == chrom.FileCount) return doc; int replaceIndex = results.Chromatograms.IndexOf(chrom); var arrayChrom = results.Chromatograms.ToArray(); arrayChrom[replaceIndex] = chrom.ChangeMSDataFilePaths(dataFilePaths); results = results.ChangeChromatograms(arrayChrom); } if (results != null && Program.DisableJoining) results = results.ChangeIsJoiningDisabled(true); return doc.ChangeMeasuredResults(results); }