Mercurial > repos > sanbi-uwc > data_manager_novocraft_index_builder
annotate data_manager/novocraft_index_builder.py @ 7:d04a59b76845 draft
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 03f281362d5cf7c4d2a813203b83f5d12eb8ca46
author | sanbi-uwc |
---|---|
date | Sat, 05 Mar 2016 09:19:21 -0500 |
parents | 8dd4b25716d1 |
children | 56e8324519c4 |
rev | line source |
---|---|
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
2 # Z. Mashologu (SANBI-UWC) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
3 # import dict as dict |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
4 from __future__ import print_function |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
5 import os |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
6 import sys |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
7 import urllib2 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
8 import logging |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
9 import argparse |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
10 import shlex |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
11 from subprocess import check_call, CalledProcessError |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
12 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
13 log = logging.getLogger(__name__) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
14 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
15 from json import loads, dumps |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
16 |
6
8dd4b25716d1
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 05004076adb510abc08f6c1e28ba22b2c1a29534
sanbi-uwc
parents:
5
diff
changeset
|
17 DEFAULT_DATA_TABLE_NAME = "novocraft_index" |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
18 |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
19 def get_dbkey_id_name(params, dbkey_description=None): |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
20 dbkey = params['param_dict']['dbkey'] |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
21 # TODO: ensure sequence_id is unique and does not already appear in location file |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
22 sequence_id = params['param_dict']['sequence_id'] |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
23 if not sequence_id: |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
24 sequence_id = dbkey # uuid.uuid4() generate and use an uuid instead? |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
25 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
26 sequence_name = params['param_dict']['sequence_name'] |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
27 if not sequence_name: |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
28 sequence_name = dbkey_description |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
29 if not sequence_name: |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
30 sequence_name = dbkey |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
31 return dbkey, sequence_id, sequence_name |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
32 |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
33 def _make_novocraft_index(data_manager_dict, fasta_filename, target_directory, dbkey, sequence_id, sequence_name, data_table_name=DEFAULT_DATA_TABLE_NAME): |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
34 if os.path.exists(target_directory) and not os.path.isdir(target_directory): |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
35 print("Output directory path already exists but is not a directory: {}".format(target_directory), |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
36 file=sys.stderr) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
37 elif not os.path.exists(target_directory): |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
38 os.mkdir(target_directory) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
39 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
40 if 'GALAXY_SLOTS' in os.environ: |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
41 nslots = os.environ['GALAXY_SLOTS'] |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
42 else: |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
43 nslots = 1 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
44 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
45 #cmdline_str = 'STAR --runMode genomeGenerate --genomeDir {} --genomeFastaFiles {} --runThreadN {}'.format( |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
46 # target_directory, |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
47 # fasta_filename, |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
48 # nslots) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
49 #cmdline = shlex.split(cmdline_str) |
7
d04a59b76845
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 03f281362d5cf7c4d2a813203b83f5d12eb8ca46
sanbi-uwc
parents:
6
diff
changeset
|
50 index_filename = 'foo.nix' |
d04a59b76845
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 03f281362d5cf7c4d2a813203b83f5d12eb8ca46
sanbi-uwc
parents:
6
diff
changeset
|
51 cmdline = ('touch', '{}/{}'.format(target_directory, index_filename)) |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
52 try: |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
53 check_call(cmdline) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
54 except CalledProcessError: |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
55 print("Error building RNA STAR index", file=sys.stderr) |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
56 |
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
57 data_table_entry = dict( value=sequence_id, dbkey=dbkey, name=sequence_name, path=target_directory ) |
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
58 _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ) |
7
d04a59b76845
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 03f281362d5cf7c4d2a813203b83f5d12eb8ca46
sanbi-uwc
parents:
6
diff
changeset
|
59 return ( index_filename ) |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
60 |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
61 def _add_data_table_entry( data_manager_dict, data_table_name, data_table_entry ): |
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
62 data_manager_dict['data_tables'] = data_manager_dict.get( 'data_tables', {} ) |
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
63 data_manager_dict['data_tables'][ data_table_name ] = data_manager_dict['data_tables'].get( data_table_name, [] ) |
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
64 data_manager_dict['data_tables'][ data_table_name ].append( data_table_entry ) |
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
65 return data_manager_dict |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
66 |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
67 def download_from_url( data_manager_dict, params, target_directory, dbkey, sequence_id, sequence_name, data_table_name=DEFAULT_DATA_TABLE_NAME ): |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
68 # TODO: we should automatically do decompression here |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
69 urls = filter(bool, map(lambda x: x.strip(), params['param_dict']['reference_source']['user_url'].split('\n'))) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
70 fasta_reader = [urllib2.urlopen(url) for url in urls] |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
71 |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
72 _make_novocraft_index(data_manager_dict, fasta_reader, target_directory, dbkey, sequence_id, sequence_name, data_table_name) |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
73 |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
74 def download_from_history( data_manager_dict, params, target_directory, dbkey, sequence_id, sequence_name, data_table_name=DEFAULT_DATA_TABLE_NAME ): |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
75 # TODO: allow multiple FASTA input files |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
76 input_filename = params['param_dict']['reference_source']['input_fasta'] |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
77 |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
78 _make_novocraft_index(data_manager_dict, input_filename, target_directory, dbkey, sequence_id, sequence_name, data_table_name) |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
79 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
80 REFERENCE_SOURCE_TO_DOWNLOAD = dict(url=download_from_url, history=download_from_history) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
81 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
82 def main(): |
7
d04a59b76845
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 03f281362d5cf7c4d2a813203b83f5d12eb8ca46
sanbi-uwc
parents:
6
diff
changeset
|
83 parser = argparse.ArgumentParser(description="Generate Novo-craft genome index and JSON describing this") |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
84 parser.add_argument('output_filename') |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
85 parser.add_argument('--dbkey_description') |
6
8dd4b25716d1
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 05004076adb510abc08f6c1e28ba22b2c1a29534
sanbi-uwc
parents:
5
diff
changeset
|
86 parser.add_argument('--data_table_name', default='novocraft_index') |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
87 args = parser.parse_args() |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
88 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
89 filename = args.output_filename |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
90 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
91 params = loads(open(filename).read()) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
92 target_directory = params['output_data'][0]['extra_files_path'] |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
93 os.makedirs(target_directory) |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
94 data_manager_dict = {} |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
95 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
96 dbkey, sequence_id, sequence_name = get_dbkey_id_name(params, dbkey_description=args.dbkey_description) |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
97 |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
98 if dbkey in [None, '', '?']: |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
99 raise Exception('"%s" is not a valid dbkey. You must specify a valid dbkey.' % (dbkey)) |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
100 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
101 # Fetch the FASTA |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
102 REFERENCE_SOURCE_TO_DOWNLOAD[params['param_dict']['reference_source']['reference_source_selector']]\ |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
103 (data_manager_dict, params, target_directory, dbkey, sequence_id, sequence_name, data_table_name=args.data_table_name or DEFAULT_DATA_TABLE_NAME) |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
104 |
4
c276a826fc4b
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 1e4e16c747ca6ef261d3307f47a09ff1d49756a1
sanbi-uwc
parents:
0
diff
changeset
|
105 open(filename, 'wb').write(dumps( data_manager_dict )) |
0
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
106 |
6cddc1a6e282
planemo upload for repository https://github.com/zipho/data_manager_novocraft_index_builder commit 3a0b36e3ee66f35f7e2d5e1220cd883a9d528fac
sanbi-uwc
parents:
diff
changeset
|
107 if __name__ == "__main__": main() |