comparison get_flanks.py @ 4:077f404ae1bb draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tool_collections/gops/get_flanks commit cae3e05d02e60f595bb8b6d77a84f030e9bd1689
author devteam
date Thu, 22 Jun 2017 18:41:29 -0400
parents 4cd116158aef
children
comparison
equal deleted inserted replaced
3:4cd116158aef 4:077f404ae1bb
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 #Done by: Guru 2 # Done by: Guru
3
4 """ 3 """
5 Get Flanking regions. 4 Get Flanking regions.
6 5
7 usage: %prog input out_file size direction region 6 usage: %prog input out_file size direction region
8 -l, --cols=N,N,N,N: Columns for chrom, start, end, strand in file 7 -l, --cols=N,N,N,N: Columns for chrom, start, end, strand in file
9 -o, --off=N: Offset 8 -o, --off=N: Offset
10 """ 9 """
10 from __future__ import print_function
11 11
12 import sys 12 import sys
13
13 from bx.cookbook import doc_optparse 14 from bx.cookbook import doc_optparse
14 from galaxy.tools.util.galaxyops import parse_cols_arg 15 from galaxy.tools.util.galaxyops import parse_cols_arg
15 16
16 17
17 def stop_err( msg ): 18 def stop_err( msg ):
52 line = line.strip() 53 line = line.strip()
53 if line and (not line.startswith( '#' )) and line != '': 54 if line and (not line.startswith( '#' )) and line != '':
54 j += 1 55 j += 1
55 try: 56 try:
56 elems = line.split('\t') 57 elems = line.split('\t')
57 #if the start and/or end columns are not numbers, skip that line. 58 # if the start and/or end columns are not numbers, skip that line.
58 assert int(elems[start_col_1]) 59 assert int(elems[start_col_1])
59 assert int(elems[end_col_1]) 60 assert int(elems[end_col_1])
60 if strand_col_1 != -1: 61 if strand_col_1 != -1:
61 strand = elems[strand_col_1] 62 strand = elems[strand_col_1]
62 #if the stand value is not + or -, skip that line. 63 # if the stand value is not + or -, skip that line.
63 assert strand in ['+', '-'] 64 assert strand in ['+', '-']
64 if direction == 'Upstream': 65 if direction == 'Upstream':
65 if strand == '+': 66 if strand == '+':
66 if region == 'end': 67 if region == 'end':
67 elems[end_col_1] = str(int(elems[end_col_1]) + offset) 68 elems[end_col_1] = str(int(elems[end_col_1]) + offset)
182 fo.close() 183 fo.close()
183 184
184 if skipped_lines == j: 185 if skipped_lines == j:
185 stop_err( "Data issue: click the pencil icon in the history item to correct the metadata attributes." ) 186 stop_err( "Data issue: click the pencil icon in the history item to correct the metadata attributes." )
186 if skipped_lines > 0: 187 if skipped_lines > 0:
187 print 'Skipped %d invalid lines starting with #%dL "%s"' % ( skipped_lines, first_invalid_line, invalid_line ) 188 print('Skipped %d invalid lines starting with #%dL "%s"' % ( skipped_lines, first_invalid_line, invalid_line ))
188 print 'Location: %s, Region: %s, Flank-length: %d, Offset: %d ' % ( direction, region, size, offset ) 189 print('Location: %s, Region: %s, Flank-length: %d, Offset: %d ' % ( direction, region, size, offset ))
190
189 191
190 if __name__ == "__main__": 192 if __name__ == "__main__":
191 main() 193 main()