/// <summary> /// Serializes the contents of a single <see cref="TransitionDocNode"/> /// to XML. /// </summary> /// <param name="writer">The XML writer</param> /// <param name="nodePep">The transition group's parent peptide node</param> /// <param name="nodeGroup">The transition node's parent group node</param> /// <param name="nodeTransition">The transition document node</param> private void WriteTransitionXml(XmlWriter writer, PeptideDocNode nodePep, TransitionGroupDocNode nodeGroup, TransitionDocNode nodeTransition) { Transition transition = nodeTransition.Transition; writer.WriteAttribute(ATTR.fragment_type, transition.IonType); writer.WriteAttribute(ATTR.quantitative, nodeTransition.ExplicitQuantitative, true); if (transition.IsCustom()) { if (!(transition.CustomIon is SettingsCustomIon)) { transition.CustomIon.WriteXml(writer, transition.Adduct); } else { writer.WriteAttributeString(ATTR.measured_ion_name, transition.CustomIon.Name); } } writer.WriteAttributeNullable(ATTR.decoy_mass_shift, transition.DecoyMassShift); // NOTE: MassIndex is the peak index in the isotopic distribution of the precursor. // 0 for monoisotopic peaks and for non "precursor" ion types. if (transition.MassIndex != 0) { writer.WriteAttribute(ATTR.mass_index, transition.MassIndex); } if (nodeTransition.HasDistInfo) { writer.WriteAttribute(ATTR.isotope_dist_rank, nodeTransition.IsotopeDistInfo.Rank); writer.WriteAttribute(ATTR.isotope_dist_proportion, nodeTransition.IsotopeDistInfo.Proportion); } if (!transition.IsPrecursor()) { if (!transition.IsCustom()) { writer.WriteAttribute(ATTR.fragment_ordinal, transition.Ordinal); writer.WriteAttribute(ATTR.calc_neutral_mass, nodeTransition.GetMoleculePersistentNeutralMass()); } writer.WriteAttribute(ATTR.product_charge, transition.Charge); if (!transition.IsCustom()) { writer.WriteAttribute(ATTR.cleavage_aa, transition.AA.ToString(CultureInfo.InvariantCulture)); writer.WriteAttribute(ATTR.loss_neutral_mass, nodeTransition.LostMass); //po } } // Order of elements matters for XSD validation WriteAnnotations(writer, nodeTransition.Annotations); writer.WriteElementString(EL.precursor_mz, SequenceMassCalc.PersistentMZ(nodeGroup.PrecursorMz)); writer.WriteElementString(EL.product_mz, SequenceMassCalc.PersistentMZ(nodeTransition.Mz)); TransitionPrediction predict = Settings.TransitionSettings.Prediction; var optimizationMethod = predict.OptimizedMethodType; double?ce = null; double?dp = null; var lib = predict.OptimizedLibrary; if (lib != null && !lib.IsNone) { var optimization = lib.GetOptimization(OptimizationType.collision_energy, Settings.GetSourceTarget(nodePep), nodeGroup.PrecursorAdduct, nodeTransition.FragmentIonName, nodeTransition.Transition.Adduct); if (optimization != null) { ce = optimization.Value; } } double regressionMz = Settings.GetRegressionMz(nodePep, nodeGroup); var ceRegression = predict.CollisionEnergy; var dpRegression = predict.DeclusteringPotential; if (optimizationMethod == OptimizedMethodType.None) { if (ceRegression != null && !ce.HasValue) { ce = ceRegression.GetCollisionEnergy(nodeGroup.PrecursorAdduct, regressionMz); } if (dpRegression != null) { dp = dpRegression.GetDeclustringPotential(regressionMz); } } else { if (!ce.HasValue) { ce = OptimizationStep <CollisionEnergyRegression> .FindOptimizedValue(Settings, nodePep, nodeGroup, nodeTransition, optimizationMethod, ceRegression, SrmDocument.GetCollisionEnergy); } dp = OptimizationStep <DeclusteringPotentialRegression> .FindOptimizedValue(Settings, nodePep, nodeGroup, nodeTransition, optimizationMethod, dpRegression, SrmDocument.GetDeclusteringPotential); } if (nodeGroup.ExplicitValues.CollisionEnergy.HasValue) { ce = nodeGroup.ExplicitValues.CollisionEnergy; // Explicitly imported, overrides any calculation } if (ce.HasValue) { writer.WriteElementString(EL.collision_energy, ce.Value); } if (dp.HasValue) { writer.WriteElementString(EL.declustering_potential, dp.Value); } WriteTransitionLosses(writer, nodeTransition.Losses); if (nodeTransition.HasLibInfo) { writer.WriteStartElement(EL.transition_lib_info); writer.WriteAttribute(ATTR.rank, nodeTransition.LibInfo.Rank); writer.WriteAttribute(ATTR.intensity, nodeTransition.LibInfo.Intensity); writer.WriteEndElement(); } if (nodeTransition.HasResults) { if (nodeTransition.HasResults) { if (UseCompactFormat()) { var protoResults = new SkylineDocumentProto.Types.TransitionResults(); protoResults.Peaks.AddRange(nodeTransition.GetTransitionPeakProtos(Settings.MeasuredResults)); byte[] bytes = protoResults.ToByteArray(); writer.WriteStartElement(EL.results_data); writer.WriteBase64(bytes, 0, bytes.Length); writer.WriteEndElement(); } else { WriteResults(writer, Settings, nodeTransition.Results, EL.transition_results, EL.transition_peak, WriteTransitionChromInfo); } } } if (WroteTransitions != null) { WroteTransitions(1); } }
/// <summary> /// Serializes the contents of a single <see cref="TransitionGroupDocNode"/> /// to XML. /// </summary> /// <param name="writer">The XML writer</param> /// <param name="nodePep">The parent peptide document node</param> /// <param name="node">The transition group document node</param> private void WriteTransitionGroupXml(XmlWriter writer, PeptideDocNode nodePep, TransitionGroupDocNode node) { TransitionGroup group = node.TransitionGroup; var isCustomIon = nodePep.Peptide.IsCustomMolecule; writer.WriteAttribute(ATTR.charge, group.PrecursorAdduct.AdductCharge); if (!group.LabelType.IsLight) { writer.WriteAttribute(ATTR.isotope_label, group.LabelType); } if (!isCustomIon) { writer.WriteAttribute(ATTR.calc_neutral_mass, node.GetPrecursorIonPersistentNeutralMass()); } writer.WriteAttribute(ATTR.precursor_mz, SequenceMassCalc.PersistentMZ(node.PrecursorMz)); WriteExplicitTransitionGroupValuesAttributes(writer, node.ExplicitValues); writer.WriteAttribute(ATTR.auto_manage_children, node.AutoManageChildren, true); writer.WriteAttributeNullable(ATTR.decoy_mass_shift, group.DecoyMassShift); writer.WriteAttributeNullable(ATTR.precursor_concentration, node.PrecursorConcentration); TransitionPrediction predict = Settings.TransitionSettings.Prediction; double regressionMz = Settings.GetRegressionMz(nodePep, node); var ce = predict.CollisionEnergy.GetCollisionEnergy(node.TransitionGroup.PrecursorAdduct, regressionMz); writer.WriteAttribute(ATTR.collision_energy, ce); var dpRegression = predict.DeclusteringPotential; if (dpRegression != null) { var dp = dpRegression.GetDeclustringPotential(regressionMz); writer.WriteAttribute(ATTR.declustering_potential, dp); } if (!isCustomIon) { // modified sequence var calcPre = Settings.GetPrecursorCalc(node.TransitionGroup.LabelType, nodePep.ExplicitMods); var seq = node.TransitionGroup.Peptide.Target; writer.WriteAttribute(ATTR.modified_sequence, calcPre.GetModifiedSequence(seq, false)); // formatNarrow = false; We want InvariantCulture, not the local format Assume.IsTrue(group.PrecursorAdduct.IsProteomic); } else { // Custom ion node.CustomMolecule.WriteXml(writer, group.PrecursorAdduct); } // Write child elements WriteAnnotations(writer, node.Annotations); if (node.HasLibInfo) { var helpers = PeptideLibraries.SpectrumHeaderXmlHelpers; writer.WriteElements(new[] { node.LibInfo }, helpers); } if (node.HasResults) { WriteResults(writer, Settings, node.Results, EL.precursor_results, EL.precursor_peak, WriteTransitionGroupChromInfo); } if (UseCompactFormat()) { writer.WriteStartElement(EL.transition_data); var transitionData = new SkylineDocumentProto.Types.TransitionData(); transitionData.Transitions.AddRange(node.Transitions.Select(transition => transition.ToTransitionProto(Settings))); byte[] bytes = transitionData.ToByteArray(); writer.WriteBase64(bytes, 0, bytes.Length); writer.WriteEndElement(); if (WroteTransitions != null) { WroteTransitions(node.TransitionCount); } } else { foreach (TransitionDocNode nodeTransition in node.Children) { writer.WriteStartElement(EL.transition); WriteTransitionXml(writer, nodePep, node, nodeTransition); writer.WriteEndElement(); } } }
/// <summary> /// Makes sure settings loaded from XML are complete, and uses default /// values where anything is missing. /// </summary> private void ValidateLoad() { SrmSettings defaults = SrmSettingsList.GetDefault(); PeptideSettings defPep = defaults.PeptideSettings; if (PeptideSettings == null) PeptideSettings = defPep; else { PeptideSettings = PeptideSettings.MergeDefaults(defPep); } TransitionSettings defTran = defaults.TransitionSettings; if (TransitionSettings == null) TransitionSettings = defTran; else { TransitionPrediction prediction = TransitionSettings.Prediction; // Backward compatibility: handle the move of RetentionTime // from TransitionSettings to PeptideSettings after v0.1.0.0 if (TransitionSettings.Prediction == null) prediction = defTran.Prediction; else if (prediction.RetentionTime != null) { if (PeptideSettings.Prediction != null && // Make Resharper happy PeptideSettings.Prediction.RetentionTime == null) { PeptideSettings = PeptideSettings.ChangePrediction( new PeptidePrediction(prediction.RetentionTime)); } prediction = new TransitionPrediction(prediction); } TransitionFilter filter = TransitionSettings.Filter ?? defTran.Filter; TransitionLibraries libraries = TransitionSettings.Libraries ?? defTran.Libraries; TransitionIntegration integration = TransitionSettings.Integration ?? defTran.Integration; TransitionInstrument instrument = TransitionSettings.Instrument ?? defTran.Instrument; TransitionFullScan fullScan = TransitionSettings.FullScan ?? defTran.FullScan; // Backward compatibility with v2.1, get a RT filter length from peptide prediction settings if (fullScan.RetentionTimeFilterType == RetentionTimeFilterType.scheduling_windows && fullScan.RetentionTimeFilterLength == 0 && PeptideSettings.Prediction != null) { double rtFilterLen = 0; if (PeptideSettings.Prediction.UseMeasuredRTs) { rtFilterLen = PeptideSettings.Prediction.MeasuredRTWindow.Value / 2; } else if (PeptideSettings.Prediction.RetentionTime != null) { rtFilterLen = PeptideSettings.Prediction.RetentionTime.TimeWindow / 2; } if (rtFilterLen > 0) { fullScan = fullScan.ChangeRetentionTimeFilter(fullScan.RetentionTimeFilterType, rtFilterLen); } } TransitionSettings transitionSettings = new TransitionSettings(prediction, filter, libraries, integration, instrument, fullScan); // If the above null checks result in a changed PeptideSettings object, // then use the changed version. if (!Equals(TransitionSettings, transitionSettings)) TransitionSettings = transitionSettings; } // Initialize mass calculators CreatePrecursorMassCalcs(); CreateFragmentMassCalcs(); }
public void OkDialog() { var helper = new MessageBoxHelper(this); // Validate and store prediction settings string massType = comboPrecursorMass.SelectedItem.ToString(); MassType precursorMassType = MassTypeExtension.GetEnum(massType); massType = comboIonMass.SelectedItem.ToString(); MassType fragmentMassType = MassTypeExtension.GetEnum(massType); string nameCE = comboCollisionEnergy.SelectedItem.ToString(); CollisionEnergyRegression collisionEnergy = Settings.Default.GetCollisionEnergyByName(nameCE); string nameDP = comboDeclusterPotential.SelectedItem.ToString(); DeclusteringPotentialRegression declusteringPotential = Settings.Default.GetDeclusterPotentialByName(nameDP); string nameCoV = comboCompensationVoltage.SelectedItem.ToString(); CompensationVoltageParameters compensationVoltage = Settings.Default.GetCompensationVoltageByName(nameCoV); string nameOptLib = comboOptimizationLibrary.SelectedItem.ToString(); OptimizationLibrary optimizationLibrary = Settings.Default.GetOptimizationLibraryByName(nameOptLib); OptimizedMethodType optimizedMethodType = OptimizedMethodType.None; if (cbUseOptimized.Checked) { optimizedMethodType = OptimizedMethodTypeExtension.GetEnum(comboOptimizeType.SelectedItem.ToString()); } TransitionPrediction prediction = new TransitionPrediction(precursorMassType, fragmentMassType, collisionEnergy, declusteringPotential, compensationVoltage, optimizationLibrary, optimizedMethodType); Helpers.AssignIfEquals(ref prediction, Prediction); // Validate and store filter settings int[] precursorCharges; int min = TransitionGroup.MIN_PRECURSOR_CHARGE; int max = TransitionGroup.MAX_PRECURSOR_CHARGE; if (!helper.ValidateNumberListTextBox(tabControl1, (int)TABS.Filter, textPrecursorCharges, min, max, out precursorCharges)) { return; } precursorCharges = precursorCharges.Distinct().ToArray(); int[] productCharges; min = Transition.MIN_PRODUCT_CHARGE; max = Transition.MAX_PRODUCT_CHARGE; if (!helper.ValidateNumberListTextBox(tabControl1, (int)TABS.Filter, textIonCharges, min, max, out productCharges)) { return; } productCharges = productCharges.Distinct().ToArray(); IonType[] types = TransitionFilter.ParseTypes(textIonTypes.Text, new IonType[0]); if (types.Length == 0) { helper.ShowTextBoxError(tabControl1, (int)TABS.Filter, textIonTypes, Resources.TransitionSettingsUI_OkDialog_Ion_types_must_contain_a_comma_separated_list_of_ion_types_a_b_c_x_y_z_and_p_for_precursor); return; } types = types.Distinct().ToArray(); double exclusionWindow = 0; if (!string.IsNullOrEmpty(textExclusionWindow.Text) && !Equals(textExclusionWindow.Text, exclusionWindow.ToString(LocalizationHelper.CurrentCulture))) { if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Filter, textExclusionWindow, TransitionFilter.MIN_EXCLUSION_WINDOW, TransitionFilter.MAX_EXCLUSION_WINDOW, out exclusionWindow)) { return; } } string fragmentRangeFirst = TransitionFilter.GetStartFragmentNameFromLabel(comboRangeFrom.SelectedItem.ToString()); string fragmentRangeLast = TransitionFilter.GetEndFragmentNameFromLabel(comboRangeTo.SelectedItem.ToString()); var measuredIons = _driverIons.Chosen; bool autoSelect = cbAutoSelect.Checked; bool exclusionUseDIAWindow = FullScanSettingsControl.IsDIA() && cbExclusionUseDIAWindow.Checked; var filter = new TransitionFilter(precursorCharges, productCharges, types, fragmentRangeFirst, fragmentRangeLast, measuredIons, exclusionWindow, exclusionUseDIAWindow, autoSelect); Helpers.AssignIfEquals(ref filter, Filter); // Validate and store library settings TransitionLibraryPick pick = TransitionLibraryPick.none; if (cbLibraryPick.Checked) { if (radioAll.Checked) { pick = TransitionLibraryPick.all; } else if (radioAllAndFiltered.Checked) { pick = TransitionLibraryPick.all_plus; } else { pick = TransitionLibraryPick.filter; } } double ionMatchTolerance; double minTol = TransitionLibraries.MIN_MATCH_TOLERANCE; double maxTol = TransitionLibraries.MAX_MATCH_TOLERANCE; if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Library, textTolerance, minTol, maxTol, out ionMatchTolerance)) { return; } int ionCount = Libraries.IonCount; if (pick != TransitionLibraryPick.none) { min = TransitionLibraries.MIN_ION_COUNT; max = TransitionLibraries.MAX_ION_COUNT; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Library, textIonCount, min, max, out ionCount)) { return; } } TransitionLibraries libraries = new TransitionLibraries(ionMatchTolerance, ionCount, pick); Helpers.AssignIfEquals(ref libraries, Libraries); // This dialog does not yet change integration settings TransitionIntegration integration = _transitionSettings.Integration; // Validate and store instrument settings int minMz; min = TransitionInstrument.MIN_MEASUREABLE_MZ; max = TransitionInstrument.MAX_MEASURABLE_MZ - TransitionInstrument.MIN_MZ_RANGE; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMinMz, min, max, out minMz)) { return; } int maxMz; min = minMz + TransitionInstrument.MIN_MZ_RANGE; max = TransitionInstrument.MAX_MEASURABLE_MZ; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxMz, min, max, out maxMz)) { return; } bool isDynamicMin = cbDynamicMinimum.Checked; double mzMatchTolerance; minTol = TransitionInstrument.MIN_MZ_MATCH_TOLERANCE; maxTol = TransitionInstrument.MAX_MZ_MATCH_TOLERANCE; if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Instrument, textMzMatchTolerance, minTol, maxTol, out mzMatchTolerance)) { return; } int?maxTrans = null; if (!string.IsNullOrEmpty(textMaxTrans.Text)) { int maxTransTemp; min = TransitionInstrument.MIN_TRANSITION_MAX; max = TransitionInstrument.MAX_TRANSITION_MAX; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxTrans, min, max, out maxTransTemp)) { return; } maxTrans = maxTransTemp; } int?maxInclusions = null; if (!string.IsNullOrEmpty(textMaxInclusions.Text)) { int maxInclusionsTemp; min = TransitionInstrument.MIN_INCLUSION_MAX; max = TransitionInstrument.MAX_INCLUSION_MAX; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxInclusions, min, max, out maxInclusionsTemp)) { return; } maxInclusions = maxInclusionsTemp; } int?minTime = null, maxTime = null; min = TransitionInstrument.MIN_TIME; max = TransitionInstrument.MAX_TIME; if (!string.IsNullOrEmpty(textMinTime.Text)) { int minTimeTemp; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMinTime, min, max, out minTimeTemp)) { return; } minTime = minTimeTemp; } if (!string.IsNullOrEmpty(textMaxTime.Text)) { int maxTimeTemp; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxTime, min, max, out maxTimeTemp)) { return; } maxTime = maxTimeTemp; } if (minTime.HasValue && maxTime.HasValue && maxTime.Value - minTime.Value < TransitionInstrument.MIN_TIME_RANGE) { helper.ShowTextBoxError(tabControl1, (int)TABS.Instrument, textMaxTime, string.Format(Resources.TransitionSettingsUI_OkDialog_The_allowable_retention_time_range__0__to__1__must_be_at_least__2__minutes_apart, minTime, maxTime, TransitionInstrument.MIN_TIME_RANGE)); return; } TransitionInstrument instrument = new TransitionInstrument(minMz, maxMz, isDynamicMin, mzMatchTolerance, maxTrans, maxInclusions, minTime, maxTime); Helpers.AssignIfEquals(ref instrument, Instrument); // Validate and store full-scan settings // If high resolution MS1 filtering is enabled, make sure precursor m/z type // is monoisotopic and isotope enrichments are set FullScanPrecursorIsotopes precursorIsotopes = PrecursorIsotopesCurrent; FullScanMassAnalyzerType precursorAnalyzerType = PrecursorMassAnalyzer; if (precursorIsotopes != FullScanPrecursorIsotopes.None && precursorAnalyzerType != FullScanMassAnalyzerType.qit) { if (precursorMassType != MassType.Monoisotopic) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_High_resolution_MS1_filtering_requires_use_of_monoisotopic_precursor_masses); tabControl1.SelectedIndex = (int)TABS.Prediction; comboPrecursorMass.Focus(); return; } if (FullScanSettingsControl.Enrichments == null) { tabControl1.SelectedIndex = (int)TABS.FullScan; MessageDlg.Show(GetParentForm(this), Resources.TransitionSettingsUI_OkDialog_Isotope_enrichment_settings_are_required_for_MS1_filtering_on_high_resolution_mass_spectrometers); FullScanSettingsControl.ComboEnrichmentsSetFocus(); return; } } IsolationScheme isolationScheme = FullScanSettingsControl.IsolationScheme; FullScanAcquisitionMethod acquisitionMethod = AcquisitionMethod; if (isolationScheme == null && acquisitionMethod == FullScanAcquisitionMethod.DIA) { tabControl1.SelectedIndex = (int)TABS.FullScan; MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_An_isolation_scheme_is_required_to_match_multiple_precursors); FullScanSettingsControl.ComboIsolationSchemeSetFocus(); return; } if (isolationScheme != null && isolationScheme.WindowsPerScan.HasValue && !maxInclusions.HasValue) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Before_performing_a_multiplexed_DIA_scan_the_instrument_s_firmware_inclusion_limit_must_be_specified); tabControl1.SelectedIndex = (int)TABS.Instrument; textMaxInclusions.Focus(); return; } if (FullScanSettingsControl.IsDIA() && cbExclusionUseDIAWindow.Checked) { if (FullScanSettingsControl.IsolationScheme.IsAllIons) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precusor_exclusion_when__All_Ions__is_selected_as_the_isolation_scheme___To_use_the_DIA_window_for_precusor_exclusion__change_the_isolation_scheme_in_the_Full_Scan_settings_); tabControl1.SelectedIndex = (int)TABS.Filter; cbExclusionUseDIAWindow.Focus(); return; } if (FullScanSettingsControl.IsolationScheme.FromResults) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precursor_exclusion_when_isolation_scheme_does_not_contain_prespecified_windows___Please_select_an_isolation_scheme_with_prespecified_windows_); tabControl1.SelectedIndex = (int)TABS.Filter; cbExclusionUseDIAWindow.Focus(); return; } } TransitionFullScan fullScan; if (!FullScanSettingsControl.ValidateFullScanSettings(helper, out fullScan, tabControl1, (int)TABS.FullScan)) { return; } Helpers.AssignIfEquals(ref fullScan, FullScan); TransitionSettings settings = new TransitionSettings(prediction, filter, libraries, integration, instrument, fullScan); // Only update, if anything changed if (!Equals(settings, _transitionSettings)) { if (!_parent.ChangeSettingsMonitored(this, Resources.TransitionSettingsUI_OkDialog_Changing_transition_settings, s => s.ChangeTransitionSettings(settings))) { return; } _transitionSettings = settings; } DialogResult = DialogResult.OK; }
public void ReporterIonTest() { // Test the code that updates old-style formulas Assert.AreEqual("C5C'H13N2", BioMassCalc.AddH("C5C'H12N2")); Assert.AreEqual("CO2H", BioMassCalc.AddH("CO2")); var docOriginal = new SrmDocument(SrmSettingsList.GetDefault().ChangeTransitionInstrument(instrument => instrument.ChangeMinMz(10))); // H2O2 is not very heavy! IdentityPath path; SrmDocument docPeptide = docOriginal.ImportFasta(new StringReader(">peptide1\nPEPMCIDEPR"), true, IdentityPath.ROOT, out path); // One of the prolines should have caused an extra transition Assert.AreEqual(4, docPeptide.PeptideTransitionCount); Assert.IsTrue(docPeptide.PeptideTransitions.Contains(nodeTran => nodeTran.Transition.Ordinal == 8)); const string formula = "H2O2"; // This was H2O, but that falls below mz=10 at z > 1 const string hydrogenPeroxide = "Hydrogen Perxoide"; var reporterIons = new[] { new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.SINGLY_PROTONATED), new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.DOUBLY_PROTONATED), new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.TRIPLY_PROTONATED), MeasuredIonList.NTERM_PROLINE }; SrmDocument docReporterIon = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(reporterIons))); AssertEx.IsDocumentTransitionCount(docReporterIon, 7); //Check With Monoisotopic var mass = BioMassCalc.MONOISOTOPIC.CalculateMassFromFormula(formula); for (int i = 0; i < 3; i++) { TransitionDocNode tranNode = docReporterIon.MoleculeTransitions.ElementAt(i); Transition tran = tranNode.Transition; Assert.AreEqual(reporterIons[i].SettingsCustomIon, tran.CustomIon); Assert.AreEqual(tran.Charge, i + 1); Assert.AreEqual(BioMassCalc.CalculateIonMz(mass, tran.Adduct), tranNode.Mz, BioMassCalc.MassElectron / 100); } //Check with Average TransitionPrediction predSettings = docReporterIon.Settings.TransitionSettings.Prediction.ChangeFragmentMassType(MassType.Average); TransitionSettings tranSettings = docReporterIon.Settings.TransitionSettings.ChangePrediction(predSettings); SrmSettings srmSettings = docReporterIon.Settings.ChangeTransitionSettings(tranSettings); SrmDocument averageDocument = docReporterIon.ChangeSettings(srmSettings); mass = BioMassCalc.AVERAGE.CalculateMassFromFormula(formula); for (int i = 0; i < 3; i++) { TransitionDocNode tranNode = averageDocument.MoleculeTransitions.ElementAt(i); Transition tran = tranNode.Transition; Assert.AreEqual(reporterIons[i].SettingsCustomIon, tran.CustomIon); Assert.AreEqual(tran.Charge, i + 1); Assert.AreEqual(BioMassCalc.CalculateIonMz(mass, tran.Adduct), tranNode.Mz, BioMassCalc.MassElectron / 100); } //Make sure the rest of the transitions aren't reporter ions for (int i = 3; i < 7; i++) { Transition tran = docReporterIon.MoleculeTransitions.ElementAt(i).Transition; Assert.AreNotEqual(tran.CustomIon, reporterIons); } var optionalIon = new MeasuredIon(hydrogenPeroxide, formula, null, null, Adduct.SINGLY_PROTONATED, true); SrmDocument optionalDoc = docPeptide.ChangeSettings(docPeptide.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { optionalIon }))); Assert.AreEqual(3, optionalDoc.PeptideTransitionCount); optionalDoc = optionalDoc.ChangeSettings(optionalDoc.Settings.ChangeTransitionFilter(filter => filter.ChangeMeasuredIons(new[] { optionalIon.ChangeIsOptional(false) }))); AssertEx.IsDocumentTransitionCount(optionalDoc, 4); Assert.AreEqual(optionalIon.ChangeIsOptional(false).SettingsCustomIon, optionalDoc.MoleculeTransitions.ElementAt(0).Transition.CustomIon); optionalDoc = optionalDoc.ChangeSettings( optionalDoc.Settings.ChangeTransitionFilter( filter => filter.ChangeMeasuredIons(new[] { optionalIon.ChangeIsOptional(true) }))); TransitionGroupDocNode nodeGroup = optionalDoc.MoleculeTransitionGroups.ElementAt(0); var filteredNodes = nodeGroup.GetPrecursorChoices(optionalDoc.Settings, optionalDoc.Molecules.ElementAt(0).ExplicitMods, true) .Cast <TransitionDocNode>() .Where(node => Equals(node.Transition.CustomIon, optionalIon.SettingsCustomIon)); var unfilteredNodes = nodeGroup.GetPrecursorChoices(optionalDoc.Settings, optionalDoc.Molecules.ElementAt(0).ExplicitMods, false) .Cast <TransitionDocNode>() .Where(node => Equals(node.Transition.CustomIon, optionalIon.SettingsCustomIon)); Assert.AreEqual(0, filteredNodes.Count()); Assert.AreEqual(1, unfilteredNodes.Count()); }
public void OkDialog() { var helper = new MessageBoxHelper(this); // Validate and store prediction settings string massType = comboPrecursorMass.SelectedItem.ToString(); MassType precursorMassType = MassTypeExtension.GetEnum(massType); massType = comboIonMass.SelectedItem.ToString(); MassType fragmentMassType = MassTypeExtension.GetEnum(massType); string nameCE = comboCollisionEnergy.SelectedItem.ToString(); CollisionEnergyRegression collisionEnergy = Settings.Default.GetCollisionEnergyByName(nameCE); string nameDP = comboDeclusterPotential.SelectedItem.ToString(); DeclusteringPotentialRegression declusteringPotential = Settings.Default.GetDeclusterPotentialByName(nameDP); string nameCoV = comboCompensationVoltage.SelectedItem.ToString(); CompensationVoltageParameters compensationVoltage = Settings.Default.GetCompensationVoltageByName(nameCoV); string nameOptLib = comboOptimizationLibrary.SelectedItem.ToString(); OptimizationLibrary optimizationLibrary = Settings.Default.GetOptimizationLibraryByName(nameOptLib); OptimizedMethodType optimizedMethodType = OptimizedMethodType.None; if (cbUseOptimized.Checked) { optimizedMethodType = OptimizedMethodTypeExtension.GetEnum(comboOptimizeType.SelectedItem.ToString()); } TransitionPrediction prediction = new TransitionPrediction(precursorMassType, fragmentMassType, collisionEnergy, declusteringPotential, compensationVoltage, optimizationLibrary, optimizedMethodType); Helpers.AssignIfEquals(ref prediction, Prediction); // Validate and store filter settings int[] precursorCharges; int min = TransitionGroup.MIN_PRECURSOR_CHARGE; int max = TransitionGroup.MAX_PRECURSOR_CHARGE; if (!helper.ValidateNumberListTextBox(tabControl1, (int) TABS.Filter, textPrecursorCharges, min, max, out precursorCharges)) return; precursorCharges = precursorCharges.Distinct().ToArray(); int[] productCharges; min = Transition.MIN_PRODUCT_CHARGE; max = Transition.MAX_PRODUCT_CHARGE; if (!helper.ValidateNumberListTextBox(tabControl1, (int) TABS.Filter, textIonCharges, min, max, out productCharges)) return; productCharges = productCharges.Distinct().ToArray(); IonType[] types = TransitionFilter.ParseTypes(textIonTypes.Text, new IonType[0]); if (types.Length == 0) { helper.ShowTextBoxError(tabControl1, (int) TABS.Filter, textIonTypes, Resources.TransitionSettingsUI_OkDialog_Ion_types_must_contain_a_comma_separated_list_of_ion_types_a_b_c_x_y_z_and_p_for_precursor); return; } types = types.Distinct().ToArray(); double exclusionWindow = 0; if (!string.IsNullOrEmpty(textExclusionWindow.Text) && !Equals(textExclusionWindow.Text, exclusionWindow.ToString(LocalizationHelper.CurrentCulture))) { if (!helper.ValidateDecimalTextBox(tabControl1, (int)TABS.Filter, textExclusionWindow, TransitionFilter.MIN_EXCLUSION_WINDOW, TransitionFilter.MAX_EXCLUSION_WINDOW, out exclusionWindow)) { return; } } string fragmentRangeFirst = TransitionFilter.GetStartFragmentNameFromLabel(comboRangeFrom.SelectedItem.ToString()); string fragmentRangeLast = TransitionFilter.GetEndFragmentNameFromLabel(comboRangeTo.SelectedItem.ToString()); var measuredIons = _driverIons.Chosen; bool autoSelect = cbAutoSelect.Checked; bool exclusionUseDIAWindow = FullScanSettingsControl.IsDIA() && cbExclusionUseDIAWindow.Checked; var filter = new TransitionFilter(precursorCharges, productCharges, types, fragmentRangeFirst, fragmentRangeLast, measuredIons, exclusionWindow, exclusionUseDIAWindow, autoSelect); Helpers.AssignIfEquals(ref filter, Filter); // Validate and store library settings TransitionLibraryPick pick = TransitionLibraryPick.none; if (cbLibraryPick.Checked) { if (radioAll.Checked) pick = TransitionLibraryPick.all; else if (radioAllAndFiltered.Checked) pick = TransitionLibraryPick.all_plus; else pick = TransitionLibraryPick.filter; } double ionMatchTolerance; double minTol = TransitionLibraries.MIN_MATCH_TOLERANCE; double maxTol = TransitionLibraries.MAX_MATCH_TOLERANCE; if (!helper.ValidateDecimalTextBox(tabControl1, (int) TABS.Library, textTolerance, minTol, maxTol, out ionMatchTolerance)) return; int ionCount = Libraries.IonCount; if (pick != TransitionLibraryPick.none) { min = TransitionLibraries.MIN_ION_COUNT; max = TransitionLibraries.MAX_ION_COUNT; if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Library, textIonCount, min, max, out ionCount)) return; } TransitionLibraries libraries = new TransitionLibraries(ionMatchTolerance, ionCount, pick); Helpers.AssignIfEquals(ref libraries, Libraries); // This dialog does not yet change integration settings TransitionIntegration integration = _transitionSettings.Integration; // Validate and store instrument settings int minMz; min = TransitionInstrument.MIN_MEASUREABLE_MZ; max = TransitionInstrument.MAX_MEASURABLE_MZ - TransitionInstrument.MIN_MZ_RANGE; if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Instrument, textMinMz, min, max, out minMz)) return; int maxMz; min = minMz + TransitionInstrument.MIN_MZ_RANGE; max = TransitionInstrument.MAX_MEASURABLE_MZ; if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Instrument, textMaxMz, min, max, out maxMz)) return; bool isDynamicMin = cbDynamicMinimum.Checked; double mzMatchTolerance; minTol = TransitionInstrument.MIN_MZ_MATCH_TOLERANCE; maxTol = TransitionInstrument.MAX_MZ_MATCH_TOLERANCE; if (!helper.ValidateDecimalTextBox(tabControl1, (int) TABS.Instrument, textMzMatchTolerance, minTol, maxTol, out mzMatchTolerance)) return; int? maxTrans = null; if (!string.IsNullOrEmpty(textMaxTrans.Text)) { int maxTransTemp; min = TransitionInstrument.MIN_TRANSITION_MAX; max = TransitionInstrument.MAX_TRANSITION_MAX; if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Instrument, textMaxTrans, min, max, out maxTransTemp)) return; maxTrans = maxTransTemp; } int? maxInclusions = null; if (!string.IsNullOrEmpty(textMaxInclusions.Text)) { int maxInclusionsTemp; min = TransitionInstrument.MIN_INCLUSION_MAX; max = TransitionInstrument.MAX_INCLUSION_MAX; if (!helper.ValidateNumberTextBox(tabControl1, (int) TABS.Instrument, textMaxInclusions, min, max, out maxInclusionsTemp)) return; maxInclusions = maxInclusionsTemp; } int? minTime = null, maxTime = null; min = TransitionInstrument.MIN_TIME; max = TransitionInstrument.MAX_TIME; if (!string.IsNullOrEmpty(textMinTime.Text)) { int minTimeTemp; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMinTime, min, max, out minTimeTemp)) return; minTime = minTimeTemp; } if (!string.IsNullOrEmpty(textMaxTime.Text)) { int maxTimeTemp; if (!helper.ValidateNumberTextBox(tabControl1, (int)TABS.Instrument, textMaxTime, min, max, out maxTimeTemp)) return; maxTime = maxTimeTemp; } if (minTime.HasValue && maxTime.HasValue && maxTime.Value - minTime.Value < TransitionInstrument.MIN_TIME_RANGE) { helper.ShowTextBoxError(tabControl1, (int) TABS.Instrument, textMaxTime, string.Format(Resources.TransitionSettingsUI_OkDialog_The_allowable_retention_time_range__0__to__1__must_be_at_least__2__minutes_apart, minTime, maxTime, TransitionInstrument.MIN_TIME_RANGE)); return; } TransitionInstrument instrument = new TransitionInstrument(minMz, maxMz, isDynamicMin, mzMatchTolerance, maxTrans, maxInclusions, minTime, maxTime); Helpers.AssignIfEquals(ref instrument, Instrument); // Validate and store full-scan settings // If high resolution MS1 filtering is enabled, make sure precursor m/z type // is monoisotopic and isotope enrichments are set FullScanPrecursorIsotopes precursorIsotopes = PrecursorIsotopesCurrent; FullScanMassAnalyzerType precursorAnalyzerType = PrecursorMassAnalyzer; if (precursorIsotopes != FullScanPrecursorIsotopes.None && precursorAnalyzerType != FullScanMassAnalyzerType.qit) { if (precursorMassType != MassType.Monoisotopic) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_High_resolution_MS1_filtering_requires_use_of_monoisotopic_precursor_masses); tabControl1.SelectedIndex = (int)TABS.Prediction; comboPrecursorMass.Focus(); return; } if (FullScanSettingsControl.Enrichments == null) { tabControl1.SelectedIndex = (int) TABS.FullScan; MessageDlg.Show(GetParentForm(this), Resources.TransitionSettingsUI_OkDialog_Isotope_enrichment_settings_are_required_for_MS1_filtering_on_high_resolution_mass_spectrometers); FullScanSettingsControl.ComboEnrichmentsSetFocus(); return; } } IsolationScheme isolationScheme = FullScanSettingsControl.IsolationScheme; FullScanAcquisitionMethod acquisitionMethod = AcquisitionMethod; if (isolationScheme == null && acquisitionMethod == FullScanAcquisitionMethod.DIA) { tabControl1.SelectedIndex = (int)TABS.FullScan; MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_An_isolation_scheme_is_required_to_match_multiple_precursors); FullScanSettingsControl.ComboIsolationSchemeSetFocus(); return; } if (isolationScheme != null && isolationScheme.WindowsPerScan.HasValue && !maxInclusions.HasValue) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Before_performing_a_multiplexed_DIA_scan_the_instrument_s_firmware_inclusion_limit_must_be_specified); tabControl1.SelectedIndex = (int)TABS.Instrument; textMaxInclusions.Focus(); return; } if (FullScanSettingsControl.IsDIA() && cbExclusionUseDIAWindow.Checked) { if (FullScanSettingsControl.IsolationScheme.IsAllIons) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precusor_exclusion_when__All_Ions__is_selected_as_the_isolation_scheme___To_use_the_DIA_window_for_precusor_exclusion__change_the_isolation_scheme_in_the_Full_Scan_settings_); tabControl1.SelectedIndex = (int)TABS.Filter; cbExclusionUseDIAWindow.Focus(); return; } if (FullScanSettingsControl.IsolationScheme.FromResults) { MessageDlg.Show(this, Resources.TransitionSettingsUI_OkDialog_Cannot_use_DIA_window_for_precursor_exclusion_when_isolation_scheme_does_not_contain_prespecified_windows___Please_select_an_isolation_scheme_with_prespecified_windows_); tabControl1.SelectedIndex = (int)TABS.Filter; cbExclusionUseDIAWindow.Focus(); return; } } TransitionFullScan fullScan; if (!FullScanSettingsControl.ValidateFullScanSettings(helper, out fullScan, tabControl1, (int)TABS.FullScan)) return; Helpers.AssignIfEquals(ref fullScan, FullScan); TransitionSettings settings = new TransitionSettings(prediction, filter, libraries, integration, instrument, fullScan); // Only update, if anything changed if (!Equals(settings, _transitionSettings)) { if (!_parent.ChangeSettingsMonitored(this, Resources.TransitionSettingsUI_OkDialog_Changing_transition_settings, s => s.ChangeTransitionSettings(settings))) { return; } _transitionSettings = settings; } DialogResult = DialogResult.OK; }