diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/resize_coordinate_window.py	Tue Jan 19 09:34:56 2016 -0500
@@ -0,0 +1,41 @@
+import argparse
+import sys
+
+
+def stop_err( msg ):
+    sys.stderr.write( msg )
+    sys.exit(1)
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--input', dest='input', help="Input dataset")
+parser.add_argument('--subtract_from_start', dest='subtract_from_start', type=int, help='Distance to subtract from start.')
+parser.add_argument('--add_to_end', dest='add_to_end', type=int, help='Distance to add to end.')
+parser.add_argument('--extend_existing', dest='extend_existing', help='Extend existing start/end rather or from computed midpoint.')
+parser.add_argument('--output', dest='output', help="Output dataset")
+args = parser.parse_args()
+
+extend_existing = args.extend_existing == 'existing'
+out = open(args.output, 'wb')
+
+for line in open(args.input):
+    if line.startswith('#'):
+        continue
+    items = line.split('\t')
+    if len(items) != 9:
+        continue
+    start = int(items[3])
+    end = int(items[4])
+    if extend_existing:
+        start -= args.subtract_from_start
+        end += args.add_to_end
+    else:
+        midpoint = (start + end) // 2
+        start = midpoint - args.subtract_from_start
+        end = midpoint + args.add_to_end
+    if start < 1:
+        out.close()
+        stop_err('Requested expansion places region beyond chromosome bounds.')
+    new_line = '\t'.join([items[0], items[1], items[2], str(start), str(end), items[5], items[6], items[7], items[8]])
+    out.write(new_line)
+out.close()
+