Question

In: Computer Science

How do I count CAG number in DNA using python? please provide an example!

How do I count CAG number in DNA using python? please provide an example!

Solutions

Expert Solution

Code for count "CAG" in DNA sequence is as below. In case of any query, do comment.

#function to count CAG in DNA sequence

def count_CAG_In_DNA(dnaSequence):

   

    countOfCAG = 0

    #do-while loop to parse the while DNA sequence

    while True:

        #find the position of CAG in DNA sequence

        positionOfCAG = dnaSequence.find("CAG")

       

        #if no CAG found then break the loop

        if (positionOfCAG == -1):

            break

        #increment the count of CAG

        countOfCAG += 1

        #extract the new array,slicing array from the character till CAG is found

        dnaSequence = dnaSequence[positionOfCAG+3:]

    return countOfCAG

   

# main driver function

#output should be 2

dnaSequence = "TACAGCAGC"

print("Count of CAG in DNA Squence :" + dnaSequence)

print(count_CAG_In_DNA(dnaSequence))

#output should be 0

dnaSequence ="TACATCATC"

print("Count of CAG in DNA Squence :" + dnaSequence)

print(count_CAG_In_DNA(dnaSequence))

#output should be 6

dnaSequence = "TACAGCAGCTACAGCAGCTACAGCAGC"

print("Count of CAG in DNA Squence :" + dnaSequence)

print(count_CAG_In_DNA(dnaSequence))

#output should be 9

dnaSequence = "TACAGCAGCTACAGCAGCTACAGCAGCTACAGCAGCTACAGC"

print("Count of CAG in DNA Squence :" + dnaSequence)

print(count_CAG_In_DNA(dnaSequence))

#output should be 7

dnaSequence ="TACAGCAGCTACAGCTACAGCAGCTACAGCAGC"

print("Count of CAG in DNA Squence :" + dnaSequence)

print(count_CAG_In_DNA(dnaSequence))

#===========================================Screen shot of code ==============

Screen shot of the code for indentation:

Output:

Please rate your answer. Thanks


Related Solutions

how do you code a psuedo-random probability(%) in python? please provide an example.
how do you code a psuedo-random probability(%) in python? please provide an example.
How do I make a dictionary in Python language? Can somebody please provide me with an...
How do I make a dictionary in Python language? Can somebody please provide me with an example code of a Dictionary in Python Language? Thank you in advance.
How can I quanitfy DNA accurately without using a nanodrop? (Provide an equation)
How can I quanitfy DNA accurately without using a nanodrop? (Provide an equation)
How do I implement Image Processing using VHDL for FPGA? Please provide VHDL code
How do I implement Image Processing using VHDL for FPGA? Please provide VHDL code
Code using R or Python We observe from our campus the temperature and count the number...
Code using R or Python We observe from our campus the temperature and count the number of squirrels. Our observations are T = [52, 52, 50, 54, 50, 52, 54, 80, 80] Sq = [8, 10, 6, 9, 6, 12, 12, 1, 0] a) What is the covariance of these vectors? (1point) b) What is the covariance matrix? (1point) c) What is the correlation coefficient? (1point) d) Find the coefficient of determination? (1point) e) Can you make any statement or...
How do you calculate incidence for population health? Please provide an example
How do you calculate incidence for population health? Please provide an example
What are agency problems and how do they come about? Please provide an example of an...
What are agency problems and how do they come about? Please provide an example of an agency problem and show how it can be mitigated.
How do I write a script for this in python in REPL or atom, NOT python...
How do I write a script for this in python in REPL or atom, NOT python shell Consider the following simple “community” in Python . . . triangle = [ ["top", [0, 1]], ["bottom-left", [0, 0]], ["bottom-right", [2, 0]], ] This is the calling of function. >>> nearestneighbor([0, 0.6], triangle, myeuclidean) 'top' The new point is (0, 0.6) and the distance function is Euclidean. Now let’s confirm this result . . . >>> myeuclidean([0, 0.6], [0, 1]) 0.4 >>> myeuclidean([0,...
how do I make a histogram. I am using the example from the book Essentials of...
how do I make a histogram. I am using the example from the book Essentials of Statistics Chapter 2.2, Problem 9BSC.
Python. Write a code that asks the user to enter a string. Count the number of...
Python. Write a code that asks the user to enter a string. Count the number of different vowels ( a, e, i, o, u) that are in the string and print out the total. You may need to write 5 different if statements, one for each vowel. Enter a string: mouse mouse has 3 different vowels
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT