public ProteinMatch(ProteinMatchSettings proteinMatchSettings, Protein protein) { Settings = proteinMatchSettings; Protein = protein; MatchTypes = ProteinMatchTypes.EMPTY; String ltext = proteinMatchSettings.SearchText.ToLower(); foreach (ProteinMatchType matchType in ProteinMatchTypes.ALL) // name, accession, gene, etc - case insenstive { if (proteinMatchSettings.MatchTypes.Contains(matchType) && !proteinMatchSettings.MatchTypes.Contains(ProteinMatchType.sequence) && !proteinMatchSettings.MatchTypes.Contains(ProteinMatchType.description)) // handle sequence and description below { if (Matches(protein.ProteinMetadata, matchType, ltext)) { MatchTypes = MatchTypes.Union(matchType); } else { foreach (ProteinMetadata alternative in Protein.AlternativeNames) { if (Matches(alternative, matchType, ltext)) { MatchTypes = MatchTypes.Union(matchType); AlternativeName = alternative; break; } } } } } if (MatchTypes.IsEmpty && // Don't bother declaring a description match if we already have a more specific one (name, accession etc) proteinMatchSettings.MatchTypes.Contains(ProteinMatchType.description)) { if (ContainsLowerCase(protein.Description, ltext) || ContainsLowerCase(protein.Name, ltext)) { MatchTypes = MatchTypes.Union(ProteinMatchType.description); } else { foreach (ProteinMetadata alternative in Protein.AlternativeNames) { if (ContainsLowerCase(alternative.Name, ltext) || ContainsLowerCase(alternative.Description, ltext)) { MatchTypes = MatchTypes.Union(ProteinMatchType.description); AlternativeDescription = alternative; } } } } if (proteinMatchSettings.MatchTypes.Contains(ProteinMatchType.sequence)) { if (protein.Sequence.IndexOf(proteinMatchSettings.SearchText, StringComparison.Ordinal) >= 0) { MatchTypes = MatchTypes.Union(ProteinMatchType.sequence); } } }
public ProteinMatchQuery(ProteinMatchSettings settings, CancellationToken cancellationToken, int maxResults = MAX_RESULTS_DEFAULT) { Settings = settings; CancellationToken = cancellationToken; MaxResults = maxResults; }
public ProteinMatch(ProteinMatchSettings proteinMatchSettings, Protein protein) { Settings = proteinMatchSettings; Protein = protein; String ltext = proteinMatchSettings.SearchText.ToLower(); for (int bit = 1; bit < (int)ProteinMatchType.all; bit <<= 1) // name, accession, gene, etc - case insenstive { ProteinMatchType matchType = (ProteinMatchType)bit; if ((0 != (proteinMatchSettings.MatchTypes & matchType)) && (0 == (matchType & (ProteinMatchType.sequence | ProteinMatchType.description)))) // handle sequence and description below { if (Matches(protein.ProteinMetadata, matchType, ltext)) { MatchType |= matchType; } else { foreach (ProteinMetadata alternative in Protein.AlternativeNames) { if (Matches(alternative, matchType, ltext)) { MatchType |= matchType; AlternativeName = alternative; break; } } } } } if ((MatchType == 0) && // Don't bother declaring a description match if we already have a more specific one (name, accession etc) (0 != (proteinMatchSettings.MatchTypes & ProteinMatchType.description))) { if (ContainsLowerCase(protein.Description, ltext) || ContainsLowerCase(protein.Name, ltext)) { MatchType |= ProteinMatchType.description; } else { foreach (ProteinMetadata alternative in Protein.AlternativeNames) { if (ContainsLowerCase(alternative.Name, ltext) || ContainsLowerCase(alternative.Description, ltext)) { MatchType |= ProteinMatchType.description; AlternativeDescription = alternative; } } } } List <DigestedPeptide> digestedPeptides = new List <DigestedPeptide>(); if (0 != (proteinMatchSettings.MatchTypes & ProteinMatchType.sequence)) { if (proteinMatchSettings.Protease != null) { String lastPeptide = null; foreach (var peptide in proteinMatchSettings.Protease.Digest(protein)) { if (!peptide.Sequence.StartsWith(proteinMatchSettings.SearchText)) { continue; } // If this peptide is just an extension of the previous peptide (i.e. with one // more missed cleavage), then only include it if the user has typed the entire // sequence of the previous peptide. if (lastPeptide != null && peptide.Sequence.StartsWith(lastPeptide) && lastPeptide.Length > proteinMatchSettings.SearchText.Length) { continue; } lastPeptide = peptide.Sequence; MatchType |= ProteinMatchType.sequence; digestedPeptides.Add(peptide); } } } DigestedPeptides = digestedPeptides; }
public ProteinMatchQuery(ProteinMatchSettings settings, int maxResults = MAX_RESULTS_DEFAULT) { Settings = settings; MaxResults = maxResults; }
/// <summary> /// When the text in the editTextBox changes, fire off the query to populate the statement completion popup. /// </summary> private void DoStatementCompletion() { if (DisableCompletion) return; String searchText = TextBox.Text; if (searchText.Length == 0) { HideStatementCompletionForm(); return; } if (_proteinMatcherLast != null) { //if (_proteinMatcherLast.Settings.SearchText == searchText) //{ // // Query is already executing for the text that the user typed: no work to do now. // return; //} if (searchText.StartsWith(_proteinMatcherLast.Settings.SearchText)) { // If the new text is just longer than the previous text, see if we can just refine the results // of the previous query. var results = _proteinMatcherLast.GetMatches(); var newResults = new List<ProteinMatch>(); if (results != null) { var oldSettings = _proteinMatcherLast.Settings; var newSettings = new ProteinMatchSettings(oldSettings.ProteomeDbPath, oldSettings.Protease, MatchTypes, searchText); newResults.AddRange(RefineMatches(results, newSettings)); } if (newResults.Count == 0) { // Nothing from the previous query matches: hide the statement completion form. HideStatementCompletionForm(); _proteinMatcherLast = null; } else { // Display the refined results: we'll still fire off another query to see if we get better results. DisplayResultsNow(newResults, _proteinMatcherLast.MaxResults); } } } if (_proteinMatcher != null) { _proteinMatcher.Cancel(); _proteinMatcher = null; } var settings = CreateProteinMatchSettings(_documentUiContainer.DocumentUI, MatchTypes, searchText); if (settings != null) { _proteinMatcher = new ProteinMatchQuery(settings); _proteinMatcher.BeginExecute(DisplayResults); } }
public static IList<ProteinMatch> RefineMatches(IEnumerable<ProteinMatch> matches, ProteinMatchSettings settings) { var newMatches = new List<ProteinMatch>(); foreach (var match in matches) { var newMatch = new ProteinMatch(settings, match.Protein); if (newMatch.MatchType != 0) { newMatches.Add(newMatch); } } return newMatches; }
public ProteinMatch(ProteinMatchSettings proteinMatchSettings, Protein protein) { Settings = proteinMatchSettings; Protein = protein; String ltext = proteinMatchSettings.SearchText.ToLower(); for (int bit = 1; bit < (int)ProteinMatchType.all; bit <<= 1) // name, accession, gene, etc - case insenstive { ProteinMatchType matchType = (ProteinMatchType) bit; if ((0 != (proteinMatchSettings.MatchTypes & matchType)) && (0==(matchType &(ProteinMatchType.sequence|ProteinMatchType.description)))) // handle sequence and description below { if (Matches(protein.ProteinMetadata, matchType, ltext)) { MatchType |= matchType; } else { foreach (ProteinMetadata alternative in Protein.AlternativeNames) { if (Matches(alternative, matchType, ltext)) { MatchType |= matchType; AlternativeName = alternative; break; } } } } } if ((MatchType == 0) && // Don't bother declaring a description match if we already have a more specific one (name, accession etc) (0 != (proteinMatchSettings.MatchTypes & ProteinMatchType.description))) { if (ContainsLowerCase(protein.Description, ltext) || ContainsLowerCase(protein.Name, ltext)) { MatchType |= ProteinMatchType.description; } else { foreach (ProteinMetadata alternative in Protein.AlternativeNames) { if (ContainsLowerCase(alternative.Name, ltext) || ContainsLowerCase(alternative.Description, ltext)) { MatchType |= ProteinMatchType.description; AlternativeDescription = alternative; } } } } List<DigestedPeptide> digestedPeptides = new List<DigestedPeptide>(); if (0 != (proteinMatchSettings.MatchTypes & ProteinMatchType.sequence)) { if (proteinMatchSettings.Protease != null) { String lastPeptide = null; foreach (var peptide in proteinMatchSettings.Protease.Digest(protein)) { if (!peptide.Sequence.StartsWith(proteinMatchSettings.SearchText)) { continue; } // If this peptide is just an extension of the previous peptide (i.e. with one // more missed cleavage), then only include it if the user has typed the entire // sequence of the previous peptide. if (lastPeptide != null && peptide.Sequence.StartsWith(lastPeptide) && lastPeptide.Length > proteinMatchSettings.SearchText.Length) { continue; } lastPeptide = peptide.Sequence; MatchType |= ProteinMatchType.sequence; digestedPeptides.Add(peptide); } } } DigestedPeptides = digestedPeptides; }
public ProteinMatchQuery(ProteinMatchSettings settings, int maxResults = MAX_RESULTS_DEFAULT) { Settings = settings; MaxResults = maxResults; }