-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsoftware.py
executable file
·163 lines (138 loc) · 6.47 KB
/
software.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env python3
"""
Copyright 2020 Ryan Wick ([email protected])
https://github.com/rrwick/Trycycler
This file is part of Trycycler. Trycycler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version. Trycycler is distributed
in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details. You should have received a copy of the GNU General Public License along with Trycycler.
If not, see <http://www.gnu.org/licenses/>.
"""
import subprocess
import sys
from .log import log
def check_miniasm():
try:
output = subprocess.check_output(['miniasm', '-V'], stderr=subprocess.STDOUT)
except FileNotFoundError:
sys.exit('\nError: unable to find miniasm - make sure that miniasm is installed and '
'available on the path, then try again.')
except subprocess.CalledProcessError:
sys.exit('\nError: unable to determine miniasm version - make sure that miniasm is '
'correctly installed, then try again.')
output = output.decode().strip()
log(f' miniasm: v{output}')
def check_minimap2():
try:
output = subprocess.check_output(['minimap2', '--version'], stderr=subprocess.STDOUT)
except FileNotFoundError:
sys.exit('\nError: unable to find minimap2 - make sure that minimap2 is installed and '
'available on the path, then try again.')
except subprocess.CalledProcessError:
sys.exit('\nError: unable to determine minimap2 version - make sure that minimap2 is '
'correctly installed, then try again.')
output = output.decode().strip()
log(f' minimap2: v{output}')
def check_muscle():
try:
output = subprocess.check_output(['muscle', '-version'], stderr=subprocess.STDOUT)
except FileNotFoundError:
sys.exit('\nError: unable to find MUSCLE - make sure that MUSCLE is installed and '
'available on the path, then try again.')
except subprocess.CalledProcessError:
sys.exit('\nError: unable to determine MUSCLE version - make sure that MUSCLE is '
'correctly installed, then try again.')
output = output.decode().strip()
version = parse_muscle_version(output)
log(f' MUSCLE: v{version}')
if not version.startswith('3') and not version.startswith('5'):
sys.exit('\nError: either MUSCLE v3 or MUSCLE v5 is required')
def get_muscle_version():
"""
This function assumes that the check_muscle function has already been run, so it doesn't catch
exceptions.
"""
output = subprocess.check_output(['muscle', '-version'], stderr=subprocess.STDOUT)
output = output.decode().strip()
return parse_muscle_version(output)
def parse_muscle_version(output):
if 'MUSCLE v' in output: # for version 3
output = output.split('MUSCLE v')[1]
output = output.split(' ')[0]
return output.strip()
elif 'muscle ' in output: # For version 5
output = output.split('muscle ')[1]
output = output.split('_')[0]
output = output.split('\n')[0]
return output.strip()
else:
return '?'
def check_mash():
try:
output = subprocess.check_output(['mash', '--version'], stderr=subprocess.STDOUT)
except FileNotFoundError:
sys.exit('\nError: unable to find Mash - make sure that Mash is installed and '
'available on the path, then try again.')
except subprocess.CalledProcessError:
sys.exit('\nError: unable to determine Mash version - make sure that Mash is '
'correctly installed, then try again.')
output = output.decode().strip()
log(f' Mash: v{output}')
def check_r():
try:
output = subprocess.check_output(['R', '--version'], stderr=subprocess.STDOUT)
except FileNotFoundError:
sys.exit('\nError: unable to find R - make sure that R is installed and '
'available on the path, then try again.')
except subprocess.CalledProcessError:
sys.exit('\nError: unable to determine R version - make sure that R is '
'correctly installed, then try again.')
output = output.decode().strip()
version = parse_r_version(output)
log(f' R: v{version}')
def parse_r_version(output):
if 'R version ' in output:
output = output.split('R version ')[1]
output = output.split(' ')[0]
return output.strip()
else:
return '?'
def check_ape():
try:
output = subprocess.check_output(['R', '--quiet', '-e', 'packageVersion("ape")'],
stderr=subprocess.STDOUT)
except (FileNotFoundError, subprocess.CalledProcessError):
sys.exit('\nError: unable to find ape - make sure that the "ape" package is installed '
'for your R installation, then try again.')
output = output.decode().strip()
if 'there is no package' in output or 'not found' in output:
sys.exit('\nError: unable to find ape - make sure that the "ape" package is installed '
'for your R installation, then try again.')
version = parse_r_package_version(output)
log(f' ape: v{version}')
def check_phangorn():
try:
output = subprocess.check_output(['R', '--quiet', '-e', 'packageVersion("phangorn")'],
stderr=subprocess.STDOUT)
except (FileNotFoundError, subprocess.CalledProcessError):
sys.exit('\nError: unable to find phangorn - make sure that the "phangorn" package is '
'installed for your R installation, then try again.')
output = output.decode().strip()
if 'there is no package' in output or 'not found' in output:
sys.exit('\nError: unable to find phangorn - make sure that the "phangorn" package is '
'installed for your R installation, then try again.')
version = parse_r_package_version(output)
log(f' phangorn: v{version}')
def parse_r_package_version(output):
if '[1] ‘' in output:
output = output.split('[1] ‘')[1]
output = output.split('’')[0]
return output.strip()
elif "[1] '" in output:
output = output.split("[1] '")[1]
output = output.split("'")[0]
return output.strip()
else:
return '?'