gravatar for annushreekurmi

3 hours ago by

Hello everyone,

I am a novice in Python and I have been trying to compute the number of A's occurring in 3rd codon position in a multifasta file. I have written the following code but it does not work.

input_file = open('MG1655.FAS', 'r')
output_file = open('A3_counts.tsv','w')
output_file.write('GenetA3n')
from Bio import SeqIO
for cur_record in SeqIO.parse(input_file, "fasta") :
      A3count = 0
      gene_name = cur_record.name
      sequence = cur_record.seq
      for i in range(0, len(sequence), 3):
             if sequence[i:i+3]=='a':
                     A3count = A3count+1
                     output = '%st%it' % (gene_name, A3count)
                     output_file.write(output)
output_file.close()
input_file.close()

Please help me with this problem.



Source link