annotate data_manager/data_manager.py @ 6:6dd9e00dea95 draft

"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
author iuc
date Fri, 19 Mar 2021 21:43:42 +0000
parents 9de2fb1ce1fb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
1 import argparse
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
2 import datetime
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
3 import json
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
4 import os
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
5 import shutil
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
6 import tarfile
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
7 import zipfile
5
9de2fb1ce1fb "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
iuc
parents: 4
diff changeset
8 from urllib.request import Request, urlopen
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
9
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
10
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
11 def url_download(url, workdir):
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
12 file_path = os.path.join(workdir, 'download.dat')
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
13 if not os.path.exists(workdir):
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
14 os.makedirs(workdir)
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
15 src = None
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
16 dst = None
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
17 try:
1
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
18 req = Request(url)
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
19 src = urlopen(req)
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
20 with open(file_path, 'wb') as dst:
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
21 while True:
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
22 chunk = src.read(2**10)
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
23 if chunk:
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
24 dst.write(chunk)
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
25 else:
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
26 break
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
27 finally:
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
28 if src:
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
29 src.close()
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
30 if tarfile.is_tarfile(file_path):
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
31 fh = tarfile.open(file_path, 'r:*')
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
32 elif zipfile.is_zipfile(file_path):
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
33 fh = zipfile.ZipFile(file_path, 'r')
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
34 else:
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
35 return
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
36 fh.extractall(workdir)
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
37 os.remove(file_path)
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
38
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
39
6
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
40 def download_name_maps(url, workdir, partial):
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
41
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
42 if partial:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
43 map_files = [
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
44 'pdb.accession2taxid.gz',
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
45 ]
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
46 else:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
47 map_files = [
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
48 'dead_nucl.accession2taxid.gz',
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
49 'dead_prot.accession2taxid.gz',
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
50 'dead_wgs.accession2taxid.gz',
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
51 'nucl_gb.accession2taxid.gz',
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
52 'nucl_wgs.accession2taxid.gz',
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
53 'pdb.accession2taxid.gz',
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
54 'prot.accession2taxid.gz',
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
55 'prot.accession2taxid.FULL.gz'
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
56 ]
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
57
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
58 if not os.path.exists(workdir):
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
59 os.makedirs(workdir)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
60
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
61 for map in map_files:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
62 src = "{}{}".format(url, map)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
63 dest = os.path.join(workdir, map)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
64
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
65 print("Downloading taxonomy accession2taxid file from {} to {}".format(src, dest))
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
66
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
67 try:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
68 req = Request(src)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
69 src = urlopen(req)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
70 with open(dest, 'wb') as dst:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
71 while True:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
72 chunk = src.read(2**10)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
73 if chunk:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
74 dst.write(chunk)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
75 else:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
76 break
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
77 finally:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
78 if src:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
79 src.close()
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
80
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
81
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
82 def move_files_to_final_dir(workdir, target_directory, copy=False):
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
83 for filename in os.listdir(workdir):
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
84 if copy:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
85 shutil.copy(os.path.join(workdir, filename), target_directory)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
86 else:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
87 shutil.move(os.path.join(workdir, filename), target_directory)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
88
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
89
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
90 def main(args):
6
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
91 workdir = os.path.abspath(os.path.join(os.getcwd(), 'taxonomy'))
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
92 url_download(args.url, workdir)
6
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
93
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
94 data_manager_entry = {}
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
95 data_manager_entry['value'] = args.name.lower()
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
96 data_manager_entry['name'] = args.name
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
97 data_manager_entry['path'] = '.'
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
98 data_manager_json = dict(data_tables=dict(ncbi_taxonomy=data_manager_entry))
6
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
99
5
9de2fb1ce1fb "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
iuc
parents: 4
diff changeset
100 with open(args.output) as fh:
9de2fb1ce1fb "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
iuc
parents: 4
diff changeset
101 params = json.load(fh)
6
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
102
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
103 if args.name_maps:
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
104 workdir_a2t = os.path.join(os.getcwd(), 'accession2taxid')
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
105 download_name_maps("ftp://ftp.ncbi.nlm.nih.gov/pub/taxonomy/accession2taxid/", workdir_a2t, args.partial)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
106
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
107 target_directory_a2t = os.path.join(params['output_data'][0]['extra_files_path'], "accession2taxid")
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
108 os.makedirs(target_directory_a2t)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
109 move_files_to_final_dir(workdir_a2t, target_directory_a2t)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
110
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
111 # Also copy taxonomy data to accession2taxid dir
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
112 move_files_to_final_dir(workdir, target_directory_a2t, copy=True)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
113
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
114 data_manager_json['data_tables']['ncbi_accession2taxid'] = data_manager_entry
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
115
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
116 target_directory_tax = os.path.join(params['output_data'][0]['extra_files_path'], "taxonomy")
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
117 os.makedirs(target_directory_tax)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
118
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
119 move_files_to_final_dir(workdir, target_directory_tax)
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
120
5
9de2fb1ce1fb "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
iuc
parents: 4
diff changeset
121 with open(args.output, 'w') as fh:
9de2fb1ce1fb "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 02d2967f77e3fa5a18aea63dc84aa9ab418dc165"
iuc
parents: 4
diff changeset
122 json.dump(data_manager_json, fh, sort_keys=True)
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
123
1
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
124
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
125 if __name__ == '__main__':
1
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
126 parser = argparse.ArgumentParser(description='Create data manager json.')
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
127 parser.add_argument('--out', dest='output', action='store', help='JSON filename')
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
128 parser.add_argument('--name', dest='name', action='store', default=str(datetime.date.today()), help='Data table entry unique ID')
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
129 parser.add_argument('--url', dest='url', action='store', default='ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz', help='Download URL')
6
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
130 parser.add_argument('--name-maps', dest='name_maps', action='store_true', help='')
6dd9e00dea95 "planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 3d78021971b83d585c432830cee0488ada7bd257"
iuc
parents: 5
diff changeset
131 parser.add_argument('--partial', dest='partial', action='store_true', help='Only download a small subset of data (for testing)')
1
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
132 args = parser.parse_args()
926847693e4d planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 8652f36a3a3838dca989426961561e81432acf4f
iuc
parents: 0
diff changeset
133
0
fafcd2f5db36 planemo upload for repository https://github.com/galaxyproject/tools-devteam/blob/master/data_managers/data_manager_fetch_ncbi_taxonomy/ commit 220e70acb66016873732b193b3ac20ae48083f0b-dirty
devteam
parents:
diff changeset
134 main(args)