Published
Edited
Apr 2, 2022
2 forks
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
filtered_tox21_cells_targets = reshaped_tox21_datasets_for_all_compounds
.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(reshaped_tox21_datasets_for_all_compounds.map(item => item["Target family"])))
Insert cell
target_types = Array.from(new Set(reshaped_tox21_datasets_for_all_compounds.map(item => item["Target type"])))
Insert cell
cell_types = cell_types_with_null.filter(item => item != null).sort()
Insert cell
cell_types_with_null = Array.from(new Set(reshaped_tox21_datasets_for_all_compounds.map(item => item["Cell type"])))
Insert cell
reshaped_tggates_fold_changes = [].concat(...tggates_significant_fold_changes)
Insert cell
reshaped_drugmatrix_fold_changes = [].concat(...drugmatrix_significant_fold_changes)
Insert cell
tggates_significant_fold_changes.forEach((dataset, index_dataset) => get_fold_changes_with_samplenames(dataset, index_dataset, tggates_samples_array))
Insert cell
drugmatrix_significant_fold_changes.forEach((dataset, index_dataset) => get_fold_changes_with_samplenames(dataset, index_dataset, drugmatrix_samples_array))
Insert cell
get_fold_changes_with_samplenames = function(dataset, index_dataset, array_of_samplenames) {
dataset.forEach((row, index_row) => {
row["Sample"] = array_of_samplenames[index_dataset]
return row
})
return dataset
}
Insert cell
tggates_significant_fold_changes = get_datasets_from_promises(tggates_promised_fold_changes)
Insert cell
drugmatrix_significant_fold_changes = get_datasets_from_promises(drugmatrix_promised_fold_changes)
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_unique_sample_names = function(array_of_datasets, selected_datasets) {
var samplenames = [];
selected_datasets.forEach(dataset_id =>
{var samplename = array_of_datasets.filter(object => object["Dataset ID"] == dataset_id)[0]["Sample"]
samplenames.push(samplename)}
)
return samplenames;
}
Insert cell
tggates_samples_array = get_unique_sample_names(tggates_datasets_of_selected_compound, unique_tggates_fold_changes_datasets)
Insert cell
drugmatrix_samples_array = get_unique_sample_names(drugmatrix_datasets_of_selected_compound, unique_drugmatrix_fold_changes_datasets)
Insert cell
tggates_promised_fold_changes = get_promised_fold_changes_datasets(unique_tggates_fold_changes_datasets)
Insert cell
drugmatrix_promised_fold_changes = get_promised_fold_changes_datasets(unique_drugmatrix_fold_changes_datasets)
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_tox21 = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
exactSearch: [{column: ["DTXSID"]}, compound_dtxsid]
},
columns: ["DTXSID"]
})
}
}
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
unique_tggates_fold_changes_datasets = get_unique_fold_changes_datasets(tggates_datasets_of_selected_compound)
Insert cell
unique_drugmatrix_fold_changes_datasets = get_unique_fold_changes_datasets(drugmatrix_datasets_of_selected_compound)
Insert cell
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
Insert cell
reshaped_tox21_datasets_for_all_compounds = reshape_tox21_datasets_for_all_compounds(tox21_datasets_of_selected_compound_with_samplename)
Insert cell
reshape_tox21_datasets_for_all_compounds = function(array_of_datasets) {
var j;
var hitcall;
var ic50;
const unique_compound_datasets = Array.from(new Set(array_of_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 = array_of_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];

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["Biological process"],
"Sample": dataset_object["Sample"],
"IC50": ic50,
});
};

return results;
}
Insert cell
tox21_datasets_of_selected_compound_with_samplename = tox21_datasets_of_selected_compound.map(function(obj) {
obj["Sample"] = obj["Dataset name"].replace("EPA-InVitroDBV3.2-TOX21_", "").replace("_", " ");
return obj;
})
Insert cell
tggates_datasets_of_selected_compound_with_samplename = tggates_datasets_of_selected_compound.map(function(obj) {
obj["Sample"] = obj["Organism"] + " / " + obj["Study type"] + " / " + obj["Organ"] + " / " + obj["Dosing"] + " / " + obj["Dose"] + " / " + obj["Duration"] + " " + obj["Duration unit"];
return obj;
})
Insert cell
Insert cell
tox21_datasets_of_selected_compound = fetch_dataset_to_array(tox21_summary_url, query_options_filter_inchikey_lowercase)
Insert cell
tggates_datasets_of_selected_compound = fetch_dataset_to_array(tggates_summary_url, query_options_filter_inchikey)
Insert cell
drugmatrix_datasets_of_selected_compound = fetch_dataset_to_array(drugmatrix_summary_url, query_options_filter_compound)
Insert cell
query_options_filter_inchikey_lowercase = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
exactSearch: [{ column: ["InChI key"] }, selected_compound_inchikey.replace('InChIKey=','')],
}
})
}
}
Insert cell
query_options_filter_inchikey = {
return {
method: 'POST',
body: JSON.stringify({
condition: {exactSearch: [{ column: ["InChI Key"] }, selected_compound_inchikey]}
})
}
}
Insert cell
query_options_filter_compound = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
exactSearch: [{ column: ["Compound"] }, selected_compound]
}
})
}
}
Insert cell
selected_compound_smiles = selected_compound_object["SMILES"]["canonical"]
Insert cell
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
Insert cell
compound_svg = get_svg_from_smiles(selected_compound_smiles)
Insert cell
selected_compound_inchikey = selected_compound_object["InChI Key"]
Insert cell
selected_compound_object = drugmatrix_summary_dataset.find(obj => {return obj.Compound === selected_compound})
Insert cell
compound_options = Array.from(new Set(drugmatrix_summary_dataset.map(obj => obj.Compound))).sort()
Insert cell
drugmatrix_summary_dataset = fetch_dataset_to_array(drugmatrix_summary_url, query_options_for_summary_compounds)
Insert cell
query_options_for_summary_compounds = {
return {
method: 'POST',
body: JSON.stringify({
columns: ["Compound", "SMILES", "InChI Key", "InChI", "CAS", "IUPAC name"]
})
}
}
Insert cell
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
drugmatrix_summary_id = '9c1c25e0-2943-4c36-9123-ccbb1f4ef2ae'
Insert cell
tggates_summary_id = '16a4418e-01ff-4dcd-9b2d-90ef00565655'
Insert cell
tox21_summary_id = "8cc0534a-5e52-4253-a736-40f616b84a41"
Insert cell
base_url_edelweiss = 'https://api.kit.edelweissconnect.com/datasets/'
Insert cell
import {Select, Range, Toggle} from "@observablehq/inputs"
Insert cell
import {select, slider} from "@jashkenas/inputs"
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell
import {render_data_table, table_styles, displayImage, displayCaution} from '@info474/utilities'
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