Пример #1
0
        public void TestPermuteComplexIons()
        {
            var mainPeptide      = new Peptide("MERCURY");
            var srmSettings      = SrmSettingsList.GetDefault();
            var transitionFilter = srmSettings.TransitionSettings.Filter;

            transitionFilter = transitionFilter
                               .ChangeFragmentRangeFirstName(TransitionFilter.StartFragmentFinder.ION_1.Name)
                               .ChangeFragmentRangeLastName(@"last ion")
                               .ChangePeptideIonTypes(new[] { IonType.precursor, IonType.y, IonType.b });
            srmSettings = srmSettings.ChangeTransitionSettings(
                srmSettings.TransitionSettings.ChangeFilter(transitionFilter));

            var transitionGroup           = new TransitionGroup(mainPeptide, Adduct.SINGLY_PROTONATED, IsotopeLabelType.light);
            var crosslinkerDef            = new StaticMod("disulfide", "C", null, "-H2");
            var linkedPeptide             = new LinkedPeptide(new Peptide("ARSENIC"), 6, null);
            var crosslinkMod              = new ExplicitMod(3, crosslinkerDef).ChangeLinkedPeptide(linkedPeptide);
            var explicitModsWithCrosslink = new ExplicitMods(mainPeptide, new[] { crosslinkMod }, new TypedExplicitModifications[0]);
            var transitionGroupDocNode    = new TransitionGroupDocNode(transitionGroup, Annotations.EMPTY, srmSettings,
                                                                       explicitModsWithCrosslink, null, ExplicitTransitionGroupValues.EMPTY, null, null, false);
            var choices = transitionGroupDocNode.GetPrecursorChoices(srmSettings, explicitModsWithCrosslink, true)
                          .Cast <TransitionDocNode>().ToArray();
            var complexFragmentIons = choices.Select(transition => transition.ComplexFragmentIon.GetName()).ToArray();

            Assert.AreNotEqual(0, complexFragmentIons.Length);
        }
        public PeptideDocNode CreateDocNodeFromSettings(LibKey key, Peptide peptide, SrmSettingsDiff diff, out TransitionGroupDocNode nodeGroupMatched)
        {
            if (!key.Target.IsProteomic)
            {
                // Scan the spectral lib entry for top N ranked (for now, that's just by intensity with high mz as tie breaker) fragments,
                // add those as mass-only fragments, or with more detail if peak annotations are present.
                foreach (var nodePep in peptide.CreateDocNodes(Settings, new MaxModFilter(0)))
                {
                    SpectrumHeaderInfo libInfo;
                    if (nodePep != null && Settings.PeptideSettings.Libraries.TryGetLibInfo(key, out libInfo))
                    {
                        var isotopeLabelType = key.Adduct.HasIsotopeLabels ? IsotopeLabelType.heavy : IsotopeLabelType.light;
                        var group            = new TransitionGroup(peptide, key.Adduct, isotopeLabelType);
                        nodeGroupMatched = new TransitionGroupDocNode(group, Annotations.EMPTY, Settings, null, libInfo, ExplicitTransitionGroupValues.EMPTY, null, null, false);
                        SpectrumPeaksInfo spectrum;
                        if (Settings.PeptideSettings.Libraries.TryLoadSpectrum(key, out spectrum))
                        {
                            // Add fragment and precursor transitions as needed
                            var transitionDocNodes =
                                Settings.TransitionSettings.Filter.SmallMoleculeIonTypes.Contains(IonType.precursor)
                                    ? nodeGroupMatched.GetPrecursorChoices(Settings, null, true) // Gives list of precursors
                                    : new List <DocNode>();

                            if (Settings.TransitionSettings.Filter.SmallMoleculeIonTypes.Contains(IonType.custom))
                            {
                                GetSmallMoleculeFragments(key, nodeGroupMatched, spectrum, transitionDocNodes);
                            }
                            nodeGroupMatched = (TransitionGroupDocNode)nodeGroupMatched.ChangeChildren(transitionDocNodes);
                            return((PeptideDocNode)nodePep.ChangeChildren(new List <DocNode>()
                            {
                                nodeGroupMatched
                            }));
                        }
                    }
                }
                nodeGroupMatched = null;
                return(null);
            }
            return(CreateDocNodeFromSettings(key.Target, peptide, diff, out nodeGroupMatched));
        }
