示例#1
0
        public static void DrawPeptideText(PeptideDocNode nodePep,
                                           SrmSettings settings,
                                           IEnumerable <TextSequence> textSequences,
                                           Graphics g,
                                           Rectangle bounds,
                                           ModFontHolder fonts,
                                           Color foreColor,
                                           Color backColor)
        {
            if (textSequences == null)
            {
                textSequences = CreateTextSequences(nodePep, settings, GetLabel(nodePep, string.Empty), g, fonts);
            }
            Rectangle rectDraw = new Rectangle(0, bounds.Y, 0, bounds.Height);

            foreach (var textSequence in textSequences)
            {
                rectDraw.X     = textSequence.Position + bounds.X + TreeViewMS.PADDING;
                rectDraw.Width = textSequence.Width;
                // Use selection highlight color, if the background is highlight.
                if (backColor != SystemColors.Highlight)
                {
                    foreColor = textSequence.Color;
                }
                TextRenderer.DrawText(g, textSequence.Text, textSequence.Font, rectDraw,
                                      foreColor, backColor, FORMAT_TEXT_SEQUENCE);
            }
        }
示例#2
0
        public static PeptideFormatter MakePeptideFormatter(SrmSettings srmSettings, PeptideDocNode peptideDocNode,
                                                            ModFontHolder modFontHolder)
        {
            var heavyLabelTypes = srmSettings.PeptideSettings.Modifications.GetHeavyModificationTypes()
                                  .Where(peptideDocNode.HasChildType).ToHashSet();

            return(MakePeptideFormatter(srmSettings, peptideDocNode.Peptide, peptideDocNode.ExplicitMods,
                                        heavyLabelTypes, modFontHolder));
        }
示例#3
0
 /// <summary>
 /// Creates a text sequence with normal font.
 /// </summary>
 public static TextSequence CreatePlainTextSequence(string text, ModFontHolder fonts)
 {
     return(new TextSequence
     {
         Text = text,
         Font = fonts.Plain,
         Color = Color.Black,
         IsPlainText = true
     });
 }
示例#4
0
 private TextSequence[] GetTextSequences(IDeviceContext g)
 {
     if (!IsMeasured)
     {
         _textSequences  = CreateTextSequences(DocNode, DocSettings, Text, g, SequenceTree.ModFonts);
         _widthText      = Text;
         _textZoomFactor = Settings.Default.TextZoom;
         _groupColors    = ModFontHolder.GetModColors();
     }
     return(_textSequences);
 }
示例#5
0
        public TextSequence GetTextSequenceAtAaIndex(int residue)
        {
            Font   font         = ModFontHolder.Plain;
            Color  color        = Color.Black;
            String strAminoAcid = UnmodifiedSequence.Substring(residue, 1);

            var modsAtResidue = GetModificationsAtResidue(residue).ToArray();

            if (modsAtResidue.Length == 0)
            {
                return(new TextSequence
                {
                    Color = color,
                    Font = font,
                    Text = strAminoAcid
                });
            }

            var firstEntry = modsAtResidue[0];

            color = ModFontHolder.GetModColor(firstEntry.Item1);
            if (modsAtResidue.Skip(1).All(entry => entry.Item2.Equals(firstEntry.Item2)))
            {
                font = ModFontHolder.GetModFont(firstEntry.Item1);
                return(new TextSequence
                {
                    Color = color,
                    Font = font,
                    Text = strAminoAcid + DisplayModificationOption.GetModificationText(SrmSettings, firstEntry.Item2)
                });
            }

            font = IsotopeLabelType.light.Equals(firstEntry.Item1)
                ? ModFontHolder.LightAndHeavy
                : ModFontHolder.GetModFont(firstEntry.Item1);
            string modText;

            if (DisplayModificationOption == DisplayModificationOption.NOT_SHOWN)
            {
                modText = strAminoAcid;
            }
            else
            {
                modText = strAminoAcid + @"[*]";
            }

            return(new TextSequence
            {
                Color = color,
                Font = font,
                Text = modText
            });
        }
