Question

step by step using python According to Wikipedia, "In genetics, a sequence motif is a nucleotide...

step by step using python

According to Wikipedia, "In genetics, a sequence motif is a nucleotide or amino-acid sequence pattern that is widespread and has, or is conjectured to have a biological significance." A very simple motif might be a fixed stretch of DNA, e.g., ATCGATC. Write a program that will ask for two inputs: (1) a DNA sequence, and (2) a motif, and have the program report all of the positions (indices) within the sequence where the motif is found. The positions should all be reported on one line, separated by commas.

Example:

Input sequence: CCATCGATCGATCTCGATTCGATCGATCCCTGCG

Motif: ATCGATC

Motif found at positions: 2, 6, 21

Homework Answers

Answer #1

Look at my code and in case of indentation issues check the screenshots.

----------------main.py---------------


def main():
   dna_sequence = input("Input sequence: ")   #get input DNA sequence from user
   motif = input("Motif: ")                   #get motif input from user
   motif_positions = []                       #list to store motif positions
   i = 0                                       #start index from 0, search motif at every index
   while i < len(dna_sequence):               #loop until we reach end of the dna_sequence
       if dna_sequence[i : i+len(motif)] == motif:       #slice the dna_sequence at the ith index, and check if it is matching motif
           motif_positions.append(i)                   #if it matches, then add i to the motif_positions
       i = i+1                                   #move to next index

   print("Motif found at positions: ", end = "")
   for pos in motif_positions:                   #print all the motif positions separated by commas
       print(str(pos), end = ", ")
   print()


main()

----------Screenshots--------------

----------Output--------------

----------------------------------------------

Do comment if you need any clarification.
Please let me know if you are facing any issues.
Please Rate the answer if it helped.

Thankyou

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions