Mercurial > repos > devteam > basecoverage
annotate gops_basecoverage.py @ 4:346e0034714a draft
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit de7140295cce07e1bc1697e51dab4271c8d7a8a6
author | devteam |
---|---|
date | Fri, 18 Dec 2015 19:36:36 -0500 |
parents | c929b6540d07 |
children | 37652c34b3bf |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 """ | |
3 Count total base coverage. | |
4 | |
5 usage: %prog in_file out_file | |
6 -1, --cols1=N,N,N,N: Columns for start, end, strand in first file | |
7 """ | |
8 | |
3
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
9 import fileinput |
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
10 import sys |
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
11 from bx.intervals.io import NiceReaderWrapper |
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
12 from bx.intervals.operations.base_coverage import base_coverage |
0 | 13 from bx.cookbook import doc_optparse |
3
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
14 from bx.tabular.io import ParseError |
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
15 from galaxy.tools.util.galaxyops import fail, parse_cols_arg, skipped |
0 | 16 |
17 assert sys.version_info[:2] >= ( 2, 4 ) | |
18 | |
3
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
19 |
0 | 20 def main(): |
21 options, args = doc_optparse.parse( __doc__ ) | |
22 try: | |
23 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 ) | |
24 in_fname, out_fname = args | |
25 except: | |
26 doc_optparse.exception() | |
3
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
27 |
0 | 28 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), |
29 chrom_col=chr_col_1, | |
30 start_col=start_col_1, | |
31 end_col=end_col_1, | |
3
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
32 strand_col=strand_col_1, |
0 | 33 fix_strand=True ) |
3
c929b6540d07
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents:
0
diff
changeset
|
34 |
0 | 35 try: |
36 bases = base_coverage(g1) | |
37 except ParseError, exc: | |
38 fail( "Invalid file format: %s" % str( exc ) ) | |
39 out_file = open( out_fname, "w" ) | |
40 out_file.write( "%s\n" % str( bases ) ) | |
41 out_file.close() | |
42 if g1.skipped > 0: | |
43 print skipped( g1, filedesc="" ) | |
44 | |
45 if __name__ == "__main__": | |
46 main() |