Mercurial > repos > cmonjeau > stacks
comparison STACKS_procrad.py @ 0:d6ba40f6c824
first commit
| author | cmonjeau |
|---|---|
| date | Mon, 24 Aug 2015 09:29:12 +0000 |
| parents | |
| children | c9e10e0d6c10 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:d6ba40f6c824 |
|---|---|
| 1 #!/usr/bin/python | |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 4 import sys | |
| 5 import os | |
| 6 import re | |
| 7 import tempfile | |
| 8 import subprocess | |
| 9 import glob | |
| 10 import shutil | |
| 11 import argparse | |
| 12 from os.path import basename | |
| 13 import zipfile | |
| 14 import tarfile | |
| 15 import gzip | |
| 16 from stacks import * | |
| 17 | |
| 18 | |
| 19 def __main__(): | |
| 20 | |
| 21 # arguments recuperation | |
| 22 | |
| 23 parser = argparse.ArgumentParser() | |
| 24 parser.add_argument('--input_type') | |
| 25 parser.add_argument('--input_enzyme') | |
| 26 parser.add_argument('--input_single') | |
| 27 parser.add_argument('--input_paired1') | |
| 28 parser.add_argument('--input_paired2') | |
| 29 parser.add_argument('--inputype') | |
| 30 parser.add_argument('--sample_name') | |
| 31 parser.add_argument('--barcode') | |
| 32 parser.add_argument('--output_choice') | |
| 33 parser.add_argument('--output_archive') | |
| 34 parser.add_argument('--enzyme1') | |
| 35 parser.add_argument('--enzyme2') | |
| 36 parser.add_argument('--outype') | |
| 37 parser.add_argument('--qualitenc') | |
| 38 parser.add_argument('-D', action='store_true') | |
| 39 parser.add_argument('-t') | |
| 40 parser.add_argument('-q', action='store_true') | |
| 41 parser.add_argument('--activate_advanced_options') | |
| 42 parser.add_argument('-r', action='store_true') | |
| 43 parser.add_argument('-w', default='0.15') | |
| 44 parser.add_argument('-s', default='10') | |
| 45 parser.add_argument('-c', action='store_true') | |
| 46 parser.add_argument('--inline_null', action='store_true') | |
| 47 parser.add_argument('--index_null', action='store_true') | |
| 48 parser.add_argument('--inline_inline', action='store_true') | |
| 49 parser.add_argument('--index_index', action='store_true') | |
| 50 parser.add_argument('--inline_index', action='store_true') | |
| 51 parser.add_argument('--index_inline', action='store_true') | |
| 52 parser.add_argument('--logfile') | |
| 53 options = parser.parse_args() | |
| 54 | |
| 55 # create the working dir | |
| 56 os.mkdir('inputs') | |
| 57 os.mkdir('job_outputs') | |
| 58 os.mkdir('galaxy_outputs') | |
| 59 | |
| 60 cmd_line = [] | |
| 61 cmd_line.append('process_radtags') | |
| 62 cmd_line.extend(['-p', 'inputs']) | |
| 63 cmd_line.extend(['-i', options.inputype]) | |
| 64 cmd_line.extend(['-b', options.barcode]) | |
| 65 | |
| 66 # parse config files and create symlink into the temp dir | |
| 67 | |
| 68 if options.input_type == 'single': | |
| 69 | |
| 70 # load the config file | |
| 71 input_single = options.input_single | |
| 72 | |
| 73 # parse the input_file to extract filenames and filepaths | |
| 74 tab_files = galaxy_config_to_tabfiles(input_single) | |
| 75 | |
| 76 # create symlink into the temp dir | |
| 77 create_symlinks_from_tabfiles(tab_files, 'inputs') | |
| 78 else: | |
| 79 | |
| 80 # load config files | |
| 81 input_paired1 = options.input_paired1 | |
| 82 input_paired2 = options.input_paired2 | |
| 83 | |
| 84 # parse the input_file to extract filenames and filepaths | |
| 85 | |
| 86 tab_files_paired1 = galaxy_config_to_tabfiles(input_paired1) | |
| 87 tab_files_paired2 = galaxy_config_to_tabfiles(input_paired2) | |
| 88 | |
| 89 # create symlinks into the temp dir | |
| 90 | |
| 91 create_symlinks_from_tabfiles(tab_files_paired1, 'inputs') | |
| 92 create_symlinks_from_tabfiles(tab_files_paired2, 'inputs') | |
| 93 | |
| 94 cmd_line.append('-P') | |
| 95 | |
| 96 # test nb enzyme | |
| 97 if options.input_enzyme == '1': | |
| 98 cmd_line.extend(['-e', options.enzyme1]) | |
| 99 | |
| 100 if options.input_enzyme == '2': | |
| 101 cmd_line.extend(['---renz_1', options.enzyme1, '--renz_2', options.enzyme2]) | |
| 102 | |
| 103 # quality | |
| 104 cmd_line.extend(['-E', options.qualitenc]) | |
| 105 | |
| 106 # outputs | |
| 107 cmd_line.extend(['-o', 'job_outputs/']) | |
| 108 cmd_line.extend(['-y', options.outype]) | |
| 109 | |
| 110 # test capture discards | |
| 111 if options.D: | |
| 112 cmd_line.append('-D') | |
| 113 | |
| 114 # optional options | |
| 115 if options.activate_advanced_options == "true": | |
| 116 | |
| 117 if options.q: | |
| 118 cmd_line.append('-q') | |
| 119 if options.r: | |
| 120 cmd_line.append('-r') | |
| 121 | |
| 122 cmd_line.extend(['-w', options.w, '-s', options.s]) | |
| 123 | |
| 124 if options.c: | |
| 125 cmd_line.append('-c') | |
| 126 if options.t != '-1': | |
| 127 cmd_line.extend(['-t', options.t]) | |
| 128 if options.inline_null: | |
| 129 cmd_line.append('--inline_null') | |
| 130 if options.index_null: | |
| 131 cmd_line.append('--index_null') | |
| 132 if options.inline_inline: | |
| 133 cmd_line.append('--inline_inline') | |
| 134 if options.index_index: | |
| 135 cmd_line.append('--index_index') | |
| 136 if options.inline_index: | |
| 137 cmd_line.append('--inline_index') | |
| 138 if options.index_inline: | |
| 139 cmd_line.append('--index_inline') | |
| 140 | |
| 141 print '[CMD_LINE] : ' + ' '.join(cmd_line) | |
| 142 | |
| 143 p = subprocess.call(cmd_line) | |
| 144 | |
| 145 # postprocesses | |
| 146 | |
| 147 try: | |
| 148 shutil.move('job_outputs/process_radtags.log', options.logfile) | |
| 149 except: | |
| 150 sys.stderr.write('Error in process_radtags execution; Please read the additional output (stdout)\n') | |
| 151 sys.exit(1) | |
| 152 | |
| 153 if options.discard_file: | |
| 154 discards_file_name = glob.glob('job_outputs/*.discards')[0] | |
| 155 shutil.move(discards_file_name, options.discard_file) | |
| 156 | |
| 157 # manage outputs names | |
| 158 | |
| 159 change_outputs_procrad_name(os.getcwd() + '/job_outputs', options.sample_name) | |
| 160 | |
| 161 # generate additional output archive file | |
| 162 | |
| 163 if options.output_choice != '1': | |
| 164 generate_additional_archive_file(os.getcwd() + '/job_outputs', options.output_archive) | |
| 165 | |
| 166 # if user has not choose the only zip archive | |
| 167 | |
| 168 if options.output_choice != '3': | |
| 169 list_files = glob.glob('job_outputs/*') | |
| 170 for i in list_files: | |
| 171 shutil.move(i, 'galaxy_outputs') | |
| 172 | |
| 173 | |
| 174 if __name__ == '__main__': | |
| 175 __main__() | |
| 176 | |
| 177 |
