Showing posts with label biopython. Show all posts
Showing posts with label biopython. Show all posts

Thursday, March 28, 2013

Two different ways to translate mRNA to Protein


from Bio.Seq import Seq
from Bio.Alphabet import IUPAC


def translate(mRNA):
    '''(str) -> str

    input is mRNA string and it returns a the corresponding protein string.

    >>>translate('AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA')
    MAMPRTEINSTRING

    Precondition: mRNA has to be Uppercase and include only GAUC
   
    '''
    #IUPAC.unambiguous_rna includes only Uppercase and GAUC
    messenger_rna = Seq(mRNA, IUPAC.unambiguous_rna)
    #translate using a dict already stored in the method
    protein = messenger_rna.translate()

    print protein


--------------------------------------------

def translate_2(mRNA):
    '''(str) -> str

    input is mRNA string and it returns a the corresponding protein string.

    >>>translate('AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA')
    MAMPRTEINSTRING
   
    '''
    #this string will be used to make a dict
    translation_table = '''UUU F      CUU L      AUU I      GUU V
    UUC F      CUC L      AUC I      GUC V
    UUA L      CUA L      AUA I      GUA V
    UUG L      CUG L      AUG M      GUG V
    UCU S      CCU P      ACU T      GCU A
    UCC S      CCC P      ACC T      GCC A
    UCA S      CCA P      ACA T      GCA A
    UCG S      CCG P      ACG T      GCG A
    UAU Y      CAU H      AAU N      GAU D
    UAC Y      CAC H      AAC N      GAC D
    UAA Stop   CAA Q      AAA K      GAA E
    UAG Stop   CAG Q      AAG K      GAG E
    UGU C      CGU R      AGU S      GGU G
    UGC C      CGC R      AGC S      GGC G
    UGA Stop   CGA R      AGA R      GGA G
    UGG W      CGG R      AGG R      GGG G'''

    #Make a list of the above string and remove all spaces or '/n
    translation_list =  translation_table.split()
    #Make dictionary from list
    translation_dict = dict(zip(translation_list[0::2], translation_list[1::2]))

    #Accumulator variable
    protein = ''
    for aa in range(0, len(mRNA)-3, 3):
        protein += translation_dict[mRNA[aa:aa+3]]

    print protein



Friday, March 22, 2013

Installing biopython on Mac OS X 10.5 and Mac OS X 10.8

Installing on Mac OS X 10.5

1. Install XCode
 - https://connect.apple.com/cgi-bin/WebObjects/MemberSite.woa/wa/getSoftware?bundleID=20414 from apple
 - Just use default install 

2.  Install NumPy

 - download http://sourceforge.net/projects/numpy/files/
 - double click on the file and it will unzip
 - I then placed the unzipped file on the desktop(shorter directory address)
 - then open terminal
 - navigate to the file
  - example
   cd /Users/computername/Desktop/numpy-1.7.0
 - then type in terminal python setup.py build (note this takes a little while to complete and as some  points it looks like to stalled.  Just wait.)
 - then type into terminal sudo python setup.py install

3. Install biopython

 - download source zip file from http://biopython.org/wiki/Download
 - double click on it and it will unzip
 - I then placed the unzipped file on the desktop(shorter directory address)
 - then open terminal
 - navigate to the file
 - type python setup.py build
 - python setup.py test
 - sudo python setup.py install



4. go to idle and test if you installed everything
>>> import numpy
>>> print numpy.__version__
1.7.0
>>> import Bio
>>> print Bio.__version__
1.61 

Installing on Mac OS X 10.8

1. Install XCode.
  - Download XCode from the Mac App Store and install

2. Install XCode the command line tools
  - Open XCode
  - Go to XCode on toolbar -> preferences -> Downloads -> click on install Command Line Tools
   - Command Line Tools are already installed on my computer therefore it says update


3. Install MacPorts
  - Download Mountain Lion MacPorts "pkg" installer

4.  Install NumPy

 - download http://sourceforge.net/projects/numpy/files/
 - double click on the file and it will unzip

 - I then placed the unzipped file on the desktop(shorter directory address)
 - then open terminal
 - navigate to the file
  - example
   cd /Users/computername/Desktop/numpy-1.7.0
 - then type in terminal python setup.py build (note this takes a little while to complete and as some  points it looks like to stalled.  Just wait.)
 - then type into terminal sudo python setup.py install

5. Install biopython
 - download source zip file from http://biopython.org/wiki/Download
 - double click on it and it will unzip
 - I then placed the unzipped file on the desktop(shorter directory address)
 - then open terminal
 - navigate to the file
 - type python setup.py build
 - python setup.py test
 - sudo python setup.py install



6. go to idle and test if you installed everything
>>> import numpy
>>> print numpy.__version__
1.7.0
>>> import Bio
>>> print Bio.__version__
1.61