[Edu-sig] bioinformatics?

kirby urner kirby.urner at gmail.com
Sat Oct 17 15:58:17 CEST 2015


I don't think code like this is exactly what's meant by bioinformatics,
which is more statistical in nature.

However as a way of reinforcing both knowledge domain content and learning
Python concepts, I think it has utility.  If you're already familiar with
some cell biology, this would be a useful way to hammer home Python.

I tossed up a simple 7 minute Youtube on the code below, talking mostly
about Inheritance & Composition in the OO sense.

https://youtu.be/UoHJdQeYa8k  (sound not so great, just using laptap
microphone).

I encourage others to do something more produced.

Example usage:


In [3]: the_cell = Eukaryote(0, 'GATACA')

In [4]: the_cell.nucleus.dna
Out[4]: ('GATACA', '')

In [5]: the_cell.nucleus.dna[0]
Out[5]: 'GATACA'

In [6]: the_cell.S_phase()  # this is when DNA replicates

In [7]: the_cell.nucleus.dna   # cell is now "mature" (ready to divide)
Out[7]: ('GATACA', 'CTATGT')

In [8]: new_cell = the_cell.divide()

In [9]: new_cell.nucleus.dna
Out[9]: ('GATACA', '')

Related:
https://mail.python.org/pipermail/edu-sig/2012-December/010709.html

Kirby




# -*- coding: utf-8 -*-
"""
Created on Sat Oct 10 12:02:55 2015

@author: Kirby Urner, MIT License
"""

class Mitochondrion:
    """Cell Battery"""
    pass

class Golgi:
    """Router"""
    pass

class Nucleus:
    """DNA Hut"""

    def __init__(self, dna_A):
        """Get half the DNA"""
        self.dna = dna_A, ''

    def mitosis(self):
        """Split DNA in two"""
        return self.dna[0], self.dna[1]

class Cell:

    def __init__(self, gen=0):
        """Age"""
        self.gen = gen + 1

class Prokaryote(Cell):
    pass  # won't have a nucleus

class Eukaryote(Cell):

    def __init__(self, gen, dna):
        super().__init__(gen) # get older
        self.nucleus = Nucleus(dna) # store DNA
        self.organelles = [Golgi(), Mitochondrion()]
        self.mature = False

    def S_phase(self):
        """Make other half of DNA"""

        dna_B = []
        dna_A = self.nucleus.dna[0]

        for base in dna_A:
            if base=='A':
                dna_B.append('T')
            elif base=='T':
                dna_B.append('A')
            elif base=='G':
                dna_B.append('C')
            elif base=='C':
                dna_B.append('G')

        dna_B = "".join(dna_B)
        self.nucleus.dna = (dna_A, dna_B)
        self.mature = True  # I'm ready for sex!

    def divide(self):
        if not self.mature:  # don't try it!
            raise ValueError

        dna_A, dna_B = self.nucleus.mitosis()
        new_cell = Eukaryote(self.gen, dna_A)

        # next generation of me
        self.gen += 1  # should be an upper limit
        self.nucleus.dna = '', dna_B
        self.mature = False
        return new_cell  # spawn of me
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/edu-sig/attachments/20151017/448c559b/attachment.html>


More information about the Edu-sig mailing list