annotate data_manager/data_manager_fetch_pharokka_db.py @ 1:50caca83e7c9 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit fcbcfe6bfcf007dc489ae035a6f23c07dc64ed31
author iuc
date Sun, 06 Aug 2023 10:11:42 +0000
parents 97f310b8e308
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
1 #!/usr/bin/env python
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
2
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
3 import argparse
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
4 import json
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
5 import os
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
6 import subprocess
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
7 import sys
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
8 from datetime import datetime
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
9
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
10
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
11 def main():
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
12 # Parse Command Line
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
13 parser = argparse.ArgumentParser(description="Create data manager JSON.")
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
14 parser.add_argument("--out", dest="output", action="store", help="JSON filename")
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
15 parser.add_argument("--version", dest="version", action="store", help="Version of the DB")
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
16 parser.add_argument(
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
17 "--test",
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
18 action="store_true",
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
19 help="option to test the script with an lighted database",
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
20 )
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
21
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
22 args = parser.parse_args()
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
23
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
24 # the output file of a DM is a json containing args that can be used by the DM
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
25 # most tools mainly use these args to find the extra_files_path for the DM, which can be used
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
26 # to store the DB data
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
27 with open(args.output) as fh:
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
28 params = json.load(fh)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
29
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
30 workdir = params["output_data"][0]["extra_files_path"]
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
31 os.mkdir(workdir)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
32
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
33 time = datetime.utcnow().strftime("%Y-%m-%dT%H%M%SZ")
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
34 db_value = "db_from_{0}".format(time)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
35 db_path = os.path.join(workdir, db_value)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
36
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
37 # create DB
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
38 if args.test: # the test only checks that the pharokka download script is available and copies the test DB
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
39
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
40 # check if install_databases.py is there
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
41 command_args = ["install_databases.py", "-h"]
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
42 proc = subprocess.Popen(args=command_args, shell=False)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
43 return_code = proc.wait()
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
44 if return_code:
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
45 print("Error downloading Pharokka database.", file=sys.stderr)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
46 sys.exit(return_code)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
47
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
48 # copy the test DB
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
49 test_db_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "subset_pharokka_db")
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
50 command_args = ["cp", "-r", test_db_path, db_path]
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
51 else:
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
52 command_args = ["install_databases.py", "-o", db_path]
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
53
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
54 proc = subprocess.Popen(args=command_args, shell=False)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
55 return_code = proc.wait()
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
56 if return_code:
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
57 print("Error downloading Pharokka database.", file=sys.stderr)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
58 sys.exit(return_code)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
59
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
60 # Update Data Manager JSON and write to file
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
61 data_manager_entry = {
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
62 "data_tables": {
1
50caca83e7c9 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit fcbcfe6bfcf007dc489ae035a6f23c07dc64ed31
iuc
parents: 0
diff changeset
63 "pharokka_db_versioned": {
0
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
64 "value": db_value,
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
65 "dbkey": db_value,
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
66 "version": args.version,
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
67 "name": f"Pharokka DB version {args.version} downloaded at {datetime.now()}",
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
68 "path": db_path,
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
69 }
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
70 }
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
71 }
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
72
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
73 with open(os.path.join(args.output), "w+") as fh:
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
74 json.dump(data_manager_entry, fh, sort_keys=True)
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
75
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
76
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
77 if __name__ == "__main__":
97f310b8e308 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_pharokka_database_fetcher/ commit 31e99045208605780b3fe4b89a999137adcabe13
iuc
parents:
diff changeset
78 main()