示例#6
0
 public PeptideFormatter(SrmSettings srmSettings, ModifiedSequence lightModifiedSequence, IEnumerable <KeyValuePair <IsotopeLabelType, ModifiedSequence> > heavyModifiedSequences, ModFontHolder modFontHolder)
 {
     SrmSettings        = srmSettings;
     _lightSequenceInfo = new SequenceInfo(lightModifiedSequence);
     if (heavyModifiedSequences != null)
     {
         _heavySequenceInfos.AddRange(heavyModifiedSequences.Select(entry => Tuple.Create(entry.Key, new SequenceInfo(entry.Value))));
     }
     LightModifiedSequence = lightModifiedSequence;
     ModFontHolder         = modFontHolder;
     LinkedPeptides        = ImmutableSortedList <ModificationSite, PeptideFormatter> .EMPTY;
 }
示例#7
0
 public PeptideFormatter(SrmSettings srmSettings, ModifiedSequence lightModifiedSequence, IEnumerable <KeyValuePair <IsotopeLabelType, ModifiedSequence> > heavyModifiedSequences, ModFontHolder modFontHolder)
 {
     SrmSettings        = srmSettings;
     _lightSequenceInfo = new SequenceInfo(lightModifiedSequence);
     if (heavyModifiedSequences != null)
     {
         _heavySequenceInfos.AddRange(heavyModifiedSequences.Select(entry => Tuple.Create(entry.Key, new SequenceInfo(entry.Value))));
     }
     LightModifiedSequence     = lightModifiedSequence;
     ModFontHolder             = modFontHolder;
     DisplayModificationOption = DisplayModificationOption.NOT_SHOWN;
 }
