-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.js
152 lines (129 loc) · 4.75 KB
/
data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
const diseasesUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/disease-summary-table.txt';
const genesUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/gene-summary-table.txt';
const featuresUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/feature-summary-table.txt';
const diseaseInfoUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/disease-info/';
const geneInfoUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/gene-info/';
const featureInfoUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/feature-info/';
const diseasePredictionsUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/disease-tables/';
const genePredictionsUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/gene-tables/';
const featurePredictionsUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/feature-tables/';
const contributionsUrl =
'https://raw.githubusercontent.com/dhimmel/het.io-dag-data/54dd91f7c3c378b4064e8a99b022d4c637fe413f/browser/prediction-terms/';
export async function fetchMainData() {
const diseases = await (await fetch(diseasesUrl)).text();
const genes = await (await fetch(genesUrl)).text();
const features = await (await fetch(featuresUrl)).text();
return {
diseases: assembleData(diseases),
genes: assembleData(genes),
features: assembleData(features)
};
}
export async function fetchDiseasePredictions(diseaseId) {
const diseasePredictions = await (await fetch(
diseasePredictionsUrl + diseaseId.replace(':', '_') + '.txt'
)).text();
return { diseasePredictions: assembleData(diseasePredictions) };
}
export async function fetchGenePredictions(geneId) {
const genePredictions = await (await fetch(
genePredictionsUrl + geneId.replace(':', '_') + '.txt'
)).text();
return { genePredictions: assembleData(genePredictions) };
}
export async function fetchFeaturePredictions(featureId) {
const featurePredictions = await (await fetch(
featurePredictionsUrl + featureId.replace(':', '_') + '.txt'
)).text();
return { featurePredictions: assembleData(featurePredictions) };
}
export async function fetchDiseaseInfo(diseaseId) {
const diseaseInfo = await (await fetch(
diseaseInfoUrl + diseaseId.replace(':', '_') + '.json'
)).json();
return { diseaseInfo: diseaseInfo };
}
export async function fetchGeneInfo(geneId) {
const geneInfo = await (await fetch(
geneInfoUrl + geneId.replace(':', '_') + '.json'
)).json();
return { geneInfo: geneInfo };
}
export async function fetchFeatureInfo(featureId) {
const featureInfo = await (await fetch(
featureInfoUrl + featureId.replace(':', '_') + '.json'
)).json();
return { featureInfo: featureInfo };
}
export async function fetchContributions(
diseasePredictionId,
genePredictionId
) {
let contributions = await (await fetch(
contributionsUrl +
diseasePredictionId.replace(':', '_') +
'/' +
genePredictionId.replace(':', '_') +
'.txt'
)).text();
// put data in format expected by Google Charts
contributions = contributions
.trim()
.split('\n')
.map((row) => row.trim())
.filter((row) => row)
.map((row) =>
row
.split('\t')
.map((cell) => cell.trim())
.map((cell) => (Number.isNaN(Number(cell)) ? cell : Number(cell)))
.filter((cell) => cell !== '')
);
// put highest contributions at top of chart
contributions.sort((a, b) => {
if (typeof b[1] !== 'number')
return 1;
else if (typeof a[1] !== 'number')
return -1;
else
return b[1] - a[1];
});
return { contributions: contributions };
}
// turn tsv data into expected format
export function assembleData(results) {
const newData = [];
results = results
.trim()
.split('\n')
.map((row) => row.trim())
.filter((row) => row)
.map((row) =>
row
.split('\t')
.map((cell) => cell.trim())
.map((cell) => (Number.isNaN(Number(cell)) ? cell : Number(cell)))
.filter((cell) => cell !== '')
);
for (const datum of results) {
const newDatum = {};
for (
let index = 0;
index < results[0].length && index < datum.length;
index++
)
newDatum[results[0][index]] = datum[index];
newData.push(newDatum);
}
newData.shift();
return newData;
}