In [1]:
from om import base, settings
from om.components import *
from om.data import *
from om.util import *
from scipy.spatial.distance import pdist, squareform
from scipy.cluster.hierarchy import linkage, dendrogram

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


ome = base.Session()
model = cobra.io.load_matlab_model('/Volumes/extra/Dropbox/om_data/models/iJO1366.mat')

ged = GeneExpressionData
dged = DifferentialGeneExpressionData
cpge = ChIPPeakGeneExpression


cobra/io/__init__.py:17 UserWarning: cobra.io.sbml requires libsbml

In [2]:
from IPython.display import display
from IPython.html import widgets as W
from IPython.utils import traitlets as T

class HeatmapWidget(W.DOMWidget):
    _view_name = T.Unicode('HeatmapView', sync=True)
    heatmap_data = T.List(sync=True)
    row_labels = T.List(sync=True)
    col_labels = T.List(sync=True)
    hcrow = T.List(sync=True)
    hccol = T.List(sync=True)
    minval = T.Float(sync=True)
    maxval = T.Float(sync=True)
    html_style = T.Unicode(sync=True)

In [74]:
%%javascript

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

require(["widgets/js/widget", "d3", "heatmap"], function(WidgetManager, d3, heatmap){
    
    });
    WidgetManager.register_widget_view("HeatmapView", HeatmapView);
});



In [75]:
html_style = """
     <style>
      /* disable text selection */
      svg *::selection {
         background : transparent;
      }
     
      svg *::-moz-selection {
         background:transparent;
      } 
     
      svg *::-webkit-selection {
         background:transparent;
      }
      rect.selection {
        stroke          : #333;
        stroke-dasharray: 4px;
        stroke-opacity  : 0.5;
        fill            : transparent;
      }

      rect.cell-border {
        stroke: #eee;
        stroke-width:0.3px;   
      }

      rect.cell-selected {
        stroke: rgb(51,102,153);
        stroke-width:0.5px;   
      }

      rect.cell-hover {
        stroke: #F00;
        stroke-width:0.3px;   
      }

      text.mono {
        font-size: 10pt;
        font-family: Consolas, courier;
        fill: #aaa;
      }

      text.text-selected {
        fill: #000;
      }

      text.text-highlight {
        fill: #c00;
      }
      text.text-hover {
        fill: #00C;
      }
      #tooltip {
        position: fixed;
        width: 200px;
        height: auto;
        padding: 10px;
        background-color: white;
        -webkit-border-radius: 10px;
        -moz-border-radius: 10px;
        border-radius: 10px;
        -webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
        -moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
        box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
        pointer-events: none;
      }

      #tooltip.hidden {
        display: none;
      }

      #tooltip p {
        margin: 0;
        font-family: sans-serif;
        font-size: 12px;
        line-height: 20px;
      }
    </style>


<div id="tooltip" class="hidden">
        <p><span id="value"></p>
</div>

 
  <select id="order">
  <option value="hclust">by cluster</option>
  <option value="probecontrast">by probe name and contrast name</option>
  <option value="probe">by probe name</option>
  <option value="contrast">by contrast name</option>
  <option value="custom">by log2 ratio</option>
  </select>
  </select>
<div id="chart" style='overflow:auto; width:960px; height:auto;'></div>
"""

In [76]:
ome.query(GeneGroup).all()


