-
Notifications
You must be signed in to change notification settings - Fork 0
/
wwindows.py
44 lines (44 loc) · 1.51 KB
/
wwindows.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sys
mul=int(sys.argv[1])
pref=sys.argv[2]
for fn in sys.argv[3:]:
SampleName=fn.split("\\")[-1].split("/")[-1][:-4]
print("transforming %s..."%fn,file=sys.stderr)
nfn="%s/%s%s.rdf"%(pref,mul,SampleName)
nf=open(nfn,"w")
first=True
with open(fn,"r") as ifile:
ConI=0
data=0
for line in ifile:
if line[0]=="#":
if line[1]=="#":
if not first:
print("\n",end="",file=nf)
first=False
sl=line[2:].split(":")
if sl[1]=="WindowSize":
OWS=int(sl[2])
print("##WindowSize:%s"%(OWS*mul),end="",file=nf)
continue
print(line.strip(),end="",file=nf)
continue
if ConI%mul!=0:
print("\n%s"%(data),end="",file=nf)
chrname=line[1:].split()[0]
length=int(line[1:].split()[1])
newl=int(length/mul)+(1 if length%mul!=0 else 0)
if not first:
print("\n",end="",file=nf)
first=False
print("#%s %s"%(chrname,newl),end="",file=nf)
data=0
ConI=0
continue
data+=int(line)
ConI+=1
if ConI%mul==0:
print("\n%s"%(data),end="",file=nf)
data=0
if ConI%mul!=0:
print("\n%s"%(data),end="",file=nf)