-
Notifications
You must be signed in to change notification settings - Fork 7
/
tripal_phylotree.module
276 lines (248 loc) · 9.15 KB
/
tripal_phylotree.module
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
<?php
/**
* @file
* Integrates the Chado Phylotree module with Drupal Nodes & Views
*/
/**
* @defgroup tripal_phylotree Phylotree Module
* @ingroup tripal_modules
* @{
* Integrates the Chado Phylotree module with Drupal Nodes
* @}
*/
require_once 'theme/tripal_phylotree.theme.inc';
require_once 'includes/tripal_phylotree.admin.inc';
require_once 'includes/tripal_phylotree.chado_node.inc';
require_once 'includes/tripal_phylotree_userinfo_block.inc';
/**
* Implements hook_permission().
*
* Set the permission types that the chado module uses. Essentially we
* want permissionis that protect creation, editing and deleting of chado
* data objects
*
* @ingroup tripal_phylotree
*/
function tripal_phylotree_permission() {
return array(
'access chado_phylotree content' => array(
'title' => t('View Phylotrees'),
'description' => t('Allow users to view phylotree pages.'),
),
'administer tripal phylotree' => array(
'title' => t('Administer Phylotrees'),
'description' => t('Allow users to administer all phylotrees.'),
),
);
}
/**
* Implements hook_menu().
*
* Menu items are automatically added for the new node types created
* by this module to the 'Create Content' Navigation menu item. This function
* adds more menu items needed for this module.
*
* @ingroup tripal_phylotree
*/
function tripal_phylotree_menu() {
$items = array();
// administration landing page. currently has no content but is
// apparently required for the Sync and Help links to work.
$items['admin/tripal/extension/tripal_phylotree'] = array(
'title' => 'Phylotrees',
'description' => 'Phylogenetic trees & gene families',
'page callback' => 'tripal_phylotree_admin_phylotrees_listing',
'access arguments' => array('administer tripal phylotree'),
'type' => MENU_NORMAL_ITEM,
);
// help menu
$items['admin/tripal/extension/tripal_phylotree/help'] = array(
'title' => 'Help',
'description' => 'Basic Description of Tripal Phylotree Module Functionality',
'page callback' => 'theme',
'page arguments' => array('tripal_phylotree_help'),
'access arguments' => array('administer tripal phylotree'),
'type' => MENU_LOCAL_TASK,
'weight' => 10
);
// configuration menu item
$items['admin/tripal/extension/tripal_phylotree/configuration'] = array(
'title' => 'Settings',
'description' => 'Configure the Tripal Phylotree module',
'page callback' => 'drupal_get_form',
'page arguments' => array('tripal_phylotree_admin'),
'access arguments' => array('administer tripal phylotree'),
'type' => MENU_LOCAL_TASK,
'weight' => 5
);
// sync menu item (will be rendered as a tab by tripal)
$items['admin/tripal/extension/tripal_phylotree/sync'] = array(
'title' => ' Sync',
'description' => 'Create pages on this site for phylotrees stored in Chado',
'page callback' => 'drupal_get_form',
'page arguments' => array('chado_node_sync_form', 'tripal_phylotree', 'chado_phylotree'),
'access arguments' => array('administer tripal phylotree'),
'type' => MENU_LOCAL_TASK,
'weight' => 2
);
// menu hook to fetch gene tree by name
$items['chado_phylotree/%'] = array(
'page callback' => 'phylotree_by_name',
'page arguments' => array(1),
'access callback' => TRUE // allow all anonymous http clients
);
// A menu hook to redirect to gene tree and hilight corresponding
// node name (polypeptide) for the given gene name
// /chado_gene_phylotree_v2?gene_name=C.cajan_38960_gene
// or comma separated list of gene names
// /chado_gene_phylotree_v2?gene_name=Araip.8X95G,Araip.JJJ8N,Araip.B0L4D
$items['chado_gene_phylotree_v2'] = array(
'page callback' => 'phylotree_redirect_by_gene',
'access callback' => TRUE, // allow all anonymous http clients
);
$items['chado_gene_phylotree/%/text'] = array(
'page callback' => 'phylotree_by_genename_text',
// found this strategy described here: http://stackoverflow.com/questions/2285944/returning-untemplated-output-in-drupal-from-menu-callback-function
// not sure if it has advantages over the simpler approach described in the top answer, but seemed worth exploring
'delivery callback' => 'tripal_phylotree_text_deliver',
'page arguments' => array(1),
'access callback' => TRUE // allow all anonymous http clients
);
// route for viewing json of all phylonodes having this phylotree_id
$items['chado_phylotree/%/json'] = array(
'page callback' => 'phylotree_json_endpoint',
'page arguments' => array(1),
'access callback' => TRUE // allow all anonymous http clients
);
// route for static scripts/ content; this is the aurelia-cli build folder.
$items['chado_phylotree/scripts/%'] = array(
'page callback' => 'phylotree_static_scripts',
'page arguments' => array(2),
'access callback' => TRUE // allow all anonymous http requests
);
// route for getting text of msa
$items['chado_phylotree_msa/%/text'] = array(
'page callback' => 'phylotree_msa_download',
'delivery callback' => 'tripal_phylotree_text_deliver',
'page arguments' => array(1),
'access callback' => TRUE // allow all anonymous http clients
);
return $items;
}
/**
* Implements hook_views_api().
*
* Essentially this hook tells drupal that there is views support for
* for this module which then includes tripal_db.views.inc where all the
* views integration code is
*
* @ingroup tripal_phylotree
*/
function tripal_phylotree_views_api() {
$path = drupal_get_path('module', 'tripal_phylotree');
return array(
'api' => 3.0,
'path' => $path . '/includes/views',
'template path' => $path .'/themes'
);
}
/**
* Implements hook_search_biological_data_views().
* Adds the described views to the "Search Data" Page created by Tripal Views
*
* @ingroup tripal_phylotree
*/
function tripal_phylotree_search_biological_data_views() {
return array(
'tripal_phylotree_user_phylotree' => array(
'machine_name' => 'tripal_phylotree_user_phylotree',
'human_name' => 'Phylotrees',
'description' => 'Gene trees, species trees, etc.',
'link' => 'chado/phylotree'
),
);
}
/**
* Implements hook_theme().
*
* We need to let drupal know about our theme functions and their arguments.
* We create theme functions to allow users of the module to customize the
* look and feel of the output generated in this module
*
* @ingroup tripal_phylotree
*/
function tripal_phylotree_theme($existing, $type, $theme, $path) {
$core_path = drupal_get_path('module', 'tripal_core');
$items = array(
// built-in theme
'node__chado_phylotree' => array(
'template' => 'node--chado-generic',
'render element' => 'node',
'base hook' => 'node',
'path' => "$core_path/theme/templates",
),
// base template for this page (default tab) includes the phylogram
'tripal_phylotree_base' => array(
'variables' => array('node' => NULL),
'template' => 'tripal_phylotree_base',
'path' => "$path/theme/templates",
),
// partial for cross references block
'tripal_phylotree_references' => array(
'variables' => array('node' => NULL),
'template' => 'tripal_phylotree_references',
'path' => "$path/theme/templates",
),
// partial for analysis block
'tripal_phylotree_analysis' => array(
'variables' => array('node' => NULL),
'template' => 'tripal_phylotree_analysis',
'path' => "$path/theme/templates",
),
// partial for teaser view
'tripal_phylotree_teaser' => array(
'variables' => array('node' => NULL),
'template' => 'tripal_phylotree_teaser',
'path' => "$path/theme/templates",
),
);
return $items;
}
/**
* hook_form_alter
*
* Add a validator to the search form.
* */
function tripal_phylotree_form_alter(&$form, &$form_state, $form_id) {
//drupal_set_message("Form ID is: $form_id"); ?~@~S uncomment to verify form name
if ($form_id == 'views_exposed_form') { $form['#validate'][] = 'tripal_phylotree_form_validate';
//drupal_set_message("Validation is set to " . var_export($form['#validate'], true)); -- uncomment to verify validator was added
}
}
/**
* Form validator for search form.
* Use this to trim whitespace from text fields.
*/
function tripal_phylotree_form_validate($form, &$form_state) {
//drupal_set_message("Form values are " . var_export($form_state['values'], true)); -- uncomment to see form field names
$form_state['values']['phylotree_name'] = trim($form_state['values']['phylotree_name']);
$form_state['values']['phylotree_comment'] = trim($form_state['values']['phylotree_comment']);
$form_state['values']['domains_con'] = trim($form_state['values']['domains_con']);
}
/**
* Implements hook_help().
* Adds a help page to the module list
*
* @ingroup tripal_phylotree
*/
function tripal_phylotree_help ($path, $arg) {
if ($path == 'admin/help#tripal_phylotree') {
return theme('tripal_phylotree_help', array());
}
}
function tripal_phylotree_text_deliver($page_callback_result) {
print $page_callback_result;
drupal_exit();
}
// hack to suppress the 'Submitted by...' info drupal adds to nodes
$variables['display_submitted'] = FALSE;