示例#1
0
 public static string GetProteinText(Protein protein, MatchOption matchOption)
 {
     return(protein != null
         ? ProteinMetadataManager.ProteinModalDisplayText(protein.DocNode.ProteinMetadata,
                                                          MatchOptionToDisplayMode(matchOption))
         : null);
 }
示例#2
0
        public Size RenderTip(Graphics g, Size sizeMax, bool draw)
        {
            var table = new TableDesc();

            using (var rt = new RenderTools())
            {
                if (_row.Peptide != null)
                {
                    table.AddDetailRow(Helpers.PeptideToMoleculeTextMapper.Translate(GroupComparisonStrings.FoldChangeRowTipProvider_RenderTip_Peptide, _row.Peptide.IsSmallMolecule()),
                                       _row.Peptide.ModifiedSequence == null ? _row.Peptide.ToString() : _row.Peptide.ModifiedSequence.ToString(), rt);
                }
                if (_row.Protein != null)
                {
                    table.AddDetailRow(Helpers.PeptideToMoleculeTextMapper.Translate(GroupComparisonStrings.FoldChangeRowTipProvider_RenderTip_Protein, _row.Protein.IsNonProteomic()),
                                       ProteinMetadataManager.ProteinModalDisplayText(_row.Protein.DocNode), rt);
                }

                table.AddDetailRow(GroupComparisonStrings.FoldChangeRowTipProvider_RenderTip_Fold_Change, _row.FoldChangeResult.FoldChange.ToString(Formats.FoldChange, CultureInfo.CurrentCulture), rt);
                table.AddDetailRow(GroupComparisonStrings.FoldChange_Log2_Fold_Change_, _row.FoldChangeResult.Log2FoldChange.ToString(Formats.FoldChange, CultureInfo.CurrentCulture), rt);
                table.AddDetailRow(GroupComparisonStrings.FoldChangeRowTipProvider_RenderTip_P_Value, _row.FoldChangeResult.AdjustedPValue.ToString(Formats.PValue, CultureInfo.CurrentCulture), rt);
                table.AddDetailRow(GroupComparisonStrings.FoldChange__Log10_P_Value_, (-Math.Log10(_row.FoldChangeResult.AdjustedPValue)).ToString(Formats.PValue, CultureInfo.CurrentCulture), rt);

                var size = table.CalcDimensions(g);

                if (draw)
                {
                    table.Draw(g);
                }

                return(new Size((int)size.Width + 2, (int)size.Height + 2));
            }
        }
示例#3
0
        public static string GetRowDisplayText(Protein protein, Databinding.Entities.Peptide peptide)
        {
            var proteomic = protein.DocNode.IsProteomic;

            if (peptide != null)
            {
                return(proteomic ? peptide.Sequence : peptide.MoleculeName);
            }
            else
            {
                return(proteomic ? ProteinMetadataManager.ProteinModalDisplayText(protein.DocNode) : protein.Name);
            }
        }
示例#4
0
        protected override void OnModelChanged()
        {
            int typeImageIndex = TypeImageIndex;

            if (typeImageIndex != ImageIndex)
            {
                ImageIndex = SelectedImageIndex = typeImageIndex;
            }
            string label = ProteinMetadataManager.ProteinModalDisplayText((PeptideGroupDocNode)Model);

            if (!string.Equals(label, Text))
            {
                Text = label;
            }

            // Make sure children are up to date
            OnUpdateChildren(SequenceTree.ExpandProteins);
        }
示例#5
0
 private void WaitForProteinMetadataBackgroundLoaderCompleted()
 {
     // In a functional test we expect the protein metadata search to at least pretend to have gone to the web
     WaitForConditionUI(() => ProteinMetadataManager.IsLoadedDocument(Program.MainWindow.Document));
 }
示例#6
0
 public static string GetProteinText(Protein protein, ProteinMetadataManager.ProteinDisplayMode proteinDisplayMode)
 {
     return(protein != null?ProteinMetadataManager.ProteinModalDisplayText(protein.DocNode.ProteinMetadata, proteinDisplayMode) : null);
 }
