0
$\begingroup$

I am trying to find a way to read and transcribe a list of DNA sequences (list of lists) only when the for loop finds a start codon (triplet of the list items) and until it finds a stop codon, over and over, but the if function will only transcribe the first codon and won't go through the whole sequence. I'm trying to do this with a mix of normal python and biopython functions cause I think it's simpler.

This is an example:

Start codon: ATG

Stop codon: TAG

gene_1= 'ACGGACTATTC'

gene_2= 'GGCCATGAGTAACGCATAGGGCCC

gene_3=GGGCCCATGACGTACTAGGGGCCCATGCATTCATAG

So, the first gene does not contain any transcript, whereas the second contains 1 and the third contains 2. I'm trying to get rid of everything outside these reading frames and append these transcripts into a list that should look something like this.

mRNAs = ['AGUAACGCA', 'ACGUAC', 'CAUUCA']

This is what I have so far:

genelist=[]

gene_1= 'A','C','G','G','A','C','T','A','T','T','C'
gene_2= 'G','G','C','C','A','T','G','A','G','T','A','A','C','G','C','A','T','A','G','G','G','C','C','C'
gene_3='G','G','G','C','C','C','A','T','G','A','C','G','T','A','C','T','A','G','G','G','G','C','C','C','A','T','G','C','A','T','T','C','A','T','A','G'

genelist.append(gene_1)
genelist.append(gene_2)
genelist.append(gene_3)

def transcription(ORF):
    mRNA= ''
    for i in range(0, len(ORF), 3):
        codon= ORF[i:i+3]
        if codon != 'ATG':
            next(codon)
            if codon == 'ATG':
                mRNA=codon.transcribe()
                if codon == 'TAG':
                    break
    return(mRNA)

mRNAs=[]
for gene in genelist:
    for codon in gene:
        mRNA= transcription(codon)
        mRNAs.append(mRNA)
print(mRNAs)

But it is not really giving anything back, I wonder if the code it's too redundant and I really don't need to define a function here, do you know any better way to do this? Thaaanks!!

$\endgroup$
5
  • $\begingroup$ There are a lot of issues with this code, some very basic Python mistakes such as forgetting quotes around ATG/TAG in your if statements, and looping through your genes per base, instead of per codon as your code seems to suggest you wish to. Try adding print statements to your code to see at which positions you are not getting expected results, and edit your code accordingly. $\endgroup$
    – Pallie
    Jul 31 '20 at 13:12
  • $\begingroup$ Is this a homework? If yes, you should mention it's a homework. If not, are you sure you want to do gene prediction like this? $\endgroup$
    – Kamil S Jaron
    Jul 31 '20 at 13:17
  • $\begingroup$ I agree, I forgot the quotes in the start-stop codons, however, the question goes more about the methodology used here, until now, I just managed to transcribe the start codon, but it wouldn't keep extracting the other codons. @KamilSJaron This is not a homework, it's just an example of what I want I'm trying to do here which is extract fragments within the start/stop frame $\endgroup$ Jul 31 '20 at 13:35
  • $\begingroup$ I bet my shoes this problem must have a reliable solution. What about ncbi.nlm.nih.gov/orffinder for example? $\endgroup$
    – Kamil S Jaron
    Jul 31 '20 at 15:31
  • $\begingroup$ Debugging 101: add print statements to see what you are actually processing. You are calling mRNA= transcription(codon). What is the value of codon? Isn't it a single base? Isn't your function expecting an array instead? have you even tried running this? Don't you get an error message? $\endgroup$
    – terdon
    Aug 1 '20 at 17:15
0
$\begingroup$

I'm afraid none of your code makes much sense. You have written a function that expects an array, and then you are passing it a single letter

for gene in genelist:
    for codon in gene:
        mRNA= transcription(codon)

Then, the function also doesn't make sense. What does next(codon) mean? How would your script know what a codon is or how to move to the next one? And your if codon == 'ATG': is within the if codon != 'ATG': block, so it will never be executed by definition.

I think what you are looking for is something like this, using the same basic approach as your script:

#!/bin/python3
from Bio.Seq import Seq
from Bio.Seq import transcribe 

genelist=[]

gene_1= 'A','C','G','G','A','C','T','A','T','T','C'
gene_2= 'G','G','C','C','A','T','G','A','G','T','A','A','C','G','C','A','T','A','G','G','G','C','C','C'
gene_3='G','G','G','C','C','C','A','T','G','A','C','G','T','A','C','T','A','G','G','G','G','C','C','C','A','T','G','C','A','T','T','C','A','T','A','G'

genelist.append(gene_1)
genelist.append(gene_2)
genelist.append(gene_3)

def transcription(ORF):
    mRNA= ''
    foundStart = False
    foundEnd = False
    for i in range(0, len(ORF), 3):
        codon= "".join(ORF[i:i+3])
        if codon == 'ATG' and not foundStart:
            foundStart = True
        if foundStart and not foundEnd:
            cc=transcribe(codon)
            mRNA = mRNA + transcribe(codon)
        if codon == 'TAG':
            foundEnd = True
       
    return(mRNA)

mRNAs=[]
for gene in genelist:
    mRNA = transcription(gene)
    mRNAs.append(mRNA)
print(mRNAs)

Which returns:

$ foo.py 
['', '', 'AUGACGUACUAG']

Of course, it only returns one mRNA since you only have one gene with an ORF in the 1st frame and your script was only looking at the forward strand and the first frame. In reality, ORFs can be in any of the 6 possible frames. You are also assuming that all ORFs will end with a TAG which is perhaps the case in the species you are working in? I don't remember if there is any genetic code that has TAG as the only stop.

If you do actually need to find ORFs in any frame, then I hope the script above should be enough to get you started.

$\endgroup$
2
  • $\begingroup$ @EdwinOrtegaArzola you're welcome, but please read the last paragraph. There are some serious issues with this approach and you shouldn't be using it for any real work. I strongly urge you to use an already existing tool for this instead of writing your own. $\endgroup$
    – terdon
    Aug 11 '20 at 13:42
  • $\begingroup$ This is precisely the structure and functions I was looking for!! I forgot about the True and False statements and they are extremely useful here! so Thank you! I agree on the ORFs issue, so, I will work later on the different reading frames, as for the stop codons I was really only using TAG as an example, I am actually including other stop condons in the code. Once, again thank you! $\endgroup$ Aug 11 '20 at 13:43
0
$\begingroup$

Just in case this isn't a homework problem, there are already plenty of programs available to do this. One program I use is getorf from the EMBOSS toolkit:

https://emboss.bioinformatics.nl/cgi-bin/emboss/getorf

$\endgroup$
1
  • $\begingroup$ Hello, this is not a homework problem but thank you for the link, I can use it to compare results! $\endgroup$ Aug 11 '20 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.