Genetic sequence¶
A genetic sequence (DNA sequence) can be represented by a string with a sequence of capital letters A, C, G and T that represent nucleotides 1.
Save all functions into the same file named dna.py.
Write function
isdna()that takes a string (str), and returnsTrueif it is a DNA orFalseotherwise. See the following examples:>>> isdna('AAAGTCTGAC') True >>> isdna('AAAGTCXGAC') False
Note
More tests are provided in the
test-isdna.txtfile.Write function
similar_dna()that takes two strings (str) with the same length and with a dna each, and returns the percentage (float) of matching pairs with respect to the total length. A matching pair is a pair of nucleotides one in each sequence which are equal and at the same position. See the following examples:>>> round(similar_dna('AGTC', 'AATA'), 2) 50.0 >>> round(similar_dna('AGTCT', 'AGTCT'), 2) 100.0 >>> round(similar_dna('TTCCG', 'AATAA'), 2) 0.0 >>> round(similar_dna('AAGTCCTTGA', 'AGCTCCTGGA'), 2) 70.0 >>> round(similar_dna('TGCCGAATGGACTTG', 'GGATTCGAATCTTGC'), 2) 13.33
Note
More tests are provided in the
test-similar.txtfile.
Solution
A solution of these functions is provided in the
dna.py file.