Python: Clean up and translate nucleotide sequences

[If you are more familiar with biology than with Python or computer programming, I highly recommend this book .]

[Note: A lot of you are finding this post through Google searches. Let me know in the comments if you found it helpful and, if not, what it was you were looking for!]

Some simple, hopefully useful, and totally non-optimized functions for working with nucleotide sequence data (note that there are many more tools as part of the biopython distribution, if you’re interested in learning the library) :

First, for cleaning up a sequence (preferably in FASTA format):

def clean_sequence( sequence ):
    """Given a sequence string, return a crap-free, standardized DNA version."""
    s = sequence.replace( '\r', '' ).split( '\n' )  # separate each line
    if s[0][0] == '>': s = s[ 1 :]                  # remove defline
    s = ''.join( s )                                # make one long string
    s = s.replace( ' ', '' ).replace( '\t', '' )    # remove spaces
    return s.upper().replace( 'U', 'T' )

Then, a function to let you know if there are characters in your sequence that shouldn’t be:

def report_bad_chars( sequence ):
    """Given a string 'sequence', return a dictionary of any non-AGCT characters."""
    bad_chars = {}
    for l in sequence:
        if l not in 'AGCT':
            if l in bad_chars: bad_chars[ l ] += 1
            else: bad_chars[ l ] = 1
    if bad_chars != {}: print( bad_chars )

After the jump, functions for translation, calculating amino acid and nucleotide frequencies, and making random DNA sequences.

Continue reading

tRNA pun

I thought of this one day while brushing my teeth. The images make it easier, but this was the original joke:

So one tRNA diffuses up to another and says, “It is frigid in here!” The other tRNA responds, “Well, then go get your codon.”

Read it out loud to get the joke. It isn’t that funny, sadly, but it made me laugh when I thought of it.

The specific tRNA in the image is yeast Phenylalanine tRNA, which I got from RCSB. The number is 1ehz. I used pyMOL to orient and take the images, and then GIMP to add in speech bubbles.

Evolution Confusion [2]

Continued…

The key to understanding how one can figure the origin of the universe is in origin science. Evolution is origin science, which is science that tries to explain the origins of the earth through studying written history and physical evidence from ancient past.

Evolution does not try to explain the origin of the earth. It tries to explain the origin of biodiversity.

Operational science includes the discovery of information through experiments that are done today. Evolutionists have tried to prove evolution through operational science, like in Miller’s experiment (Ham and Mortenson 24).

Again, this type of experiment only supports specific hypotheses, not the theory of evolution. But otherwise you are correct; scientists have tried to prove evolution through “operational science.” And have been successful (look into evolution of pesticide and antibiotic resistance). Probably the greatest and most obvious example of all, however, is dog breeding. This is essentially a grand experiment done over thousands of years that has brought the original wolf ancestor to exist as one species with forms as diverse as a chihuahua and great dane. And this experiment wasn’t even done on purpose!

Which probably requires that I add this note: natural and “artificial” selection are the same thing. We call it artificial when it is done by people. So “natural” selection is when the environment selects for/against certain traits, and “artificial” selection is when the environment that does the selecting is controlled by people (in other words, an experiment).

Evolutionists claim that evolution can be seen in modern society, but this “evolution” that we see is mutations—a loss of genetic information, rather than a gain in genetic information that evolution requires (25).

Continue reading