tripal_feature.admin.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. *
  8. *
  9. * @ingroup tripal_feature
  10. */
  11. function tripal_feature_admin() {
  12. // before proceeding check to see if we have any
  13. // currently processing jobs. If so, we don't want
  14. // to give the opportunity to sync libraries
  15. $active_jobs = FALSE;
  16. if (tripal_get_module_active_jobs('tripal_feature')) {
  17. $active_jobs = TRUE;
  18. }
  19. if (!$active_jobs) {
  20. get_tripal_feature_admin_form_url_set($form);
  21. $form['browser'] = array(
  22. '#type' => 'fieldset',
  23. '#title' => t('Feature Browser'),
  24. '#collapsible' => 1,
  25. '#collapsed' => 1 ,
  26. );
  27. $allowedoptions1 = array(
  28. 'show_feature_browser' => "Show the feature browser on the organism page. The browser loads when page loads. This may be slow for large sites.",
  29. 'hide_feature_browser' => "Hide the feature browser on the organism page. Disables the feature browser completely.",
  30. );
  31. // $allowedoptions ['allow_feature_browser'] = "Allow loading of the feature browsing through AJAX. For large sites the initial page load will be quick with the feature browser loading afterwards.";
  32. $form['browser']['browser_desc'] = array(
  33. '#type' => 'markup',
  34. '#value' => 'A feature browser can be added to an organism page to allow users to quickly '.
  35. 'access a feature. This will most likely not be the ideal mechanism for accessing feature '.
  36. 'information, especially for large sites, but it will alow users exploring the site (such '.
  37. 'as students) to better understand the data types available on the site.',
  38. );
  39. $form['browser']['feature_types'] = array(
  40. '#title' => t('Feature Types'),
  41. '#type' => 'textarea',
  42. '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that " .
  43. "will be shown in the feature browser."),
  44. '#default_value' => variable_get('chado_browser_feature_types', 'gene contig'),
  45. );
  46. $form['browser']['browse_features'] = array(
  47. '#title' => 'Feature Browser on Organism Page',
  48. '#type' => 'radios',
  49. '#options' => $allowedoptions1,
  50. '#default_value' => variable_get('tripal_feature_browse_setting', 'show_feature_browser'),
  51. );
  52. $form['browser']['browse_features_library'] = array(
  53. '#title' => 'Feature Browser on Library Page',
  54. '#type' => 'radios',
  55. '#options' => array(
  56. 'show_feature_browser' => "Show the feature browse on the library page. The browser loads when page loads. This may be slow for large sites.",
  57. 'hide_feature_browser' => "Hide the feature browser on the library page. Disables the feature browser completely.",
  58. ),
  59. '#default_value' => variable_get('tripal_library_feature_browse_setting', 'show_feature_browser'),
  60. );
  61. $form['browser']['browse_features_analysis'] = array(
  62. '#title' => 'Feature Browser on Analysis Page',
  63. '#type' => 'radios',
  64. '#options' => array(
  65. 'show_feature_browser' => "Show the feature browse on the analysis page. The browser loads when page loads. This may be slow for large sites.",
  66. 'hide_feature_browser' => "Hide the feature browser on the analysis page. Disables the feature browser completely.",
  67. ),
  68. '#default_value' => variable_get('tripal_analysis_feature_browse_setting', 'show_feature_browser'),
  69. );
  70. $form['browser']['set_browse_button'] = array(
  71. '#type' => 'submit',
  72. '#value' => t('Set Browser'),
  73. '#weight' => 2,
  74. );
  75. $form['feature_edit'] = array(
  76. '#type' => 'fieldset',
  77. '#title' => t('Feature Editing'),
  78. '#collapsible' => 1,
  79. '#collapsed' => 1 ,
  80. );
  81. $form['feature_edit']['browser_desc'] = array(
  82. '#type' => 'markup',
  83. '#value' => 'When editing or creating a feature, a user must provide the feature type. '.
  84. 'The Sequence Ontology list is very large, therefore, to simply the list of types for the user, the following '.
  85. 'textbox allows you to specify which features types can be used. This list of terms will appear in the '.
  86. 'feature type drop down list of the feature creation/edit form.',
  87. );
  88. $form['feature_edit']['feature_edit_types'] = array(
  89. '#title' => t('Feature Types'),
  90. '#type' => 'textarea',
  91. '#description' => t("Enter the Sequence Ontology (SO) terms for the allowed feature types when creating or editing features."),
  92. '#default_value' => variable_get('chado_edit_feature_types', 'gene contig EST mRNA'),
  93. );
  94. $form['feature_edit']['set_feature_types'] = array(
  95. '#type' => 'submit',
  96. '#value' => t('Set Feature Types'),
  97. );
  98. $form['summary'] = array(
  99. '#type' => 'fieldset',
  100. '#title' => t('Feature Summary Report'),
  101. '#collapsible' => 1,
  102. '#collapsed' => 1 ,
  103. );
  104. $allowedoptions2 ['show_feature_summary'] = "Show the feature summary on the organism page. The summary loads when page loads.";
  105. $allowedoptions2 ['hide_feature_summary'] = "Hide the feature summary on the organism page. Disables the feature summary.";
  106. $form['summary']['feature_summary'] = array(
  107. '#title' => 'Feature Summary on Organism Page',
  108. '#description' => 'A feature summary can be added to an organism page to allow users to see the '.
  109. 'type and quantity of features available for the organism.',
  110. '#type' => 'radios',
  111. '#options' => $allowedoptions2,
  112. '#default_value' => variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
  113. );
  114. $form['summary']['feature_mapping'] = array(
  115. '#title' => 'Map feature types',
  116. '#description' => t('You may specify which Sequence Ontology (SO) terms to show in the '.
  117. 'feature summary report by listing them in the following text area. Enter one per line. '.
  118. 'If left blank, all SO terms for all features will be shown in the report. Only those terms '.
  119. 'listed below will be shown in the report. Terms will appear in the report in the same order listed. To rename a '.
  120. 'SO term to be more human readable form, use an \'=\' sign after the SO term (e.g. \'polypeptide = Protein\')'),
  121. '#type' => 'textarea',
  122. '#rows' => 15,
  123. '#default_value' => variable_get('tripal_feature_summary_report_mapping', ''),
  124. );
  125. $form['summary']['set_summary_button'] = array(
  126. '#type' => 'submit',
  127. '#value' => t('Set Summary'),
  128. '#weight' => 2,
  129. );
  130. get_tripal_feature_admin_form_taxonomy_set($form);
  131. get_tripal_feature_admin_form_reindex_set($form);
  132. get_tripal_feature_admin_form_cleanup_set($form);
  133. }
  134. else {
  135. $form['notice'] = array(
  136. '#type' => 'fieldset',
  137. '#title' => t('Feature Management Temporarily Unavailable')
  138. );
  139. $form['notice']['message'] = array(
  140. '#value' => t('Currently, feature management jobs are waiting or ".
  141. "are running. Managemment features have been hidden until these ".
  142. "jobs complete. Please check back later once these jobs have ".
  143. "finished. You can view the status of pending jobs in the Tripal ".
  144. "jobs page.'),
  145. );
  146. }
  147. return system_settings_form($form);
  148. }
  149. /**
  150. *
  151. *
  152. * @ingroup tripal_feature
  153. */
  154. function tripal_feature_admin_validate($form, &$form_state) {
  155. global $user; // we need access to the user info
  156. $job_args = array();
  157. variable_set('chado_browser_feature_types', $form_state['values']['feature_types']);
  158. // if the user wants to sync up the chado features then
  159. // add the job to the management queue
  160. switch ($form_state['values']['op']) {
  161. case t('Sync all Features') :
  162. tripal_add_job('Sync all features', 'tripal_feature',
  163. 'tripal_feature_sync_features', $job_args, $user->uid);
  164. break;
  165. case t('Set/Reset Taxonomy for all feature nodes') :
  166. tripal_add_job('Set all feature taxonomy', 'tripal_feature',
  167. 'tripal_features_set_taxonomy', $job_args, $user->uid);
  168. break;
  169. case t('Reindex all feature nodes') :
  170. tripal_add_job('Reindex all features', 'tripal_feature',
  171. 'tripal_features_reindex', $job_args, $user->uid);
  172. break;
  173. case t('Clean up orphaned features') :
  174. tripal_add_job('Cleanup orphaned features', 'tripal_feature',
  175. 'tripal_features_cleanup', $job_args, $user->uid);
  176. break;
  177. case t('Set Browser') :
  178. variable_set('tripal_feature_browse_setting', $form_state['values']['browse_features']);
  179. variable_set('tripal_library_feature_browse_setting', $form_state['values']['browse_features_library']);
  180. variable_set('tripal_analysis_feature_browse_setting', $form_state['values']['browse_features_analysis']);
  181. break;
  182. case t('Set Feature Types') :
  183. variable_set('tripal_feature_type_setting', $form_state['values']['feature_edit_types']);
  184. break;
  185. case t('Set Summary') :
  186. variable_set('tripal_feature_summary_setting', $form_state['values']['feature_summary']);
  187. variable_set('tripal_feature_summary_report_mapping', $form_state['values']['feature_mapping']);
  188. break;
  189. case t('Set Feature URLs') :
  190. variable_set('chado_feature_url', $form_state['values']['feature_url']);
  191. tripal_add_job('Set Feature URLs', 'tripal_feature',
  192. 'tripal_feature_set_urls', $job_args, $user->uid);
  193. break;
  194. }
  195. }
  196. /**
  197. *
  198. *
  199. * @ingroup tripal_feature
  200. */
  201. function get_tripal_feature_admin_form_cleanup_set(&$form) {
  202. $form['cleanup'] = array(
  203. '#type' => 'fieldset',
  204. '#title' => t('Clean Up'),
  205. '#collapsible' => 1,
  206. '#collapsed' => 1 ,
  207. );
  208. $form['cleanup']['description'] = array(
  209. '#type' => 'item',
  210. '#value' => t("With Drupal and chado residing in different databases ".
  211. "it is possible that nodes in Drupal and features in Chado become ".
  212. "\"orphaned\". This can occur if a feature node in Drupal is ".
  213. "deleted but the corresponding chado feature is not and/or vice ".
  214. "versa. The Cleanup function will also remove nodes for features ".
  215. "that are not in the list of allowed feature types as specified ".
  216. "above. This is helpful when a feature type needs to be ".
  217. "removed but was previously present as Drupal nodes. ".
  218. "Click the button below to resolve these discrepancies."),
  219. '#weight' => 1,
  220. );
  221. $form['cleanup']['button'] = array(
  222. '#type' => 'submit',
  223. '#value' => t('Clean up orphaned features'),
  224. '#weight' => 2,
  225. );
  226. }
  227. /**
  228. *
  229. *
  230. * @ingroup tripal_feature
  231. */
  232. function get_tripal_feature_admin_form_reindex_set(&$form) {
  233. $form['reindex'] = array(
  234. '#type' => 'fieldset',
  235. '#title' => t('Index/Reindex'),
  236. '#collapsible' => 1,
  237. '#collapsed' => 1 ,
  238. );
  239. $form['reindex']['description'] = array(
  240. '#type' => 'item',
  241. '#value' => t("Indexing or reindexing of nodes is required for Drupal's full text searching. ".
  242. "Index features for the first time to allow for searching of content, and later when content for features ".
  243. "is updated. Depending on the number of features this may take ".
  244. "quite a while. Click the button below to begin reindexing of ".
  245. "features. "),
  246. '#weight' => 1,
  247. );
  248. $form['reindex']['button'] = array(
  249. '#type' => 'submit',
  250. '#value' => t('Reindex all feature nodes'),
  251. '#weight' => 2,
  252. );
  253. }
  254. /**
  255. *
  256. *
  257. * @ingroup tripal_feature
  258. */
  259. function get_tripal_feature_admin_form_taxonomy_set(&$form) {
  260. $form['taxonomy'] = array(
  261. '#type' => 'fieldset',
  262. '#title' => t('Set Taxonomy'),
  263. '#collapsible' => 1,
  264. '#collapsed' => 1 ,
  265. );
  266. $form['taxonomy']['description'] = array(
  267. '#type' => 'item',
  268. '#value' => t("Drupal allows for assignment of \"taxonomy\" or ".
  269. "catagorical terms to nodes. These terms allow for advanced ".
  270. "filtering during searching."),
  271. '#weight' => 1,
  272. );
  273. $tax_options = array(
  274. 'organism' => t('Organism name'),
  275. 'feature_type' => t('Feature Type (e.g. EST, mRNA, etc.)'),
  276. 'analysis' => t('Analysis Name'),
  277. 'library' => t('Library Name'),
  278. );
  279. $form['taxonomy']['tax_classes'] = array(
  280. '#title' => t('Available Taxonomic Classes'),
  281. '#type' => t('checkboxes'),
  282. '#description' => t("Please select the class of terms to assign to ".
  283. "chado features"),
  284. '#required' => FALSE,
  285. '#prefix' => '<div id="taxclass_boxes">',
  286. '#suffix' => '</div>',
  287. '#options' => $tax_options,
  288. '#weight' => 2,
  289. '#default_value' => variable_get('tax_classes', ''),
  290. );
  291. $form['taxonomy']['button'] = array(
  292. '#type' => 'submit',
  293. '#value' => t('Set/Reset Taxonomy for all feature nodes'),
  294. '#weight' => 3,
  295. );
  296. }
  297. function get_tripal_feature_admin_form_url_set(&$form) {
  298. $form['url'] = array(
  299. '#type' => 'fieldset',
  300. '#title' => t('Feature URL Path')
  301. );
  302. $form['url']['desc'] = array(
  303. '#type' => 'markup',
  304. '#value' => t('Each synced feature will have a unique URL which consists of '.
  305. 'the site domain followed by a unique identifer: for '.
  306. 'example http://my-tripal-site.org/ID1034, where the '.
  307. 'element just after the final slash is the unique '.
  308. 'identifier for the feature.'),
  309. );
  310. $options = array(
  311. 'internal ID' => 'Internal ID (Chado feature_id)',
  312. 'feature unique name' => 'Feature unique name',
  313. 'feature name' => 'Feature name',
  314. 'genus_species_uqname' => 'Genus + species + unique name (e.g. http://your.site.url/[genus]/[genus]_[species]/[unique_name]',
  315. 'genus_species_name' => 'Genus + species + name (e.g. http://your.site.url/[genus]/[genus]_[species]/[name]',
  316. );
  317. $form['url']['chado_feature_url'] = array(
  318. '#title' => t('Unique Identifier'),
  319. '#type' => 'radios',
  320. '#description' => t('Choose an identifier type '.
  321. 'from the list above that is guaranteed to be unique in your synced '.
  322. 'dataset. If in doubt it is safest to coose the internal ID. '.
  323. 'The descrpitor need not be unique amont the total dataset. '.
  324. 'It only need be unique among the synced dataset.'),
  325. '#required' => FALSE,
  326. '#options' => $options,
  327. '#default_value' => variable_get('chado_feature_url', 'internal ID'),
  328. );
  329. $form['url']['chado_feature_accession_prefix'] = array(
  330. '#title' => t('ID Prefix'),
  331. '#type' => t('textfield'),
  332. '#description' => t("If you choose an Internal ID above you must also enter an ID prefix.".
  333. "this prefix will be prepended to the internal ID number (e.g. ID38294). ".
  334. "if you chose to use the feature name or unique name then this prfix is not used"),
  335. '#required' => TRUE,
  336. '#default_value' => variable_get('chado_feature_accession_prefix', 'ID'),
  337. );
  338. $form['url']['button'] = array(
  339. '#type' => 'submit',
  340. '#value' => t('Set Feature URLs'),
  341. '#weight' => 3,
  342. );
  343. }