Пример #3
0
        public void TestLooplink()
        {
            var peptide          = new Peptide("PEPTIDE");
            var srmSettings      = SrmSettingsList.GetDefault();
            var transitionFilter = srmSettings.TransitionSettings.Filter;

            transitionFilter = transitionFilter
                               .ChangeFragmentRangeFirstName(TransitionFilter.StartFragmentFinder.ION_1.Name)
                               .ChangeFragmentRangeLastName(@"last ion")
                               .ChangePeptideIonTypes(new[] { IonType.precursor, IonType.y, IonType.b });
            srmSettings = srmSettings.ChangeTransitionSettings(
                srmSettings.TransitionSettings.ChangeFilter(transitionFilter));

            var transitionGroup           = new TransitionGroup(peptide, Adduct.SINGLY_PROTONATED, IsotopeLabelType.light);
            var crosslinkerDef            = new StaticMod("dss", null, null, "C8H10O2");
            var linkedPeptide             = new LinkedPeptide(null, 5, null);
            var crosslinkMod              = new ExplicitMod(2, crosslinkerDef).ChangeLinkedPeptide(linkedPeptide);
            var explicitModsWithCrosslink = new ExplicitMods(peptide, new[] { crosslinkMod }, new TypedExplicitModifications[0]);
            var transitionGroupDocNode    = new TransitionGroupDocNode(transitionGroup, Annotations.EMPTY, srmSettings,
                                                                       explicitModsWithCrosslink, null, ExplicitTransitionGroupValues.EMPTY, null, null, false);
            var modifiedSequence = ModifiedSequence.GetModifiedSequence(srmSettings, peptide.Sequence,
                                                                        explicitModsWithCrosslink, IsotopeLabelType.light);

            Assert.AreEqual("PEPTIDE-[dss@3-6]", modifiedSequence.FullNames);

            var choices = transitionGroupDocNode.GetPrecursorChoices(srmSettings, explicitModsWithCrosslink, true)
                          .Cast <TransitionDocNode>().ToArray();
            var complexFragmentIons = choices.Select(transition => transition.ComplexFragmentIon.GetName()).ToArray();
            // Make sure none of the transitions involve a cleavage in between the two ends of the looplink
            // PEpTIdE
            var yOrdinals = complexFragmentIons.Where(ion => ion.IonType == IonType.y).Select(ion => ion.Ordinal)
                            .Distinct().ToList();
            var bOrdinals = complexFragmentIons.Where(ion => ion.IonType == IonType.b).Select(ion => ion.Ordinal)
                            .Distinct().ToList();

            CollectionAssert.AreEquivalent(new[] { 6, 5, 1 }, yOrdinals);
            CollectionAssert.AreEquivalent(new[] { 1, 2, 6 }, bOrdinals);
        }
