private static string GetDisplayText(ProteinDisplayMode arg, ProteinMetadata proteinMetadata) { string val; switch (arg) { case ProteinDisplayMode.ByAccession: val = proteinMetadata.Accession; break; case ProteinDisplayMode.ByGene: val = proteinMetadata.Gene; break; case ProteinDisplayMode.ByPreferredName: val = proteinMetadata.PreferredName; break; default: val = proteinMetadata.Name; break; } Assert.IsFalse(String.IsNullOrEmpty(val)); if (arg != ProteinDisplayMode.ByName) { Assert.AreNotEqual(val, proteinMetadata.Name); } return(val); }
public static string ProteinModalDisplayText(ProteinMetadata metadata, ProteinDisplayMode displayProteinsMode) { switch (displayProteinsMode) { case ProteinDisplayMode.ByAccession: case ProteinDisplayMode.ByPreferredName: case ProteinDisplayMode.ByGene: break; default: return(metadata.Name); } // If the desired field is not populated because it's not yet searched, say so if (metadata.NeedsSearch()) { return(Resources.ProteinMetadataManager_LookupProteinMetadata_resolving_protein_details); } // If the desired field is not populated, return something like "<name: YAL01234>" var failsafe = String.Format(Resources.PeptideGroupTreeNode_ProteinModalDisplayText__name___0__, metadata.Name); switch (displayProteinsMode) { case ProteinDisplayMode.ByAccession: return(metadata.Accession ?? failsafe); case ProteinDisplayMode.ByPreferredName: return(metadata.PreferredName ?? failsafe); case ProteinDisplayMode.ByGene: return(metadata.Gene ?? failsafe); } return(failsafe); }
public DbProteinName(DbProtein protein, ProteinMetadata proteinMetadata) { // ReSharper disable DoNotCallOverridableMethodsInConstructor IsPrimary = (protein == null); Protein = protein; // ReSharper restore DoNotCallOverridableMethodsInConstructor _proteinMetadata = proteinMetadata ?? ProteinMetadata.EMPTY; }
public FastaSequence AddAlternative(ProteinMetadata proteinMetadata) { var alternativesNew = new List <ProteinMetadata>(Alternatives) { proteinMetadata }; return(new FastaSequence(_name, _description, alternativesNew, _sequence, _isDecoy)); }
public PeptideGroupDocNode(PeptideGroup id, Annotations annotations, ProteinMetadata proteinMetadata, PeptideDocNode[] children, bool autoManageChildren) : base(id, annotations, children, autoManageChildren) { if (Equals(id.Name, proteinMetadata.Name)) proteinMetadata = proteinMetadata.ChangeName(null); // Make it clear that the name hasn't been altered if (Equals(id.Description, proteinMetadata.Description)) proteinMetadata = proteinMetadata.ChangeDescription(null); // Make it clear that the description hasn't been altered _proteinMetadata = proteinMetadata; }
private void WriteProteinMetadataXML(XmlWriter writer, ProteinMetadata proteinMetadata, bool skipNameAndDescription) { if (!skipNameAndDescription) { writer.WriteAttributeIfString(ATTR.name, proteinMetadata.Name); writer.WriteAttributeIfString(ATTR.description, proteinMetadata.Description); } writer.WriteAttributeIfString(ATTR.accession, proteinMetadata.Accession); writer.WriteAttributeIfString(ATTR.gene, proteinMetadata.Gene); writer.WriteAttributeIfString(ATTR.species, proteinMetadata.Species); writer.WriteAttributeIfString(ATTR.preferred_name, proteinMetadata.PreferredName); writer.WriteAttributeIfString(ATTR.websearch_status, proteinMetadata.WebSearchInfo.ToString()); }
public PeptideGroupDocNode ChangeProteinMetadata(ProteinMetadata proteinMetadata) { var newMetadata = proteinMetadata; if (Equals(PeptideGroup.Name, newMetadata.Name)) { newMetadata = newMetadata.ChangeName(null); // no actual override } if (Equals(PeptideGroup.Description, newMetadata.Description)) { newMetadata = newMetadata.ChangeDescription(null); // no actual override } return(ChangeProp(ImClone(this), im => im._proteinMetadata = newMetadata)); }
public PeptideGroupDocNode(PeptideGroup id, Annotations annotations, ProteinMetadata proteinMetadata, PeptideDocNode[] children, bool autoManageChildren) : base(id, annotations, children, autoManageChildren) { if (Equals(id.Name, proteinMetadata.Name)) { proteinMetadata = proteinMetadata.ChangeName(null); // Make it clear that the name hasn't been altered } if (Equals(id.Description, proteinMetadata.Description)) { proteinMetadata = proteinMetadata.ChangeDescription(null); // Make it clear that the description hasn't been altered } _proteinMetadata = proteinMetadata; }
public FastaSequence GetFastaSequence(String proteinName, out ProteinMetadata foundMetadata) { foundMetadata = null; if (IsNone) { return(null); } using (var proteomeDb = OpenProteomeDb()) { Protein protein = proteomeDb.GetProteinByName(proteinName); if (protein == null) { return(null); } foundMetadata = protein.ProteinMetadata; return(MakeFastaSequence(protein)); } }
public FastaSequence GetFastaSequence(String proteinName, out ProteinMetadata foundMetadata) { foundMetadata = null; if (IsNone) { return(null); } using (var proteomeDb = OpenProteomeDb()) { Protein protein = proteomeDb.GetProteinByName(proteinName); if (protein == null) { return(null); } List <ProteinMetadata> alternativeProteins = new List <ProteinMetadata>(); foreach (var alternativeName in protein.AlternativeNames) { alternativeProteins.Add(alternativeName); } foundMetadata = protein.ProteinMetadata; return(new FastaSequence(protein.ProteinMetadata.Name, protein.ProteinMetadata.Description, alternativeProteins, protein.Sequence)); } }
public PeptideGroupDocNode(PeptideGroup id, Annotations annotations, ProteinMetadata proteinMetadata, PeptideDocNode[] children, bool autoManageChildren) : this(id, annotations, proteinMetadata, children, autoManageChildren, null) { }
public static string ProteinModalDisplayText(ProteinMetadata metadata, string displayProteinsMode) { return(ProteinModalDisplayText(metadata, ProteinsDisplayMode(displayProteinsMode))); }
private static string GetDisplayText(ProteinDisplayMode arg, ProteinMetadata proteinMetadata) { string val; switch (arg) { case ProteinDisplayMode.ByAccession: val = proteinMetadata.Accession; break; case ProteinDisplayMode.ByGene: val = proteinMetadata.Gene; break; case ProteinDisplayMode.ByPreferredName: val = proteinMetadata.PreferredName; break; default: val = proteinMetadata.Name; break; } Assert.IsFalse(String.IsNullOrEmpty(val)); if (arg != ProteinDisplayMode.ByName) Assert.AreNotEqual(val, proteinMetadata.Name); return val; }
[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)); }
public FastaSequence GetFastaSequence(String proteinName, out ProteinMetadata foundMetadata) { foundMetadata = null; if (IsNone) return null; using (var proteomeDb = OpenProteomeDb()) { Protein protein = proteomeDb.GetProteinByName(proteinName); if (protein == null) { return null; } List<ProteinMetadata> alternativeProteins = new List<ProteinMetadata>(); foreach (var alternativeName in protein.AlternativeNames) { alternativeProteins.Add(alternativeName); } foundMetadata = protein.ProteinMetadata; return new FastaSequence(protein.ProteinMetadata.Name, protein.ProteinMetadata.Description, alternativeProteins, protein.Sequence); } }
public DbProtein(ProteinMetadata other) { _proteinMetadata = other; }
public virtual void SetWebSearchCompleted() { // Prepend the "done" tag to the searchterm/history. _proteinMetadata = _proteinMetadata.SetWebSearchCompleted(); }
public void ChangeProteinMetadata(ProteinMetadata other) { ProteinDbInfo.ChangeProteinMetadata(other); }
public virtual void SetWebSearchTerm(WebSearchTerm search) { _proteinMetadata = _proteinMetadata.SetWebSearchTerm(search); }
private FastaSequence GetFastaSequence(DataGridViewRow row, string proteinName, out ProteinMetadata metadata) { metadata = null; var backgroundProteome = GetBackgroundProteome(DocumentUiContainer.DocumentUI); if (backgroundProteome.IsNone) return null; var fastaSequence = backgroundProteome.GetFastaSequence(proteinName, out metadata); if (fastaSequence == null) { // Sometimes the protein name in the background proteome will have an extra "|" on the end. // In that case, update the name of the protein to match the one in the database. fastaSequence = backgroundProteome.GetFastaSequence(proteinName + "|"); // Not L10N if (fastaSequence != null) { row.Cells[colPeptideProtein.Index].Value = fastaSequence.Name; } } return fastaSequence; }
public virtual ProteinMetadata ClearWebSearchInfo() { // Sometimes you really just want to initialize, not have a search history. _proteinMetadata = _proteinMetadata.ClearWebSearchInfo(); return(_proteinMetadata); }
public virtual ProteinMetadata MergeProteinMetadata(DbProteinName other) { _proteinMetadata = _proteinMetadata.Merge(other.GetProteinMetadata()); return(_proteinMetadata); }
public virtual ProteinMetadata ChangeProteinMetadata(ProteinMetadata other) { _proteinMetadata = other; return(_proteinMetadata); }
public PeptideGroupDocNode(PeptideGroup id, ProteinMetadata proteinMetadata, PeptideDocNode[] children) : this(id, Annotations.EMPTY, proteinMetadata, children, true) { }
public PeptideGroupDocNode ChangeProteinMetadata(ProteinMetadata proteinMetadata) { var newMetadata = proteinMetadata; if (Equals(PeptideGroup.Name, newMetadata.Name)) newMetadata = newMetadata.ChangeName(null); // no actual override if (Equals(PeptideGroup.Description, newMetadata.Description)) newMetadata = newMetadata.ChangeDescription(null); // no actual override return ChangeProp(ImClone(this), im => im._proteinMetadata = newMetadata); }
public DbProtein() { _proteinMetadata = ProteinMetadata.EMPTY; }
private static bool Matches(ProteinMetadata proteinMetadata, ProteinMatchType matchType, string ltext) { return ContainsLowerCase(proteinMetadata.TextForMatchTypes(matchType), ltext); }
private SrmDocument AddProteins(SrmDocument document, ref IdentityPath selectedPath) { if (tabControl1.SelectedTab != tabPageProteinList) return document; var backgroundProteome = GetBackgroundProteome(document); for (int i = gridViewProteins.Rows.Count - 1; i >= 0; i--) { var row = gridViewProteins.Rows[i]; var proteinName = Convert.ToString(row.Cells[colProteinName.Index].Value); if (String.IsNullOrEmpty(proteinName)) { continue; } var pastedMetadata = new ProteinMetadata(proteinName, Convert.ToString(row.Cells[colProteinDescription.Index].Value), NullForEmpty(Convert.ToString(row.Cells[colProteinPreferredName.Index].Value)), NullForEmpty(Convert.ToString(row.Cells[colProteinAccession.Index].Value)), NullForEmpty(Convert.ToString(row.Cells[colProteinGene.Index].Value)), NullForEmpty(Convert.ToString(row.Cells[colProteinSpecies.Index].Value))); FastaSequence fastaSequence = null; if (!backgroundProteome.IsNone) { ProteinMetadata protdbMetadata; fastaSequence = backgroundProteome.GetFastaSequence(proteinName, out protdbMetadata); // Fill in any gaps in pasted metadata with that in protdb pastedMetadata = pastedMetadata.Merge(protdbMetadata); } // Strip any whitespace (tab, newline etc) In case it was copied out of a FASTA file var fastaSequenceString = new string(Convert.ToString(row.Cells[colProteinSequence.Index].Value).Where(c => !Char.IsWhiteSpace(c)).ToArray()); if (!string.IsNullOrEmpty(fastaSequenceString)) { try { if (fastaSequence == null) // Didn't match anything in protdb { fastaSequence = new FastaSequence(pastedMetadata.Name, pastedMetadata.Description, new ProteinMetadata[0], fastaSequenceString); } else { if (fastaSequence.Sequence != fastaSequenceString) { fastaSequence = new FastaSequence(pastedMetadata.Name, pastedMetadata.Description, fastaSequence.Alternatives, fastaSequenceString); } } } catch (Exception exception) { ShowProteinError(new PasteError { Line = i, Column = colProteinDescription.Index, Message = string.Format(Resources.PasteDlg_AddProteins_Invalid_protein_sequence__0__, exception.Message) }); return null; } } if (fastaSequence == null) { ShowProteinError( new PasteError { Line = i, Message = backgroundProteome.IsNone ? Resources.PasteDlg_AddProteins_Missing_protein_sequence : Resources.PasteDlg_AddProteins_This_protein_was_not_found_in_the_background_proteome_database }); return null; } var description = pastedMetadata.Description; if (!string.IsNullOrEmpty(description) && description != fastaSequence.Description) { fastaSequence = new FastaSequence(fastaSequence.Name, description, fastaSequence.Alternatives, fastaSequence.Sequence); } pastedMetadata = pastedMetadata.ChangeName(fastaSequence.Name).ChangeDescription(fastaSequence.Description); // Make sure these agree var nodeGroupPep = new PeptideGroupDocNode(fastaSequence, pastedMetadata, new PeptideDocNode[0]); nodeGroupPep = nodeGroupPep.ChangeSettings(document.Settings, SrmSettingsDiff.ALL); var to = selectedPath; if (to == null || to.Depth < (int)SrmDocument.Level.MoleculeGroups) document = (SrmDocument)document.Add(nodeGroupPep); else { Identity toId = selectedPath.GetIdentity((int)SrmDocument.Level.MoleculeGroups); document = (SrmDocument)document.Insert(toId, nodeGroupPep); } selectedPath = new IdentityPath(nodeGroupPep.Id); } return document; }
public static string ProteinModalDisplayText(ProteinMetadata metadata, string displayProteinsMode) { return ProteinModalDisplayText(metadata, ProteinsDisplayMode(displayProteinsMode)); }
private PeptideGroupDocNode GetMoleculePeptideGroup(SrmDocument document, DataGridViewRow row, bool requireProductInfo) { var pepGroup = new PeptideGroup(); var pep = GetMoleculePeptide(document, row, pepGroup, requireProductInfo); if (pep == null) return null; var name = Convert.ToString(row.Cells[INDEX_MOLECULE_GROUP].Value); if (string.IsNullOrEmpty(name)) name = document.GetPeptideGroupId(true); var metadata = new ProteinMetadata(name, string.Empty).SetWebSearchCompleted(); // FUTURE: some kind of lookup for small molecules return new PeptideGroupDocNode(pepGroup, metadata, new[] {pep}); }
public static string ProteinModalDisplayText(ProteinMetadata metadata, ProteinDisplayMode displayProteinsMode) { switch (displayProteinsMode) { case ProteinDisplayMode.ByAccession: case ProteinDisplayMode.ByPreferredName: case ProteinDisplayMode.ByGene: break; default: return metadata.Name; } // If the desired field is not populated because it's not yet searched, say so if (metadata.NeedsSearch()) return Resources.ProteinMetadataManager_LookupProteinMetadata_resolving_protein_details; // If the desired field is not populated, return something like "<name: YAL01234>" var failsafe = String.Format(Resources.PeptideGroupTreeNode_ProteinModalDisplayText__name___0__, metadata.Name); switch (displayProteinsMode) { case ProteinDisplayMode.ByAccession: return metadata.Accession ?? failsafe; case ProteinDisplayMode.ByPreferredName: return metadata.PreferredName ?? failsafe; case ProteinDisplayMode.ByGene: return metadata.Gene ?? failsafe; } return failsafe; }
public ProteinMetadata ParseProteinMetaData(ProteinMetadata proteinMetadata) { if (proteinMetadata.Name == null) return null; // watch for inputs like name="Library Peptides" which clearly isn't an actual protein name if (proteinMetadata.Name.Contains(" ")) // Not L10N return null; return ParseProteinMetaData(proteinMetadata.Name + " " + proteinMetadata.Description); // Not L10N }
private ProteinMetadata MergeSearchResult(ProteinMetadata searchResult, ProteinMetadata original) { // like a normal merge, use update to fill gaps in current, but // then prefer the update name and description // we do this to make it easier for user to relate back to the original // fasta header line while still allowing for cases where there may not // possibly have been a proper original source for descrption or even name ProteinMetadata result = searchResult.Merge(original); if (!String.IsNullOrEmpty(original.Name)) result = result.ChangeName(original.Name); if (!String.IsNullOrEmpty(original.Description)) result = result.ChangeDescription(original.Description); return result; }
/// <summary> /// Create the ordered list of dropdown items, with a rational sort order: /// First present any sequence matches, sorted by sequence /// Then present any name, accession, gene, preferredname, or species metadata matches, sorted by the matched metadata field /// Then present any matches against the description field, sorted by the description text starting at the match location /// </summary> public static IList <ListViewItem> CreateListViewItems(IList <ProteinMatch> matches, String searchText, ProteinMatchType matchTypes, int maxCount) { var listItems = new SortedList <string, ListViewItem>(); var listUsedMatches = new List <string>(); // First check for matching by sequence foreach (var match in matches) { if (0 != (matchTypes & match.MatchType & ProteinMatchType.sequence)) { foreach (DigestedPeptide digestedPeptide in match.DigestedPeptides) { var listItem = new ListViewItem { Text = digestedPeptide.Sequence, Tag = new StatementCompletionItem { Peptide = digestedPeptide.Sequence, ProteinInfo = match.Protein.ProteinMetadata, SearchText = searchText }, }; StatementCompletionForm.AddDescription(listItem, match.Protein.ProteinMetadata.TextForMatchTypes(matchTypes), null); listUsedMatches.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 ProteinMatchType displayMatchType = ProteinMatchType.all; switch (SequenceTree.ProteinsDisplayMode) { case ProteinDisplayMode.ByName: displayMatchType &= ~ProteinMatchType.name; break; case ProteinDisplayMode.ByAccession: displayMatchType &= ~ProteinMatchType.accession; break; case ProteinDisplayMode.ByGene: displayMatchType &= ~ProteinMatchType.gene; break; case ProteinDisplayMode.ByPreferredName: displayMatchType &= ~ProteinMatchType.preferredName; break; } foreach (var match in matches) { // Try matching on name, accession etc - cycle through name, accession, preferredName, gene for (int bit = 1; bit < (int)ProteinMatchType.all; bit = bit << 1) { ProteinMatchType tryType = (ProteinMatchType)bit; if ((tryType != ProteinMatchType.sequence) && // We already did sequence (tryType != ProteinMatchType.description) && // And aren't ready for description (0 != (matchTypes & match.MatchType & tryType) && !listUsedMatches.Contains(match.Protein.Name))) { var listItem = new ListViewItem(); // Show description, and any other fields we were searching on if (match.AlternativeName != null) { listItem.Text = PeptideGroupTreeNode.ProteinModalDisplayText(match.AlternativeName, Settings.Default.ShowPeptidesDisplayMode); listItem.Tag = new StatementCompletionItem { ProteinInfo = match.AlternativeName, SearchText = searchText }; StatementCompletionForm.AddDescription(listItem, match.AlternativeName.TextForMatchTypes(displayMatchType & ~ProteinMatchType.name), searchText); } else { listItem.Text = PeptideGroupTreeNode.ProteinModalDisplayText(match.Protein.ProteinMetadata, Settings.Default.ShowPeptidesDisplayMode); listItem.Tag = new StatementCompletionItem { ProteinInfo = match.Protein.ProteinMetadata, SearchText = searchText }; StatementCompletionForm.AddDescription(listItem, match.Protein.ProteinMetadata.TextForMatchTypes(displayMatchType), searchText); } listUsedMatches.Add(match.Protein.Name); listItem.ImageIndex = (int)ImageId.protein; var tooltip = new StringBuilder(); tooltip.AppendLine(Resources.StatementCompletionTextBox_CreateListViewItems_Descriptions) .Append(match.Protein.ProteinMetadata.TextForMatchTypes(displayMatchType)); foreach (var altName in match.Protein.AlternativeNames) { tooltip.AppendLine().Append(altName.TextForMatchTypes(displayMatchType)); } 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(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 ((0 != (match.MatchType & ProteinMatchType.description)) && !listUsedMatches.Contains(match.Protein.Name)) { ProteinMetadata mainName = match.AlternativeDescription; string matchName = match.Protein.Name; var proteinInfo = match.Protein.ProteinMetadata; if (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 = PeptideGroupTreeNode.ProteinModalDisplayText(mainName, Settings.Default.ShowPeptidesDisplayMode), ImageIndex = (int)ImageId.protein, Tag = new StatementCompletionItem { ProteinInfo = proteinInfo, SearchText = searchText } }; StatementCompletionForm.AddDescription(listItem, mainName.TextForMatchTypes(displayMatchType), 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(displayMatchType | 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; 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)); }