-
-
Save nb1page/e6cc2e72f2267d601c25a83488c875e0 to your computer and use it in GitHub Desktop.
A minimal example of usage of the nb-dispatch Javascript library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width" /> | |
<title>An exmaple of nb-dispatch</title> | |
<!-- Load nb-dispatch library --> | |
<script src="https://unpkg.com/@nucleome/nb-dispatch"></script> | |
</head> | |
<body> | |
<p>This is a minimal example showing how to create a customized website to communicate with Nucleome Browser using <a href="https://github.com/nucleome/nb-dispatch">nb-dispatch</a></p> | |
<p>Open <a href="https://vis.nucleome.org" target="_blank">Nucleome Browser</a> </p> | |
<h3>Part I: Control Nucleome Browser</h3> | |
<p>Click the following buttons to goto centain genomic region or highligh multiple regions</p> | |
<div id="connection"></div> | |
<!-- Create two buttons. --> | |
<!-- Click the 'Navigate' button to navigate to target region --> | |
<button onclick="navigate()" >Navigate to chr1:0-10M </button> | |
<!-- Click the 'Highlight' button to highligh regions on the genome with color --> | |
<button onclick="highlight()"> Highlight multi-regions </button> | |
<h3>Part II: Monitor the operations of Nucleome Browser</h3> | |
<p>Navigate or highlight regions on Nucleome Browser and show the current genomic region or highlighted regions below</p> | |
<div> | |
Current genomic region | |
<div id="current" style="min-height:50px"></div> | |
</div> | |
<div> | |
Current highlighted region | |
<div id="current_highlight" style="min-height:50px"></div> | |
</div> | |
<script> | |
var chan = nb.dispatch("navigate","highlight") | |
chan.connect(function(d){ | |
document.getElementById("connection").innerHTML = d.connection | |
}) | |
var navigate = function(){ | |
chan.call("update",this,[{chr:"chr1",start:0,end:10000000}]) | |
} | |
var highlight = function() { | |
chan.call("brush",this,[{ | |
chr:"chr1",start:0,end:1000000,color:"red" | |
},{ | |
chr:"chr1",start:2000000,end:3000000,color:"orange" | |
},{ | |
chr:"chr1",start:4000000,end:5000000, color:"yellow" | |
},{ | |
chr:"chr1",start:6000000, end:7000000, color:"green" | |
},{ | |
chr:"chr1",start:8000000, end:9000000, color:"blue" | |
}]) | |
} | |
var regionText = function (d) { | |
return d.chr + ":" + (d.start+1) + "-" + d.end; | |
}; | |
var regionsText = function (regions) { | |
var r = []; | |
regions.forEach(function (d) { | |
r.push(regionText(d)); | |
}); | |
return r.join(","); | |
}; | |
var a = nb.dispatch("update","brush") | |
a.connect(function(d){ | |
document.getElementById("connection").innerHTML = d.connection | |
}) | |
a.on("update",function(d){ | |
document.getElementById("current").innerHTML=regionsText(d) | |
}) | |
a.on("brush",function(d){ | |
document.getElementById("current_highlight").innerHTML=regionsText(d) | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment