Published
Edited
Dec 8, 2021
Insert cell
Insert cell
Insert cell
select_gene
Insert cell
gene_options = ['none'].concat(Object.keys(gene_colors))
Insert cell
viewof select_gene_dropdown = select({'options':gene_options, value: 'none'})
Insert cell
mutable select_gene = select_gene_dropdown
Insert cell
Insert cell
transcript_data.map(x => x.name).filter((v, i, a) => a.indexOf(v) === i)
Insert cell
gene_colors = ({'Ddr1': 'purple',
'Glp2r': 'blue',
'Gpr182': 'blue',
'Sstr4': 'orange',
'Th': 'green',
'Trhr': 'red'})
Insert cell
transcript_data_ini = JSON.parse(decode_zipped_string(zip_string))
Insert cell
zip_string = FileAttachment("transcripts_zip_string@1.txt").text()
Insert cell
pako = require('pako/dist/pako.min.js')
Insert cell
container = html `<div style="height:${height}px; border-style:solid; border-color:#d3d3d3; border-width:1px"></div>`
Insert cell
Insert cell
transcript_data = transcript_data_ini.map(d => {

var inst_color_name = gene_colors[d.name]
var rgb = d3.color(inst_color_name)
var inst_color = [rgb.r, rgb.g, rgb.b] // 255

var new_obj = ({
'': d[''],
'name': d.name,
'position': eval(d.position),
'color': inst_color
})
return new_obj
})

// transcript_data = transcript_data_ini
Insert cell
Insert cell
radius = 0.5
Insert cell
radius_min_pixels = 1.5
Insert cell
transitionDuration = 3000
Insert cell
transitions = ({
getPosition: {
duration:transitionDuration,
easing: d3.easeCubic
}
})
Insert cell
rgb = d3.color('red')
Insert cell
inst_color = [rgb.r, rgb.g, rgb.b, 255]
Insert cell
Object.keys(gene_colors)
Insert cell
select_gene
Insert cell
transcript_layer = new deck.ScatterplotLayer({
id: 'transcript_layer',
data: transcript_data,
pickable: is_pickable,
getPosition: d => d.position,

getFillColor: d => {
var inst_color
var unselected_color = [0, 0, 0, 0]
// allow transcript color filtering
if (select_gene === 'none'){
inst_color = d.color
} else {
inst_color = unselected_color
// check gene name
if (d.name === select_gene){
inst_color = d.color

}
}
return inst_color
},
getRadius: transcript_radius,
radiusMinPixels: transcript_radius,
pickable: true,
opacity: transcript_opacity,
visible: visible_transcripts,
updateTriggers: {
getFillColor: select_gene,
},
onClick: (info, event) => {
if (select_gene !== info.object.name){
mutable select_gene = info.object.name
d3.select('#meta_dropdown').select('select').node().value = info.object.name
} else {
mutable select_gene = 'none'
d3.select('#meta_dropdown').select('select').node().value = 'none'
}
}
})
Insert cell
mutable visible_transcripts = true
Insert cell
select_gene
Insert cell
// mutable select_gene = 'none'
Insert cell
layers = [transcript_layer]
Insert cell
is_pickable = true
Insert cell
deckgl.setProps({layers: layers});
Insert cell
view = new deck.OrthographicView({id: 'ortho'})
Insert cell
function ini_deckgl(container){
var deckgl =
new deck.DeckGL({
container,
views:[view],
initialViewState: initial_view_state,
controller: {doubleClickZoom: false},
// getTooltip: ({object}) => {
// return object &&
// `${object['name']}`
// // `pos: ${object.x}, ${object['y']}\n`
// },
getTooltip: ({object}) => object && {
html: `${object.name}`,
style: {
fontSize: '0.8em',
padding: '5px',
}
},
// onViewStateChange: ({viewState}) => {
// debounced_something(viewState)
// return viewState
// },
// onClick: ({info}) => {
// console.log(info)
// return info
// }
});
return deckgl
}
Insert cell
deckgl = ini_deckgl(container)
Insert cell
// d3.max(transcript_data,
mean_x = d3.mean(transcript_data.map(x => x['position'][0]))
Insert cell
mean_y = d3.mean(transcript_data.map(x => x['position'][1]))
Insert cell
min_zoom = -5
Insert cell
zoom = -3.5
Insert cell
initial_view_state = ({
target: [mean_x, mean_y, 0],
zoom: zoom,
minZoom: min_zoom,
maxZoom:10
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
height = 800
Insert cell
Insert cell
detail_zoom_thresh = 1.25
Insert cell
visible_transcripts
Insert cell
mutable fovs = []
Insert cell
function decode_zipped_string(b64Data){
// Get some base64 encoded binary data from the server. Imagine we got this:
// Decode base64 (convert ascii to binary)
var strData = atob(b64Data);
// Convert binary string to character-number array
var charData = strData.split('').map(function(x){return x.charCodeAt(0);});
// Turn number array into byte-array
var binData = new Uint8Array(charData);
// Pako magic
var data = pako.inflate(binData);
// // Convert gunzipped byteArray back to ascii string:
// var strData = String.fromCharCode.apply(null, new Uint16Array(data));

// https://stackoverflow.com/questions/8936984/uint8array-to-string-in-javascript
var strData = new TextDecoder().decode(data);
// Output to console
// console.log(strData);
return strData
}
Insert cell
# Requirements
Insert cell
deck = require.alias({
// optional dependencies
h3: {}
})('deck.gl@latest/dist.min.js')
Insert cell
Insert cell
import {select} from '@jashkenas/inputs'
Insert cell
viewof transcript_radius = slider({
value: 0.75,
min: 0.1,
max: 2.0,
precision: 2,
description: "transcript size"
})
Insert cell
viewof transcript_opacity = slider({
value: 0.75,
min: 0.0,
max: 1.0,
precision: 2,
description: "transcript opacity"
})
Insert cell
d3 = require("d3@5")
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
deck
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more