예제 #1
0
        internal IList <long> GetProteinIdsThatMightHaveSequence(IStatelessSession session, ICollection <string> sequencesToLookFor)
        {
            Func <ICollection <String>, IEnumerable <long> > functionToCall;
            IList <String> uniqueStrings;
            bool           useSubsequenceTable;

            if (UseSubsequenceTable.HasValue)
            {
                useSubsequenceTable = UseSubsequenceTable.Value;
            }
            else
            {
                useSubsequenceTable = ProteomeDb.HasSubsequencesTable(() => session.Connection) &&
                                      !sequencesToLookFor.Any(s => s.Length < ProteomeDb.MIN_SEQUENCE_LENGTH);
            }
            if (useSubsequenceTable)
            {
                functionToCall = batchedArgs => QuerySubsequencesTableForSubstrings(session, batchedArgs);
                uniqueStrings  = RemoveSuperstrings(sequencesToLookFor
                                                    .Select(s => s.Substring(0, Math.Min(s.Length, ProteomeDb.MAX_SEQUENCE_LENGTH))));
            }
            else
            {
                functionToCall = batchedArgs => QueryProteinTableForSubstrings(session, batchedArgs);
                uniqueStrings  = RemoveSuperstrings(sequencesToLookFor);
            }
            return(ProteomeDb.BatchUpArgumentsForFunction(functionToCall, uniqueStrings, 500).Distinct().ToArray());
        }
예제 #2
0
 public Digestion(ProteomeDb proteomeDb, DbDigestion digestion) : base(proteomeDb, digestion)
 {
     Name              = digestion.Name;
     Description       = digestion.Description;
     MinSequenceLength = digestion.MinSequenceLength;
     MaxSequenceLength = digestion.MaxSequenceLength;
 }
예제 #3
0
 public IDictionary <String, List <Protein> > GetProteinsWithSequences(IEnumerable <string> sequences)
 {
     using (var session = ProteomeDb.OpenStatelessSession(false))
     {
         return(GetProteinsWithSequences(session, sequences));
     }
 }
예제 #4
0
        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);
            }
        }
예제 #5
0
        /// <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);
            }
        }
예제 #6
0
파일: EntityModel.cs 프로젝트: zrolfs/pwiz
 public EntityModel(ProteomeDb proteomeDb, T entity) : this(proteomeDb.ProteomeDbPath, entity)
 {
 }
예제 #7
0
 public Digestion(ProteomeDb proteomeDb)
 {
     ProteomeDb = proteomeDb;
 }
예제 #8
0
 // ReSharper disable NonLocalizedString
 private IList <Protein> GetProteinsWithIds(IStatelessSession session, IList <long> ids)
 {
     return(ProteomeDb.GetProteinsWithIds(session, ids));
 }
 private ProteinMatchSettings CreateProteinMatchSettings(SrmDocument srmDocument, ProteinMatchType matchTypes, String searchText)
 {
     var peptideSettings = srmDocument.Settings.PeptideSettings;
     var backgroundProteome = peptideSettings.BackgroundProteome;
     if (backgroundProteome.IsNone)
     {
         return null;
     }
     try
     {
         if (_proteomeDb != null && _proteomeDb.Path != backgroundProteome.DatabasePath)
         {
             _proteomeDb.Dispose();
             _proteomeDb = null;
         }
         if (_proteomeDb == null)
         {
             _proteomeDb = backgroundProteome.OpenProteomeDb();
         }
         return new ProteinMatchSettings(_proteomeDb.ProteomeDbPath,
                                     new ProteaseImpl(peptideSettings.Enzyme),
                                     matchTypes,
                                     searchText);
     }
     catch (SQLiteException)
     {
         // CONSIDER: Silent failure could be confusing.  Show a message box
         //           about failing to open the database.
         return null;
     }
 }
 public void Detach()
 {
     if (TextBox == null)
     {
         return;
     }
     HideStatementCompletionForm();
     if (_proteinMatcher != null)
     {
         _proteinMatcher.Cancel();
         _proteinMatcher = null;
     }
     if (null != _proteomeDb)
     {
         _proteomeDb.Dispose();
         _proteomeDb = null;
     }
     TextBox.KeyDown -= TextBox_KeyDown;
     TextBox.TextChanged -= TextBox_TextChanged;
     TextBox.GotFocus -= TextBox_GotFocus;
     TextBox.LostFocus -= TextBox_LostFocus;
     TextBox.LocationChanged -= TextBox_LocationChanged;
     TextBox = null;
 }
예제 #11
0
 public Digestion GetDigestion(ProteomeDb proteomeDb, PeptideSettings peptideSettings)
 {
     return proteomeDb.GetDigestion(peptideSettings.Enzyme.Name);
 }