Mercurial > repos > gga > apollo_feat_from_gff3
comparison create_or_update_organism.py @ 11:1e37bbd4a73b draft
"planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 81492a9c8b9e5649a3867bc30afe617a30fb47a1"
author | gga |
---|---|
date | Tue, 14 Apr 2020 10:44:32 -0400 |
parents | 5d1cf95ade8a |
children | 250745643de2 |
comparison
equal
deleted
inserted
replaced
10:5d1cf95ade8a | 11:1e37bbd4a73b |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 from __future__ import print_function | 2 from __future__ import print_function |
3 | 3 |
4 import argparse | 4 import argparse |
5 import glob | |
6 import json | 5 import json |
7 import logging | 6 import logging |
8 import os | 7 import os |
8 import re | |
9 import shutil | 9 import shutil |
10 import stat | 10 import stat |
11 import subprocess | 11 import subprocess |
12 import sys | 12 import sys |
13 import tarfile | 13 import tarfile |
14 import tempfile | 14 import tempfile |
15 import time | 15 import time |
16 from pathlib import Path | |
16 | 17 |
17 from apollo import accessible_organisms | 18 from apollo import accessible_organisms |
18 from apollo.util import GuessOrg, OrgOrGuess | 19 from apollo.util import GuessOrg, OrgOrGuess |
19 | 20 |
20 from arrow.apollo import get_apollo_instance | 21 from arrow.apollo import get_apollo_instance |
45 return False | 46 return False |
46 | 47 |
47 | 48 |
48 def IsRemote(): | 49 def IsRemote(): |
49 return 'GALAXY_SHARED_DIR' not in os.environ or len(os.environ['GALAXY_SHARED_DIR'].lower().strip()) == 0 | 50 return 'GALAXY_SHARED_DIR' not in os.environ or len(os.environ['GALAXY_SHARED_DIR'].lower().strip()) == 0 |
51 | |
52 | |
53 def zip_data_dir(dataset_data_dir, tar): | |
54 tar.add(dataset_data_dir, arcname='./', recursive=False) | |
55 for r, d, f in os.walk(dataset_data_dir): | |
56 for file_name in f: | |
57 abs_file = os.path.join(r, file_name) | |
58 rel_dir = os.path.relpath(r, dataset_data_dir) | |
59 rel_file = os.path.join(rel_dir, file_name) | |
60 if not rel_file.startswith('./'): | |
61 rel_file = './' + rel_file | |
62 if os.path.islink(abs_file): | |
63 target = Path(abs_file).resolve().absolute().as_posix() | |
64 if re.match(r'.*/_metadata_files/[0-9]+/metadata_[0-9]+.dat', target): | |
65 # This is a metadata file generated by galaxy, symlink would certainly be dead on remote host, resolve it | |
66 abs_file = target | |
67 tar.add(abs_file, arcname=rel_file) | |
50 | 68 |
51 | 69 |
52 if __name__ == '__main__': | 70 if __name__ == '__main__': |
53 parser = argparse.ArgumentParser(description='Create or update an organism in an Apollo instance') | 71 parser = argparse.ArgumentParser(description='Create or update an organism in an Apollo instance') |
54 parser.add_argument('jbrowse_src', help='Source JBrowse Data Directory') | 72 parser.add_argument('jbrowse_src', help='Source JBrowse Data Directory') |
134 log.info("\tUpdating Organism") | 152 log.info("\tUpdating Organism") |
135 if IsRemote(): | 153 if IsRemote(): |
136 with tempfile.NamedTemporaryFile(suffix='.tar.gz') as archive: | 154 with tempfile.NamedTemporaryFile(suffix='.tar.gz') as archive: |
137 with tarfile.open(archive.name, mode="w:gz") as tar: | 155 with tarfile.open(archive.name, mode="w:gz") as tar: |
138 dataset_data_dir = args.jbrowse_src | 156 dataset_data_dir = args.jbrowse_src |
139 for file in glob.glob(dataset_data_dir): | 157 zip_data_dir(dataset_data_dir, tar) |
140 tar.add(file, arcname=file.replace(dataset_data_dir, './')) | |
141 if IsBlatEnabled(): | 158 if IsBlatEnabled(): |
142 tar.add(path_2bit, arcname="./searchDatabaseData/genome.2bit") | 159 tar.add(path_2bit, arcname="./searchDatabaseData/genome.2bit") |
143 data = wa.remote.update_organism( | 160 data = wa.remote.update_organism( |
144 org['id'], | 161 org['id'], |
145 archive, | 162 archive, |
175 | 192 |
176 if IsRemote(): | 193 if IsRemote(): |
177 with tempfile.NamedTemporaryFile(suffix='.tar.gz') as archive: | 194 with tempfile.NamedTemporaryFile(suffix='.tar.gz') as archive: |
178 with tarfile.open(archive.name, mode="w:gz") as tar: | 195 with tarfile.open(archive.name, mode="w:gz") as tar: |
179 dataset_data_dir = args.jbrowse_src | 196 dataset_data_dir = args.jbrowse_src |
180 for file in glob.glob(dataset_data_dir): | 197 zip_data_dir(dataset_data_dir, tar) |
181 tar.add(file, arcname=file.replace(dataset_data_dir, './')) | |
182 if IsBlatEnabled(): | 198 if IsBlatEnabled(): |
183 with tempfile.TemporaryDirectory() as empty_dir: | 199 with tempfile.TemporaryDirectory() as empty_dir: |
184 os.chmod(empty_dir, stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) | 200 os.chmod(empty_dir, stat.S_IRUSR | stat.S_IXUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) |
185 tar.add(empty_dir, arcname="./searchDatabaseData/") | 201 tar.add(empty_dir, arcname="./searchDatabaseData/") |
186 tar.add(path_2bit, arcname="./searchDatabaseData/genome.2bit") | 202 tar.add(path_2bit, arcname="./searchDatabaseData/genome.2bit") |