示例#1
0
 public TransitionLoss(StaticMod precursorMod, FragmentLoss loss, MassType massType)
     : this()
 {
     PrecursorMod = precursorMod;
     Loss = loss;
     Mass = Loss.GetMass(massType);
 }
示例#2
0
 public TransitionLoss(StaticMod precursorMod, FragmentLoss loss, MassType massType)
     : this()
 {
     PrecursorMod = precursorMod;
     Loss         = loss;
     Mass         = Loss.GetMass(massType);
 }
示例#3
0
 public bool Equals(FragmentLoss other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.Formula, Formula) &&
            other.MonoisotopicMass.Equals(MonoisotopicMass) &&
            other.AverageMass.Equals(AverageMass) &&
            other.Inclusion.Equals(Inclusion));
 }
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string formulaLoss = _formulaBox.Formula;
            double? monoLoss = null;
            double? avgLoss = null;
            if (!string.IsNullOrEmpty(formulaLoss))
            {
                try
                {
                    double massMono = SequenceMassCalc.ParseModMass(BioMassCalc.MONOISOTOPIC, formulaLoss);
                    double massAverage = SequenceMassCalc.ParseModMass(BioMassCalc.AVERAGE, formulaLoss);
                    if (FragmentLoss.MIN_LOSS_MASS > massMono || FragmentLoss.MIN_LOSS_MASS > massAverage)
                    {
                        _formulaBox.ShowTextBoxErrorFormula(helper, string.Format(Resources.EditFragmentLossDlg_OkDialog_Neutral_loss_masses_must_be_greater_than_or_equal_to__0__,
                                                              FragmentLoss.MIN_LOSS_MASS));
                        return;
                    }
                    if (massMono > FragmentLoss.MAX_LOSS_MASS || massAverage > FragmentLoss.MAX_LOSS_MASS)
                    {
                        _formulaBox.ShowTextBoxErrorFormula(helper, string.Format(Resources.EditFragmentLossDlg_OkDialog_Neutral_loss_masses_must_be_less_than_or_equal_to__0__,
                                                              FragmentLoss.MAX_LOSS_MASS));
                        return;
                    }
                }
                catch (ArgumentException x)
                {
                    _formulaBox.ShowTextBoxErrorFormula(helper, x.Message);
                    return;
                }
            }
            else if (_formulaBox.MonoMass != null ||
                    _formulaBox.AverageMass != null)
            {
                formulaLoss = null;
                double mass;
                if (!_formulaBox.ValidateMonoText(helper, FragmentLoss.MIN_LOSS_MASS, FragmentLoss.MAX_LOSS_MASS, out mass))
                    return;
                monoLoss = mass;
                if (!_formulaBox.ValidateAverageText(helper, FragmentLoss.MIN_LOSS_MASS, FragmentLoss.MAX_LOSS_MASS, out mass))
                    return;
                avgLoss = mass;
            }
            else
            {
                _formulaBox.ShowTextBoxErrorFormula(helper,Resources.EditFragmentLossDlg_OkDialog_Please_specify_a_formula_or_constant_masses);
                return;
            }

            // Make sure the new loss does not already exist.
            var loss = new FragmentLoss(formulaLoss, monoLoss, avgLoss, Inclusion);
            if (_existing.Contains(loss))
            {
                MessageDlg.Show(this, string.Format(Resources.EditFragmentLossDlg_OkDialog_The_loss__0__already_exists, loss));
                return;
            }

            Loss = loss;

            DialogResult = DialogResult.OK;
        }
