Mercurial > repos > devteam > data_manager_twobit_builder
comparison data_manager/twobit_builder.py @ 7:94a50db37d1a draft default tip
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_twobit_builder commit 096286097ed5cdf189a1b68c3fc34d10f4142e54
author | iuc |
---|---|
date | Sun, 16 Apr 2023 08:31:43 +0000 |
parents | 62359a151521 |
children |
comparison
equal
deleted
inserted
replaced
6:62359a151521 | 7:94a50db37d1a |
---|---|
24 if not sequence_name: | 24 if not sequence_name: |
25 sequence_name = dbkey | 25 sequence_name = dbkey |
26 return sequence_id, sequence_name | 26 return sequence_id, sequence_name |
27 | 27 |
28 | 28 |
29 def build_twobit(data_manager_dict, fasta_filename, params, target_directory, dbkey, sequence_id, sequence_name, long): | 29 def build_twobit(data_manager_dict, fasta_filename, params, target_directory, dbkey, sequence_id, sequence_name): |
30 twobit_base_name = "%s.2bit" % (sequence_id) | 30 twobit_base_name = "%s.2bit" % (sequence_id) |
31 twobit_filename = os.path.join(target_directory, twobit_base_name) | 31 twobit_filename = os.path.join(target_directory, twobit_base_name) |
32 | 32 |
33 args = ['faToTwoBit'] | 33 args = ['faToTwoBit', fasta_filename, twobit_filename] |
34 if long: | |
35 args.append('-long') | |
36 args.extend([fasta_filename, twobit_filename]) | |
37 tmp_stderr = tempfile.NamedTemporaryFile(prefix="tmp-data-manager-twobit-builder-stderr") | 34 tmp_stderr = tempfile.NamedTemporaryFile(prefix="tmp-data-manager-twobit-builder-stderr") |
38 proc = subprocess.Popen(args=args, shell=False, cwd=target_directory, stderr=tmp_stderr.fileno()) | 35 proc = subprocess.Popen(args=args, shell=False, cwd=target_directory, stderr=tmp_stderr.fileno()) |
39 return_code = proc.wait() | 36 return_code = proc.wait() |
40 if return_code: | 37 if return_code: |
41 tmp_stderr.flush() | 38 tmp_stderr.flush() |
43 print("Error building index:", file=sys.stderr) | 40 print("Error building index:", file=sys.stderr) |
44 while True: | 41 while True: |
45 chunk = tmp_stderr.read(CHUNK_SIZE) | 42 chunk = tmp_stderr.read(CHUNK_SIZE) |
46 if not chunk: | 43 if not chunk: |
47 break | 44 break |
48 sys.stderr.write(chunk.decode('utf-8')) | 45 sys.stderr.write(chunk) |
49 sys.exit(return_code) | 46 sys.exit(return_code) |
50 tmp_stderr.close() | 47 tmp_stderr.close() |
51 # lastz_seqs | 48 # lastz_seqs |
52 data_table_entry = dict(value=sequence_id, name=sequence_name, path=twobit_base_name) | 49 data_table_entry = dict(value=sequence_id, name=sequence_name, path=twobit_base_name) |
53 | 50 |
72 def main(): | 69 def main(): |
73 parser = optparse.OptionParser() | 70 parser = optparse.OptionParser() |
74 parser.add_option('-f', '--fasta_filename', dest='fasta_filename', action='store', type="string", default=None, help='fasta_filename') | 71 parser.add_option('-f', '--fasta_filename', dest='fasta_filename', action='store', type="string", default=None, help='fasta_filename') |
75 parser.add_option('-d', '--fasta_dbkey', dest='fasta_dbkey', action='store', type="string", default=None, help='fasta_dbkey') | 72 parser.add_option('-d', '--fasta_dbkey', dest='fasta_dbkey', action='store', type="string", default=None, help='fasta_dbkey') |
76 parser.add_option('-t', '--fasta_description', dest='fasta_description', action='store', type="string", default=None, help='fasta_description') | 73 parser.add_option('-t', '--fasta_description', dest='fasta_description', action='store', type="string", default=None, help='fasta_description') |
77 parser.add_option('-l', '--long', dest='long', action="store_true", default=False, help='For big genomes you need to pass the -long option.') | |
78 | |
79 (options, args) = parser.parse_args() | 74 (options, args) = parser.parse_args() |
80 | 75 |
81 filename = args[0] | 76 filename = args[0] |
82 | 77 |
83 with open(filename) as fh: | 78 with open(filename) as fh: |
93 raise Exception('"%s" is not a valid dbkey. You must specify a valid dbkey.' % (dbkey)) | 88 raise Exception('"%s" is not a valid dbkey. You must specify a valid dbkey.' % (dbkey)) |
94 | 89 |
95 sequence_id, sequence_name = get_id_name(params, dbkey=dbkey, fasta_description=options.fasta_description) | 90 sequence_id, sequence_name = get_id_name(params, dbkey=dbkey, fasta_description=options.fasta_description) |
96 | 91 |
97 # build the index | 92 # build the index |
98 build_twobit(data_manager_dict, options.fasta_filename, params, target_directory, dbkey, sequence_id, sequence_name, options.long) | 93 build_twobit(data_manager_dict, options.fasta_filename, params, target_directory, dbkey, sequence_id, sequence_name) |
99 | 94 |
100 # save info to json file | 95 # save info to json file |
101 with open(filename, 'w') as fh: | 96 with open(filename, 'w') as fh: |
102 json.dump(data_manager_dict, fh, sort_keys=True) | 97 json.dump(data_manager_dict, fh, sort_keys=True) |
103 | 98 |