public static ProcessedIrtAverages ProcessRetentionTimes(int?numCirt, IRetentionTimeProvider[] irtProviders, DbIrtPeptide[] standardPeptides, DbIrtPeptide[] cirtPeptides, IrtRegressionType regressionType, IProgressMonitor monitor, out DbIrtPeptide[] newStandardPeptides) { newStandardPeptides = null; var processed = !numCirt.HasValue ? RCalcIrt.ProcessRetentionTimes(monitor, irtProviders, standardPeptides, new DbIrtPeptide[0], regressionType) : RCalcIrt.ProcessRetentionTimesCirt(monitor, irtProviders, cirtPeptides, numCirt.Value, regressionType, out newStandardPeptides); return(processed); }
public static bool AddIrts(Library lib, LibrarySpec libSpec, IrtStandard standard, Control parent, bool useTopMostForm = false) { if (lib == null || !lib.IsLoaded || standard == null || standard.Name.Equals(IrtStandard.EMPTY.Name)) { return(false); } Control GetParent() { return(useTopMostForm ? FormUtil.FindTopLevelOpenForm(f => f is BuildLibraryNotification) ?? parent : parent); } IRetentionTimeProvider[] irtProviders = null; var cirtPeptides = new DbIrtPeptide[0]; using (var longWait = new LongWaitDlg { Text = Resources.LibraryBuildNotificationHandler_AddIrts_Loading_retention_time_providers }) { var status = longWait.PerformWork(GetParent(), 800, monitor => { monitor.UpdateProgress(new ProgressStatus().ChangePercentComplete(-1)); irtProviders = lib.RetentionTimeProvidersIrt.ToArray(); if (!irtProviders.Any()) { irtProviders = lib.RetentionTimeProviders.ToArray(); } if (ReferenceEquals(standard, IrtStandard.CIRT_SHORT)) { var libPeptides = irtProviders.SelectMany(provider => provider.PeptideRetentionTimes).Select(rt => rt.PeptideSequence).ToHashSet(); cirtPeptides = IrtStandard.CIRT.Peptides.Where(pep => libPeptides.Contains(pep.ModifiedTarget)).ToArray(); } }); if (status.IsCanceled) { return(false); } if (status.IsError) { throw status.ErrorException; } } int?numCirt = null; if (cirtPeptides.Length >= RCalcIrt.MIN_PEPTIDES_COUNT) { using (var dlg = new AddIrtStandardsDlg(cirtPeptides.Length, string.Format( Resources.LibraryBuildNotificationHandler_AddIrts__0__distinct_CiRT_peptides_were_found__How_many_would_you_like_to_use_as_iRT_standards_, cirtPeptides.Length))) { if (dlg.ShowDialog(GetParent()) != DialogResult.OK) { return(false); } numCirt = dlg.StandardCount; } } var standardPeptides = standard.Peptides.ToArray(); ProcessedIrtAverages processed = null; using (var longWait = new LongWaitDlg { Text = Resources.LibraryBuildNotificationHandler_AddIrts_Processing_retention_times }) { try { var status = longWait.PerformWork(GetParent(), 800, monitor => { processed = !numCirt.HasValue ? RCalcIrt.ProcessRetentionTimes(monitor, irtProviders, standardPeptides, new DbIrtPeptide[0]) : RCalcIrt.ProcessRetentionTimesCirt(monitor, irtProviders, cirtPeptides, numCirt.Value, out standardPeptides); }); if (status.IsCanceled) { return(false); } if (status.IsError) { throw status.ErrorException; } } catch (Exception x) { MessageDlg.ShowWithException(GetParent(), TextUtil.LineSeparate( Resources.BuildPeptideSearchLibraryControl_AddIrtLibraryTable_An_error_occurred_while_processing_retention_times_, x.Message), x); return(false); } } using (var resultsDlg = new AddIrtPeptidesDlg(AddIrtPeptidesLocation.spectral_library, processed)) { if (resultsDlg.ShowDialog(GetParent()) != DialogResult.OK) { return(false); } } var recalibrate = false; if (processed.CanRecalibrateStandards(standardPeptides)) { using (var dlg = new MultiButtonMsgDlg( TextUtil.LineSeparate(Resources.LibraryGridViewDriver_AddToLibrary_Do_you_want_to_recalibrate_the_iRT_standard_values_relative_to_the_peptides_being_added_, Resources.LibraryGridViewDriver_AddToLibrary_This_can_improve_retention_time_alignment_under_stable_chromatographic_conditions_), MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false)) { recalibrate = dlg.ShowDialog(GetParent()) == DialogResult.Yes; } } var processedDbIrtPeptides = processed.DbIrtPeptides.ToArray(); if (!processedDbIrtPeptides.Any()) { return(false); } using (var longWait = new LongWaitDlg { Text = Resources.LibraryBuildNotificationHandler_AddIrts_Adding_iRTs_to_library }) { try { DbIrtPeptide[] newStandards = null; var status = longWait.PerformWork(GetParent(), 800, monitor => { if (recalibrate) { monitor.UpdateProgress(new ProgressStatus().ChangeSegments(0, 2)); newStandards = processed.RecalibrateStandards(standardPeptides).ToArray(); processed = RCalcIrt.ProcessRetentionTimes(monitor, processed.ProviderData.Select(data => data.RetentionTimeProvider).ToArray(), newStandards.ToArray(), new DbIrtPeptide[0]); } var irtDb = IrtDb.CreateIrtDb(libSpec.FilePath); irtDb.AddPeptides(monitor, (newStandards ?? standardPeptides).Concat(processed.DbIrtPeptides).ToList()); }); if (status.IsError) { throw status.ErrorException; } } catch (Exception x) { MessageDlg.ShowWithException(GetParent(), TextUtil.LineSeparate( Resources.LibraryBuildNotificationHandler_AddIrts_An_error_occurred_trying_to_add_iRTs_to_the_library_, x.Message), x); return(false); } } return(true); }