Mercurial > repos > iuc > data_manager_bakta
annotate data_manager/bakta_build_database.py @ 5:baceff842902 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_build_bakta_database commit e277883fca66013904bae930f04e7f3be5fcb1a2
author | iuc |
---|---|
date | Wed, 05 Jun 2024 14:20:59 +0000 |
parents | d74850cf4e42 |
children | 97b1b5ad1cda |
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: |
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
|
138 total_length = resp.headers.get("content-length") |
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
|
139 if total_length is None: # no content length header |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
140 for data in resp.iter_content(chunk_size=1024 * 1024): |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
141 fh_out.write(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
|
142 else: |
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 for data in resp.iter_content(chunk_size=1024 * 1024): |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 ) |
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
|
152 |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 ) 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
|
159 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
|
160 print(f"Untar the database in {db_path}") |
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
|
161 |
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
|
162 if not self.test_mode: |
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
|
163 self.move_files(db_path=db_path) |
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
|
164 |
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
|
165 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
|
166 sys.exit(f"ERROR: Could not extract {self.tar_name} " f"to {db_path}") |
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
|
167 |
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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 if file.is_file(): # to avoid moving amrfinder-plus folder |
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
|
176 input = input_dir.joinpath(file) |
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 output = output_dir.joinpath(file) |
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 input.rename(output) |
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
|
179 |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
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 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 ) |
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
|
196 |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
197 |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
198 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
|
199 # 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
|
200 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
|
201 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
|
202 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
|
203 "-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
|
204 "--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
|
205 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
|
206 "(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
|
207 "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
|
208 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
|
209 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
|
210 ) |
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 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
|
212 "-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
|
213 "--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
|
214 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
|
215 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
|
216 ) |
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
|
217 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
|
218 |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
219 |
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 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 # 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
|
227 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
|
228 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
|
229 ) |
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_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
|
231 # 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
|
232 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
|
233 # 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
|
234 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
|
235 # 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
|
236 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
|
237 # 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
|
238 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
|
239 # 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
|
240 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
|
241 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
|
242 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
|
243 |
a19189a128cb
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_bakta commit fba6deae1d3707e0c14202433d0495e157745afd
iuc
parents:
diff
changeset
|
244 |
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
|
245 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
|
246 main() |