Published
Edited
Apr 2, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
plot_tox21_data_for_all_compounds = function(array) {
var i;
var vl_array = [];
for (i = 0; i < array.length; i++) {
var data = array[i]["Results"];
var compound_name = array[i]["Compound"];
vl_array.push(
vl.markRect().data(data)
.encode(
vl.x({"grid": true}).fieldN("Dataset name"),
vl.color().fieldN("Hit call")
.legend({"orient": "left"})
.scale({
"type": "ordinal",
"domain": ["active", "inactive", "ambiguous"],
"range": ["#ff6f69", "#96ceb4", "#ffcc5c"]}),
vl.tooltip([
vl.fieldN("Dataset name"),
{
"field": "IC50",
"type": "quantitative",
"format": ",.2f"
},
vl.fieldN("Organism"),
vl.fieldN("Biological process")]),
).title({"text": compound_name + " (Tanimoto similarity: " + tox21_hits.filter(function(item) {return item["Substance name"] == compound_name})[0].SMILES.similarity + ")", "anchor": "start"})
);
}
return vl.vconcat(vl_array).render();
}
Insert cell
plot_drugmatrix_tggates_data_for_all_compounds = function(array, assay_hits) {
if (array.length < 1) {
return "No data to display";
} else {
var i;
var vl_array = [];

for (i = 0; i < array.length; i++) {
var data = array[i]["Actual datasets with sample names"];
var compound_name = array[i]["Compound"];

vl_array.push(
vl.markRect().data(data)
.encode(
vl.y().fieldN("Sample"),
vl.x().fieldN("SYMBOL"),
vl.color().fieldQ("logFC").legend({"orient": "left"}).scale({scheme: "lightmulti", reverse: false, zero: false}),
vl.tooltip([
vl.fieldN("Sample"),
{
"field": "logFC",
"type": "quantitative",
"format": ",.2f"
},
vl.fieldN("ENSEMBL"),
vl.fieldN("ENTREZID")]),
).title({"text": compound_name + " (Tanimoto similarity: " + assay_hits.filter(function(item) {return item["Compound"] == compound_name})[0].SMILES.similarity + ")", "anchor": "start"})
);
}

return vl.vconcat(vl_array).render();
}
}
Insert cell
reshaped_tox21_datasets_for_all_compounds = reshape_tox21_datasets_for_all_compounds(filtered_tox21_hits, selected_tox21_compounds)
Insert cell
tox21_similar_compounds= Array.from(new Set(filtered_tox21_hits.map(item => item["Substance name"])))
Insert cell
reshape_tox21_datasets_for_all_compounds = function(array_of_datasets, array_of_compounds) {
var i;
var arr = [];
var j;
var hitcall;
var ic50;
for (i = 0; i < array_of_compounds.length; i++) {
const compound = array_of_compounds[i];
var compound_datasets = array_of_datasets.filter(item => item["Substance name"] == compound);
var unique_compound_datasets = Array.from(new Set(compound_datasets.map(item => item["Summary data"])));
var results = [];
// loop over unique compound datasets and evaluate
for (j = 0; j < unique_compound_datasets.length; j++) {
const dataset_id = unique_compound_datasets[j];
const datasets = compound_datasets.filter(item => item["Summary data"] == dataset_id);
const hitcalls = datasets.map(item => item["Hit call"]);
const unique_hitcalls = Array.from(new Set(hitcalls));
const ic50_values = datasets.map(item => item["IC50"]);
if (unique_hitcalls.length > 1) {
hitcall = "ambiguous";
} else {
hitcall = unique_hitcalls[0];
};
if (hitcall == "active") {
const arrSum = ic50_values => ic50_values.reduce((a,b) => a + b, 0);
ic50 = arrSum / (ic50_values.length);
} else {
ic50 = null;
}
const dataset_object = datasets[0];
if (colors.includes(hitcall)) {
results.push({
"Hit call": hitcall,
"Organism": dataset_object["Organism"],
"Cell type": dataset_object["Cell type"],
"Design type": dataset_object["Design Type"],
"Target type": dataset_object["Target type"],
"Target family": dataset_object["Target family"],
"Biological process": dataset_object["Biolological process"],
"Dataset name": dataset_object["Dataset name"].replace("EPA-InVitroDBV3.2-", "").replace("_", " "),
"IC50": ic50,
});
}
};
var compound_object = {
"Compound": compound,
"Results": results,
};
arr.push(compound_object);
}

return arr;
}
Insert cell
filtered_tox21_hits = tox21_hits
.filter(item => selected_cell_types.includes(item["Cell type"]))
.filter(item => selected_target_types.includes(item["Target type"]))
.filter(item => selected_target_families.includes(item["Target family"]))
Insert cell
target_families = Array.from(new Set(tox21_hits.map(item => item["Target family"])))
Insert cell
target_types = Array.from(new Set(tox21_hits.map(item => item["Target type"])))
Insert cell
selected_cell_types = selected_cell_types_with_descriptions.map(item => item.split(" ")[0])
Insert cell
cell_types_with_descriptions = [
"C3H10T1/2 (Mouse mesenchymal cell line)",
"CHO-K1 (Chinese Hamster Ovary cell line)",
"DT40 (Chicken bursal lymphoma cell line)",
"ERR-HEK293T (Human embryonic kidney 293 cell line)",
"GH3 (Rat pituitary tumor cell line)",
"HCT-116 (Human colon carcinoma cell line)",
"HEK293 (Human embryonic kidney 293 cell line)",
"HEK293T (Human embryonic kidney 293 cell line)",
"HeLa (Human epithelial cell line)",
"HepG2 (Human hepatocellular carcinoma cell line)",
"MCF-7 (Human breast cancer cell line)",
"MDA-kb2 (Human breast cancer cell line)",
"ME-180 (Human epithelial cell line)",
"NIH/3T3 (Mouse embryo fibroblast cell line)",
"PGC/ERR HEK293T (Human embryonic kidney 293 cell line)",
"PR-UAS-bla-HEK293T (Human embryonic kidney 293 cell line)",
"VM7 (Human breast cancer cell line)",
]
Insert cell
cell_types = cell_types_with_null.filter(item => item != null).sort()
Insert cell
cell_types_with_null = Array.from(new Set(tox21_hits.map(item => item["Cell type"])))
Insert cell
reshaped_tggates_datasets_for_all_compounds = reshape_datasets_for_all_compounds(tggates_datasets_for_all_compounds, selected_tggates_compounds)
Insert cell
reshaped_drugmatrix_datasets_for_all_compounds = reshape_datasets_for_all_compounds(drugmatrix_datasets_for_all_compounds, selected_drugmatrix_compounds)
Insert cell
reshape_datasets_for_all_compounds = function(array_of_compound_datasets, array_of_compounds) {
var i;
var arr = [];
for (i = 0; i < array_of_compound_datasets.length; i++) {
var compound_object = array_of_compound_datasets[i];
var compound = compound_object.Compound;
if (array_of_compounds.includes(compound)) {
var compound_samplenames = compound_object["Sample names"];
var compound_datasets = compound_object["Actual datasets"];
var compound_datasets_with_samplenames = [];

// loop over datasets for this compound
var j;
for (j = 0; j < compound_datasets.length; j++) {
var dataset = compound_datasets[j];

var dataset_with_samplename = dataset.map(item => {
item["Sample"] = compound_samplenames[j];
return item
})

compound_datasets_with_samplenames.push(dataset_with_samplename);
}

compound_object["Actual datasets with sample names"] = [].concat(...compound_datasets_with_samplenames);
arr.push(compound_object);
}
}
return arr;
}
Insert cell
tggates_datasets_for_all_compounds = get_promised_fold_changes_datasets_for_all_compounds(reshaped_tggates_hits)
Insert cell
drugmatrix_datasets_for_all_compounds = get_promised_fold_changes_datasets_for_all_compounds(reshaped_drugmatrix_hits)
Insert cell
get_datasets_from_promises = function(array_of_promises) {
return Promise.all(array_of_promises).then(item => item.map(dataset => dataset.results.map(row => row.data)))
}
Insert cell
get_promised_fold_changes_datasets_for_all_compounds = async function(array) {
var i;
var new_array = [];
for (i = 0; i < array.length; i++) {
var object = array[i];
const promised_datasets = get_promised_fold_changes_datasets(object["Fold changes datasets"]);
object["Promised datasets"] = promised_datasets;
object["Actual datasets"] = await get_datasets_from_promises(promised_datasets);
new_array.push(object);
}
return new_array;
}
Insert cell
get_promised_fold_changes_datasets = function(array_of_datasets) {
return array_of_datasets.map(dataset => {
return fetch(base_url_edelweiss + dataset + "/versions/latest/data", query_options_for_fold_changes).then(response_dataset => {
if (!response_dataset.ok) throw new Error(response_dataset.status);
return response_dataset.json();
})
})
}
Insert cell
query_options_for_fold_changes = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
or: [
{lt: [{column: ["logFC"]}, -logfc_threshold]},
{gt: [{column: ["logFC"]}, logfc_threshold]},
]
},
columns: ["logFC", "SYMBOL", "ENSEMBL", "ENTREZID"]
})
}
}
Insert cell
reshaped_tggates_hits = reshape_tggates_hits(tggates_hits, tggates_unique_compounds)
Insert cell
reshape_tggates_hits = function(array_of_datasets, compounds) {
var arr = [];
compounds.forEach(compound => {
var compound_datasets = array_of_datasets.filter(object => object["Compound"] == compound);
var unique_compound_datasets = function_get_unique_fold_changes_datasets(compound_datasets);
var i;
var sample_names = [];
for (i = 0; i < unique_compound_datasets.length; i++) {
var dataset_id = unique_compound_datasets[i];
var obj = array_of_datasets.filter(item => item["Dataset ID"] == dataset_id)[0];
var sample_name = obj["Organism"] + " / " + obj["Study type"] + " / " + obj["Organ"] + " / " + obj["Dosing"] + " / " + obj["Dose"] + " / " + obj["Duration"] + " " + obj["Duration unit"];
sample_names.push(sample_name);
}
arr.push({
"Compound": compound,
"Fold changes datasets": unique_compound_datasets,
"Sample names": sample_names
})
});
return arr;
}
Insert cell
reshaped_drugmatrix_hits = reshape_drugmatrix_hits(drugmatrix_hits, drugmatrix_unique_compounds)
Insert cell
reshape_drugmatrix_hits = function(array_of_datasets, compounds) {
var arr = [];
compounds.forEach(compound => {
var compound_datasets = array_of_datasets.filter(object => object["Compound"] == compound);
var unique_compound_datasets = function_get_unique_fold_changes_datasets(compound_datasets);
var i;
var sample_names = [];
for (i = 0; i < unique_compound_datasets.length; i++) {
var dataset_id = unique_compound_datasets[i];
var obj = array_of_datasets.filter(item => item["Dataset ID"] == dataset_id)[0];
var sample_name = obj["Strain"] + " / " + obj["Route"] + " / " + obj["Organ or cell type"] + " / " + obj["Dose"] + " " + obj["Dose unit"] + " / " + obj["Duration"] + " " + obj["Duration unit"];
sample_names.push(sample_name);
}
arr.push({
"Compound": compound,
"Fold changes datasets": unique_compound_datasets,
"Sample names": sample_names
})
});
return arr;
}
Insert cell
tox21_unique_compounds_similarities = tox21_unique_compounds.map(compound => {
return tox21_hits.filter(item => item["Substance name"] == compound).map(item => item.SMILES.similarity)[0]
})
Insert cell
tox21_unique_svg = Promise.all(tox21_unique_smiles.map(smiles => function_get_svg_from_smiles(smiles)))
Insert cell
tox21_unique_smiles = tox21_unique_compounds.map(compound => {
return tox21_hits.filter(item => item["Substance name"] == compound).map(item => item.SMILES.canonical)[0]
})
Insert cell
tox21_unique_compounds = get_unique_compounds(tox21_hits, "Substance name")
Insert cell
tggates_unique_compounds_similarities = tggates_unique_compounds.map(compound => {
return tggates_hits.filter(item => item.Compound == compound).map(item => item.SMILES.similarity)[0]
})
Insert cell
tggates_unique_svg = Promise.all(tggates_unique_smiles.map(smiles => function_get_svg_from_smiles(smiles)))
Insert cell
tggates_unique_smiles = tggates_unique_compounds.map(compound => {
return tggates_hits.filter(item => item.Compound == compound).map(item => item.SMILES.canonical)[0]
})
Insert cell
tggates_unique_compounds = get_unique_compounds(tggates_hits, "Compound")
Insert cell
drugmatrix_unique_svg = Promise.all(drugmatrix_unique_smiles.map(smiles => function_get_svg_from_smiles(smiles)))
Insert cell
drugmatrix_unique_smiles = drugmatrix_unique_compounds.map(compound => {
return drugmatrix_hits.filter(item => item.Compound == compound).map(item => item.SMILES.canonical)[0]
})
Insert cell
drugmatrix_unique_compounds_similarities = drugmatrix_unique_compounds.map(compound => {
return drugmatrix_hits.filter(item => item.Compound == compound).map(item => item.SMILES.similarity)[0]
})
Insert cell
drugmatrix_hits.filter(item => item.Compound == drugmatrix_unique_compounds[0]).map(item => item.SMILES.canonical)[0]
Insert cell
drugmatrix_unique_compounds = get_unique_compounds(drugmatrix_hits, "Compound")
Insert cell
function_get_unique_fold_changes_datasets = function get_unique_fold_changes_datasets(array_of_datasets) {
var set_of_datasets = new Set(array_of_datasets.map(x => x["Dataset ID"]));
return Array.from(set_of_datasets).filter(function(item) {return item != null;})
}
Insert cell
get_unique_compounds = function(array_of_datasets, compound_name_column) {
var set_of_datasets = new Set(array_of_datasets.map(x => x[compound_name_column]));
return Array.from(set_of_datasets).filter(function(item) {return item != null;})
}
Insert cell
tox21_hits.filter(function(item) {return item["Substance name"] == "Zileuton"})[0].SMILES.similarity
Insert cell
tox21_hits = function_fetch_dataset_to_array(tox21_summary_url, query_options)
Insert cell
tggates_hits = function_fetch_dataset_to_array(tggates_summary_url, query_options)
Insert cell
drugmatrix_hits = function_fetch_dataset_to_array(drugmatrix_summary_url, query_options)
Insert cell
function_fetch_dataset_to_array = function fetch_dataset_to_array(dataset_url, query_options) {
return fetch(dataset_url, query_options).then(response_dataset => {
if (!response_dataset.ok) throw new Error(response_dataset.status);
return response_dataset.json();}).then(json => json.results.map(x => x.data));
}
Insert cell
tox21_summary_url = base_url_edelweiss + tox21_summary_id + "/versions/latest/data"
Insert cell
tggates_summary_url = base_url_edelweiss + tggates_summary_id + "/versions/latest/data"
Insert cell
drugmatrix_summary_url = base_url_edelweiss + drugmatrix_summary_id + "/versions/latest/data"
Insert cell
tox21_summary_id = "8cc0534a-5e52-4253-a736-40f616b84a41"
Insert cell
tggates_summary_id = '16a4418e-01ff-4dcd-9b2d-90ef00565655'
Insert cell
drugmatrix_summary_id = '9c1c25e0-2943-4c36-9123-ccbb1f4ef2ae'
Insert cell
base_url_edelweiss = 'https://api.kit.edelweissconnect.com/datasets/'
Insert cell
query_options = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
gt: [{tanimotoSimilarity: [smiles, { column: ["SMILES"] }]}, tanimoto_threshold]
},
orderBy: [
{expression: {tanimotoSimilarity: [smiles, { column: ["SMILES"] }]}, ordering: "descending"}
]
})
}
}
Insert cell
svg = function_get_svg_from_smiles(smiles)
Insert cell
function_get_svg_from_smiles = function get_svg_from_smiles(smiles) {
const safeSmiles = encodeURIComponent(smiles);
const svg_url = "https://chemidconvert.cloud.douglasconnect.com/v1/asSvg?width=200&height=200&smiles=" + safeSmiles;
return fetch(svg_url).then(response => response.text());
}
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell
import {select, textarea, text, slider} from "@jashkenas/inputs"
Insert cell
import {Select, Checkbox} from "@observablehq/inputs"
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