Mercurial > repos > sanbi-uwc > data_manager_novoalign_index_builder
annotate data_manager/novoalign_index_builder.py @ 1:4d67344bdea7 draft
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit 1f4717cce284465cddbb221a5ca4d1f601c14f84
author | sanbi-uwc |
---|---|
date | Thu, 03 Mar 2016 06:28:09 -0500 |
parents | 85fbd52dbb36 |
children | e51fb8188ed9 |
rev | line source |
---|---|
0
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
2 # Z. Mashologu (SANBI-UWC) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
3 #import dict as dict |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
4 import os |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
5 import shutil |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
6 import optparse |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
7 import urllib2 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
8 import logging |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
9 log = logging.getLogger( __name__ ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
10 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
11 from json import loads, dumps |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
12 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
13 def cleanup_before_exit( tmp_dir ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
14 if tmp_dir and os.path.exists( tmp_dir ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
15 shutil.rmtree( tmp_dir ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
16 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
17 def _stream_fasta_to_file( fasta_stream, target_directory, params, close_stream=True ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
18 fasta_base_filename = "%s.fa" % sequence_id |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
19 fasta_filename = os.path.join( target_directory, fasta_base_filename ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
20 fasta_writer = open( fasta_filename, 'wb+' ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
21 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
22 if isinstance( fasta_stream, list ) and len( fasta_stream ) == 1: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
23 fasta_stream = fasta_stream[0] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
24 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
25 if isinstance( fasta_stream, list ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
26 last_char = None |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
27 for fh in fasta_stream: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
28 if last_char not in [ None, '\n', '\r' ]: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
29 fasta_writer.write( '\n' ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
30 while True: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
31 data = fh.read( CHUNK_SIZE ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
32 if data: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
33 fasta_writer.write( data ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
34 last_char = data[-1] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
35 else: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
36 break |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
37 if close_stream: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
38 fh.close() |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
39 else: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
40 while True: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
41 data = fasta_stream.read( CHUNK_SIZE ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
42 if data: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
43 fasta_writer.write( data ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
44 else: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
45 break |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
46 if close_stream: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
47 fasta_stream.close() |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
48 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
49 fasta_writer.close() |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
50 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
51 return dict( path=fasta_base_filename ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
52 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
53 def download_from_url( data_manager_dict, params, target_directory, dbkey, sequence_id, sequence_name ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
54 #TODO: we should automatically do decompression here |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
55 urls = filter( bool, map( lambda x: x.strip(), params['param_dict']['reference_source']['user_url'].split( '\n' ) ) ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
56 fasta_reader = [ urllib2.urlopen( url ) for url in urls ] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
57 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
58 data_table_entry = _stream_fasta_to_file( fasta_reader, target_directory, params ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
59 _add_data_table_entry( data_manager_dict, data_table_entry ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
60 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
61 def download_from_history( data_manager_dict, params, target_directory): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
62 #TODO: allow multiple FASTA input files |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
63 input_filename = params['param_dict']['reference_source']['input_fasta'] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
64 if isinstance( input_filename, list ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
65 fasta_reader = [ open( filename, 'rb' ) for filename in input_filename ] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
66 else: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
67 fasta_reader = open( input_filename ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
68 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
69 data_table_entry = _stream_fasta_to_file( fasta_reader, target_directory, params ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
70 _add_data_table_entry( data_manager_dict, data_table_entry ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
71 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
72 def copy_from_directory( data_manager_dict, params, target_directory ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
73 input_filename = params['param_dict']['reference_source']['fasta_filename'] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
74 create_symlink = params['param_dict']['reference_source']['create_symlink'] == 'create_symlink' |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
75 if create_symlink: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
76 data_table_entry = _create_symlink( input_filename, target_directory ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
77 else: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
78 if isinstance( input_filename, list ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
79 fasta_reader = [ open( filename, 'rb' ) for filename in input_filename ] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
80 else: |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
81 fasta_reader = open( input_filename ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
82 data_table_entry = _stream_fasta_to_file( fasta_reader, target_directory, params ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
83 _add_data_table_entry( data_manager_dict, data_table_entry ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
84 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
85 def _create_symlink( input_filename, target_directory ): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
86 fasta_base_filename = "%s.fa" % sequence_id |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
87 fasta_filename = os.path.join( target_directory, fasta_base_filename ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
88 os.symlink( input_filename, fasta_filename ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
89 return dict( path=fasta_base_filename ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
90 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
91 REFERENCE_SOURCE_TO_DOWNLOAD = dict( url=download_from_url, history=download_from_history, directory=copy_from_directory ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
92 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
93 def main(): |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
94 #Parse Command Line |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
95 parser = optparse.OptionParser() |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
96 parser.add_option( '-d', '--data_table_name' ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
97 (options, args) = parser.parse_args() |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
98 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
99 filename = args[0] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
100 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
101 params = loads( open( filename ).read() ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
102 target_directory = params[ 'output_data' ][0]['extra_files_path'] |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
103 os.mkdir( target_directory ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
104 data_manager_dict = {} |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
105 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
106 #Fetch the FASTA |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
107 REFERENCE_SOURCE_TO_DOWNLOAD[ params['param_dict']['reference_source']['reference_source_selector'] ]( data_manager_dict, params, target_directory ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
108 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
109 #save info to json file |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
110 open( filename, 'wb' ).write( dumps( data_manager_dict ) ) |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
111 |
85fbd52dbb36
planemo upload for repository https://github.com/zipho/data_manager_novoalign_index_builder commit d51fdc6291de173e829a839e98c6c3ae367d84bf
sanbi-uwc
parents:
diff
changeset
|
112 if __name__ == "__main__": main() |