Out[76]:
[Gene Group (#1, class 1) 7 genes,
 Gene Group (#5, glycerol_repressed) 58 genes,
 Gene Group (#6, glycerol_activated_dict) 106 genes,
 Gene Group (#7, fructose_repressed) 48 genes,
 Gene Group (#9, fructose_activated) 89 genes,
 Gene Group (#10, glycerol_activated) 106 genes,
 Gene Group (#18, crp_catabolic_genes) 129 genes,
 Gene Group (#19, crp_anabolic_genes) 99 genes,
 Gene Group (#20, crp_chemiosmotic_genes) 57 genes,
 Gene Group (#21, Glycolysis / Gluconeogenesis) 40 genes,
 Gene Group (#22, Citrate cycle (TCA cycle)) 28 genes,
 Gene Group (#23, Pentose phosphate pathway) 30 genes,
 Gene Group (#24, Pentose and glucuronate interconversions) 27 genes,
 Gene Group (#25, Fructose and mannose metabolism) 38 genes,
 Gene Group (#26, Galactose metabolism) 33 genes,
 Gene Group (#27, Ascorbate and aldarate metabolism) 14 genes,
 Gene Group (#28, Fatty acid biosynthesis) 12 genes,
 Gene Group (#29, Fatty acid metabolism) 16 genes,
 Gene Group (#30, Ubiquinone and other terpenoid-quinone biosynthesis) 17 genes,
 Gene Group (#31, Oxidative phosphorylation) 41 genes,
 Gene Group (#32, Purine metabolism) 87 genes,
 Gene Group (#33, Pyrimidine metabolism) 53 genes,
 Gene Group (#34, Alanine, aspartate and glutamate metabolism) 29 genes,
 Gene Group (#35, Glycine, serine and threonine metabolism) 32 genes,
 Gene Group (#36, Cysteine and methionine metabolism) 28 genes,
 Gene Group (#37, Valine, leucine and isoleucine degradation) 12 genes,
 Gene Group (#38, Geraniol degradation) 6 genes,
 Gene Group (#39, Valine, leucine and isoleucine biosynthesis) 21 genes,
 Gene Group (#40, Lysine biosynthesis) 16 genes,
 Gene Group (#41, Lysine degradation) 11 genes,
 Gene Group (#42, Arginine and proline metabolism) 43 genes,
 Gene Group (#43, Histidine metabolism) 9 genes,
 Gene Group (#44, Tyrosine metabolism) 9 genes,
 Gene Group (#45, Phenylalanine metabolism) 18 genes,
 Gene Group (#46, gamma-Hexachlorocyclohexane degradation) 5 genes,
 Gene Group (#47, Benzoate degradation via hydroxylation) 5 genes,
 Gene Group (#48, Fluorobenzoate degradation) 1 genes,
 Gene Group (#49, Tryptophan metabolism) 11 genes,
 Gene Group (#50, Phenylalanine, tyrosine and tryptophan biosynthesis) 21 genes,
 Gene Group (#51, Novobiocin biosynthesis) 4 genes,
 Gene Group (#52, beta-Alanine metabolism) 15 genes,
 Gene Group (#53, Taurine and hypotaurine metabolism) 6 genes,
 Gene Group (#54, Phosphonate and phosphinate metabolism) 2 genes,
 Gene Group (#55, Selenoamino acid metabolism) 14 genes,
 Gene Group (#56, Cyanoamino acid metabolism) 6 genes,
 Gene Group (#57, D-Glutamine and D-glutamate metabolism) 5 genes,
 Gene Group (#58, D-Alanine metabolism) 4 genes,
 Gene Group (#59, Glutathione metabolism) 17 genes,
 Gene Group (#60, Starch and sucrose metabolism) 32 genes,
 Gene Group (#61, Other glycan degradation) 4 genes,
 Gene Group (#62, Amino sugar and nucleotide sugar metabolism) 44 genes,
 Gene Group (#63, Streptomycin biosynthesis) 9 genes,
 Gene Group (#64, Polyketide sugar unit biosynthesis) 6 genes,
 Gene Group (#65, Lipopolysaccharide biosynthesis) 27 genes,
 Gene Group (#66, Peptidoglycan biosynthesis) 23 genes,
 Gene Group (#67, Glycerolipid metabolism) 13 genes,
 Gene Group (#68, Inositol phosphate metabolism) 3 genes,
 Gene Group (#69, Glycerophospholipid metabolism) 28 genes,
 Gene Group (#70, Arachidonic acid metabolism) 2 genes,
 Gene Group (#71, alpha-Linolenic acid metabolism) 3 genes,
 Gene Group (#72, Sphingolipid metabolism) 3 genes,
 Gene Group (#73, Pyruvate metabolism) 43 genes,
 Gene Group (#74, Biphenyl degradation) 2 genes,
 Gene Group (#75, Toluene and xylene degradation) 2 genes,
 Gene Group (#76, 1- and 2-Methylnaphthalene degradation) 4 genes,
 Gene Group (#77, Naphthalene and anthracene degradation) 1 genes,
 Gene Group (#78, 1,4-Dichlorobenzene degradation) 3 genes,
 Gene Group (#79, Fluorene degradation) 3 genes,
 Gene Group (#80, Carbazole degradation) 2 genes,
 Gene Group (#81, Glyoxylate and dicarboxylate metabolism) 36 genes,
 Gene Group (#82, Benzoate degradation via CoA ligation) 16 genes,
 Gene Group (#83, Trinitrotoluene degradation) 7 genes,
 Gene Group (#84, Propanoate metabolism) 30 genes,
 Gene Group (#85, 3-Chloroacrylic acid degradation) 4 genes,
 Gene Group (#86, Ethylbenzene degradation) 4 genes,
 Gene Group (#87, Styrene degradation) 3 genes,
 Gene Group (#88, Butanoate metabolism) 35 genes,
 Gene Group (#89, C5-Branched dibasic acid metabolism) 9 genes,
 Gene Group (#90, One carbon pool by folate) 13 genes,
 Gene Group (#91, Methane metabolism) 15 genes,
 Gene Group (#92, Thiamine metabolism) 14 genes,
 Gene Group (#93, Riboflavin metabolism) 11 genes,
 Gene Group (#94, Vitamin B6 metabolism) 9 genes,
 Gene Group (#95, Nicotinate and nicotinamide metabolism) 17 genes,
 Gene Group (#96, Pantothenate and CoA biosynthesis) 21 genes,
 Gene Group (#97, Biotin metabolism) 7 genes,
 Gene Group (#98, Lipoic acid metabolism) 3 genes,
 Gene Group (#99, Folate biosynthesis) 12 genes,
 Gene Group (#100, Porphyrin and chlorophyll metabolism) 25 genes,
 Gene Group (#101, Terpenoid backbone biosynthesis) 13 genes,
 Gene Group (#102, Limonene and pinene degradation) 5 genes,
 Gene Group (#103, Nitrogen metabolism) 35 genes,
 Gene Group (#104, Sulfur metabolism) 13 genes,
 Gene Group (#105, Caprolactam degradation) 4 genes,
 Gene Group (#106, Aminoacyl-tRNA biosynthesis) 26 genes,
 Gene Group (#107, Biosynthesis of unsaturated fatty acids) 6 genes,
 Gene Group (#108, Biosynthesis of siderophore group nonribosomal peptides) 6 genes,
 Gene Group (#109, ABC transporters) 182 genes,
 Gene Group (#110, Two-component system) 130 genes,
 Gene Group (#111, Bacterial chemotaxis) 21 genes,
 Gene Group (#112, Flagellar assembly) 38 genes,
 Gene Group (#113, Phosphotransferase system (PTS)) 45 genes,
 Gene Group (#114, Ribosome) 79 genes,
 Gene Group (#115, RNA degradation) 15 genes,
 Gene Group (#116, RNA polymerase) 4 genes,
 Gene Group (#117, DNA replication) 17 genes,
 Gene Group (#118, Protein export) 19 genes,
 Gene Group (#119, Bacterial secretion system) 32 genes,
 Gene Group (#120, Base excision repair) 14 genes,
 Gene Group (#121, Nucleotide excision repair) 8 genes,
 Gene Group (#122, Mismatch repair) 22 genes,
 Gene Group (#123, Homologous recombination) 27 genes,
 Gene Group (#124, zero_non_rpod) 16 genes]

In [77]:
catabolic_genes = ome.query(GeneGroup).filter(GeneGroup.name.ilike('Two-%')).first().genes
#hcrow,hccol,row_labels,col_labels,heatmap_data = gene_heatmap(catabolic_genes, 
#                                                              analysis_type=ChIPPeakGeneExpression,
#                                                              strain1=ome.query(Strain).filter(Strain.name.in_(['delta-crp','delAr1','delAr2','delAr1delAr2'])),
#                                                              strain2=ome.query(Strain).all(),
#                                                              environments2=ome.query(InVivoEnvironment).\
#                                                                                filter(InVivoEnvironment.carbon_source.in_(['glycerol','fructose'])).all())



heatmap_args = gene_heatmap(catabolic_genes, analysis_type=GeneExpressionData,
                                             dataset_type='rna_seq_experiment',
                                             strain1=ome.query(Strain).filter(Strain.name.in_(['delta-crp','delAr1','delAr2','delAr1delAr2'])).all())



heatmap_args['html_style'] = html_style

In [78]:
catabolic_heatmap_diagram = HeatmapWidget(**heatmap_args)
display(catabolic_heatmap_diagram)

In [ ]:


In [ ]:


In [10]:
chemiosmotic_genes = ome.query(GeneGroup).filter(GeneGroup.name.ilike('crp_chemi%')).first().genes
hcrow,hccol,row_labels,col_labels,heatmap_data = gene_heatmap(chemiosmotic_genes, 
                                                              analysis_type=ChIPPeakGeneExpression,
                                                              strain1=ome.query(Strain).filter(Strain.name.in_(['delta-crp','delAr1','delAr2','delAr1delAr2'])),
                                                              strain2=ome.query(Strain).all(),
                                                              environments2=ome.query(InVivoEnvironment).\
                                                                                filter(InVivoEnvironment.carbon_source.in_(['glycerol','fructose','glucose'])).all())

In [ ]: