コード例 #1
0
        private static IEnumerable <KeyValuePair <IsotopeLabelType, string> > GetTypedModifiedSequences(
            PeptideDocNode nodePep, SrmSettings settings)
        {
            foreach (var labelType in settings.PeptideSettings.Modifications.GetModificationTypes())
            {
                if (nodePep.Peptide.IsCustomMolecule)
                {
                    continue;
                }
                // Only return the modified sequence, if the peptide actually as a child
                // of this type.
                if (!nodePep.HasChildType(labelType))
                {
                    continue;
                }
                var calc = settings.TryGetPrecursorCalc(labelType, nodePep.ExplicitMods);
                if (calc == null)
                {
                    continue;
                }

                string modSequence = calc.GetModifiedSequence(nodePep.Peptide.Target, true).Sequence; // Never have to worry about this being a custom molecule, we already checked

                // Only return if the modified sequence contains modifications
                if (modSequence.Contains('['))
                {
                    yield return(new KeyValuePair <IsotopeLabelType, string>(labelType, modSequence));
                }
            }
        }
コード例 #2
0
        public static PeptideFormatter MakePeptideFormatter(SrmSettings srmSettings, PeptideDocNode peptideDocNode,
                                                            ModFontHolder modFontHolder)
        {
            var lightModifiedSequence =
                ModifiedSequence.GetModifiedSequence(srmSettings, peptideDocNode, IsotopeLabelType.light);
            var heavyModifiedSequences = new List <KeyValuePair <IsotopeLabelType, ModifiedSequence> >();

            foreach (var labelType in srmSettings.PeptideSettings.Modifications.GetHeavyModificationTypes())
            {
                if (!peptideDocNode.HasChildType(labelType))
                {
                    continue;
                }

                heavyModifiedSequences.Add(new KeyValuePair <IsotopeLabelType, ModifiedSequence>(labelType,
                                                                                                 ModifiedSequence.GetModifiedSequence(srmSettings, peptideDocNode, labelType)));
            }

            return(new PeptideFormatter(srmSettings, lightModifiedSequence, heavyModifiedSequences, modFontHolder));
        }
コード例 #3
0
        public static TextSequence[] CreateTextSequences(PeptideDocNode nodePep,
                                                         SrmSettings settings, string label, IDeviceContext g, ModFontHolder fonts)
        {
            // Store text and font information for all label types
            bool heavyMods         = false;
            var  listTypeSequences = new List <TextSequence> {
                CreateTypeTextSequence(nodePep, settings, IsotopeLabelType.light, fonts)
            };

            foreach (var labelType in settings.PeptideSettings.Modifications.GetHeavyModificationTypes())
            {
                // Only color for the label types actually measured in this peptide
                if (!nodePep.HasChildType(labelType))
                {
                    continue;
                }

                var textSequence = CreateTypeTextSequence(nodePep, settings, labelType, fonts);
                listTypeSequences.Add(textSequence);
                heavyMods = (heavyMods || textSequence != null);
            }

            // Calculate text sequence values for the peptide display string
            var listTextSequences = new List <TextSequence>();

            if (nodePep.Peptide.IsCustomMolecule)
            {
                listTextSequences.Add(CreatePlainTextSequence(label, fonts));
            }
            // If no modifications, use a single plain text sequence
            else if (!heavyMods && !listTypeSequences[0].Text.Contains(@"[")) // For identifying modifications
            {
                listTextSequences.Add(CreatePlainTextSequence(label, fonts));
            }
            else
            {
                var peptideFormatter = PeptideFormatter.MakePeptideFormatter(settings, nodePep, fonts);
                peptideFormatter.DisplayModificationOption = DisplayModificationOption.Current;
                peptideFormatter.DeviceContext             = g;
                string pepSequence = peptideFormatter.UnmodifiedSequence;
                int    startPep    = label.IndexOf(pepSequence, StringComparison.Ordinal);
                int    endPep      = startPep + pepSequence.Length;


                IEnumerable <TextSequence> rawTextSequences = new TextSequence[0];
                // Add prefix plain-text if necessary
                if (startPep > 0)
                {
                    string prefix = label.Substring(0, startPep);
                    rawTextSequences = rawTextSequences.Append(CreatePlainTextSequence(prefix, fonts));
                }

                rawTextSequences = rawTextSequences.Concat(Enumerable.Range(0, pepSequence.Length).Select(aaIndex => peptideFormatter.GetTextSequenceAtAaIndex(aaIndex)));
                if (endPep < label.Length)
                {
                    string suffix = label.Substring(endPep);
                    rawTextSequences = rawTextSequences.Append(CreatePlainTextSequence(suffix, fonts));
                }

                listTextSequences.AddRange(TextSequence.Coalesce(rawTextSequences));
            }

            if (g != null)
            {
                // Calculate placement for each text sequence
                int textRectWidth = 0;
                foreach (var textSequence in listTextSequences)
                {
                    Size sizeMax = new Size(int.MaxValue, int.MaxValue);
                    textSequence.Position = textRectWidth;
                    textSequence.Width    = TextRenderer.MeasureText(g, textSequence.Text,
                                                                     textSequence.Font, sizeMax, FORMAT_TEXT_SEQUENCE).
                                            Width;
                    textRectWidth += textSequence.Width;
                }
            }

            return(listTextSequences.ToArray());
        }
