How to find out the complementary strand of DNA using Python

How to find out the complementary strand of DNA using Python

What is a complementary strand?

DNA (deoxyribonucleic acid) is made up of pentose Sugar, nitrogenous bases, and phosphate. DNA has a backbone of sugar and phosphate. As we all know DNA is a double helical structure (Watson & crick model) and both the strand of DNA are complementary of each other.

So, what does it mean to be a complementary strand (cDNA)?

Suppose we have a DNA strand 5’ GGTACTTGCCAT 3’ for this strand of DNA the complementary strand is 3’ CCATGAACGGTA 5’. This is because we all know that there are 4 base pairs in DNA: Adenine (A), Guanine (G), Cytosine (C), and Thymine (T), these base pairs bonds together these bonds follow the lock and key principle.
in DNA A=T and G≡C (where A, G are purines and T, C are pyrimidines)

In the process of DNA Replication, both of the strands are unzipped by an enzyme named helicase and both of them serve as a template strand for new DNA (semiconservative nature of DNA).

IUPAC Degeneracies

Base Name Bases Represented Complementary Base
A Adenine A T
T Thymidine T A
U Uridine (in RNA) U A
G Guanidine G C
C Cytidine C G
Y pyrimidine C T R
R purine A G Y

 

Let’s see the methods for solving this:
Method 1: using the concept of if-elif-else conditional statements.
Below is the implementation:

# method 1:
# Define a function for finding
# complementary strand of given
# DNA strand
def complementary_strand_find(dna_strand):

    # empty string define
    complementary_strand = ""

    # looping through the
    # given DNA strand one
    # by one character at
    # a time 
    for base in dna_strand:

        # using if-elif-else
        # conditional statement
        if base == "A" :
            # string concatenation
            complementary_strand += "T"

        elif base == "T" :
            complementary_strand += "A"

        elif base == "U" :
            complementary_strand += "A"

        elif base == "G" :
            complementary_strand += "C"

        elif base == "C" :
            complementary_strand += "G"

        elif base == "Y" :
            complementary_strand += "R"

        elif base == "R" :
            complementary_strand += "Y"

        else :
            print("Wrong input")

            # assigning None to the variable
            # if wrong input is given 
            complementary_strand = None
            
            # break out of the loop
            # if wrong input is given
            break

    # return final result
    return complementary_strand

# main code
if __name__ == "__main__":

    # input the DNA strand
    dna_strand = "GGTACTTGCCAT"

    print("DNA strand is:",
          dna_strand)

    # function call and printing
    # the result
    print("complementary strand is:",
          complementary_strand_find(dna_strand))

Output:

DNA strand is: GGTACTTGCCAT
complementary strand is: CCATGAACGGTA

Method 2: Using the concept of Dictionary.
Below is the implementation:

# Define a function for finding
# complementary strand of given
# DNA strand
def complementary_strand_find(dna_strand):

    # create a dictionary for
    # storing conversion pairs
    conversion_dictionary = {
        "A" : "T",
        "T" : "A",
        "U" : "A",
        "G" : "C",
        "C" : "G",
        "Y" : "R",
        "R" : "Y"
        }

    # empty string define
    complementary_strand = ""

    # looping through the
    # given DNA strand one
    # by one character at
    # a time    
    for base in dna_strand:

        # checking base is present in
        # dictionary or not
        # if not then error input
        # is given
        if base in conversion_dictionary:
            
            # string concatenation
            complementary_strand += conversion_dictionary[base]
            
        else :
            print("Wrong input")

            # assigning None to the variable
            # if wrong input is given 
            complementary_strand = None
            
            # break out of the loop
            # if wrong input is given
            break

    # return final result
    return complementary_strand
     
# main code
if __name__ == "__main__":

    # input the DNA strand
    dna_strand = "GGTACTTGCCAT"

    print("DNA strand is:",
          dna_strand)

    # function call and printing
    # the result
    print("complementary strand is:",
          complementary_strand_find(dna_strand))

Output:

DNA strand is: GGTACTTGCCAT
complementary strand is: CCATGAACGGTA

8 Comments

  1. I thought it was gonna be some boring old publish, but it in truth paid out for my time. I will article a link to the page in my weblog. I am sure my personal guests will unearth that invaluable. . . .

  2. I guess you have made many really interesting points. Not as well many ppl would actually think about it the direction you just did. I am really impressed that there is so much about this subject that has been uncovered and you made it so nicely, with so considerably class. Top-notch one, man! Very special things right here.

  3. Thank you for that smart critique. Me & my neighbour were preparing to do some research about that. We received a very good book on that matter from our local library and most books exactly where not as influensive as your information. Im quite glad to see this kind of information which I was searching for a long time.

  4. I don’t even know the way I finished up right here, but I assumed this post used to be great. I do not recognize who you might be however definitely you are going to a well-known blogger if you arent already 😉 Cheers!

Leave a Reply

Your email address will not be published. Required fields are marked *

📢 Need further clarification or have any questions? Let's connect!

Connect 1:1 With Me: Schedule Call


If you have any doubts or would like to discuss anything related to this blog, feel free to reach out to me. I'm here to help! You can schedule a call by clicking on the above given link.
I'm looking forward to hearing from you and assisting you with any inquiries you may have. Your understanding and engagement are important to me!

This will close in 20 seconds