# HG changeset patch # User iuc # Date 1616190222 0 # Node ID 6dd9e00dea958a5e15eb50a7d52dce765c69f7f2 # Parent 9de2fb1ce1fb1881641fbcfe4c0e0a5ffa289ffb "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257" diff -r 9de2fb1ce1fb -r 6dd9e00dea95 data_manager/data_manager.py --- a/data_manager/data_manager.py Sun Nov 22 12:48:48 2020 +0000 +++ b/data_manager/data_manager.py Fri Mar 19 21:43:42 2021 +0000 @@ -37,21 +37,87 @@ os.remove(file_path) +def download_name_maps(url, workdir, partial): + + if partial: + map_files = [ + 'pdb.accession2taxid.gz', + ] + else: + map_files = [ + 'dead_nucl.accession2taxid.gz', + 'dead_prot.accession2taxid.gz', + 'dead_wgs.accession2taxid.gz', + 'nucl_gb.accession2taxid.gz', + 'nucl_wgs.accession2taxid.gz', + 'pdb.accession2taxid.gz', + 'prot.accession2taxid.gz', + 'prot.accession2taxid.FULL.gz' + ] + + if not os.path.exists(workdir): + os.makedirs(workdir) + + for map in map_files: + src = "{}{}".format(url, map) + dest = os.path.join(workdir, map) + + print("Downloading taxonomy accession2taxid file from {} to {}".format(src, dest)) + + try: + req = Request(src) + src = urlopen(req) + with open(dest, 'wb') as dst: + while True: + chunk = src.read(2**10) + if chunk: + dst.write(chunk) + else: + break + finally: + if src: + src.close() + + +def move_files_to_final_dir(workdir, target_directory, copy=False): + for filename in os.listdir(workdir): + if copy: + shutil.copy(os.path.join(workdir, filename), target_directory) + else: + shutil.move(os.path.join(workdir, filename), target_directory) + + def main(args): - workdir = os.path.join(os.getcwd(), 'taxonomy') + workdir = os.path.abspath(os.path.join(os.getcwd(), 'taxonomy')) url_download(args.url, workdir) + data_manager_entry = {} data_manager_entry['value'] = args.name.lower() data_manager_entry['name'] = args.name data_manager_entry['path'] = '.' data_manager_json = dict(data_tables=dict(ncbi_taxonomy=data_manager_entry)) + with open(args.output) as fh: params = json.load(fh) - target_directory = params['output_data'][0]['extra_files_path'] - os.mkdir(target_directory) - output_path = os.path.abspath(os.path.join(os.getcwd(), 'taxonomy')) - for filename in os.listdir(workdir): - shutil.move(os.path.join(output_path, filename), target_directory) + + if args.name_maps: + workdir_a2t = os.path.join(os.getcwd(), 'accession2taxid') + download_name_maps("ftp://ftp.ncbi.nlm.nih.gov/pub/taxonomy/accession2taxid/", workdir_a2t, args.partial) + + target_directory_a2t = os.path.join(params['output_data'][0]['extra_files_path'], "accession2taxid") + os.makedirs(target_directory_a2t) + move_files_to_final_dir(workdir_a2t, target_directory_a2t) + + # Also copy taxonomy data to accession2taxid dir + move_files_to_final_dir(workdir, target_directory_a2t, copy=True) + + data_manager_json['data_tables']['ncbi_accession2taxid'] = data_manager_entry + + target_directory_tax = os.path.join(params['output_data'][0]['extra_files_path'], "taxonomy") + os.makedirs(target_directory_tax) + + move_files_to_final_dir(workdir, target_directory_tax) + with open(args.output, 'w') as fh: json.dump(data_manager_json, fh, sort_keys=True) @@ -61,6 +127,8 @@ parser.add_argument('--out', dest='output', action='store', help='JSON filename') parser.add_argument('--name', dest='name', action='store', default=str(datetime.date.today()), help='Data table entry unique ID') parser.add_argument('--url', dest='url', action='store', default='ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz', help='Download URL') + parser.add_argument('--name-maps', dest='name_maps', action='store_true', help='') + parser.add_argument('--partial', dest='partial', action='store_true', help='Only download a small subset of data (for testing)') args = parser.parse_args() main(args) diff -r 9de2fb1ce1fb -r 6dd9e00dea95 data_manager/ncbi_taxonomy_fetcher.xml --- a/data_manager/ncbi_taxonomy_fetcher.xml Sun Nov 22 12:48:48 2020 +0000 +++ b/data_manager/ncbi_taxonomy_fetcher.xml Fri Mar 19 21:43:42 2021 +0000 @@ -1,5 +1,5 @@ - + taxonomy downloader python @@ -13,11 +13,15 @@ #if $database_name: --name '${database_name}' #end if + $name_maps + $partial_data ]]> + + @@ -28,9 +32,17 @@ + + + + + + + Download a taxonomy dump from a provided URL. The default URL is the latest dump from NCBI taxonomy. + The accession2taxid data comes from ftp://ftp.ncbi.nlm.nih.gov/pub/taxonomy/accession2taxid/ and can be used by the Diamond data_manager (uses ~20Gb as of 2021). diff -r 9de2fb1ce1fb -r 6dd9e00dea95 data_manager_conf.xml --- a/data_manager_conf.xml Sun Nov 22 12:48:48 2020 +0000 +++ b/data_manager_conf.xml Fri Mar 19 21:43:42 2021 +0000 @@ -1,12 +1,13 @@ - + + ${path}/taxonomy ncbi_taxonomy/${value} ${GALAXY_DATA_MANAGER_DATA_PATH}/ncbi_taxonomy/${value} @@ -14,5 +15,19 @@ + + + + + + + ${path}/accession2taxid + ncbi_accession2taxid/${value} + + ${GALAXY_DATA_MANAGER_DATA_PATH}/ncbi_accession2taxid/${value} + abspath + + + diff -r 9de2fb1ce1fb -r 6dd9e00dea95 test-data/ncbi_accession2taxid.loc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/ncbi_accession2taxid.loc Fri Mar 19 21:43:42 2021 +0000 @@ -0,0 +1,5 @@ +# Tab separated fields where +# value is unique key +# name is descriptive name +# path is path to directory containing accession2taxid files +#value name path diff -r 9de2fb1ce1fb -r 6dd9e00dea95 test-data/taxonomy_with_accession2taxid.json --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/taxonomy_with_accession2taxid.json Fri Mar 19 21:43:42 2021 +0000 @@ -0,0 +1,1 @@ +{"data_tables": {"ncbi_accession2taxid": {"name": "tax_name", "path": ".", "value": "tax_name"}, "ncbi_taxonomy": {"name": "tax_name", "path": ".", "value": "tax_name"}}} \ No newline at end of file diff -r 9de2fb1ce1fb -r 6dd9e00dea95 tool-data/ncbi_accession2taxid.loc.sample --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tool-data/ncbi_accession2taxid.loc.sample Fri Mar 19 21:43:42 2021 +0000 @@ -0,0 +1,5 @@ +# Tab separated fields where +# value is unique key +# name is descriptive name +# path is path to directory containing accession2taxid files +#value name path diff -r 9de2fb1ce1fb -r 6dd9e00dea95 tool_data_table_conf.xml.sample --- a/tool_data_table_conf.xml.sample Sun Nov 22 12:48:48 2020 +0000 +++ b/tool_data_table_conf.xml.sample Fri Mar 19 21:43:42 2021 +0000 @@ -5,4 +5,8 @@ value, name, path + + value, name, path + +
diff -r 9de2fb1ce1fb -r 6dd9e00dea95 tool_data_table_conf.xml.test --- a/tool_data_table_conf.xml.test Sun Nov 22 12:48:48 2020 +0000 +++ b/tool_data_table_conf.xml.test Fri Mar 19 21:43:42 2021 +0000 @@ -5,4 +5,8 @@ value, name, path + + value, name, path + +