Exemplo n.º 1
0
        private void QueryPeptideProteins(ILongWaitBroker longWaitBroker)
        {
            List <HashSet <Protein> > peptideProteins = new List <HashSet <Protein> >();

            if (BackgroundProteome != null)
            {
                using (var proteomeDb = BackgroundProteome.OpenProteomeDb(longWaitBroker.CancellationToken))
                {
                    Digestion digestion = proteomeDb.GetDigestion();
                    if (digestion != null)
                    {
                        var peptidesOfInterest   = _peptideDocNodes.Select(node => node.Item2.Peptide.Target.Sequence);
                        var sequenceProteinsDict = digestion.GetProteinsWithSequences(peptidesOfInterest);
                        if (longWaitBroker.IsCanceled)
                        {
                            return;
                        }
                        foreach (var tuple in _peptideDocNodes)
                        {
                            if (longWaitBroker.IsCanceled)
                            {
                                return;
                            }
                            var peptideGroup                   = (PeptideGroup)tuple.Item1.GetIdentity(0);
                            var peptideDocNode                 = tuple.Item2;
                            HashSet <Protein> proteins         = new HashSet <Protein>();
                            var            peptideGroupDocNode = PeptideGroupDocNodes.First(g => ReferenceEquals(g.PeptideGroup, peptideGroup));
                            List <Protein> proteinsForSequence;
                            if (sequenceProteinsDict.TryGetValue(peptideDocNode.Peptide.Target.Sequence, out proteinsForSequence))
                            {
                                if (peptideGroupDocNode != null)
                                {
                                    foreach (var protein in proteinsForSequence)
                                    {
                                        if (protein.Sequence == peptideGroupDocNode.PeptideGroup.Sequence)
                                        {
                                            _peptidesInBackgroundProteome.Add(tuple.Item1);
                                            continue;
                                        }
                                        proteins.Add(protein);
                                    }
                                }
                            }
                            peptideProteins.Add(proteins);
                        }
                    }
                }
            }
            _peptideProteins = peptideProteins;
        }
Exemplo n.º 2
0
        void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentCell == null || dataGridView1.CurrentRow == null)
            {
                return;
            }
            var rowTag = (Tuple <IdentityPath, PeptideDocNode>)dataGridView1.CurrentRow.Tag;

            if (rowTag == null)
            {
                return;
            }
            PeptideDocNode peptideDocNode = rowTag.Item2;
            // Expecting to find this peptide
            var             peptideGroupDocNode = PeptideGroupDocNodes.First(g => g.Peptides.Contains(peptideDocNode));
            String          peptideSequence     = peptideDocNode.Peptide.Target.Sequence;
            String          proteinSequence;
            var             proteinColumn = dataGridView1.Columns[dataGridView1.CurrentCell.ColumnIndex].Tag as ProteinColumn;
            ProteinMetadata metadata;

            if (proteinColumn == null)
            {
                metadata        = peptideGroupDocNode.ProteinMetadata;
                proteinSequence = peptideGroupDocNode.PeptideGroup.Sequence;
            }
            else
            {
                metadata        = proteinColumn.Protein.ProteinMetadata;
                proteinSequence = proteinColumn.Protein.Sequence;
            }
            tbxProteinName.Text        = metadata.Name;
            tbxProteinDescription.Text = metadata.Description;
            tbxProteinDetails.Text     = metadata.DisplayTextWithoutNameOrDescription(); // Don't show name or description

            if (!string.IsNullOrEmpty(proteinSequence))
            {
                var           regex         = new Regex(peptideSequence);
                StringBuilder formattedText = new StringBuilder("{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}{\\colortbl ;\\red0\\green0\\blue255;}\\f0\\pard \\fs16"); // Not L10N
                int           lastIndex     = 0;
                for (Match match = regex.Match(proteinSequence, 0); match.Success; lastIndex = match.Index + match.Length, match = match.NextMatch())
                {
                    formattedText.Append("\\cf0\\b0 " + proteinSequence.Substring(lastIndex, match.Index - lastIndex));        // Not L10N
                    formattedText.Append("\\cf1\\b " + proteinSequence.Substring(match.Index, match.Length));                  // Not L10N
                }
                formattedText.Append("\\cf0\\b0 " + proteinSequence.Substring(lastIndex, proteinSequence.Length - lastIndex)); // Not L10N
                formattedText.Append("\\par }");                                                                               // Not L10N
                richTextBoxSequence.Rtf = formattedText.ToString();
            }
        }
