Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
panacota
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Amandine PERRIN
panacota
Commits
7eff7c24
Commit
7eff7c24
authored
5 years ago
by
Amandine PERRIN
Browse files
Options
Downloads
Patches
Plain Diff
More comments on pool for annotation step
parent
7f20e65a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
PanACoTA/annotate_module/prokka_prodigal_functions.py
+43
-7
43 additions, 7 deletions
PanACoTA/annotate_module/prokka_prodigal_functions.py
with
43 additions
and
7 deletions
PanACoTA/annotate_module/prokka_prodigal_functions.py
+
43
−
7
View file @
7eff7c24
...
@@ -51,8 +51,9 @@ def run_annotation_all(genomes, threads, force, annot_folder, prodigal_only=Fals
...
@@ -51,8 +51,9 @@ def run_annotation_all(genomes, threads, force, annot_folder, prodigal_only=Fals
-------
-------
dict
dict
{genome: boolean} -> with True if prokka/prodigal ran well, False otherwise.
{genome: boolean} -> with True if prokka/prodigal ran well, False otherwise.
#
"""
"""
# Update information according to annotation soft used and write message
if
prodigal_only
:
if
prodigal_only
:
message
=
"
Annotating all genomes with prodigal
"
message
=
"
Annotating all genomes with prodigal
"
run_annot
=
run_prodigal
run_annot
=
run_prodigal
...
@@ -62,8 +63,10 @@ def run_annotation_all(genomes, threads, force, annot_folder, prodigal_only=Fals
...
@@ -62,8 +63,10 @@ def run_annotation_all(genomes, threads, force, annot_folder, prodigal_only=Fals
run_annot
=
run_prokka
run_annot
=
run_prokka
main_logger
=
logging
.
getLogger
(
"
qc_annotate.prokka
"
)
main_logger
=
logging
.
getLogger
(
"
qc_annotate.prokka
"
)
main_logger
.
info
(
message
)
main_logger
.
info
(
message
)
# Get total number of genomes to annotate, used to show annotation progress
nbgen
=
len
(
genomes
)
nbgen
=
len
(
genomes
)
bar
=
None
bar
=
None
# If user did not ask for quiet, create progressbar
if
not
quiet
:
if
not
quiet
:
# Create progress bar
# Create progress bar
widgets
=
[
'
Annotation:
'
,
progressbar
.
Bar
(
marker
=
'
█
'
,
left
=
''
,
right
=
''
),
widgets
=
[
'
Annotation:
'
,
progressbar
.
Bar
(
marker
=
'
█
'
,
left
=
''
,
right
=
''
),
...
@@ -72,6 +75,9 @@ def run_annotation_all(genomes, threads, force, annot_folder, prodigal_only=Fals
...
@@ -72,6 +75,9 @@ def run_annotation_all(genomes, threads, force, annot_folder, prodigal_only=Fals
]
]
bar
=
progressbar
.
ProgressBar
(
widgets
=
widgets
,
max_value
=
nbgen
,
bar
=
progressbar
.
ProgressBar
(
widgets
=
widgets
,
max_value
=
nbgen
,
term_width
=
100
).
start
()
term_width
=
100
).
start
()
# Get resource availability:
# - number of threads used by prokka/prodigal (cores_annot)
# - how many genomes can be annotated at the same time (pool_size)
if
threads
<=
3
:
if
threads
<=
3
:
cores_annot
=
threads
cores_annot
=
threads
pool_size
=
1
pool_size
=
1
...
@@ -84,33 +90,60 @@ def run_annotation_all(genomes, threads, force, annot_folder, prodigal_only=Fals
...
@@ -84,33 +90,60 @@ def run_annotation_all(genomes, threads, force, annot_folder, prodigal_only=Fals
else
:
else
:
cores_annot
=
2
cores_annot
=
2
pool_size
=
int
(
threads
/
cores_annot
)
pool_size
=
int
(
threads
/
cores_annot
)
# Create pool with a given size (=number of tasks to be launched in parallel)
pool
=
multiprocessing
.
Pool
(
pool_size
)
pool
=
multiprocessing
.
Pool
(
pool_size
)
# Create a Queue to put logs from processes, and handle them after from a single thread
# Create a Queue to put logs from processes, and handle them after from a single thread
m
=
multiprocessing
.
Manager
()
m
=
multiprocessing
.
Manager
()
q
=
m
.
Queue
()
q
=
m
.
Queue
()
# {genome: [name,
g
path_
cut_gembas
e, size, nbcont,
l
90]}
# {genome: [
gembase_
name, path_
to_origfile, path_toannotate_fil
e,
g
size, nbcont,
L
90]}
# arguments
:
(
gpath,
annot
_folder, threads, name, force, nbcont,
q) for each genome
# arguments: gpath,
prok
_folder, threads, name, force, nbcont,
small(for prodigal), q
arguments
=
[(
genomes
[
g
][
1
],
annot_folder
,
cores_annot
,
genomes
[
g
][
0
],
arguments
=
[(
genomes
[
g
][
2
],
annot_folder
,
cores_annot
,
genomes
[
g
][
0
],
force
,
genomes
[
g
][
3
],
small
,
q
)
force
,
genomes
[
g
][
4
],
small
,
q
)
for
g
in
sorted
(
genomes
)]
for
g
in
sorted
(
genomes
)]
try
:
try
:
# Start pool (run 'run_annot' n each set of arguments)
final
=
pool
.
map_async
(
run_annot
,
arguments
,
chunksize
=
1
)
final
=
pool
.
map_async
(
run_annot
,
arguments
,
chunksize
=
1
)
# Close pool: no more data will be put on this pool
pool
.
close
()
pool
.
close
()
# Listen for logs in processes
# Listen for logs in processes
lp
=
threading
.
Thread
(
target
=
utils
.
logger_thread
,
args
=
(
q
,))
lp
=
threading
.
Thread
(
target
=
utils
.
logger_thread
,
args
=
(
q
,))
lp
.
start
()
lp
.
start
()
if
not
quiet
:
if
not
quiet
:
while
True
:
while
True
:
# Final is ready when all pool elements are done
if
final
.
ready
():
if
final
.
ready
():
break
break
# If not done, get number of genomes left
remaining
=
final
.
_number_left
remaining
=
final
.
_number_left
# Update progress bar
bar
.
update
(
nbgen
-
remaining
)
bar
.
update
(
nbgen
-
remaining
)
# End progress bar
bar
.
finish
()
bar
.
finish
()
pool
.
join
()
pool
.
join
()
# Put None to tell 'q' that everything is finished. It can stopped and be joined.
q
.
put
(
None
)
q
.
put
(
None
)
# join lp (tell to stop once all log processes are done, which is the case here)
lp
.
join
()
lp
.
join
()
final
=
final
.
get
()
final
=
final
.
get
()
# If an error occurs, terminate pool and exit
# # If user stops programm (ctrl+C), end it
# except KeyboardInterrupt as ki:
# print("error")
# for worker in pool._pool:
# print(worker.is_alive())
# pool.join()
# print("closed")
# pool.terminate()
# print("--------------terminate ok----------------")
# lp.join()
# print("thread stopped")
# # run_event.clear()
# # lp.terminate()
# # print("--------------JOIN--------------")
# # pool.terminate()
# main_logger.error("Process killed by CTRL+C")
# return "coucou"
# If an error occurs, terminate pool, write error and exit
except
Exception
as
excp
:
# pragma: no cover
except
Exception
as
excp
:
# pragma: no cover
pool
.
terminate
()
pool
.
terminate
()
main_logger
.
error
(
excp
)
main_logger
.
error
(
excp
)
...
@@ -153,10 +186,13 @@ def run_prokka(arguments):
...
@@ -153,10 +186,13 @@ def run_prokka(arguments):
root
.
addHandler
(
qh
)
root
.
addHandler
(
qh
)
logger
=
logging
.
getLogger
(
'
run_prokka
'
)
logger
=
logging
.
getLogger
(
'
run_prokka
'
)
logger
.
log
(
utils
.
detail_lvl
(),
"
Start annotating {} {} with Prokka
"
.
format
(
name
,
gpath
))
logger
.
log
(
utils
.
detail_lvl
(),
"
Start annotating {} {} with Prokka
"
.
format
(
name
,
gpath
))
# Define prokka directory and logfile, and check their existence
# Define prokka directory and logfile, and check their existence
prok_dir
=
os
.
path
.
join
(
prok_folder
,
os
.
path
.
basename
(
gpath
)
+
"
-prokkaRes
"
)
prok_dir
=
os
.
path
.
join
(
prok_folder
,
os
.
path
.
basename
(
gpath
)
+
"
-prokkaRes
"
)
fnull
=
open
(
os
.
devnull
,
'
w
'
)
fnull
=
open
(
os
.
devnull
,
'
w
'
)
prok_logfile
=
os
.
path
.
join
(
prok_folder
,
os
.
path
.
basename
(
gpath
)
+
"
-prokka.log
"
)
prok_logfile
=
os
.
path
.
join
(
prok_folder
,
os
.
path
.
basename
(
gpath
)
+
"
-prokka.log
"
)
# import sys
# sys.exit(1)
# If result dir already exists, check if we can use it or next step or not
# If result dir already exists, check if we can use it or next step or not
if
os
.
path
.
isdir
(
prok_dir
)
and
not
force
:
if
os
.
path
.
isdir
(
prok_dir
)
and
not
force
:
logger
.
warning
((
"
Prokka results folder already exists.
"
).
format
(
prok_dir
))
logger
.
warning
((
"
Prokka results folder already exists.
"
).
format
(
prok_dir
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment