forked from guoweilong/cgmaptools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcgmaptools
executable file
·288 lines (272 loc) · 12.1 KB
/
cgmaptools
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/usr/bin/env python
"""
cgmaptools
Copyright (C) Weilong Guo & Ping Zhu
Contact: Weilong Guo <guoweilong@126.com>
Ping Zhu <pingzhu.work@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
import sys, os
#os.system(sys.argv[0])
#print sys.argv[0]
#print sys.argv[1]
#print sys.argv[-1]
DIR=os.path.dirname(sys.argv[0])
#print DIR
import subprocess
#subprocess.call(["ls", "-l", "/etc/resolv.conf"])
argv_len = len(sys.argv)
def PrintVersion() :
print("Version: 0.1.2")
print("Updated on: Dec. 14th, 2018")
#
if (argv_len) == 1 or sys.argv[1] in ["-h", "-H", "--help"]:
print("Program : cgmaptools (Tools for analysis in CGmap/ATCGmap format)")
PrintVersion()
print("Usage: cgmaptools <command> [options]")
print("Commands:")
print(" -- File manipulation")
print(" convert + data format conversion tools")
print(" fetch + fetch a region by random accessing")
print(" refill refill the missing columns")
print(" intersect intersect two files")
print(" merge2 + merge two files into one")
print(" mergelist + merge a list of files")
print(" sort sort lines by chromosome and position")
print(" split + split file by chromosomes")
print(" select + select lines by region/site")
print(" -- SNV analysis")
print(" snv snv analysis")
print(" -- Methylation analysis")
print(" dms differentially methylated site analysis")
print(" dmr differentially methylated region analysis")
print(" asm allele-specific methylation analysis")
print(" mbed average methylation level in regions")
print(" mbin * single sample, mC levels in bins")
print(" mmbin multiple samples, mC levels in bins")
print(" mfg methlation levels across fragmented region")
print(" mstat * methyaltion statistic")
print(" mtr methylation level to each region")
print(" -- Coverage analysis")
print(" oac +* overall coverage (for ATCGmap)")
print(" mec +* methylation effective coverage (for CGmap)")
print(" -- Graph related functions")
print(" lollipop * show local mC levels as lollipop bars")
print(" heatmap * global mC distribution for multiple samples")
print(" fragreg * show mC profile across fragmented regions")
print(" tanghulu * show local mapped reads in Tanghulu shape")
print(" -- Other Utils")
print(" findCCGG get MspI cutting sites for RRBS")
print(" bed2fragreg get fragmented region based on region")
print("Note: ")
print(" Commands support figures generation are marked with \"*\" ")
print(" Commands contain sub-commands are marked with \"+\" ")
print("Authors:")
print(" GUO, Weilong; guoweilong@126.com; http://guoweilong.github.io")
print(" ZHU, Ping; pingzhu.work@gmail.com; http://perry-zhu.github.io")
print("")
else :
code1 = sys.argv[1]
# -- File manipulation
if code1 == "convert" :
if (argv_len) == 2 or sys.argv[2] in ["-h", "-H", "--help"]:
print("Usage: cgmaptools convert <command> [options]")
PrintVersion()
print("Commands:")
print(" bam2cgmap BAM => CGmap & ATCGmap")
print(" atcgmap2atcgbz ATCGmap => ATCGbz")
print(" atcgbz2atcgmap ATCGbz => ATCGmap")
print(" atcgmap2cgmap ATCGmap => CGmap")
print(" cgmap2cgbz CGamp => CGbz")
print(" cgbz2cgmap CGbz => CGmap")
print(" cgmap2wig CGmap => WIG")
print(" bismark2cgmap Bismark => CGmap")
else :
code2 = sys.argv[2]
if code2 == "bam2cgmap" :
subprocess.call([DIR + "/bin/CGmapFromBAM"]+ sys.argv[3:])
elif code2 == "cgmap2wig" :
subprocess.call([DIR + "/bin/CGmapToWig"]+ sys.argv[3:])
elif code2 == "atcgbz2atcgmap" :
subprocess.call([DIR + "/bin/ATCGbzToATCGmap"]+ sys.argv[3:])
elif code2 == "atcgmap2atcgbz" :
subprocess.call([DIR + "/bin/ATCGmapToATCGbz"]+ sys.argv[3:])
elif code2 == "cgbz2cgmap" :
subprocess.call([DIR + "/bin/CGbzToCGmap"]+ sys.argv[3:])
elif code2 == "cgmap2cgbz" :
subprocess.call([DIR + "/bin/CGmapToCGbz"]+ sys.argv[3:])
elif code2 == "atcgmap2cgmap" :
subprocess.call([DIR + "/bin/ATCGmapToCGmapWig"]+ sys.argv[3:])
elif code2 == "bismark2cgmap" :
subprocess.call([DIR + "/bin/BismarkToCGmap"]+ sys.argv[3:])
else :
print("Wrong parameter. Enter \"cgmaptools convert -h\" for more information.")
#
#
elif code1 == "fetch" :
if (argv_len) == 2 or sys.argv[2] in ["-h", "-H", "--help"]:
print("Usage: cgmaptools fetch <command> [options]")
PrintVersion()
print("Commands:")
print(" atcgbz fetch lines from ATCGbz")
print(" cgbz fetch lines from CGbz")
else :
code2 = sys.argv[2]
if code2 == "atcgbz" :
subprocess.call([DIR + "/bin/ATCGbzFetchRegion"]+ sys.argv[3:])
elif code2 == "cgbz" :
subprocess.call([DIR + "/bin/CGbzFetchRegion"]+ sys.argv[3:])
else :
print("Wrong parameter. Enter \"cgmaptools fetch -h\" for more information.")
#
#
elif code1 == "refill" :
subprocess.call([DIR + "/bin/CGmapFillContext"]+ sys.argv[2:])
elif code1 == "intersect" :
subprocess.call([DIR + "/bin/CGmapIntersect"]+ sys.argv[2:])
elif code1 == "merge2" :
if (argv_len) == 2 or sys.argv[2] in ["-h", "-H", "--help"]:
print("Usage: cgmaptools merge2 <command> [options]")
PrintVersion()
print("Commands:")
print(" atcgmap merge two ATCGmap files into one")
print(" cgmap merge two CGmap files into one")
else :
code2 = sys.argv[2]
if code2 == "atcgmap" :
subprocess.call([DIR + "/bin/ATCGmapMerge"]+ sys.argv[3:])
elif code2 == "cgmap" :
subprocess.call([DIR + "/bin/CGmapMerge"]+ sys.argv[3:])
else :
print("Wrong parameter. Enter \"cgmaptools merge2 -h\" for more information.")
#
#
elif code1 == "mergelist" :
if (argv_len) == 2 or sys.argv[2] in ["-h", "-H", "--help"]:
print("Usage: cgmaptools mergelist <command> [options]")
PrintVersion()
print("Commands:")
print(" tomatrix mC levels matrix from multiple files")
print(" tosingle merge list of input files into one")
else :
code2 = sys.argv[2]
if code2 == "tomatrix" :
subprocess.call([DIR + "/bin/CGmapFillIndex"]+ sys.argv[3:])
elif code2 == "tosingle" :
subprocess.call([DIR + "/bin/MergeListOfCGmap"]+ sys.argv[3:])
else :
print("Wrong parameter. Enter \"cgmaptools mergelist -h\" for more information.")
#
#
elif code1 == "sort" :
subprocess.call([DIR + "/bin/Sort_chr_pos"]+ sys.argv[2:])
elif code1 == "split" :
subprocess.call([DIR + "/bin/CGmapSplitByChr"]+ sys.argv[2:])
elif code1 == "select" :
if (argv_len) == 2 or sys.argv[2] in ["-h", "-H", "--help"]:
print("Usage: cgmaptools select <command> [options]")
PrintVersion()
print("Commands:")
print(" region select or exclude liens by region lists")
print(" site select or exclude lines by site list")
else :
code2 = sys.argv[2]
if code2 == "region" :
subprocess.call([DIR + "/bin/CGmapSelectByRegion"]+ sys.argv[3:])
elif code2 == "site" :
subprocess.call([DIR + "/bin/CGmapSelectBySite"]+ sys.argv[3:])
else :
print("Wrong parameter. Enter \"cgmaptools select -h\" for more information.")
#
#
# -- SNV analysis
elif code1 == "snv" :
subprocess.call([DIR + "/bin/SNVFromATCGmap"]+ sys.argv[2:])
# -- Methylation analysis
elif code1 == "dms" :
subprocess.call([DIR + "/bin/CGmapInterDiffSite"]+ sys.argv[2:])
elif code1 == "dmr" :
subprocess.call([DIR + "/bin/CGmapInterDiffReg"]+ sys.argv[2:])
elif code1 == "asm" :
subprocess.call([DIR + "/bin/ASM"]+ sys.argv[2:])
elif code1 == "mbed" :
subprocess.call([DIR + "/bin/CGmapMethInBed"]+ sys.argv[2:])
elif code1 == "mbin" :
subprocess.call([DIR + "/bin/CGmapMethInBins"]+ sys.argv[2:])
elif code1 == "mmbin" :
subprocess.call([DIR + "/bin/CGmapsMethInBins"]+ sys.argv[2:])
elif code1 == "mfg" :
subprocess.call([DIR + "/bin/CGmapMethInFragReg"]+ sys.argv[2:])
elif code1 == "mstat" :
subprocess.call([DIR + "/bin/CGmapStatMeth"]+ sys.argv[2:])
elif code1 == "mtr" :
subprocess.call([DIR + "/bin/CGmapToRegion"]+ sys.argv[2:])
# -- Coverage analysis
elif code1 == "oac" :
if (argv_len) == 2 or sys.argv[2] in ["-h", "-H", "--help"]:
print("Usage: cgmaptools oac <command> [options]")
PrintVersion()
print("Commands:")
print(" bin * overall coverage in bins")
print(" stat * overall coverage statistics globally")
else :
code2 = sys.argv[2]
if code2 == "bin" :
subprocess.call([DIR + "/bin/ATCGmapCovInBins"]+ sys.argv[3:])
elif code2 == "stat" :
subprocess.call([DIR + "/bin/ATCGmapStatCov"]+ sys.argv[3:])
else :
print("Wrong parameter. Enter \"cgmaptools oac -h\" for more information.")
#
#
elif code1 == "mec" :
if (argv_len) == 2 or sys.argv[2] in ["-h", "-H", "--help"]:
print("Usage: cgmaptools mec <command> [options]")
PrintVersion()
print("Commands:")
print(" bin * methylation effective coverage in bins")
print(" stat * methylation effective coverage statistics globally")
else :
code2 = sys.argv[2]
if code2 == "bin" :
subprocess.call([DIR + "/bin/CGmapCovInBins"]+ sys.argv[3:])
elif code2 == "stat" :
subprocess.call([DIR + "/bin/CGmapStatCov"]+ sys.argv[3:])
else :
print("Wrong parameter. Enter \"cgmaptools mec -h\" for more information.")
#
#
# -- Graph related funtion
elif code1 == "lollipop" :
subprocess.call([DIR + "/bin/mCLollipop"]+ sys.argv[2:])
elif code1 == "heatmap" :
subprocess.call([DIR + "/bin/mCBinHeatmap"]+ sys.argv[2:])
elif code1 == "fragreg" :
subprocess.call([DIR + "/bin/mCFragRegView"]+ sys.argv[2:])
elif code1 == "tanghulu" :
subprocess.call([DIR + "/bin/mCTanghulu"]+ sys.argv[2:])
# -- other utilities
elif code1 == "findCCGG" :
subprocess.call([DIR + "/bin/FindCCGG"]+ sys.argv[2:])
elif code1 == "combinestrands" :
subprocess.call([DIR + "/bin/CGmapCombineStrands"]+ sys.argv[2:])
elif code1 == "bed2fragreg" :
subprocess.call([DIR + "/bin/FragRegFromBED"]+ sys.argv[2:])
else :
print("Wrong parameter. Enter \"cgmaptools -h\" for more information.")
#
#