示例#8
0
        public void TestNeutralLossTextSequences()
        {
            var document =
                (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(
                    new StringReader(NEUTRAL_LOSS_DOCUMENT));
            var peptideDocNode = document.Molecules.First();
            var modFontHolder  = new ModFontHolder(new Control());
            var textSequences  = PeptideTreeNode.CreateTextSequences(peptideDocNode, document.Settings, "MGFGGTLEIK", null, modFontHolder);

            VerifyTextSequences(textSequences,
                                Tuple.Create("M", FontStyle.Bold | FontStyle.Underline, Color.Black),
                                Tuple.Create("GFGGTLEIK", FontStyle.Regular, Color.Black)
                                );
        }
示例#9
0
        public void TestStaticAndHeavyTextSequences()
        {
            var document =
                (SrmDocument) new XmlSerializer(typeof(SrmDocument)).Deserialize(
                    new StringReader(STATIC_AND_HEAVY_MODIFICATIONS_DOCUMENT));
            var modFontHolder   = new ModFontHolder(new Control());
            var oxidizedPeptide = document.Molecules.First();

            VerifyTextSequences(PeptideTreeNode.CreateTextSequences(oxidizedPeptide, document.Settings, "MPEPTIDE", null, modFontHolder),
                                Tuple.Create("M", FontStyle.Bold | FontStyle.Underline, Color.Blue),
                                Tuple.Create("PEPTIDE", FontStyle.Bold, Color.Blue)
                                );

            var peptide = document.Molecules.Skip(1).First();

            VerifyTextSequences(PeptideTreeNode.CreateTextSequences(peptide, document.Settings, "MPEPTIDE", null, modFontHolder),
                                Tuple.Create("MPEPTIDE", FontStyle.Bold, Color.Blue));
        }
示例#10
0
        /// <summary>
        /// Creates a text sequence with the fully modified peptide sequence text
        /// and font information for a given label type.
        /// </summary>
        private static TextSequence CreateTypeTextSequence(PeptideDocNode nodePep, SrmSettings settings,
                                                           IsotopeLabelType labelType, ModFontHolder fonts)
        {
            var calc = settings.TryGetPrecursorCalc(labelType, nodePep.ExplicitMods);

            if (calc == null)
            {
                return(null);
            }

            return(new TextSequence
            {
                Text = nodePep.IsProteomic
                               ? calc.GetModifiedSequence(nodePep.Peptide.Sequence, true)
                               : nodePep.CustomIon.DisplayName,
                Font = fonts.GetModFont(labelType),
                Color = ModFontHolder.GetModColor(labelType)
            });
        }
示例#11
0
        /// <summary>
        /// Creates a text sequence with the fully modified peptide sequence text
        /// and font information for a given label type.
        /// </summary>
        private static TextSequence CreateTypeTextSequence(PeptideDocNode nodePep, SrmSettings settings,
                                                           IsotopeLabelType labelType, ModFontHolder fonts)
        {
            var calc = settings.TryGetPrecursorCalc(labelType, nodePep.ExplicitMods);

            if (calc == null)
            {
                return(null);
            }

            return(new TextSequence
            {
                Text = nodePep.IsProteomic
                               ? calc.GetModifiedSequence(nodePep.Peptide.Target, SequenceModFormatType.mass_diff_narrow, false).Sequence
                               : nodePep.CustomMolecule.DisplayName,
                Font = fonts.GetModFont(labelType),
                Color = ModFontHolder.GetModColor(labelType)
            });
        }
示例#12
0
        public static PeptideFormatter MakePeptideFormatter(SrmSettings srmSettings, Peptide peptide,
                                                            ExplicitMods explicitMods, ICollection <IsotopeLabelType> heavyLabelTypes,
                                                            ModFontHolder modFontHolder)
        {
            var lightModifiedSequence =
                ModifiedSequence.GetModifiedSequence(srmSettings, peptide.Sequence, explicitMods, IsotopeLabelType.light);
            var heavyModifiedSequences = new List <KeyValuePair <IsotopeLabelType, ModifiedSequence> >();

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

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

            var peptideFormatter = new PeptideFormatter(srmSettings, lightModifiedSequence, heavyModifiedSequences, modFontHolder);

            if (explicitMods != null && explicitMods.HasCrosslinks)
            {
                var linkedPeptides = new List <KeyValuePair <ModificationSite, PeptideFormatter> >();
                foreach (var entry in explicitMods.Crosslinks)
                {
                    if (entry.Value.Peptide == null)
                    {
                        continue;
                    }

                    var childFormatter = MakePeptideFormatter(srmSettings, entry.Value.Peptide,
                                                              entry.Value.ExplicitMods, heavyLabelTypes, modFontHolder)
                                         .ChangeCrosslinkedIndexAa(entry.Value.IndexAa);
                    linkedPeptides.Add(new KeyValuePair <ModificationSite, PeptideFormatter>(entry.Key, childFormatter));
                }

                peptideFormatter = peptideFormatter
                                   .ChangeLinkedPeptides(ImmutableSortedList.FromValues(linkedPeptides));
            }

            return(peptideFormatter);
        }
示例#13
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));
        }
示例#14
0
        private void UpdateAminoAcidLabel(int indexAA)
        {
            if (indexAA >= _listLabelAA.Count)
            {
                return;
            }

            FontStyle fontStyle = FontStyle.Regular;
            Color     textColor = Color.Black;

            if (!string.IsNullOrEmpty((string)_listComboStatic[indexAA].SelectedItem))
            {
                fontStyle = FontStyle.Bold | FontStyle.Underline;
            }

            for (int i = 0; i < _listListComboHeavy.Count; i++)
            {
                if (!string.IsNullOrEmpty((string)_listListComboHeavy[i][indexAA].SelectedItem))
                {
                    fontStyle |= FontStyle.Bold;
                    textColor  = ModFontHolder.GetModColor(_listLabelTypeHeavy[i]);
                    break;
                }
            }

            var label = _listLabelAA[indexAA];

            if (label.Font.Style != fontStyle)
            {
                label.Font = new Font(label.Font.Name, label.Font.SizeInPoints,
                                      fontStyle, GraphicsUnit.Point, 0);
            }

// ReSharper disable RedundantCheckBeforeAssignment
            if (label.ForeColor != textColor)
            {
                label.ForeColor = textColor;
            }
// ReSharper restore RedundantCheckBeforeAssignment
        }
