Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
sweng66 committed Nov 20, 2019
1 parent b5f94d1 commit 57befa0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions scripts/loading/go/load_gpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,16 @@ def load_go_annotations(gpad_file, noctua_gpad_file, gpi_file, annotation_type,
log.info(str(datetime.now()))
log.info("Uploading GPAD/GPI files to AWS...")

ENGINE_CREATED = 0

update_database_load_file_to_s3(nex_session, gpad_file, source_to_id,
edam_to_id, 'gpad')
edam_to_id, ENGINE_CREATED)

update_database_load_file_to_s3(nex_session, noctua_gpad_file, source_to_id,
edam_to_id, 'gpad')
update_database_load_file_to_s3(nex_session, gpi_file, source_to_id,
edam_to_id, ENGINE_CREATED)

update_database_load_file_to_s3(nex_session, gpi_file, source_to_id,
edam_to_id, 'gpi')
update_database_load_file_to_s3(nex_session, noctua_gpad_file, source_to_id,
edam_to_id, ENGINE_CREATED)

log.info(str(datetime.now()))
log.info("Writing summary...")
Expand Down Expand Up @@ -586,12 +588,12 @@ def delete_extensions_evidences(nex_session, annotation_id):
for x in to_delete_list:
nex_session.delete(x)

def update_database_load_file_to_s3(nex_session, go_file, source_to_id, edam_to_id, file_type):
def update_database_load_file_to_s3(nex_session, go_file, source_to_id, edam_to_id, ENGINE_CREATED):

import hashlib

desc = "Gene Product Association Data (GPAD)"
if file_type == 'gpi':
if "gp_information" in go_file:
desc = "Gene Product Information (GPI)"

go_local_file = open(go_file, mode='rb')
Expand All @@ -601,7 +603,10 @@ def update_database_load_file_to_s3(nex_session, go_file, source_to_id, edam_to_
go_row = nex_session.query(Filedbentity).filter_by(md5sum = go_md5sum).one_or_none()

if go_row is not None:
log.info("The current version of " + go_file + " is already in the database.\n")
return

log.info("Adding " + go_file + " to the database.\n")

nex_session.query(Dbentity).filter_by(display_name=go_file, dbentity_status='Active').update({"dbentity_status": 'Archived'})
nex_session.commit()
Expand All @@ -610,11 +615,12 @@ def update_database_load_file_to_s3(nex_session, go_file, source_to_id, edam_to_
topic_id = edam_to_id.get('EDAM:0089') ## topic:0089 Ontology and terminology
format_id = edam_to_id.get('EDAM:3475') ## format:3475 TSV

if 'gp_association' in go_file:
if ENGINE_CREATED == 0:
from sqlalchemy import create_engine
from src.models import DBSession
engine = create_engine(os.environ['NEX2_URI'], pool_recycle=3600)
DBSession.configure(bind=engine)
ENGINE_CREATED = 1

if go_row is None:
upload_file(CREATED_BY, go_local_file,
Expand Down

0 comments on commit 57befa0

Please sign in to comment.