changeset 4:f119fb382a21 draft

Uploaded
author estrain
date Mon, 23 May 2022 09:55:24 +0000
parents 2c887282d3ef
children d6c3cee5fe48
files data_manager_amrfinderplus/data_manager/data_manager_amrfinderplus.py
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/data_manager_amrfinderplus/data_manager/data_manager_amrfinderplus.py	Mon May 23 09:41:15 2022 +0000
+++ b/data_manager_amrfinderplus/data_manager/data_manager_amrfinderplus.py	Mon May 23 09:55:24 2022 +0000
@@ -12,13 +12,16 @@
 from ftplib import FTP
 
 
-def download_from_ncbi():
+def download_from_ncbi(output_direcotry):
     NCBI_FTP_SERVER = 'ftp.ncbi.nlm.nih.gov'
     FILENAME = 'version.txt' 
     NCBI_DOWNLOAD_PATH = '/pathogen/Antimicrobial_resistance/AMRFinderPlus/database/latest/'
     
     email = 'anonymous@example.com'
 
+    cwd = os.getcwd() 
+    os.chdir(output_directory)
+
     ftp = FTP( NCBI_FTP_SERVER )
     ftp.login( 'anonymous', email)
     ftp.cwd(NCBI_DOWNLOAD_PATH)
@@ -56,6 +59,8 @@
 
     ftp.quit()
     
+    os.chdir(cwd)    
+    
     return version 
 
 def print_json (version,argspath,argsname,argsout):
@@ -83,16 +88,15 @@
 
     args = parser.parse_args()
 
+    with open(args.out[0]) as fh:
+        params = json.load(fh)
 
-    with open(args.out[0]) as fh:
-        config = json.load(fh)
-
-    output_directory = config.get("output_data", [{}])[0].get("extra_files_path", None)
-    os.mkdir( output_directory )
+    output_directory = params['output_data'][0]['extra_files_path']
+    os.mkdir(output_directory)
     data_manager_dict = {}
 
     #Fetch the files and build blast databases
-    version=download_from_ncbi()    
+    version=download_from_ncbi(output_directory)    
 
     #shutil.copytree("amrdb",args.path[0])
     print_json(version,output_directory,args.name[0],args.out[0])