public void GetDriftTimesFromResults() { try { var driftTable = new MeasuredDriftTimeTable(gridMeasuredDriftTimes, MeasuredDriftTimeSequence.TargetResolver); bool useHighEnergyOffset = cbOffsetHighEnergySpectra.Checked; var tempDriftTimePredictor = new IonMobilityPredictor(@"tmp", driftTable.GetTableMeasuredIonMobility(useHighEnergyOffset, Units), null, null, IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType.resolving_power, 30, 0, 0); using (var longWaitDlg = new LongWaitDlg { Text = Resources.EditDriftTimePredictorDlg_GetDriftTimesFromResults_Finding_ion_mobility_values_for_peaks, Message = string.Empty, ProgressValue = 0 }) { longWaitDlg.PerformWork(this, 100, broker => { tempDriftTimePredictor = tempDriftTimePredictor.ChangeMeasuredIonMobilityValuesFromResults(Program.MainWindow.Document, Program.MainWindow.DocumentFilePath, useHighEnergyOffset, broker); }); if (!longWaitDlg.IsCanceled && tempDriftTimePredictor != null) { // Set display units based on what we found in the data UpdateMeasuredDriftTimesControl(tempDriftTimePredictor); } } } catch (Exception ex) { MessageDlg.ShowException(this, ex); } }
private void UpdateMeasuredDriftTimesControl(IonMobilityPredictor predictor) { // List any measured ion mobility values, taking care to show only those matching display units gridMeasuredDriftTimes.Rows.Clear(); if (predictor == null) { return; } _predictor = (_predictor ?? IonMobilityPredictor.EMPTY).ChangeMeasuredIonMobilityValues(predictor.MeasuredMobilityIons); Units = _predictor.GetIonMobilityUnits(); var units = Units; if (predictor.MeasuredMobilityIons != null) { bool hasHighEnergyOffsets = predictor.MeasuredMobilityIons.Any(p => p.Value.HighEnergyIonMobilityValueOffset != 0); cbOffsetHighEnergySpectra.Checked = hasHighEnergyOffsets; foreach (var p in predictor.MeasuredMobilityIons) { var ccs = p.Value.CollisionalCrossSectionSqA.HasValue ? string.Format(@"{0:F04}", p.Value.CollisionalCrossSectionSqA.Value) : string.Empty; var im = p.Value.IonMobility.Units == units ? p.Value.IonMobility.Mobility : null; var imOffset = p.Value.IonMobility.Units == units ? p.Value.HighEnergyIonMobilityValueOffset : 0; var chargeOrAdductString = _smallMoleculeUI ? p.Key.Adduct.AdductFormula : p.Key.Charge.ToString(LocalizationHelper.CurrentCulture); if (hasHighEnergyOffsets) { gridMeasuredDriftTimes.Rows.Add(p.Key.Target, chargeOrAdductString, im.HasValue ? im.Value.ToString(LocalizationHelper.CurrentCulture) : string.Empty, ccs, imOffset.ToString(LocalizationHelper.CurrentCulture) ); } else { gridMeasuredDriftTimes.Rows.Add(p.Key.Target, chargeOrAdductString, im.HasValue ? im.Value.ToString(LocalizationHelper.CurrentCulture) : string.Empty, ccs ); } } } else { cbOffsetHighEnergySpectra.Checked = false; } }
private void IonMobilityLibraryChanged() { var calc = _driverIonMobilityLibraryListComboDriver.SelectedItem; if (calc != null) { try { if (_predictor != null) { _predictor = _predictor.ChangeLibrary(calc); } } catch (Exception e) { MessageDlg.ShowException(this, e); } } UpdateControls(); }
public void OkDialog(bool forceOverwrite = false) { var helper = new MessageBoxHelper(this); var driftTable = new MeasuredDriftTimeTable(gridMeasuredDriftTimes, MeasuredDriftTimeSequence.TargetResolver); var table = new ChargeRegressionTable(gridRegression); string name; if (!helper.ValidateNameTextBox(textName, out name)) { return; } if (_existing.Contains(r => !Equals(_predictor, r) && Equals(name, r.Name)) && !forceOverwrite) { if (MessageBox.Show(this, TextUtil.LineSeparate(string.Format(Resources.EditDriftTimePredictorDlg_OkDialog_An_ion_mobility_predictor_with_the_name__0__already_exists_, name), Resources.EditDriftTimePredictorDlg_OkDialog_Do_you_want_to_change_it_), Program.Name, MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } if (driftTable.GetTableMeasuredIonMobility(cbOffsetHighEnergySpectra.Checked, Units) == null) // Some error detected in the measured drift times table { return; } if (table.GetTableChargeRegressionLines() == null) // Some error detected in the charged regression lines table { return; } double resolvingPower = 0; double widthAtDt0 = 0; double widthAtDtMax = 0; IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType peakWidthType; if (cbLinear.Checked) { if (!helper.ValidateDecimalTextBox(textWidthAtDt0, out widthAtDt0)) { return; } if (!helper.ValidateDecimalTextBox(textWidthAtDtMax, out widthAtDtMax)) { return; } var errmsg = ValidateWidth(widthAtDt0); if (errmsg != null) { helper.ShowTextBoxError(textWidthAtDt0, errmsg); return; } errmsg = ValidateWidth(widthAtDtMax); if (errmsg != null) { helper.ShowTextBoxError(textWidthAtDtMax, errmsg); return; } peakWidthType = IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType.linear_range; } else { if (!helper.ValidateDecimalTextBox(textResolvingPower, out resolvingPower)) { return; } var errmsg = ValidateResolvingPower(resolvingPower); if (errmsg != null) { helper.ShowTextBoxError(textResolvingPower, errmsg); return; } peakWidthType = IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType.resolving_power; } if ((comboLibrary.SelectedIndex > 0) && (comboLibrary.SelectedItem.ToString().Length == 0)) { MessageBox.Show(this, Resources.EditDriftTimePredictorDlg_OkDialog_Drift_time_prediction_requires_an_ion_mobility_library_, Program.Name); comboLibrary.Focus(); return; } var ionMobilityLibrary = _driverIonMobilityLibraryListComboDriver.SelectedItem; IonMobilityPredictor predictor = new IonMobilityPredictor(name, driftTable.GetTableMeasuredIonMobility(cbOffsetHighEnergySpectra.Checked, Units), ionMobilityLibrary, table.GetTableChargeRegressionLines(), peakWidthType, resolvingPower, widthAtDt0, widthAtDtMax); _predictor = predictor; DialogResult = DialogResult.OK; }