tripal_feature.admin.inc 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. <?php
  2. /**
  3. * Purpose: Provide Guidance to new Tripal Admin
  4. *
  5. * @return
  6. * HTML Formatted text
  7. *
  8. * @ingroup tripal_feature
  9. */
  10. function tripal_feature_module_description_page() {
  11. $text .= '<h3>Tripal Feature Administrative Tools Quick Links:</h3>';
  12. $text .= "<ul>
  13. <li><a href=\"".url("admin/tripal/tripal_feature/configuration") . "\">Feature Configuration</a></li>
  14. <li><a href=\"".url("admin/tripal/tripal_feature/fasta_loader"). "\">Import a multi-FASTA file</a></li>
  15. <li><a href=\"".url("admin/tripal/tripal_feature/gff3_load"). "\">Import a GFF3 file</a></li>
  16. <li><a href=\"".url("admin/tripal/tripal_feature/sync") . "\">Sync Features</a></li>
  17. <li><a href=\"".url("admin/tripal/tripal_feature/delete") . "\">Delete Features</a></li>
  18. </ul>";
  19. # <li><a href=\"".url("admin/tripal/tripal_feature/aggregate"). "\">Feature Relationship Aggegators</a></li>
  20. $text .= '<h3>Module Description:</h3>';
  21. $text .= '<p>This module provides an interface for the Chado feature module which stores information
  22. related to genomic features. This module provides support for bulk loading of data in
  23. FASTA or GFF format, visualization of "feature" pages, editing and updating.
  24. </p>';
  25. $text .= '<h3>Setup Instructions:</h3>';
  26. $text .= '<p>After installation of the feature module. The following tasks should be performed
  27. <ol>
  28. <li><p><b>Set Permissions</b>: The feature module supports the Drupal user permissions interface for
  29. controlling access to feature content and functions. These permissions include viewing,
  30. creating, editing or administering of
  31. feature content. The default is that only the original site administrator has these
  32. permissions. You can <a href="'.url('admin/user/roles').'">add roles</a> for classifying users,
  33. <a href="'.url('admin/user/user').'">assign users to roles</a> and
  34. <a href="'.url('admin/user/permissions').'">assign permissions</a> for the feature content to
  35. those roles. For a simple setup, allow anonymous users access to view organism content and
  36. allow the site administrator all other permissions.</p></li>
  37. <li><p><b>Themeing</b>: Before content from Chado can be visualized the Tripal base theme must
  38. be installed. This should have been done prior to this point. But is mentioned here in the event you
  39. follow the instructions below and cannot see content. In this case, if you do not see content
  40. check that Tripal theming is properly installed</p></li>
  41. <li><p><b>Loading of Ontologies</b>: If you
  42. used Tripal to create the Chado database, then you must load ontologies before proceeding. Visit the
  43. page to <a href="'.url('admin/tripal/tripal_cv/obo_loader').'">load ontologies</a> and load at
  44. least the following ontologies:
  45. <ul>
  46. <li>Chado Feature Properties</li>
  47. <li>Relationship Ontology</li>
  48. <li>Sequence Ontology</li>
  49. <li>Gene Ontology (if loading GO terms for features)</li>
  50. </ul></p></li>
  51. <li><p><b>Create Organisms</b>: Before adding feature data you must already have the
  52. organisms loaded in the database. See the
  53. <a href="'.url('admin/tripal/tripal_organism').'">Tripal Organism Admin page</a> for
  54. instructions for adding and Syncing organisms.</p></li>
  55. <li><p><b>Create Analysis</b>: Tripal requires that feature data loaded using the Tripal loaders
  56. be associated with an analyis. This provides a grouping for the feature data and can be used
  57. later to visualize data pipelines. Before loading feature data through the FASTA or GFF loaders
  58. you will need to <a href="'.url('node/add').'">create an analysis</a> for the data.</p></li>
  59. <li><p><b>Create Referring Database Entries</b>: If you would like to associate your feature data with an
  60. external reference database, check to ensure that the <a href="'.url('admin/tripal/tripal_db/edit_db').'">
  61. database record already exists</a>. If not you should <a href="'.url('admin/tripal/tripal_db/add_db').'">add a new database record</a> before importing
  62. feature data.</p></li>
  63. <li><p><b>Data Import</b>: if you do not already have an existing Chado database with preloaded data
  64. then you will want
  65. to import data. You can do so using the Chado perl scripts that come with the normal
  66. <a href="http://gmod.org/wiki/Chado">distribution of Chado</a> or you can use the <a href="'.url('admin/tripal/tripal_feature/fasta_loader').'">FASTA loader</a> and
  67. <a href="'.url('admin/tripal/tripal_feature/gff3_load').'">GFF loader</a> provided here. If you
  68. created the Chado database using Tripal then you\'ll most likely want to use the Tripal loaders. If your data
  69. is not condusive for loading with these loaders you may have to write your own loaders.
  70. </p></li>
  71. <li><p><b>Sync Features</b>: After data is loaded you need to sync features. This process is what
  72. creates the pages for viewing online. Not all features need be synced. For instance, if you
  73. have loaded whole genome sequence with fully defined gene models with several features to define
  74. a gene and its products (e.g. gene, mRNA, CDS, 5\'UTR, 3\'UTR, etc) you probably only want to create
  75. pages for genes or genes and mRNA. You probably do not want a page for a 5\'UTR.
  76. Using the <a href="'.url('admin/tripal/tripal_feature/configuration/sync').'">Feature Sync page</a>
  77. you can sync (or create pages) for the desired feature types. </p></li>
  78. <li><p><b>Set Feature URL</b>: It is often convenient to have a simple URL for each feature page.
  79. For example, http://www.mygenomesite.org/[feature], where [feature] is a unique identifier for a feature page.
  80. With this, people can easily include links to feature pages of interest. Use the
  81. <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a>
  82. to specify whether to use the feature name, unique name or internal ID as the [feature] portion of the
  83. URL. Select the one that will guarantee a unique identifier for feature pages.</p></li>
  84. <li><p><b>Indexing</b>: Once all data has been loaded (including analysis data--e.g. blast, interpro, etc.)
  85. you can index all feature pages for searching if you want to ues the Drupal default search mechanism.
  86. Use the <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a>
  87. to either Index (for the first time) or "Reindex" (after adding new data)
  88. the feature pages for searching. Once the site is 100% indexed the pages will be searchable using Drupal\'s
  89. full text searching. You can find the percent indexed for the entire site by visiting the
  90. <a href="'.url('admin/settings/search').'">Search settings page</a>. Indexing
  91. can take quite a while if you have a lot of data</p></li>
  92. <li><p><b>Set Taxonomy</b>: Drupal provides a mechanism for categorizing content to allow
  93. for advanced searching. Drupal calls this "Taxonomy", but is essentially categorizing the pages.
  94. You can categorize feature pages by their type (e.g. gene, mRNA, contig, EST, etc.) and by the
  95. organism to which they belong. This allows for filtering of search results by organism and feature type.
  96. Use the <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a> to
  97. set the Taxonomy.</p></li>
  98. </ol>
  99. </p>';
  100. $text .= '<h3>Features of this Module:</h3>';
  101. $text .= '<p>Aside from data loading and feature page setup (as described in the Setup section above),
  102. The Tripal feature module also provides the following functionality
  103. <ul>
  104. <li><p><b>Feature Browser:</b> The feature browser is a tabular list of features with links to their
  105. feature pages which appears on the organism
  106. page. It was created to provide a mechanism to allow site visitors to quickly
  107. accesss feature pages when they do not know what to search for. For sites with large numbers of features, this
  108. method for finding a specific pages is inadequate, but may still be included to aid new site
  109. visitors. This browser can be toggled on or off using the
  110. <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a></p></li>
  111. <li><p><b>Feature Summary:</b> The feature summary is a pie chart that indicates the types and quantities
  112. of feature types (Sequence Ontology terms) that are loaded in the database. It appears on the organism
  113. page. The summary can be toggled on or off using the
  114. <a href="'.url('admin/tripal/tripal_feature/configuration').'">Feature Configuration page</a></p></li>
  115. <li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
  116. a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
  117. It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database
  118. and create custom lists without PHP programming or customization of Tripal source code. Views can also
  119. be created to filter content that has not yet been synced with Druapl in order to protect access to non
  120. published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing
  121. Views <a href="'.url('admin/build/views/').'">here</a>, as well as create your own. </p></li>
  122. <li><p><b>Basic Feature Lookup View</b>: This module provides a basic <a href="'.url('features').'">feature search
  123. tool</a> for finding or listing features in Chado. It does not require indexing for Drupal searching but relies
  124. on Drupal Views. <a href="http://drupal.org/project/views">Drupal Views</a> must be installed. </p></li>
  125. <li><p><b>Delete Features</b>: This module provides a <a href="'.url('admin/tripal/tripal_feature/delete').'">Delete Feature page</a>
  126. for bulk deltions of features. You may delete features using a list of feature names, or for a specific organism
  127. or for a specific feature type.</p></li>
  128. </ul>
  129. </p>';
  130. $text .= '<h3>Page Customizations</h3>';
  131. $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
  132. Below is a description of several methods. These methods may be used in conjunction with one another to
  133. provide fine-grained control.
  134. <ul>
  135. <li><p><b>Integration with Drupal Panels</b>: <a href="http://drupal.org/project/views">Drupal Panels</a>
  136. allows for customization of a page layout if you don\'t want to do PHP/Javascript/CSS programming. Tripal comes with pre-set layouts for feature pages. However,
  137. Panels become useful if you prefer a layout that is different from the pre-set layouts. Chado content
  138. is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
  139. Panel\'s GUI.</p></li>
  140. <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the
  141. <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
  142. to any page without need to edit template files or knowing PHP. You must first download and install CCK.
  143. With CCK, the site administartor can create a new field to appear on the page. For example, currently,
  144. the Chado publication module is not yet supported by Tripal. Therefore, the site administrator can add a text
  145. field to the feature pages. This content is not stored in Chado, but will appear on the feature page. A field
  146. added by CCK will also appear in the form when editing a feature to allow users to manually enter the appropriate
  147. text. If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
  148. indicate that it is not to be shown (using the CCK interface), then manually add the new content type
  149. where desired by editing the templates (as described below). If using Panels, the CCK field can be added to the
  150. location desired using the Panels interface.</p></li>
  151. <li><p><b>Drupal Node Templates</b>: The Tripal packages comes with a "theme_tripal" directory that contains the
  152. themeing for Chado content. The feature module has a template file for feature "nodes" (Tripal feature pages). This file
  153. is named "node-chado_feature.tpl.php", and provides javascript, HTML and PHP code for display of the feature
  154. pages. You can edit this file to control which types of information (or which feature "blocks") are displayed for features. Be sure to
  155. copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  156. future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
  157. for instructions on how to access variables and other Chado content within the template file.</p></li>
  158. <li><p><b>Feature "Block" Templates</b>: In the "theme_tripal" directory is a subdirectory named "tripal_feature".
  159. Inside this directory is a set of templates that control distinct types of information for features. For example,
  160. there is a "base" template for displaying of data directly from the Chado feature table, and a "references"
  161. template for showing external site references for a feature (data from the feature_dbxref table). These templates are used both by Drupal blocks
  162. for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
  163. provides (also desribed above). You can customize this template as you desire. Be sure to copy the
  164. template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  165. future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
  166. for instructions on how to access variables and other Chado content within the template files.</p></li>
  167. </li>
  168. <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
  169. will see a "Resources" sidebar on each page. The links that appear on the sidebar are automatically generated
  170. using Javascript for all of the feature "Blocks" that appear on the page. If you want to add additional links
  171. (e.g. a dynamic link to GBrowse for the feature) and you want that link to appear in the
  172. "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
  173. section at the bottom of the template file where the resources section is found.</p></li>
  174. </ul>
  175. </p>';
  176. return $text;
  177. }
  178. /**
  179. *
  180. *
  181. * @ingroup tripal_feature
  182. */
  183. function tripal_feature_admin () {
  184. // before proceeding check to see if we have any
  185. // currently processing jobs. If so, we don't want
  186. // to give the opportunity to sync libraries
  187. $active_jobs = FALSE;
  188. if(tripal_get_module_active_jobs('tripal_feature')){
  189. $active_jobs = TRUE;
  190. }
  191. if(!$active_jobs){
  192. get_tripal_feature_admin_form_url_set($form);
  193. $form['browser'] = array(
  194. '#type' => 'fieldset',
  195. '#title' => t('Feature Browser')
  196. );
  197. $allowedoptions1 = array (
  198. 'show_feature_browser' => "Show the feature browser on the organism page. The browser loads when page loads. This may be slow for large sites.",
  199. 'hide_feature_browser' => "Hide the feature browser on the organism page. Disables the feature browser completely.",
  200. );
  201. // $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.";
  202. $form['browser']['browser_desc'] = array(
  203. '#type' => 'markup',
  204. '#value' => 'A feature browser can be added to an organism page to allow users to quickly '.
  205. 'access a feature. This will most likely not be the ideal mechanism for accessing feature '.
  206. 'information, especially for large sites, but it will alow users exploring the site (such '.
  207. 'as students) to better understand the data types available on the site.',
  208. );
  209. $form['browser']['feature_types'] = array(
  210. '#title' => t('Feature Types'),
  211. '#type' => 'textarea',
  212. '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that ".
  213. "will be shown in the feature browser."),
  214. '#default_value' => variable_get('chado_browser_feature_types','gene contig'),
  215. );
  216. $form['browser']['browse_features'] = array(
  217. '#title' => 'Feature Browser on Organism Page',
  218. '#type' => 'radios',
  219. '#options' => $allowedoptions1,
  220. '#default_value'=>variable_get('tripal_feature_browse_setting', 'show_feature_browser'),
  221. );
  222. $form['browser']['set_browse_button'] = array(
  223. '#type' => 'submit',
  224. '#value' => t('Set Browser'),
  225. '#weight' => 2,
  226. );
  227. $form['feature_edit'] = array(
  228. '#type' => 'fieldset',
  229. '#title' => t('Feature Editing')
  230. );
  231. $form['feature_edit']['browser_desc'] = array(
  232. '#type' => 'markup',
  233. '#value' => 'When editing or creating a feature, a user must provide the feature type. '.
  234. 'The Sequence Ontology list is very large, therefore, to simply the list of types for the user, the following '.
  235. 'textbox allows you to specify which features types can be used. This list of terms will appear in the '.
  236. 'feature type drop down list of the feature creation/edit form.',
  237. );
  238. $form['feature_edit']['feature_edit_types'] = array(
  239. '#title' => t('Feature Types'),
  240. '#type' => 'textarea',
  241. '#description' => t("Enter the Sequence Ontology (SO) terms for the allowed feature types when creating or editing features."),
  242. '#default_value' => variable_get('chado_edit_feature_types','gene contig EST mRNA'),
  243. );
  244. $form['feature_edit']['set_feature_types'] = array(
  245. '#type' => 'submit',
  246. '#value' => t('Set Feature Types'),
  247. );
  248. $form['summary'] = array(
  249. '#type' => 'fieldset',
  250. '#title' => t('Feature Summary')
  251. );
  252. $allowedoptions2 ['show_feature_summary'] = "Show the feature summary on the organism page. The summary loads when page loads.";
  253. $allowedoptions2 ['hide_feature_summary'] = "Hide the feature summary on the organism page. Disables the feature summary.";
  254. $form['summary']['feature_summary'] = array(
  255. '#title' => 'Feature Summary on Organism Page',
  256. '#description' => 'A feature summary can be added to an organism page to allow users to see the '.
  257. 'type and quantity of features available for the organism.',
  258. '#type' => 'radios',
  259. '#options' => $allowedoptions2,
  260. '#default_value'=>variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
  261. );
  262. $form['summary']['set_summary_button'] = array(
  263. '#type' => 'submit',
  264. '#value' => t('Set Summary'),
  265. '#weight' => 2,
  266. );
  267. get_tripal_feature_admin_form_taxonomy_set($form);
  268. get_tripal_feature_admin_form_reindex_set($form);
  269. get_tripal_feature_admin_form_cleanup_set($form);
  270. } else {
  271. $form['notice'] = array(
  272. '#type' => 'fieldset',
  273. '#title' => t('Feature Management Temporarily Unavailable')
  274. );
  275. $form['notice']['message'] = array(
  276. '#value' => t('Currently, feature management jobs are waiting or ".
  277. "are running. Managemment features have been hidden until these ".
  278. "jobs complete. Please check back later once these jobs have ".
  279. "finished. You can view the status of pending jobs in the Tripal ".
  280. "jobs page.'),
  281. );
  282. }
  283. return system_settings_form($form);
  284. }
  285. /**
  286. *
  287. *
  288. * @ingroup tripal_feature
  289. */
  290. function tripal_feature_admin_validate($form, &$form_state) {
  291. global $user; // we need access to the user info
  292. $job_args = array();
  293. variable_set('chado_browser_feature_types',$form_state['values']['feature_types']);
  294. // if the user wants to sync up the chado features then
  295. // add the job to the management queue
  296. switch ($form_state['values']['op']){
  297. case t('Sync all Features') :
  298. tripal_add_job('Sync all features','tripal_feature',
  299. 'tripal_feature_sync_features',$job_args,$user->uid);
  300. break;
  301. case t('Set/Reset Taxonomy for all feature nodes') :
  302. tripal_add_job('Set all feature taxonomy','tripal_feature',
  303. 'tripal_features_set_taxonomy',$job_args,$user->uid);
  304. break;
  305. case t('Reindex all feature nodes') :
  306. tripal_add_job('Reindex all features','tripal_feature',
  307. 'tripal_features_reindex',$job_args,$user->uid);
  308. break;
  309. case t('Clean up orphaned features') :
  310. tripal_add_job('Cleanup orphaned features','tripal_feature',
  311. 'tripal_features_cleanup',$job_args,$user->uid);
  312. break;
  313. case t('Set Browser') :
  314. variable_set('tripal_feature_browse_setting',$form_state['values']['browse_features']);
  315. break;
  316. case t('Set Feature Types') :
  317. variable_set('tripal_feature_type_setting',$form_state['values']['feature_edit_types']);
  318. break;
  319. case t('Set Summary') :
  320. variable_set('tripal_feature_summary_setting',$form_state['values']['feature_summary']);
  321. break;
  322. case t('Set Feature URLs') :
  323. variable_set('chado_feature_url',$form_state['values']['feature_url']);
  324. tripal_add_job('Set Feature URLs','tripal_feature',
  325. 'tripal_feature_set_urls',$job_args,$user->uid);
  326. break;
  327. }
  328. }
  329. /**
  330. *
  331. *
  332. * @ingroup tripal_feature
  333. */
  334. function get_tripal_feature_admin_form_cleanup_set(&$form) {
  335. $form['cleanup'] = array(
  336. '#type' => 'fieldset',
  337. '#title' => t('Clean Up')
  338. );
  339. $form['cleanup']['description'] = array(
  340. '#type' => 'item',
  341. '#value' => t("With Drupal and chado residing in different databases ".
  342. "it is possible that nodes in Drupal and features in Chado become ".
  343. "\"orphaned\". This can occur if a feature node in Drupal is ".
  344. "deleted but the corresponding chado feature is not and/or vice ".
  345. "versa. The Cleanup function will also remove nodes for features ".
  346. "that are not in the list of allowed feature types as specified ".
  347. "above. This is helpful when a feature type needs to be ".
  348. "removed but was previously present as Drupal nodes. ".
  349. "Click the button below to resolve these discrepancies."),
  350. '#weight' => 1,
  351. );
  352. $form['cleanup']['button'] = array(
  353. '#type' => 'submit',
  354. '#value' => t('Clean up orphaned features'),
  355. '#weight' => 2,
  356. );
  357. }
  358. /**
  359. *
  360. *
  361. * @ingroup tripal_feature
  362. */
  363. function get_tripal_feature_admin_form_reindex_set(&$form) {
  364. $form['reindex'] = array(
  365. '#type' => 'fieldset',
  366. '#title' => t('Index/Reindex')
  367. );
  368. $form['reindex']['description'] = array(
  369. '#type' => 'item',
  370. '#value' => t("Indexing or reindexing of nodes is required for Drupal's full text searching. ".
  371. "Index features for the first time to allow for searching of content, and later when content for features ".
  372. "is updated. Depending on the number of features this may take ".
  373. "quite a while. Click the button below to begin reindexing of ".
  374. "features. "),
  375. '#weight' => 1,
  376. );
  377. $form['reindex']['button'] = array(
  378. '#type' => 'submit',
  379. '#value' => t('Reindex all feature nodes'),
  380. '#weight' => 2,
  381. );
  382. }
  383. /**
  384. *
  385. *
  386. * @ingroup tripal_feature
  387. */
  388. function get_tripal_feature_admin_form_taxonomy_set (&$form) {
  389. $form['taxonomy'] = array(
  390. '#type' => 'fieldset',
  391. '#title' => t('Set Taxonomy')
  392. );
  393. $form['taxonomy']['description'] = array(
  394. '#type' => 'item',
  395. '#value' => t("Drupal allows for assignment of \"taxonomy\" or ".
  396. "catagorical terms to nodes. These terms allow for advanced ".
  397. "filtering during searching."),
  398. '#weight' => 1,
  399. );
  400. $tax_options = array (
  401. 'organism' => t('Organism name'),
  402. 'feature_type' => t('Feature Type (e.g. EST, mRNA, etc.)'),
  403. 'analysis' => t('Analysis Name'),
  404. 'library' => t('Library Name'),
  405. );
  406. $form['taxonomy']['tax_classes'] = array (
  407. '#title' => t('Available Taxonomic Classes'),
  408. '#type' => t('checkboxes'),
  409. '#description' => t("Please select the class of terms to assign to ".
  410. "chado features"),
  411. '#required' => FALSE,
  412. '#prefix' => '<div id="taxclass_boxes">',
  413. '#suffix' => '</div>',
  414. '#options' => $tax_options,
  415. '#weight' => 2,
  416. '#default_value' => variable_get('tax_classes',''),
  417. );
  418. $form['taxonomy']['button'] = array(
  419. '#type' => 'submit',
  420. '#value' => t('Set/Reset Taxonomy for all feature nodes'),
  421. '#weight' => 3,
  422. );
  423. }
  424. function get_tripal_feature_admin_form_url_set (&$form) {
  425. $form['url'] = array(
  426. '#type' => 'fieldset',
  427. '#title' => t('Feature URL Path')
  428. );
  429. $form['url']['desc'] = array (
  430. '#type' => 'markup',
  431. '#value' => t('Each synced feature will have a unique URL which consists of '.
  432. 'the site domain followed by a unique identifer: for '.
  433. 'example http://my-tripal-site.org/ID1034, where the '.
  434. 'element just after the final slash is the unique '.
  435. 'identifier for the feature.'),
  436. );
  437. $form['url']['chado_feature_url'] = array(
  438. '#title' => t('Unique Identifier'),
  439. '#type' => 'radios',
  440. '#description' => t('Choose an identifier type '.
  441. 'from the list above that is guaranteed to be unique in your synced '.
  442. 'dataset. If in doubt it is safest to coose the internal ID. '.
  443. 'The descrpitor need not be unique amont the total dataset. '.
  444. 'It only need be unique among the synced dataset.'),
  445. '#required' => FALSE,
  446. '#options' => array('internal ID' => 'internal ID (Chado feature_id)',
  447. 'feature unique name' => 'feature unique name',
  448. 'feature name' => 'feature name'),
  449. '#default_value' => variable_get('chado_feature_url','internal ID'),
  450. );
  451. $form['url']['chado_feature_accession_prefix'] = array (
  452. '#title' => t('ID Prefix'),
  453. '#type' => t('textfield'),
  454. '#description' => t("If you choose an Internal ID above you must also enter an ID prefix.".
  455. "this prefix will be prepended to the internal ID number (e.g. ID38294). ".
  456. "if you chose to use the feature name or unique name then this prfix is not used"),
  457. '#required' => TRUE,
  458. '#default_value' => variable_get('chado_feature_accession_prefix','ID'),
  459. );
  460. $form['url']['button'] = array(
  461. '#type' => 'submit',
  462. '#value' => t('Set Feature URLs'),
  463. '#weight' => 3,
  464. );
  465. }
  466. /**
  467. *
  468. *
  469. * @ingroup tripal_feature
  470. */
  471. function tripal_feature_aggregator_page(){
  472. $add_url = url("admin/tripal/tripal_feature/aggregate/new");
  473. $output = "<a href=\"$add_url\">Add a new aggregator</a>";
  474. $output .= drupal_get_form('tripal_feature_aggregator_select_form');
  475. $output .= '<div id="db-edit-div">Please select an aggregator base type to view or edit</div>';
  476. return $output;
  477. }
  478. /**
  479. *
  480. *
  481. * @ingroup tripal_feature
  482. */
  483. function tripal_feature_aggregator_select_form(){
  484. // get a list of base terms from chado for user to choose
  485. $sql = "SELECT DISTINCT type_id FROM {tripal_feature_relagg} ORDER BY type_id ";
  486. $results = db_query ($sql);
  487. $sql = "SELECT * FROM {cvterm} WHERE cvterm_id = %d";
  488. $previous_db = tripal_db_set_active('chado');
  489. $types = array();
  490. $types[] = '';
  491. while($base = db_fetch_object($results)){
  492. $term = db_fetch_object(db_query($sql,$base->type_id));
  493. $types[$base->type_id] = $term->name;
  494. }
  495. tripal_db_set_active($previous_db);
  496. $form['type_id'] = array(
  497. '#title' => t('Aggregator Base Type'),
  498. '#type' => 'select',
  499. '#options' => $types,
  500. '#ahah' => array(
  501. 'path' => 'admin/tripal/tripal_feature/aggregate/edit/js',
  502. 'wrapper' => 'db-edit-div',
  503. 'effect' => 'fade',
  504. 'event' => 'change',
  505. 'method' => 'replace',
  506. ),
  507. );
  508. return $form;
  509. }
  510. /**
  511. *
  512. *
  513. * @ingroup tripal_feature
  514. */
  515. function tripal_feature_aggregator_form(&$form_state = NULL,$type_id = NULL){
  516. // get this requested database
  517. if($type_id){
  518. $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d ";
  519. $tsql = "SELECT * FROM {cvterm} WHERE cvterm_id = %d ";
  520. // get the default list of terms
  521. $results = db_query($sql,$type_id);
  522. while($type = db_fetch_object($results)){
  523. $previous_db = tripal_db_set_active('chado');
  524. $term = db_fetch_object(db_query($tsql,$type->rel_type_id));
  525. tripal_db_set_active($previous_db);
  526. $default_others .= $term->name . " ";
  527. }
  528. $default_base = $base->name;
  529. $action = 'Update';
  530. $form['type_id'] = array(
  531. '#type' => 'hidden',
  532. '#value' => $type_id
  533. );
  534. } else {
  535. $action = 'Add';
  536. $form['base']= array(
  537. '#type' => 'textfield',
  538. '#title' => t('Base Feature type'),
  539. '#description' => t('Please enter the Sequence Ontology (SO) term for the base feature type for this aggregator.'),
  540. '#default_value' => $default_base,
  541. '#required' => TRUE,
  542. '#weight' => 1
  543. );
  544. }
  545. $form['others']= array(
  546. '#type' => 'textarea',
  547. '#title' => t('Aggregate these types if a relationship exists'),
  548. '#description' => t('Please enter the Sequence Ontology (SO) terms that should be aggregated with the base feature type listed above. Separate each by a space or newline'),
  549. '#default_value' => $default_others,
  550. '#required' => TRUE,
  551. '#weight' => 2
  552. );
  553. if(strcmp($action,'Update')==0){
  554. $form['update'] = array (
  555. '#type' => 'submit',
  556. '#value' => t('Update'),
  557. '#weight' => 5,
  558. '#executes_submit_callback' => TRUE,
  559. );
  560. $form['delete'] = array (
  561. '#type' => 'submit',
  562. '#value' => t('Delete'),
  563. '#weight' => 6,
  564. '#executes_submit_callback' => TRUE,
  565. );
  566. } else {
  567. $form['add'] = array (
  568. '#type' => 'submit',
  569. '#value' => t('Add'),
  570. '#weight' => 5,
  571. '#executes_submit_callback' => TRUE,
  572. );
  573. }
  574. $form['#redirect'] = 'admin/tripal/tripal_feature/aggregate';
  575. return $form;
  576. }
  577. /**
  578. *
  579. *
  580. * @ingroup tripal_feature
  581. */
  582. function tripal_feature_aggregator_form_validate($form, &$form_state){
  583. $type_id = $form_state['values']['type_id'];
  584. $base = $form_state['values']['base'];
  585. $others = $form_state['values']['others'];
  586. $op = $form_state['values']['op'];
  587. // split apart the feature types to be aggregated
  588. $types = preg_split('/\s+/',$others);
  589. // the SQL for finding the term
  590. $tsql = "
  591. SELECT *
  592. FROM {cvterm} CVT
  593. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  594. WHERE CVT.name = '%s' and CV.name = 'sequence'";
  595. // make sure the base type exists
  596. if($base){
  597. $previous_db = tripal_db_set_active('chado');
  598. $term = db_fetch_object(db_query($tsql,$base));
  599. tripal_db_set_active($previous_db);
  600. if(!$term){
  601. form_set_error('base',t('The specified base type is not a valid SO term'));
  602. }
  603. // make sure this type doesn't already in the table
  604. $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d ";
  605. $agg = db_fetch_object(db_query($sql,$term->cvterm_id));
  606. if($agg){
  607. form_set_error('base',t('The specified base type is already used as a base type for another aggregator and cannot be readded.'));
  608. }
  609. }
  610. // iterate through each type to be aggregated and make sure they are valid
  611. foreach($types as $type){
  612. $previous_db = tripal_db_set_active('chado');
  613. $term = db_fetch_object(db_query($tsql,$type));
  614. tripal_db_set_active($previous_db);
  615. if(!$term){
  616. form_set_error('others',t('The specified type ') . $type . t(' is not a valid SO term'));
  617. }
  618. }
  619. }
  620. /**
  621. *
  622. *
  623. * @ingroup tripal_feature
  624. */
  625. function tripal_feature_aggregator_form_submit($form, &$form_state){
  626. $type_id = $form_state['values']['type_id'];
  627. $base = $form_state['values']['base'];
  628. $others = $form_state['values']['others'];
  629. $op = $form_state['values']['op'];
  630. // split apart the feature types to be aggregated
  631. $types = preg_split('/\s+/',$others);
  632. // the SQL for finding the term
  633. $tsql = "
  634. SELECT *
  635. FROM {cvterm} CVT
  636. INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
  637. WHERE CVT.name = '%s' and CV.name = 'sequence'";
  638. // the SQL for deleting an aggregator
  639. $dsql = "
  640. DELETE FROM {tripal_feature_relagg}
  641. WHERE type_id = %d
  642. ";
  643. // if this is an insert then we have a base type name. We
  644. // need to get the corresponding term id
  645. if($base){
  646. $previous_db = tripal_db_set_active('chado');
  647. $term = db_fetch_object(db_query($tsql,$base));
  648. tripal_db_set_active($previous_db);
  649. $type_id = $term->cvterm_id;
  650. }
  651. if(strcmp($op,'Delete')==0){
  652. $result = db_query($dsql,$type_id);
  653. if($result){
  654. drupal_set_message("Aggregator deleted");
  655. } else {
  656. drupal_set_message("Failed to delete mailing list.");
  657. }
  658. }
  659. else {
  660. // for an update, first remove all the current aggregator settings
  661. // and we'll add them again
  662. $result = db_query($dsql,$type_id);
  663. // the SQL for inserting the aggregated types
  664. $isql = "
  665. INSERT INTO {tripal_feature_relagg}
  666. (type_id,rel_type_id)
  667. VALUES
  668. (%d,%d)
  669. ";
  670. // iterate through each type to be aggregated and add an entry in the table
  671. foreach($types as $type){
  672. $previous_db = tripal_db_set_active('chado');
  673. $term = db_fetch_object(db_query($tsql,$type));
  674. tripal_db_set_active($previous_db);
  675. $result = db_query($isql,$type_id,$term->cvterm_id);
  676. }
  677. drupal_set_message("Aggregator added");
  678. }
  679. return '';
  680. }
  681. /**
  682. *
  683. *
  684. * @ingroup tripal_feature
  685. */
  686. function tripal_feature_aggregator_ajax_edit (){
  687. // get the database id, build the form and then return the JSON object
  688. $type_id = $_POST['type_id'];
  689. $form = drupal_get_form('tripal_feature_aggregator_form',$type_id);
  690. drupal_json(array('status' => TRUE, 'data' => $form));
  691. }