-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmc_genotype.py
executable file
·47 lines (40 loc) · 1.42 KB
/
mc_genotype.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
#!/usr/bin/env python3
import subprocess
import os
from sys import argv
def remove_dummy(vcf_in, vcf_out):
header = []
variants =[]
SNVsites = []
with open(vcf_in, 'r') as gz:
for line in gz:
line = line.rstrip('\n')
if line[1] == '#':
header.append(line.rstrip('\n'))
elif line[1] =='C':
columns = line.rstrip('\n')
else:
# line = line.rstrip('\n')
variant = line.split('\t')
variants.append(variant)
with open(vcf_out, 'w') as out:
for h in header:
out.write(h)
out.write('\t'.join(columns.split('\t')[:9]) + '\t' + columns.split('\t')[10])
for v in variants:
out.write('\t'.join(v[:9]) + '\t' + v[10])
def geno_cov(mccortex, reference, calls_vcf, raw_ctx, outdir):
ref = os.path.basename(reference)
sample = os.path.basename(raw_ctx).rstrip('.ctx')
subprocess.call(
[mccortex + " vcfcov -q -n 50M -m 1G -r " + outdir + "/ref/" + ref + " -f -o " + outdir + "/" + sample + ".cov.vcf " +
calls_vcf + " " + outdir + "/raw/" + raw_ctx + ".ctx" ], stdout=subprocess.PIPE, shell=True)
def main():
mccortex = argv[1]
reference = argv[2]
calls_vcf = argv[3]
raw_ctx = argv[4]
outdir = argv[5]
geno_cov(mccortex, reference, calls_vcf, raw_ctx, outdir)
if __name__ == '__main__':
main()