def upload(self, db): """Upload the content for this dataset into the database.""" dbid = self._check_reference(db) stmts = self._get_statements() # Raise any validity issues with statements as exceptions here # to avoid uploading invalid content. for stmt in stmts: assert_valid_statement(stmt) insert_db_stmts(db, stmts, dbid) return
def update(self, db): """Add any new statements that may have come into the dataset.""" dbid = self._check_reference(db, can_create=False) if dbid is None: raise ValueError("This knowledge base has not yet been " "registered.") existing_keys = set(db.select_all([db.RawStatements.mk_hash, db.RawStatements.source_hash], db.RawStatements.db_info_id == dbid)) stmts = self._get_statements() filtered_stmts = [s for s in stmts if (s.get_hash(), s.evidence[0].get_source_hash()) not in existing_keys] insert_db_stmts(db, filtered_stmts, dbid) return
def test_simple_db_insert(): db = get_temp_db() db._clear(force=True) stmts = [ Phosphorylation(Agent('MEK', db_refs={'FPLX': 'MEK'}), Agent('ERK', db_refs={'FPLX': 'ERK'}), evidence=Evidence(source_api='test')), Complex([Agent(n, db_refs={'FPLX': n}) for n in ('MEK', 'ERK')], evidence=Evidence(source_api='test')) ] dbid = db.insert(db.DBInfo, db_name='test', source_api='tester') insert_db_stmts(db, stmts, dbid) db_stmts = db.select_all(db.RawStatements) db_agents = db.select_all(db.RawAgents) assert len(db_stmts) == 2, len(db_stmts) assert len(db_agents) == 8, len(db_agents) db.session.close()
def upload(self, db): """Upload the content for this dataset into the database.""" dbid = self._check_reference(db) stmts = self._get_statements() insert_db_stmts(db, stmts, dbid) return