1 | #!/usr/bin/python2.6 |
---|
2 | |
---|
3 | """ |
---|
4 | Mask out potential CpG sites from a maf. Restricted or inclusive definition |
---|
5 | of CpG sites can be used. The total fraction masked is printed to stderr. |
---|
6 | |
---|
7 | usage: %prog < input > output |
---|
8 | -m, --mask=N: Character to use as mask ('?' is default) |
---|
9 | -r, --restricted: Use restricted definition of CpGs |
---|
10 | """ |
---|
11 | |
---|
12 | import bx.align |
---|
13 | import bx.align.maf |
---|
14 | from bx.cookbook import doc_optparse |
---|
15 | import sys |
---|
16 | import bx.align.sitemask.cpg |
---|
17 | |
---|
18 | def main(): |
---|
19 | options, args = doc_optparse.parse( __doc__ ) |
---|
20 | try: |
---|
21 | if options.mask: |
---|
22 | mask = options.mask |
---|
23 | else: |
---|
24 | mask = "?" |
---|
25 | except: |
---|
26 | doc_optparse.exception() |
---|
27 | |
---|
28 | reader = bx.align.maf.Reader( sys.stdin ) |
---|
29 | writer = bx.align.maf.Writer( sys.stdout ) |
---|
30 | |
---|
31 | if options.restricted: |
---|
32 | cpgfilter = bx.align.sitemask.cpg.Restricted( mask=mask ) |
---|
33 | else: |
---|
34 | cpgfilter = bx.align.sitemask.cpg.Inclusive( mask=mask ) |
---|
35 | cpgfilter.run( reader, writer.write ) |
---|
36 | |
---|
37 | print >> sys.stderr, str( float(cpgfilter.masked)/float(cpgfilter.total) * 100 ) + "% bases masked." |
---|
38 | |
---|
39 | if __name__ == "__main__": |
---|
40 | main() |
---|