Question: '''Run this cell please''' import random def create_gene(n): '''Creates random DNA sequence of length n. Arguments: n: length of DNA sequence Result: returns DNA sequence
'''Run this cell please'''
import random
def create_gene(n):
'''Creates random DNA sequence of length n.
Arguments:
n: length of DNA sequence
Result:
returns DNA sequence
'''
return ''.join([random.choice('ATGC') for _ in range(n)])
def write_fasta(header,seq,fileout):
'''Writes a FASTA file.
Arguments:
header: FASTA header
seq: sequence
Result:
writes fasta file
'''
with open(fileout,'w') as outfile: #this is a context manager that opens and closes the file
outfile.write('{} '.format(header))
outfile.write('{} '.format(seq))
#create FASTA files
amount_of_files = 20
for num in range(amount_of_files):
header = '{} {}'.format('>gene',num+1)
filename = '{}_{}.fasta'.format('sequence',num+1)
random_gene = create_gene(random.randint(50,100))
write_fasta(header,random_gene,filename)
- how to create a function that counts the number of codons in each sequence from the FASTA files. Which fasta file has the sequence with the most occurances of ATG?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