示例#5
0
        public StaticMod MatchVariableAndLossInclusion(StaticMod mod)
        {
            // Only allowed if the mods are equivalent
            Assume.IsTrue(Equivalent(mod));

            var result = this;
            if (!Equals(result.IsVariable, mod.IsVariable))
                result = result.ChangeVariable(mod.IsVariable);
            if (result.Losses != null && !ArrayUtil.EqualsDeep(result.Losses, mod.Losses))
            {
                int len = result.Losses.Count;
                var newLosses = new FragmentLoss[len];
                for (int i = 0; i < len; i++)
                {
                    newLosses[i] = result.Losses[i].ChangeInclusion(mod.Losses[i].Inclusion);
                }
                result = result.ChangeLosses(newLosses);
            }
            return result;
        }
示例#6
0
 private bool EquivalentFormulas(FragmentLoss loss1, FragmentLoss loss2)
 {
     return ArrayUtil.EqualsDeep(GetFormulaCounts(loss1.Formula).ToArray(),
                                 GetFormulaCounts(loss2.Formula).ToArray());
 }
示例#7
0
 public bool Equals(FragmentLoss other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Formula, Formula) &&
         other.MonoisotopicMass.Equals(MonoisotopicMass) &&
         other.AverageMass.Equals(AverageMass) &&
         other.Inclusion.Equals(Inclusion);
 }
