Skip to content

Commit eff2407

Browse files
committed
0.4a.05: max threads, import MSA bug.
1 parent 7620183 commit eff2407

File tree

6 files changed

+180
-48
lines changed

6 files changed

+180
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AB12PHYLO
22

33
![PyPI license](https://img.shields.io/pypi/l/ansicolortags.svg)
4-
![gitlab version](https://img.shields.io/static/v1?label=version&message=0.4a04&color=blue&style=flat)
4+
![gitlab version](https://img.shields.io/static/v1?label=version&message=0.4a05&color=blue&style=flat)
55
![Python version](https://img.shields.io/static/v1?label=python&message=3.6&color=orange&style=flat&logo=python)
66

77
[AB12PHYLO](https://gitlab.lrz.de/leokaindl/ab12phylo/) is an integrated, easy-to-use pipeline for Maximum Likelihood (ML) phylogenetic tree inference from ABI sequencing data.

ab12phylo/files/gui.glade

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22
<!-- Generated with glade 3.38.2 -->
33
<interface>
44
<requires lib="gtk+" version="3.22"/>
5+
<object class="GtkAdjustment" id="cpu_adj">
6+
<property name="lower">1</property>
7+
<property name="upper">400</property>
8+
<property name="value">1</property>
9+
<property name="step-increment">1</property>
10+
<property name="page-increment">1</property>
11+
</object>
12+
<object class="GtkEntry" id="cpu_count_bak">
13+
<property name="name">cpu_count_bak</property>
14+
<property name="visible">True</property>
15+
<property name="can-focus">False</property>
16+
<property name="vexpand">False</property>
17+
<property name="editable">False</property>
18+
<property name="max-length">10</property>
19+
<property name="width-chars">3</property>
20+
<property name="placeholder-text" translatable="yes">1</property>
21+
<property name="input-purpose">number</property>
22+
</object>
523
<object class="GtkAdjustment" id="dist_adj">
624
<property name="upper">100</property>
725
<property name="step-increment">0.20</property>
@@ -4864,7 +4882,7 @@ Alternatively, a color legend would nicely fit here.</property>
48644882
<property name="hexpand">False</property>
48654883
<property name="vexpand">True</property>
48664884
<child>
4867-
<!-- n-columns=2 n-rows=12 -->
4885+
<!-- n-columns=2 n-rows=14 -->
48684886
<object class="GtkGrid" id="raxml">
48694887
<property name="visible">True</property>
48704888
<property name="can-focus">False</property>
@@ -4956,7 +4974,7 @@ Alternatively, a color legend would nicely fit here.</property>
49564974
</object>
49574975
<packing>
49584976
<property name="left-attach">0</property>
4959-
<property name="top-attach">6</property>
4977+
<property name="top-attach">8</property>
49604978
<property name="width">2</property>
49614979
</packing>
49624980
</child>
@@ -5331,11 +5349,79 @@ Alternatively, a color legend would nicely fit here.</property>
53315349
</object>
53325350
<packing>
53335351
<property name="left-attach">0</property>
5334-
<property name="top-attach">7</property>
5352+
<property name="top-attach">9</property>
53355353
<property name="width">2</property>
53365354
<property name="height">5</property>
53375355
</packing>
53385356
</child>
5357+
<child>
5358+
<object class="GtkLabel">
5359+
<property name="visible">True</property>
5360+
<property name="can-focus">False</property>
5361+
<property name="halign">end</property>
5362+
<property name="hexpand">False</property>
5363+
<property name="vexpand">False</property>
5364+
<property name="label" translatable="yes"> CPUs:</property>
5365+
<property name="use-underline">True</property>
5366+
</object>
5367+
<packing>
5368+
<property name="left-attach">0</property>
5369+
<property name="top-attach">6</property>
5370+
</packing>
5371+
</child>
5372+
<child>
5373+
<object class="GtkLabel">
5374+
<property name="visible">True</property>
5375+
<property name="can-focus">False</property>
5376+
<property name="halign">end</property>
5377+
<property name="hexpand">False</property>
5378+
<property name="vexpand">False</property>
5379+
<property name="label" translatable="yes">use at most:</property>
5380+
<property name="use-underline">True</property>
5381+
</object>
5382+
<packing>
5383+
<property name="left-attach">0</property>
5384+
<property name="top-attach">7</property>
5385+
</packing>
5386+
</child>
5387+
<child>
5388+
<object class="GtkSpinButton" id="cpu_use">
5389+
<property name="name">cpu_use</property>
5390+
<property name="visible">True</property>
5391+
<property name="can-focus">True</property>
5392+
<property name="tooltip-markup" translatable="yes">You can also set this for the export bash script via &lt;i&gt;-f&lt;/i&gt;.</property>
5393+
<property name="hexpand">False</property>
5394+
<property name="max-length">2</property>
5395+
<property name="width-chars">2</property>
5396+
<property name="text" translatable="yes">0,10</property>
5397+
<property name="input-purpose">number</property>
5398+
<property name="adjustment">cpu_adj</property>
5399+
<property name="climb-rate">1</property>
5400+
<property name="numeric">True</property>
5401+
<property name="value">1</property>
5402+
</object>
5403+
<packing>
5404+
<property name="left-attach">1</property>
5405+
<property name="top-attach">7</property>
5406+
</packing>
5407+
</child>
5408+
<child>
5409+
<object class="GtkLabel" id="cpu_count">
5410+
<property name="name">cpu_count</property>
5411+
<property name="visible">True</property>
5412+
<property name="can-focus">False</property>
5413+
<property name="halign">start</property>
5414+
<property name="margin-start">8</property>
5415+
<property name="hexpand">False</property>
5416+
<property name="vexpand">False</property>
5417+
<property name="label" translatable="yes">1</property>
5418+
<property name="use-underline">True</property>
5419+
</object>
5420+
<packing>
5421+
<property name="left-attach">1</property>
5422+
<property name="top-attach">6</property>
5423+
</packing>
5424+
</child>
53395425
</object>
53405426
<packing>
53415427
<property name="name">RAxML-NG</property>

ab12phylo/gtk_ml.py

Lines changed: 82 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,18 @@ def _load_raxml_help(self):
142142
iface.ml_help.props.buffer.props.text = res.stdout.decode().lstrip()
143143
LOG.debug('got RAxML --help')
144144

145+
try:
146+
# get number of available CPUs
147+
res = run(args='nproc ', stdout=PIPE, stderr=PIPE, shell=True)
148+
cpus = int(res.stdout.decode().strip())
149+
iface.cpu_count.set_text(str(cpus))
150+
cpu_adj = iface.cpu_use.get_adjustment().props
151+
cpu_adj.upper = cpus
152+
cpu_adj.value = cpus
153+
LOG.debug('found %d CPUs' % cpus)
154+
except Exception as ex:
155+
LOG.error('reading CPUs failed')
156+
145157
def reload_ui_state(self):
146158
data = self.data
147159
iface = self.iface
@@ -180,7 +192,7 @@ def start_ML(self, widget, mode, run_after=None):
180192

181193
if mode in ['raxml', 'raxml_export']:
182194
ml.raxml = iface.raxml_exe.get_filename()
183-
for w_name in ['evo_modify', 'bootstraps', 'rand', 'pars', 'raxml_seed']:
195+
for w_name in ['evo_modify', 'bootstraps', 'rand', 'pars', 'raxml_seed', 'cpu_use']:
184196
ml.__setattr__(w_name, iface.__getattribute__(w_name).get_text())
185197
if w_name in ['bootstraps', 'rand', 'pars']:
186198
ml.__setattr__(w_name, int(ml.__getattribute__(w_name)))
@@ -227,23 +239,24 @@ def do_ML(self, mode):
227239
iface.i = 0
228240

229241
# prepare the calls
230-
chck = '%s --msa %s --check --model %s' \
231-
+ ml.evo_modify + ' --prefix %s'
242+
chck = '%s --msa "%s" --check --model %s' \
243+
+ ml.evo_modify + ' --prefix "%s"'
232244

233-
inML = '%s --msa %s --model %s' + ml.evo_modify + \
234-
' --prefix %s' + ' --seed %d' % ml.raxml_seed + \
235-
' --threads auto{16} --workers auto{16}' \
245+
inML = '%s --msa "%s" --model %s' + ml.evo_modify + \
246+
' --prefix "%s"' + ' --seed %d' % ml.raxml_seed + \
247+
' --threads auto{%s} --workers auto{%s}' + \
236248
' --redo --tree %s ' % ','.join(
237249
[a for a in ['rand{%d}' % ml.rand if ml.rand > 0 else None,
238250
'pars{%d}' % ml.pars if ml.pars > 0 else None] if a])
239251

240-
boot = '%s --bootstrap --msa %s --model %s --tree %s' + \
241-
' --prefix %s' + ' --bs-trees %d' % ml.bootstraps + \
252+
boot = '%s --bootstrap --msa "%s" --model %s --tree "%s"' + \
253+
' --prefix "%s"' + ' --bs-trees %d' % ml.bootstraps + \
242254
' --seed %d' % ml.raxml_seed + \
243-
' --threads auto{16} --workers auto{16} --redo'
255+
' --threads auto{%s} --workers auto{%s} --redo'
244256

245-
supp = '%s --support --tree %s --bs-trees %s --bs-metric fbp,tbe ' \
246-
'--prefix %s --threads auto{16} --workers auto{16} --redo'
257+
supp = '%s --support --tree "%s" --bs-trees %s --bs-metric fbp,tbe ' + \
258+
'--prefix "%s" --threads ' + \
259+
'auto{%s} --workers auto{%s} --redo'
247260

248261
# res = run(stdout=PIPE, stderr=PIPE, args=shlex.split(
249262
# arg % (ml.raxml, msa, prefix / 'bs_')))
@@ -256,45 +269,48 @@ def do_ML(self, mode):
256269

257270
if ml.raxml_shell:
258271
with open(shell, 'w') as sh:
259-
sh.write('#!/bin/bash\n\ntrap \'\' SIGINT\n\n')
272+
sh.write('#!/bin/bash\n\n')
260273

261274
# loop over the stages
262275
for i, (desc, key, prev, arg, add) in enumerate(zip(
263276
['check MSA', 'infer ML tree', 'bootstrapping', 'calc. branch support'],
264277
[False, 'ML', 'BS', False], [0, 1, ml.rand + ml.pars + 1, iface.k - 2],
265278
[chck, inML, boot, supp],
266279
[(ml.raxml, msa, ml.evo_model, prefix / 'chk'),
267-
(ml.raxml, msa, ml.evo_model, prefix / 'ml'),
280+
(ml.raxml, msa, ml.evo_model,
281+
prefix / 'ml', ml.cpu_use, ml.cpu_use),
268282
(ml.raxml, msa, prefix / 'ml.raxml.bestModel',
269-
prefix / 'ml.raxml.bestTree', prefix / 'bs'),
283+
prefix / 'ml.raxml.bestTree',
284+
prefix / 'bs', ml.cpu_use, ml.cpu_use),
270285
(ml.raxml, prefix / 'ml.raxml.bestTree',
271-
prefix / 'bs.raxml.bootstraps', prefix / 'sp')])):
286+
prefix / 'bs.raxml.bootstraps',
287+
prefix / 'sp', ml.cpu_use, ml.cpu_use)])):
272288

