annotate data_manager/funannotate.py @ 0:ef7f9e2f32f2 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
author iuc
date Thu, 26 Aug 2021 06:54:45 +0000
parents
children 8dff71edbce5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
1 #!/usr/bin/env python
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
2
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
3 import argparse
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
4 import json
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
5 import operator
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
6 import os
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
7 import subprocess
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
8 import sys
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
9 from datetime import datetime
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
10
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
11
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
12 if __name__ == "__main__":
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
13
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
14 parser = argparse.ArgumentParser()
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
15 parser.add_argument('--partial', dest='partial', action='store_true', help='Only download a small subset of data (for testing)')
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
16 parser.add_argument("version_id")
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
17 parser.add_argument("datatable_name")
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
18 parser.add_argument("galaxy_datamanager_filename")
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
19 args = parser.parse_args()
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
20
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
21 with open(args.galaxy_datamanager_filename) as fh:
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
22 config = json.load(fh)
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
23
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
24 output_directory = config.get("output_data", [{}])[0].get("extra_files_path", None)
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
25 data_manager_dict = {}
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
26 data_manager_dict["data_tables"] = config.get("data_tables", {})
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
27 data_manager_dict["data_tables"][args.datatable_name] = data_manager_dict[
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
28 "data_tables"
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
29 ].get(args.datatable_name, [])
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
30
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
31 os.mkdir(output_directory)
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
32 cmd_args = ['funannotate', 'setup', '-d', output_directory, '-b', 'all']
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
33 if args.partial:
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
34 cmd_args += ['-i', 'merops', '-b', 'eukaryota']
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
35 proc = subprocess.Popen(args=cmd_args, shell=False, cwd=output_directory)
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
36 return_code = proc.wait()
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
37 if return_code:
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
38 print("Error downloading Funannotate database.", file=sys.stderr)
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
39 sys.exit(return_code)
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
40
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
41 version_id = datetime.today().strftime('%Y-%m-%d-%H%M%S')
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
42
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
43 version = '1.0'
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
44
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
45 data_manager_dict["data_tables"][args.datatable_name].append(
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
46 dict(
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
47 value=version_id,
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
48 description="Funannotate database %s" % version_id,
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
49 format_version=version,
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
50 path=output_directory,
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
51 )
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
52 )
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
53
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
54 data_manager_dict["data_tables"][args.datatable_name].sort(
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
55 key=operator.itemgetter("value"), reverse=True
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
56 )
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
57 with open(args.galaxy_datamanager_filename, "w") as fh:
ef7f9e2f32f2 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_funannotate commit 9613152729099079c7465c3d5d42005ef22ca91e"
iuc
parents:
diff changeset
58 json.dump(data_manager_dict, fh, indent=2, sort_keys=True)