import math
#up_sticky_end is the up strand where the sequence is split
#bottom_sticky_end is the bottom strand where the sequence is split
def Calculate_distance(file_pdb,up_strand_list,bottom_strand_list,up_sticky_end,bottom_sticky_end):
file_pdb_data=open(file_pdb,'r')
lines_data=file_pdb_data.readlines()
file_pdb_data.close()
up_point_list=[]
bottom_point_list=[]
for i in range(0,len(up_strand_list)):
for line_data in lines_data:
line_data_list=line_data.split()
if up_strand_list[i]!=up_sticky_end:
if up_strand_list[i] in line_data_list[4:] and "P" in line_data_list[2:]:
up_point_list.append(line_data_list[-5:-2])
break
elif up_strand_list[i]==up_sticky_end:
if up_strand_list[i] in line_data_list[4:] and "O5'" in line_data_list[2:]:
up_point_list.append(line_data_list[-5:-2])
break
for j in range(0,len(bottom_strand_list)):
for line_data in lines_data:
line_data_list=line_data.split()
if bottom_strand_list[j]!=bottom_sticky_end:
if bottom_strand_list[j] in line_data_list[4:] and "P" in line_data_list[2:]:
bottom_point_list.append(line_data_list[-5:-2])
break
elif bottom_strand_list[j]==bottom_sticky_end:
if bottom_strand_list[j] in line_data_list[4:] and "O5'" in line_data_list[2:]:
bottom_point_list.append(line_data_list[-5:-2])
break
print up_point_list[1:],bottom_point_list[:-1]
return up_point_list[1:],bottom_point_list[:-1]
def distance(list1,list2,i):
x_avg=(float(list1[i][0])+float(list2[i][0]))/2
y_avg=(float(list1[i][1])+float(list2[i][1]))/2
z_avg=(float(list1[i][2])+float(list2[i][2]))/2
return x_avg,y_avg,z_avg
def extract_resdue_list(file):
resdue_file=open(file,"r")
all_resdue_list=[]
for line in resdue_file.readlines():
line_list=line.split()[1:]
all_resdue_list.append(line_list)
resdue_file.close()
return all_resdue_list
if __name__=="__main__":
#resdue_lists=extract_resdue_list("sequence.txt")
#The following is the test data
L1=["756","757","530"]
L2=["52","12","11"]
list_one,list_two=Calculate_distance("0.pdb",L1,L2,"93","-1")
distance(list_one,list_two)