Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:36:39+00:00 2026-06-11T17:36:39+00:00

I am posting a follow-up question to a previous question I had regarding reading

  • 0

I am posting a follow-up question to a previous question I had regarding reading frames.

sequence = 'AAATGAAATAAGGATGGGGTAGTATGATGTGTTT'

I am ultimately looking for a specific pattern ‘ATG’ and I want to scan the input sequence until it is found. Once it is found, I want it to proceed with a reading frame of 3 until it finds another sequence either ‘TAA’ or ‘TAG’ or ‘TGT’ and then continue scanning until it finds the next ‘ATG’ with a downstream ‘TAA’ or ‘TAG’ or ‘TGT’

codon_list = ['ATG','AAA','TAA'],['ATG','GGG','TAG'],['ATG','ATG','TGT']

I was trying this

start_frame = sequence.find('ATG')

but it would only give me the first occurence of ‘ATG’. (i.e. ‘2’)

Just for the first list of codons I wrote

for codon in range(len(sequence)):
    next_codon = fdna[start_frame:start_frame + 3]
    codon_list.append(next_codon)
    start_frame = start_frame + 3
    if next_codon == 'TAA': 
        break
    if next_codon == 'TAG':
        break
    elif next_codon=='TGT':
        break
print codon_list
>>> ['ATG','AAA','TAA']

It only works for the first occurence of ‘ATG’.

The next part is where I want to create a name for each codon (0,1,2,3,…) and I think I figured that part out:

indx = range(0,len(codon_list))

indx_codon = dict(zip(indx,codon_list)

indx_codon = {0:['ATG','AAA','TAA'],1:['ATG','GGG','TAG'],2:['ATG','ATG','TGT']}

codon_start = ['2','13','23']
codon_end = ['8','21','31']
codon_positions = []

for p,q in zip(codon_start,codon_end):
    codon_positions.append(str(p)+':'+str(q))

print codon_positions
>>> ['2:8', '13:21', '23:31']

So my biggest problem is that the .find() function only works for the first occurrence and it gets messed up when I’m creating the index if there is a ‘TAA’ or ‘TAG’ or ‘TGT’ before the ‘ATG’ (‘ATG’ is the one that is supposed to start the reading frame of 3)

How can I create a list of multiple sequences that follow these criteria (i.e. turn sequence into codon_list)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:36:40+00:00Added an answer on June 11, 2026 at 5:36 pm

    Here is a fairly concise solution using regular expressions:

    import re
    sequence = 'AAATGAAATAAGGATGGGGTAGTATGATGTGTTT'
    codons = re.findall(r'ATG(?:...)*?(?:TAA|TAG|TGT)', sequence)
    codon_list = [[s[i:i+3] for i in range(0, len(s), 3)] for s in codons]
    

    Result:

    >>> codon_list
    [['ATG', 'AAA', 'TAA'], ['ATG', 'GGG', 'TAG'], ['ATG', 'ATG', 'TGT']]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am posting this question after reading other similar questions about my problem but
This is a follow up to a previous question: Disparity between date/time calculations in
note: this is a direct follow up to this previous question I have very
This is a follow-up question to 1832203. I'm making it a new question as
This is somewhat of a follow up to a question posted earlier last month.
This is the first time I am posting a question on stackoverflow, so please
Drawing a blank with finalizing my deploy scheme here. After posting this question: Migrating
This is the follow up question to the question I already asked. It was
I'm developing an application in Silverlight2 and trying to follow the Model-View-ViewModel pattern. I
I follow this link https://github.com/RestKit/RestKit/wiki/Posting-NSDictionary-as-JSON to create the json post, and get back json

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.