Mercurial > repos > devteam > coverage
comparison gops_coverage.py @ 2:bc9c66c1e9c9 draft
planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/coverage commit a1517c9d22029095120643bbe2c8fa53754dd2b7
| author | devteam | 
|---|---|
| date | Wed, 11 Nov 2015 12:48:05 -0500 | 
| parents | 1e864693a1c0 | 
| children | 4ef9819dc7fb | 
   comparison
  equal
  deleted
  inserted
  replaced
| 1:16b62a897aac | 2:bc9c66c1e9c9 | 
|---|---|
| 5 | 5 | 
| 6 usage: %prog bed_file_1 bed_file_2 out_file | 6 usage: %prog bed_file_1 bed_file_2 out_file | 
| 7 -1, --cols1=N,N,N,N: Columns for start, end, strand in first file | 7 -1, --cols1=N,N,N,N: Columns for start, end, strand in first file | 
| 8 -2, --cols2=N,N,N,N: Columns for start, end, strand in second file | 8 -2, --cols2=N,N,N,N: Columns for start, end, strand in second file | 
| 9 """ | 9 """ | 
| 10 import sys, traceback, fileinput | 10 import fileinput | 
| 11 from warnings import warn | 11 import sys | 
| 12 from bx.intervals import * | 12 from bx.intervals.io import GenomicInterval, NiceReaderWrapper | 
| 13 from bx.intervals.io import * | 13 from bx.intervals.operations.coverage import coverage | 
| 14 from bx.intervals.operations.coverage import * | |
| 15 from bx.cookbook import doc_optparse | 14 from bx.cookbook import doc_optparse | 
| 16 from galaxy.tools.util.galaxyops import * | 15 from bx.tabular.io import ParseError | 
| 16 from galaxy.tools.util.galaxyops import fail, parse_cols_arg, skipped | |
| 17 | 17 | 
| 18 assert sys.version_info[:2] >= ( 2, 4 ) | 18 assert sys.version_info[:2] >= ( 2, 4 ) | 
| 19 | 19 | 
| 20 | |
| 20 def main(): | 21 def main(): | 
| 21 upstream_pad = 0 | |
| 22 downstream_pad = 0 | |
| 23 | |
| 24 options, args = doc_optparse.parse( __doc__ ) | 22 options, args = doc_optparse.parse( __doc__ ) | 
| 25 try: | 23 try: | 
| 26 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 ) | 24 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 ) | 
| 27 chr_col_2, start_col_2, end_col_2, strand_col_2 = parse_cols_arg( options.cols2 ) | 25 chr_col_2, start_col_2, end_col_2, strand_col_2 = parse_cols_arg( options.cols2 ) | 
| 28 in_fname, in2_fname, out_fname = args | 26 in_fname, in2_fname, out_fname = args | 
| 29 except: | 27 except: | 
| 30 doc_optparse.exception() | 28 doc_optparse.exception() | 
| 31 | 29 | 
| 32 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), | 30 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), | 
| 43 fix_strand=True ) | 41 fix_strand=True ) | 
| 44 | 42 | 
| 45 out_file = open( out_fname, "w" ) | 43 out_file = open( out_fname, "w" ) | 
| 46 | 44 | 
| 47 try: | 45 try: | 
| 48 for line in coverage( [g1,g2] ): | 46 for line in coverage( [g1, g2] ): | 
| 49 if type( line ) is GenomicInterval: | 47 if type( line ) is GenomicInterval: | 
| 50 out_file.write( "%s\n" % "\t".join( line.fields ) ) | 48 out_file.write( "%s\n" % "\t".join( line.fields ) ) | 
| 51 else: | 49 else: | 
| 52 out_file.write( "%s\n" % line ) | 50 out_file.write( "%s\n" % line ) | 
| 53 except ParseError, exc: | 51 except ParseError, exc: | 
