Public
Edited
May 10, 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
Insert cell
x_axis = "Treatment concentration"
Insert cell
selected_studies = ["EUT103"]
Insert cell
pathways = enrichr_output['KEGG_2015'].map(item => {return {
Pathway: item[1],
'Gene symbol': item[5].join(', '),
Rank: item[0],
'p-value': item[2],
'Adj. p-value': item[6],
'Z-score': item[3],
'Combined score': item[4]
}})
Insert cell
enrichr_output = fetch_enrichr(enrich_get_url, {method: 'GET'})
Insert cell
enrich_get_url = fetch_enrichr("https://amp.pharm.mssm.edu/Enrichr/addList", enrichr_post_query_options)
.then(content => content.userListId)
.then(userid => "https://amp.pharm.mssm.edu/Enrichr/enrich?userListId=" + userid + "&backgroundType=KEGG_2015")
Insert cell
formData = {
var f = new FormData()
f.append('list', genes_for_lineplot.join('\n'))
return f}
Insert cell
enrichr_post_query_options = {
return {
method: "POST",
body: formData}
}
Insert cell
function fetch_enrichr(url, query_options) {
return fetch(url, query_options).then(response_dataset => {
if (!response_dataset.ok) throw new Error(response_dataset.status);
return response_dataset.json();})
}
Insert cell
lineplots_charts = function(arr) {
var vl_arr = []
for (let i = 0; i < arr.length; i++) {
var data = arr[i]
var compound = selected_compounds_names[i]

const layer_1 = vl.markLine().data(lineplots_data[i]).title(compound).encode(
vl.x().fieldQ(x_axis).scale({"type": "log"}),
vl.y().fieldQ("logFC"),
vl.color().fieldN("SYMBOL")
).width(width).height(height)
const layer_2 = vl.markPoint().data(lineplots_data[i]).encode(
vl.x().fieldQ(x_axis).scale({"type": "log"}),
vl.y().fieldQ("logFC"),
vl.color().fieldN("SYMBOL")
)

vl_arr.push(vl.layer(layer_1, layer_2)
)
}

return vl.hconcat(vl_arr).render()
}
Insert cell
lineplots_data = {
var arr = []
for (let i=0; i<heatmaps_data.length; i++) {
arr.push(heatmaps_data[i].filter(item => genes_for_lineplot.includes(item.SYMBOL)))
}
return arr
}
Insert cell
lineplot_data = heatmap_data.filter(item => genes_for_lineplot.includes(item.SYMBOL))
Insert cell
keys = ["Control compound", "Control timepoint", "Treatment compound", "Treatment timepoint", "Control concentration", "Treatment concentration"]
Insert cell
plot_heatmaps = function(arr) {
var vl_arr = []
for (let i = 0; i < arr.length; i++) {
var data = arr[i]
var compound = selected_compounds_names[i]

vl_arr.push(
vl.markRect().data(data).title(compound)
.encode(
vl.y().fieldN("SYMBOL"),
vl.x().fieldN(x_axis),
vl.color().fieldQ("logFC").scale({scheme: "lightmulti", reverse: false, zero: false}),
vl.tooltip([
{
"field": "logFC",
"type": "quantitative",
"format": ",.2f"
},
vl.fieldN("SYMBOL"),
vl.fieldN("ENSEMBL"),
vl.fieldN("GENENAME"),
vl.fieldN("Treatment compound"),
vl.fieldQ("Treatment concentration"),
vl.fieldQ("Treatment timepoint"),
vl.fieldN("Control compound"),
vl.fieldQ("Control concentration"),
vl.fieldQ("Control timepoint"),
]),
)
)
}

return vl.hconcat(vl_arr).render()
}
Insert cell
heatmaps_data = {
var arr1 = []

for (let compound_name of selected_compounds_names) {
var logfc_selected_genes_this_compound = logfc_selected_genes.filter((el,i) => compound_dataset_indexes[compound_name].some(j => i === j))
var arr2 = []
for (let i = 0; i < logfc_selected_genes_this_compound.length; i++) {
var dataset_index = compound_dataset_indexes[compound_name][i]
var dataset = filtered_datasets[dataset_index]
var logfc_array = logfc_selected_genes_this_compound[i]
for (let j = 0; j < logfc_array.length; j++) {
var logfc_item = logfc_array[j]
for (var key of keys) {
logfc_item[key] = dataset[key]
}
arr2.push(logfc_item)
}
}

arr1.push(arr2)
}
return arr1
}
Insert cell
heatmap_data = {
var arr = []
for (let i = 0; i < logfc_selected_genes.length; i++) {
var dataset = filtered_datasets[i]
var logfc_array = logfc_selected_genes[i]
for (let j = 0; j < logfc_array.length; j++) {
var logfc_item = logfc_array[j]
for (var key of keys) {
logfc_item[key] = dataset[key]
}

arr.push(logfc_item)
}
}
return arr
}
Insert cell
compound_dataset_indexes = {
var compound_dataset_map = {}
for (let compound of selected_compounds_names) {
var indexes = []
for (let i=0; i < filtered_datasets.length; i++) {
if (filtered_datasets[i]['Treatment compound'] == compound) {
indexes.push(i)
}
}

compound_dataset_map[compound] = indexes
}

return compound_dataset_map
}
Insert cell
logfc_selected_genes = get_datasets_from_promises(
get_promised_fold_changes_datasets(
filtered_datasets.map(item => item["Dataset id"]), query_options_for_fold_changes_of_selected_genes
)
)
Insert cell
query_options_for_fold_changes_of_selected_genes = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
containedIn: [{ column: ["SYMBOL"] }, unique_deregulated_genes],
},
})
}
}
Insert cell
unique_deregulated_genes = Array.from(new Set(deregulated_genes))
Insert cell
deregulated_genes = [].concat(...logfc_arrays).map(item => item.SYMBOL)
Insert cell
filtered_datasets
Insert cell
logfc_arrays = get_datasets_from_promises(
get_promised_fold_changes_datasets(
filtered_datasets.map(item => item["Dataset id"]), query_options_for_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_promised_fold_changes_datasets = function(array_of_datasets, query) {
return array_of_datasets.map(dataset => {
return fetch(base_url_edelweiss + dataset + "/versions/latest/data", query).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: {

and: [
{lt: [{column: ["padj"]}, padj_threshold]},
{or: [
{lt: [{column: ["logFC"]}, -logfc_threshold]},
{gt: [{column: ["logFC"]}, logfc_threshold]},
]},
]
},
})
}
}
Insert cell
compounds_table = {
var tbl = [];
var i = 0;
for (var compound of selected_compounds) {
tbl.push({
'Name': compound['Name'],
'Molecular formula': svgs[i],
})
i = i + 1
}
return tbl;
};
Insert cell
svgs = Promise.all(promises)
Insert cell
// Copied from PCR analysis notebook

promises = {
var promises = [];
for (var compound of selected_compounds) {
const smiles = compound.SMILES;
const safeSmiles = encodeURIComponent(smiles);
const svg_url = "https://chemidconvert.cloud.douglasconnect.com/v1/asSvg?width=200&height=200&smiles=" + safeSmiles;
const svg = fetch(svg_url).then(response => response.text());
promises.push(svg);
}
return promises;
}
Insert cell
filtered_datasets = fetch_dataset_to_array(overview_url, query_options_filter_compound_and_timepoint)
Insert cell
selected_compounds_names = selected_compounds.map(item => item.Name)
Insert cell
query_options_filter_compound_and_timepoint = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
and: [
{containedIn: [{ column: ["Treatment compound"] }, selected_compounds_names]},
{containedIn: [{ column: ["Treatment timepoint"] }, selected_timepoints]},
{containedIn: [{ column: ["Control compound"] }, selected_controls]},
{containedIn: [{ column: ["Study"] }, selected_studies]},
]
}
})
}
}
Insert cell
control_compounds = get_unique_elements(overview_filtered_for_studies_case_studies_compounds, "Control compound")
Insert cell
concentrations = get_unique_elements(overview_filtered_for_studies_case_studies_compounds, "Treatment concentration")
Insert cell
timepoints = get_unique_elements(overview_filtered_for_studies_case_studies_compounds, "Treatment timepoint")
Insert cell
overview_filtered_for_studies_case_studies_compounds = fetch_dataset_to_array(overview_url, query_options_filter_studies_case_studies_compounds)
Insert cell
query_options_filter_studies_case_studies_compounds = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
and: [
{containedIn: [{ column: ["Treatment compound"] }, selected_compounds_names]},
{containedIn: [{ column: ["Case study"] }, selected_case_studies]},
{containedIn: [{ column: ["Study"] }, selected_studies]},
]
}
})
}
}
Insert cell
unique_filtered_compounds = Array.from(new Set(filtered_compounds.map(a => a.Id)))
.map(id => {
return filtered_compounds.find(a => a.Id === id)
})
Insert cell
filtered_compounds = overview_filtered_for_studies_and_case_studies.map(item => {
return {
"Code": item.Code,
"SMILES": item.SMILES.canonical,
"CAS": item["CAS number"],
"Parent compound": item["Parent compound"],
"Name": item["Treatment compound"],
"Id": item["Index in compound list"],
}
})
Insert cell
//compounds = get_unique_elements(overview_filtered_for_studies_and_case_studies, "Treatment compound")
Insert cell
overview_filtered_for_studies_and_case_studies = fetch_dataset_to_array(overview_url, query_options_filter_studies_case_studies)
Insert cell
query_options_filter_studies_case_studies = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
and: [
{containedIn: [{ column: ["Case study"] }, selected_case_studies]},
{containedIn: [{ column: ["Study"] }, selected_studies]},
]
}
})
}
}
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
studies = get_unique_elements(overview, "Study")
Insert cell
case_studies = get_unique_elements(overview, "Case study")
Insert cell
get_unique_elements = function(array, parameter) {
return Array.from(new Set(array.map(item => item[parameter])))
}
Insert cell
overview = fetch_dataset_to_array(overview_url, {})
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
overview_url = base_url_edelweiss + overview_id + "/versions/latest/data"
Insert cell
overview_id = "d8922983-1724-4ce8-af07-93f290d9c3c2"
Insert cell
base_url_edelweiss = 'https://api.develop.edelweiss.douglasconnect.com/datasets/'
Insert cell
// Import libraries for data table rendering
import {render_data_table} from '@info474/utilities'
Insert cell
import {select, slider} from "@jashkenas/inputs"
Insert cell
import {Select, Range, Toggle, Table} from "@observablehq/inputs"
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more