comparison data_manager/data_manager_humann2_download.py @ 5:ff9cf22838d4 draft default tip

"planemo upload for repository https://github.com/ASaiM/galaxytools/tree/master/data_managers/data_manager_humann2_database_downloader commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
author iuc
date Sun, 22 Nov 2020 12:50:08 +0000
parents 9244804f69a7
children
comparison
equal deleted inserted replaced
4:9244804f69a7 5:ff9cf22838d4
36 NB the directory pointed to by 'extra_files_path' 36 NB the directory pointed to by 'extra_files_path'
37 doesn't exist initially, it is the job of the script 37 doesn't exist initially, it is the job of the script
38 to create it if necessary. 38 to create it if necessary.
39 39
40 """ 40 """
41 params = json.loads(open(jsonfile).read()) 41 with open(jsonfile) as fh:
42 params = json.load(fh)
42 return (params['param_dict'], 43 return (params['param_dict'],
43 params['output_data'][0]['extra_files_path']) 44 params['output_data'][0]['extra_files_path'])
44 45
45 46
46 # Utility functions for creating data table dictionaries 47 # Utility functions for creating data table dictionaries
48 # Example usage: 49 # Example usage:
49 # >>> d = create_data_tables_dict() 50 # >>> d = create_data_tables_dict()
50 # >>> add_data_table(d,'my_data') 51 # >>> add_data_table(d,'my_data')
51 # >>> add_data_table_entry(dict(dbkey='hg19',value='human')) 52 # >>> add_data_table_entry(dict(dbkey='hg19',value='human'))
52 # >>> add_data_table_entry(dict(dbkey='mm9',value='mouse')) 53 # >>> add_data_table_entry(dict(dbkey='mm9',value='mouse'))
53 # >>> print str(json.dumps(d)) 54 # >>> print(json.dumps(d))
54 def create_data_tables_dict(): 55 def create_data_tables_dict():
55 """Return a dictionary for storing data table information 56 """Return a dictionary for storing data table information
56 57
57 Returns a dictionary that can be used with 'add_data_table' 58 Returns a dictionary that can be used with 'add_data_table'
58 and 'add_data_table_entry' to store information about a 59 and 'add_data_table_entry' to store information about a
107 database: database to download (chocophlan or uniref) 108 database: database to download (chocophlan or uniref)
108 build: build of the database to download 109 build: build of the database to download
109 target_dir: directory to put copy or link to the data file 110 target_dir: directory to put copy or link to the data file
110 111
111 """ 112 """
112 value = "%s-%s-%s" % (database, build, datetime.date.today().isoformat()) 113 value = "{}-{}-{}".format(database, build, datetime.date.today().isoformat())
113 db_target_dir = os.path.join(target_dir, database) 114 db_target_dir = os.path.join(target_dir, database)
114 build_target_dir = os.path.join(db_target_dir, build) 115 build_target_dir = os.path.join(db_target_dir, build)
115 cmd = "humann2_databases --download %s %s %s --update-config no" % ( 116 cmd = "humann2_databases --download {} {} {} --update-config no".format(
116 database, 117 database,
117 build, 118 build,
118 db_target_dir) 119 db_target_dir)
119 subprocess.check_call(cmd, shell=True) 120 subprocess.check_call(cmd, shell=True)
120 shutil.move(os.path.join(db_target_dir, database), build_target_dir) 121 shutil.move(os.path.join(db_target_dir, database), build_target_dir)
169 options.build, 170 options.build,
170 target_dir) 171 target_dir)
171 172
172 # Write output JSON 173 # Write output JSON
173 print("Outputting JSON") 174 print("Outputting JSON")
174 print(str(json.dumps(data_tables))) 175 with open(jsonfile, 'w') as fh:
175 open(jsonfile, 'wb').write(json.dumps(data_tables)) 176 json.dump(data_tables, fh, sort_keys=True)
176 print("Done.") 177 print("Done.")