Published
Edited
Mar 16, 2021
1 fork
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) {
var i, j;
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 count_column_name = timepoint;

var new_item = {
"SYMBOL": item.SYMBOL,
"ENSEMBL": item.Ensembl_IDs,
"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,
"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
//selected_gene_objects = gene_objects_with_names.filter(item => selected_genes.includes(item.NAME))
Insert cell
gene_list = gene_objects_with_names.map(item => item.NAME)
Insert cell
gene_objects_with_names = gene_objects.map(item => {item.NAME = item.SYMBOL + ", " + item.Ensembl_IDs; return item})
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
query_options_for_gene_list = {
return {
method: 'POST',
body: JSON.stringify({
//columns: ["Ensembl_IDs", "SYMBOL"],
condition: {
or: [
{fuzzySearch: [{ "column": ["SYMBOL"] }, keyword]},
{fuzzySearch: [{ "column": ["SYMBOL"] }, keyword2]},
]
},
orderBy: [{ expression: { column: ["SYMBOL"] }, ordering: "ascending" }],
})
}
}
Insert cell
normalized_dataset_url = api_url + dataset_id + "/versions/3/data"
Insert cell
dataset_url = api_url + dataset_id + "/versions/4/data"
Insert cell
api_url = "https://api.edelweissdata.com/datasets/"
Insert cell
dataset_id = "7bff53eb-7c1a-4875-b6b1-cd002e7e9c4c"
Insert cell
import {Select, Range, Toggle, Search, Table, Text} from "@observablehq/inputs"
Insert cell
import {vl} from "@vega/vega-lite-api"
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