Mercurial > repos > iuc > resize_coordinate_window
comparison resize_coordinate_window.py @ 0:08b6255afde7 draft
planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
author | iuc |
---|---|
date | Tue, 19 Jan 2016 09:34:56 -0500 |
parents | |
children | 0164d2edba9f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:08b6255afde7 |
---|---|
1 import argparse | |
2 import sys | |
3 | |
4 | |
5 def stop_err( msg ): | |
6 sys.stderr.write( msg ) | |
7 sys.exit(1) | |
8 | |
9 parser = argparse.ArgumentParser() | |
10 parser.add_argument('--input', dest='input', help="Input dataset") | |
11 parser.add_argument('--subtract_from_start', dest='subtract_from_start', type=int, help='Distance to subtract from start.') | |
12 parser.add_argument('--add_to_end', dest='add_to_end', type=int, help='Distance to add to end.') | |
13 parser.add_argument('--extend_existing', dest='extend_existing', help='Extend existing start/end rather or from computed midpoint.') | |
14 parser.add_argument('--output', dest='output', help="Output dataset") | |
15 args = parser.parse_args() | |
16 | |
17 extend_existing = args.extend_existing == 'existing' | |
18 out = open(args.output, 'wb') | |
19 | |
20 for line in open(args.input): | |
21 if line.startswith('#'): | |
22 continue | |
23 items = line.split('\t') | |
24 if len(items) != 9: | |
25 continue | |
26 start = int(items[3]) | |
27 end = int(items[4]) | |
28 if extend_existing: | |
29 start -= args.subtract_from_start | |
30 end += args.add_to_end | |
31 else: | |
32 midpoint = (start + end) // 2 | |
33 start = midpoint - args.subtract_from_start | |
34 end = midpoint + args.add_to_end | |
35 if start < 1: | |
36 out.close() | |
37 stop_err('Requested expansion places region beyond chromosome bounds.') | |
38 new_line = '\t'.join([items[0], items[1], items[2], str(start), str(end), items[5], items[6], items[7], items[8]]) | |
39 out.write(new_line) | |
40 out.close() | |
41 |