Skip to content

Commit

Permalink
Merge pull request #2124 from RTXteam/issue-2098
Browse files Browse the repository at this point in the history
#2098 fixing compute_ngd.py
  • Loading branch information
saramsey authored Aug 30, 2023
2 parents 993f192 + 1bc2ad8 commit cc7bc2c
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions code/ARAX/ARAXQuery/Overlay/compute_ngd.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,37 +442,20 @@ def _get_canonical_curies_map(self, curies):
return canonical_curies_map

def _setup_ngd_database(self):
# Download the ngd database if there isn't already a local copy or if a newer version is available
#db_path_local = f"{os.path.dirname(os.path.abspath(__file__))}/ngd/{self.ngd_database_name}"
#db_path_remote = f"/data/orangeboard/databases/KG2.3.4/{self.ngd_database_name}"
ngd_filepath = os.path.sep.join([*pathlist[:(RTXindex + 1)], 'code', 'ARAX', 'KnowledgeSources', 'NormalizedGoogleDistance'])
ngd_filepath = os.path.sep.join([*pathlist[:(RTXindex + 1)],
'code',
'ARAX',
'KnowledgeSources',
'NormalizedGoogleDistance'])
db_path_local = f"{ngd_filepath}{os.path.sep}{self.ngd_database_name}"
db_path_remote = RTXConfig.curie_to_pmids_path
# FW: Removed in favor of using the DBmanager but just commenting out in case there is some reason to keep this
# if not os.path.exists(f"{db_path_local}"):
# self.response.debug(f"Downloading fast NGD database because no copy exists... (will take a few minutes)")
# #os.system(f"scp rtxconfig@arax.ncats.io:{db_path_remote} {db_path_local}")
# os.system(f"scp {RTXConfig.curie_to_pmids_username}@{RTXConfig.curie_to_pmids_host}:{RTXConfig.curie_to_pmids_path} {db_path_local}")
# else:
# last_modified_local = int(os.path.getmtime(db_path_local))
# last_modified_remote_byte_str = subprocess.check_output(f"ssh rtxconfig@arax.ncats.io 'stat -c %Y {db_path_remote}'", shell=True)
# last_modified_remote = int(str(last_modified_remote_byte_str, 'utf-8'))
# if last_modified_local < last_modified_remote:
# self.response.debug(f"Downloading new version of fast NGD database... (will take a few minutes)")
# #os.system(f"scp rtxconfig@arax.ncats.io:{db_path_remote} {db_path_local}")
# os.system(f"scp {RTXConfig.curie_to_pmids_username}@{RTXConfig.curie_to_pmids_host}:{RTXConfig.curie_to_pmids_path} {db_path_local}")
# else:
# self.response.debug(f"Confirmed local NGD database is current")
DBmanager = ARAXDatabaseManager()
if DBmanager.check_versions():
self.response.debug(f"Downloading databases because mismatch in local versions and remote versions was found... (will take a few minutes)")
self.response = DBmanager.update_databases(response=self.response)
# Set up a connection to the database so it's ready for use
try:
connection = sqlite3.connect(db_path_local)
cursor = connection.cursor()
except Exception:
self.response.error(f"Encountered an error connecting to ngd sqlite database", error_code="DatabaseSetupIssue")
self.response.error("Encountered an error connecting "
"to ngd sqlite database",
error_code="DatabaseSetupIssue")
return None, None
else:
return connection, cursor
Expand All @@ -482,4 +465,3 @@ def _close_database(self):
self.cursor.close()
if self.connection:
self.connection.close()

0 comments on commit cc7bc2c

Please sign in to comment.