コード例 #4
0
        public static TextSequence[] CreateTextSequences(PeptideDocNode nodePep,
                                                         SrmSettings settings, string label, IDeviceContext g, ModFontHolder fonts)
        {
            // Store text and font information for all label types
            bool heavyMods         = false;
            var  listTypeSequences = new List <TextSequence> {
                CreateTypeTextSequence(nodePep, settings, IsotopeLabelType.light, fonts)
            };

            foreach (var labelType in settings.PeptideSettings.Modifications.GetHeavyModificationTypes())
            {
                // Only color for the label types actually measured in this peptide
                if (!nodePep.HasChildType(labelType))
                {
                    continue;
                }

                var textSequence = CreateTypeTextSequence(nodePep, settings, labelType, fonts);
                listTypeSequences.Add(textSequence);
                heavyMods = (heavyMods || textSequence != null);
            }

            // Calculate text sequence values for the peptide display string
            var listTextSequences = new List <TextSequence>();

            if (nodePep.Peptide.IsCustomIon)
            {
                listTextSequences.Add(CreatePlainTextSequence(nodePep.CustomIon.DisplayName, fonts));
            }
            // If no modifications, use a single plain text sequence
            else if (!heavyMods && !listTypeSequences[0].Text.Contains("[")) // Not L10N: For identifying modifications
            {
                listTextSequences.Add(CreatePlainTextSequence(label, fonts));
            }
            else
            {
                string pepSequence = nodePep.Peptide.Sequence;
                int    startPep    = label.IndexOf(pepSequence, StringComparison.Ordinal);
                int    endPep      = startPep + pepSequence.Length;

                // Add prefix plain-text if necessary
                if (startPep > 0)
                {
                    string prefix = label.Substring(0, startPep);
                    listTextSequences.Add(CreatePlainTextSequence(prefix, fonts));
                }

                // Enumerate amino acid characters coallescing their font information
                // into text sequences.
                var prevCharFont = new CharFont('.', fonts.Plain, Color.Black); // Not L10N: Amino acid format
                var indexes      = new int[listTypeSequences.Count];

                CharFont charFont;
                var      sb = new StringBuilder();
                while ((charFont = GetCharFont(indexes, listTypeSequences, fonts)) != null)
                {
                    if (!charFont.IsSameDisplay(prevCharFont) && sb.Length > 0)
                    {
                        listTextSequences.Add(CreateTextSequence(sb, prevCharFont));
                        sb.Remove(0, sb.Length);
                    }
                    sb.Append(charFont.Character);
                    prevCharFont = charFont;
                }
                // Add the last segment
                if (sb.Length > 0)
                {
                    listTextSequences.Add(CreateTextSequence(sb, prevCharFont));
                }

                // Add suffix plain-text if necessary
                if (endPep < label.Length)
                {
                    string suffix = label.Substring(endPep);
                    listTextSequences.Add(CreatePlainTextSequence(suffix, fonts));
                }
            }

            if (g != null)
            {
                // Calculate placement for each text sequence
                int textRectWidth = 0;
                foreach (var textSequence in listTextSequences)
                {
                    Size sizeMax = new Size(int.MaxValue, int.MaxValue);
                    textSequence.Position = textRectWidth;
                    textSequence.Width    = TextRenderer.MeasureText(g, textSequence.Text,
                                                                     textSequence.Font, sizeMax, FORMAT_TEXT_SEQUENCE).
                                            Width;
                    textRectWidth += textSequence.Width;
                }
            }

            return(listTextSequences.ToArray());
        }