示例#15
0
        public PopupPickList(IChildPicker picker, string childHeading, bool okOnDeactivate)
        {
            InitializeComponent();

            Size = SizeAll;

            cbItems.Text = childHeading;

            _modFonts = new ModFontHolder(pickListMulti);
            _nodeTip = new NodeTip(this);

            _picker = picker;
            _chosenAtStart = new List<DocNode>(picker.Chosen);
            _okOnDeactivate = okOnDeactivate;

            bool filter = tbbFilter.Checked = _picker.Filtered;
            var choices = picker.GetChoices(filter).ToArray();
            if (choices.Length != choices.Select(c => c.Id.GlobalIndex).Distinct().Count())
                throw new ArgumentException("Choices must be unique"); // Not L10N

            if (filter)
            {
                // If filtered choices do not contain a choice that
                // has already been chose, then use the unfiltered list.
                foreach (var choice in _chosenAtStart)
                {
                    if (!ContainsChoice(choices, choice))
                    {
                        choices = picker.GetChoices(false).ToArray();
                        tbbFilter.Checked = false;
                        break;
                    }
                }
            }
            SetChoices(choices, _chosenAtStart);

            if (pickListMulti.Items.Count > 0)
                pickListMulti.SelectedIndex = 0;

            // Avoid setting the property, because it will actually
            // change what is picked.
            _autoManageChildren = _picker.AutoManageChildren;
            UpdateAutoManageUI();

            // Hide the synchronize checkbox, or set its label correctly
            string synchLabelText = _picker.SynchSiblingsLabel;
            if (string.IsNullOrEmpty(synchLabelText))
            {
                cbSynchronize.Visible = false;

                // Resize to hide space for the checkbox
                var anchorList = pickListMulti.Anchor;
                pickListMulti.Anchor = anchorList & ~AnchorStyles.Bottom;
                Height = pickListMulti.Bottom + 8;
                pickListMulti.Anchor = anchorList;
            }
            else
            {
                cbSynchronize.Text = synchLabelText;
                cbSynchronize.Checked = _picker.IsSynchSiblings;
            }
        }
示例#16
0
        public TextSequence GetTextSequenceAtAaIndex(DisplayModificationOption displayModificationOption, int residue)
        {
            Font   font         = ModFontHolder.Plain;
            Color  color        = Color.Black;
            string strAminoAcid = UnmodifiedSequence.Substring(residue, 1);

            var modsAtResidue = GetModificationsAtResidue(displayModificationOption, residue).ToArray();

            if (residue == CrosslinkedIndexAa ||
                modsAtResidue.Any(labeledMod => labeledMod.Item2.Any(mod => mod.ExplicitMod.LinkedPeptide != null)) ||
                _lightSequenceInfo.LooplinkSites.Contains(residue))
            {
                return(new TextSequence
                {
                    Color = COLOR_CROSSLINK,
                    Font = ModFontHolder.LightAndHeavy,
                    Text = strAminoAcid
                });
            }
            if (modsAtResidue.Length == 0)
            {
                return(new TextSequence
                {
                    Color = color,
                    Font = font,
                    Text = strAminoAcid
                });
            }

            var firstEntry = modsAtResidue[0];

            color = ModFontHolder.GetModColor(firstEntry.Item1);
            var firstMismatch = modsAtResidue.Skip(1).FirstOrDefault(entry => !entry.Item2.Equals(firstEntry.Item2));

            if (firstMismatch == null)
            {
                font = ModFontHolder.GetModFont(firstEntry.Item1);
                return(new TextSequence
                {
                    Color = color,
                    Font = font,
                    Text = strAminoAcid + displayModificationOption.GetModificationText(SrmSettings, firstEntry.Item2)
                });
            }

            if (IsotopeLabelType.light.Equals(firstEntry.Item1))
            {
                font  = ModFontHolder.LightAndHeavy;
                color = ModFontHolder.GetModColor(firstMismatch.Item1);
            }
            else
            {
                font = ModFontHolder.LightAndHeavy;
            }
            string modText;

            if (displayModificationOption == DisplayModificationOption.NOT_SHOWN)
            {
                modText = strAminoAcid;
            }
            else
            {
                modText = strAminoAcid + @"[*]";
            }

            return(new TextSequence
            {
                Color = color,
                Font = font,
                Text = modText
            });
        }
