forked from YuSugihara/MutMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalignment.py
executable file
·42 lines (33 loc) · 1.27 KB
/
alignment.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
import subprocess as sbp
from mutmap.utils import time_stamp, clean_cmd, call_log
class Alignment(object):
def __init__(self, args):
self.args = args
self.out = args.out
def run(self, fastq1, fastq2, index):
print(time_stamp(),
'start to align reads of {} by BWA.'.format(index),
flush=True)
cmd = 'bwa mem -t {0} {1} {2} {3} | \
samtools view -b \
-o {4}/20_bam/{5}.bam \
>> {4}/log/bwa.log \
2>&1'.format(self.args.threads,
self.args.ref,
fastq1,
fastq2,
self.out,
index)
cmd = clean_cmd(cmd)
try:
sbp.run(cmd,
stdout=sbp.DEVNULL,
stderr=sbp.DEVNULL,
shell=True,
check=True)
except sbp.CalledProcessError:
call_log(self.out, 'bwa', cmd)
sys.exit()
print(time_stamp(),
'alignment {} successfully finished.'.format(index),
flush=True)