...
 
Commits (14)
[*.{js,php}]
indent_style = space
indent_size = 2
This diff is collapsed.
......@@ -109,14 +109,51 @@
height: 37px;
}
.input-container {
display: flex;
justify-content: space-between;
}
.network-input {
flex-basis: 49%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.network-input select {
font-size: 1.5em;
}
.network-control {
flex-basis: 49%;
display: flex;
flex-direction: column;
}
.network-wrapper {
display: flex;
justify-content: space-between;
height: 100%;
}
.network-container {
flex: 1;
flex-basis: 100%;
border: 1px solid #CCCCCC;
height: 500px;
}
.network-table-wrapper {
display: flex;
justify-content: space-between;
}
.network-table-wrapper div {
flex-basis: 100%;
}
.network-table-wrapper div table {
width: 100%;
}
.accordion{
......@@ -181,16 +218,9 @@ height: 37px;
}*/
.accordion .accordion-content {
background: rgba(255, 255, 255, 0.5);
margin-top: -24px;
overflow: hidden;
height: 24px;
position: relative;
z-index: 10;
-webkit-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
-moz-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
-o-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
-ms-transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
transition: height 0.3s ease-in-out, box-shadow 0.6s linear;
}
.accordion .accordion-content {
color: #777;
......@@ -200,17 +230,12 @@ height: 37px;
text-shadow: 1px 1px 1px rgba(255,255,255,0.8);
}
.accordion .accordion-content {
-webkit-transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
-moz-transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
-o-transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
-ms-transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
transition: height 0.5s ease-in-out, box-shadow 0.1s linear;
box-shadow: 0px 0px 0px 1px rgba(155,155,155,0.3);
}
.accordion .accordion-content.ac-small{
height: 140px;
}
.accordion .accordion-content..ac-medium{
.accordion .accordion-content.ac-medium{
height: 180px;
}
......@@ -226,63 +251,6 @@ height: 37px;
height: 291px;
}
/*Slider*/
.slider {
width: 100%;
}
.slider > .dragger {
background: #63BEC4;
background: -webkit-linear-gradient(top, #63BEC4, #63BEC4);
background: -moz-linear-gradient(top, #63BEC4, #63BEC4);
background: linear-gradient(top, #63BEC4, #63BEC4);
-webkit-box-shadow: inset 0 2px 2px rgba(255,255,255,0.5), 0 2px 8px rgba(0,0,0,0.2);
-moz-box-shadow: inset 0 2px 2px rgba(255,255,255,0.5), 0 2px 8px rgba(0,0,0,0.2);
box-shadow: inset 0 2px 2px rgba(255,255,255,0.5), 0 2px 8px rgba(0,0,0,0.2);
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
border: 1px solid #3d7489;
width: 16px;
height: 16px;
}
.slider > .dragger:hover {
background: -webkit-linear-gradient(top, #3d7489, #3d7489);
}
.slider > .track, .slider > .highlight-track {
background: #ccc;
background: -webkit-linear-gradient(top, #bbb, #ddd);
background: -moz-linear-gradient(top, #bbb, #ddd);
background: linear-gradient(top, #bbb, #ddd);
-webkit-box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
-moz-box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
border: 1px solid #aaa;
height: 4px;
}
.slider > .highlight-track {
background-color: #63BEC4;
background: -webkit-linear-gradient(top, #63BEC4, #63BEC4);
background: -moz-linear-gradient(top, #63BEC4, #63BEC4);
background: linear-gradient(top, #63BEC4, #63BEC4);
border-color: #63BEC4;
}
/**subtables*/
#sub_table{
margin-left:22px;
......
......@@ -10,6 +10,26 @@ try {
echo 'Connection failed: '.$e->getMessage();
}
function build_in_array($key_prefix, $a) {
return array_combine(
array_map(
function ($v) use (&$key_prefix) {
return ":{$key_prefix}_{$v}";
},
array_keys($a)
), $a);
}
function prepare_in($key_prefix, $a) {
return implode(',', array_keys(build_in_array($key_prefix, $a)));
}
function bind_in_params($stmt, $type, $values) {
$args = build_in_array($type, $values);
call_user_func_array(array($stmt, "bind_param"), ref_array($args));
}
$spNames = array("pt" => "P. tremula", "at" => "A. thaliana", "os" => "Z. mays");
$tmp_op = isset($_POST['op']) ? $_POST['op'] : null;
......
This diff is collapsed.
This diff is collapsed.
var __slice=[].slice,__indexOf=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++){if(t in this&&this[t]===e)return t}return-1};(function(e,t){var n;n=function(){function t(t,n){var r,i=this;this.input=t;this.defaultOptions={animate:true,snapMid:false,classPrefix:null,classSuffix:null,theme:null,highlight:false};this.settings=e.extend({},this.defaultOptions,n);if(this.settings.theme){this.settings.classSuffix="-"+this.settings.theme}this.input.hide();this.slider=e("<div>").addClass("slider"+(this.settings.classSuffix||"")).css({position:"relative",userSelect:"none",boxSizing:"border-box"}).insertBefore(this.input);if(this.input.attr("id")){this.slider.attr("id",this.input.attr("id")+"-slider")}this.track=this.createDivElement("track").css({width:"100%"});if(this.settings.highlight){this.highlightTrack=this.createDivElement("highlight-track").css({width:"0"})}this.dragger=this.createDivElement("dragger");this.slider.css({minHeight:this.dragger.outerHeight(),marginLeft:this.dragger.outerWidth()/2,marginRight:this.dragger.outerWidth()/2});this.track.css({marginTop:this.track.outerHeight()/-2});if(this.settings.highlight){this.highlightTrack.css({marginTop:this.track.outerHeight()/-2})}this.dragger.css({marginTop:this.dragger.outerHeight()/-2,marginLeft:this.dragger.outerWidth()/-2});this.track.mousedown(function(e){return i.trackEvent(e)});if(this.settings.highlight){this.highlightTrack.mousedown(function(e){return i.trackEvent(e)})}this.dragger.mousedown(function(e){if(e.which!==1){return}i.dragging=true;i.dragger.addClass("dragging");i.domDrag(e.pageX,e.pageY);return false});e("body").mousemove(function(t){if(i.dragging){i.domDrag(t.pageX,t.pageY);return e("body").css({cursor:"pointer"})}}).mouseup(function(t){if(i.dragging){i.dragging=false;i.dragger.removeClass("dragging");return e("body").css({cursor:"auto"})}});this.pagePos=0;if(this.input.val()===""){this.value=this.getRange().min;this.input.val(this.value)}else{this.value=this.nearestValidValue(this.input.val())}this.setSliderPositionFromValue(this.value);r=this.valueToRatio(this.value);this.input.trigger("slider:ready",{value:this.value,ratio:r,position:r*this.slider.outerWidth(),el:this.slider})}t.prototype.createDivElement=function(t){var n;n=e("<div>").addClass(t).css({position:"absolute",top:"50%",userSelect:"none",cursor:"pointer"}).appendTo(this.slider);return n};t.prototype.setRatio=function(e){var t;e=Math.min(1,e);e=Math.max(0,e);t=this.ratioToValue(e);this.setSliderPositionFromValue(t);return this.valueChanged(t,e,"setRatio")};t.prototype.setValue=function(e){var t;e=this.nearestValidValue(e);t=this.valueToRatio(e);this.setSliderPositionFromValue(e);return this.valueChanged(e,t,"setValue")};t.prototype.trackEvent=function(e){if(e.which!==1){return}this.domDrag(e.pageX,e.pageY,true);this.dragging=true;return false};t.prototype.domDrag=function(e,t,n){var r,i,s;if(n==null){n=false}r=e-this.slider.offset().left;r=Math.min(this.slider.outerWidth(),r);r=Math.max(0,r);if(this.pagePos!==r){this.pagePos=r;i=r/this.slider.outerWidth();s=this.ratioToValue(i);this.valueChanged(s,i,"domDrag");if(this.settings.snap){return this.setSliderPositionFromValue(s,n)}else{return this.setSliderPosition(r,n)}}};t.prototype.setSliderPosition=function(e,t){if(t==null){t=false}if(t&&this.settings.animate){this.dragger.animate({left:e},200);if(this.settings.highlight){return this.highlightTrack.animate({width:e},200)}}else{this.dragger.css({left:e});if(this.settings.highlight){return this.highlightTrack.css({width:e})}}};t.prototype.setSliderPositionFromValue=function(e,t){var n;if(t==null){t=false}n=this.valueToRatio(e);return this.setSliderPosition(n*this.slider.outerWidth(),t)};t.prototype.getRange=function(){if(this.settings.allowedValues){return{min:Math.min.apply(Math,this.settings.allowedValues),max:Math.max.apply(Math,this.settings.allowedValues)}}else if(this.settings.range){return{min:parseFloat(this.settings.range[0]),max:parseFloat(this.settings.range[1])}}else{return{min:0,max:1}}};t.prototype.nearestValidValue=function(t){var n,r,i,s;i=this.getRange();t=Math.min(i.max,t);t=Math.max(i.min,t);if(this.settings.allowedValues){n=null;e.each(this.settings.allowedValues,function(){if(n===null||Math.abs(this-t)<Math.abs(n-t)){return n=this}});return n}else if(this.settings.step){r=(i.max-i.min)/this.settings.step;s=Math.floor((t-i.min)/this.settings.step);if((t-i.min)%this.settings.step>this.settings.step/2&&s<r){s+=1}return s*this.settings.step+i.min}else{return t}};t.prototype.valueToRatio=function(e){var t,n,r,i,s,o,u,a;if(this.settings.equalSteps){a=this.settings.allowedValues;for(i=o=0,u=a.length;o<u;i=++o){t=a[i];if(!(typeof n!=="undefined"&&n!==null)||Math.abs(t-e)<Math.abs(n-e)){n=t;r=i}}if(this.settings.snapMid){return(r+.5)/this.settings.allowedValues.length}else{return r/(this.settings.allowedValues.length-1)}}else{s=this.getRange();return(e-s.min)/(s.max-s.min)}};t.prototype.ratioToValue=function(e){var t,n,r,i,s;if(this.settings.equalSteps){s=this.settings.allowedValues.length;i=Math.round(e*s-.5);t=Math.min(i,this.settings.allowedValues.length-1);return this.settings.allowedValues[t]}else{n=this.getRange();r=e*(n.max-n.min)+n.min;return this.nearestValidValue(r)}};t.prototype.valueChanged=function(t,n,r){var i;if(t.toString()===this.value.toString()){return}this.value=t;i={value:t,ratio:n,position:n*this.slider.outerWidth(),trigger:r,el:this.slider};return this.input.val(t).trigger(e.Event("change",i)).trigger("slider:changed",i)};return t}();e.extend(e.fn,{simpleSlider:function(){var t,r,i;i=arguments[0],t=2<=arguments.length?__slice.call(arguments,1):[];r=["setRatio","setValue"];return e(this).each(function(){var s,o;if(i&&__indexOf.call(r,i)>=0){s=e(this).data("slider-object");return s[i].apply(s,t)}else{o=i;return e(this).data("slider-object",new n(e(this),o))}})}});return e(function(){return e("[data-slider]").each(function(){var t,n,r,i;t=e(this);r={};n=t.data("slider-values");if(n){r.allowedValues=function(){var e,t,r,s;r=n.split(",");s=[];for(e=0,t=r.length;e<t;e++){i=r[e];s.push(parseFloat(i))}return s}()}if(t.data("slider-range")){r.range=t.data("slider-range").split(",")}if(t.data("slider-step")){r.step=t.data("slider-step")}r.snap=t.data("slider-snap");r.equalSteps=t.data("slider-equal-steps");if(t.data("slider-theme")){r.theme=t.data("slider-theme")}if(t.attr("data-slider-highlight")){r.highlight=t.data("slider-highlight")}if(t.data("slider-animate")!=null){r.animate=t.data("slider-animate")}return t.simpleSlider(r)})})})(this.jQuery||this.Zepto,this)
\ No newline at end of file
var layoutOptions = {
name: 'cose-bilkent',
tile: true,
animate: 'during',
refresh: 60
};
function TableNetwork(active_table_element, other_table_element, network_element) {
this.activeTable = $(active_table_element).DataTable({
searching: false,
columnDefs: [{
orderable: false,
className: 'select-checkbox',
targets: 0,
data: null,
defaultContent: ""
}, {
data: 'gene',
targets: 1
}],
select: {
style: "os",
},
rowId: "id",
order: [[1, 'asc']]
});
this.otherTable = $(other_table_element).DataTable({
searching: false,
columnDefs: [{
orderable: false,
className: 'select-checkbox',
targets: 0,
data: null,
defaultContent: ""
}, {
data: 'gene',
targets: 1
}, {
data: 'network',
targets: 2
}],
select: {
style: "os",
},
rowId: "id",
order: [[1, 'asc']]
});
$(`${active_table_element} thead th, ${other_table_element} thead th`).each(function() {
if ($(this).index() != 0) {
var title = $(this).text();
$(this).html(title + '</br><input id="' + title.toLowerCase() +
'_index" type="text" placeholder="Search ' + title.toLowerCase() + '">');
}
});
this.cy = cytoscape({
container: $(network_element),
style: [
{
selector: 'node.active',
style: {
'background-color': '#eafff5'
}
}, {
selector: 'node',
style: {
content: 'data(label)'
}
}, {
selector: 'node.network',
style: {
'font-size': '3em'
}
}, {
selector: 'edge.orthology',
style: {
'line-style': 'dashed',
'label': 'data(conservation_pvalue)',
'display': 'none'
}
}
],
userZoomingEnabled: false,
boxSelectionEnabled: true
});
this.cy.panzoom({
});
this.networkLayout = this.cy.layout(layoutOptions);
var self = this;
var networkSelect = false;
var tableSelect = false;
this.cy.on('select', 'node', function(e) {
if (tableSelect) {
tableSelect = true;
return;
}
networkSelect = true;
var nodeId = e.target.data('id');
if (e.target.data('parent') === `network${self.activeNetworkID}`) {
self.activeTable.row(`#${nodeId}`).select();
} else {
self.otherTable.row(`#${nodeId}`).select();
}
// Display orthology edges
e.target.connectedEdges('.orthology').style('display', 'element');
});
this.cy.on('unselect', 'node', function(e) {
if (tableSelect) {
tableSelect = false;
return;
}
networkSelect = true;
var nodeId = e.target.data('id');
if (e.target.data('parent') === `network${self.activeNetworkID}`) {
self.activeTable.row(`#${nodeId}`).deselect();
} else {
self.otherTable.row(`#${nodeId}`).deselect();
}
// Hide ortholog edges
e.target.connectedEdges('.orthology').style('display', 'none');
});
var networkSelectionFromTable = function(e, dt, type, fromActiveTable) {
if (networkSelect) {
networkSelect = false;
return;
}
tableSelect = true;
if (type === "row") {
var nodeIds = dt.rows({selected: true}).ids().toArray();
if (fromActiveTable) {
self.cy.nodes(`[id = "network${self.activeNetworkID}"]`).children().deselect();
} else {
self.cy.nodes(`[id != "network${self.activeNetworkID}"]`).children().deselect();
}
self.cy.nodes().filter(function(x) {
return $.inArray(x.data('id'), nodeIds) !== -1;
}).select();
}
tableSelect = false;
}
this.activeTable.on('select', function(e, dt, type) {
networkSelectionFromTable(e, dt, type, true);
});
this.activeTable.on('deselect', function(e, dt, type) {
networkSelectionFromTable(e, dt, type, true);
});
this.otherTable.on('select', function(e, dt, type) {
networkSelectionFromTable(e, dt, type, false);
});
this.otherTable.on('deselect', function(e, dt, type) {
networkSelectionFromTable(e, dt, type, false);
});
this.add_network = function(networkID) {
}
this.set_data = function(data, activeNetwork) {
this.cy.elements().remove();
this.data = data;
this.activeNetworkID = activeNetwork;
this.cy.add(this.data);
self.networkLayout = self.cy.elements('node, edge.co-expression').layout(layoutOptions);
self.networkLayout.run();
this.activeTable.clear();
var activeTableData = $.grep(this.data.nodes, function(x) {
return x.classes.match(/gene/) !== null && x.data.parent === `network${activeNetwork}`;
}).map(function(x) {
return {
gene: x.data.label,
id: x.data.id,
network: x.data.parent
};
});
this.activeTable.rows.add(activeTableData).draw();
this.otherTable.clear();
var otherTableData = $.grep(this.data.nodes, function(x) {
return x.classes.match(/gene/) !== null && x.data.parent !== `network${activeNetwork}`;
}).map(function(x) {
return {
gene: x.data.label,
id: x.data.id,
network: x.data.parent
};
});
this.otherTable.rows.add(otherTableData).draw();
};
this.highlightOrthologs = function(id, secondNetworkID) {
$.ajax({
url: 'service/orthologs.php',
method: 'POST',
data: {
gene_id: Array.isArray(id) ? id : [id],
network_id1: this.data.id,
network_id2: secondNetworkID
},
dataType: 'json',
success: function(data, textStatus, jqXHR) {
console.log(data);
},
error: function(jqXHR, textStatus) {
console.error(jqXHR.responseJSON.error);
}
});
}
}
......@@ -2,11 +2,22 @@ var firsttable;
var secondtable;
var table_options = {
searching: false
searching: false,
columns: [
{
data: "selected",
render: function(data, type, row, meta) {
var checkbox = '<input type="checkbox" value="' +
data.id + '" ' + (data.is_selected ? ' checked' : '') + '/>';
return type === 'display' ? checkbox : data;
}
},
{data: "gene"}
]
};
function ComplexTable(element) {
this.datatable = $(element).dataTable(table_options);
this.datatable = $(element).DataTable(table_options);
$(element + " thead th").each(function() {
if ($(this).index() != 0) {
var title = $(this).text();
......@@ -15,7 +26,19 @@ function ComplexTable(element) {
});
this.set_data = function(data) {
return;
this.datatable.clear();
var table_data = $.grep(data, function(x) {
return x.group === 'nodes';
}).map(function(x) {
return {
selected: {
is_selected: typeof(x.selected) == "undefined" ? false : x.selected,
id: x.data.id
},
gene: x.data.label
};
});
this.datatable.rows.add(table_data).draw();
};
}
......
......@@ -4,16 +4,6 @@ require_once("../db.php");
require("array_column.php");
$execution_time = microtime(true);
function build_in_array($key_prefix, $a) {
return array_combine(
array_map(
function ($v) use (&$key_prefix) {
return ":{$key_prefix}_{$v}";
},
array_keys($a)
), $a);
}
if ($tmp_op == 'expand'){
try {
$in_params = build_in_array('name', $gsel1);
......@@ -225,7 +215,7 @@ foreach ($network2 as $edge) {
}
echo json_encode(array(
'network1' => $network1_out,
'network2' => $network2_out,
'network1' => array('id' => $tmp_sp1, 'network' => $network1_out),
'network2' => array('id' => $tmp_sp2, 'network' => $network2_out),
'execution_time' => $execution_time
));
<?php
require_once('../db.php');
$method = isset($_POST['method']) ? $_POST['method'] : 'get_network';
$network_ids = isset($_POST['network_ids']) ? $_POST['network_ids'] : null;
$active_network = isset($_POST['active_network']) ? $_POST['active_network'] : null;
$gene_ids = isset($_POST['gene_ids']) ? $_POST['gene_ids'] : null;
$gene_names = isset($_POST['gene_names']) ? $_POST['gene_names'] : null;
$threshold = isset($_POST['threshold']) ? floatval($_POST['threshold']) : null;
if (is_null($network_ids)) {
http_response_code(400);
echo json_encode(array('error' => 'no network id given'));
exit(1);
}
if (is_null($active_network)) {
http_response_code(400);
echo json_encode(array('error' => 'there is no active network'));
exit(1);
}
if (is_null($gene_ids) && is_null($gene_names)) {
http_response_code(400);
echo json_encode(array('error' => 'no gene ids or names given'));
exit(1);
}
if (is_null($threshold)) {
http_response_code(400);
echo json_encode(array('error' => 'no threshold specified'));
exit(1);
}
function get_network($network_ids, $active_id, $gene_names, $threshold) {
global $db;
$network_name_query = 'SELECT id, name FROM network WHERE id IN ('.prepare_in('network', $network_ids).')';
$stmt = $db->prepare($network_name_query);
$stmt->execute(build_in_array('network', $network_ids));
$res = $stmt->fetchAll(PDO::FETCH_ASSOC);
$networks = array();
foreach ($res as $n) {
$networks[$n['id']] = $n['name'];
}
$gene_query = 'SELECT id, name FROM gene WHERE name IN ('.prepare_in('gene', $gene_names).')';
$stmt = $db->prepare($gene_query);
$stmt->execute(build_in_array('gene', $gene_names));
$genes = $stmt->fetchAll(PDO::FETCH_ASSOC);
$gene_ids = array_map(function($x) { return $x['id']; }, $genes);
// Get the orthologs in the other networks
$network_orthologs = array();
$ortholog_edges = array();
foreach ($network_ids as $id) {
if ($id === $active_id) {
continue;
}
$ortho_query = 'SELECT
c.gene_id1 AS g1,
c.gene_id2 AS g2,
g2.name AS g2_name,
c.pvalue AS pvalue,
CONCAT(COALESCE(o1.type, ""), COALESCE(o2.type, "")) AS support
FROM conservation AS c
LEFT OUTER JOIN gene AS g2
ON g2.id = c.gene_id2
LEFT OUTER JOIN orthology AS o1
ON o1.gene_id1 = c.gene_id1 AND o1.gene_id2 = c.gene_id2
LEFT OUTER JOIN orthology AS o2
ON o2.gene_id1 = c.gene_id2 AND o2.gene_id2 = c.gene_id1
WHERE c.network_id2 = :network_id
AND c.gene_id1 IN ('.prepare_in('gene', $gene_ids).')';
$params = array_merge(array(':network_id' => $id), build_in_array('gene', $gene_ids));
$stmt = $db->prepare($ortho_query);
$stmt->execute($params);
$ortho_res = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($ortho_res as $or) {
$network_orthologs[$id][$or['g2']] = array(
'gene_id' => $or['g2'],
'gene_name' => $or['g2_name']
);
$ortholog_edges[] = array(
'group' => 'edges',
'data' => array(
'source' => $or['g1'],
'target' => $or['g2'],
'conservation_pvalue' => $or['pvalue'],
'support' => $or['support']
),
'classes' => 'orthology'
);
}
}
$params = array_merge(
array(':network_id' => $active_id, ':threshold' => $threshold),
build_in_array('gene', $gene_ids)
);
$query = 'SELECT gene_id1, g1.name AS gene1, gene_id2, g2.name AS gene2, score
FROM network_score
LEFT OUTER JOIN gene AS g1
ON g1.id = gene_id1
LEFT OUTER JOIN gene AS g2
ON g2.id = gene_id2
WHERE network_id = :network_id
AND gene_id1 IN ('.prepare_in('gene', $gene_ids).')
AND gene_id2 IN ('.prepare_in('gene', $gene_ids).')
AND score > :threshold';
$stmt = $db->prepare($query);
$stmt->execute($params);
$active_edges = $stmt->fetchAll(PDO::FETCH_ASSOC);
$nodes = array_merge(
array(
array(
'group' => 'nodes',
'data' => array(
'id' => 'network'.$active_id,
'label' => $networks[$active_id]
),
'classes' => 'network active',
'selectable' => false
)
),
array_map(function($x) use (&$active_id) {
return array(
'group' => 'nodes',
'data' => array(
'id' => intval($x['id']),
'label' => $x['name'],
'parent' => 'network'.$active_id
),
'classes' => 'gene'
);
}, $genes)
);
$edges = array_map(function($x) {
return array(
'group' => 'edges',
'data' => array(
'source' => intval($x['gene_id1']),
'target' => intval($x['gene_id2']),
'weight' => floatval($x['score'])
),
'classes' => 'co-expression'
);
}, $active_edges);
// Get the edges among the orthologs in the other selected networks
foreach ($network_orthologs as $id => $ortho_genes) {
if ($id == $active_id) {
continue;
}
$ortho_gene_ids = array_keys($ortho_genes);
$edge_query = 'SELECT
gene_id1,
gene_id2,
score
FROM network_score
WHERE network_id = :network_id
AND gene_id1 IN ('.prepare_in('gene', $ortho_gene_ids).')
AND gene_id2 IN ('.prepare_in('gene', $ortho_gene_ids).')
AND score > :threshold';
$params = array_merge(
array(':network_id' => $id, ':threshold' => $threshold),
build_in_array('gene', $ortho_gene_ids)
);
$stmt = $db->prepare($edge_query);
$stmt->execute($params);
$ortho_edges = $stmt->fetchAll(PDO::FETCH_ASSOC);
$nodes = array_merge(
$nodes,
array(
array(
'group' => 'nodes',
'data' => array(
'id' => 'network'.$id,
'label' => $networks[$id]
),
'classes' => 'network',
'selectable' => false
)
), array_map(function($x) use (&$id) {
return array(
'group' => 'nodes',
'data' => array(
'id' => intval($x['gene_id']),
'label' => $x['gene_name'],
'parent' => 'network'.$id
),
'classes' => 'gene'
);
}, $ortho_genes)
);
$edges = array_merge(
$edges,
array_map(function($x) {
return array(
'group' => 'edges',
'data' => array(
'source' => intval($x['gene_id1']),
'target' => intval($x['gene_id2']),
'weight' => floatval($x['score'])
),
'classes' => 'co-expression'
);
}, $ortho_edges)
);
}
echo json_encode(array('nodes' => $nodes, 'edges' => array_merge($edges, $ortholog_edges)));
}
function expand() {
}
switch ($method) {
case 'get_network':
get_network($network_ids, $active_network, $gene_names, $threshold);
break;
case 'expand':
expand();
break;
default:
http_response_code(400);
echo json_encode(array('error' => 'invalid method '.$method));
exit(1);
break;
}
?>