annotate gops_basecoverage.py @ 3:c929b6540d07 draft

planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
author devteam
date Tue, 13 Oct 2015 12:49:07 -0400
parents 3755ee8a74d7
children 37652c34b3bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
1 #!/usr/bin/env python
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
2 """
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
3 Count total base coverage.
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
4
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
5 usage: %prog in_file out_file
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
6 -1, --cols1=N,N,N,N: Columns for start, end, strand in first file
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
7 """
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
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
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
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
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
16
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
17 assert sys.version_info[:2] >= ( 2, 4 )
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
18
3
c929b6540d07 planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents: 0
diff changeset
19
0
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
20 def main():
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
21 options, args = doc_optparse.parse( __doc__ )
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
22 try:
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
23 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 )
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
24 in_fname, out_fname = args
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
25 except:
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
26 doc_optparse.exception()
3
c929b6540d07 planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents: 0
diff changeset
27
0
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
28 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
29 chrom_col=chr_col_1,
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
30 start_col=start_col_1,
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
31 end_col=end_col_1,
3
c929b6540d07 planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents: 0
diff changeset
32 strand_col=strand_col_1,
0
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
33 fix_strand=True )
3
c929b6540d07 planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
devteam
parents: 0
diff changeset
34
0
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
35 try:
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
36 bases = base_coverage(g1)
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
37 except ParseError, exc:
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
38 fail( "Invalid file format: %s" % str( exc ) )
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
39 out_file = open( out_fname, "w" )
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
40 out_file.write( "%s\n" % str( bases ) )
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
41 out_file.close()
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
42 if g1.skipped > 0:
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
43 print skipped( g1, filedesc="" )
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
44
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
45 if __name__ == "__main__":
3755ee8a74d7 Imported from capsule None
devteam
parents:
diff changeset
46 main()