I read multiple files using for-loop and append output in separate files using the below code. what I am looking for is not to print the line after the count+=1 (pls see below) every time for each iteration except the final iteration.
output.write(file_name + ": The total number of reads with two AB sequences is " +
str(count) + '\n')
Is there a way to print the final count+=1 only once at the end of the output file based on my code?
from Bio import SeqIO
files=['2_.fasta','4_.fasta']
for file_name in files:
count=0
with open(file_name,'r') as f:
for record in SeqIO.parse(f,'fasta'):
#some code
if str(v1) in record.seq and str(v2) in record.seq:
#some code
out = "sample" + file_name[:1] + "_two_AB.txt"
with open(out,'a') as output:
output.write(file_name + '\n')
output.write(">"+str(record.id) + '\n')
count+=1
output.write(file_name + ": The total number of reads with two AB sequences is "
+ str(count) + '\n')
output.close()