Created
August 6, 2014 09:51
-
-
Save peterjwest/e3aa3ce3e8e66d7a3a9b to your computer and use it in GitHub Desktop.
DNA python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
print '\nExample 1' | |
# Input DNA 1 | |
dna = "ACTGATCGATTACGTATAGTATTTGCTATCATACATATATATCGATGCGTTCAT" | |
print 'DNA:', dna | |
# Calculate AT count | |
A_count = dna.count("A") | |
T_count = dna.count("T") | |
AT_count = A_count + T_count | |
print 'AT count:', AT_count | |
dna_length = len(dna) | |
print 'DNA length:', dna_length | |
# Calculate AT content percentage | |
AT_content = AT_count / dna_length | |
print 'AT percentage:', AT_content * 100 | |
print '\nExample 2' | |
# Work out complement DNA | |
complement_dna_B = dna.replace("A", "B") | |
complement_dna_D = complement_dna_B.replace("C", "D") | |
complement_dna_E = complement_dna_D.replace("G", "C") | |
complement_dna_F = complement_dna_E.replace("T", "A") | |
complement_dna_G = complement_dna_F.replace("B", "T") | |
complement_dna = complement_dna_G.replace("D", "G") | |
print 'Complement DNA:', complement_dna | |
print '\nExample 3' | |
# Input DNA 2 | |
restriction_dna = "ACTGATCGATTACGTATAGTAGAATTCTATCATACATATATATCGATGCGTTCAT" | |
print 'DNA:', restriction_dna | |
restriction_position = restriction_dna.find("GAATTC") | |
fragment_size_1 = len(restriction_dna[0:restriction_position]) | |
cut_site = 1 | |
fragment_size_3 = fragment_size_1 + cut_site | |
print 'Fragment 1 size:', fragment_size_3 | |
total = len(restriction_dna) | |
print 'DNA length:', total | |
fragment_size_4 = total - fragment_size_3 | |
print 'Fragment 2 size:', fragment_size_4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment