-
Notifications
You must be signed in to change notification settings - Fork 14
/
blast_ui.admin.inc
342 lines (304 loc) · 14.3 KB
/
blast_ui.admin.inc
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<?php
/**
* @file
* Administrative interface for the BLAST UI
*/
/**
*
*/
function blast_ui_admin_form($form, $form_state) {
$form['general'] = array(
'#type' => 'fieldset',
'#title' => 'General'
);
$form['general']['blast_path']= array(
'#type' => 'textfield',
'#title' => t('Enter the path of the BLAST program'),
'#description' => t('You can ignore if your $PATH variable is set. Otherwise, enter the absoulte path to bin folder. For example, /opt/blast/2.2.29+/bin/'),
'#default_value' => variable_get('blast_path', ''),
);
$form['general']['blast_threads']= array(
'#type' => 'textfield',
'#title' => t('Enter the number of CPU threads to use in blast search.'),
'#description' => t('You can increase the number to reduce the search time. Before you increase, please check your hardware configurations . A value of one(1) can result in a slower search for some programs eg. tblastn.'),
'#default_value' => variable_get('blast_threads', 1),
);
$form['general']['eVal']= array(
'#type' => 'textfield',
'#title' => t('Default e-value (Expected Threshold)'),
'#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format.'),
'#default_value' => variable_get('eVal', 0.001),
//'#default_value' => variable_get('blast_threads', 1),
);
$form['general']['qRange']= array(
'#type' => 'textfield',
'#title' => t('Default max matches in a query range'),
'#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
'#default_value' => variable_get('qRange', 0),
);
$form['file_upload'] = array(
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => true,
'#title' => 'Allow File Upload',
'#description' => 'The following options allow you to control whether your users can
upload files for the query or target respectively. The ability to upload files allows
them to more conviently BLAST large sets of sequences. However, the size of the
files could be problematic, storage-wise, on your server.<br />'
);
$form['file_upload']['query_upload'] = array(
'#type' => 'checkbox',
'#title' => 'Enable Query Sequence Upload',
'#description' => 'When checked, a query file upload field will be available on BLAST request forms.',
'#default_value' => FALSE,
'#default_value' => variable_get('blast_ui_allow_query_upload', TRUE)
);
$form['file_upload']['target_upload'] = array(
'#type' => 'checkbox',
'#title' => 'Enable Target Sequence Upload',
'#description' => 'When checked, a target file upload field will be available on BLAST request forms.',
'#default_value' => FALSE,
'#default_value' => variable_get('blast_ui_allow_target_upload', FALSE)
);
$form['example_sequence'] = array(
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => true,
'#title' => 'Set Example Sequences',
'#description' => 'There is the ability to show example sequences built-in to the various BLAST forms. Use the following fields to set these example sequences. This allows you to provide more relevant examples to your users.'
);
$nucleotide_default = '>partial lipoxygenase Glyma15g03040
TTTCGTATGA GATTAAAATG TGTGAAATTT TGTTTGATAG GACATGGGAA
AGGAAAAGTT GGAAAGGCTA CAAATTTAAG AGGACAAGTG TCGTTACCAA
CCTTGGGAGC TGGCGAAGAT GCATACGATG TTCATTTTGA ATGGGACAGT
GACTTCGGAA TTCCCGGTGC ATTTTACATT AAGAACTTCA TGCAAGTTGA
GTTCTATCTC AAGTCTCTAA CTCTCGAAGA CATTCCAAAC CACGGAACCA
TTCACTTCGT ATGCAACTCC TGGGTTTACA ACTCAAAATC CTACCATTCT
GATCGCATTT TCTTTGCCAA CAATGTAAGC TACTTAAATA CTGTTATACA
TTGTCTAACA TCTTGTTAGA GTCTTGCATG ATGTGTACCG TTTATTGTTG
TTGTTGAACT TTACCACATG GCATGGATGC AAAAGTTGTT ATACACATAA
ATTATAATGC AGACATATCT TCCAAGCGAG ACACCGGCTC CACTTGTCAA
GTACAGAGAA GAAGAATTGA AGAATGTAAG AGGGGATGGA ACTGGTGAGC
GCAAGGAATG GGATAGGATC TATGATTATG ATGTCTACAA TGACTTGGGC
GATCCAGATA AGGGTGAAAA GTATGCACGC CCCGTTCTTG GAGGTTCTGC
CTTACCTTAC CCTCGCAGAG GAAGAACCGG AAGAGGAAAA ACTAGAAAAG
GTTTCTCACT AGTCACTAAT TTATTACTTT TTAATGTTTG TTTTTAGGCA
TCTTTTCTGA TGAAATGTAT ACTTTTGATG TTTTTTTGTT TTAGCATAAC
TGAATTAGTA AAGTGTGTTG TGTTCCTTAG AAGTTAGAAA AGTACTAAGT
ATAAGGTCTT TGAGTTGTCG TCTTTATCTT AACAGATCCC AACAGTGAGA
AGCCCAGTGA TTTTGTTTAC CTTCCGAGAG ATGAAGCATT TGGTCACTTG
AAGTCATCAG ATTTTCTCGT TTATGGAATC AAATCAGTGG CTCAAGACGT
CTTGCCCGTG TTGACTGATG CGTTTGATGG CAATCTTTTG AGCCTTGAGT
TTGATAACTT TGCTGAAGTG CGCAAACTCT ATGAAGGTGG AGTTACACTA
CCTACAAACT TTCTTAGCAA GATCGCCCCT ATACCAGTGG TCAAGGAAAT
TTTTCGAACT GATGGCGAAC AGTTCCTCAA GTATCCACCA CCTAAAGTGA
TGCAGGGTAT GCTACATATT TTGAATATGT AGAATATTAT CAATATACTC
CTGTTTTTAT TCAACATATT TAATCACATG GATGAATTTT TGAACTGTTA';
$form['example_sequence']['nucleotide_example'] = array(
'#type' => 'textarea',
'#title' => 'Nucleotide Example',
'#description' => t('Enter a complete nucleotide FASTA record including the header. More information: <a href="@fasta-format-url" target="_blank">FASTA format</a>.',
array('@fasta-format-url' => 'https://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml')),
'#default_value' => variable_get(
'blast_ui_nucleotide_example_sequence',
$nucleotide_default
)
);
$protein_default = '>gi|166477|gb|AAA96434.1| resveratrol synthase [Arachis hypogaea]
MVSVSGIRKVQRAEGPATVLAIGTANPPNCIDQSTYADYYFRVTNSEHMTDLKKKFQRICERTQIKNRHM
YLTEEILKENPNMCAYKAPSLDAREDMMIREVPRVGKEAATKAIKEWGQPMSKITHLIFCTTSGVALPGV
DYELIVLLGLDPCVKRYMMYHQGCFAGGTVLRLAKDLAENNKDARVLIVCSENTAVTFRGPSETDMDSLV
GQALFADGAAAIIIGSDPVPEVEKPIFELVSTDQKLVPGSHGAIGGLLREVGLTFYLNKSVPDIISQNIN
DALNKAFDPLGISDYNSIFWIAHPGGRAILDQVEQKVNLKPEKMKATRDVLSNYGNMSSACVFFIMDLMR
KRSLEEGLKTTGEGLDWGVLFGFGPGLTIETVVLRSVAI';
$form['example_sequence']['protein_example'] = array(
'#type' => 'textarea',
'#title' => 'Protein Example',
'#description' => t('Enter a complete protein FASTA record including the header. More information: <a href="@fasta-format-url" target="_blank">FASTA format</a>.',
array('@fasta-format-url' => 'https://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml')),
'#default_value' => variable_get(
'blast_ui_protein_example_sequence',
$protein_default
)
);
// PROTECTION
$form['protection'] = array(
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => true,
'#title' => 'Protect against large jobs',
'#description' => 'Depending on the size and nature of your target databases, you may wish to constrain use of this module.',
);
$form['protection']['max_results_displayed'] = array(
'#type' => 'textfield',
'#title' => 'Maximum number of results to show on report page',
'#description' => 'If there are more hits that this, the user is able to download but not visualize the results.',
'#default_value' => variable_get('blast_ui_max_results_displayed', 500)
);
// CVITJS
$cvitjs_enabled = variable_get('blast_ui_cvitjs_enabled', FALSE);
$description = 'The JavaScript program CViTjs enables users to see BLAST hits on an '
. 'entire genome assembly. See the help tab for information on how to '
. 'download and set up CViTjs.';
$form['cvitjs'] = array(
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => !$cvitjs_enabled,
'#title' => 'Enable and configure genome visualization',
'#description' => $description,
);
$absolute_cvitjs_data_path = DRUPAL_ROOT . '/sites/all/libraries/cvitjs/data';
$description = '<div class ="messages warning">CViTjs is only applicable for genome BLAST targets. After it is '
. 'enabled here, CViTjs will need to be enabled for each applicable BLAST '
. 'target node.</div>'
. '<div class="messages status"><strong>CViTjs Data Location: '.$absolute_cvitjs_data_path.'</strong>'
. '<br />The GFF3 and Genome Target-specific CViTjs configuration files should be located '
. 'at the above system path. Feel free to organize this directory further. '
. 'See the "Help" tab for more information.</div>';
$form['cvitjs']['explanation'] = array(
'#markup' => t($description),
);
$form['cvitjs']['cvitjs_enabled'] = array(
'#type' => 'checkbox',
'#title' => 'Enable CViTjs',
'#description' => 'When checked, CViTjs will be enabled.',
'#default_value' => $cvitjs_enabled,
);
// Get CViTjs confuration text, if possible.
if (!$default_value = blast_ui_get_cvit_conf_text()) {
$default_value = 'Unable to get CViTjs configuration information. '
. 'You will need to enable CViTjs and set and save the '
. 'path to CViTjs before you can edit the CViTjs configuration text.';
$disabled = true;
}
else {
$disabled = false;
}
$description = 'This is the contents of the file that defines data directories and '
. 'backbone GFF files for each genome assembly target. It is named '
. 'cvit.conf and is in the root directory for the CViTjs javascript code. '
. 'This is NOT the config file that is used to build the display for each '
. 'individual genome. See the help tab for more information about '
. 'configuration files.';
$form['cvitjs']['cvitjs_config'] = array(
'#type' => 'textarea',
'#title' => 'CViTjs configuration',
'#description' => $description,
'#default_value' => $default_value,
'#rows' => 10,
'#disabled' => $disabled,
);
//eksc:
// WARNING
$description = 'This permits display of a temporary warning message at the top of the
BLAST input form. Text can include HTML tags. Remember to remove the
message when it is no longer relevant.';
$form['warning'] = array(
'#type' => 'fieldset',
'#collapsible' => true,
'#collapsed' => true,
'#title' => 'Show warning text',
'#description' => $description,
);
$form['warning']['warning_text'] = array(
'#type' => 'textarea',
'#title' => 'Text to be displayed',
'#description' => $description,
'#default_value' => variable_get('blast_ui_warning_text', ''),
'#rows' => 10,
);
// SUBMIT
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save Configuration'
);
return $form;
}
/**
* Validate the Admin/Settings form.
*/
function blast_ui_admin_form_validate($form, &$form_state) {
// Check path to BLAST executables
$blast_path = $form_state['values']['blast_path'];
$blast_path .= 'blastn';
if(!empty($form_state['values']['blast_path'])) {
if(file_exists($blast_path) ) {
variable_set('blast_path', $form_state['values']['blast_path']);
}
else {
form_set_error('blast_path', t('Please enter a valid path not including the name of the blast program (ie: /usr/bin/). You can leave this blank if you have your $PATH variable set appropriately.'));
}
}
// Check path to CViTjs executable and make sure cvit.conf is writable
if ($form_state['values']['cvitjs_enabled']) {
$cvit_path = blast_ui_get_cvit_conf();
if (!$cvit_path || !file_exists($cvit_path)) {
$msg = "The CViTjs configuration file, cvit.conf, does not exist at the path given ("
. $form_state['values']['cvitjs_location']
. "). Please check your path. "
. "If you have not yet downloaded CViTjs, see the help tab for more information.";
form_set_error('cvitjs_location', t($msg));
}
if (!is_writable($cvit_path)) {
$msg = "The file $cvit_path is not writable by this page. "
. "Please enable write access for apache then try saving these settings again.";
form_set_error('cvitjs_location', t($msg));
}
}
// Empty contents of cvitjs_config textarea if it is disabled
if ($form['cvitjs']['cvitjs_config']['#disabled']) {
$form_state['values']['cvitjs_config'] = '';
}
// Check CViTjs configuration text
if ($form_state['values']['cvitjs_config']
&& !preg_match('/\[general\]\s*\ndata_default =.*/m',
$form_state['values']['cvitjs_config'])) {
$msg = "The CViTjs configuration text looks incorrect. "
. "It should contain a [general] section. "
. "See the help tab for more information.";
form_set_error('cvitjs_config', t($msg));
}
if ($form_state['values']['cvitjs_config']
&& !preg_match('/\[.*\]\s*\nconf = .*\ndefaultData =.*/m',
$form_state['values']['cvitjs_config'])) {
$msg = "The CViTjs configuration text looks incorrect. "
. "It should contain one section for each genome target. "
. "See the help tab for more information.";
form_set_error('cvitjs_config', t($msg));
}
}
/**
* Submit the Admin/settings form.
*/
function blast_ui_admin_form_submit($form, $form_state) {
//General
variable_set('blast_path', $form_state['values']['blast_path']);
variable_set('blast_threads', $form_state['values']['blast_threads']);
variable_set('eVal', $form_state['values']['eVal']);
variable_set('qRange', $form_state['values']['qRange']);
// Uploads
variable_set('blast_ui_allow_query_upload', $form_state['values']['query_upload']);
variable_set('blast_ui_allow_target_upload', $form_state['values']['target_upload']);
// Example sequence
variable_set('blast_ui_nucleotide_example_sequence', $form_state['values']['nucleotide_example']);
variable_set('blast_ui_protein_example_sequence', $form_state['values']['protein_example']);
// Protect against large result sets
variable_set('blast_ui_max_results_displayed', $form_state['values']['max_results_displayed']);
// Whole genome visualization - CViTjs
variable_set('blast_ui_cvitjs_enabled', $form_state['values']['cvitjs_enabled']);
if ($form_state['values']['cvitjs_enabled'] && $form_state['values']['cvitjs_config']) {
// Need absolute path to conf file to write
$cvit_conf_path = getcwd() . DIRECTORY_SEPARATOR
. blast_ui_get_cvit_conf($form_state['values']['cvitjs_location']);
if ($fh = fopen($cvit_conf_path, 'w')) {
fwrite($fh, $form_state['values']['cvitjs_config']);
fclose($fh);
}
else {
drupal_set_message("Unable to open CViTjs conf file for writing: <pre>" . print_r(error_get_last(),true) . "</pre>");
}
}
//eksc:
// Warning text
variable_set('blast_ui_warning_text', $form_state['values']['warning_text']);
}