tripal_featuremap.module 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. <?php
  2. /**
  3. * @defgroup tripal_featuremap Map
  4. * @{
  5. * Provides functions for managing chado maps including creating details pages for each map
  6. * @}
  7. * @ingroup tripal_modules
  8. */
  9. require('api/tripal_featuremap.api.inc');
  10. /**
  11. * Display help and module information
  12. * @param path which path of the site we're displaying help
  13. * @param arg array that holds the current path as would be returned from arg()
  14. * function
  15. * @return help text for the path
  16. *
  17. * @ingroup tripal_featuremap
  18. */
  19. function tripal_featuremap_help($path, $arg) {
  20. $output = '';
  21. switch ($path) {
  22. case "admin/help#tripal_featuremap":
  23. $output = '<p>'.
  24. t("Displays links to nodes created on this date") .
  25. '</p>';
  26. break;
  27. }
  28. return $output;
  29. }
  30. /**
  31. * Provide information to drupal about the node types that we're creating
  32. * in this module
  33. *
  34. * @ingroup tripal_featuremap
  35. */
  36. function tripal_featuremap_node_info() {
  37. $nodes = array();
  38. $nodes['chado_featuremap'] = array(
  39. 'name' => t('Map'),
  40. 'module' => 'chado_featuremap',
  41. 'description' => t('A feature map from the chado database (e.g. genetic map)'),
  42. 'has_title' => FALSE,
  43. 'title_label' => t('Feature Map'),
  44. 'has_body' => FALSE,
  45. 'body_label' => t('Feature Map Description'),
  46. 'locked' => TRUE
  47. );
  48. return $nodes;
  49. }
  50. /**
  51. * Set the permission types that the chado module uses. Essentially we
  52. * want permissionis that protect creation, editing and deleting of chado
  53. * data objects
  54. *
  55. * @ingroup tripal_featuremap
  56. */
  57. function tripal_featuremap_perm() {
  58. return array(
  59. 'access chado_featuremap content',
  60. 'create chado_featuremap content',
  61. 'delete chado_featuremap content',
  62. 'edit chado_featuremap content',
  63. );
  64. }
  65. /**
  66. * Set the permission types that the module uses.
  67. *
  68. * @ingroup tripal_featuremap
  69. */
  70. function chado_featuremap_access($op, $node, $account) {
  71. if ($op == 'create') {
  72. if (!user_access('create chado_featuremap content', $account)) {
  73. return FALSE;
  74. }
  75. }
  76. if ($op == 'update') {
  77. if (!user_access('edit chado_featuremap content', $account)) {
  78. return FALSE;
  79. }
  80. }
  81. if ($op == 'delete') {
  82. if (!user_access('delete chado_featuremap content', $account)) {
  83. return FALSE;
  84. }
  85. }
  86. if ($op == 'view') {
  87. if (!user_access('access chado_featuremap content', $account)) {
  88. return FALSE;
  89. }
  90. }
  91. return NULL;
  92. }
  93. /**
  94. * Menu items are automatically added for the new node types created
  95. * by this module to the 'Create Content' Navigation menu item. This function
  96. * adds more menu items needed for this module.
  97. *
  98. * @ingroup tripal_featuremap
  99. */
  100. function tripal_featuremap_menu() {
  101. $items = array();
  102. // The administative settings menu
  103. $items['admin/tripal/tripal_featuremap'] = array(
  104. 'title' => 'Maps',
  105. 'description' => 'Basic Description of Tripal Map Module Functionality',
  106. 'page callback' => 'tripal_featuremap_module_description_page',
  107. 'access arguments' => array('access administration pages'),
  108. 'type' => MENU_NORMAL_ITEM,
  109. );
  110. $items['admin/tripal/tripal_featuremap/configuration'] = array(
  111. 'title' => 'Configuration',
  112. 'description' => 'Manage integration of Chado maps including associated features.',
  113. 'page callback' => 'drupal_get_form',
  114. 'page arguments' => array('tripal_featuremap_admin'),
  115. 'access arguments' => array('access administration pages'),
  116. 'type' => MENU_NORMAL_ITEM,
  117. );
  118. // Synchronizing maps from Chado to Drupal
  119. $items['chado_sync_maps'] = array(
  120. 'title' => 'Sync Data',
  121. 'page callback' => 'tripal_featuremap_sync_maps',
  122. 'access arguments' => array('access administration pages'),
  123. 'type' => MENU_CALLBACK
  124. );
  125. // Displaying maps
  126. $items['maps'] = array(
  127. 'menu_name' => ('primary-links'), //Enable the 'Map' primary link
  128. 'title' => 'Feature Maps',
  129. 'page callback' => 'tripal_featuremap_show_maps',
  130. 'access arguments' => array('access chado_featuremap content'),
  131. 'type' => MENU_NORMAL_ITEM
  132. );
  133. return $items;
  134. }
  135. /**
  136. * Implements hook_views_api()
  137. * Purpose: Essentially this hook tells drupal that there is views support for
  138. * for this module which then includes tripal_db.views.inc where all the
  139. * views integration code is
  140. *
  141. * @ingroup tripal_featuremap
  142. */
  143. function tripal_featuremap_views_api() {
  144. return array(
  145. 'api' => 2.0,
  146. );
  147. }
  148. /**
  149. * Purpose: Provide Guidance to new Tripal Admin
  150. *
  151. * @return HTML Formatted text
  152. *
  153. * @ingroup tripal_featuremap
  154. */
  155. function tripal_featuremap_module_description_page() {
  156. $text = '';
  157. $text .= '<h3>Tripal Feature Map Administrative Tools Quick Links:</h3>';
  158. $text .= "<ul>
  159. <li><a href=\"" . url("admin/tripal/tripal_featuremap/configuration") . "\">Map Configuration</a></li>
  160. </ul>";
  161. $text .= '<h3>Module Description:</h3>';
  162. $text .= '<p>The Tripal Map module is an interface for the Chado Map module which groups features (sequences) into genetic maps.
  163. This module provides support for visualization of "map" pages, editing and updating.</p>';
  164. $text .= '<h3>Setup Instructions:</h3>';
  165. $text .= '<ol>';
  166. $text .= '<li><p><b>Set Permissions</b>: The map module supports the Drupal user permissions interface for
  167. controlling access to map content and functions. These permissions include viewing,
  168. creating, editing or administering of
  169. map content. The default is that only the original site administrator has these
  170. permissions. You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
  171. <a href="' . url('admin/user/user') . '">assign users to roles</a> and
  172. <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the map content to
  173. those roles. For a simple setup, allow anonymous users access to view organism content and
  174. allow the site administrator all other permissions.</p></li>';
  175. $text .= '<li><p><b>Sync any Existing Maps</b>: Near the top of the ' . l('Map Configuration page', 'admin/tripal/tripal_featuremap/configuration') . ' there is
  176. a Sync Maps section which provides list of maps currently in chado which can be sync\'d.
  177. Simply select the maps you would like to create Drupal/Tripal pages for and click Sync Maps.</p></li>';
  178. $text .= '</ol>';
  179. $text .= '<h3>Features of this Module:</h3>';
  180. $text .= '<ul>';
  181. $text .= '<li><b>Add/Edit/Delete Maps</b>: Maps with no associated features can be created ' . l('here', 'node/add/chado-map') . ' but it is
  182. recommended to create the map using the feature loader. For example, when you load FASTA files using the Tripal loader you are
  183. given the option of specifying a map for all created features. Existing Maps (regardless of the method used to create them) can be
  184. edited or deleted by clicking the Edit tab at the top of the Map Page.</li>';
  185. $text .= '<li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
  186. a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
  187. It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database
  188. and create custom lists without PHP programming or customization of Tripal source code. Views can also
  189. be created to filter content that has not yet been synced with Druapl in order to protect access to non
  190. published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing
  191. Views <a href="' . url('admin/build/views/') . '">here</a>, as well as create your own. </p></li>';
  192. $text .= '<li><b>Basic Listing</b>: This module provides a basic <a href="' . url('maps') . '">map display
  193. tool</a> for finding or listing maps in Chado. It does not require indexing for Drupal searching but relies
  194. on Drupal Views. <a href="http://drupal.org/project/views">Drupal Views</a> must be installed.</li>';
  195. $text .= '</ul>';
  196. $text .= '<h3>Page Customizations</h3>';
  197. $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
  198. Below is a description of several methods. These methods may be used in conjunction with one another to
  199. provide fine-grained control.
  200. <ul>
  201. <li><p><b>Integration with Drupal Panels</b>: <a href="http://drupal.org/project/views">Drupal Panels</a>
  202. 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 map pages. However,
  203. Panels become useful if you prefer a layout that is different from the pre-set layouts. Chado content
  204. is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
  205. Panel\'s GUI.</p></li>
  206. <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the
  207. <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
  208. to any page without need to edit template files or knowing PHP. You must first download and install CCK.
  209. With CCK, the site administartor can create a new field to appear on the page. For example, currently,
  210. the Chado publication module is not yet supported by Tripal. Therefore, the site administrator can add a text
  211. field to the map pages. This content is not stored in Chado, but will appear on the map page. A field
  212. added by CCK will also appear in the form when editing a map to allow users to manually enter the appropriate
  213. text. If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
  214. indicate that it is not to be shown (using the CCK interface), then manually add the new content type
  215. where desired by editing the templates (as described below). If using Panels, the CCK field can be added to the
  216. location desired using the Panels interface.</p></li>
  217. <li><p><b>Drupal Node Templates</b>: The Tripal packages comes with a "theme_tripal" directory that contains the
  218. themeing for Chado content. The map module has a template file for map "nodes" (Tripal map pages). This file
  219. is named "node-chado_featuremap.tpl.php", and provides javascript, HTML and PHP code for display of the map
  220. pages. You can edit this file to control which types of information (or which map "blocks") are displayed for maps. Be sure to
  221. copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  222. future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
  223. for instructions on how to access variables and other Chado content within the template file.</p></li>
  224. <li><p><b>Map "Block" Templates</b>: In the "theme_tripal" directory is a subdirectory named "tripal_featuremap".
  225. Inside this directory is a set of templates that control distinct types of information for maps. For example,
  226. there is a "base" template for displaying of data directly from the Chado map table. These templates are used both by Drupal blocks
  227. for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
  228. provides (also desribed above). You can customize this template as you desire. Be sure to copy the
  229. template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
  230. future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
  231. for instructions on how to access variables and other Chado content within the template files.</p></li>
  232. </li>
  233. <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
  234. will see a "Resources" sidebar on each page. The links that appear on the sidebar are automatically generated
  235. using Javascript for all of the map "Blocks" that appear on the page. If you want to add additional links
  236. (e.g. a link to a views table showing all features of the current map) and you want that link to appear in the
  237. "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
  238. section at the bottom of the template file where the resources section is found.</p></li>
  239. </ul>
  240. </p>';
  241. return $text;
  242. }
  243. /**
  244. * Administrative settings form
  245. *
  246. * @ingroup tripal_featuremap
  247. */
  248. function tripal_featuremap_admin() {
  249. $form = array();
  250. // before proceeding check to see if we have any
  251. // currently processing jobs. If so, we don't want
  252. // to give the opportunity to sync maps
  253. $active_jobs = FALSE;
  254. if (tripal_get_module_active_jobs('tripal_featuremap')) {
  255. $active_jobs = TRUE;
  256. }
  257. // add the field set for syncing maps
  258. if (!$active_jobs) {
  259. get_tripal_featuremap_admin_form_sync_set($form);
  260. get_tripal_featuremap_admin_form_cleanup_set($form);
  261. get_tripal_featuremap_admin_form_reindex_set($form);
  262. get_tripal_featuremap_admin_form_taxonomy_set($form);
  263. get_tripal_featuremap_admin_form_cleanup_set($form);
  264. }
  265. else {
  266. $form['notice'] = array(
  267. '#type' => 'fieldset',
  268. '#title' => t('Feature Map Management Temporarily Unavailable')
  269. );
  270. $form['notice']['message'] = array(
  271. '#value' => t('Currently, feature map management jobs are waiting or are running. Managemment features have been hidden until these jobs complete. Please check back later once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.'),
  272. );
  273. }
  274. return system_settings_form($form);
  275. }
  276. /**
  277. * Implementation of hook_nodeapi().
  278. * Display map information for associated features or organisms
  279. * This function also provides contents for indexing
  280. *
  281. * @ingroup tripal_featuremap
  282. */
  283. function tripal_featuremap_nodeapi(&$node, $op, $teaser, $page) {
  284. switch ($op) {
  285. // Note that this function only adds map view to an organism/feature
  286. // node.
  287. case 'view':
  288. // add the map to the organism/feature search indexing
  289. if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
  290. $node->content['tripal_featuremap_index_version'] = array(
  291. '#value' => theme('tripal_featuremap_search_index', $node),
  292. );
  293. }
  294. elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
  295. $node->content['tripal_featuremap_index_version'] = array(
  296. '#value' => theme('tripal_featuremap_search_result', $node),
  297. );
  298. }
  299. else {
  300. switch ($node->type) {
  301. case 'chado_organism':
  302. // Show map if the organism/feature is not at teaser view
  303. $node->content['tripal_organism_maps'] = array(
  304. '#value' => theme('tripal_organism_maps', $node),
  305. );
  306. break;
  307. case 'chado_feature':
  308. // Show map if the organism/feature is not at teaser view
  309. $node->content['tripal_feature_maps'] = array(
  310. '#value' => theme('tripal_feature_maps', $node),
  311. );
  312. break;
  313. }
  314. }
  315. break;
  316. }
  317. }
  318. /**
  319. * We need to let drupal know about our theme functions and their arguments.
  320. * We create theme functions to allow users of the module to customize the
  321. * look and feel of the output generated in this module
  322. *
  323. * @ingroup tripal_featuremap
  324. */
  325. function tripal_featuremap_theme() {
  326. return array(
  327. 'tripal_featuremap_search_index' => array(
  328. 'arguments' => array('node'),
  329. ),
  330. 'tripal_featuremap_search_result' => array(
  331. 'arguments' => array('node'),
  332. ),
  333. 'tripal_organism_maps' => array(
  334. 'arguments' => array('node' => NULL),
  335. 'template' => 'tripal_organism_maps',
  336. ),
  337. 'tripal_feature_maps' => array(
  338. 'arguments' => array('node' => NULL),
  339. 'template' => 'tripal_feature_maps',
  340. ),
  341. 'tripal_featuremap_base' => array(
  342. 'arguments' => array('node' => NULL),
  343. 'template' => 'tripal_featuremap_base',
  344. ),
  345. );
  346. }
  347. /**
  348. * This function is an extension of the chado_feature_view and
  349. * chado_organism_view by providing the markup for the map object
  350. * THAT WILL BE INDEXED.
  351. *
  352. * @ingroup tripal_featuremap
  353. */
  354. function theme_tripal_featuremap_search_index($node) {
  355. if ($node->type == 'chado_organism') {
  356. $content = "";
  357. }
  358. elseif ($node->type == 'chado_feature') {
  359. $content = "";
  360. }
  361. return $content;
  362. }
  363. /**
  364. *
  365. *
  366. * @ingroup tripal_featuremap
  367. */
  368. function get_tripal_featuremap_admin_form_cleanup_set(&$form) {
  369. $form['cleanup'] = array(
  370. '#type' => 'fieldset',
  371. '#title' => t('Clean Up')
  372. );
  373. $form['cleanup']['description'] = array(
  374. '#type' => 'item',
  375. '#value' => t("With Drupal and chado residing in different databases ".
  376. "it is possible that nodes in Drupal and maps in Chado become ".
  377. "\"orphaned\". This can occur if an map node in Drupal is ".
  378. "deleted but the corresponding chado map is not and/or vice ".
  379. "versa. Click the button below to resolve these discrepancies."),
  380. '#weight' => 1,
  381. );
  382. $form['cleanup']['button'] = array(
  383. '#type' => 'submit',
  384. '#value' => t('Clean up orphaned maps'),
  385. '#weight' => 2,
  386. );
  387. }
  388. /**
  389. *
  390. *
  391. * @ingroup tripal_featuremap
  392. */
  393. function get_tripal_featuremap_admin_form_taxonomy_set(&$form) {
  394. $form['taxonify'] = array(
  395. '#type' => 'fieldset',
  396. '#title' => t('Assign Drupal Taxonomy to Map Features')
  397. );
  398. // get the list of maps
  399. $sql = "SELECT * FROM {featuremap} ORDER BY uniquename";
  400. $previous_db = tripal_db_set_active('chado'); // use chado database
  401. $lib_rset = db_query($sql);
  402. tripal_db_set_active($previous_db); // now use drupal database
  403. // iterate through all of the maps
  404. $lib_boxes = array();
  405. while ($map = db_fetch_object($lib_rset)) {
  406. $lib_boxes[$map->map_id] = "$map->name";
  407. }
  408. $form['taxonify']['description'] = array(
  409. '#type' => 'item',
  410. '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
  411. "nodes. These terms allow for advanced filtering during searching. This option allows ".
  412. "for setting taxonomy only for features that belong to the selected maps below. All other features will be unaffected. To set taxonomy for all features in the site see the Feature Administration page."),
  413. '#weight' => 1,
  414. );
  415. $form['taxonify']['tx-maps'] = array(
  416. '#title' => t('Maps'),
  417. '#type' => t('checkboxes'),
  418. '#description' => t("Check the maps whose features you want to reset taxonomy. Note: this list contains all maps, even those that may not be synced."),
  419. '#required' => FALSE,
  420. '#prefix' => '<div id="lib_boxes">',
  421. '#suffix' => '</div>',
  422. '#options' => $lib_boxes,
  423. '#weight' => 2
  424. );
  425. $form['taxonify']['tx-button'] = array(
  426. '#type' => 'submit',
  427. '#value' => t('Set Feature Taxonomy'),
  428. '#weight' => 3
  429. );
  430. }
  431. /**
  432. *
  433. * @ingroup tripal_featuremap
  434. */
  435. function get_tripal_featuremap_admin_form_reindex_set(&$form) {
  436. // define the fieldsets
  437. $form['reindex'] = array(
  438. '#type' => 'fieldset',
  439. '#title' => t('Reindex Map Features')
  440. );
  441. // get the list of maps
  442. $sql = "SELECT * FROM {featuremap} ORDER BY uniquename";
  443. $previous_db = tripal_db_set_active('chado'); // use chado database
  444. $lib_rset = db_query($sql);
  445. tripal_db_set_active($previous_db); // now use drupal database
  446. // iterate through all of the maps
  447. $lib_boxes = array();
  448. while ($map = db_fetch_object($lib_rset)) {
  449. $lib_boxes[$map->map_id] = "$map->name";
  450. }
  451. $form['reindex']['description'] = array(
  452. '#type' => 'item',
  453. '#value' => t("This option allows for reindexing of only those features that belong to the selected maps below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
  454. '#weight' => 1,
  455. );
  456. $form['reindex']['re-maps'] = array(
  457. '#title' => t('Maps'),
  458. '#type' => t('checkboxes'),
  459. '#description' => t("Check the maps whoee features you want to reindex. Note: this list contains all maps, even those that may not be synced."),
  460. '#required' => FALSE,
  461. '#prefix' => '<div id="lib_boxes">',
  462. '#suffix' => '</div>',
  463. '#options' => $lib_boxes,
  464. '#weight' => 2,
  465. );
  466. $form['reindex']['re-button'] = array(
  467. '#type' => 'submit',
  468. '#value' => t('Reindex Features'),
  469. '#weight' => 3,
  470. );
  471. }
  472. /**
  473. *
  474. * @ingroup tripal_featuremap
  475. */
  476. function get_tripal_featuremap_admin_form_sync_set(&$form) {
  477. // define the fieldsets
  478. $form['sync'] = array(
  479. '#type' => 'fieldset',
  480. '#title' => t('Sync Maps')
  481. );
  482. // get the list of maps
  483. $sql = "SELECT * FROM {featuremap} ORDER BY uniquename";
  484. $previous_db = tripal_db_set_active('chado'); // use chado database
  485. $lib_rset = db_query($sql);
  486. tripal_db_set_active($previous_db); // now use drupal database
  487. // if we've added any maps to the list that can be synced
  488. // then we want to build the form components to allow the user
  489. // to select one or all of them. Otherwise, just present
  490. // a message stating that all maps are currently synced.
  491. $lib_boxes = array();
  492. $added = 0;
  493. while ($map = db_fetch_object($lib_rset)) {
  494. // check to see if the map is already present as a node in drupal.
  495. // if so, then skip it.
  496. $sql = "SELECT * FROM {chado_featuremap} WHERE map_id = %d";
  497. if (!db_fetch_object(db_query($sql, $map->map_id))) {
  498. $lib_boxes[$map->map_id] = "$map->name";
  499. $added++;
  500. }
  501. }
  502. // if we have maps we need to add to the checkbox then
  503. // build that form element
  504. if ($added > 0) {
  505. $lib_boxes['all'] = "All Maps";
  506. $form['reindex']['description'] = array(
  507. '#type' => 'item',
  508. '#value' => t("This option allows for the creation of Drupal content for maps in chado. Only the selected maps will be synced."),
  509. '#weight' => 1,
  510. );
  511. $form['sync']['maps'] = array(
  512. '#title' => t('Available Maps'),
  513. '#type' => t('checkboxes'),
  514. '#description' => t("Check the maps you want to sync. Drupal content will be created for each of the maps listed above. Select 'All Maps' to sync all of them."),
  515. '#required' => FALSE,
  516. '#prefix' => '<div id="lib_boxes">',
  517. '#suffix' => '</div>',
  518. '#options' => $lib_boxes,
  519. '#weight' => 2,
  520. );
  521. $form['sync']['button'] = array(
  522. '#type' => 'submit',
  523. '#value' => t('Sync Maps'),
  524. '#weight' => 3,
  525. );
  526. }
  527. // we don't have any maps to select from
  528. else {
  529. $form['sync']['value'] = array(
  530. '#value' => t('All maps in Chado are currently synced with Drupal.')
  531. );
  532. }
  533. }
  534. /**
  535. *
  536. * @ingroup tripal_featuremap
  537. */
  538. function tripal_featuremap_admin_validate($form, &$form_state) {
  539. global $user; // we need access to the user info
  540. $job_args = array();
  541. // Submit the Sync Job if selected
  542. if ($form_state['values']['op'] == t('Sync Maps')) {
  543. // check to see if the user wants to sync chado and drupal. If
  544. // so then we need to register a job to do so with tripal
  545. $maps = $form_state['values']['maps'];
  546. $do_all = FALSE;
  547. $to_sync = array();
  548. foreach ($maps as $map_id) {
  549. if (preg_match("/^all$/i", $map_id)) {
  550. $do_all = TRUE;
  551. }
  552. if ($map_id and preg_match("/^\d+$/i", $map_id)) {
  553. // get the map info
  554. $sql = "SELECT * FROM {Map} WHERE map_id = %d";
  555. $previous_db = tripal_db_set_active('chado'); // use chado database
  556. $map = db_fetch_object(db_query($sql, $map_id));
  557. tripal_db_set_active($previous_db); // now use drupal database
  558. $to_sync[$map_id] = $map->name;
  559. }
  560. }
  561. // submit the job to the tripal job manager
  562. if ($do_all) {
  563. tripal_add_job('Sync all maps', 'tripal_featuremap', 'tripal_featuremap_sync_maps', $job_args, $user->uid);
  564. }
  565. else{
  566. foreach ($to_sync as $map_id => $name) {
  567. $job_args[0] = $map_id;
  568. tripal_add_job("Sync map: $name", 'tripal_featuremap', 'tripal_featuremap_sync_maps', $job_args, $user->uid);
  569. }
  570. }
  571. }
  572. // -------------------------------------
  573. // Submit the Reindex Job if selected
  574. if ($form_state['values']['op'] == t('Reindex Features')) {
  575. $maps = $form_state['values']['re-maps'];
  576. foreach ($maps as $map_id) {
  577. if ($map_id and preg_match("/^\d+$/i", $map_id)) {
  578. // get the map info
  579. $sql = "SELECT * FROM {Map} WHERE map_id = %d";
  580. $previous_db = tripal_db_set_active('chado'); // use chado database
  581. $map = db_fetch_object(db_query($sql, $map_id));
  582. tripal_db_set_active($previous_db); // now use drupal database
  583. $job_args[0] = $map_id;
  584. tripal_add_job("Reindex features for map: $map->name", 'tripal_featuremap',
  585. 'tripal_featuremap_reindex_features', $job_args, $user->uid);
  586. }
  587. }
  588. }
  589. // -------------------------------------
  590. // Submit the Taxonomy Job if selected
  591. if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
  592. $maps = $form_state['values']['tx-maps'];
  593. foreach ($maps as $map_id) {
  594. if ($map_id and preg_match("/^\d+$/i", $map_id)) {
  595. // get the map info
  596. $sql = "SELECT * FROM {Map} WHERE map_id = %d";
  597. $previous_db = tripal_db_set_active('chado'); // use chado database
  598. $map = db_fetch_object(db_query($sql, $map_id));
  599. tripal_db_set_active($previous_db); // now use drupal database
  600. $job_args[0] = $map_id;
  601. tripal_add_job("Set taxonomy for features in map: $map->name", 'tripal_featuremap',
  602. 'tripal_featuremap_taxonify_features', $job_args, $user->uid);
  603. }
  604. }
  605. }
  606. // -------------------------------------
  607. // Submit the Cleanup Job if selected
  608. if ($form_state['values']['op'] == t('Clean up orphaned maps')) {
  609. tripal_add_job('Cleanup orphaned maps', 'tripal_featuremap',
  610. 'tripal_featuremap_cleanup', $job_args, $user->uid);
  611. }
  612. }
  613. /**
  614. *
  615. * @ingroup tripal_featuremap
  616. */
  617. function tripal_featuremap_cron() {
  618. }
  619. /**
  620. *
  621. * CHADO_LIBRARY NODE FUNCTIONS
  622. *
  623. * The following function proves access control for users trying to
  624. * perform actions on data managed by this module
  625. *
  626. * @ingroup tripal_featuremap
  627. */
  628. function tripal_featuremap_map_access($op, $node, $account) {
  629. if ($op == 'create') {
  630. if (!user_access('create chado_featuremap content', $account)) {
  631. return FALSE;
  632. }
  633. }
  634. if ($op == 'update') {
  635. if (!user_access('edit any chado_featuremap content', $account) &&
  636. !user_access('edit own chado_featuremap content', $account)) {
  637. return FALSE;
  638. }
  639. if (user_access('edit own chado_featuremap content', $account) &&
  640. $account->uid != $node->uid) {
  641. return FALSE;
  642. }
  643. }
  644. if ($op == 'delete') {
  645. if (!user_access('delete any chado_featuremap content', $account) &&
  646. !user_access('delete own chado_featuremap content', $account)) {
  647. return FALSE;
  648. }
  649. if (user_access('delete own chado_featuremap content', $account) &&
  650. $account->uid != $node->uid) {
  651. return FALSE;
  652. }
  653. }
  654. return NULL;
  655. }
  656. /**
  657. * validates submission of form when adding or updating a map node
  658. *
  659. * @ingroup tripal_featuremap
  660. */
  661. function chado_featuremap_validate($node) {
  662. $lib = 0;
  663. // check to make sure the unique name on the map is unique
  664. // before we try to insert into chado.
  665. if ($node->map_id) {
  666. $sql = "SELECT * FROM ".
  667. "{Map} WHERE ".
  668. "uniquename = '%s' ".
  669. "AND NOT map_id = %d";
  670. $previous_db = tripal_db_set_active('chado');
  671. $lib = db_fetch_object(db_query($sql, $node->uniquename,
  672. $node->map_id));
  673. tripal_db_set_active($previous_db);
  674. }
  675. else {
  676. $sql = "SELECT * FROM ".
  677. "{Map} ".
  678. "WHERE uniquename = '%s'";
  679. $previous_db = tripal_db_set_active('chado');
  680. $lib = db_fetch_object(db_query($sql, $node->uniquename));
  681. tripal_db_set_active($previous_db);
  682. }
  683. if ($lib) {
  684. form_set_error('uniquename', t('The unique map name already exists. '.
  685. 'Please choose another'));
  686. }
  687. }
  688. /**
  689. * When a new chado_featuremap node is created we also need to add information
  690. * to our chado_featuremap table. This function is called on insert of a new node
  691. * of type 'chado_featuremap' and inserts the necessary information.
  692. *
  693. * @ingroup tripal_featuremap
  694. */
  695. function chado_featuremap_insert($node) {
  696. if ($node->map_id) {
  697. $map['map_id'] = $node->map_id;
  698. }
  699. else {
  700. // get the map type id
  701. $values = array(
  702. 'cv_id' => array(
  703. 'name' => 'tripal'
  704. ),
  705. 'name' => $node->map_type
  706. );
  707. $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
  708. $values = array(
  709. 'name' => $node->title,
  710. 'uniquename' => $node->uniquename,
  711. 'organism_id' => $node->organism_id,
  712. 'type_id' => $type[0]->cvterm_id
  713. );
  714. $map = tripal_core_chado_insert('map', $values);
  715. }
  716. if ($map) {
  717. // add the description property
  718. tripal_featuremap_insert_property($map['map_id'], 'map_description', $node->map_description);
  719. // make sure the entry for this feature doesn't already exist in the chado_featuremap table
  720. // if it doesn't exist then we want to add it.
  721. $map_id = chado_get_id_for_node('map', $node) ;
  722. if (!$map_id) {
  723. // next add the item to the drupal table
  724. $sql = "INSERT INTO {chado_featuremap} (nid, vid, map_id) ".
  725. "VALUES (%d, %d, %d)";
  726. db_query($sql, $node->nid, $node->vid, $map['map_id']);
  727. }
  728. }
  729. else {
  730. drupal_set_message(t('Unable to add map.', 'warning'));
  731. watchdog('tripal_featuremap',
  732. 'Insert feature: Unable to create map where values: %values',
  733. array('%values' => print_r($values, TRUE)),
  734. WATCHDOG_WARNING
  735. );
  736. }
  737. }
  738. /**
  739. * Update nodes
  740. *
  741. * @ingroup tripal_featuremap
  742. */
  743. function chado_featuremap_update($node) {
  744. if ($node->revision) {
  745. // TODO -- decide what to do about revisions
  746. }
  747. else {
  748. $map_id = chado_get_id_for_node('map', $node) ;
  749. // get the map type id
  750. $values = array(
  751. 'cv_id' => array(
  752. 'name' => 'tripal'
  753. ),
  754. 'name' => $node->map_type
  755. );
  756. $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
  757. // update the map record
  758. $match = array(
  759. 'map_id' => $map_id,
  760. );
  761. $values = array(
  762. 'name' => $node->title,
  763. 'uniquename' => $node->uniquename,
  764. 'organism_id' => $node->organism_id,
  765. 'type_id' => $type[0]->cvterm_id
  766. );
  767. $status = tripal_core_chado_update('map', $match, $values);
  768. tripal_featuremap_update_property($map_id, 'map_description', $node->map_description);
  769. }
  770. }
  771. /**
  772. * Add the map as a taxonomy term for associating with map_features
  773. *
  774. * @ingroup tripal_featuremap
  775. */
  776. function tripal_featuremap_add_taxonomy($node, $map_id) {
  777. //include the file containing the required functions. We only have to
  778. // do this because Drupal 6 fails to do this globally for us and
  779. // the drupal_execute function below won't work
  780. module_load_include('inc', 'taxonomy', 'taxonomy.admin');
  781. /* // get the vocabulary id
  782. $vocabularies = taxonomy_get_vocabularies();
  783. $vid = NULL;
  784. foreach($vocabularies as $vocab){
  785. if($vocab->name == 'DNA Maps'){
  786. $vid = $vocab->vid;
  787. }
  788. }
  789. if(!$vid){ */
  790. // add the vocabulary
  791. $vocab_form['values']['name'] = 'DNA Maps';
  792. $vocab_form['values']['description'] = 'Allows for associating/searching of map features by map name';
  793. $vocab_form['values']['help'] = '';
  794. $vocab_form['values']['module'] = 'taxonomy';
  795. drupal_execute('taxonomy_form_vocabulary', $vocab_form);
  796. return;
  797. // }
  798. // make sure this term doesn't already exist. If it doesn't then add it
  799. if ($vid) {
  800. $tree = taxonomy_get_tree($vid);
  801. $found = 0;
  802. foreach ($tree as $term) {
  803. if ($term->name == $node->title) {
  804. $found = 1;
  805. }
  806. }
  807. // add the term to the vocabulary
  808. if (!$found) {
  809. $form_state = array();
  810. $form_state['values']['name'] = $node->title;
  811. $form_state['values']['description'] = $map_id;
  812. drupal_execute('taxonomy_form_term', $form_state, $vid);
  813. }
  814. }
  815. }
  816. /**
  817. * When editing or creating a new node of type 'chado_featuremap' we need
  818. * a form. This function creates the form that will be used for this.
  819. *
  820. * @ingroup tripal_featuremap
  821. */
  822. function chado_featuremap_form($node) {
  823. $form = array();
  824. $map = $node->map;
  825. // get the default values
  826. $uniquename = $node->uniquename;
  827. if (!$uniquename) {
  828. $uniquename = $map->uniquename;
  829. }
  830. $map_type = $node->map_type;
  831. if (!$map_type) {
  832. $map_type = $map->type_id->name;
  833. }
  834. $organism_id = $node->organism_id;
  835. if (!$organism_id) {
  836. $organism_id = $map->organism_id->organism_id;
  837. }
  838. $map_description = $node->map_description;
  839. if (!$map_description) {
  840. $libprop = tripal_featuremap_get_property($map->map_id, 'map_description');
  841. $map_description = $libprop->value;
  842. }
  843. // keep track of the map id if we have. If we do have one then
  844. // this is an update as opposed to an insert.
  845. $form['map_id'] = array(
  846. '#type' => 'value',
  847. '#value' => $map->map_id,
  848. );
  849. $form['title']= array(
  850. '#type' => 'textfield',
  851. '#title' => t('Map Title'),
  852. '#description' => t('Please enter the title for this map. '.
  853. 'This appears at the top of the map page.'),
  854. '#required' => TRUE,
  855. '#default_value' => $node->title,
  856. '#weight' => 1
  857. );
  858. $form['uniquename']= array(
  859. '#type' => 'textfield',
  860. '#title' => t('Unique Map Name'),
  861. '#description' => t('Please enter a unique name for this map'),
  862. '#required' => TRUE,
  863. '#default_value' => $uniquename,
  864. '#weight' => 2
  865. );
  866. // These map types should not be hard coded, but for now the are...
  867. $map_types = array();
  868. $map_types[''] = '';
  869. $map_types['cdna_map'] = 'cDNA Map';
  870. $map_types['bac_map'] = 'BAC Map';
  871. $map_types['fosmid_map'] = 'FOSMID Map';
  872. $map_types['cosmid_map'] = 'COSMID Map';
  873. $map_types['yac_map'] = 'YAC Map';
  874. $form['map_type'] = array(
  875. '#title' => t('Map Type'),
  876. '#type' => t('select'),
  877. '#description' => t("Choose the map type."),
  878. '#required' => TRUE,
  879. '#default_value' => $map_type,
  880. '#options' => $map_types,
  881. '#weight' => 3
  882. );
  883. // get the list of organisms
  884. $sql = "SELECT * FROM {Organism}";
  885. $previous_db = tripal_db_set_active('chado'); // use chado database
  886. $org_rset = db_query($sql);
  887. tripal_db_set_active($previous_db); // now use drupal database
  888. $organisms = array();
  889. $organisms[''] = '';
  890. while ($organism = db_fetch_object($org_rset)) {
  891. $organisms[$organism->organism_id] =
  892. "$organism->genus $organism->species ($organism->common_name)";
  893. }
  894. $form['organism_id'] = array(
  895. '#title' => t('Organism'),
  896. '#type' => t('select'),
  897. '#description' => t("Choose the organism with which this map is ".
  898. "associated."),
  899. '#required' => TRUE,
  900. '#default_value' => $organism_id,
  901. '#options' => $organisms,
  902. '#weight' => 4,
  903. );
  904. $form['map_description']= array(
  905. '#type' => 'textarea',
  906. '#title' => t('Map Description'),
  907. '#description' => t('A brief description of the map'),
  908. '#required' => TRUE,
  909. '#default_value' => $map_description,
  910. '#weight' => 5
  911. );
  912. return $form;
  913. }
  914. /**
  915. *
  916. *
  917. * @ingroup tripal_featuremap
  918. */
  919. function tripal_featuremap_sync_maps($map_id = NULL, $job_id = NULL) {
  920. global $user;
  921. $page_content = '';
  922. // get the list of maps and create new nodes
  923. if (!$map_id) {
  924. $sql = "SELECT * FROM {Map} L";
  925. $previous_db = tripal_db_set_active('chado'); // use chado database
  926. $results = db_query($sql);
  927. tripal_db_set_active($previous_db); // now use drupal database
  928. }
  929. else {
  930. $sql = "SELECT * FROM {Map} L WHERE map_id = %d";
  931. $previous_db = tripal_db_set_active('chado'); // use chado database
  932. $results = db_query($sql, $map_id);
  933. tripal_db_set_active($previous_db); // now use drupal database
  934. }
  935. // We'll use the following SQL statement for checking if the map
  936. // already exists as a drupal node.
  937. $sql = "SELECT * FROM {chado_featuremap} ".
  938. "WHERE map_id = %d";
  939. while ($map = db_fetch_object($results)) {
  940. // check if this map already exists in the drupal database. if it
  941. // does then skip this map and go to the next one.
  942. if (!db_fetch_object(db_query($sql, $map->map_id))) {
  943. $new_node = new stdClass();
  944. $new_node->type = 'chado_featuremap';
  945. $new_node->uid = $user->uid;
  946. $new_node->title = "$map->name";
  947. $new_node->map_id = $map->map_id;
  948. $new_node->organism_id = $map->organism_id;
  949. $new_node->uniquename = $map->uniquename;
  950. $new_node->type_id = $map->type_id;
  951. node_validate($new_node);
  952. $errors = form_get_errors();
  953. if (!$errors) {
  954. $node = node_submit($new_node);
  955. node_save($node);
  956. if ($node->nid) {
  957. print "Added " . $map->name . "\n";
  958. }
  959. else {
  960. print "ERROR: Unable to create " . $map->name . "\n";
  961. }
  962. }
  963. else {
  964. print "ERROR: Unable to create " . $map->name . "\n" . print_r($errors, TRUE) . "\n";
  965. }
  966. }
  967. else {
  968. print "Skipped " . $map->name . "\n";
  969. }
  970. }
  971. return $page_content;
  972. }
  973. /**
  974. * When a node is requested by the user this function is called to allow us
  975. * to add auxiliary data to the node object.
  976. *
  977. * @ingroup tripal_featuremap
  978. */
  979. function chado_featuremap_load($node) {
  980. // get the feature details from chado
  981. $map_id = chado_get_id_for_node('map', $node);
  982. $values = array('map_id' => $map_id);
  983. $map = tripal_core_generate_chado_var('map', $values);
  984. $additions = new stdClass();
  985. $additions->map = $map;
  986. return $additions;
  987. }
  988. /**
  989. * This function customizes the view of the chado_featuremap node. It allows
  990. * us to generate the markup. This function is required for node [Preview]
  991. *
  992. * @ingroup tripal_featuremap
  993. */
  994. function chado_featuremap_view($node, $teaser = FALSE, $page = FALSE) {
  995. // use drupal's default node view:
  996. if (!$teaser) {
  997. $node = node_prepare($node, $teaser);
  998. }
  999. return $node;
  1000. }
  1001. /**
  1002. *
  1003. * @ingroup tripal_featuremap
  1004. */
  1005. function tripal_featuremap_feature_set_taxonomy($map_id = NULL) {
  1006. //TO DO : return usable error if vocabs don't exist
  1007. // get the list of vocabularies and find our two vocabularies of interest
  1008. $vocabularies = taxonomy_get_vocabularies();
  1009. $vid = NULL;
  1010. foreach ($vocabularies as $vocab) {
  1011. if ($vocab->name == 'Map') {
  1012. $vid = $vocab->vid;
  1013. }
  1014. }
  1015. if (!$vid) {
  1016. return;
  1017. }
  1018. // We'll use the following SQL statement for getting the node info
  1019. if ($map_id) {
  1020. print "Finding features for map with ID: $map_id\n";
  1021. $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
  1022. "FROM {map_feature} LF ".
  1023. "INNER JOIN Map L ON LF.map_id = L.map_id ".
  1024. "WHERE L.map_id = $map_id ".
  1025. "ORDER BY LF.feature_id";
  1026. $previous_db = tripal_db_set_active('chado'); // use chado database
  1027. $features = db_query($sql);
  1028. tripal_db_set_active($previous_db); // now use drupal database
  1029. }
  1030. else {
  1031. print "Finding features for all maps\n";
  1032. $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
  1033. "FROM {map_feature} LF ".
  1034. "INNER JOIN Map L ON LF.map_id = L.map_id ".
  1035. "ORDER BY LF.feature_id";
  1036. $previous_db = tripal_db_set_active('chado'); // use chado database
  1037. $features = db_query($sql);
  1038. tripal_db_set_active($previous_db); // now use drupal database
  1039. }
  1040. $node_sql = "SELECT * FROM {chado_feature} CF ".
  1041. " INNER JOIN {node} N ON CF.nid = N.nid ".
  1042. "WHERE feature_id = %d";
  1043. // iterate through the features and add the taxonomy
  1044. while ($feature = db_fetch_object($features)) {
  1045. $node = db_fetch_object(db_query($node_sql, $feature->feature_id));
  1046. $tags["$vid"] = $feature->libname;
  1047. $terms['tags'] = $tags;
  1048. taxonomy_node_save($node, $terms);
  1049. print "Updated $feature->feature_id as $feature->libname\n";
  1050. }
  1051. }
  1052. /**
  1053. *
  1054. * @ingroup tripal_featuremap
  1055. */
  1056. function tripal_featuremap_reindex_features($map_id = NULL, $job_id = NULL) {
  1057. $i = 0;
  1058. // if the caller provided a map_id then get all of the features
  1059. // associated with the map. Otherwise get all sequences assoicated
  1060. // with all maps.
  1061. if ($map_id) {
  1062. $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
  1063. " FROM {map_feature} LF ".
  1064. " INNER JOIN Map L ON LF.map_id = L.map_id ".
  1065. "WHERE L.map_id = $map_id ".
  1066. "ORDER BY LF.feature_id";
  1067. $previous_db = tripal_db_set_active('chado'); // use chado database
  1068. $results = db_query($sql);
  1069. tripal_db_set_active($previous_db); // now use drupal database
  1070. }
  1071. else {
  1072. $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
  1073. " FROM {map_feature} LF ".
  1074. " INNER JOIN Map L ON LF.map_id = L.map_id ".
  1075. "ORDER BY LF.feature_id";
  1076. $previous_db = tripal_db_set_active('chado'); // use chado database
  1077. $results = db_query($sql);
  1078. tripal_db_set_active($previous_db); // now use drupal database
  1079. }
  1080. // load into ids array
  1081. $count = 0;
  1082. $ids = array();
  1083. while ($id = db_fetch_object($results)) {
  1084. $ids[$count] = $id->feature_id;
  1085. $count++;
  1086. }
  1087. $interval = intval($count * 0.01);
  1088. foreach ($ids as $feature_id) {
  1089. // update the job status every 1% features
  1090. if ($job_id and $i % interval == 0) {
  1091. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  1092. }
  1093. tripal_feature_sync_feature($feature_id);
  1094. $i++;
  1095. }
  1096. }
  1097. /**
  1098. *
  1099. * @ingroup tripal_featuremap
  1100. */
  1101. function tripal_featuremap_taxonify_features($map_id = NULL, $job_id = NULL) {
  1102. $i = 0;
  1103. // if the caller provided a map_id then get all of the features
  1104. // associated with the map. Otherwise get all sequences assoicated
  1105. // with all maps.
  1106. if ($map_id) {
  1107. $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
  1108. " FROM {map_feature} LF ".
  1109. " INNER JOIN Map L ON LF.map_id = L.map_id ".
  1110. "WHERE L.map_id = $map_id ".
  1111. "ORDER BY LF.feature_id";
  1112. $previous_db = tripal_db_set_active('chado'); // use chado database
  1113. $results = db_query($sql);
  1114. tripal_db_set_active($previous_db); // now use drupal database
  1115. }
  1116. else {
  1117. $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
  1118. " FROM {map_feature} LF ".
  1119. " INNER JOIN Map L ON LF.map_id = L.map_id ".
  1120. "ORDER BY LF.feature_id";
  1121. $previous_db = tripal_db_set_active('chado'); // use chado database
  1122. $results = db_query($sql);
  1123. tripal_db_set_active($previous_db); // now use drupal database
  1124. }
  1125. // load into ids array
  1126. $count = 0;
  1127. $ids = array();
  1128. while ($id = db_fetch_object($results)) {
  1129. $ids[$count] = $id->feature_id;
  1130. $count++;
  1131. }
  1132. // make sure our vocabularies are set before proceeding
  1133. tripal_feature_set_vocabulary();
  1134. // use this SQL for getting the nodes
  1135. $nsql = "SELECT * FROM {chado_feature} CF ".
  1136. " INNER JOIN {node} N ON N.nid = CF.nid ".
  1137. "WHERE feature_id = %d";
  1138. // iterate through the features and set the taxonomy
  1139. $interval = intval($count * 0.01);
  1140. foreach ($ids as $feature_id) {
  1141. // update the job status every 1% features
  1142. if ($job_id and $i % interval == 0) {
  1143. tripal_job_set_progress($job_id, intval(($i/$count)*100));
  1144. }
  1145. $node = db_fetch_object(db_query($nsql, $feature_id));
  1146. tripal_feature_set_taxonomy($node, $feature_id);
  1147. $i++;
  1148. }
  1149. }
  1150. /**
  1151. * Delete data from drupal and chado databases when a node is deleted
  1152. * @ingroup tripal_featuremap
  1153. */
  1154. function chado_featuremap_delete(&$node) {
  1155. $map_id = chado_get_id_for_node('map', $node);
  1156. // if we don't have a map id for this node then this isn't a node of
  1157. // type chado_featuremap or the entry in the chado_featuremap table was lost.
  1158. if (!$map_id){
  1159. return;
  1160. }
  1161. // Remove data from {chado_featuremap}, {node} and {node_revisions} tables of
  1162. // drupal database
  1163. $sql_del = "DELETE FROM {chado_featuremap} ".
  1164. "WHERE nid = %d ".
  1165. "AND vid = %d";
  1166. db_query($sql_del, $node->nid, $node->vid);
  1167. $sql_del = "DELETE FROM {node} ".
  1168. "WHERE nid = %d ".
  1169. "AND vid = %d";
  1170. db_query($sql_del, $node->nid, $node->vid);
  1171. $sql_del = "DELETE FROM {node_revisions} ".
  1172. "WHERE nid = %d ".
  1173. "AND vid = %d";
  1174. db_query($sql_del, $node->nid, $node->vid);
  1175. // Remove data from map and mapprop tables of chado database as well
  1176. $previous_db = tripal_db_set_active('chado');
  1177. db_query("DELETE FROM {map} WHERE map_id = %d", $map_id);
  1178. db_query("DELETE FROM {mapprop} WHERE map_id = %d", $map_id);
  1179. tripal_db_set_active($previous_db);
  1180. }
  1181. /**
  1182. * Display block with maps
  1183. * @param op - parameter to define the phase being called for the block
  1184. * @param delta - id of the block to return (ignored when op is list)
  1185. * @param edit - when op is save, contains the submitted form data
  1186. *
  1187. * @ingroup tripal_featuremap
  1188. */
  1189. function tripal_featuremap_block($op = 'list', $delta = '0', $edit = array()) {
  1190. switch ($op) {
  1191. case 'list':
  1192. $blocks['libreferences']['info'] = t('Tripal Map References');
  1193. $blocks['libreferences']['cache'] = BLOCK_NO_CACHE;
  1194. $blocks['libbase']['info'] = t('Tripal Map Details');
  1195. $blocks['libbase']['cache'] = BLOCK_NO_CACHE;
  1196. $blocks['libsynonyms']['info'] = t('Tripal Map Synonyms');
  1197. $blocks['libsynonyms']['cache'] = BLOCK_NO_CACHE;
  1198. $blocks['libproperties']['info'] = t('Tripal Map Properties');
  1199. $blocks['libproperties']['cache'] = BLOCK_NO_CACHE;
  1200. $blocks['featurelibs']['info'] = t('Tripal Feature Maps');
  1201. $blocks['featurelibs']['cache'] = BLOCK_NO_CACHE;
  1202. $blocks['orglibs']['info'] = t('Tripal Organism Maps');
  1203. $blocks['orglibs']['cache'] = BLOCK_NO_CACHE;
  1204. return $blocks;
  1205. case 'view':
  1206. if (user_access('access chado_featuremap content') and arg(0) == 'node' and is_numeric(arg(1))) {
  1207. $nid = arg(1);
  1208. $node = node_load($nid);
  1209. $block = array();
  1210. switch ($delta) {
  1211. case 'libreferences':
  1212. $block['subject'] = t('References');
  1213. $block['content'] = theme('tripal_featuremap_references', $node);
  1214. break;
  1215. case 'libbase':
  1216. $block['subject'] = t('Map Details');
  1217. $block['content'] = theme('tripal_featuremap_base', $node);
  1218. break;
  1219. case 'libsynonyms':
  1220. $block['subject'] = t('Synonyms');
  1221. $block['content'] = theme('tripal_featuremap_synonyms', $node);
  1222. break;
  1223. case 'libproperties':
  1224. $block['subject'] = t('Properties');
  1225. $block['content'] = theme('tripal_featuremap_properties', $node);
  1226. break;
  1227. case 'featurelibs':
  1228. $block['subject'] = t('Maps');
  1229. $block['content'] = theme('tripal_feature_maps', $node);
  1230. break;
  1231. case 'orglibs':
  1232. $block['subject'] = t('Maps');
  1233. $block['content'] = theme('tripal_organism_maps', $node);
  1234. break;
  1235. default :
  1236. }
  1237. return $block;
  1238. }
  1239. }
  1240. }
  1241. /**
  1242. * Remove orphaned drupal nodes
  1243. *
  1244. * @param $dummy
  1245. * Not Used -kept for backwards compatibility
  1246. * @param $job_id
  1247. * The id of the tripal job executing this function
  1248. *
  1249. * @ingroup tripal_featuremap
  1250. */
  1251. function tripal_featuremap_cleanup($dummy = NULL, $job_id = NULL) {
  1252. return tripal_core_clean_orphaned_nodes('map', $job_id);
  1253. }
  1254. /************************************************************************
  1255. */
  1256. function theme_tripal_featuremap_search_result($node) {
  1257. }