示例#8
0
        protected override void DoTest()
        {
            // Create modifications used in this test
            var aquaMod = new StaticMod("Aqua 13C", "K, R", ModTerminus.C, null, LabelAtoms.C13|LabelAtoms.N15, null, null);
            var phosphoLossMod = new StaticMod("Phospho Loss", "S, T, Y", null, false, "HPO3",
                LabelAtoms.None, RelativeRT.Matching, null, null,  new[] { new FragmentLoss("H3PO4"), });
            var multipleLossMod = new StaticMod("Multiple Loss-only", "A", null, false, null,
                LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("NH3"), new FragmentLoss("H2O") });
            var explicitMassesLossMod = new StaticMod("Explicit Mass Loss", "N", null, false, null,
                LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss(null, 5, 10) });
            var variableLossMod = new StaticMod("Methionine Oxidized Loss", "M", null, true, "O",
                LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("CH3O") });

            Settings.Default.HeavyModList.Clear();
            Settings.Default.HeavyModList.Add(aquaMod);
            Settings.Default.StaticModList.Clear();
            Settings.Default.StaticModList.AddRange(StaticModList.GetDefaultsOn());
            Settings.Default.StaticModList.Add(variableLossMod);

            // Bump up the max mz a bit
            var transitionSettingsUI = ShowDialog<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI);
            RunUI(() =>
            {
                transitionSettingsUI.SelectedTab = TransitionSettingsUI.TABS.Instrument;
                transitionSettingsUI.MaxMz = 1510;
            });
            OkDialog(transitionSettingsUI, transitionSettingsUI.OkDialog);

            // Bring up add modification dialog
            var peptideSettingsUI = ShowDialog<PeptideSettingsUI>(() =>
                SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Modifications));
            var editModsDlg = ShowEditStaticModsDlg(peptideSettingsUI);
            var addModDlg = ShowAddModDlg(editModsDlg);
            // Try a few things with new loss UI on the phospho loss modification
            RunUI(() =>
            {
                addModDlg.Modification = phosphoLossMod;
                Assert.IsTrue(addModDlg.GetLossText(0).EndsWith(phosphoLossMod.Losses[0].Formula));
                addModDlg.LossSelectedIndex = 0;
                addModDlg.DeleteLoss();
            });
            // Add back the original loss with the new loss editor dialog
            RunDlg<EditFragmentLossDlg>(addModDlg.AddLoss, dlg =>
            {
                dlg.Loss = phosphoLossMod.Losses[0];
                dlg.OkDialog();
            });
            // Add a smaller formula loss with the new loss editor dialog
            var fragmentLossWater = new FragmentLoss("H2O");
            RunDlg<EditFragmentLossDlg>(addModDlg.AddLoss, dlg =>
            {
                dlg.Loss = fragmentLossWater;
                dlg.OkDialog();
            });
            // Add an explicit mass loss with the new loss editor dialog
            var fragmentLossConstants = new FragmentLoss(null, 20, 25);
            RunDlg<EditFragmentLossDlg>(addModDlg.AddLoss, dlg =>
            {
                dlg.Loss = fragmentLossConstants;
                dlg.OkDialog();
            });
            // Check the added losses, and remove all but the original loss
            RunUI(() =>
            {
                VerifyLossText(addModDlg.GetLossText(0), fragmentLossWater);
                VerifyLossText(addModDlg.GetLossText(1), fragmentLossConstants);
                VerifyLossText(addModDlg.GetLossText(2), phosphoLossMod.Losses[0]);
                addModDlg.LossSelectedIndex = 0;
                addModDlg.DeleteLoss();
                addModDlg.DeleteLoss();
            });
            OkDialog(addModDlg, addModDlg.OkDialog);
            // Add a loss modification with 2 losses and no formula
            RunDlg<EditStaticModDlg>(editModsDlg.AddItem, dlg =>
            {
                dlg.Modification = multipleLossMod;
                VerifyLossText(dlg.GetLossText(0), multipleLossMod.Losses[0]);
                VerifyLossText(dlg.GetLossText(1), multipleLossMod.Losses[1]);
                dlg.OkDialog();
            });
            // Add a loss modification with explicit numeric losses and no formula
            // starting with no losses
            var addExplicitLossDlg = ShowAddModDlg(editModsDlg);
            RunUI(() =>
            {
                addExplicitLossDlg.Modification = explicitMassesLossMod;
                addExplicitLossDlg.ShowLoss = true;
                VerifyLossText(addExplicitLossDlg.GetLossText(0), explicitMassesLossMod.Losses[0]);
                addExplicitLossDlg.LossSelectedIndex = 0;
                addExplicitLossDlg.DeleteLoss();
            });
            // Add the explicit numeric loss
            RunDlg<EditFragmentLossDlg>(addExplicitLossDlg.AddLoss, dlg =>
            {
                dlg.Loss = fragmentLossConstants;
                dlg.OkDialog();
            });
            OkDialog(addExplicitLossDlg, addExplicitLossDlg.OkDialog);
            OkDialog(editModsDlg, editModsDlg.OkDialog);
            // Check the phospho loss modification
            RunUI(() => peptideSettingsUI.PickedStaticMods =
                new List<string>(peptideSettingsUI.PickedStaticMods) { phosphoLossMod.Name }.ToArray());
            WaitForOpenForm<PeptideSettingsUI>(); // Show Modifications tab for form testing
            OkDialog(peptideSettingsUI, peptideSettingsUI.OkDialog);

            // Add FASTA sequence
            RunUI(() => SkylineWindow.Paste(TEXT_FASTA_YEAST_7));
            // Losses not added by default without a library
            Assert.AreEqual(0, GetLossCount(SkylineWindow.Document, 1));

            // Make sure setting losses as included Always works
            {
                var docBeforeAlways = SkylineWindow.Document;
                var peptideSettingsUIAlways = ShowDialog<PeptideSettingsUI>(() =>
                    SkylineWindow.ShowPeptideSettingsUI(PeptideSettingsUI.TABS.Modifications));
                var editModsDlgAlways = ShowEditStaticModsDlg(peptideSettingsUIAlways);
                RunUI(() => editModsDlgAlways.SelectItem(phosphoLossMod.Name));
                var editModDlgAlways = ShowDialog<EditStaticModDlg>(editModsDlgAlways.EditItem);
                RunUI(() => editModDlgAlways.LossSelectedIndex = 0);
                RunDlg<EditFragmentLossDlg>(editModDlgAlways.EditLoss, dlg =>
                {
                    dlg.Inclusion = LossInclusion.Always;
                    dlg.OkDialog();
                });
                OkDialog(editModDlgAlways, editModDlgAlways.OkDialog);
                OkDialog(editModsDlgAlways, editModsDlgAlways.OkDialog);
                OkDialog(peptideSettingsUIAlways, peptideSettingsUIAlways.OkDialog);
                var docAfterAlways = WaitForDocumentChange(docBeforeAlways);
                Assert.AreEqual(5, GetLossCount(docAfterAlways, 1));
                AssertEx.Serializable(docAfterAlways);
                // Undo and revert to original phospo loss modification definition
                RunUI(SkylineWindow.Undo);
                Settings.Default.StaticModList.SetValue(phosphoLossMod);
            }

            // Show losses in the pick list
            var docFasta = WaitForProteinMetadataBackgroundLoaderCompletedUI();
            SelectNode(SrmDocument.Level.TransitionGroups, 0);
            RunDlg<PopupPickList>(SkylineWindow.ShowPickChildrenInTest, dlg =>
            {
                dlg.ApplyFilter(false);
                var losses = GetLossGroups(dlg.ItemNames).ToArray();
                Assert.AreEqual(1, losses.Length);
                VerifyLossGroup(losses, 0, 98, 124);
                dlg.ToggleFind();
                dlg.SearchString = "-98";
                dlg.ToggleItem(0);
                dlg.ToggleItem(1);
                dlg.OnOk();
            });
            var docLoss = WaitForDocumentChange(docFasta);
            // Make sure two losses were added
            Assert.AreEqual(2, GetLossCount(docLoss, 1));

            // Allow 2 neutral losses per fragment
            RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, dlg =>
            {
                dlg.MaxNeutralLosses = 2;
                dlg.OkDialog();
            });

            var docLoss2 = WaitForDocumentChange(docLoss);

            // Make sure 2 phospho losses are now possible
            IGrouping<double, string>[] losses1 = null;
            RunDlg<PopupPickList>(SkylineWindow.ShowPickChildrenInTest, dlg =>
            {
                dlg.ApplyFilter(false);
                losses1 = GetLossGroups(dlg.ItemNames).ToArray();
                Assert.AreEqual(2, losses1.Length);
                VerifyLossGroup(losses1, 0, 98, 124);
                VerifyLossGroup(losses1, 1, 196, 109);
                dlg.OnCancel();
            });

            // Add a modification with multiple possible losses
            RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, dlg =>
            {
                dlg.PickedStaticMods = new List<string>(dlg.PickedStaticMods)
                    { multipleLossMod.Name }.ToArray();
                dlg.OkDialog();
            });

            var docLossMulti = WaitForDocumentChange(docLoss2);

            // Make sure all combinations of 2 except 2 of the multiple
            // losses are possible, since only one amino acid A exists in this
            // peptide.
            RunDlg<PopupPickList>(SkylineWindow.ShowPickChildrenInTest, dlg =>
            {
                dlg.ApplyFilter(false);
                var losses = GetLossGroups(dlg.ItemNames).ToArray();
                Assert.AreEqual(6, losses.Length);
                VerifyLossGroup(losses, 0, 17, 66);
                VerifyLossGroup(losses, 1, 18, 66);
                VerifyLossGroup(losses, 2, 98, 124);
                VerifyLossGroup(losses, 3, 115, 61);
                VerifyLossGroup(losses, 4, 116, 61);
                VerifyLossGroup(losses, 5, 196, 109);
                AssertEx.NoDiff(TextUtil.LineSeparate(losses1[0].ToArray()), TextUtil.LineSeparate(losses[2].ToArray()));
                AssertEx.NoDiff(TextUtil.LineSeparate(losses1[1].ToArray()), TextUtil.LineSeparate(losses[5].ToArray()));
                // Add new neutral loss transitions to the document
                dlg.ToggleFind();
                dlg.SearchString = "-17]";
                dlg.ToggleItem(0);
                dlg.SearchString = "-115]";
                dlg.ToggleItem(0);
                dlg.OnOk();
            });

            var docLossMultiAdded = WaitForDocumentChange(docLossMulti);
            Assert.AreEqual(1, GetLossCount(docLossMultiAdded, 2));

            // Add heavy modifications and make sure transition group is added with losses
            RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, dlg =>
            {
                dlg.PickedHeavyMods = new[] { aquaMod.Name };
                dlg.OkDialog();
            });

            var docLossMultiHeavy = WaitForDocumentChange(docLossMultiAdded);
            Assert.AreEqual(4, docLossMultiHeavy.PeptideTransitionGroupCount);
            Assert.AreEqual(8, GetLossCount(docLossMultiHeavy, 1));
            Assert.AreEqual(2, GetLossCount(docLossMultiHeavy, 2));

            // Make sure this document is serializable
            AssertEx.Serializable(docLossMultiHeavy, AssertEx.DocumentCloned);

            // Reset to just 1 neutral loss per fragment, and turn off heavy mod
            RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, dlg =>
            {
                dlg.PickedHeavyMods = new string[0];
                dlg.MaxNeutralLosses = 1;
                dlg.OkDialog();
            });

            var docLossMulti1 = WaitForDocumentChange(docLossMultiHeavy);
            Assert.AreEqual(3, GetLossCount(docLossMulti1, 1));
            Assert.AreEqual(0, GetLossCount(docLossMulti1, 2));

            // Remove all neutral loss modifications currently on the document
            // and add the constant numeric loss
            RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, dlg =>
            {
                dlg.PickedStaticMods = new[] { explicitMassesLossMod.Name };
                dlg.OkDialog();
            });

            var docNoLoss2 = WaitForDocumentChange(docLossMulti1);
            Assert.AreEqual(0, GetLossCount(docNoLoss2, 1));

            // Add a neutral loss transition with constant numeric loss
            RunDlg<PopupPickList>(SkylineWindow.ShowPickChildrenInTest, dlg =>
            {
                dlg.ApplyFilter(false);
                var losses = GetLossGroups(dlg.ItemNames).ToArray();
                Assert.AreEqual(1, losses.Length);
                VerifyLossGroup(losses, 0, 20, 85);
                // Add new neutral loss transitions to the document
                dlg.ToggleFind();
                dlg.SearchString = "-20";
                dlg.ToggleItem(0);
                dlg.OnOk();
            });

            // Verify that the expected loss was added to the document
            var docConstantMono = WaitForDocumentChange(docNoLoss2);
            Assert.AreEqual(1, GetLossCount(docConstantMono, 1));
            var pathTranLoss = docConstantMono.GetPathTo((int) SrmDocument.Level.Transitions, 0);
            var nodeTranLos = (TransitionDocNode) docConstantMono.FindNode(pathTranLoss);
            Assert.AreEqual(IonType.precursor.GetLocalizedString() + " -20", nodeTranLos.FragmentIonName);

            // Switch mass type to average
            RunDlg<TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI, dlg =>
            {
                dlg.FragmentMassType = MassType.Average;
                dlg.OkDialog();
            });

            // Make sure neutral loss changes as expected
            var docConstantAverage = WaitForDocumentChange(docConstantMono);
            Assert.AreEqual(1, GetLossCount(docConstantAverage, 1));
            nodeTranLos = (TransitionDocNode)docConstantAverage.FindNode(pathTranLoss);
            Assert.AreEqual(IonType.precursor.GetLocalizedString() + " -25", nodeTranLos.FragmentIonName);

            // Make sure the resulting document is serializable
            AssertEx.Serializable(docConstantAverage, AssertEx.DocumentCloned);
        }
示例#9
0
 private static void VerifyLossText(string lossText, FragmentLoss loss)
 {
     if (loss.Formula != null)
         Assert.IsTrue(lossText.EndsWith(loss.Formula));
     Assert.IsTrue(lossText.StartsWith(string.Format("{0:F04}", loss.MonoisotopicMass)));
 }