In [3]:
from om import base, settings
from om.components import *
from om.data import *
from om.util import *

import pandas as pd
import numpy as np
import math,cobra

ome = base.Session()
model = cobra.io.load_matlab_model(settings.data_directory+'/models/iJO1366.mat')

ged = GeneExpressionData
dged = DifferentialGeneExpressionData
cpge = ChIPPeakGeneExpression


/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/io/excel.py:626: UserWarning: Installed openpyxl is not supported at this time. Use >=1.6.1 and <2.0.0.
  .format(openpyxl_compat.start_ver, openpyxl_compat.stop_ver))

In [7]:
ome.query(cpge).limit(20).all()


Out[7]:
[TF: Crp, Gene: (fixA, b0041),  1.59,  0.11 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 42217-42418 value:9753.90,
 TF: Crp, Gene: (fixA, b0041),  1.59,  0.11 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 42101-42302 value:12970.00,
 TF: Crp, Gene: (fixA, b0041),  1.59,  0.11 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 42001-42202 value:11061.00,
 TF: Crp, Gene: (fixA, b0041),  1.59,  0.11 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 42140-42341 value:8265.60,
 TF: Crp, Gene: (fixA, b0041),  1.59,  0.11 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 41949-42150 value:11610.60,
 TF: Crp, Gene: (fixA, b0041),  1.59,  0.11 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 41843-42044 value:10466.10,
 TF: Crp, Gene: (fixA, b0041),  1.59,  0.11 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 42085-42286 value:8112.80,
 TF: Crp, Gene: (fixA, b0041),  1.59,  0.11 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 41931-42132 value:9688.00,
 TF: Crp, Gene: (metQ, b0197),  0.66,  0.22 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 223357-223558 value:14241.00,
 TF: Crp, Gene: (alaV, b0203),   inf,  0.00 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 223357-223558 value:14241.00,
 TF: Crp, Gene: (tsx, b0411),  1.54,  0.01 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 431272-431473 value:9119.00,
 TF: Crp, Gene: (nmpC, b0553),  7.21,  0.00 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 575987-576188 value:11561.00,
 TF: Crp, Gene: (insH1, b0552), -28.27,  0.00 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 575987-576188 value:11561.00,
 TF: Crp, Gene: (cspE, b0623),  2.01,  0.00 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 656383-656584 value:23263.20,
 TF: Crp, Gene: (cspE, b0623),  2.01,  0.00 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 656341-656542 value:9294.80,
 TF: Crp, Gene: (sucA, b0726),  2.47,  0.00 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 754092-754293 value:7952.00,
 TF: Crp, Gene: (sucB, b0727),  2.38,  0.00 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 754092-754293 value:7952.00,
 TF: Crp, Gene: (sucD, b0729),  2.81,  0.03 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 754092-754293 value:7952.00,
 TF: Crp, Gene: (adhE, b1241),  1.51,  0.02 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 1297427-1297628 value:22908.90,
 TF: Crp, Gene: (adhE, b1241),  1.51,  0.02 delta-crp-->wt Condition: fructose, NH4Cl, O2 Peak: 1297450-1297651 value:11029.40]

In [9]:
ome.query(RNASeqExperiment).all()


