||
##file为bed文件:chr,start,end file1为10条染色体的cM数据:position,cM
import os,sys
import bisect
for file in os.listdir("/share/xulab_10t/lxl/IBD_20141224_recobination"):
if file.endswith("_trop_trop.bed"):
file1=file.replace("_trop_trop.bed",".raw.sort")
file2=file.replace("bed","cM")
inf1=open(file,"r")
inf2=open(file1,"r")
ouf=open(file2,"w")
d={}
for line in inf2:
L=line.strip().split()
d[int(float(L[1]))]=float(L[0])
sd=[(k,d[k]) for k in sorted(d.keys())]
#print sd[0:20]
sd_key=map(lambda x:x[0],sd)
print sd[0:20],sd_key[0:20]
for line in inf1:
b=line.strip().split()
start=int(b[1])
end=int(b[2])
start_key= min(sd_key, key=lambda x:abs(x-start))
end_key=min(sd_key, key=lambda x:abs(x-end))
#print start_key,end_key
ouf.write("%st%st%st%st%sn" % (b[0],b[1],b[2], d[start_key] ,d[end_key]))
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-19 15:36
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社