annotate data_manager/data_manager.py @ 2:2b4526fdf7fb draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
author iuc
date Mon, 24 Apr 2023 12:26:46 +0000
parents 15b97817550a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
1 #!/usr/bin/env python
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
2 #
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
3 # Data manager for reference data for the 'BUSCO' Galaxy tools
0
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
4 import argparse
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
5 import datetime
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
6 import json
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
7 import os
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
8 import shutil
2
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
9 import subprocess
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
10 from pathlib import Path
0
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
11
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
12
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
13 def main(args):
2
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
14 workdir = os.path.join(os.getcwd(), "busco_downloads")
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
15 cmd = "busco --download %s" % args.database
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
16 subprocess.check_call(cmd, shell=True)
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
17 with open(args.json) as fh:
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
18 params = json.load(fh)
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
19 target_directory = params["output_data"][0]["extra_files_path"]
0
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
20 data_manager_entry = {}
2
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
21 data_manager_entry["value"] = args.name.lower()
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
22 data_manager_entry["name"] = args.name
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
23 data_manager_entry["version"] = args.version
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
24 data_manager_entry["path"] = str(Path(target_directory))
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
25 data_manager_json = dict(data_tables=dict(busco_database=data_manager_entry))
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
26
0
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
27 os.mkdir(target_directory)
2
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
28 output_path = os.path.abspath(os.path.join(os.getcwd(), "busco_downloads"))
0
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
29 for filename in os.listdir(workdir):
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
30 shutil.move(os.path.join(output_path, filename), target_directory)
2
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
31 with open(args.json, "w") as fh:
1
15b97817550a "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
iuc
parents: 0
diff changeset
32 json.dump(data_manager_json, fh, sort_keys=True)
0
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
33
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
34
2
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
35 if __name__ == "__main__":
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
36
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
37 # Read command line
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
38 parser = argparse.ArgumentParser(description="Download BUSCO database")
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
39 parser.add_argument("--database", help="Database name")
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
40 parser.add_argument(
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
41 "--name", default=str(datetime.date.today()), help="Data table entry unique ID"
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
42 )
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
43 parser.add_argument("--version", help="BUSCO version")
2b4526fdf7fb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2d2c72dc464b938bfa4def2511ce0938f3a1ea7d
iuc
parents: 1
diff changeset
44 parser.add_argument("--json", help="Path to JSON file")
0
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
45 args = parser.parse_args()
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
46
53eec20e8fb6 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_busco/ commit 2896dcfd180800d00ea413a59264ef8b11788b8e
iuc
parents:
diff changeset
47 main(args)