---------------------------------------------------------------------------
InternalError                             Traceback (most recent call last)
<ipython-input-9-bf4609327f2a> in <module>()
----> 1 ome.query(RNASeqExperiment).all()

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/orm/query.pyc in all(self)
   2290 
   2291         """
-> 2292         return list(self)
   2293 
   2294     @_generative(_no_clauseelement_condition)

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/orm/query.pyc in __iter__(self)
   2402         if self._autoflush and not self._populate_existing:
   2403             self.session._autoflush()
-> 2404         return self._execute_and_instances(context)
   2405 
   2406     def _connection_from_session(self, **kw):

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/orm/query.pyc in _execute_and_instances(self, querycontext)
   2417                         close_with_result=True)
   2418 
-> 2419         result = conn.execute(querycontext.statement, self._params)
   2420         return loading.instances(self, result, querycontext)
   2421 

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in execute(self, object, *multiparams, **params)
    718                                 type(object))
    719         else:
--> 720             return meth(self, multiparams, params)
    721 
    722     def _execute_function(self, func, multiparams, params):

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/sql/elements.pyc in _execute_on_connection(self, connection, multiparams, params)
    315 
    316     def _execute_on_connection(self, connection, multiparams, params):
--> 317         return connection._execute_clauseelement(self, multiparams, params)
    318 
    319     def unique_params(self, *optionaldict, **kwargs):

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_clauseelement(self, elem, multiparams, params)
    815             compiled_sql,
    816             distilled_params,
--> 817             compiled_sql, distilled_params
    818         )
    819         if self._has_events or self.engine._has_events:

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_context(self, dialect, constructor, statement, parameters, *args)
    945                                 parameters,
    946                                 cursor,
--> 947                                 context)
    948 
    949         if self._has_events or self.engine._has_events:

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in _handle_dbapi_exception(self, e, statement, parameters, cursor, context)
   1106                                         self.dialect.dbapi.Error,
   1107                                         connection_invalidated=self._is_disconnect),
-> 1108                                     exc_info
   1109                                 )
   1110 

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/util/compat.pyc in raise_from_cause(exception, exc_info)
    183             exc_info = sys.exc_info()
    184         exc_type, exc_value, exc_tb = exc_info
--> 185         reraise(type(exception), exception, tb=exc_tb)
    186 
    187 if py3k:

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in _execute_context(self, dialect, constructor, statement, parameters, *args)
    938                                      statement,
    939                                      parameters,
--> 940                                      context)
    941         except Exception as e:
    942             self._handle_dbapi_exception(

/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sqlalchemy/engine/default.pyc in do_execute(self, cursor, statement, parameters, context)
    433 
    434     def do_execute(self, cursor, statement, parameters, context=None):
--> 435         cursor.execute(statement, parameters)
    436 
    437     def do_execute_no_params(self, cursor, statement, context=None):

InternalError: (InternalError) current transaction is aborted, commands ignored until end of transaction block
 'SELECT rna_seq_experiment.id AS rna_seq_experiment_id, data_set.id AS data_set_id, data_set.name AS data_set_name, data_set.type AS data_set_type, data_set.replicate AS data_set_replicate, data_set.strain_id AS data_set_strain_id, data_set.environment_id AS data_set_environment_id, data_set.data_source_id AS data_set_data_source_id, rna_seq_experiment.sequencing_type AS rna_seq_experiment_sequencing_type, rna_seq_experiment.machine_id AS rna_seq_experiment_machine_id, rna_seq_experiment.normalization_method AS rna_seq_experiment_normalization_method, rna_seq_experiment.normalization_factor AS rna_seq_experiment_normalization_factor, rna_seq_experiment.file_name AS rna_seq_experiment_file_name \nFROM data_set JOIN rna_seq_experiment ON data_set.id = rna_seq_experiment.id' {}

In [1]:
%%html

<div id="d3-example"></div>

<style>

svg {
  font: 11px "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

.axis--y path {
  display: none;
}

.genome_data {
  fill: none;
  stroke: #aaa;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-width: 1.5px;
}

.data_track--hover {
  stroke: #000;
}

.focus text {
  text-anchor: middle;
  text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff;
}

.voronoi path {
  fill: none;
  pointer-events: all;
}

.voronoi--show path {
  stroke: red;
  stroke-opacity: .2;
}

#form {
  position: absolute;
  top: 20px;
  right: 30px;
}

</style>



In [2]:
%%javascript

require.config({paths: {d3: "https://mpld3.github.io/js/d3.v3.min"}});

require(["d3"], function(d3) {

var positions;

var margin = {top: 20, right: 30, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var x = d3.scale.linear()
    .range([0, width]);
    
var y = d3.scale.linear()
    .range([height, 0]);

var color = d3.scale.category20();

var voronoi = d3.geom.voronoi()
    .x(function(d) { return x(d.position); })
    .y(function(d) { return y(d.value); })
    .clipExtent([[-margin.left, -margin.top], [width + margin.right, height + margin.bottom]]);

var line = d3.svg.line()
    .interpolate("basis")
    .x(function(d) { return x(d.position); })
    .y(function(d) { return y(d.value); });

var svg = d3.select("#d3-example").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

d3.csv("data/peak_tmp.tsv", type, function(error, genome_data) {
  //x.domain(d3.extent(positions));
  console.log(d3.extent(genome_data));
  x.domain([0,1000]);
  y.domain([0, d3.max(genome_data, function(c) { return d3.max(c.values, function(d) { return d.value; }); })]).nice();
  console.log(d3.extent(positions));
  svg.append("g")
      .attr("class", "axis axis--x")
      .attr("transform", "translate(0," + height + ")")
      .call(d3.svg.axis()
        .scale(x)
        .orient("bottom"));

  svg.append("g")
      .attr("class", "axis axis--y")
      .call(d3.svg.axis()
        .scale(y)
        .orient("left")
        .ticks(10, "%"))
    .append("text")
      .attr("x", 4)
      .attr("dy", ".32em")
      .style("font-weight", "bold");

  svg.append("g")
      .attr("class", "genome_data")
    .selectAll("path")
      .data(genome_data)
    .enter().append("path")
      .attr("d", function(d) { d.line = this; return line(d.values);});

  var focus = svg.append("g")
      .attr("transform", "translate(-100,-100)")
      .attr("class", "focus");

  focus.append("circle")
      .attr("r", 3.5);

  focus.append("text")
      .attr("y", -10);

  var voronoiGroup = svg.append("g")
      .attr("class", "voronoi");

  voronoiGroup.selectAll("path")
      .data(voronoi(d3.nest()
          .key(function(d) { return x(d.position) + "," + y(d.value); })
          .rollup(function(v) { return v[0]; })
          .entries(d3.merge(genome_data.map(function(d) { return d.values; })))
          .map(function(d) { return d.values; })))
    .enter().append("path")
      .attr("d", function(d) { return "M" + d.join("L") + "Z"; })
      .datum(function(d) { return d.point; })
      .on("mouseover", mouseover)
      .on("mouseout", mouseout);

  d3.select("#show-voronoi")
      .property("disabled", false)
      .on("change", function() { voronoiGroup.classed("voronoi--show", this.checked); });

  function mouseover(d) {
    d3.select(d.data_track.line).classed("data_track--hover", true);
    d.data_track.line.parentNode.appendChild(d.data_track.line);
    focus.attr("transform", "translate(" + x(d.position) + "," + y(d.value) + ")");
    focus.select("text").text(d.data_track.name);
  }

  function mouseout(d) {
    d3.select(d.data_track.line).classed("data_track--hover", false);
    focus.attr("transform", "translate(-100,-100)");
  }
});

function type(d, i) {
  if (!i) positions = Object.keys(d).filter(Number);
  var data_track = {
    name: d.name,
    values: null
  };
  data_track.values = positions.map(function(m) {
    return {
      data_track: data_track,
      position: m,
      value: d[m]
    };
  });
  return data_track;
}});



In [ ]: