/// <summary> /// Executes the query (which must be a query on the DbProtein table), and adds /// all of the rows in that query to the ProteinMatches. /// </summary> private void AddProteinMatches(IStatelessSession session, Func <IEnumerable <long> > proteinIdQuery) { Dictionary <long, ProteinMatch> newMatches = new Dictionary <long, ProteinMatch>(); lock (this) { if (_matches != null) { foreach (var entry in _matches) { newMatches.Add(entry.Key, entry.Value); } } } var newProteinIds = new List <long>(); CancellationToken.ThrowIfCancellationRequested(); foreach (long id in proteinIdQuery()) { CancellationToken.ThrowIfCancellationRequested(); if (newMatches.ContainsKey(id)) { continue; } newProteinIds.Add(id); } if (newProteinIds.Count == 0) { return; } using (var proteomeDb = ProteomeDb.OpenProteomeDb(Settings.ProteomeDbPath.FilePath, CancellationToken)) { // We fetched the protein ids. Now fetch all the protein rows themselves. var proteins = proteomeDb.GetProteinsWithIds(session, newProteinIds); foreach (var protein in proteins) { var proteinMatch = new ProteinMatch(Settings, protein); newMatches.Add(protein.Id, proteinMatch); } SetProteinMatches(newMatches); } }
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; }
/// <summary> /// Executes the query (which must be a query on the DbProtein table), and adds /// all of the rows in that query to the ProteinMatches. /// </summary> private void AddProteinMatches(IQuery query) { Dictionary <long, ProteinMatch> newMatches = new Dictionary <long, ProteinMatch>(); lock (this) { if (_matches != null) { foreach (var entry in _matches) { newMatches.Add(entry.Key, entry.Value); } } } query.SetMaxResults(MaxResults); var newProteinIds = new List <long>(); ThrowIfCancelled(); foreach (DbProtein dbProtein in query.Enumerable()) { ThrowIfCancelled(); if (!dbProtein.Id.HasValue || newMatches.ContainsKey(dbProtein.Id.Value)) { continue; } newProteinIds.Add(dbProtein.Id.Value); } if (newProteinIds.Count == 0) { return; } // We fetched the protein ids. Now fetch all the protein rows themselves. var newProteins = new List <DbProtein>(); _session.CreateCriteria(typeof(DbProtein)) .Add(Restrictions.In("Id", newProteinIds)) // Not L10N .List(newProteins); // Now fetch all of the protein name records at once var criteria = _session.CreateCriteria(typeof(DbProteinName)) .Add(Restrictions.In("Protein", newProteins)); // Not L10N var proteinNames = new Dictionary <DbProtein, List <DbProteinName> >(); foreach (DbProteinName proteinName in criteria.List()) { List <DbProteinName> names; if (!proteinNames.TryGetValue(proteinName.Protein, out names)) { names = new List <DbProteinName>(); proteinNames.Add(proteinName.Protein, names); } names.Add(proteinName); } // Create a ProteinMatch for each Protein foreach (var entry in proteinNames) { var proteinMatch = new ProteinMatch(Settings, new Protein(Settings.ProteomeDbPath, entry.Key, entry.Value)); if (entry.Key.Id.HasValue) { newMatches.Add(entry.Key.Id.Value, proteinMatch); } } SetProteinMatches(newMatches); }
/// <summary> /// Executes the query (which must be a query on the DbProtein table), and adds /// all of the rows in that query to the ProteinMatches. /// </summary> private void AddProteinMatches(IQuery query) { Dictionary<long, ProteinMatch> newMatches = new Dictionary<long, ProteinMatch>(); lock (this) { if (_matches != null) { foreach (var entry in _matches) { newMatches.Add(entry.Key, entry.Value); } } } query.SetMaxResults(MaxResults); var newProteinIds = new List<long>(); ThrowIfCancelled(); foreach (DbProtein dbProtein in query.Enumerable()) { ThrowIfCancelled(); if (!dbProtein.Id.HasValue || newMatches.ContainsKey(dbProtein.Id.Value)) { continue; } newProteinIds.Add(dbProtein.Id.Value); } if (newProteinIds.Count == 0) { return; } // We fetched the protein ids. Now fetch all the protein rows themselves. var newProteins = new List<DbProtein>(); _session.CreateCriteria(typeof (DbProtein)) .Add(Restrictions.In("Id", newProteinIds)) // Not L10N .List(newProteins); // Now fetch all of the protein name records at once var criteria = _session.CreateCriteria(typeof (DbProteinName)) .Add(Restrictions.In("Protein", newProteins)); // Not L10N var proteinNames = new Dictionary<DbProtein, List<DbProteinName>>(); foreach (DbProteinName proteinName in criteria.List()) { List<DbProteinName> names; if (!proteinNames.TryGetValue(proteinName.Protein, out names)) { names = new List<DbProteinName>(); proteinNames.Add(proteinName.Protein, names); } names.Add(proteinName); } // Create a ProteinMatch for each Protein foreach (var entry in proteinNames) { var proteinMatch = new ProteinMatch(Settings, new Protein(Settings.ProteomeDbPath, entry.Key, entry.Value)); if (entry.Key.Id.HasValue) newMatches.Add(entry.Key.Id.Value, proteinMatch); } SetProteinMatches(newMatches); }