Пример #4
0
        public static Size RenderTip(PeptideDocNode nodePep,
                                     TransitionGroupDocNode nodeGroup,
                                     TransitionDocNode nodeTranSelected,
                                     SrmSettings settings,
                                     Graphics g,
                                     Size sizeMax,
                                     bool draw)
        {
            if (nodeGroup.TransitionGroup.IsCustomIon)  // TODO(bspratt) this seems to leave out a lot of detail
            {
                var customTable = new TableDesc();
                using (RenderTools rt = new RenderTools())
                {
                    customTable.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Molecule, nodeGroup.CustomMolecule.Name, rt);
                    customTable.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Precursor_charge,
                                             nodeGroup.TransitionGroup.PrecursorAdduct.AdductCharge.ToString(LocalizationHelper.CurrentCulture), rt);
                    customTable.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Precursor_mz,
                                             string.Format(@"{0:F04}", nodeGroup.PrecursorMz), rt);
                    if (nodeGroup.CustomMolecule.Formula != null)
                    {
                        customTable.AddDetailRow(Resources.TransitionTreeNode_RenderTip_Formula,
                                                 nodeGroup.CustomMolecule.Formula + nodeGroup.TransitionGroup.PrecursorAdduct.AdductFormula.ToString(LocalizationHelper.CurrentCulture), rt);
                    }
                    SizeF size = customTable.CalcDimensions(g);
                    customTable.Draw(g);
                    return(new Size((int)size.Width + 2, (int)size.Height + 2));
                }
            }
            ExplicitMods          mods    = (nodePep != null ? nodePep.ExplicitMods : null);
            IEnumerable <DocNode> choices = nodeGroup.GetPrecursorChoices(settings, mods, true).ToArray();
            HashSet <DocNode>     chosen  = new HashSet <DocNode>(nodeGroup.Children);

            // Make sure all chosen peptides get listed
            HashSet <DocNode> setChoices = new HashSet <DocNode>(choices);

            setChoices.UnionWith(chosen);
            choices = setChoices.ToArray();

            Transition tranSelected = (nodeTranSelected != null ? nodeTranSelected.Transition : null);

            IFragmentMassCalc calc = settings.GetFragmentCalc(nodeGroup.TransitionGroup.LabelType, mods);
            var aa     = nodeGroup.TransitionGroup.Peptide.Target.Sequence; // We handled custom ions above, and returned
            var masses = calc.GetFragmentIonMasses(nodeGroup.TransitionGroup.Peptide.Target);

            var filter = settings.TransitionSettings.Filter;

            // Get charges and type pairs, making sure all chosen charges are included
            var setCharges = new HashSet <Adduct>(filter.PeptideProductCharges.Where(charge =>
                                                                                     Math.Abs(charge.AdductCharge) <= Math.Abs(nodeGroup.TransitionGroup.PrecursorCharge) &&
                                                                                     Math.Sign(charge.AdductCharge) == Math.Sign(nodeGroup.TransitionGroup.PrecursorCharge)));
            HashSet <IonType> setTypes = new HashSet <IonType>(filter.PeptideIonTypes);

            foreach (TransitionDocNode nodTran in chosen)
            {
                var type = nodTran.Transition.IonType;
                if (!Transition.IsPeptideFragment(type))
                {
                    continue;
                }
                setCharges.Add(nodTran.Transition.Adduct);
                setTypes.Add(type);
            }
            setTypes.RemoveWhere(t => !Transition.IsPeptideFragment(t));
            var charges = setCharges.Where(c => c.IsProteomic).ToArray();

            Array.Sort(charges);
            IonType[] types = Transition.GetTypePairs(setTypes);

            var tableDetails = new TableDesc();
            var table        = new TableDesc();

            using (RenderTools rt = new RenderTools())
            {
                var seqModified = GetModifiedSequence(nodePep, nodeGroup, settings);
                if (!Equals(seqModified, nodeGroup.TransitionGroup.Peptide.Target))
                {
                    tableDetails.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Modified, seqModified.Sequence, rt);
                }

                var precursorCharge = nodeGroup.TransitionGroup.PrecursorAdduct;
                var precursorMz     = nodeGroup.PrecursorMz;
                tableDetails.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Precursor_charge,
                                          precursorCharge.AdductCharge.ToString(LocalizationHelper.CurrentCulture), rt);
                tableDetails.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Precursor_mz,
                                          string.Format(@"{0:F04}", precursorMz), rt);
                tableDetails.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Precursor_mh,
                                          string.Format(@"{0:F04}", nodeGroup.GetPrecursorIonMass()),
                                          rt);
                int?decoyMassShift = nodeGroup.TransitionGroup.DecoyMassShift;
                if (decoyMassShift.HasValue)
                {
                    tableDetails.AddDetailRow(Resources.TransitionGroupTreeNode_RenderTip_Decoy_Mass_Shift,
                                              decoyMassShift.Value.ToString(LocalizationHelper.CurrentCulture), rt);
                }
                if (nodeGroup.HasLibInfo)
                {
                    foreach (KeyValuePair <PeptideRankId, string> pair in nodeGroup.LibInfo.RankValues)
                    {
                        tableDetails.AddDetailRow(pair.Key.Label, pair.Value, rt);
                    }
                }

                if (charges.Length > 0 && types.Length > 0)
                {
                    var headers = new RowDesc
                    {
                        CreateHead(@"#", rt),
                        CreateHead(@"AA", rt),
                        CreateHead(@"#", rt)
                    };
                    foreach (var charge in charges)
                    {
                        string plusSub = Transition.GetChargeIndicator(charge);
                        foreach (IonType type in types)
                        {
                            CellDesc cell = CreateHead(type.ToString().ToLower() + plusSub, rt);
                            if (Transition.IsNTerminal(type))
                            {
                                headers.Insert(0, cell);
                            }
                            else
                            {
                                headers.Add(cell);
                            }
                        }
                    }
                    table.Add(headers);

                    int len = aa.Length;
                    for (int i = 0; i < len; i++)
                    {
                        CellDesc cellAA = CreateRowLabel(aa.Substring(i, 1), rt);
                        cellAA.Align = StringAlignment.Center;

                        var row = new RowDesc
                        {
                            CreateRowLabel(i == len - 1 ? string.Empty : (i + 1).ToString(CultureInfo.InvariantCulture), rt),
                            cellAA,
                            CreateRowLabel(i == 0 ? string.Empty : (len - i).ToString(CultureInfo.InvariantCulture), rt)
                        };

                        foreach (var charge in charges)
                        {
                            foreach (IonType type in types)
                            {
                                CellDesc cell;
                                if (Transition.IsNTerminal(type))
                                {
                                    if (i == len - 1)
                                    {
                                        cell = CreateData(string.Empty, rt);
                                    }
                                    else
                                    {
                                        var massH = masses[type, i];
                                        cell = CreateIon(type, i + 1, massH, charge, choices, chosen, tranSelected, rt);
                                    }
                                    row.Insert(0, cell);
                                }
                                else
                                {
                                    if (i == 0)
                                    {
                                        cell = CreateData(string.Empty, rt);
                                    }
                                    else
                                    {
                                        var massH = masses[type, i - 1];
                                        cell = CreateIon(type, len - i, massH, charge, choices, chosen, tranSelected, rt);
                                    }
                                    row.Add(cell);
                                }
                            }
                        }
                        table.Add(row);
                    }
                }

                SizeF sizeDetails = tableDetails.CalcDimensions(g);
                sizeDetails.Height += TableDesc.TABLE_SPACING;    // Spacing between details and fragments
                SizeF size = table.CalcDimensions(g);
                if (draw)
                {
                    tableDetails.Draw(g);
                    g.TranslateTransform(0, sizeDetails.Height);
                    table.Draw(g);
                    g.TranslateTransform(0, -sizeDetails.Height);
                }

                int width  = (int)Math.Round(Math.Max(sizeDetails.Width, size.Width));
                int height = (int)Math.Round(sizeDetails.Height + size.Height);
                return(new Size(width + 2, height + 2));
            }
        }
Пример #5
0
        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());
        }