Hello readers we are back with another interesting post. This post is based on coding in Python. Hope all are doing well and safe. Explore all the contents of our blog and support us.

In this post we are going to find number of genes in a given DNA combination using a simple python program.

What is a DNA?





A self-replicating material which is present in nearly all living organisms as the main constituent of chromosomes. It is the carrier of genetic information.

Here we are not going to find the DNA combination of person using python we are just going to find the number of genes in  given DNA combination.

Example for a DNA combination:

AATTATGAGCCTATCGGCATAAGCCATGCATTGCAG

Here "A",  "T",  "C",  "G" represent the nucleotides, the whole DNA is made up of such nucleotides . Their combination is different for different humans. The above mentioned is just an example combination. There will be million such combinations in a DNA.

How to find a Gene?

A gene normally starts with "ATG" and ends with "TAA". Speaking in terms of a programming language a gene is a string which starts with "ATG" and ends with "TAA". We count the number of such strings to find the number of genes.

ATCGGGCATGGGCATCGGCTAGGCATTGTAAATCATGTTCCGATCTAAGCAGCA



In the above combination the highlighted string represent a gene. The highlighted are the strings starting with "ATG" and ending "TAA" . From a large number of combinations we are going to pick out such strings and display and count them.


Python code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
dna="ATCGGGCATGGGCATCGGCTAGGCATTGTAAATCATGTTCCGATCTAAGCAGCA"
i=0
l=[]
s=""

while(i<=len(dna)-3):
    
    if dna[i]=="A" and dna[i+1]=="T" and dna[i+2]=="G":
        s+="ATG"
        i+=3
        while(True):
            if dna[i]=="T" and dna[i+1]=="A" and dna[i+2]=="A":
                s+="TAA"
                i+=3
                l.append(s)
                s=""
                break
            
            else:
                s+=dna[i]
                i+=1
    else:
        i+=1
li=[l[i] for i in range(len(l)) if len(l[i])>60]
print(l)
            
        


Many would think that the program would be very complex but it is not complex as everyone think and using python made it more simple.

What we are going to do is that we are going to find the genes in the huge combination and append them into a list and count them.

We store the DNA combination is a variable called dna for reference. You can add your own combination. Variable "i" is assigned to 0 and an empty list is created to store the genes and an empty string is created. 

First step to be done is to iterate through the string upto "length of string-3" as "ATG" and "TAA" has length of 3 and iterating upto "length of string-3" will work. If  and only if the first three characters are "ATG" then we will add it to the empty string and increment "i" by 3.  otherwise the "i" is incremented by 1.

Inside it another while loop is created, If the string "TAA" is found , "i" is incremented by 3 and "TAA" is added to the string and the string is appended into the list and it is made empty to store other genes in the combination and break the inner while loop.

If end is not encountered we will simply add the character to the string and increment "i" by  1. If the string "ATG" is not encountered the i value will be incrementing by 1. The inner while loop works if and only if a starting string "ATG" is found.


Thanks for Reading. Keep visiting!!!

 

Post a Comment

Previous Post Next Post