Exemplo n.º 3
0
        private void QueryPeptideProteins(ILongWaitBroker longWaitBroker)
        {
            List <HashSet <Protein> > peptideProteins = new List <HashSet <Protein> >();

            if (BackgroundProteome != null)
            {
                using (var proteomeDb = BackgroundProteome.OpenProteomeDb())
                {
                    Digestion digestion = BackgroundProteome.GetDigestion(proteomeDb, SrmDocument.Settings.PeptideSettings);
                    if (digestion != null)
                    {
                        var peptidesOfInterest   = _peptideDocNodes.Select(node => node.Peptide.Sequence);
                        var sequenceProteinsDict = digestion.GetProteinsWithSequences(peptidesOfInterest, null);
                        if (longWaitBroker.IsCanceled)
                        {
                            return;
                        }
                        foreach (var peptideDocNode in _peptideDocNodes)
                        {
                            HashSet <Protein> proteins         = new HashSet <Protein>();
                            var            peptideGroupDocNode = PeptideGroupDocNodes.First(g => g.Peptides.Contains(peptideDocNode));
                            List <Protein> proteinsForSequence;
                            if (sequenceProteinsDict.TryGetValue(peptideDocNode.Peptide.Sequence, out proteinsForSequence))
                            {
                                if (peptideGroupDocNode != null)
                                {
                                    foreach (var protein in proteinsForSequence)
                                    {
                                        if (protein.Sequence == peptideGroupDocNode.PeptideGroup.Sequence)
                                        {
                                            _peptidesInBackgroundProteome.Add(peptideDocNode);
                                            continue;
                                        }
                                        proteins.Add(protein);
                                    }
                                }
                            }
                            peptideProteins.Add(proteins);
                        }
                    }
                }
            }
            _peptideProteins = peptideProteins;
        }
Exemplo n.º 4
0
        private void SelectPeptidesWithNumberOfMatchesAtOrBelowThreshold(int threshold, UniquenessType uniqueBy)
        {
            dataGridView1.EndEdit();
            var dubious = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            for (int rowIndex = 0; rowIndex < dataGridView1.Rows.Count; rowIndex++)
            {
                var row        = dataGridView1.Rows[rowIndex];
                var rowTag     = (Tuple <IdentityPath, PeptideDocNode>)row.Tag;
                int matchCount = _peptidesInBackgroundProteome.Contains(rowTag.Item1) ? 1 : 0;
                for (int col = 0; col < dataGridView1.ColumnCount; col++)
                {
                    if (col == PeptideIncludedColumn.Index || col == PeptideColumn.Index)
                    {
                        continue;
                    }

                    if (row.Cells[col].Value is bool && ((bool)row.Cells[col].Value))
                    {
                        if (uniqueBy == UniquenessType.protein)
                        {
                            matchCount++;
                        }
                        else
                        {
                            var    peptide = rowTag.Item2;
                            var    parent  = PeptideGroupDocNodes.First(p => p.Children.Contains(peptide));
                            string testValA;
                            string testValB;
                            // ATP5B and atp5b are the same thing, as are "mus musculus" and "MUS MUSCULUS"
                            if (uniqueBy == UniquenessType.gene)
                            {
                                // ReSharper disable once PossibleNullReferenceException
                                testValA = parent.ProteinMetadata.Gene;
                                testValB = ((ProteinColumn)dataGridView1.Columns[col].Tag).Protein.Gene;
                            }
                            else
                            {
                                // ReSharper disable once PossibleNullReferenceException
                                testValA = parent.ProteinMetadata.Species;
                                testValB = ((ProteinColumn)dataGridView1.Columns[col].Tag).Protein.Species;
                            }
                            // Can't filter on something that isn't there - require nonempty values
                            if (!string.IsNullOrEmpty(testValA) && !string.IsNullOrEmpty(testValB) &&
                                string.Compare(testValA, testValB, StringComparison.OrdinalIgnoreCase) != 0)
                            {
                                matchCount++;
                            }
                            if (string.IsNullOrEmpty(testValA))
                            {
                                dubious.Add(parent.Name);
                            }
                            if (string.IsNullOrEmpty(testValB))
                            {
                                dubious.Add(((ProteinColumn)dataGridView1.Columns[col].Tag).Protein.Name);
                            }
                        }
                    }
                    if (matchCount > threshold)
                    {
                        break;
                    }
                }
                row.Cells[PeptideIncludedColumn.Name].Value = (matchCount <= threshold);
            }
            SetCheckBoxPeptideIncludedHeaderState();
            if (dubious.Any())
            {
                var dubiousValues = TextUtil.LineSeparate(uniqueBy == UniquenessType.gene ?
                                                          Resources.UniquePeptidesDlg_SelectPeptidesWithNumberOfMatchesAtOrBelowThreshold_Some_background_proteome_proteins_did_not_have_gene_information__this_selection_may_be_suspect_ :
                                                          Resources.UniquePeptidesDlg_SelectPeptidesWithNumberOfMatchesAtOrBelowThreshold_Some_background_proteome_proteins_did_not_have_species_information__this_selection_may_be_suspect_,
                                                          Resources.UniquePeptidesDlg_SelectPeptidesWithNumberOfMatchesAtOrBelowThreshold_These_proteins_include_,
                                                          TextUtil.LineSeparate(dubious)); // Not L10N
                MessageDlg.Show(this, dubiousValues);
            }
        }