示例#17
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();
        }
示例#18
0
 /// <summary>
 /// Creates a text sequence with normal font.
 /// </summary>
 public static TextSequence CreatePlainTextSequence(string text, ModFontHolder fonts)
 {
     return new TextSequence
                {
                    Text = text,
                    Font = fonts.Plain,
                    Color = Color.Black,
                    IsPlainText = true
                };
 }
示例#19
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());
        }
示例#20
0
 public static void DrawPeptideText(PeptideDocNode nodePep,
     SrmSettings settings,
     IEnumerable<TextSequence> textSequences,
     Graphics g,
     Rectangle bounds,
     ModFontHolder fonts,
     Color foreColor,
     Color backColor)
 {
     if (textSequences == null)
         textSequences = CreateTextSequences(nodePep, settings, GetLabel(nodePep, string.Empty), g, fonts);
     Rectangle rectDraw = new Rectangle(0, bounds.Y, 0, bounds.Height);
     foreach (var textSequence in textSequences)
     {
         rectDraw.X = textSequence.Position + bounds.X + TreeViewMS.PADDING;
         rectDraw.Width = textSequence.Width;
         // Use selection highlight color, if the background is highlight.
         if (backColor != SystemColors.Highlight)
             foreColor = textSequence.Color;
         TextRenderer.DrawText(g, textSequence.Text, textSequence.Font, rectDraw,
             foreColor, backColor, FORMAT_TEXT_SEQUENCE);
     }
 }
示例#21
0
 public override bool DrawPickLabel(DocNode child, Graphics g, Rectangle bounds, ModFontHolder fonts, Color foreColor, Color backColor)
 {
     PeptideTreeNode.DrawPeptideText((PeptideDocNode)child, DocSettings, null,
                                     g, bounds, fonts, foreColor, backColor);
     return(true);
 }
示例#22
0
        /// <summary>
        /// Creates a text sequence with the fully modified peptide sequence text
        /// and font information for a given label type.
        /// </summary>
        private static TextSequence CreateTypeTextSequence(PeptideDocNode nodePep, SrmSettings settings,
            IsotopeLabelType labelType, ModFontHolder fonts)
        {
            var calc = settings.TryGetPrecursorCalc(labelType, nodePep.ExplicitMods);
            if (calc == null)
                return null;

            return new TextSequence
                       {
                           Text = nodePep.IsProteomic
                               ? calc.GetModifiedSequence(nodePep.Peptide.Sequence, true)
                               : nodePep.CustomIon.DisplayName,
                           Font = fonts.GetModFont(labelType),
                           Color = ModFontHolder.GetModColor(labelType)
                       };
        }
示例#23
0
        /// <summary>
        /// Calculates font information for a single amino acid character in
        /// the peptide, and increments indexes to next amino acid character.
        /// </summary>
        /// <param name="indexes">Index locations of the amino acid in each text sequence</param>
        /// <param name="textSequences">List of text sequences for all label types being considered</param>
        /// <param name="fonts">Modifications fonts</param>
        /// <returns>The amino acid character and its font information</returns>
        private static CharFont GetCharFont(int[] indexes, IList<TextSequence> textSequences, ModFontHolder fonts)
        {
            int iChar = indexes[0];
            string text = textSequences[0].Text;
            if (iChar >= text.Length)
                return null;

            char c = text[iChar];
            Font font = fonts.Plain;
            Color color = Color.Black;

            string modString = NextAA(0, indexes, textSequences);
            if (modString != null)
                font = textSequences[0].Font;

            for (int i = 1; i < indexes.Length; i++)
            {
                string modStringHeavy = NextAA(i, indexes, textSequences);
                if (modStringHeavy == null)
                    continue;

                if (Equals(color, Color.Black) && !Equals(modString, modStringHeavy))
                {
                    color = textSequences[i].Color;
                    font = modString == null ? textSequences[i].Font : fonts.LightAndHeavy;
                }
            }

            return new CharFont(c, font, color);
        }
