Mercurial > repos > devteam > merge
comparison gops_merge.py @ 3:b9c97d3233bb draft
planemo upload commit 33927a87ba2eee9bf0ecdd376a66241b17b3d734
| author | devteam | 
|---|---|
| date | Tue, 13 Oct 2015 12:51:07 -0400 | 
| parents | 10ac6097acdb | 
| children | dfbbc0291b36 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 2:1e9d95cae35f | 3:b9c97d3233bb | 
|---|---|
| 5 usage: %prog in_file out_file | 5 usage: %prog in_file out_file | 
| 6 -1, --cols1=N,N,N,N: Columns for start, end, strand in first file | 6 -1, --cols1=N,N,N,N: Columns for start, end, strand in first file | 
| 7 -m, --mincols=N: Require this much overlap (default 1bp) | 7 -m, --mincols=N: Require this much overlap (default 1bp) | 
| 8 -3, --threecol: Output 3 column bed | 8 -3, --threecol: Output 3 column bed | 
| 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.merge import merge | 
| 14 from bx.intervals.operations.merge 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 mincols = 1 | 22 mincols = 1 | 
| 22 upstream_pad = 0 | |
| 23 downstream_pad = 0 | |
| 24 | 23 | 
| 25 options, args = doc_optparse.parse( __doc__ ) | 24 options, args = doc_optparse.parse( __doc__ ) | 
| 26 try: | 25 try: | 
| 27 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 ) | 26 chr_col_1, start_col_1, end_col_1, strand_col_1 = parse_cols_arg( options.cols1 ) | 
| 28 if options.mincols: mincols = int( options.mincols ) | 27 if options.mincols: | 
| 28 mincols = int( options.mincols ) | |
| 29 in_fname, out_fname = args | 29 in_fname, out_fname = args | 
| 30 except: | 30 except: | 
| 31 doc_optparse.exception() | 31 doc_optparse.exception() | 
| 32 | 32 | 
| 33 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), | 33 g1 = NiceReaderWrapper( fileinput.FileInput( in_fname ), | 
| 34 chrom_col=chr_col_1, | 34 chrom_col=chr_col_1, | 
| 35 start_col=start_col_1, | 35 start_col=start_col_1, | 
| 36 end_col=end_col_1, | 36 end_col=end_col_1, | 
| 37 strand_col = strand_col_1, | 37 strand_col=strand_col_1, | 
| 38 fix_strand=True ) | 38 fix_strand=True ) | 
| 39 | 39 | 
| 40 out_file = open( out_fname, "w" ) | 40 out_file = open( out_fname, "w" ) | 
| 41 | 41 | 
| 42 try: | 42 try: | 
| 43 for line in merge(g1,mincols=mincols): | 43 for line in merge(g1, mincols=mincols): | 
| 44 if options.threecol: | 44 if options.threecol: | 
| 45 if type( line ) is GenomicInterval: | 45 if type( line ) is GenomicInterval: | 
| 46 out_file.write( "%s\t%s\t%s\n" % ( line.chrom, str( line.startCol ), str( line.endCol ) ) ) | 46 out_file.write( "%s\t%s\t%s\n" % ( line.chrom, str( line.startCol ), str( line.endCol ) ) ) | 
| 47 elif type( line ) is list: | 47 elif type( line ) is list: | 
| 48 out_file.write( "%s\t%s\t%s\n" % ( line[chr_col_1], str( line[start_col_1] ), str( line[end_col_1] ) ) ) | 48 out_file.write( "%s\t%s\t%s\n" % ( line[chr_col_1], str( line[start_col_1] ), str( line[end_col_1] ) ) ) | 
