Published
Edited
Aug 16, 2020
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
Insert cell
Insert cell
Insert cell
Insert cell
most_interesting_gene = {
var maxval = 1;
var maxobj = {};
for (var obj of data) {
if (obj.Fold > maxval) {
maxobj = obj;
maxval = obj.Fold;
}
}

return maxobj;
}
Insert cell
Insert cell
compounds_table = {
var tbl = [];
var i = 0;
for (var compound of metadata.Compounds) {
tbl.push({
'Compound': compound.Compound,
'Code': compound['Compound code'],
'Mol': svgs[i],
})
i = i + 1
}
return tbl;
}
Insert cell
Insert cell
svgs = Promise.all(promises)
Insert cell
Insert cell
promises = {
var promises = [];
for (var compound of metadata.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
Insert cell
metadata_to_table = function(section) {
// initiate empty array
var temp = [];
// loop over key, value pairs of metadata's section
for (const [key, value] of Object.entries(metadata[section])) {
// append object with Field-Value properties to the array
temp.push({
'Field': key,
'Value': value});
}
return temp
}
Insert cell
md`**Get the column names (i.e. keys of the object in "data" array)**`
Insert cell
columns = Object.keys(data[0])
Insert cell
Insert cell
filtered_data = data.filter(function(obj) {
if (obj.Gene == gene) {return obj}
})
Insert cell
Insert cell
// Select only unique gene names among the all gene names
genes = Array.from(new Set(valid_genes))
Insert cell
valid_genes = all_genes.filter(function (el) {
return el != null;
});
Insert cell
// First get the gene names in all of the rows of data. This is done by extracting the "Gene" property of each row in the data
all_genes = data.map(obj => obj.Gene)
Insert cell
Insert cell
// Extract data from the server's response. This is one by taking the the "data" property of each object (row) inside the raw_data.results array
data = raw_data.results.map(x => x.data)
Insert cell
Insert cell
// Access the data published under url_data and store it into a raw_data variable
raw_data = fetch(url_data)
.then(response => {
if (!response.ok) throw new Error(response.status);
return response.json();})
Insert cell
// Access the metadata published under the url_metadata and store it into a metadata variable
metadata = fetch(url_metadata)
.then(response => {
if (!response.ok) throw new Error(response.status);
return response.json();})
Insert cell
Insert cell
// URL to data is automatically generated from dataset ID
url_data = "https://api.develop.edelweiss.douglasconnect.com/datasets/" + dataset_id + "/versions/1/data"
Insert cell
// URL to metadata is automatically generated from dataset ID
url_metadata = "https://api.develop.edelweiss.douglasconnect.com/datasets/" + dataset_id + "/versions/1/metadata"
Insert cell
dataset_id = get_selected_dataset(datasets, dataset_name)
Insert cell
Insert cell
get_selected_dataset = function(datasets, dataset_name) {
var selected_datasets = datasets.filter(function(obj) {
if (obj['Dataset name'] == dataset_name) {return obj}
})
if (selected_datasets.length == 1) {
return selected_datasets[0]['Dataset ID']
} else {
return null
}
}
Insert cell
Insert cell
Insert cell
response = fetch("https://api.develop.edelweiss.douglasconnect.com/datasets/e62fa517-ee8f-41d5-8953-6dfba8120718/versions/1/data")
.then(response => {
if (!response.ok) throw new Error(response.status);
return response.json();})
Insert cell
Insert cell
// Import D3 library for graphics
d3 = require("d3@5")
Insert cell
// Import the select library
import {text} from "@jashkenas/inputs"
Insert cell
// Import the select library
import {select} from "@jashkenas/inputs"
Insert cell
// Import the vegalite library
import {vl} from "@vega/vega-lite-api"
Insert cell
// Import libraries for data table rendering
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