273289
if ml.raxml_shell and mode == 'raxml':
274290
with open(shell, 'a') as sh:
275291
sh.write('# %s\n' % desc)
276-
sh.write(arg % add)
277-
# if i != 2:
278-
# sh.write(arg % add)
279-
# else:
280-
# # special case bootstrapping:
281-
# bash = '''
282-
# mkfifo pipe || exit 1
283-
# (%s) > pipe &
284-
# pid=$!
285-
# echo "AB12PHYLO: Bootstrapping PID is $pid"
286-
# while read -r line; do
287-
# echo "$line"
288-
# if [[ "${line::12}" == "Elapsed time" ]]; then
289-
# echo "AB12PHYLO: Finished bootstrapping, terminating process $pid to ensure it exits."
290-
# kill -s SIGTERM $pid
291-
# break
292-
# fi
293-
# done < pipe
294-
# rm pipe
295-
# '''.strip() % (arg % add)
296-
# sh.write(bash)
297-
# sh.write('\n\necho "AB12PHYLO: %s done"\n' % desc)
292+
# sh.write(arg % add)
293+
if i != 2:
294+
sh.write(arg % add)
295+
else:
296+
# special case bootstrapping:
297+
bash = '''
298+
mkfifo pipe || exit 1
299+
(%s) > pipe &
300+
pid=$!
301+
echo "AB12PHYLO: Bootstrapping PID is $pid"
302+
while read -r line; do
303+
echo "$line"
304+
if [[ "${line::12}" == "Elapsed time" ]]; then
305+
echo "AB12PHYLO: Finished bootstrapping, terminating process $pid to ensure it exits."
306+
kill -s SIGTERM $pid
307+
break
308+
fi
309+
done < pipe
310+
rm pipe
311+
'''.strip() % (arg % add)
312+
sh.write(bash)
313+
sh.write('\n\necho "AB12PHYLO: %s done"\n' % desc)
298314
if i != 3:
299315
sh.write('\nsleep 1s\n\n')
300316
continue
@@ -346,17 +362,41 @@ def do_ML(self, mode):
346362
LOG.debug(iface.text)
347363
sh = 'raxml_run.sh'
348364
with open(sh, 'w') as sf:
349-
sf.write('#!/bin/bash')
365+
bash = '''
366+
#!/bin/bash\n
367+
echo "You can set a CPU limit here! This will proceed in a bit, interrupt with Ctrl+C"\n
368+
print_usage() {
369+
printf "Usage: Limit the number of threads/logical cores used via -f <number>"\n}\n
370+
print_usage\n
371+
sleep 10s\n
372+
cpu_limit=400\n
373+
while getopts 'f:' flag; do
374+
case "${flag}" in
375+
f) cpu_limit="${OPTARG}" ;;
376+
*) print_usage
377+
exit 1 ;;\n esac\ndone\n
378+
# get the number of CPUs available
379+
cpus=$(nproc)\n
380+
# find the minimum of the CPUs allowed and available
381+
if [ $cpu_limit -lt $cpus ]; then
382+
used=$cpu_limit\nfi
383+
if [ $cpus -lt $cpu_limit ];then
384+
used=$cpus\nfi\n
385+
echo "CPUs available: $cpus, use at most $used"
386+
'''.strip()
387+
sf.write(bash)
350388
sf.write('\n\n# Check MSA\n')
351-
sf.write(chck % ('./raxml-ng', 'msa.fasta', Path(ml.evo_model).name, 'chk'))
389+
sf.write(chck % ('./raxml-ng', 'msa.fasta',
390+
Path(ml.evo_model).name, 'chk'))
352391
sf.write('\n\n# Find best ML tree\n')
353-
sf.write(inML % ('./raxml-ng', 'msa.fasta', Path(ml.evo_model).name, 'ml'))
392+
sf.write(inML % ('./raxml-ng', 'msa.fasta',
393+
Path(ml.evo_model).name, 'ml', '$used', '$used'))
354394
sf.write('\n\n# Compute bootstrap iterations\n')
355395
sf.write(boot % ('./raxml-ng', 'msa.fasta', 'ml.raxml.bestModel',
356-
'ml.raxml.bestTree', 'bs'))
396+
'ml.raxml.bestTree', 'bs', '$used', '$used'))
357397
sf.write('\n\n# Calculate branch support\n')
358398
sf.write(supp % ('./raxml-ng', 'ml.raxml.bestTree',
359-
'bs.raxml.bootstraps', 'sp'))
399+
'bs.raxml.bootstraps', 'sp', '$used', '$used'))
360400
sf.write('\n\n')
361401

