This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
200 lines (178 loc) · 5.66 KB
/
index.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* giant-api-biojs
* https://github.com/amr4/giant-api-biojs
*
* Copyright (c) 2015 amr4
* Licensed under the MIT license.
*/
/**
@class giantapibiojs
*/
var giantapibiojs;
module.exports = giantapibiojs = function(opts) {
this.el = opts.el;
this.el.textContent = giantapibiojs.hello(opts.text);
};
/**
* Private Methods
*/
/**
* Public Methods
*/
/**
* Method responsible to say Hello
*
* @example
*
* giantapibiojs.hello('biojs');
*
* @method hello
* @param {String} name Name of a person
* @return {String} Returns hello name
*/
giantapibiojs.hello = function (name) {
return 'hello ' + name;
};
/**
* GIANT functions
*/
giantapibiojs.graphBasic = function(opts) {
/* Place an optional caption in the DIV first. Comment this out if only the
graph is needed. */
opts.el.innerHTML += "<p style='margin-top: 15px; font-weight: bold;'>" +
"Tissue: " + opts.tissue + "; Genes[s]: " + opts.genes + "<br>" +
"</p>";
// Append graph
giant.graph({
el: opts.el,
tissue: opts.tissue,
genes: opts.genes,
filters: false,
datasets: false
});
};
giantapibiojs.graphWithFilters = function(opts) {
/* Place an optional caption in the DIV first. Comment this out if only the
graph is needed. */
opts.el.innerHTML += "<p style='margin-top: 15px; font-weight: bold;'>" +
"Tissue: " + opts.tissue + "; Genes[s]: " + opts.genes + "<br>" +
"</p>";
// Append graph
giant.graph({
el: opts.el,
tissue: opts.tissue,
genes: opts.genes,
filters: true,
datasets: false
});
};
giantapibiojs.graphWithFiltersAndDatasets = function(opts) {
/* Place an optional caption in the DIV first. Comment this out if only the
graph is needed. */
opts.el.innerHTML += "<p style='margin-top: 15px; font-weight: bold;'>" +
"Tissue: " + opts.tissue + "; Genes[s]: " + opts.genes + "<br>" +
"<span style='font-weight: normal;'>" +
"(Click on any link to display supporting datasets.)" +
"</span>" +
"</p>";
// Append graph
giant.graph({
el: opts.el,
tissue: opts.tissue,
genes: opts.genes,
filters: true,
datasets: true
});
};
giantapibiojs.graphWithFormFields = function(opts) {
// Target div to display form fields
var el = opts.el;
var tableHtml = "<table id='formTable' class='formTable'>" +
"<tr>" +
"<td class='formTableTd'><b>Tissue</b></td>" +
"<td class='formTableTd centered'><select id='tissueSel'></select></td>" +
"<td></td>" +
"</tr>" +
"<tr>" +
"<td class='formTableTd'><b>Gene[s]</b></td>" +
"<td class='formTableTd'><div id='geneSelDiv'></div></td>" +
"<td class='formTableTd'><button id='graphButton' disabled='true'>Graph</button></td>" +
"</tr>" +
"</table>";
el.innerHTML += tableHtml;
// Init tissue selector options
var url = "http://giant-api.princeton.edu/tissues";
console.log("API call:", url);
d3.json(url, function(error, response) {
if(error)
throw error;
for (var i = 0; i < response.length; i++) {
var tissue = response[i];
var tissueSelEl = document.getElementById("tissueSel");
var option = document.createElement("option");
option.text = tissue;
if (tissue == 'lung_')
option.selected = "selected";
tissueSelEl.add(option);
}
$('#tissueSel').multiselect({
enableFiltering: true,
enableCaseInsensitiveFiltering: true,
maxHeight: 250,
buttonWidth: '300px',
templates: {filterClearBtn:''}
});
});
// Init gene selector options
var url = "http://giant-api.princeton.edu/genes";
console.log("API call:", url);
d3.json(url, function(error, response) {
if(error)
throw error;
newResponse = [];
for (var i = 0; i < response.length; i++) {
newResponse.push({id: i, name: response[i]});
}
response = newResponse;
$("#geneSelDiv").tokenInput(response, {
theme: 'facebook',
minChars: 2,
preventDuplicates: true,
tokenLimit: 100,
hintText: "Type in a gene name",
noResultsText: "No gene found",
onAdd: function() {
if ( $("#tissueSel").val() && $("#geneSelDiv").tokenInput('get').length > 0 )
$("#graphButton").removeAttr('disabled');
},
onDelete: function() {
if (!$("#tissueSel").val())
$("#graphButton").prop('disabled', 'true');
if ($("#geneSelDiv").tokenInput('get').length == 0)
$("#graphButton").prop('disabled', 'true');
},
});
});
// Process graph button click event
$(document).on('click', '#graphButton', function() {
// Remove any existing summary and dataset tables
$("#dataTablesTr").remove();
// Pack parameters
var tissue = document.getElementById("tissueSel").value;
tissue = tissue.replace(/ /g, '_').toLowerCase();
var selectedGenes = $("#geneSelDiv").tokenInput("get");
var genes = "";
for (var i = 0; i < selectedGenes.length; i++ ) {
genes += selectedGenes[i].name + ",";
}
genes = genes.replace(/,+$/, "");
// Call graph function
giant.graph({
el: el,
tissue: tissue,
genes: genes,
filters: true,
datasets: true
});
});
};