Exemple #1
0
 private void ReadVersion(ISession session)
 {
     // do we even have a version? 0th-gen protdb doesn't have this.
     if (!SqliteOperations.TableExists(session.Connection, @"ProteomeDbSchemaVersion"))
     {
         _schemaVersionMajor = SCHEMA_VERSION_MAJOR_0; // an ancient, unversioned file
         _schemaVersionMinor = SCHEMA_VERSION_MINOR_0; // an ancient, unversioned file
     }
     else
     {
         using (IDbCommand cmd2 = session.Connection.CreateCommand())
         {
             cmd2.CommandText = @"SELECT SchemaVersionMajor FROM ProteomeDbSchemaVersion";
             var obj2 = cmd2.ExecuteScalar();
             _schemaVersionMajor = Convert.ToInt32(obj2);
         }
         using (IDbCommand cmd3 = session.Connection.CreateCommand())
         {
             cmd3.CommandText = @"SELECT SchemaVersionMinor FROM ProteomeDbSchemaVersion";
             var obj3 = cmd3.ExecuteScalar();
             _schemaVersionMinor = Convert.ToInt32(obj3);
         }
     }
     _schemaVersionMajorAsRead = _schemaVersionMajor;
     _schemaVersionMinorAsRead = _schemaVersionMinor;
 }
Exemple #2
0
 public void ReadScores(SQLiteConnection connection)
 {
     if (!SqliteOperations.TableExists(connection, @"peptidescores"))
     {
         return;
     }
     using (var cmd = new SQLiteCommand(connection))
     {
         cmd.CommandText =
             @"select PeptideModSeq, PrecursorCharge, SourceFile, QValue, PosteriorErrorProbability from peptidescores";
         using (var reader = cmd.ExecuteReader())
         {
             while (reader.Read())
             {
                 var    key      = Tuple.Create(reader.GetString(0), Convert.ToInt32(reader.GetValue(1)));
                 var    value    = Tuple.Create(reader.GetDouble(3), reader.GetDouble(3));
                 string filename = reader.GetString(2);
                 IDictionary <string, Tuple <double, double> > values;
                 if (!_dictionary.TryGetValue(key, out values))
                 {
                     values = new Dictionary <string, Tuple <double, double> >();
                     _dictionary.Add(key, values);
                 }
                 values[filename] = value;
             }
         }
     }
 }
Exemple #3
0
        public string GetDocumentXml()
        {
            using (var session = new StatelessSessionWithLock(_sessionFactory.OpenStatelessSession(), _databaseLock,
                                                              false, CancellationToken.None))
            {
                if (!SqliteOperations.TableExists(session.Connection, @"DocumentXml"))
                {
                    return(null);
                }

                using (var cmd = session.Connection.CreateCommand())
                {
                    cmd.CommandText = @"SELECT Xml FROM DocumentXml";
                    return(Convert.ToString(cmd.ExecuteScalar()));
                }
            }
        }
Exemple #4
0
        private readonly bool _isTmp; // We won't hang onto the global session factory if we know we're temporary

        private ProteomeDb(String path, CancellationToken cancellationToken, bool isTmp)
        {
            _schemaVersionMajor       = -1; // unknown
            _schemaVersionMinor       = -1; // unknown
            _schemaVersionMajorAsRead = -1; // unknown
            _schemaVersionMinorAsRead = -1; // unknown
            _isTmp = isTmp;
            if (!File.Exists(path))
            {
                // Do not try to open the file if it does not exist, because that would create a zero byte file.
                throw new FileLoadException(String.Format(Resources.ProteomeDb_ProteomeDb_The_file__0__does_not_exist_, path));
            }
            _databaseResource = DatabaseResource.GetDbResource(path);
            CancellationToken = cancellationToken;
            using (var session = OpenSession())
            {
                // Is this even a proper protDB file? (https://skyline.gs.washington.edu/labkey/announcements/home/issues/exceptions/thread.view?rowId=14893)
                if (!SqliteOperations.TableExists(session.Connection, @"ProteomeDbProteinName"))
                {
                    throw new FileLoadException(
                              String.Format(Resources.ProteomeDb_ProteomeDb__0__does_not_appear_to_be_a_valid___protDB__background_proteome_file_, path));
                }

                // Do we need to update the db to current version?
                ReadVersion(session);
            }
            if (_schemaVersionMajor != SCHEMA_VERSION_MAJOR_CURRENT)
            {
                throw new FileLoadException(
                          String.Format(Resources.SessionFactoryFactory_EnsureVersion_Background_proteome_file__0__has_a_format_which_is_newer_than_the_current_software___Please_update_to_the_latest_software_version_and_try_again_,
                                        Path));
            }
            else if (_schemaVersionMinor < SCHEMA_VERSION_MINOR_CURRENT)
            {
                using (var session = OpenWriteSession())
                {
                    UpdateSchema(session);
                }
            }
        }
Exemple #5
0
 public void TestTableExists()
 {
     using (var connection = new SQLiteConnection(new SQLiteConnectionStringBuilder
     {
         DataSource = ":memory:"
     }.ToString()))
     {
         connection.Open();
         using (var cmd = connection.CreateCommand())
         {
             cmd.CommandText = "CREATE TABLE Table1(Id INTEGER)";
             cmd.ExecuteNonQuery();
         }
         using (var cmd = connection.CreateCommand())
         {
             cmd.CommandText = "CREATE TABLE \"Table With Space\"(Id INTEGER)";
             cmd.ExecuteNonQuery();
         }
         Assert.IsTrue(SqliteOperations.TableExists(connection, "Table1"));
         Assert.IsFalse(SqliteOperations.TableExists(connection, "Table2"));
         Assert.IsTrue(SqliteOperations.TableExists(connection, "Table With Space"));
         Assert.IsFalse(SqliteOperations.TableExists(connection, "Other Table With Space"));
     }
 }
Exemple #6
0
 internal static bool CheckHasSubsequenceTable(IDbConnection connection)
 {
     return(SqliteOperations.TableExists(connection, @"ProteomeDbSubsequence"));
 }