private void ExecuteBackground() { try { ProteinMatchTypes matchTypesRemaining = Settings.MatchTypes; using (var proteomeDb = ProteomeDb.OpenProteomeDb(Settings.ProteomeDbPath.FilePath, CancellationToken)) using (var session = proteomeDb.OpenStatelessSession(false)) { if (matchTypesRemaining.Contains(ProteinMatchType.sequence) && IsAminoAcidSequence(Settings.SearchText)) { AddProteinMatches(session, () => proteomeDb.GetDigestion() .GetProteinIdsThatMightHaveSequence(session, new[] { Settings.SearchText })); } matchTypesRemaining = matchTypesRemaining.Except(ProteinMatchType.sequence); if (DoMatching) { string pattern = @"%" + Settings.SearchText + @"%"; if (Settings.SearchText.Length < MIN_FREE_SEARCH_LENGTH) { // That could cast a pretty wide net - only match to beginning of keywords, and not to description or species pattern = Settings.SearchText + @"%"; matchTypesRemaining = matchTypesRemaining.Except(ProteinMatchType.description, ProteinMatchType.species); } var exprLike = new List <string>(); foreach (ProteinMatchType matchType in matchTypesRemaining) { exprLike.Add(String.Format(@"pn.{0} LIKE :expr", ProteinMatchTypeDbFieldName(matchType))); } String hql = @"SELECT distinct pn.Protein FROM " + typeof(DbProteinName) + @" pn " // ReSharper disable LocalizableElement + String.Format("\nWHERE {0}", String.Join(" OR ", exprLike)) + "\nORDER BY pn.IsPrimary DESC, pn.Name"; // ReSharper restore LocalizableElement IQuery query = session.CreateQuery(hql).SetParameter(@"expr", pattern); query.SetMaxResults(MaxResults); AddProteinMatches(session, () => { return(query.List <DbProtein>() .Where(dbProtein => null != dbProtein) .Select(dbProtein => dbProtein.Id.Value)); }); } } } catch (Exception exception) { if (CancellationToken.IsCancellationRequested) { return; } Trace.TraceError(@"Unhandled exception: {0}", exception); } }
public static string TextForMatchTypes(this ProteinMetadata p, ProteinMatchTypes types) { if (types.IsSingleton(ProteinMatchType.sequence)) { return(null); } var results = new List <string>(); if (types.Contains(ProteinMatchType.name)) { results.Add(p.Name ?? String.Empty); } if (types.Contains(ProteinMatchType.accession)) { results.Add(p.Accession ?? String.Empty); } if (types.Contains(ProteinMatchType.preferredName)) { results.Add(p.PreferredName ?? String.Empty); } if (types.Contains(ProteinMatchType.gene)) { results.Add(p.Gene ?? String.Empty); } if (types.Contains(ProteinMatchType.species)) { results.Add(p.Species ?? String.Empty); } if (types.Contains(ProteinMatchType.description)) // put this last, as it likely contains the others { results.Add(p.Description ?? String.Empty); } if (results.Count > 0) { return(String.Join(@" ", results)); } return(null); }