-
Notifications
You must be signed in to change notification settings - Fork 2
/
produce_bcftools_call.py
75 lines (58 loc) · 2.11 KB
/
produce_bcftools_call.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
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 5 21:15:31 2020
@author: YudongCai
@Email: [email protected]
"""
import click
def load_genomefile(gfile):
"""
第一列染色体ID,第二列长度
"""
glens = {}
with open(gfile) as f:
for line in f:
tline = line.strip().split()
glens[tline[0]] = int(tline[1])
return glens
def produce_shell(i, chrom, start, end):
return f"""/stor9000/apps/users/NWSUAF/2012010954/Software/bcftools/bcftools-1.10.2/bcftools \\
mpileup \\
-C 50 \\
-q 30 \\
-Q 20 \\
-r {chrom}:{start}-{end} \\
-a INFO/AD,FORMAT/AD,FORMAT/DP,FORMAT/ADF,FORMAT/ADR \\
-f /stor9000/apps/users/NWSUAF/2012010954/Genome/ASM_gaot/ASM.fa \\
-b BAM.list | \\
/stor9000/apps/users/NWSUAF/2012010954/Software/bcftools/bcftools-1.10.2/bcftools \\
call \\
-v \\
-m \\
-f GQ,GP \\
--threads 2 \\
--skip-variants indels \\
-O z \\
-o /stor9000/apps/users/NWSUAF/2012010954/01_GoatProject/01_data/06_bcftools/V1/out/split/{i}_chr{chrom}.raw.vcf.gz
/stor9000/apps/users/NWSUAF/2012010954/Software/bcftools/bcftools-1.10.2/bcftools \\
index \\
/stor9000/apps/users/NWSUAF/2012010954/01_GoatProject/01_data/06_bcftools/V1/out/split/{i}_chr{chrom}.raw.vcf.gz
"""
@click.command()
@click.option('--gfile', help='.genome文件,第一列染色体号,第二列长度。')
@click.option('--blocksize', help='以blocksize为长度创建shell, 单位Mbp, 默认100Mbp', type=int, default=30)
@click.option('--outprefix', help='输出shell前缀')
def main(gfile, blocksize, outprefix):
blocksize *= 1_000_000
glens = load_genomefile(gfile)
i = 0
for chrom, glen in glens.items():
for start in range(1, glen+1, blocksize):
i += 1
end = start + blocksize - 1
print(f'file{i} {chrom}:{start}-{end}')
cmd = produce_shell(i, chrom, start, end)
with open(f'{outprefix}_{i}.sh', 'w') as f:
f.write(cmd)
if __name__ == '__main__':
main()