Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cnvCallerGPU
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gad-public
cnvCallerGPU
Commits
f55201d8
Commit
f55201d8
authored
Feb 29, 2024
by
Theo Serralta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
final code to find CNV with multithreading
parent
70f8dbd4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
14 deletions
+23
-14
test_final_multithreading.py
CNV/test_final_multithreading.py
+23
-14
No files found.
CNV/test_final_multithreading.py
View file @
f55201d8
...
...
@@ -2,10 +2,13 @@ import pysam
import
concurrent.futures
import
sys
import
getopt
import
logging
#Options
output_file
=
""
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'b:w:s:t:o:e'
)
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
'b:w:s:t:o:e
:
'
)
for
opt
,
arg
in
opts
:
if
opt
in
(
"-b"
):
bamfile
=
arg
...
...
@@ -16,15 +19,18 @@ try:
if
opt
in
(
"-t"
):
num_threads
=
int
(
arg
)
if
opt
in
(
"-o"
):
output_file
=
open
(
arg
,
"
w
"
)
if
opt
in
(
"-e"
)
:
logfile
=
open
(
arg
,
"w"
)
output_file
=
open
(
arg
,
"
a
"
)
if
opt
in
(
"-e"
):
logfile
=
arg
except
getopt
.
GetoptError
:
print
(
'Invalid argument'
)
sys
.
exit
(
1
)
def
calcul_depth_seq
(
bamfile
,
seq
,
window_size
,
step_size
):
logging
.
basicConfig
(
filename
=
'
%
s'
%
(
logfile
),
filemode
=
'a'
,
level
=
logging
.
INFO
,
format
=
'
%(asctime)
s
%(levelname)
s -
%(message)
s'
)
logging
.
info
(
'start'
)
def
calcul_depth_seq
(
bamfile
,
seq
,
window_size
,
step_size
,
numero_de_thread
):
sys
.
stderr
.
write
(
"
\t
entering calcul_depth_seq : thread numero
%
s
\n
"
%
numero_de_thread
)
samfile
=
pysam
.
AlignmentFile
(
bamfile
,
"rb"
)
seq_length
=
samfile
.
lengths
[
samfile
.
references
.
index
(
seq
)]
#Permet d'obtenir la longueur de la sequence
...
...
@@ -36,30 +42,31 @@ def calcul_depth_seq(bamfile, seq, window_size, step_size):
window_depths
.
append
(
pileupcolumn
.
n
)
#ajoute le nb de lecture couvrant cette position à la liste window_depths
if
window_depths
:
#calcul la profondeur moyenne pour chaque sequence
sys
.
stderr
.
write
(
"
\t\t
entering wd thread numero
%
s
\n
"
%
numero_de_thread
)
avg_depth
=
sum
(
window_depths
)
/
len
(
window_depths
)
print
(
f
"{seq}:{pos_start}-{pos_end}: {avg_depth}"
)
sys
.
stdout
.
write
(
f
"{seq}:{pos_start}-{pos_end}: {avg_depth}
\n
"
)
output_file
.
write
(
f
"{seq}:{pos_start}-{pos_end}: {avg_depth}
\n
"
)
s
amfile
.
close
(
)
s
ys
.
stderr
.
write
(
"
\t
leaving calcul_depth_seq thread numero
%
s
\n
"
%
numero_de_thread
)
def
calcul_depth_all
(
bamfile
,
window_size
,
step_size
,
num_threads
):
sys
.
stderr
.
write
(
"entering calcul_depth_all
\n
"
)
samfile
=
pysam
.
AlignmentFile
(
bamfile
,
"rb"
)
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
num_threads
)
as
executor
:
futures
=
[]
#liste pour stocker les futures
n
=
0
for
seq
in
samfile
.
references
:
future
=
executor
.
submit
(
calcul_depth_seq
,
bamfile
,
seq
,
window_size
,
step_size
)
n
+=
1
future
=
executor
.
submit
(
calcul_depth_seq
,
bamfile
,
seq
,
window_size
,
step_size
,
n
)
futures
.
append
(
future
)
concurrent
.
futures
.
wait
(
futures
)
samfile
.
close
()
if
output_file
!=
sys
.
stdout
:
output_file
.
close
()
if
logfile
:
logfile
.
close
()
#if output_file != sys.stdout:
# output_file.close()
#Programme principal
if
len
(
sys
.
argv
)
<
2
or
bamfile
is
None
:
...
...
@@ -68,3 +75,5 @@ if len(sys.argv) <2 or bamfile is None:
bamfile_path
=
bamfile
calcul_depth_all
(
bamfile_path
,
window_size
,
step_size
,
num_threads
)
logging
.
info
(
'end'
)
samfile
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment