private bool AddProteinRowsToGrid(ILongWaitBroker longWaitBroker) { longWaitBroker.Message = Resources.UniquePeptidesDlg_AddProteinRowsToGrid_Adding_rows_to_grid_; HashSet <Protein> proteinSet = new HashSet <Protein>(); foreach (var proteins in _peptideProteins) { proteinSet.UnionWith(proteins); } List <Protein> proteinList = new List <Protein>(); proteinList.AddRange(proteinSet); proteinList.Sort(); var proteinsByPreferredNameCounts = proteinList .Where(p => !string.IsNullOrEmpty(p.PreferredName)) .ToLookup(p => p.PreferredName, StringComparer.OrdinalIgnoreCase) .ToDictionary(grouping => grouping.Key, grouping => grouping.Count(), StringComparer.OrdinalIgnoreCase); var newColumns = new List <DataGridViewColumn>(); foreach (var protein in proteinList) { ProteinColumn proteinColumn = new ProteinColumn(_proteinColumns.Count + dataGridView1.ColumnCount, protein); _proteinColumns.Add(proteinColumn); var accession = string.IsNullOrEmpty(protein.Accession) ? string.Empty : protein.Accession + "\n"; // Not L10N var proteinName = protein.Name; // Isoforms may all get the same preferredname, which is confusing to look at if (!string.IsNullOrEmpty(protein.PreferredName)) { int countProteinsWithSameName; if (proteinsByPreferredNameCounts.TryGetValue(protein.PreferredName, out countProteinsWithSameName) && countProteinsWithSameName == 1) { proteinName = protein.PreferredName; } } var gene = string.IsNullOrEmpty(protein.Gene) ? string.Empty : "\n" + protein.Gene; // Not L10N DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn { Name = proteinColumn.Name, HeaderText = accession + proteinName + gene, ReadOnly = true, ToolTipText = protein.ProteinMetadata.DisplayTextWithoutName(), SortMode = DataGridViewColumnSortMode.Automatic, FillWeight = 1f, Tag = proteinColumn, }; if (longWaitBroker.IsCanceled) { return(false); } newColumns.Add(column); } int actualProteinCount = dataGridView1.AddColumns(newColumns); if (actualProteinCount < _proteinColumns.Count) { _proteinColumns.RemoveRange(actualProteinCount, _proteinColumns.Count - actualProteinCount); } for (int i = 0; i < _peptideDocNodes.Count; i++) { if (longWaitBroker.IsCanceled) { return(false); } longWaitBroker.ProgressValue = 100 * i / _peptideDocNodes.Count; var peptideTag = _peptideDocNodes[i]; var proteins = _peptideProteins[i]; var row = dataGridView1.Rows[dataGridView1.Rows.Add()]; row.Tag = peptideTag; row.Cells[PeptideIncludedColumn.Index].Value = true; row.Cells[PeptideColumn.Index].Value = peptideTag.Item2.Peptide.Target; foreach (var proteinColumn in _proteinColumns) { row.Cells[proteinColumn.Index].Value = proteins.Contains(proteinColumn.Protein); } } dataGridView1.EndEdit(); if (dataGridView1.RowCount > 0) { // Select the first peptide to populate the other controls in the dialog. dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[1]; } DrawCheckBoxOnPeptideIncludedColumnHeader(); return(true); }
private void LaunchPeptideProteinsQuery() { HashSet <Protein> proteinSet = new HashSet <Protein>(); using (var longWaitDlg = new LongWaitDlg { Text = Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Querying_Background_Proteome_Database, Message = Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Looking_for_proteins_with_matching_peptide_sequences }) { try { longWaitDlg.PerformWork(this, 1000, QueryPeptideProteins); } catch (Exception x) { var message = TextUtil.LineSeparate(string.Format(Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Failed_querying_background_proteome__0__, BackgroundProteome.Name), x.Message); MessageDlg.ShowWithException(this, message, x); } } if (_peptideProteins == null) { Close(); return; } foreach (var proteins in _peptideProteins) { proteinSet.UnionWith(proteins); } List <Protein> proteinList = new List <Protein>(); proteinList.AddRange(proteinSet); proteinList.Sort(); foreach (var protein in proteinList) { ProteinColumn proteinColumn = new ProteinColumn(_proteinColumns.Count, protein); _proteinColumns.Add(proteinColumn); DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn { Name = proteinColumn.Name, HeaderText = ((protein.Gene != null) ? String.Format(Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_, protein.Name, protein.Gene) : protein.Name), // Not L10N ReadOnly = true, ToolTipText = protein.ProteinMetadata.DisplayTextWithoutName(), SortMode = DataGridViewColumnSortMode.Automatic, Tag = proteinColumn, }; dataGridView1.Columns.Add(column); } for (int i = 0; i < _peptideDocNodes.Count; i++) { var peptide = _peptideDocNodes[i]; var proteins = _peptideProteins[i]; var row = dataGridView1.Rows[dataGridView1.Rows.Add()]; row.Tag = peptide; row.Cells[PeptideIncludedColumn.Name].Value = true; row.Cells[PeptideColumn.Name].Value = peptide.Peptide.Sequence; foreach (var proteinColumn in _proteinColumns) { row.Cells[proteinColumn.Name].Value = proteins.Contains(proteinColumn.Protein); } } dataGridView1.EndEdit(); if (dataGridView1.RowCount > 0) { // Select the first peptide to populate the other controls in the dialog. dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[1]; } DrawCheckBoxOnPeptideIncludedColumnHeader(); }
private void LaunchPeptideProteinsQuery() { HashSet<Protein> proteinSet = new HashSet<Protein>(); using (var longWaitDlg = new LongWaitDlg { Text = Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Querying_Background_Proteome_Database, Message = Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Looking_for_proteins_with_matching_peptide_sequences }) { try { longWaitDlg.PerformWork(this, 1000, QueryPeptideProteins); } catch (Exception x) { var message = TextUtil.LineSeparate(string.Format(Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Failed_querying_background_proteome__0__, BackgroundProteome.Name), x.Message); MessageDlg.ShowWithException(this, message, x); } } if (_peptideProteins == null) { Close(); return; } foreach (var proteins in _peptideProteins) { proteinSet.UnionWith(proteins); } List<Protein> proteinList = new List<Protein>(); proteinList.AddRange(proteinSet); proteinList.Sort(); foreach (var protein in proteinList) { ProteinColumn proteinColumn = new ProteinColumn(_proteinColumns.Count, protein); _proteinColumns.Add(proteinColumn); DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn { Name = proteinColumn.Name, HeaderText = ((protein.Gene != null) ? String.Format(Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_, protein.Name, protein.Gene) : protein.Name), // Not L10N ReadOnly = true, ToolTipText = protein.ProteinMetadata.DisplayTextWithoutName(), SortMode = DataGridViewColumnSortMode.Automatic, Tag = proteinColumn, }; dataGridView1.Columns.Add(column); } for (int i = 0; i < _peptideDocNodes.Count; i++) { var peptide = _peptideDocNodes[i]; var proteins = _peptideProteins[i]; var row = dataGridView1.Rows[dataGridView1.Rows.Add()]; row.Tag = peptide; row.Cells[PeptideIncludedColumn.Name].Value = true; row.Cells[PeptideColumn.Name].Value = peptide.Peptide.Sequence; foreach (var proteinColumn in _proteinColumns) { row.Cells[proteinColumn.Name].Value = proteins.Contains(proteinColumn.Protein); } } dataGridView1.EndEdit(); if (dataGridView1.RowCount > 0) { // Select the first peptide to populate the other controls in the dialog. dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[1]; } DrawCheckBoxOnPeptideIncludedColumnHeader(); }
private void LaunchPeptideProteinsQuery() { HashSet <Protein> proteinSet = new HashSet <Protein>(); using (var longWaitDlg = new LongWaitDlg { Text = Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Querying_Background_Proteome_Database, Message = Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Looking_for_proteins_with_matching_peptide_sequences }) { try { longWaitDlg.PerformWork(this, 1000, QueryPeptideProteins); } catch (Exception x) { var message = TextUtil.LineSeparate(string.Format(Resources.UniquePeptidesDlg_LaunchPeptideProteinsQuery_Failed_querying_background_proteome__0__, BackgroundProteome.Name), x.Message); MessageDlg.ShowWithException(this, message, x); } } if (_peptideProteins == null) { Close(); return; } foreach (var proteins in _peptideProteins) { proteinSet.UnionWith(proteins); } List <Protein> proteinList = new List <Protein>(); proteinList.AddRange(proteinSet); proteinList.Sort(); foreach (var protein in proteinList) { ProteinColumn proteinColumn = new ProteinColumn(_proteinColumns.Count, protein); _proteinColumns.Add(proteinColumn); var accession = string.IsNullOrEmpty(protein.Accession) ? string.Empty : protein.Accession + "\n"; // Not L10N var proteinName = protein.Name; // Isoforms may all get the same preferredname, which is confusing to look at if (!string.IsNullOrEmpty(protein.PreferredName) && !proteinList.Any(p => (!ReferenceEquals(p, protein) && (string.Compare(p.PreferredName, protein.PreferredName, StringComparison.OrdinalIgnoreCase) == 0)))) { proteinName = protein.PreferredName; } var gene = string.IsNullOrEmpty(protein.Gene) ? string.Empty : "\n" + protein.Gene; // Not L10N DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn { Name = proteinColumn.Name, HeaderText = accession + proteinName + gene, ReadOnly = true, ToolTipText = protein.ProteinMetadata.DisplayTextWithoutName(), SortMode = DataGridViewColumnSortMode.Automatic, Tag = proteinColumn, }; dataGridView1.Columns.Add(column); } for (int i = 0; i < _peptideDocNodes.Count; i++) { var peptide = _peptideDocNodes[i]; var proteins = _peptideProteins[i]; var row = dataGridView1.Rows[dataGridView1.Rows.Add()]; row.Tag = peptide; row.Cells[PeptideIncludedColumn.Name].Value = true; row.Cells[PeptideColumn.Name].Value = peptide.Peptide.Sequence; foreach (var proteinColumn in _proteinColumns) { row.Cells[proteinColumn.Name].Value = proteins.Contains(proteinColumn.Protein); } } dataGridView1.EndEdit(); if (dataGridView1.RowCount > 0) { // Select the first peptide to populate the other controls in the dialog. dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[1]; } DrawCheckBoxOnPeptideIncludedColumnHeader(); }