Example of TnT Genome that shows genes and transcripts in the same track, but transcripts only for a specific gene. This is done by getting the default data retriever for the gene track (which is a promise) and set a new retriever that chains the original one with a function that retrieves all the transcripts (exons, etc) only for the specific gene (PTEN in this case).
Last active
January 12, 2016 16:45
-
-
Save emepyc/2a3dd22933aa8cf4055f to your computer and use it in GitHub Desktop.
Genes and transcripts
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
<!DOCTYPE html> | |
<head> | |
<link rel="stylesheet" href="http://tntvis.github.io/tnt.genome/build/tnt.genome.css" type="text/css" /> | |
<style> | |
#mydiv { | |
margin-top: 50px; | |
} | |
</style> | |
<script src="http://d3js.org/d3.v3.min.js"></script> | |
<script src="http://tntvis.github.io/tnt.genome/build/tnt.genome.min.js"></script> | |
<script src="render.js"></script> | |
</head> | |
<body> | |
<div id="mydiv"></div> | |
<script> | |
render(document.getElementById("mydiv")); | |
</script> | |
</body> |
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
var thisGene = "PTEN"; | |
var render = function (div) { | |
var mixed_track = tnt.board.track() | |
.height(200) | |
.color("#EEEFFF") | |
.display(tnt.board.track.feature.genome.transcript() | |
.color (function (t) { | |
if (t.isGene) { | |
return "#005588"; | |
} | |
return "red"; | |
}) | |
.on("click", function (d) { | |
console.log(d); | |
}) | |
); | |
var mixed_data = tnt.board.track.data.genome.gene(); | |
var eRest = tnt.board.track.data.genome.ensembl; | |
var gene_updater = mixed_data.retriever(); | |
mixed_data.retriever (function (loc) { | |
return gene_updater.call(mixed_track, loc) | |
.then (function (genes) { // genes | |
for (var i=0; i<genes.length; i++) { | |
genes[i].key = genes[i].id; | |
genes[i].isGene = true; | |
genes[i].exons = [{ | |
start: genes[i].start, | |
end: genes[i].end, | |
coding: true, | |
offset: 0, | |
isGene: true | |
}]; | |
} | |
var url = eRest.url() | |
.endpoint("xrefs/symbol/:species/:symbol") | |
.parameters({ | |
species: "human", | |
symbol: thisGene | |
}); | |
return eRest.call(url) | |
.then (function (resp) { | |
var ensId = resp.body[0].id; | |
return ensId; | |
}) | |
.then (function (ensId) { | |
var url = eRest.url() | |
.endpoint("lookup/id/:id") | |
.parameters({ | |
id: ensId, | |
expand: true | |
}); | |
return eRest.call(url); | |
}) | |
.then (function (resp) { // transcripts + exons | |
var g = resp.body; | |
var tss = tnt.board.track.data.genome.transcript().gene2Transcripts(g); | |
genes = genes.concat(tss); | |
return genes; | |
}); | |
}); | |
}); | |
mixed_track | |
.data(mixed_data); | |
var genome = tnt.board.genome().species("human").gene(thisGene).width(950); | |
genome(div); | |
genome | |
.zoom_in(100) | |
.add_track(mixed_track); | |
genome.start(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment