annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
1 import argparse
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
2 import sys
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
3
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
4
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
5 def stop_err( msg ):
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
6 sys.stderr.write( msg )
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
7 sys.exit(1)
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
8
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
9 parser = argparse.ArgumentParser()
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
10 parser.add_argument('--input', dest='input', help="Input dataset")
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
11 parser.add_argument('--subtract_from_start', dest='subtract_from_start', type=int, help='Distance to subtract from start.')
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
12 parser.add_argument('--add_to_end', dest='add_to_end', type=int, help='Distance to add to end.')
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
13 parser.add_argument('--extend_existing', dest='extend_existing', help='Extend existing start/end rather or from computed midpoint.')
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
14 parser.add_argument('--output', dest='output', help="Output dataset")
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
15 args = parser.parse_args()
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
16
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
17 extend_existing = args.extend_existing == 'existing'
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
18 out = open(args.output, 'wb')
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
19
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
20 for line in open(args.input):
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
21 if line.startswith('#'):
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
22 continue
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
23 items = line.split('\t')
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
24 if len(items) != 9:
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
25 continue
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
26 start = int(items[3])
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
27 end = int(items[4])
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
28 if extend_existing:
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
29 start -= args.subtract_from_start
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
30 end += args.add_to_end
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
31 else:
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
32 midpoint = (start + end) // 2
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
33 start = midpoint - args.subtract_from_start
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
34 end = midpoint + args.add_to_end
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
35 if start < 1:
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
36 out.close()
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
37 stop_err('Requested expansion places region beyond chromosome bounds.')
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
38 new_line = '\t'.join([items[0], items[1], items[2], str(start), str(end), items[5], items[6], items[7], items[8]])
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
39 out.write(new_line)
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
40 out.close()
08b6255afde7 planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/resize_coordinate_window commit b'67cff25a50ba173b0468819204d0999496f68ea9'
iuc
parents:
diff changeset
41