# Lab 2, Program 4
#
# Given a DNA sequence, find the percentages of nucleotides in the sequence
# that are A's, C's, T's, and G's.
#
# This program is based largely on Program 3.  In order to find the
# percentages, we need to count the A's, C's, T's, and G's, then divide
# each by the total number of nucleotides in the sequence.
#
# There are two things going on here that are new to us:
#
# * Because we want to divide by the length of the DNA sequence, it would
#   be handy if we could find its length.  There is a function in Python
#   called "len" (short for length), which figures out the length of a
#   sequence of things that you pass to it.  Since a string is a sequence
#   of characters, len tells you the number of characters in the string.
#
# * The counts (like aCount) and the length of the DNA sequence are both
#   integers.  If we divide one by the other, according to the rules of
#   Python, we get an integer as a result.  So, we have to tell Python
#   that we're interested in getting a decimal result.  Decimal numbers
#   in Python are called "floats" (short for "floating-point numbers,"
#   which alludes to the way that computers store them in memory).  If
#   we want to divide two integers, i and j, but get a decimal result, we
#   can do so by first converting one of them to a float; this tells
#   Python that decimal digits are important to us.  Here's how you can
#   do it:
#
#       float(i) / j
#
#   It makes no difference which one you convert, so long as you convert
#   at least one of them.

dnaSequence = "atcgatgagagctagcgata"

aCount = 0
cCount = 0
tCount = 0
gCount = 0

for c in dnaSequence:
    if c == 'a':
        aCount = aCount + 1
    elif c == 'c':
        cCount = cCount + 1
    elif c == 't':
        tCount = tCount + 1
    elif c == 'g':
        gCount = gCount + 1

sequenceLength = len(dnaSequence)

print "Percentage of A's in sequence:", (float(aCount) / sequenceLength) * 100
print "Percentage of C's in sequence:", (float(cCount) / sequenceLength) * 100
print "Percentage of T's in sequence:", (float(tCount) / sequenceLength) * 100
print "Percentage of G's in sequence:", (float(gCount) / sequenceLength) * 100