示例#7
0
        private void UpdateGraph()
        {
            if (!IsHandleCreated)
            {
                return;
            }
            zedGraphControl.GraphPane.GraphObjList.Clear();
            zedGraphControl.GraphPane.CurveList.Clear();
            _barGraph = null;
            _rows     = null;
            var points = new PointPairList();
            var groupComparisonModel = FoldChangeBindingSource.GroupComparisonModel;
            var groupComparisonDef   = groupComparisonModel.GroupComparisonDef;
            var document             = groupComparisonModel.Document;
            var sequences            = new List <Tuple <string, bool> >();

            foreach (var nodePep in document.Molecules)
            {
                sequences.Add(new Tuple <string, bool>(nodePep.ModifiedTarget.DisplayName, nodePep.IsProteomic));
            }
            var uniquePrefixGenerator = new UniquePrefixGenerator(sequences, 3);
            var textLabels            = new List <string>();
            var rows = _bindingListSource.OfType <RowItem>()
                       .Select(rowItem => rowItem.Value)
                       .OfType <FoldChangeBindingSource.FoldChangeRow>()
                       .ToArray();
            bool showLabelType = rows.Select(row => row.IsotopeLabelType).Distinct().Count() > 1;
            bool showMsLevel   = rows.Select(row => row.MsLevel).Distinct().Count() > 1;
            bool showGroup     = rows.Select(row => row.Group).Distinct().Count() > 1;

            foreach (var row in rows)
            {
                var    foldChangeResult = row.FoldChangeResult;
                double error            = Math.Log(foldChangeResult.MaxFoldChange / foldChangeResult.FoldChange, 2.0);
                var    point            = MeanErrorBarItem.MakePointPair(points.Count, foldChangeResult.Log2FoldChange, error);
                points.Add(point);
                string label;
                if (null != row.Peptide)
                {
                    try
                    {
                        label = uniquePrefixGenerator.GetUniquePrefix(
                            row.Peptide.GetDocNode().ModifiedTarget.DisplayName, row.Peptide.GetDocNode().IsProteomic);
                    }
                    catch
                    {
                        // Peptide must have been deleted.
                        label = row.Peptide.GetDocNode().ModifiedTarget.DisplayName;
                    }
                }
                else
                {
                    label = ProteinMetadataManager.ProteinModalDisplayText(row.Protein.DocNode);
                }
                if (showMsLevel && row.MsLevel.HasValue)
                {
                    label += @" MS" + row.MsLevel; //;
                }
                if (showLabelType && row.IsotopeLabelType != null)
                {
                    label += @" (" + row.IsotopeLabelType.Title + @")";
                }
                if (showGroup && !Equals(row.Group, default(GroupIdentifier)))
                {
                    label += @" " + row.Group;
                }
                textLabels.Add(label);
                if (IsSelected(row))
                {
                    double y, height;
                    if (foldChangeResult.Log2FoldChange >= 0)
                    {
                        y      = foldChangeResult.Log2FoldChange + error;
                        height = y;
                    }
                    else
                    {
                        y      = 0;
                        height = error - foldChangeResult.Log2FoldChange;
                    }
                    zedGraphControl.GraphPane.GraphObjList.Add(new BoxObj(point.X + .5, y, .99, height)
                    {
                        ZOrder = ZOrder.E_BehindCurves,
                        IsClippedToChartRect = true
                    });
                }
            }
            zedGraphControl.GraphPane.XAxis.Title.Text = groupComparisonDef.PerProtein ? GroupComparisonStrings.FoldChangeBarGraph_UpdateGraph_Protein : GroupComparisonStrings.FoldChangeBarGraph_UpdateGraph_Peptide;
            zedGraphControl.GraphPane.YAxis.Title.Text = GroupComparisonStrings.FoldChangeBarGraph_UpdateGraph_Log_2_Fold_Change;
            var barGraph = new MeanErrorBarItem(null, points, Color.Black, Color.Blue);

            zedGraphControl.GraphPane.CurveList.Add(barGraph);
            zedGraphControl.GraphPane.XAxis.Scale.MinAuto     = zedGraphControl.GraphPane.XAxis.Scale.MaxAuto =
                zedGraphControl.GraphPane.YAxis.Scale.MinAuto = zedGraphControl.GraphPane.YAxis.Scale.MaxAuto = true;
            zedGraphControl.GraphPane.XAxis.Type             = AxisType.Text;
            zedGraphControl.GraphPane.XAxis.Scale.TextLabels = textLabels.ToArray();
            _axisLabelScaler.ScaleAxisLabels();
            zedGraphControl.GraphPane.AxisChange();
            zedGraphControl.Invalidate();
            _barGraph = barGraph;
            _rows     = rows;
        }
        [MethodImpl(MethodImplOptions.NoOptimization)] // TODO(nicksh): reenable optimizations after we track down a NullReferenceException
        public static IList <ListViewItem> CreateListViewItems(IList <ProteinMatch> matches, String searchText, ProteinMatchTypes matchTypes, PeptideSettings peptideSettings, int maxCount)
        {
            var listItems      = new SortedList <string, ListViewItem>();
            var setUsedMatches = new HashSet <string>();

            // First check for matching by sequence
            foreach (var match in matches)
            {
                if (matchTypes.Contains(ProteinMatchType.sequence))
                {
                    HashSet <String> addedPeptideSequences = new HashSet <string>();
                    FastaSequence    fastaSequence;
                    try
                    {
                        fastaSequence = new FastaSequence("name", "description", new ProteinMetadata[0], match.Protein.Sequence); // Not L10N
                    }
                    catch (InvalidDataException)
                    {
                        // It's possible that the peptide sequence in the fasta file was bogus, in which case we just don't digest it.
                        continue;
                    }
                    foreach (Peptide peptide in peptideSettings.Enzyme.Digest(fastaSequence, peptideSettings.DigestSettings))
                    {
                        if (!peptide.Sequence.StartsWith(searchText))
                        {
                            continue;
                        }
                        if (!addedPeptideSequences.Add(peptide.Sequence))
                        {
                            continue;
                        }
                        var listItem = new ListViewItem
                        {
                            Text = peptide.Sequence,
                            Tag  = new StatementCompletionItem
                            {
                                Peptide     = peptide.Sequence,
                                ProteinInfo = match.Protein.ProteinMetadata,
                                SearchText  = searchText
                            },
                        };
                        StatementCompletionForm.AddDescription(listItem,
                                                               match.Protein.ProteinMetadata.TextForMatchTypes(matchTypes),
                                                               null);
                        setUsedMatches.Add(match.Protein.Name);
                        listItem.ImageIndex = (int)ImageId.peptide;
                        var tooltip = new StringBuilder();
                        tooltip.AppendLine(Resources.StatementCompletionTextBox_CreateListViewItems_Descriptions)
                        .Append(match.Protein.ProteinMetadata.TextForMatchTypes(matchTypes));
                        foreach (var name in match.Protein.AlternativeNames)
                        {
                            tooltip.AppendLine().Append(name.TextForMatchTypes(matchTypes));
                        }
                        listItem.ToolTipText = StripTabs(tooltip.ToString());
                        // Note the leading space in this sort key - we'd like to list sequence matches first
                        var key = TextUtil.SpaceSeparate(" ", listItem.Text, listItem.ToolTipText); // Not L10N
                        if (!listItems.ContainsKey(key))
                        {
                            listItems.Add(key, listItem);
                        }
                    }
                }
            }
            if (listItems.Count >= maxCount)
            {
                return(new List <ListViewItem>(listItems.Values));  // We used to exit here if we had any matches - but that's frustrating when you're not actually trying to match by sequence
            }

            // Decide which field not to display on righthand side, based on what's already showing on the left due to View|Targets|By* menu
            ProteinMatchTypes displayMatchTypes = ProteinMatchTypes.ALL;

            switch (SequenceTree.ProteinsDisplayMode)
            {
            case ProteinMetadataManager.ProteinDisplayMode.ByName:
                displayMatchTypes = displayMatchTypes.Except(ProteinMatchType.name);
                break;

            case ProteinMetadataManager.ProteinDisplayMode.ByAccession:
                displayMatchTypes = displayMatchTypes.Except(ProteinMatchType.accession);
                break;

            case ProteinMetadataManager.ProteinDisplayMode.ByGene:
                displayMatchTypes = displayMatchTypes.Except(ProteinMatchType.gene);
                break;

            case ProteinMetadataManager.ProteinDisplayMode.ByPreferredName:
                displayMatchTypes = displayMatchTypes.Except(ProteinMatchType.preferredName);
                break;
            }

            ProteinMatchTypes secondPassMatchTypes = matchTypes.Except(
                ProteinMatchType.sequence,     // We already did sequence
                ProteinMatchType.description); // And aren't ready for description

            foreach (var match in matches)
            {
                if (setUsedMatches.Contains(match.Protein.Name))
                {
                    continue;
                }
                // Try matching on name, accession etc - cycle through name, accession, preferredName, gene
                foreach (ProteinMatchType tryType in secondPassMatchTypes)
                {
                    if (match.MatchTypes.Contains(tryType))
                    {
                        var listItem = new ListViewItem();
                        // Show description, and any other fields we were searching on
                        if (match.AlternativeName != null)
                        {
                            listItem.Text = ProteinMetadataManager.ProteinModalDisplayText(match.AlternativeName, Settings.Default.ShowPeptidesDisplayMode);
                            listItem.Tag  = new StatementCompletionItem {
                                ProteinInfo = match.AlternativeName, SearchText = searchText
                            };
                            StatementCompletionForm.AddDescription(listItem,
                                                                   match.AlternativeName.TextForMatchTypes(displayMatchTypes.Except(ProteinMatchType.name)), searchText);
                        }
                        else
                        {
                            listItem.Text = ProteinMetadataManager.ProteinModalDisplayText(match.Protein.ProteinMetadata, Settings.Default.ShowPeptidesDisplayMode);
                            listItem.Tag  = new StatementCompletionItem {
                                ProteinInfo = match.Protein.ProteinMetadata, SearchText = searchText
                            };
                            StatementCompletionForm.AddDescription(listItem,
                                                                   match.Protein.ProteinMetadata.TextForMatchTypes(displayMatchTypes), searchText);
                        }
                        setUsedMatches.Add(match.Protein.Name);
                        listItem.ImageIndex = (int)ImageId.protein;
                        var tooltip = new StringBuilder();
                        tooltip.AppendLine(Resources.StatementCompletionTextBox_CreateListViewItems_Descriptions)
                        .Append(match.Protein.ProteinMetadata.TextForMatchTypes(displayMatchTypes));
                        foreach (var altName in match.Protein.AlternativeNames)
                        {
                            tooltip.AppendLine().Append(altName.TextForMatchTypes(displayMatchTypes));
                        }
                        listItem.ToolTipText = StripTabs(tooltip.ToString());
                        // We want the sort to be on the particular bit of metadata that we matched
                        var key = TextUtil.SpaceSeparate(match.Protein.ProteinMetadata.TextForMatchTypes(ProteinMatchTypes.Singleton(tryType)),
                                                         listItem.Text, listItem.ToolTipText);
                        if (!listItems.ContainsKey(key))
                        {
                            listItems.Add(key, listItem);
                        }
                        break;
                    }
                }
            }
            if (listItems.Count >= maxCount)
            {
                return(new List <ListViewItem>(listItems.Values));  // We used to exit here if we had any matches - but that's frustrating when you're not actually trying to match by sequence
            }

            // Any matches by description?
            foreach (var match in matches)
            {
                if (setUsedMatches.Contains(match.Protein.Name))
                {
                    continue;
                }
                if (match.MatchTypes.Contains(ProteinMatchType.description))
                {
                    ProteinMetadata mainName    = match.AlternativeDescription;
                    string          matchName   = match.Protein.Name;
                    var             proteinInfo = match.Protein.ProteinMetadata;
                    if (matchName != null && matchName.Length > MAX_NAME_LENGTH)
                    {
                        proteinInfo = proteinInfo.ChangeName(matchName.Substring(0, MAX_NAME_LENGTH) + "..."); // Not L10N
                    }
                    var alternativeNames = new List <ProteinMetadata>();
                    if (mainName == null)
                    {
                        mainName = proteinInfo;
                    }
                    else
                    {
                        alternativeNames.Add(proteinInfo);
                    }
                    var listItem = new ListViewItem
                    {
                        Text       = ProteinMetadataManager.ProteinModalDisplayText(mainName, Settings.Default.ShowPeptidesDisplayMode),
                        ImageIndex = (int)ImageId.protein,
                        Tag        = new StatementCompletionItem {
                            ProteinInfo = proteinInfo, SearchText = searchText
                        }
                    };

                    StatementCompletionForm.AddDescription(listItem, mainName.TextForMatchTypes(displayMatchTypes), searchText);
                    if (match.Protein.AlternativeNames.Count > 0)
                    {
                        alternativeNames.AddRange(match.Protein.AlternativeNames);
                        StringBuilder tooltip = new StringBuilder(Resources.StatementCompletionTextBox_CreateListViewItems_Alternative_Names);
                        foreach (var altName in alternativeNames)
                        {
                            if (altName.Name == mainName.Name)
                            {
                                continue;
                            }

                            tooltip.AppendLine().Append(altName.TextForMatchTypes(displayMatchTypes.Union(ProteinMatchType.name)));
                        }
                        listItem.ToolTipText = StripTabs(tooltip.ToString());
                    }
                    // We want the sort to be on what we matched in the description, and what follows.
                    var remains = match.Protein.ProteinMetadata.Description ?? string.Empty;
                    int pos     = remains.ToLower().IndexOf(searchText.ToLower(), StringComparison.Ordinal);
                    if (pos > 0)
                    {
                        remains = remains.Substring(pos);
                    }
                    var key = TextUtil.SpaceSeparate(remains, listItem.Text, listItem.ToolTipText);
                    if (!listItems.ContainsKey(key))
                    {
                        listItems.Add(key, listItem);
                    }
                }
            }
            return(new List <ListViewItem>(listItems.Values));
        }
示例#9
0
 public override string GetDisplayText(DisplaySettings settings)
 {
     return(ProteinMetadataManager.ProteinModalDisplayText(this));
 }