Mercurial > repos > iuc > data_manager_selection_background
annotate data_manager/data_manager_selection_background.py @ 3:10ac95ec81d9 draft
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
author | iuc |
---|---|
date | Wed, 25 Aug 2021 21:07:59 +0000 |
parents | e4f07770b340 |
children |
rev | line source |
---|---|
0
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
2 import argparse |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
3 import bz2 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
4 import gzip |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
5 import json |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
6 import os |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
7 import shutil |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
8 import sys |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
9 import uuid |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
10 import zipfile |
1
0bd1cd5eac51
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit 56142b399aae44a46fb6a588603eda2286cf73b2"
iuc
parents:
0
diff
changeset
|
11 from urllib.request import urlretrieve |
0
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
12 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
13 # Nice solution to opening compressed files (zip/bz2/gz) transparently |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
14 # https://stackoverflow.com/a/13045892/638445 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
15 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
16 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
17 class CompressedFile(object): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
18 magic = None |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
19 file_type = None |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
20 mime_type = None |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
21 proper_extension = None |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
22 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
23 def __init__(self, f): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
24 # f is an open file or file like object |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
25 self.f = f |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
26 self.accessor = self.open() |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
27 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
28 @classmethod |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
29 def is_magic(self, data): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
30 return data.startswith(self.magic) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
31 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
32 def open(self): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
33 return None |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
34 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
35 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
36 class ZIPFile(CompressedFile): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
37 magic = '\x50\x4b\x03\x04' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
38 file_type = 'zip' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
39 mime_type = 'compressed/zip' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
40 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
41 def open(self): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
42 return zipfile.ZipFile(self.f) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
43 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
44 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
45 class BZ2File(CompressedFile): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
46 magic = '\x42\x5a\x68' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
47 file_type = 'bz2' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
48 mime_type = 'compressed/bz2' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
49 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
50 def open(self): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
51 return bz2.BZ2File(self.f) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
52 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
53 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
54 class GZFile(CompressedFile): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
55 magic = '\x1f\x8b\x08' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
56 file_type = 'gz' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
57 mime_type = 'compressed/gz' |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
58 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
59 def open(self): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
60 return gzip.GzipFile(self.f) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
61 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
62 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
63 # factory function to create a suitable instance for accessing files |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
64 def get_compressed_file(filename): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
65 with open(filename, 'rb') as f: |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
66 start_of_file = f.read(1024) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
67 f.seek(0) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
68 for cls in (ZIPFile, BZ2File, GZFile): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
69 if cls.is_magic(start_of_file): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
70 f.close() |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
71 return cls(filename) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
72 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
73 return None |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
74 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
75 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
76 def url_download(url): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
77 """Attempt to download gene annotation file from a given url |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
78 :param url: full url to gene annotation file |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
79 :type url: str. |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
80 :returns: name of downloaded gene annotation file |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
81 :raises: ContentDecodingError, IOError |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
82 """ |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
83 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
84 # Generate file_name |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
85 file_name = url.split('/')[-1] |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
86 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
87 try: |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
88 # download URL (FTP and HTTP work, probably local and data too) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
89 urlretrieve(url, file_name) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
90 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
91 # uncompress file if needed |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
92 cf = get_compressed_file(file_name) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
93 if cf is not None: |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
94 uncompressed_file_name = os.path.splitext(file_name)[0] |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
95 with open(uncompressed_file_name, 'w+') as uncompressed_file: |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
96 shutil.copyfileobj(cf.accessor, uncompressed_file) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
97 os.remove(file_name) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
98 file_name = uncompressed_file_name |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
99 except IOError as e: |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
100 sys.stderr.write('Error occured downloading reference file: %s' % e) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
101 os.remove(file_name) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
102 return file_name |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
103 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
104 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
105 def main(): |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
106 parser = argparse.ArgumentParser(description='Create data manager JSON.') |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
107 parser.add_argument('--output', dest='output', action='store', required=True, help='JSON filename') |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
108 parser.add_argument('--dbkey', dest='dbkey', action='store', default=uuid.uuid4(), help='Data table entry unique ID') |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
109 parser.add_argument('--label', dest='label', action='store', required=True, help='Label to display') |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
110 parser.add_argument('--uri', dest='uri', action='store', help='URI for the sequences') |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
111 parser.add_argument('--dataset', dest='dataset', action='store', help='Path for the sequences') |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
112 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
113 args = parser.parse_args() |
3
10ac95ec81d9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
iuc
parents:
2
diff
changeset
|
114 dbkey = str(args.dbkey) |
0
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
115 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
116 if args.uri is not None: |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
117 background_fasta = url_download(args.uri) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
118 else: |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
119 background_fasta = args.dataset |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
120 |
3
10ac95ec81d9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
iuc
parents:
2
diff
changeset
|
121 with open(args.output) as fh: |
10ac95ec81d9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
iuc
parents:
2
diff
changeset
|
122 params = json.load(fh) |
10ac95ec81d9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
iuc
parents:
2
diff
changeset
|
123 target_directory = params['output_data'][0]['extra_files_path'] |
10ac95ec81d9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
iuc
parents:
2
diff
changeset
|
124 os.makedirs(target_directory, exist_ok=True) |
10ac95ec81d9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
iuc
parents:
2
diff
changeset
|
125 table_entry = '%s.fa' % dbkey |
10ac95ec81d9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
iuc
parents:
2
diff
changeset
|
126 shutil.copy(background_fasta, os.path.join(target_directory, table_entry)) |
0
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
127 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
128 # Update Data Manager JSON and write to file |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
129 data_manager_entry = { |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
130 'data_tables': { |
3
10ac95ec81d9
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit bbba39ae993250a1e7301965b03c12621513775e"
iuc
parents:
2
diff
changeset
|
131 'selection_background': {'value': dbkey, 'label': args.label, 'path': table_entry} |
0
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
132 } |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
133 } |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
134 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
135 with open(os.path.join(args.output), 'w+') as fh: |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
136 json.dump(data_manager_entry, fh, sort_keys=True) |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
137 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
138 |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
139 if __name__ == '__main__': |
bb5794942b5e
"planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_selection_background commit af3bfbbd3f1236bf96a25bcb8483f2889295ec0c"
iuc
parents:
diff
changeset
|
140 main() |