Public
Edited
Jun 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
ccfOpenapiClient = import("https://cdn.skypack.dev/@ccf-openapi/js-client@1.1.2");
Insert cell
Insert cell
host = "https://ccf-api.hubmapconsortium.org/v1";
Insert cell
apiClient = new ccfOpenapiClient.ApiClient(host);
Insert cell
apiInstance = new ccfOpenapiClient.DefaultApi(apiClient);
Insert cell
Insert cell
status = await apiInstance.dbStatus();
Insert cell
Insert cell
Insert cell
// Result from Scene API
sceneResult = {
return apiInstance.scene({
'ontologyTerms': ["http://purl.obolibrary.org/obo/UBERON_0002113",],
'cellTypeTerms': ["http://purl.obolibrary.org/obo/CL_0000000",],
'sex': "both"
});
}
Insert cell
Insert cell
// Convert Scene
sceneEntityASDict = {
let sceneEntityASDict = {};
for (let scene of sceneResult) {
if (scene.hasOwnProperty('entityId')) {
if (!(scene['entityId'] in sceneEntityASDict)) {
sceneEntityASDict[scene['entityId']] = [];
}
sceneEntityASDict[scene['entityId']].push(...scene['ccf_annotations']);
}
}
return sceneEntityASDict;
}
Insert cell
queryParam = {
let purlIris = new Set();
// Collecting all unique AS iri's
for (let k in sceneEntityASDict) {
for (let v of sceneEntityASDict[k]) {
purlIris.add(v);
}
}

let purlString = [...purlIris].map(s => `<${s}>`).join(", ");
return purlString;
}
Insert cell
Insert cell
queryResponse = {
let query = `PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ccf: <http://purl.org/ccf/>

SELECT DISTINCT (STR(?asLabel) as ?as_label) (STR(?qlabel) as ?cell_label) ?as_iri ?cell_iri WHERE {
?cell_iri ccf:ccf_located_in ?as_iri .
?cell_iri rdfs:label ?qlabel .
?as_iri rdfs:label ?asLabel .

FILTER (?as_iri in (${queryParam}))
}`
return apiInstance.sparql(query);
}
Insert cell
Insert cell
function reverseObject(input_object) {
let reversed_object = {};

for (let key in input_object) {
let values = input_object[key];
for (let value of values) {
if (value in reversed_object) {
reversed_object[value].push(key);
} else {
reversed_object[value] = [key];
}
}
}
return reversed_object;
}
Insert cell
ASEntityDict = reverseObject(sceneEntityASDict);
Insert cell
Insert cell
tissueBlockResult = {
return apiInstance.tissueBlocks({
'ontologyTerms': ["http://purl.obolibrary.org/obo/UBERON_0002113",],
'cellTypeTerms': ["http://purl.obolibrary.org/obo/CL_0000000",],
'sex': "both"
});
}
Insert cell
Insert cell
blockDonorLabel = {
let blockDonorLabel = {}
tissueBlockResult.forEach((ti) => {
blockDonorLabel[ti["@id"]] = ti["donor"]["label"]
});
return blockDonorLabel;
}
Insert cell
Insert cell
mergedData = {
let mergedData = [];
for (let response of queryResponse) {
let entity_ids = ASEntityDict[response['as_iri']];
for (let e of entity_ids) {
let new_response = Object.assign({}, response);
new_response['block_id'] = e;
new_response['donor_label'] = blockDonorLabel[e]
if (!mergedData.some(item => JSON.stringify(item) === JSON.stringify(new_response))) {
mergedData.push(new_response);
}
}
}
return mergedData;
}
Insert cell
counts = {
let ctCount = new Set(mergedData.map(o => o.cell_iri)).size;
let asCount = new Set(mergedData.map(o => o.as_iri)).size;
let blockCount = new Set(mergedData.map(o => o.block_id)).size;
const p = document.createElement("p");
p.appendChild(document.createElement("b")).appendChild(document.createTextNode("SUMMARY:"));
p.appendChild(document.createElement("br"));
p.appendChild(document.createTextNode("Number of Blocks: "+blockCount));
p.appendChild(document.createElement("br"));
p.appendChild(document.createTextNode("Number of Unique ASs identified: "+asCount));
p.appendChild(document.createElement("br"));
p.appendChild(document.createTextNode("Number of Unique CTs identified: "+ctCount));

return p;
}
Insert cell
mergedData
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
blob = new Blob([d3.csvFormat(mergedData)], {type: "text/csv"})
Insert cell
Insert cell
fileName = "exampleFileName"
Insert cell
DOM.download(blob, `${fileName}.csv`)
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