Difference between revisions of "Team:EPF Lausanne/Project/Modelling/Code"

(Created page with "<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <style type="text/css"> #contentSub, #footer-box, #catlinks, #search-controls, #p-logo...")
 
Line 20: Line 20:
 
   max-height:50%;
 
   max-height:50%;
 
}
 
}
 +
 +
.highlight .hll { background-color: #49483e }
 +
.highlight  { background: #272822; color: #f8f8f2 }
 +
.highlight .c { color: #75715e } /* Comment */
 +
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
 +
.highlight .k { color: #66d9ef } /* Keyword */
 +
.highlight .l { color: #ae81ff } /* Literal */
 +
.highlight .n { color: #f8f8f2 } /* Name */
 +
.highlight .o { color: #f92672 } /* Operator */
 +
.highlight .p { color: #f8f8f2 } /* Punctuation */
 +
.highlight .cm { color: #75715e } /* Comment.Multiline */
 +
.highlight .cp { color: #75715e } /* Comment.Preproc */
 +
.highlight .c1 { color: #75715e } /* Comment.Single */
 +
.highlight .cs { color: #75715e } /* Comment.Special */
 +
.highlight .gd { color: #f92672 } /* Generic.Deleted */
 +
.highlight .ge { font-style: italic } /* Generic.Emph */
 +
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
 +
.highlight .gs { font-weight: bold } /* Generic.Strong */
 +
.highlight .gu { color: #75715e } /* Generic.Subheading */
 +
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
 +
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
 +
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
 +
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
 +
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
 +
.highlight .kt { color: #66d9ef } /* Keyword.Type */
 +
.highlight .ld { color: #e6db74 } /* Literal.Date */
 +
.highlight .m { color: #ae81ff } /* Literal.Number */
 +
.highlight .s { color: #e6db74 } /* Literal.String */
 +
.highlight .na { color: #a6e22e } /* Name.Attribute */
 +
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
 +
.highlight .nc { color: #a6e22e } /* Name.Class */
 +
.highlight .no { color: #66d9ef } /* Name.Constant */
 +
.highlight .nd { color: #a6e22e } /* Name.Decorator */
 +
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
 +
.highlight .ne { color: #a6e22e } /* Name.Exception */
 +
.highlight .nf { color: #a6e22e } /* Name.Function */
 +
.highlight .nl { color: #f8f8f2 } /* Name.Label */
 +
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
 +
.highlight .nx { color: #a6e22e } /* Name.Other */
 +
.highlight .py { color: #f8f8f2 } /* Name.Property */
 +
.highlight .nt { color: #f92672 } /* Name.Tag */
 +
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
 +
.highlight .ow { color: #f92672 } /* Operator.Word */
 +
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
 +
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
 +
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
 +
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
 +
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
 +
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
 +
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
 +
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
 +
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
 +
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
 +
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
 +
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
 +
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
 +
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
 +
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
 +
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
 +
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
 +
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
 +
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
 +
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
 +
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
 +
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
 +
 +
 
</style>
 
</style>
 
     <!--  
 
     <!--  
Line 120: Line 187:
 
             <div class="row">
 
             <div class="row">
 
                 <div class="col-md-12 text-center">
 
                 <div class="col-md-12 text-center">
                     <h3>Description</h3>
+
                     <h3>Code</h3>
 
                 </div>
 
                 </div>
 
             </div>
 
             </div>
Line 129: Line 196:
 
         <div class="container">
 
         <div class="container">
 
             <div class="row">
 
             <div class="row">
                 <div class="col-md-8 col-centered">
+
                 <div class="col-md-12 col-centered">
                     <h3>Biologic Orthogonal GRNA-Implemented Circuit</h3>
+
                     <h3>ODE Generator</h3>
                    <p>This summer, the EPFL iGEM team strives to pave the way for simpler implementation of digital circuits in vivo. Using the newly discovered dCas9 as a synthetic transcription factor, we aim to design biocompatible transistor-like elements. Our ultimate goal is to make cells smarters by assembling these transistors into logic gates that are both chainable and parallelizable in a homogenous logic framework.</p>
+
               
                    <h2>Thinking Binary</h2>
+
                <div class="highlight"><pre><span class="k">class</span> <span class="nc">Reaction</span><span class="p">:</span>
                    <p>Boolean Logic is the bedrock of the digital revolution. Developed by George Boole in the mid-19th century, it is based on a simple set of values: 0 (“FALSE”) or 1 (“TRUE”). Modern computers represent all forms of information using strings of the same 0s and 1s (also named “Bits”). The processing of bits is handled by logical transistors - which can be seen as electronically controllable switches. Elementary logic operation are performed using cleverly assembled transistors. Such assemblies are named “logic gates”. Gates are the bricks with which complex behaviour is produced.</p>
+
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reaction_</span><span class="p">,</span> <span class="n">cst_name_</span><span class="p">,</span> <span class="n">cst_value_</span><span class="p">,</span> <span class="n">description_</span><span class="p">):</span>
                    <h2>Biological computers</h2>
+
<span class="bp">self</span><span class="o">.</span><span class="n">reaction</span> <span class="o">=</span> <span class="n">reaction_</span>
                    <p>Since the early 2000’s, multiple synthetic biological gates have been built, revolutionizing our ability to dictate the way organisms react to stimuli. Their applications range from intelligent biosensors to cellular therapeutics with improved in vivo targeting and curing.<br>
+
<span class="bp">self</span><span class="o">.</span><span class="n">cst_name</span> <span class="o">=</span> <span class="n">cst_name_</span>
                    Unfortunately, the development of programmable cells has been hampered by difficulties in the multiplication and chaining of logic elements. This has hindered the complexification of bio-circuits as well as the automation and flexibility of their design.<br>
+
<span class="bp">self</span><span class="o">.</span><span class="n">cst_value</span> <span class="o">=</span> <span class="n">cst_value_</span>
                    To overcome these limitations, an ideal in vivo logic element should be modular, reusable, and orthogonal - i.e avoiding unwanted cross-talk with its host organism as well as other elements of the engineered circuit.</p>
+
<span class="bp">self</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="n">description_</span>
                    <h2>Cas9 Logic Gates</h2>
+
                    <p>Cas9 (CRISPR associated protein 9) is an RNA-guided DNA endonuclease that targets and cleaves any DNA sequence complementary to its guide RNA (gRNA). Our project will be based upon a derivative of this technology : catalytically “dead” Cas9 (dCas9) that lack the ability to cleave DNA. When fused to a RNA polymerase (RNAP) recruiting element (e.g. the omega subunit of RNAP in E. Coli or VP64 in eukaryotes), chimeric dCas9 can act as a  programmable transcription activator. In addition, activating dCas9 may also act as a DNA transcription inhibitor: depending on its gRNA-determined binding site, it has been shown in yeasts to sterically hinder RNAP recruitment to promoter sequences.<br>
+
<span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
                    Exploiting dCas9-omega/VP64’s ambivalence, we propose the creation of gRNA-controlled switch-like elements analogous to transistors. The state of the switch would be solely dependent on the position of dCas9 relative to the promoter. The content of the gRNA-targeted sequences might therefore be designed such that each transistor is orthogonal to other logic elements. Using gRNA to make what could be seen as “biological wires”,  we also hope to achieve chainability of the transistors and thus complexification of bio-circuits.</p>
+
    <span class="k">return</span> <span class="s">&quot;{}</span><span class="se">\n</span><span class="s">{} = {}</span><span class="se">\n</span><span class="s">{}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">reaction</span><span class="p">,</span>
 +
    <span class="bp">self</span><span class="o">.</span><span class="n">cst_name</span><span class="p">,</span>
 +
    <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cst_value</span><span class="p">),</span>
 +
    <span class="bp">self</span><span class="o">.</span><span class="n">description</span><span class="p">)</span>
 +
 +
<span class="k">class</span> <span class="nc">ReactionParser</span><span class="p">:</span>
 +
 +
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">input_</span><span class="p">,</span> <span class="n">sep_</span><span class="o">=</span><span class="s">&quot;:&quot;</span><span class="p">,</span> <span class="n">comment_</span><span class="o">=</span><span class="s">&quot;#&quot;</span><span class="p">):</span>
 +
<span class="bp">self</span><span class="o">.</span><span class="n">sep</span> <span class="o">=</span> <span class="n">sep_</span>
 +
<span class="bp">self</span><span class="o">.</span><span class="n">comment</span> <span class="o">=</span> <span class="n">comment_</span>
 +
 +
<span class="bp">self</span><span class="o">.</span><span class="n">file</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">input_</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">)</span> <span class="c"># TODO: OPEN SAFELY</span>
 +
 +
<span class="bp">self</span><span class="o">.</span><span class="n">reactions</span> <span class="o">=</span> <span class="p">[]</span>
 +
 +
<span class="bp">self</span><span class="o">.</span><span class="n">_load</span><span class="p">()</span>
 +
 +
<span class="k">def</span> <span class="nf">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
 +
<span class="bp">self</span><span class="o">.</span><span class="n">file</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
 +
 +
<span class="k">def</span> <span class="nf">_load</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
 +
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">file</span><span class="p">:</span>
 +
<span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="o">==</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span> <span class="ow">or</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="o">==</span> <span class="s">&quot;&quot;</span><span class="p">:</span> <span class="c"># Check for empty lines</span>
 +
<span class="k">continue</span>
 +
 +
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> <span class="o">!=</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">comment</span><span class="p">:</span> <span class="c"># Check for comments</span>
 +
<span class="k">continue</span>
 +
 +
<span class="n">splitted</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;:&quot;</span><span class="p">)</span>
 +
 +
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">splitted</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">4</span><span class="p">:</span>
 +
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;ReactionParser: problem with the input file (not enough arguments)&#39;</span><span class="p">)</span>
 +
 +
<span class="n">reaction</span> <span class="o">=</span> <span class="n">Reaction</span><span class="p">(</span><span class="n">splitted</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span>
 +
<span class="n">splitted</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">(),</span>
 +
<span class="nb">float</span><span class="p">(</span><span class="n">splitted</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()),</span>
 +
<span class="n">splitted</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
 +
 +
<span class="bp">self</span><span class="o">.</span><span class="n">reactions</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">reaction</span><span class="p">)</span>
 +
 +
<span class="k">def</span> <span class="nf">print_reactions</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
 +
<span class="k">for</span> <span class="n">reaction</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">reactions</span><span class="p">:</span>
 +
<span class="k">print</span><span class="p">(</span><span class="n">reaction</span><span class="p">)</span>
 +
<span class="k">print</span><span class="p">()</span>
 +
 +
<span class="k">def</span> <span class="nf">reaction_table</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
 +
<span class="n">kin</span> <span class="o">=</span> <span class="p">[]</span>
 +
 +
<span class="k">for</span> <span class="n">reaction</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">reactions</span><span class="p">:</span>
 +
<span class="n">splitted</span> <span class="o">=</span> <span class="n">reaction</span><span class="o">.</span><span class="n">reaction</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;-&gt;&quot;</span><span class="p">)</span>
 +
 +
<span class="n">left</span> <span class="o">=</span> <span class="n">splitted</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
 +
<span class="n">right</span> <span class="o">=</span> <span class="n">splitted</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
 +
 +
<span class="n">kin</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="p">([</span><span class="n">left</span><span class="p">,</span> <span class="n">right</span><span class="p">],</span> <span class="p">(</span><span class="n">reaction</span><span class="o">.</span><span class="n">cst_name</span><span class="p">,</span> <span class="n">reaction</span><span class="o">.</span><span class="n">description</span><span class="p">,</span> <span class="n">reaction</span><span class="o">.</span><span class="n">cst_value</span><span class="p">)</span> <span class="p">)</span> <span class="p">)</span>
 +
 +
<span class="k">return</span> <span class="n">kin</span>
 +
 +
 +
 +
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span>
 +
<span class="n">myParser</span> <span class="o">=</span> <span class="n">ReactionParser</span><span class="p">(</span><span class="s">&quot;reactions.dat&quot;</span><span class="p">)</span>
 +
 +
<span class="c">#myParser.load()</span>
 +
<span class="n">myParser</span><span class="o">.</span><span class="n">print_reactions</span><span class="p">()</span>
 +
 +
<span class="n">kin</span> <span class="o">=</span> <span class="n">myParser</span><span class="o">.</span><span class="n">reaction_table</span><span class="p">()</span>
 +
 +
<span class="k">print</span><span class="p">(</span><span class="n">kin</span><span class="p">)</span>
 +
</pre></div>
 +
 
 +
                   
 
                 </div>
 
                 </div>
 
             </div>
 
             </div>

Revision as of 16:05, 29 July 2015

Code

ODE Generator

class Reaction:
	def __init__(self, reaction_, cst_name_, cst_value_, description_):
		self.reaction = reaction_
		self.cst_name = cst_name_
		self.cst_value = cst_value_
		self.description = description_
		
	def __str__(self):
		    return "{}\n{} = {}\n{}".format(self.reaction,
		    self.cst_name,
		    str(self.cst_value),
		    self.description)
		
class ReactionParser:
	
	def __init__(self, input_, sep_=":", comment_="#"):
		self.sep = sep_
		self.comment = comment_
		
		self.file = open(input_, 'r') # TODO: OPEN SAFELY
		
		self.reactions = []
		
		self._load()
	
	def __del__(self):
		self.file.close()
		
	def _load(self):
		for line in self.file:
			if line.strip() == "\n" or line.strip() == "": # Check for empty lines
				continue
				
			if len(line.strip()) != 0 and line.strip()[0] == self.comment: # Check for comments
				continue
		
			splitted = line.split(":")
			
			if len(splitted) != 4:
				raise ValueError('ReactionParser: problem with the input file (not enough arguments)')
			
			reaction = Reaction(splitted[0].strip(),
								splitted[1].strip(),
								float(splitted[2].strip()),
								splitted[3].strip())
								
			self.reactions.append(reaction)
			
	def print_reactions(self):
		for reaction in self.reactions:
			print(reaction)
			print()
			
	def reaction_table(self):
		kin = []
		
		for reaction in self.reactions:
			splitted = reaction.reaction.split("->")
		
			left = splitted[0].strip()
			right = splitted[-1].strip()
			
			kin.append( ([left, right], (reaction.cst_name, reaction.description, reaction.cst_value) ) )
		
		return kin
		
			
		
if __name__ == "__main__":
	myParser = ReactionParser("reactions.dat")
	
	#myParser.load()
	myParser.print_reactions()
	
	kin = myParser.reaction_table()
	
	print(kin)

Still under construction