Mercurial > repos > sanbi-uwc > data_manager_rnastar_index_builder
annotate data_manager/rnastar_index_builder.py @ 5:aed097239724 draft
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
author | sanbi-uwc |
---|---|
date | Wed, 10 Feb 2016 07:49:35 -0500 |
parents | 2883a3b7dc56 |
children | 56686a746b91 |
rev | line source |
---|---|
0
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
1 #!/usr/bin/env python |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
2 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
3 from __future__ import print_function |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
4 import argparse |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
5 from subprocess import check_call, CalledProcessError |
5
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
6 from json import load, dump, dumps |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
7 from os import environ, mkdir, makedirs |
0
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
8 from os.path import isdir, exists |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
9 import shlex |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
10 import sys |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
11 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
12 def get_id_name( params, dbkey, fasta_description=None): |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
13 #TODO: ensure sequence_id is unique and does not already appear in location file |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
14 sequence_id = params['param_dict']['sequence_id'] |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
15 if not sequence_id: |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
16 sequence_id = dbkey |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
17 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
18 sequence_name = params['param_dict']['sequence_name'] |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
19 if not sequence_name: |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
20 sequence_name = fasta_description |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
21 if not sequence_name: |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
22 sequence_name = dbkey |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
23 return sequence_id, sequence_name |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
24 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
25 def make_rnastar_index(output_directory, fasta_filename): |
5
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
26 #STAR |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
27 # --runMode genomeGenerate |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
28 # --genomeDir tempstargenomedir |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
29 # --genomeFastaFiles $input1 |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
30 # --runThreadsN \${GALAXY_SLOTS:-1} |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
31 # --genomeChrBinNbits $advanced_options.chr_bin_nbits |
0
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
32 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
33 if exists(output_directory) and not isdir(output_directory): |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
34 print("Output directory path already exists but is not a directory: {}".format(output_directory), file=sys.stderr) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
35 elif not exists(output_directory): |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
36 mkdir(output_directory) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
37 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
38 if 'GALAXY_SLOTS' in environ: |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
39 nslots = environ['GALAXY_SLOTS'] |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
40 else: |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
41 nslots = 1 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
42 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
43 # cmdline_str = 'STAR --runMode genomeGenerate --genomeDir {} --genomeFastaFiles {} --runThreadsN {}'.format(output_directory, |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
44 # fasta_filename, |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
45 # nslots) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
46 # cmdline = shlex.split(cmdline_str) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
47 cmdline = ('touch', '{}/foo'.format(output_directory)) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
48 try: |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
49 check_call(cmdline) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
50 except CalledProcessError: |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
51 print("Error building RNA STAR index", file=sys.stderr) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
52 return(output_directory) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
53 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
54 parser = argparse.ArgumentParser(description="Generate RNA STAR genome index and JSON describing this") |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
55 parser.add_argument('output_filename') |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
56 parser.add_argument('--fasta_filename') |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
57 parser.add_argument('--fasta_dbkey') |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
58 parser.add_argument('--fasta_description', default=None) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
59 parser.add_argument('--data_table_name', default='rnastar_indexes') |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
60 args = parser.parse_args() |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
61 |
5
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
62 filename = args.output_filename |
0
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
63 |
5
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
64 params = load(open(filename, 'rb')) |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
65 output_directory = params[ 'output_data' ][0]['extra_files_path'] |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
66 makedirs( output_directory ) |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
67 data_manager_dict = {} |
0
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
68 |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
69 make_rnastar_index(output_directory, args.fasta_filename) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
70 (sequence_id, sequence_name) = get_id_name(params, args.fasta_dbkey, args.fasta_description) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
71 data_table_entry = dict(value=sequence_id, dbkey=args.fasta_dbkey, name=sequence_name, path=output_directory) |
2883a3b7dc56
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff
changeset
|
72 |
5
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
73 #dt_tables = {args.data_table_name : [data_table_entry]} |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
74 output_datatable_dict = dict(data_tables={args.data_table_name : [data_table_entry]}) |
aed097239724
planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 9d7fb6d7c47e94fb113e0fe26427086935122ff0
sanbi-uwc
parents:
0
diff
changeset
|
75 open( filename, 'wb' ).write( dumps( output_datatable_dict ) ) |