private IEnumerable <IsolationWindow> GetIsoWindows(double precursorMz) { var lower = new IsolationWindow(precursorMz - _isolationWindowUpperOffset, 0, 0); var higher = new IsolationWindow(precursorMz + _isolationWindowLowerOffset, 0, 0); return(_isolationWindows.GetViewBetween(lower, higher)); }
/// <summary> /// Shows or hides instrument Precursor m/z and mass from the instrument /// Reads data from LCMSRun if necessary /// </summary> /// <param name="value">Should the instrument data be shown?</param> /// <param name="pbfLcmsRun">LCMSRun for this data set.</param> /// <returns>Asynchronous task.</returns> public async Task ToggleShowInstrumentDataAsync(bool value, PbfLcMsRun pbfLcmsRun) { if (value) { if (pbfLcmsRun != null) { var scans = this.Data; foreach (var scan in scans.Where(scan => scan.Sequence.Count == 0)) { PrSm scan1 = scan; IsolationWindow isolationWindow = await Task.Run(() => pbfLcmsRun.GetIsolationWindow(scan1.Scan)); scan.PrecursorMz = isolationWindow.MonoisotopicMz ?? double.NaN; scan.Charge = isolationWindow.Charge ?? 0; scan.Mass = isolationWindow.MonoisotopicMass ?? double.NaN; } } } else { var scans = this.Data; foreach (var scan in scans.Where(scan => scan.Sequence.Count == 0)) { scan.PrecursorMz = double.NaN; scan.Charge = 0; scan.Mass = double.NaN; } } }
private List <IsolationWindow> GetIsolationWindows() { //Overlap requires an even number of windows if (Overlap && _gridViewDriver.Items.Count % 2 == 1) { MessageDlg.Show(this, Resources.EditIsolationSchemeDlg_GetIsolationWindows_Overlap_requires_an_even_number_of_windows_); return(null); } // Validate prespecified windows. var windowList = new List <IsolationWindow>(); for (int row = 0; row < _gridViewDriver.Items.Count; row++) { var editWindow = _gridViewDriver.Items[row]; // Report any problems in this row. int errorCell = FindErrorCell(editWindow); if (errorCell >= COLUMN_START) { _gridViewDriver.SelectCell(errorCell, row); MessageDlg.Show(this, string.Format(Resources.EditIsolationSchemeDlg_OkDialog_Specify__0__for_isolation_window, _gridViewDriver.GetHeaderText(errorCell))); _gridViewDriver.EditCell(); return(null); } IsolationWindow isolationWindow; try { double startValue = editWindow.Start.Value; double endValue = editWindow.End.Value; if (Equals(comboIsolation.SelectedItem, WindowType.MEASUREMENT)) { startValue += editWindow.StartMargin ?? 0; endValue -= editWindow.StartMargin ?? 0; } isolationWindow = new IsolationWindow( // ReSharper disable PossibleInvalidOperationException startValue, endValue, // ReSharper restore PossibleInvalidOperationException null, cbSpecifyMargin.Checked ? editWindow.StartMargin : null, cbSpecifyMargin.Checked ? editWindow.StartMargin : null, cbSpecifyCERange.Checked ? editWindow.CERange : null); } catch (InvalidDataException exception) { _gridViewDriver.SelectRow(row); MessageDlg.ShowException(this, exception); return(null); } windowList.Add(isolationWindow); } return(windowList); }
/// <summary> /// The extent of the isolation window in m/z above the isolation window target m/z. /// The lower and upper offsets may be asymmetric about the target m/z. [PSI:MS] /// </summary> public static IsolationWindow SetIsolationWindowUpperOffset( this IsolationWindow iw, double offset) { if (offset < 0) { throw new ArgumentOutOfRangeException("offset"); } return(iw.SetCvParam(IsolationWindowUpperOffset, offset).PSIMS_Mz()); }
/// <summary> /// The primary or reference m/z about which the isolation window is defined. [PSI:MS] /// </summary> public static IsolationWindow SetIsolationWindowTargetMz( this IsolationWindow iw, double mz) { if (mz < 0) { throw new ArgumentOutOfRangeException("mz"); } return(iw.SetCvParam(IsolationWindowTargetMz, mz).PSIMS_Mz()); }
/// <summary> /// The extent of the isolation window in m/z above the isolation window target m/z. /// The lower and upper offsets may be asymmetric about the target m/z. [PSI:MS] /// </summary> public static bool TryGetIsolationWindowUpperOffset( this IsolationWindow iw, out double offset) { CvParam p; if (iw.TryGetParam(IsolationWindowUpperOffset, out p)) { offset = p.GetDouble(); return(true); } else { offset = default(double); return(false); } }
/// <summary> /// The primary or reference m/z about which the isolation window is defined. [PSI:MS] /// </summary> public static bool TryGetIsolationWindowTargetMz( this IsolationWindow iw, out double mz) { CvParam p; if (iw.TryGetParam(IsolationWindowTargetMz, out p)) { mz = p.GetDouble(); return(true); } else { mz = default(double); return(false); } }
public void SerializeIsolationSchemeTest() { var isolationScheme = new IsolationScheme("object test", 1.0, 2.0); // Test IsolationScheme.Validate method through ChangeProp isolationScheme = (IsolationScheme)isolationScheme.ChangeName("test2"); // Test IsolationScheme object methods isolationScheme.Equals(null); isolationScheme.Equals(isolationScheme); // ReSharper disable ReturnValueOfPureMethodIsNotUsed isolationScheme.Equals((object)null); isolationScheme.Equals((object)isolationScheme); isolationScheme.GetHashCode(); // ReSharper restore ReturnValueOfPureMethodIsNotUsed // Test IsolationWindow object methods var isolationWindow = new IsolationWindow(100.0, 150.0, 125.0, 1.0, 1.0); isolationWindow.Equals(null); isolationWindow.Equals(isolationWindow); // ReSharper disable ReturnValueOfPureMethodIsNotUsed isolationWindow.Equals((object)null); isolationWindow.Equals((object)isolationWindow); // ReSharper disable SuspiciousTypeConversion.Global isolationWindow.Equals(2); // ReSharper restore SuspiciousTypeConversion.Global isolationWindow.GetHashCode(); isolationWindow.GetSchema(); // ReSharper restore ReturnValueOfPureMethodIsNotUsed // Test round trip serialization AssertEx.Serialization <IsolationSchemeList>(ISOLATION_SCHEME_LIST, CheckSettingsList, false); // Not part of a Skyline document, don't check against schema // Valid first AssertEx.DeserializeNoError <IsolationScheme>( @"<isolation_scheme name=""Validate (1)"" precursor_filter=""1""/>"); AssertEx.DeserializeNoError <IsolationScheme>( @"<isolation_scheme name=""Validate (2)"" precursor_left_filter=""0.5"" precursor_right_filter=""0.5""/>"); AssertEx.DeserializeNoError <IsolationScheme>( @"<isolation_scheme name=""Validate (3)"" special_handling=""Multiplexed"" windows_per_scan=""2""> <isolation_window start=""100"" end=""110""/><isolation_window start=""110"" end=""130""/></isolation_scheme>"); AssertEx.DeserializeNoError <IsolationScheme>( @"<isolation_scheme name=""Validate (4)"" special_handling=""MSe""/>"); // Missing parameters AssertEx.DeserializeError <IsolationScheme>(@"<isolation_scheme/>"); // No name AssertEx.DeserializeError <IsolationScheme>(@"<isolation_scheme precursor_filter=""1""/>"); // Filter and prespecified window AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (1)"" precursor_filter=""1""><isolation_window start=""1"" end=""10""/></isolation_scheme>"); // Filter and special handling //AssertEx.DeserializeError<IsolationScheme>( // @"<isolation_scheme name=""Invalid (2)"" precursor_filter=""1"" special_handling=""MSe""/>"); // Filter and windows per scan AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (3)"" precursor_filter=""1"" windows_per_scan=""3""/>"); // Special handling but no windows (now uses results windows) // AssertEx.DeserializeError<IsolationScheme>( // @"<isolation_scheme name=""Invalid (4)"" special_handling=""Multiplexed""/>"); // Right filter only AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (5)"" precursor_right_filter=""1""/>"); // Windows per scan with no special handling AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (6)"" windows_per_scan=""2""><isolation_window start=""1"" end=""10""/></isolation_scheme>"); // Windows per scan with MSe AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (7)"" windows_per_scan=""2"" special_handling=""MSe"" />"); // Multiplexed and no windows per scan AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (8)"" special_handling=""Multiplexed""><isolation_window start=""1"" end=""10""/></isolation_scheme>"); // Multiplexed and invalid windows per scan AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (9)"" windows_per_scan=""0"" special_handling=""Multiplexed""><isolation_window start=""1"" end=""10""/></isolation_scheme>"); // Invalid special handling AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (10)"" special_handling=""invalid option""/>"); // Bad window: start > end AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (10)""><isolation_window start=""10"" end=""1""/></isolation_scheme>"); // Bad window: target not between start and end AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (11)""><isolation_window start=""1"" end=""10"" target=""20""/></isolation_scheme>"); // Bad window: start margin < 0 AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (12)""><isolation_window start=""1"" end=""10"" margin_left=""-1"" margin_right=""2""/></isolation_scheme>"); // MSe with window AssertEx.DeserializeError <IsolationScheme>( @"<isolation_scheme name=""Invalid (14)"" special_handling=""MSe""><isolation_window start=""1"" end=""10""/></isolation_scheme>"); }
public void OkDialog() { var helper = new MessageBoxHelper(this); string name; if (!helper.ValidateNameTextBox(textName, out name)) { return; } if (_existing.Contains(en => !ReferenceEquals(_isolationScheme, en) && Equals(name, en.Name))) { helper.ShowTextBoxError(textName, Resources.EditIsolationSchemeDlg_OkDialog_The_isolation_scheme_named__0__already_exists, name); return; } if (rbUseResultsData.Checked) { double?precursorFilter = null; bool filterMargin = Equals(comboIsolationWidth.SelectedItem, IsolationWidthType.RESULTS_WITH_MARGIN); if (!Equals(comboIsolationWidth.SelectedItem, IsolationWidthType.RESULTS)) { double minFilt = filterMargin ? 0 : TransitionFullScan.MIN_PRECURSOR_MULTI_FILTER; double maxFilt = filterMargin ? TransitionFullScan.MAX_PRECURSOR_MULTI_FILTER_MARGIN : TransitionFullScan.MAX_PRECURSOR_MULTI_FILTER; double precFilt; if (!helper.ValidateDecimalTextBox(textPrecursorFilterMz, minFilt, maxFilt, out precFilt)) { return; } precursorFilter = precFilt; } try { _isolationScheme = new IsolationScheme(name, SpecialHandling, precursorFilter, null, filterMargin); } catch (InvalidDataException exception) { MessageDlg.ShowException(this, exception); return; } } else { // Validate prespecified windows. List <IsolationWindow> windowList; if ((windowList = GetIsolationWindows()) == null) { return; } // Must be at least one window. if (windowList.Count == 0) { _gridViewDriver.SelectCell(COLUMN_START, 0); MessageDlg.Show(this, Resources .EditIsolationSchemeDlg_OkDialog_Specify_Start_and_End_values_for_at_least_one_isolation_window); gridIsolationWindows.Focus(); _gridViewDriver.EditCell(); return; } int?windowsPerScan = null; if (Equals(SpecialHandling, IsolationScheme.SpecialHandlingType.MULTIPLEXED)) { int x; if (!helper.ValidateNumberTextBox(textWindowsPerScan, IsolationScheme.MIN_MULTIPLEXED_ISOLATION_WINDOWS, IsolationScheme.MAX_MULTIPLEXED_ISOLATION_WINDOWS, out x)) { return; } windowsPerScan = x; } // Check for overlap and gaps var sortedWindowList = windowList.OrderBy(o => o.Start).ToList(); bool gapsOk = false; bool overlapsOk = false; bool overlap = Overlap; int increment = overlap ? 2 : 1; int subtraction = overlap ? 3 : 1; const double tolerance = 0.0001; for (int i = 0; i < sortedWindowList.Count - subtraction; i += increment) { for (int j = 0; j < increment; j++) { IsolationWindow current = sortedWindowList.ElementAt(i + j); IsolationWindow next = sortedWindowList.ElementAt(i + j + increment); if (!gapsOk && next.Start - current.End > tolerance) { if (MultiButtonMsgDlg.Show(this, Resources .EditIsolationSchemeDlg_OkDialog_There_are_gaps_in_a_single_cycle_of_your_extraction_windows__Do_you_want_to_continue_, MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false) != DialogResult.Yes) { return; } gapsOk = true; } else if (!overlapsOk && current.End - next.Start > tolerance) { if (MultiButtonMsgDlg.Show(this, Resources.EditIsolationSchemeDlgOkDialogThereAreOverlapsContinue, MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, false) != DialogResult.Yes) { return; } overlapsOk = true; } } } try { _isolationScheme = new IsolationScheme(name, windowList, SpecialHandling, windowsPerScan); } catch (InvalidDataException exception) { MessageDlg.ShowException(this, exception); return; } } DialogResult = DialogResult.OK; }
public DiaIsolationWindowsGraphForm(List <IsolationWindow> isolationWindows, bool usesMargins, object deconv, int windowsPerScan) { InitializeComponent(); Icon = Resources.Skyline; if (isolationWindows.Count == 0) { return; } bool overlap = Equals(deconv, EditIsolationSchemeDlg.DeconvolutionMethod.MSX_OVERLAP) || Equals(deconv, EditIsolationSchemeDlg.DeconvolutionMethod.OVERLAP) || Equals(deconv, EditIsolationSchemeDlg.DeconvolutionMethod.FAST_OVERLAP); //Setup Graph zgIsolationGraph.GraphPane.Title.Text = Resources.DiaIsolationWindowsGraphForm_DiaIsolationWindowsGraphForm_Measurement_Windows; zgIsolationGraph.GraphPane.XAxis.Title.Text = Resources.DiaIsolationWindowsGraphForm_DiaIsolationWindowsGraphForm_m_z; zgIsolationGraph.GraphPane.YAxis.Title.Text = Resources.DiaIsolationWindowsGraphForm_DiaIsolationWindowsGraphForm_Cycle; zgIsolationGraph.GraphPane.IsFontsScaled = false; zgIsolationGraph.GraphPane.YAxis.Scale.IsReverse = true; zgIsolationGraph.GraphPane.YAxisList[0].MajorTic.IsOpposite = false; zgIsolationGraph.GraphPane.YAxisList[0].MinorTic.IsOpposite = false; zgIsolationGraph.GraphPane.XAxis.MajorTic.IsOpposite = false; zgIsolationGraph.GraphPane.XAxis.MinorTic.IsOpposite = false; zgIsolationGraph.MasterPane.Border.IsVisible = false; zgIsolationGraph.GraphPane.YAxis.MajorGrid.IsZeroLine = false; zgIsolationGraph.GraphPane.Border.IsVisible = false; zgIsolationGraph.GraphPane.Chart.Border.IsVisible = false; zgIsolationGraph.IsZoomOnMouseCenter = true; //Draw Lines and rectangles _windows = new List <BoxObj>(20); _leftMargins = new List <BoxObj>(20); _rightMargins = new List <BoxObj>(20); _smallesMz = Double.MaxValue; _largestMz = 0; var isolationWindowArray = isolationWindows.ToArray(); // ReSharper int windowCount = isolationWindowArray.Length; for (int cycle = 0; cycle < TOTAL_CYCLES_SHOWN; cycle++) { int firstIndex = overlap && cycle % 2 == 1 ? windowCount / 2 : 0; int stopIndex = overlap && cycle % 2 == 0 ? windowCount / 2 : windowCount; for (int i = firstIndex; i < stopIndex; i++) { IsolationWindow window = isolationWindowArray[i]; double windowY = cycle + (double)(i - firstIndex) / (stopIndex - firstIndex); double windowX = window.Start; double windowWidth = window.End - window.Start; double windowHeight = 1.0 / (stopIndex - firstIndex); BoxObj windowBox = new BoxObj(windowX, windowY, windowWidth, windowHeight, _windowColor, _windowColor) { IsClippedToChartRect = true }; zgIsolationGraph.GraphPane.GraphObjList.Add(windowBox); _windows.Add(windowBox); if (usesMargins) { double marginLeftX = windowX - window.StartMargin ?? 0; double marginLeftWidth = window.StartMargin ?? 0; BoxObj marginLeftBox = new BoxObj(marginLeftX, windowY, marginLeftWidth, windowHeight, _marginColor, _marginColor) { IsClippedToChartRect = true }; zgIsolationGraph.GraphPane.GraphObjList.Add(marginLeftBox); _leftMargins.Add(marginLeftBox); double marginRightX = windowX + windowWidth; double marginRightWidth = window.EndMargin ?? window.StartMargin ?? 0; BoxObj marginRightBox = new BoxObj(marginRightX, windowY, marginRightWidth, windowHeight, _marginColor, _marginColor) { IsClippedToChartRect = true }; zgIsolationGraph.GraphPane.GraphObjList.Add(marginRightBox); _rightMargins.Add(marginRightBox); _largestMz = Math.Max(marginRightX + marginRightWidth, _largestMz); _smallesMz = Math.Min(marginLeftX, _smallesMz); } _largestMz = Math.Max(_largestMz, windowX + windowWidth); _smallesMz = Math.Min(_smallesMz, windowX); } } _overlapRayBoxes = overlap ? new List <BoxObj>() : null; _gapBoxes = new List <BoxObj>(); _overlapBoxes = new List <BoxObj>(); for (int cycle = 0; cycle < TOTAL_CYCLES_SHOWN; cycle++) { int currentCycleStart; int currentCycleCount; int nextCycleStart; int nextCycleCount; if (overlap) { currentCycleStart = cycle * windowCount / 2; currentCycleCount = windowCount / 2; nextCycleStart = currentCycleStart + currentCycleCount; nextCycleCount = windowCount / 2; } else { currentCycleStart = cycle * windowCount; currentCycleCount = windowCount; nextCycleStart = currentCycleStart + windowCount; nextCycleCount = windowCount; } List <BoxObj> currentCycleWindows = _windows.GetRange(currentCycleStart, currentCycleCount).OrderBy(o => Location.X).ToList(); List <BoxObj> nextCycleWindows = cycle < TOTAL_CYCLES_SHOWN - 1 ? _windows.GetRange(nextCycleStart, nextCycleCount).OrderBy(o => Location.X).ToList() : null; for (int i = 0; i < currentCycleWindows.Count; i++) { BoxObj currentCycleCurrentBox = currentCycleWindows.ElementAt(i); BoxObj currentCycleNextBox = i < currentCycleWindows.Count - 1 ? currentCycleWindows.ElementAt(i + 1) : null; if (currentCycleNextBox != null) { checkGaps(currentCycleCurrentBox, currentCycleNextBox); checkOverlaps(currentCycleCurrentBox, currentCycleNextBox); } if (overlap && i % 2 == 0 && nextCycleWindows != null) { int leftBoxIndex = cycle % 2 == 0 ? i : i - 1; BoxObj nextCycleLeftBox = leftBoxIndex >= 0 ? nextCycleWindows.ElementAt(leftBoxIndex) : null; int rightBoxIndex = cycle % 2 == 0 ? i + 1 : i; BoxObj nextCycleRightBox = rightBoxIndex < nextCycleWindows.Count ? nextCycleWindows.ElementAt(rightBoxIndex) : null; BoxObj rayBoxLeft = null; BoxObj rayBoxRight = null; if (nextCycleLeftBox != null) { rayBoxLeft = GetOverLapRay(currentCycleCurrentBox, nextCycleLeftBox); if (rayBoxLeft != null) { zgIsolationGraph.GraphPane.GraphObjList.Add(rayBoxLeft); _overlapRayBoxes.Add(rayBoxLeft); } } if (nextCycleRightBox != null) { rayBoxRight = GetOverLapRay(currentCycleCurrentBox, nextCycleRightBox); if (rayBoxRight != null) { zgIsolationGraph.GraphPane.GraphObjList.Add(rayBoxRight); _overlapRayBoxes.Add(rayBoxRight); } } if (rayBoxLeft != null && rayBoxRight == null) { rayBoxLeft.Location.X1 = currentCycleCurrentBox.Location.X1; rayBoxLeft.Location.Width = currentCycleCurrentBox.Location.Width; } else if (rayBoxRight != null && rayBoxLeft == null) { rayBoxRight.Location.X1 = currentCycleCurrentBox.Location.X1; rayBoxRight.Location.Width = currentCycleCurrentBox.Location.Width; } } } } zgIsolationGraph.GraphPane.XAxis.Scale.Min = _smallesMz; zgIsolationGraph.GraphPane.XAxis.Scale.Max = _largestMz; zgIsolationGraph.GraphPane.YAxis.Scale.Min = Y_SCALE_MIN; zgIsolationGraph.GraphPane.YAxis.Scale.Max = Y_SCALE_MAX; zgIsolationGraph.AxisChange(); zgIsolationGraph.Invalidate(); //Setup check boxes and color labels if (usesMargins) { cbMargin.Checked = true; } else { cbMargin.Hide(); labelMarginColor.Hide(); int width = cbMargin.Width; cbShowOverlapRays.Left -= width; labelOverlapColor.Left -= width; cbShowOverlapsSingle.Left -= width; labelSingleOverlapColor.Left -= width; cbShowGaps.Left -= width; labelGapColor.Left -= width; } cbShowGaps.Checked = true; cbShowOverlapsSingle.Checked = true; if (overlap) { cbShowOverlapRays.Checked = true; labelOverlapColor.Visible = true; } else { cbShowOverlapRays.Hide(); labelOverlapColor.Hide(); } labelMarginColor.BackColor = _marginColor; labelWindowColor.BackColor = _windowColor; labelGapColor.BackColor = _gapColor; labelSingleOverlapColor.BackColor = _overlapColor; labelOverlapColor.BackColor = _overlapRayColor; }
private IEnumerable<IsolationWindow> GetIsoWindows(double precursorMz) { var lower = new IsolationWindow(precursorMz - _isolationWindowUpperOffset, 0, 0); var higher = new IsolationWindow(precursorMz + _isolationWindowLowerOffset, 0, 0); return _isolationWindows.GetViewBetween(lower, higher); }
private void WriteIsolationWindow(IsolationWindow isolationWindow) { writer.WriteStartElement("isolationWindow"); WriteParamGroup(isolationWindow); writer.WriteEndElement(); }