示例#24
0
        /// <summary>
        /// Calculates font information for a single amino acid character in
        /// the peptide, and increments indexes to next amino acid character.
        /// </summary>
        /// <param name="indexes">Index locations of the amino acid in each text sequence</param>
        /// <param name="textSequences">List of text sequences for all label types being considered</param>
        /// <param name="fonts">Modifications fonts</param>
        /// <returns>The amino acid character and its font information</returns>
        private static CharFont GetCharFont(int[] indexes, IList <TextSequence> textSequences, ModFontHolder fonts)
        {
            int    iChar = indexes[0];
            string text  = textSequences[0].Text;

            if (iChar >= text.Length)
            {
                return(null);
            }

            char  c     = text[iChar];
            Font  font  = fonts.Plain;
            Color color = Color.Black;

            string modString = NextAA(0, indexes, textSequences);

            if (modString != null)
            {
                font = textSequences[0].Font;
            }

            for (int i = 1; i < indexes.Length; i++)
            {
                string modStringHeavy = NextAA(i, indexes, textSequences);
                if (modStringHeavy == null)
                {
                    continue;
                }

                if (Equals(color, Color.Black) && !Equals(modString, modStringHeavy))
                {
                    color = textSequences[i].Color;
                    font  = modString == null ? textSequences[i].Font : fonts.LightAndHeavy;
                }
            }

            return(new CharFont(c, font, color));
        }
示例#25
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());
        }
示例#26
0
        public PopupPickList(IChildPicker picker, string childHeading, bool okOnDeactivate)
        {
            InitializeComponent();

            Size = SizeAll;

            cbItems.Text = childHeading;

            _modFonts = new ModFontHolder(pickListMulti);
            _nodeTip  = new NodeTip(this)
            {
                Parent = this
            };

            _picker         = picker;
            _chosenAtStart  = new List <DocNode>(picker.Chosen);
            _okOnDeactivate = okOnDeactivate;

            bool filter  = tbbFilter.Checked = _picker.Filtered;
            var  choices = picker.GetChoices(filter).ToArray();

            if (choices.Length != choices.Select(c => c.Id.GlobalIndex).Distinct().Count())
            {
                throw new ArgumentException("Choices must be unique"); // Not L10N
            }
            if (filter)
            {
                // If filtered choices do not contain a choice that
                // has already been chose, then use the unfiltered list.
                foreach (var choice in _chosenAtStart)
                {
                    if (!ContainsChoice(choices, choice))
                    {
                        choices           = picker.GetChoices(false).ToArray();
                        tbbFilter.Checked = false;
                        break;
                    }
                }
            }
            SetChoices(choices, _chosenAtStart);

            if (pickListMulti.Items.Count > 0)
            {
                pickListMulti.SelectedIndex = 0;
            }

            // Avoid setting the property, because it will actually
            // change what is picked.
            _autoManageChildren = _picker.AutoManageChildren;
            UpdateAutoManageUI();

            // Hide the synchronize checkbox, or set its label correctly
            string synchLabelText = _picker.SynchSiblingsLabel;

            if (string.IsNullOrEmpty(synchLabelText))
            {
                cbSynchronize.Visible = false;

                // Resize to hide space for the checkbox
                var anchorList = pickListMulti.Anchor;
                pickListMulti.Anchor = anchorList & ~AnchorStyles.Bottom;
                Height = pickListMulti.Bottom + 8;
                pickListMulti.Anchor = anchorList;
            }
            else
            {
                cbSynchronize.Text    = synchLabelText;
                cbSynchronize.Checked = _picker.IsSynchSiblings;
            }
        }
示例#27
0
 public override bool DrawPickLabel(DocNode child, Graphics g, Rectangle bounds, ModFontHolder fonts, Color foreColor, Color backColor)
 {
     PeptideTreeNode.DrawPeptideText((PeptideDocNode) child, DocSettings, null,
         g, bounds, fonts, foreColor, backColor);
     return true;
 }