annotate scripts/ReMatCh/modules/utils.py @ 6:20ff3dca457f draft default tip

planemo upload commit 6857c749c21f580c828aba3543e294b69d32b662
author iss
date Mon, 23 Oct 2023 11:45:36 +0000
parents c6bab5103a14
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
1 import pickle
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
2 from traceback import format_exception as traceback_format_exception
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
3 import shlex
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
4 import subprocess
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
5 from threading import Timer
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
6 import shutil
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
7 import time
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
8 from functools import wraps as functools_wraps
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
9 import os.path
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
10 import sys
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
11
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
12
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
13 def start_logger(workdir):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
14 time_str = time.strftime("%Y%m%d-%H%M%S")
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
15 sys.stdout = Logger(workdir, time_str)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
16 logfile = sys.stdout.getLogFile()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
17 return logfile, time_str
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
18
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
19
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
20 class Logger(object):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
21 def __init__(self, out_directory, time_str):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
22 self.logfile = os.path.join(out_directory, str('run.' + time_str + '.log'))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
23 self.terminal = sys.stdout
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
24 self.log = open(self.logfile, "w")
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
25
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
26 def write(self, message):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
27 self.terminal.write(message)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
28 self.log.write(message)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
29 self.log.flush()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
30
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
31 def flush(self):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
32 pass
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
33
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
34 def getLogFile(self):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
35 return self.logfile
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
36
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
37
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
38 def get_cpu_information(outdir, time_str):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
39 with open(os.path.join(outdir, 'cpu_information.' + time_str + '.cpu.txt'), 'wt') as writer:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
40 command = ['cat', '/proc/cpuinfo']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
41 run_successfully, stdout, stderr = run_command_popen_communicate(command, False, None, False)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
42 if run_successfully:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
43 writer.write(stdout)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
44
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
45 with open(os.path.join(outdir, 'cpu_information.' + time_str + '.slurm.txt'), 'wt') as writer:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
46 for environment in sorted(os.environ):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
47 if environment.startswith('SLURM_'):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
48 writer.write('#' + environment + '\n' + os.environ[environment] + '\n')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
49
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
50
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
51 def setPATHvariable(doNotUseProvidedSoftware, script_path):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
52 path_variable = os.environ['PATH']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
53 script_folder = os.path.dirname(script_path)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
54 # Set path to use provided softwares
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
55 if not doNotUseProvidedSoftware:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
56 bowtie2 = os.path.join(script_folder, 'src', 'bowtie2-2.2.9')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
57 samtools = os.path.join(script_folder, 'src', 'samtools-1.3.1', 'bin')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
58 bcftools = os.path.join(script_folder, 'src', 'bcftools-1.3.1', 'bin')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
59
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
60 os.environ['PATH'] = str(':'.join([bowtie2, samtools, bcftools, path_variable]))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
61
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
62 # Print PATH variable
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
63 print('\n' + 'PATH variable:')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
64 print(os.environ['PATH'])
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
65
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
66
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
67 def checkPrograms(programs_version_dictionary):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
68 print('\n' + 'Checking dependencies...')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
69 programs = programs_version_dictionary
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
70 which_program = ['which', '']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
71 listMissings = []
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
72 for program in programs:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
73 which_program[1] = program
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
74 run_successfully, stdout, stderr = run_command_popen_communicate(which_program, False, None, False)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
75 if not run_successfully:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
76 listMissings.append(program + ' not found in PATH.')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
77 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
78 print(stdout.splitlines()[0])
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
79 if programs[program][0] is None:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
80 print(program + ' (impossible to determine programme version) found at: ' + stdout.splitlines()[0])
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
81 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
82 if program.endswith('.jar'):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
83 check_version = ['java', '-jar', stdout.splitlines()[0], programs[program][0]]
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
84 programs[program].append(stdout.splitlines()[0])
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
85 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
86 check_version = [stdout.splitlines()[0], programs[program][0]]
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
87 run_successfully, stdout, stderr = run_command_popen_communicate(check_version, False, None, False)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
88 if stdout == '':
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
89 stdout = stderr
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
90 if program in ['wget', 'awk']:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
91 version_line = stdout.splitlines()[0].split(' ', 3)[2]
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
92 elif program in ['prefetch', 'fastq-dump']:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
93 version_line = stdout.splitlines()[1].split(' ')[-1]
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
94 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
95 version_line = stdout.splitlines()[0].split(' ')[-1]
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
96 replace_characters = ['"', 'v', 'V', '+', ',']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
97 for i in replace_characters:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
98 version_line = version_line.replace(i, '')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
99 print(program + ' (' + version_line + ') found')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
100 if programs[program][1] == '>=':
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
101 program_found_version = version_line.split('.')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
102 program_version_required = programs[program][2].split('.')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
103 if len(program_version_required) == 3:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
104 if len(program_found_version) == 2:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
105 program_found_version.append(0)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
106 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
107 program_found_version[2] = program_found_version[2].split('_')[0]
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
108 for i in range(0, len(program_version_required)):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
109 if int(program_found_version[i]) > int(program_version_required[i]):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
110 break
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
111 elif int(program_found_version[i]) == int(program_version_required[i]):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
112 continue
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
113 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
114 listMissings.append('It is required ' + program + ' with version ' +
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
115 programs[program][1] + ' ' + programs[program][2])
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
116 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
117 if version_line != programs[program][2]:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
118 listMissings.append('It is required ' + program + ' with version ' + programs[program][1] +
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
119 ' ' + programs[program][2])
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
120 return listMissings
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
121
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
122
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
123 def requiredPrograms(asperaKey, downloadCramBam, SRA, SRAopt):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
124 programs_version_dictionary = {}
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
125 programs_version_dictionary['wget'] = ['--version', '>=', '1.12']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
126 programs_version_dictionary['gzip'] = ['--version', '>=', '1.6']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
127 programs_version_dictionary['bowtie2'] = ['--version', '>=', '2.2.9']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
128 programs_version_dictionary['samtools'] = ['--version', '==', '1.3.1']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
129 programs_version_dictionary['bcftools'] = ['--version', '==', '1.3.1']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
130 if asperaKey is not None:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
131 programs_version_dictionary['ascp'] = ['--version', '>=', '3.6.1']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
132 if SRA or SRAopt:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
133 programs_version_dictionary['prefetch'] = ['--version', '>=', '2.8.2']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
134 programs_version_dictionary['fastq-dump'] = ['--version', '>=', '2.8.2']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
135 programs_version_dictionary['awk'] = ['--version', '>=', '3.0.4']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
136 missingPrograms = checkPrograms(programs_version_dictionary)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
137 if len(missingPrograms) > 0:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
138 sys.exit('\n' + 'Errors:' + '\n' + '\n'.join(missingPrograms))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
139
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
140
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
141 def general_information(logfile, version, outdir, time_str, doNotUseProvidedSoftware, asperaKey, downloadCramBam, SRA, SRAopt):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
142 # Check if output directory exists
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
143
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
144 print('\n' + '==========> ReMatCh <==========')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
145 print('\n' + 'Program start: ' + time.ctime())
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
146
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
147 # Tells where the logfile will be stored
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
148 print('\n' + 'LOGFILE:')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
149 print(logfile)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
150
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
151 # Print command
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
152 print('\n' + 'COMMAND:')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
153 script_path = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'rematch.py')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
154 print(sys.executable + ' ' + ' '.join(sys.argv))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
155
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
156 # Print directory where programme was lunch
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
157 print('\n' + 'PRESENT DIRECTORY:')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
158 present_directory = os.path.abspath(os.getcwd())
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
159 print(present_directory)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
160
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
161 # Print program version
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
162 print('\n' + 'VERSION:')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
163 script_version_git(version, present_directory, script_path)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
164
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
165 # Get CPU information
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
166 get_cpu_information(outdir, time_str)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
167
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
168 # Set and print PATH variable
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
169 setPATHvariable(doNotUseProvidedSoftware, script_path)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
170
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
171 # Check programms
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
172 requiredPrograms(asperaKey, downloadCramBam, SRA, SRAopt)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
173
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
174 return script_path
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
175
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
176
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
177 def script_version_git(version, current_directory, script_path, no_git_info=False):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
178 """
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
179 Print script version and get GitHub commit information
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
180
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
181 Parameters
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
182 ----------
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
183 version : str
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
184 Version of the script, e.g. "4.0"
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
185 current_directory : str
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
186 Path to the directory where the script was start to run
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
187 script_path : str
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
188 Path to the script running
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
189 no_git_info : bool, default False
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
190 True if it is not necessary to retreive the GitHub commit information
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
191
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
192 Returns
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
193 -------
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
194
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
195 """
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
196 print('Version {}'.format(version))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
197
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
198 if not no_git_info:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
199 try:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
200 os.chdir(os.path.dirname(os.path.dirname(script_path)))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
201 command = ['git', 'log', '-1', '--date=local', '--pretty=format:"%h (%H) - Commit by %cn, %cd) : %s"']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
202 run_successfully, stdout, stderr = run_command_popen_communicate(command, False, 15, False)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
203 print(stdout)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
204 command = ['git', 'remote', 'show', 'origin']
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
205 run_successfully, stdout, stderr = run_command_popen_communicate(command, False, 15, False)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
206 print(stdout)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
207 except:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
208 print('HARMLESS WARNING: git command possibly not found. The GitHub repository information will not be'
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
209 ' obtained.')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
210 finally:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
211 os.chdir(current_directory)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
212
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
213
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
214 def run_time(start_time):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
215 end_time = time.time()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
216 time_taken = end_time - start_time
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
217 hours, rest = divmod(time_taken, 3600)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
218 minutes, seconds = divmod(rest, 60)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
219 print('Runtime :' + str(hours) + 'h:' + str(minutes) + 'm:' + str(round(seconds, 2)) + 's')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
220 return round(time_taken, 2)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
221
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
222
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
223 def timer(function, name):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
224 @functools_wraps(function)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
225 def wrapper(*args, **kwargs):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
226 print('\n' + 'RUNNING {0}\n'.format(name))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
227 start_time = time.time()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
228
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
229 results = list(function(*args, **kwargs)) # guarantees return is a list to allow .insert()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
230
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
231 time_taken = run_time(start_time)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
232 print('END {0}'.format(name))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
233
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
234 results.insert(0, time_taken)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
235 return results
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
236 return wrapper
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
237
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
238
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
239 def remove_directory(directory):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
240 if os.path.isdir(directory):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
241 shutil.rmtree(directory)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
242
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
243
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
244 def save_variable_to_pickle(variableToStore, outdir, prefix):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
245 pickleFile = os.path.join(outdir, str(prefix + '.pkl'))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
246 with open(pickleFile, 'wb') as writer:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
247 pickle.dump(variableToStore, writer)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
248
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
249
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
250 def extract_variable_from_pickle(pickleFile):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
251 with open(pickleFile, 'rb') as reader:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
252 variable = pickle.load(reader)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
253 return variable
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
254
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
255
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
256 def trace_unhandled_exceptions(func):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
257 @functools_wraps(func)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
258 def wrapped_func(*args, **kwargs):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
259 try:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
260 func(*args, **kwargs)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
261 except Exception as e:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
262 print('Exception in ' + func.__name__)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
263 print(e)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
264
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
265 exc_type, exc_value, exc_tb = sys.exc_info()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
266 print(''.join(traceback_format_exception(exc_type, exc_value, exc_tb)))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
267
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
268 raise exc_type(exc_value)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
269
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
270 return wrapped_func
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
271
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
272
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
273 def kill_subprocess_Popen(subprocess_Popen, command):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
274 print('Command run out of time: ' + str(command))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
275 subprocess_Popen.kill()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
276
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
277
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
278 def run_command_popen_communicate(command, shell_True, timeout_sec_None, print_comand_True):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
279 run_successfully = False
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
280 if not isinstance(command, str):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
281 command = ' '.join(command)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
282 command = shlex.split(command)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
283
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
284 if print_comand_True:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
285 print('Running: ' + ' '.join(command))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
286
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
287 if shell_True:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
288 command = ' '.join(command)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
289 proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
290 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
291 proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
292
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
293 not_killed_by_timer = True
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
294 if timeout_sec_None is None:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
295 stdout, stderr = proc.communicate()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
296 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
297 time_counter = Timer(timeout_sec_None, kill_subprocess_Popen, args=(proc, command,))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
298 time_counter.start()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
299 stdout, stderr = proc.communicate()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
300 time_counter.cancel()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
301 not_killed_by_timer = time_counter.isAlive()
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
302
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
303 if proc.returncode == 0:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
304 run_successfully = True
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
305 else:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
306 if not print_comand_True and not_killed_by_timer:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
307 print('Running: ' + str(command))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
308 if len(stdout) > 0:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
309 print('STDOUT')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
310 print(stdout.decode("utf-8"))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
311 if len(stderr) > 0:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
312 print('STDERR')
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
313 print(stderr.decode("utf-8"))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
314 return run_successfully, stdout.decode("utf-8"), stderr.decode("utf-8")
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
315
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
316
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
317 def rchop(string, ending):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
318 if string.endswith(ending):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
319 string = string[:-len(ending)]
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
320 return string
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
321
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
322
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
323 def reverse_complement(seq):
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
324 complement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A', 'N': 'N'}
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
325
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
326 reverse_complement_string = ''
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
327
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
328 seq = reversed(list(seq.upper()))
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
329
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
330 for base in seq:
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
331 reverse_complement_string += complement[base]
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
332
c6bab5103a14 "planemo upload commit 6abf3e299d82d07e6c3cf8642bdea80e96df64c3-dirty"
iss
parents:
diff changeset
333 return reverse_complement_string