annotate data_manager/rnastar_index_builder.py @ 0:2883a3b7dc56 draft

planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
author sanbi-uwc
date Mon, 08 Feb 2016 03:23:34 -0500
parents
children aed097239724
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
6 from json import load, dump
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
7 from os import environ, mkdir
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):
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
26 # STAR
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
27 # --runMode genomeGenerate
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
28 # --genomeDir tempstargenomedir
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
29 # --genomeFastaFiles $input1
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
30 # --runThreadsN \${GALAXY_SLOTS:-1}
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
31 # --genomeChrBinNbits $advanced_options.chr_bin_nbits
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
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
62 params = load(open(args.output_filename, 'rb'))
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
63
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
64 output_directory = params['output_data'][0]['extra_files_path']
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
65
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
66 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
67 (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
68 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
69 output_datatable_dict = dict('data_tables', dict(args.data_table_name, [data_table_entry]))
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
70
2883a3b7dc56 planemo upload for repository https://github.com/pvanheus/data_manager_rnastar_index_builder commit 265fa1966ea606ebccea8c2865043c014959c10c-dirty
sanbi-uwc
parents:
diff changeset
71 dump(output_datatable_dict(open(args.output_file, 'wb')))