I have a BLAST output file and want to calculate query coverage, appending the query lengths as an additional column to the output. Let's say I have
2 7 15
f=open('file.txt', 'r')
lines=f.readlines()
import re
for line in lines:
new_list=re.split(r'\t+',line.strip())
q_start=new_list[0]
q_end=new_list[1]
q_len=new_list[3]
q_cov=((float(q_end)-float(q_start))/float(q_len))*100
q_cov=round(q_cov,1)
q_cov=str(q_cov)
new_list.append(q_cov)
r=open('results.txt', 'a')
x='\t'.join(new_list)
x=x+'\n'
r.writelines(x)
f.close()
r.close()