Mercurial > repos > weilong-guo > bs_seeker2
comparison BSseeker2/bs_utils/utils.py @ 1:8b26adf64adc draft default tip
V2.0.5
| author | weilong-guo | 
|---|---|
| date | Tue, 05 Nov 2013 01:55:39 -0500 | 
| parents | e6df770c0e58 | 
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 0:e6df770c0e58 | 1:8b26adf64adc | 
|---|---|
| 21 | 21 | 
| 22 | 22 | 
| 23 | 23 | 
| 24 def show_version() : | 24 def show_version() : | 
| 25 print "" | 25 print "" | 
| 26 print " BS-Seeker2 v2.0.3 - May 19, 2013 " | 26 print " BS-Seeker2 v2.0.5 - Nov 5, 2013 " | 
| 27 print "" | 27 print "" | 
| 28 | 28 | 
| 29 | 29 | 
| 30 | 30 | 
| 31 """ | 31 """ | 
| 133 aligner_options_prefixes = { BOWTIE : '--bt-', | 133 aligner_options_prefixes = { BOWTIE : '--bt-', | 
| 134 BOWTIE2 : '--bt2-', | 134 BOWTIE2 : '--bt2-', | 
| 135 SOAP : '--soap-', | 135 SOAP : '--soap-', | 
| 136 RMAP : '--rmap-' } | 136 RMAP : '--rmap-' } | 
| 137 | 137 | 
| 138 aligner_path = dict((aligner, os.path.expanduser(find_location(aligner) or default_path)) | 138 #aligner_path = dict((aligner, os.path.expanduser(find_location(aligner) or default_path)) | 
| 139 for aligner, default_path in | 139 # for aligner, default_path in | 
| 140 [(BOWTIE,'~/bowtie-0.12.7/'), | 140 # [(BOWTIE,'~/bowtie/'), | 
| 141 (BOWTIE2, '~/bowtie-0.12.7/'), | 141 # (BOWTIE2, '~/bowtie2/'), | 
| 142 (SOAP, '~/soap2.21release/'), | 142 # (SOAP, '~/soap/'), | 
| 143 (RMAP, '~/rmap_v2.05/bin') | 143 # (RMAP, '~/rmap/bin') | 
| 144 ]) | 144 # ]) | 
| 145 | 145 aligner_path = dict((aligner, os.path.expanduser(find_location(aligner) or "None")) | 
| 146 for aligner in [(BOWTIE), (BOWTIE2), (SOAP), (RMAP)]) | |
| 146 | 147 | 
| 147 reference_genome_path = os.path.join(os.path.split(globals()['__file__'])[0],'reference_genomes') | 148 reference_genome_path = os.path.join(os.path.split(globals()['__file__'])[0],'reference_genomes') | 
| 148 | 149 | 
| 149 | 150 | 
| 150 | 151 | 
| 212 | 213 | 
| 213 def split_file(filename, output_prefix, nlines): | 214 def split_file(filename, output_prefix, nlines): | 
| 214 """ Splits a file (equivalend to UNIX split -l ) """ | 215 """ Splits a file (equivalend to UNIX split -l ) """ | 
| 215 fno = 0 | 216 fno = 0 | 
| 216 lno = 0 | 217 lno = 0 | 
| 217 INPUT = open(filename, 'r') | 218 if filename.endswith(".gz") : | 
| 219 INPUT = gzip.open(filename, 'rb') | |
| 220 else : | |
| 221 INPUT = open(filename, 'r') | |
| 218 output = None | 222 output = None | 
| 219 for l in INPUT: | 223 for l in INPUT: | 
| 220 if lno == 0: | 224 if lno == 0: | 
| 221 fno += 1 | 225 fno += 1 | 
| 222 if output is not None: output.close() | 226 if output is not None: output.close() | 
| 319 | 323 | 
| 320 def run_in_parallel(commands): | 324 def run_in_parallel(commands): | 
| 321 | 325 | 
| 322 commands = [(cmd[0], open(cmd[1], 'w')) if type(cmd) is tuple else (cmd, None) for cmd in commands] | 326 commands = [(cmd[0], open(cmd[1], 'w')) if type(cmd) is tuple else (cmd, None) for cmd in commands] | 
| 323 | 327 | 
| 324 logm('Starting commands:\n' + '\n'.join([cmd for cmd, stdout in commands])) | 328 #logm('Starting commands:\n' + '\n'.join([cmd for cmd, stdout in commands])) | 
| 329 logm('Starting commands:') | |
| 330 for cmd, stdout in commands : | |
| 331 logm("Launched: "+cmd) | |
| 325 for i, proc in enumerate([subprocess.Popen(args = shlex.split(cmd), stdout = stdout) for cmd, stdout in commands]): | 332 for i, proc in enumerate([subprocess.Popen(args = shlex.split(cmd), stdout = stdout) for cmd, stdout in commands]): | 
| 326 return_code = proc.wait() | 333 return_code = proc.wait() | 
| 327 logm('Finished: ' + commands[i][0]) | 334 logm('Finished: ' + commands[i][0]) | 
| 328 if return_code != 0: | 335 if return_code != 0: | 
| 329 error('%s \nexit with an error code: %d. Please, check the log files.' % (commands[i], return_code)) | 336 error('%s \nexit with an error code: %d. Please, check the log files.' % (commands[i], return_code)) | 
