is made up of sugar, a phosphate group, and one of the four nitrogenous bases: adenine
Problem A. DNA: CG Pairs
DNA (Deoxyribonucleic Acid) is a molecule that encodes genetic blueprints for living
organisms. Understanding how it works is one of the fundamental pursuits of modern biology and genetics. Each strand of DNA is a chain of nucleotides. Each nucleotide is made up of sugar, a phosphate group, and one of the four nitrogenous bases: adenine (A), thymine (T), cytosine (C) and guanine (G). For this reason, a common way to represent a strand of DNA is by simply writing out the letters corresponding to the base that each nucleotide contains. For example, a small strand of DNA could be represented as:
dna_str = 'AGCTTTCATTCTGAC'(This is a very very short dna sequence, actual sequences are much longer. If you're interested in what a real DNA sequence looks like, check out the National Center for Biotechnology Information at the National Institute of Health. Here is the page that contains the first segment of the genome for a Burmese python.)
Vertebrates have a much lower density of CG pairs than would occur by chance, but they have a relatively high concentration near genes. Because of this, finding higher concentrations of CG pairs is a good way to find possible sites of genes.
Build a function cg_pairs(dna) that takes a string containing a dna strand as its argument and returns the fraction of dinucleotides (i.e. pairs of consecutive nucleotides) that are “cg” in that strand, without using the built-in count method. For example, the following dna strand has a cg_ratio of 0.25:
cg_pairs('accgttcgc')because it contains 8 dinucleotides (‘ac’, ‘cc’, ‘cg’, ‘gt’, ‘tt’, ‘tc’, ‘cg’, ‘gc’), and 2 of them are ‘cg’, so we get 2/8 = 0.25.
Examples (values in bold are returned, values in italics are printed) >>> cg_pairs('atcgttcg')
0.2857142857142857
>>> cg_pairs('ggGCg')
0.25
>>> cg_pairs('cGa')0.5
>>> cg_pairs('testing') Error in DNA strand0.0
>>> cg_pairs('gccGtTfa') Error in DNA strand0.0
Trending now
This is a popular solution!
Step by step
Solved in 2 steps