-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbam_to_snp.py
executable file
·77 lines (70 loc) · 2.17 KB
/
bam_to_snp.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
76
77
#!/usr/bin/python3
import os
import re
import sys
import csv
import urllib.request
import zipfile
import gzip
from pyliftover import LiftOver
import pysam
import argparse
import snpload
import bamload
#TODO: map quality
#TODO: mt str option
obuild=38
force_ibuild=None
min_qual=20
min_mapqual=20
min_reads=1
read_max=100
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--obuild', help='Output build')
parser.add_argument('-i', '--ibuild', help='Force input build')
parser.add_argument('-b', '--bqual', help='Min base quality')
parser.add_argument('-q', '--mqual', help='Min map quality')
parser.add_argument('-m', '--minread', help='Min reads to qualify')
parser.add_argument('-x', '--maxread', help='Max reads to analyze per location')
parser.add_argument('-a', '--ancient-ends', help='Discard A/T if within n bases at the ends - try 1-5')
parser.add_argument('--no-mt', action="store_true", help='Skip MT')
parser.add_argument('--no-y', action="store_true", help='Skip Y')
parser.add_argument('--no-ystr', action="store_true", help='Skip Y-STR')
parser.add_argument('--auto', action="store_true", help='Convert autosomal')
parser.add_argument('--ybrowse', action="store_true", help='Use full ybrowse database positions')
parser.add_argument('file', nargs='+')
args = parser.parse_args()
if args.obuild:
obuild = int(args.obuild)
if args.mqual:
min_mapqual = int(args.mqual)
if args.bqual:
min_qual = int(args.bqual)
if args.minread:
min_reads = int(args.minread)
if args.maxread:
read_max = int(args.maxread)
if args.ancient_ends:
bamload.ancient_mode_ends = int(args.ancient_ends)
if args.no_mt:
bamload.convert_mt=0
if args.no_y:
bamload.convert_y=0
if args.no_ystr:
bamload.convert_ystr=0
if args.auto:
bamload.convert_snpauto=1
if args.ybrowse:
bamload.load_ybrowse=1
bamload.min_qual=min_qual
bamload.min_mapqual=min_mapqual
bamload.min_reads=min_reads
bamload.read_max=read_max
for samfname in args.file:
if args.ibuild:
in_build = int(args.ibuild)
else:
in_build = bamload.get_build(samfname)
bamload.setup_conv(in_build)
snpset = bamload.full_convert(samfname)
snpload.save(samfname+'.snp.txt', snpset, obuild)