Skip to content

Instantly share code, notes, and snippets.

@bherr2
Last active January 13, 2021 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bherr2/51b9b8e8276f2b2bec7863208150ff68 to your computer and use it in GitHub Desktop.
Save bherr2/51b9b8e8276f2b2bec7863208150ff68 to your computer and use it in GitHub Desktop.
HuBMAP CCF Registrations
license: MIT
height: 700
scrolling: no
border: yes

HuBMAP CCF Registrations

Report for HuBMAP Data that have CCF "rui locations". See https://hubmapconsortium.github.io/ccf/ for more information.

Access to my data

To access your data, grab your API key and set it using localStorage.setItem('HUBMAP_KEY', 'my-key-goes-here') from the developer console and refresh. Note that keys expire and may cause the query to fail after a while. In that case, simply update the key above or delete it via the developer console.

<!doctype html>
<html lang="en">
<head>
<title>HuBMAP CCF Registrations</title>
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@4"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
</head>
<body>
<div id="visualization" style="width: 920px; height: 600px;"></div>
<script type="text/javascript">
const searchUri = "https://search.api.hubmapconsortium.org/entities/search";
// const searchUri = 'https://search-api.dev.hubmapconsortium.org/entities/search';
const postData = {
"credentials": "omit",
"headers": { "Content-type": "application/json" },
"body": "{\"version\":true,\"size\":10000,\"_source\":{\"excludes\":[\"donor\",\"immediate_ancestors\",\"immediate_descendants\",\"ancestor_ids\",\"descendant_ids\"]},\"stored_fields\":[\"*\"],\"script_fields\":{},\"docvalue_fields\":[],\"query\":{\"exists\":{\"field\":\"rui_location\"}}}",
"method": "POST"
};
if (localStorage.getItem('HUBMAP_KEY')) {
postData.headers.Authorization = 'Bearer ' + localStorage.getItem('HUBMAP_KEY');
}
fetch("vis.vl.json").then((result) => result.json()).then((spec) =>
fetch(searchUri, postData).then((result) => result.json()).then((jsonData) => {
// Embed the graph data in the spec for ease of use from Vega Editor
spec.datasets = {
data: jsonData.hits.hits.map(n => Object.assign({}, n._source, {
rui_location: JSON.parse(n._source.rui_location)
}))
};
console.log(spec.datasets.data);
return vegaEmbed("#visualization", spec, { "renderer": "svg", "actions": true });
})
).then((results) => {
console.log("Visualization successfully loaded");
});
</script>
</body>
</html>
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Report for HuBMAP CCF Registrations",
"autosize": {"type": "fit", "resize": true},
"config": {"view": {"strokeOpacity": 0}, "style": {"guide-label": {"width": 10}}},
"vconcat": [
{
"hconcat": [
{
"mark": {"type": "bar", "tooltip": {"content": "data"}},
"data": {"name": "data"},
"transform": [
{"calculate": "datum.origin_sample.organ", "as": "organ"}
],
"encoding": {
"x": {"aggregate": "count", "field": "organ"},
"y": {"field": "organ", "type": "nominal", "sort": "y", "title": "Organ Code"}
}
},
{
"mark": {"type": "bar", "tooltip": {"content": "data"}},
"data": {"name": "data"},
"transform": [
{"calculate": "datum.origin_sample.organ", "as": "organ"},
{"calculate": "datum.rui_location.ccf_annotations.length > 0 ? 1 : 0", "as": "num_as"}
],
"encoding": {
"x": {"aggregate": "sum", "field": "num_as", "title": "# Samples with Anatomical Structures"},
"y": {"field": "organ", "type": "nominal", "sort": "y", "title": "Organ Code"}
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment