Published
Edited
Apr 27, 2021
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
reshaped_rnaseq_data = reshape_rnaseq_data(rnaseq_data)
Insert cell
reshaped_normalized_rnaseq_data = reshape_normalized_rnaseq_data(normalized_rnaseq_data)
Insert cell
timepoints = ["24h", "48h", "72h", "144h"]
Insert cell
reshape_rnaseq_data = function(data) {
let i, j;
const arr = [];
//const processedEnsemblIds = new Set()
for (i = 0; i < data.length; i++) {
//const ensemblId = data[i].Ensembl_IDs
//if (!processedEnsemblIds.has(ensemblId)) {
//processedEnsemblIds.add(ensemblId)
for (j = 0; j < timepoints.length; j++) {
const item = data[i];
const timepoint = timepoints[j];
const count_column_name = timepoint;

var new_item = {
"SYMBOL": item.SYMBOL,
"ENSEMBL": item.Ensembl_IDs,
"PATHWAY": item.Pathway,
"TIMEPOINT": timepoint,
"COUNT": item[count_column_name],
"RESCALED_COUNT": item[count_column_name] / max_count,
"SAMPLE": item.SYMBOL + ", " + item.Ensembl_IDs,
};

arr.push(new_item);
}
//}
}
return arr;
}
Insert cell
replicates = [1, 2, 3]
Insert cell
reshape_normalized_rnaseq_data = function(data) {
var i, j, k;
var arr = [];
for (i = 0; i < data.length; i++) {
for (j = 0; j < timepoints.length; j++) {
var item = data[i];
var timepoint = timepoints[j];
var average_count = 0;
for (k = 0; k < replicates.length; k++) {
var count_column_name = timepoint + "_Replicate" + replicates[k];
average_count = average_count + item[count_column_name];
}
average_count = average_count / (replicates.length);

var new_item = {
"SYMBOL": item.SYMBOL,
"ENSEMBL": item.Ensembl_IDs,
"PATHWAY": item.Pathway,
"TIMEPOINT": timepoint,
"COUNT": average_count,
"SAMPLE": item.SYMBOL + ", " + item.Ensembl_IDs,
};

arr.push(new_item);
}
}
return arr;
}
Insert cell
normalized_rnaseq_data = fetch_dataset_to_array(normalized_dataset_url, query_options_for_rnaseq_data)
Insert cell
rnaseq_data = fetch_dataset_to_array(dataset_url, query_options_for_rnaseq_data)
Insert cell
query_options_for_rnaseq_data = {
return {
method: 'POST',
body: JSON.stringify({
condition: {
containedIn: [
{column: ["Ensembl_IDs"]}, selected_gene_objects.map(item => item.Ensembl_IDs),
]
},
})
}
}
Insert cell
gene_list = gene_objects_with_names.map(item => item.NAME)
Insert cell
gene_objects_with_names = _.chain(gene_objects).uniqBy(item => item.Ensembl_IDs).map(item => {item.NAME = item.SYMBOL + ", " + item.Ensembl_IDs; return item}).value()
Insert cell
max_count = {
var maximums = [];
var i;
for (i = 0; i < timepoints.length; i++) {
var timepoint = timepoints[i];
maximums.push(
Math.max(...gene_objects.map(item => item[timepoint]))
)
}

return Math.max(...maximums);
}
Insert cell
gene_objects = fetch_dataset_to_array(dataset_url, query_options_for_gene_list)
Insert cell
function dynamicSort(property) {
var sortOrder = 1;
if(property[0] === "-") {
sortOrder = -1;
property = property.substr(1);
}
return function (a,b) {
/* next line works with strings and numbers,
* and you may want to customize it to your needs
*/
var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
return result * sortOrder;
}
}
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
mutable gene_fragments = ["CYP"]
Insert cell
query_options_for_gene_list = {
let condition;
if (toxicologicalCategory === "") {
if (majorPathwayDropdown !== "" || majorMinorPathwayDropdown !== "") {
condition = ({
and: [
({ fuzzySearch: [({"column": ["Pathway"]}), majorPathwayDropdown]}),
({ fuzzySearch: [({"column": ["Pathway"]}), majorMinorPathwayDropdown]}),
]
})
}
else {
let conditionFragments = []
if (gene_fragments.length > 0) {
conditionFragments = (gene_fragments.map(item => ({fuzzySearch: [({ "column": ["SYMBOL"] }), item]})))
}
if (pathwaySearch !== "") {
conditionFragments.push(({fuzzySearch: [({ "column": ["Pathway"] }), pathwaySearch]}))
}
if (conditionFragments.length > 0) {
condition = ({ and: conditionFragments
})
}
}
}
else {
condition = ({
exactSearch: [({"column": ["Toxicological.categories"]}), toxicologicalCategory]
})
}

return {
method: 'POST',
body: JSON.stringify({
//columns: ["Ensembl_IDs", "SYMBOL"],
condition: condition,
orderBy: [{ expression: { column: ["SYMBOL"] }, ordering: "ascending" }],
})
}
}
Insert cell
pathways_dropdown = unique_pathways.unshift("", "NA")
Insert cell
unique_pathways = Array.from(new Set(all_pathways.map(item => item.Pathway)))
Insert cell
all_pathways = fetch_dataset_to_array(dataset_url, {
method: 'POST',
body: JSON.stringify({
columns: ["Pathway"],
condition: {
"not": [
{ "exactSearch": [{ "column": ["Pathway"] }, "NA"] }
]
},
orderBy: [{ expression: { column: ["Pathway"] }, ordering: "ascending" }],
})
})
Insert cell
toxicologicalCategoryVocuabulary = [
"",
"Efflux transporter(hepatocyte to bile canaliculi)",
"Uptake transporters (Blood to hepatocytes)",
"Important liver CYPs (Less abundant)",
"Efflux transporters (Hepatocytes to blood)",
"Important liver CYPs (Most abundant)"
]
Insert cell
normalized_dataset_url = api_url + dataset_id + "/versions/3/data"
Insert cell
dataset_url = api_url + dataset_id + "/versions/9/data"
Insert cell
api_url = "https://api.edelweissdata.com/datasets/"
Insert cell
dataset_id = "7bff53eb-7c1a-4875-b6b1-cd002e7e9c4c"
Insert cell
unshift = {major_pathways.unshift("")}
Insert cell
inshift2 = {major_minor_pathways.unshift("")}
Insert cell
major_pathways = major_pathways_records.map(item => item["Major pathways"])
Insert cell
major_minor_pathways = major_minor_pathways_records.map(item => item["Maroj and Minor Pathways"])
Insert cell
major_minor_pathways_records = fetch_dataset_to_array(major_minor_pathway_dataset_url, {
method: 'POST',
body: JSON.stringify({
columns: ["Maroj and Minor Pathways"],
orderBy: [{ expression: { column: ["Maroj and Minor Pathways"] }, ordering: "ascending" }],
})
})
Insert cell
major_pathways_records = fetch_dataset_to_array(major_pathway_dataset_url, {
method: 'POST',
body: JSON.stringify({
columns: ["Major pathways"],
orderBy: [{ expression: { column: ["Major pathways"] }, ordering: "ascending" }],
})
})
Insert cell
major_minor_pathway_dataset_url = api_url + major_minor_pathway_dataset_id + "/versions/latest/data"
Insert cell
major_pathway_dataset_url = api_url + major_pathway_dataset_id + "/versions/latest/data"
Insert cell
major_pathway_dataset_id = "7f87c58f-be80-4f91-8c86-57493e1f1fa6"
Insert cell
major_minor_pathway_dataset_id = "962c1d9c-ae72-4f1f-aa57-435d3097a2cd"
Insert cell
import {Select, Range, Toggle, Search, Table, Text} from "@observablehq/inputs"
Insert cell
_ = require("lodash");
Insert cell
import {vl} from "@vega/vega-lite-api"
Insert cell
import {html} from "@observablehq/htl"
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