annotate data_manager/bakta_build_database.py @ 6:97b1b5ad1cda draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
author iuc
date Thu, 20 Jun 2024 19:13:58 +0000
parents baceff842902
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
1 import argparse
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
2 import hashlib
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
3 import json
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
4 import re
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
5 import sys
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
6 import tarfile
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
7 from datetime import datetime
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
8 from pathlib import Path
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
9
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
10
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
11 import requests
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
12
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
13
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
14 class GetBaktaDatabaseInfo:
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
15 """
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
16 Extract bakta database information to make a json file for data_manager
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
17 """
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
18
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
19 def __init__(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
20 self,
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
21 data_table_name="bakta_database",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
22 db_version="latest",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
23 tarball_name="db.tar.gz",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
24 test_mode=False,
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
25 ):
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
26 self.bakta_table_list = None
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
27 self.db_url = None
4
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
28 self.db_name = "bakta-db"
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
29 self.db_type = ""
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
30 self.data_table_entry = None
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
31 self.data_table_name = data_table_name
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
32 self.tar_name = tarball_name
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
33 self.db_version = db_version
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
34 self.DB_VERSIONS_URL = "https://raw.githubusercontent.com/oschwengers/bakta/master/db-versions.json"
5
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
35 self.DB_TEST_URL = "https://zenodo.org/record/11381156/files/db-versions.json"
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
36 self.test_mode = test_mode
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
37
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
38 def get_database_type(self):
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
39 self.light_db = bool(re.search(pattern="light", string=self.db_version))
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
40 self.db_version = self.db_version.split(sep="_")[0]
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
41 if self.light_db:
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
42 self.db_type = "light"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
43 self.tar_name = "db-light.tar.gz"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
44 self.md5 = self.fetch_db_versions()["md5-light"]
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
45 else:
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
46 self.md5 = self.fetch_db_versions()["md5"]
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
47
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
48 def get_data_table_format(self):
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
49 """
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
50 Skeleton of a data_table format
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
51 return: a data table formated for json output
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
52 """
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
53 self.data_table_entry = {"data_tables": {self.data_table_name: {}}}
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
54 return self.data_table_entry
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
55
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
56 def fetch_db_versions(self):
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
57 """
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
58 List bakta database info related to the db_version selected
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
59 """
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
60
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
61 if self.test_mode:
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
62 self.DB_VERSIONS_URL = self.DB_TEST_URL
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
63 try:
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
64 with requests.get(self.DB_VERSIONS_URL) as resp:
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
65 versions = json.loads(resp.content)
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
66 except IOError as e:
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
67 print(e, file=sys.stderr)
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
68 raise e
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
69
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
70 if self.db_version == "latest":
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
71 db_date_list = []
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
72 for db_dic in versions:
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
73 db_date_list.append(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
74 datetime.strptime(db_dic["date"], "%Y-%m-%d").date()
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
75 )
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
76 filtered_version = max(versions, key=lambda x: x["date"])
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
77 else:
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
78 filtered_version = None
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
79 for item in versions:
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
80 if "{0}.{1}".format(item["major"], item["minor"]) == self.db_version:
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
81 filtered_version = item
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
82 break
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
83 if filtered_version is None:
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
84 print("No matching version detected in the list")
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
85 else:
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
86 self.db_url = f"https://zenodo.org/record/{filtered_version['record']}/files/{self.tar_name}"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
87 return filtered_version
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
88
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
89 def get_data_manager(self, bakta_database_info):
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
90 self.bakta_table_list = self.get_data_table_format()
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
91 bakta_name = (
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
92 f"V{bakta_database_info['major']}."
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
93 f"{bakta_database_info['minor']}{self.db_type}_"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
94 f"{bakta_database_info['date']}"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
95 )
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
96 tool_version = str(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
97 f"{bakta_database_info['software-min']['major']}."
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
98 f"{bakta_database_info['software-min']['minor']}"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
99 )
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
100 data_info = dict(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
101 value=bakta_name,
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
102 dbkey=bakta_database_info["record"],
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
103 bakta_version=tool_version,
4
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
104 path=self.db_name,
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
105 )
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
106 self.bakta_table_list["data_tables"][self.data_table_name] = [data_info]
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
107 return self.bakta_table_list
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
108
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
109
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
110 class InstallBaktaDatabase(GetBaktaDatabaseInfo):
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
111 """
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
112 Download the bakta database,
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
113 check md5 sum,
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
114 untar the download db and update for the amrfinderplus database
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
115 """
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
116
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
117 def __init__(
4
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
118 self,
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
119 db_dir=Path.cwd(),
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
120 db_name="bakta-db",
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
121 db_version="latest",
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
122 test_mode=False
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
123 ):
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
124 super().__init__()
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
125 self.md5 = None
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
126 self.db_version = db_version
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
127 self.db_dir = db_dir
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
128 self.db_name = db_name
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
129 self.tarball_path = ""
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
130 self.test_mode = test_mode
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
131 self.get_database_type()
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
132
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
133 def download(self):
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
134 bakta_path = Path(self.db_dir).joinpath(self.tar_name)
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
135 try:
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
136 with bakta_path.open("wb") as fh_out, requests.get(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
137 self.db_url, stream=True) as resp:
6
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
138 # total_length = resp.headers.get("content-length")
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
139 for data in resp.iter_content(chunk_size=1024 * 1024):
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
140 fh_out.write(data)
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
141 print(f"Download bakta database {self.db_version}")
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
142 self.tarball_path = bakta_path
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
143 except IOError:
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
144 print(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
145 f"ERROR: Could not download file from Zenodo!"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
146 f" url={self.db_url}, to={self.tarball_path}"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
147 )
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
148
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
149 def untar(self):
4
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
150 db_path = Path(self.db_dir).joinpath(self.db_name)
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
151 try:
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
152 with self.tarball_path.open("rb") as fh_in, tarfile.open(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
153 fileobj=fh_in, mode="r:gz"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
154 ) as tar_file:
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
155 tar_file.extractall(path=db_path)
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
156 print(f"Untar the database in {db_path}")
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
157 except OSError:
4
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
158 sys.exit(f"ERROR: Could not extract {self.tar_name} " f"to {db_path}")
6
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
159 if not self.test_mode:
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
160 self.move_files(db_path=db_path)
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
161 self.db_dir = db_path.resolve()
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
162
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
163 def delete_folder(self, path):
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
164 for sub in path.iterdir():
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
165 if sub.is_dir() and sub.name != "latest":
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
166 self.delete_folder(sub)
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
167 else:
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
168 sub.unlink()
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
169 path.rmdir()
4
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
170
5
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
171 def move_files(self, db_path):
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
172 if db_path.joinpath("db-light").is_dir():
4
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
173 input_dir = db_path.joinpath("db-light")
5
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
174 elif db_path.joinpath("db").is_dir():
4
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
175 input_dir = db_path.joinpath("db")
d74850cf4e42 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 404dc5eae30884c5814e463921eb3678bbd6878e
iuc
parents: 3
diff changeset
176 output_dir = db_path
5
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
177 for file in input_dir.iterdir():
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
178 if file.is_file(): # to avoid moving amrfinder-plus folder
6
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
179 output = output_dir.joinpath(file.name)
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
180 file.rename(output)
97b1b5ad1cda planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e0ce56ac52cff0e8f85e546440d28ca46853b11d
iuc
parents: 5
diff changeset
181 self.delete_folder(input_dir)
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
182
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
183 def calc_md5_sum(self, buffer_size=1048576):
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
184 tarball_path = Path(self.db_dir).joinpath(self.tar_name)
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
185 md5 = hashlib.md5()
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
186 with tarball_path.open("rb") as fh:
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
187 data = fh.read(buffer_size)
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
188 while data:
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
189 md5.update(data)
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
190 data = fh.read(buffer_size)
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
191 if md5.hexdigest() == self.md5:
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
192 print("\t...md5 control database OK")
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
193 else:
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
194 print(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
195 f"Error: corrupt database file! "
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
196 f"calculated md5 = {md5.hexdigest()}"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
197 f" different from {self.md5} "
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
198 )
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
199
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
200
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
201 def parse_arguments():
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
202 # parse options and arguments
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
203 arg_parser = argparse.ArgumentParser()
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
204 arg_parser.add_argument("data_manager_json")
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
205 arg_parser.add_argument(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
206 "-d",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
207 "--database_version",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
208 help="Select the database version "
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
209 "(major and minor eg. 4.0),"
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
210 "default is the latest version",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
211 default="latest",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
212 required=True,
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
213 )
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
214 arg_parser.add_argument(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
215 "-t",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
216 "--test",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
217 action="store_true",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
218 help="option to test the script with an empty database",
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
219 )
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
220 return arg_parser.parse_args()
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
221
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
222
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
223 def main():
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
224 all_args = parse_arguments()
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
225 with open(all_args.data_manager_json) as fh:
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
226 params = json.load(fh)
5
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
227 target_dir = Path(params["output_data"][0]["extra_files_path"])
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
228 target_dir.mkdir(parents=True, exist_ok=True)
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
229 # init the class to download bakta db
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
230 bakta_upload = InstallBaktaDatabase(
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
231 test_mode=all_args.test, db_version=all_args.database_version
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
232 )
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
233 bakta_db = bakta_upload.fetch_db_versions()
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
234 # update the path for galaxy
5
baceff842902 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
iuc
parents: 4
diff changeset
235 bakta_upload.db_dir = target_dir.absolute()
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
236 # download the database
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
237 bakta_upload.download()
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
238 # check md5 sum
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
239 bakta_upload.calc_md5_sum()
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
240 # untar db
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
241 bakta_upload.untar()
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
242 # make the data_manager metadata
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
243 bakta_data_manager = bakta_upload.get_data_manager(bakta_database_info=bakta_db)
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
244 with open(all_args.data_manager_json, "w") as fh:
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
245 json.dump(bakta_data_manager, fh, sort_keys=True)
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
246
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
247
3
3e73c97f025d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit 487cb35fe55883ac6eeb8dda58b56c9ca2ec0a85
iuc
parents: 1
diff changeset
248 if __name__ == "__main__":
0
a19189a128cb planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff changeset
249 main()