annotate makewindow.py @ 12:2f4ea569f048

Uploaded
author xuebing
date Sat, 10 Mar 2012 08:10:44 -0500
parents b7f1d9f8f3bc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
1 def makeWindow(filename,outfile,window):
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
2 window = window/2
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
3 f=open(filename)
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
4 out = open(outfile,'w')
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
5 for line in f:
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
6 flds = line.strip().split()
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
7 #new position
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
8 center = (int(flds[1]) + int(flds[2]))/2
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
9 start = center - window
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
10 end = center + window
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
11 if start >= 0:
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
12 flds[1] = str(start)
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
13 flds[2] = str(end)
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
14 out.write('\t'.join(flds)+'\n')
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
15 f.close()
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
16 out.close()
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
17
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
18 import sys
b7f1d9f8f3bc Uploaded
xuebing
parents:
diff changeset
19 makeWindow(sys.argv[1],sys.argv[2],int(sys.argv[3]))