annotate gops_basecoverage.py @ 5:21898544368b draft

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit d7b1a60c0aecc46b7f625c3e32f882562b512fd9
author devteam
date Mon, 13 Jun 2022 16:20:48 +0000
parents 2cedec3759e4
children 9c5ff4695c97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
1 #!/usr/bin/env python
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
2 """
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
3 Count total base coverage.
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
4
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
5 usage: %prog in_file out_file
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
6 -1, --cols1=N,N,N,N: Columns for start, end, strand in first file
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
7 """
4
2cedec3759e4 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit cae3e05d02e60f595bb8b6d77a84f030e9bd1689
devteam
parents: 3
diff changeset
8 from __future__ import print_function
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
9
3
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
10 import fileinput
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
11 import sys
4
2cedec3759e4 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit cae3e05d02e60f595bb8b6d77a84f030e9bd1689
devteam
parents: 3
diff changeset
12
2cedec3759e4 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit cae3e05d02e60f595bb8b6d77a84f030e9bd1689
devteam
parents: 3
diff changeset
13 from bx.cookbook import doc_optparse
3
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
14 from bx.intervals.io import NiceReaderWrapper
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
15 from bx.intervals.operations.base_coverage import base_coverage
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
16 from bx.tabular.io import ParseError
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
17 from galaxy.tools.util.galaxyops import fail, parse_cols_arg, skipped
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
18
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
19 assert sys.version_info[:2] >= ( 2, 4 )
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
20
3
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
21
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
22 def main():
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
23 options, args = doc_optparse.parse( __doc__ )
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
24 try:
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
25 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 )
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
26 in_fname, out_fname = args
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
27 except:
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
28 doc_optparse.exception()
3
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
29
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
30 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ),
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
31 chrom_col=chr_col_1,
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
32 start_col=start_col_1,
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
33 end_col=end_col_1,
3
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
34 strand_col=strand_col_1,
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
35 fix_strand=True )
3
0a3e3133b09d planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
devteam
parents: 0
diff changeset
36
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
37 try:
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
38 bases = base_coverage(g1)
4
2cedec3759e4 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit cae3e05d02e60f595bb8b6d77a84f030e9bd1689
devteam
parents: 3
diff changeset
39 except ParseError as exc:
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
40 fail( "Invalid file format: %s" % str( exc ) )
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
41 out_file = open( out_fname, "w" )
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
42 out_file.write( "%s\n" % str( bases ) )
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
43 out_file.close()
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
44 if g1.skipped > 0:
4
2cedec3759e4 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit cae3e05d02e60f595bb8b6d77a84f030e9bd1689
devteam
parents: 3
diff changeset
45 print(skipped( g1, filedesc="" ))
2cedec3759e4 planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/basecoverage commit cae3e05d02e60f595bb8b6d77a84f030e9bd1689
devteam
parents: 3
diff changeset
46
0
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
47
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
48 if __name__ == "__main__":
1e6a9e97fa41 Imported from capsule None
devteam
parents:
diff changeset
49 main()