362402
with ZipFile(self.wd / 'RAxML_export.zip', 'w', ZIP_DEFLATED) as zf:

ab12phylo/gtk_msa.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,13 @@ def load_msa(self, widget):
213213
self.wd / repo.PATHS.import_msa, 'fasta')}}
214214
iface.aligner, cmd = self.get_msa_build_cmd(
215215
repo.toalgo(iface.msa_algo.get_active_text()), self.wd, data.genes)
216+
# write a metadata.tsv
217+
with open(self.wd / repo.PATHS.tsv, 'w') as metadata:
218+
metadata.write('id\tgene\n')
219+
for _id in data.gene_ids['import']:
220+
metadata.write('%s\timport\n' % _id)
216221
LOG.debug('using imported MSA')
222+
self.set_changed(PAGE, False)
217223
self.save_ui_state()
218224

219225
def refresh(self):

ab12phylo/gtk_proj.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self):
4646
self.msa = Namespace(cmd=dict(), remote_cmd=dict(), last_cmd='')
4747
self.gbl = Namespace(ignore_ids=set())
4848
self.ml = Namespace(evo_model='GTR', evo_modify='+G4', bootstraps=1000,
49-
rand=20, pars=20, raxml_shell=True)
49+
rand=20, pars=20, raxml_shell=True, cpu_count='1', cpu_use='1')
5050
self.phy = Namespace(gap_share=.1, unk_share=.1, flip=.7, dist=0, sel_gene=None,
5151
did_BLAST=False, query='', exclude='',
5252
rect=True, circ=False, unro=False, tbe=True, fbp=False, supp=True,

ab12phylo_cmd/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
__author__ = 'Leo Kaindl'
44
__email__ = '[email protected]'
5-
__version__ = '0.4a04'
5+
__version__ = '0.4a05'
66
__date__ = '28 January 2021'
77
__license__ = 'MIT'
88
__status__ = 'Alpha'

0 commit comments

Comments
 (0)