forked from zhangtaolab/Chorus2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChorusNGSselect.py
More file actions
171 lines (94 loc) · 5.27 KB
/
Copy pathChorusNGSselect.py
File metadata and controls
171 lines (94 loc) · 5.27 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import sys
import argparse
import os
import pandas as pd
from Choruslib.revcom import revcom
def main():
args = check_options(get_options())
try:
probe = pd.read_table(args.input,names=("chrom","start","end","sequence","score","strand"),
dtype={"chrom":str,"start":int,"end":int,"sequence":str,"score":int,"strand":str})
ftprobe = probe[((probe.score > args.mink) & (probe.score < args.maxk) & (
probe.score > probe.score.quantile(args.minquantile)) & (
probe.score < probe.score.quantile(args.maxquantile)))]
probe = ''
chromnames = ftprobe.chrom.unique()
outio = open(args.output, 'w')
for chrom in chromnames:
prestart = 0
strandfr = 1
for index, row in ftprobe[ftprobe.chrom == chrom].sort_values(by='start').iterrows():
nowpbstart = row.start
if nowpbstart > prestart + args.dis:
if args.strand == True:
if strandfr % 2 == 0:
row[5] = '-'
row[3] = revcom(row[3])
strandfr += 1
prestart = nowpbstart
print(row.chrom, row.start, row.end, row.sequence, row.score, row.strand, sep='\t', file=outio)
outio.close()
print("Filtered finished!")
except:
print("Probe file format error. Please check your probe file!")
sys.exit(1)
def check_options(parser):
args = parser.parse_args()
if args.input:
if not os.path.exists(args.input):
print("Can not locate input file, please input input file.\n")
parser.print_help()
sys.exit(1)
if args.mink > args.maxk:
print("min k-mer (%s) score greater than max k-mer (%s) score" % (args.mink , args.maxk))
parser.print_help()
sys.exit(1)
if args.minquantile > args.maxquantile:
print("min quantile (%s) greater than max quantile (%s)" % (args.minquantile , args.maxquantile))
parser.print_help()
sys.exit(1)
if args.minquantile > 1 or args.minquantile < 0:
print("min quantile error, please check!")
parser.print_help()
sys.exit(1)
if args.maxquantile > 1 or args.maxquantile < 0:
print("max quantile error, please check!")
parser.print_help()
sys.exit(1)
return args
def get_options():
parser = argparse.ArgumentParser(description="ChorusNGSselect for Oligo FISH probe selection by NGS k-mer score", prog='ChorusNGSselect',
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="Example:\n"
" ChorusNGSselect -i ChorusNGSfilter_output.bed -q 0.1 -p 0.9 -d 25 \\ \n"
" -o filtered_output.bed"
)
parser.add_argument('--version', action='version', version='%(prog)s 1.0')
parser.add_argument('-i', '--input', dest='input', help='Input bed format probe file generated by ChorusNGSfilter',
required=True, type=str)
parser.add_argument('-o', '--output', dest='output', help='Output bed format probe file after k-mer score filter. (Default: filtered_output.bed)',
default='filtered_output.bed', type=str)
parser.add_argument('-m', '--min', dest='mink', help='Minimum k-mer score, score < min value will be dropped. For example: 900. '
'Incompatible with parameter \'-q/-p\' (Default: 0)', default=0, type=int)
parser.add_argument('-l', '--max', dest='maxk', help='Maximum k-mer score, score > max value will be dropped. For example: 2000. '
'Incompatible with parameter \'-q/-p\' (Default: 10000000)', default=10000000, type=int)
parser.add_argument('-q', '--minquantile', dest='minquantile', type=float,
help='Filter < min%% quantile k-mer score, range from 0 to 1. For example: 0.25 means 25%% quantile. '
'Incompatible with parameter \'-m/-l\'. (Default: 0.1)', default=0.1)
parser.add_argument('-p', '--maxquantile', dest='maxquantile', type=float,
help='Filter > max%% quantile k-mer score, range from 0 to 1. For example: 0.75 means 75%% quantile. '
'Incompatible with parameter \'-m/-l\'. (Default: 0.9)', default=0.9)
parser.add_argument('-bs', '--bothstrand', dest='strand', help='Keep both + and - strand probes. (Default is True)',
action='store_true')
parser.add_argument('-ss', '--singlestrand', dest='strand', help='Keep only + strand probes. Incompatible with parameter \'-bs/--bothstrand\'',
action='store_false')
parser.set_defaults(strand=True)
parser.add_argument('-d', '--distance', dest='dis', help='Minimum distance between two adjacent probes. (Default: 25)',
default=25, type=int)
return parser
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
sys.stderr.write("User interrupt\n")
sys.exit(0)