-
Notifications
You must be signed in to change notification settings - Fork 28
/
dependencies.py
172 lines (139 loc) · 5.34 KB
/
dependencies.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
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python
from __future__ import print_function
import logging
import os
import subprocess
import sys
from doit.dependency import Dependency, SqliteDB
from .common import which
from . import common
class DependencyHandler(object):
def __init__(self):
self.logger = logging.getLogger(self.__class__.__name__)
self.checks = [('HMMER', check_hmmer),
('Infernal', check_infernal),
('BLAST+', check_blast),
('BUSCO', check_busco),
('TransDecoder', check_transdecoder),
('LAST', check_last),
('crb-blast', check_crb_blast)]
def add_dependency_check(self, name, function):
'''Add a new dependency to the handler.
Args:
name (str): The name of the dependency.
function (callable): A function which returns a tuple
of (boolean, string) for the status and a message, and
takes a Logger object.
'''
self.logger.debug('Add check function for {0}'.format(name))
self.checks.append((name, function))
def clear_dependency_checks(self):
self.logger.debug('Clearing {0} dependency checks from'\
' handler'.format(len(self.checks)))
self.checks = []
def run_checks(self):
for name, function in self.checks:
self.logger.debug('Run dependency function on {0}'.format(name))
status, msg = function(self.logger)
self.logger.debug('{0} has status {1}, msg: {2}'.format(name, status, msg))
yield name, status, msg
def handle(self):
common.print_header('Checking PATH for dependencies', level=2)
missing = []
for name, status, msg in self.run_checks():
if status is False:
missing.append(name)
self.logger.warning('[ ] {0}... {1}'.format(name, msg))
else:
self.logger.info('[x] {0}'.format(name))
common.print_header('Dependency results', level=2)
if missing:
self.logger.warning('{0} missing'.format(', '.join(missing)))
else:
self.logger.info('All dependencies satisfied!')
return missing
def check_or_fail(self):
missing = self.handle()
if missing:
self.logger.error('Install dependencies to continue; exiting')
sys.exit(1)
def check_hmmer(logger):
hmmscan = which('hmmscan')
hmmpress = which('hmmpress')
if hmmscan is None or hmmpress is None:
return False, 'Not found on $PATH'
else:
logger.debug('hmmscan:' + hmmscan)
logger.debug('hmmpress:' + hmmpress)
return True, os.path.dirname(hmmscan)
def check_infernal(logger):
cmscan = which('cmscan')
cmpress = which('cmpress')
if cmscan is None or cmpress is None:
return False, 'Not found on $PATH'
else:
logger.debug('cmscan:' + cmscan)
logger.debug('cmpress:' + cmpress)
return True, os.path.dirname(cmscan)
def check_blast(logger):
blastp = which('blastp')
blastx = which('blastx')
tblastn = which('tblastn')
makeblastdb = which('makeblastdb')
if (blastp is None) or (blastx is None) \
or (tblastn is None) or (makeblastdb is None):
return False, 'Not found on $PATH'
else:
logger.debug('blastp:' + blastp)
logger.debug('blastx:' + blastx)
logger.debug('tblastn:' + tblastn)
logger.debug('makeblastdb:' + makeblastdb)
return True, os.path.dirname(blastp)
def check_busco(logger):
versions = [(122, 'BUSCO_v1.22.py'),
(111, 'BUSCO_v1.1b1.py')]
for version, exc in versions:
busco = which(exc)
if busco is not None:
break
if busco is None:
return False, 'Not found on $PATH'
else:
if logger:
logger.debug('BUSCO:' + busco)
return True, busco
def check_transdecoder(logger):
longorfs = which('TransDecoder.LongOrfs')
predict = which('TransDecoder.Predict')
if longorfs is None or predict is None:
return False, 'Not found on $PATH'
else:
logger.debug('TransDecoder.LongOrfs:' + longorfs)
logger.debug('TransDecoder.Predict:' + predict)
return True, os.path.dirname(longorfs)
def check_last(logger):
lastdb = which('lastdb')
lastal = which('lastal')
if lastdb is None or lastal is None:
return False, 'Not found on $PATH'
else:
try:
version_string = subprocess.check_output(['lastal', '--version'])
except subprocess.CalledProcessError as e:
return False, '[{0}] {1}'.format(e.returncode, e.output)
except OSError as e:
return False, '[{0}] {1}'.format(e.errno, str(e))
else:
_, version = version_string.strip().split()
if int(version) < 600:
return False, 'lastal version {0} < 600, please update'.format(version)
logger.debug('lastal:' + lastal)
logger.debug('latsdb:' + lastdb)
return True, os.path.dirname(lastal)
def check_crb_blast(logger):
crb_blast = which('crb-blast')
if crb_blast is None:
return False, ''
else:
logger.debug('crb-blast:' + crb_blast)
return True, os.path.dirname(crb_blast)