|
@@ -0,0 +1,1393 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+/**
|
|
|
+ * @defgroup tripal_featuremap Map
|
|
|
+ * @{
|
|
|
+ * Provides functions for managing chado maps including creating details pages for each map
|
|
|
+ * @}
|
|
|
+ * @ingroup tripal_modules
|
|
|
+ */
|
|
|
+
|
|
|
+require('api/tripal_featuremap.api.inc');
|
|
|
+
|
|
|
+/**
|
|
|
+ * Display help and module information
|
|
|
+ * @param path which path of the site we're displaying help
|
|
|
+ * @param arg array that holds the current path as would be returned from arg()
|
|
|
+ * function
|
|
|
+ * @return help text for the path
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_help($path, $arg) {
|
|
|
+ $output = '';
|
|
|
+ switch ($path) {
|
|
|
+ case "admin/help#tripal_featuremap":
|
|
|
+ $output = '<p>'.
|
|
|
+ t("Displays links to nodes created on this date") .
|
|
|
+ '</p>';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return $output;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Provide information to drupal about the node types that we're creating
|
|
|
+ * in this module
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_node_info() {
|
|
|
+ $nodes = array();
|
|
|
+ $nodes['chado_featuremap'] = array(
|
|
|
+ 'name' => t('Map'),
|
|
|
+ 'module' => 'chado_featuremap',
|
|
|
+ 'description' => t('A feature map from the chado database (e.g. genetic map)'),
|
|
|
+ 'has_title' => FALSE,
|
|
|
+ 'title_label' => t('Feature Map'),
|
|
|
+ 'has_body' => FALSE,
|
|
|
+ 'body_label' => t('Feature Map Description'),
|
|
|
+ 'locked' => TRUE
|
|
|
+ );
|
|
|
+ return $nodes;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Set the permission types that the chado module uses. Essentially we
|
|
|
+ * want permissionis that protect creation, editing and deleting of chado
|
|
|
+ * data objects
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_perm() {
|
|
|
+ return array(
|
|
|
+ 'access chado_featuremap content',
|
|
|
+ 'create chado_featuremap content',
|
|
|
+ 'delete chado_featuremap content',
|
|
|
+ 'edit chado_featuremap content',
|
|
|
+ );
|
|
|
+}
|
|
|
+/**
|
|
|
+ * Set the permission types that the module uses.
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function chado_featuremap_access($op, $node, $account) {
|
|
|
+ if ($op == 'create') {
|
|
|
+ if (!user_access('create chado_featuremap content', $account)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($op == 'update') {
|
|
|
+ if (!user_access('edit chado_featuremap content', $account)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($op == 'delete') {
|
|
|
+ if (!user_access('delete chado_featuremap content', $account)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($op == 'view') {
|
|
|
+ if (!user_access('access chado_featuremap content', $account)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+/**
|
|
|
+ * Menu items are automatically added for the new node types created
|
|
|
+ * by this module to the 'Create Content' Navigation menu item. This function
|
|
|
+ * adds more menu items needed for this module.
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_menu() {
|
|
|
+ $items = array();
|
|
|
+ // The administative settings menu
|
|
|
+ $items['admin/tripal/tripal_featuremap'] = array(
|
|
|
+ 'title' => 'Maps',
|
|
|
+ 'description' => 'Basic Description of Tripal Map Module Functionality',
|
|
|
+ 'page callback' => 'tripal_featuremap_module_description_page',
|
|
|
+ 'access arguments' => array('access administration pages'),
|
|
|
+ 'type' => MENU_NORMAL_ITEM,
|
|
|
+ );
|
|
|
+
|
|
|
+ $items['admin/tripal/tripal_featuremap/configuration'] = array(
|
|
|
+ 'title' => 'Configuration',
|
|
|
+ 'description' => 'Manage integration of Chado maps including associated features.',
|
|
|
+ 'page callback' => 'drupal_get_form',
|
|
|
+ 'page arguments' => array('tripal_featuremap_admin'),
|
|
|
+ 'access arguments' => array('access administration pages'),
|
|
|
+ 'type' => MENU_NORMAL_ITEM,
|
|
|
+ );
|
|
|
+
|
|
|
+ // Synchronizing maps from Chado to Drupal
|
|
|
+ $items['chado_sync_maps'] = array(
|
|
|
+ 'title' => 'Sync Data',
|
|
|
+ 'page callback' => 'tripal_featuremap_sync_maps',
|
|
|
+ 'access arguments' => array('access administration pages'),
|
|
|
+ 'type' => MENU_CALLBACK
|
|
|
+ );
|
|
|
+
|
|
|
+ // Displaying maps
|
|
|
+ $items['maps'] = array(
|
|
|
+ 'menu_name' => ('primary-links'), //Enable the 'Map' primary link
|
|
|
+ 'title' => 'Feature Maps',
|
|
|
+ 'page callback' => 'tripal_featuremap_show_maps',
|
|
|
+ 'access arguments' => array('access chado_featuremap content'),
|
|
|
+ 'type' => MENU_NORMAL_ITEM
|
|
|
+ );
|
|
|
+
|
|
|
+ return $items;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implements hook_views_api()
|
|
|
+ * Purpose: Essentially this hook tells drupal that there is views support for
|
|
|
+ * for this module which then includes tripal_db.views.inc where all the
|
|
|
+ * views integration code is
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_views_api() {
|
|
|
+ return array(
|
|
|
+ 'api' => 2.0,
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Purpose: Provide Guidance to new Tripal Admin
|
|
|
+ *
|
|
|
+ * @return HTML Formatted text
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_module_description_page() {
|
|
|
+ $text = '';
|
|
|
+ $text .= '<h3>Tripal Feature Map Administrative Tools Quick Links:</h3>';
|
|
|
+ $text .= "<ul>
|
|
|
+ <li><a href=\"" . url("admin/tripal/tripal_featuremap/configuration") . "\">Map Configuration</a></li>
|
|
|
+ </ul>";
|
|
|
+ $text .= '<h3>Module Description:</h3>';
|
|
|
+ $text .= '<p>The Tripal Map module is an interface for the Chado Map module which groups features (sequences) into genetic maps.
|
|
|
+ This module provides support for visualization of "map" pages, editing and updating.</p>';
|
|
|
+
|
|
|
+ $text .= '<h3>Setup Instructions:</h3>';
|
|
|
+ $text .= '<ol>';
|
|
|
+ $text .= '<li><p><b>Set Permissions</b>: The map module supports the Drupal user permissions interface for
|
|
|
+ controlling access to map content and functions. These permissions include viewing,
|
|
|
+ creating, editing or administering of
|
|
|
+ map content. The default is that only the original site administrator has these
|
|
|
+ permissions. You can <a href="' . url('admin/user/roles') . '">add roles</a> for classifying users,
|
|
|
+ <a href="' . url('admin/user/user') . '">assign users to roles</a> and
|
|
|
+ <a href="' . url('admin/user/permissions') . '">assign permissions</a> for the map content to
|
|
|
+ those roles. For a simple setup, allow anonymous users access to view organism content and
|
|
|
+ allow the site administrator all other permissions.</p></li>';
|
|
|
+ $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
|
|
|
+ a Sync Maps section which provides list of maps currently in chado which can be sync\'d.
|
|
|
+ Simply select the maps you would like to create Drupal/Tripal pages for and click Sync Maps.</p></li>';
|
|
|
+ $text .= '</ol>';
|
|
|
+
|
|
|
+
|
|
|
+ $text .= '<h3>Features of this Module:</h3>';
|
|
|
+ $text .= '<ul>';
|
|
|
+ $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
|
|
|
+ recommended to create the map using the feature loader. For example, when you load FASTA files using the Tripal loader you are
|
|
|
+ given the option of specifying a map for all created features. Existing Maps (regardless of the method used to create them) can be
|
|
|
+ edited or deleted by clicking the Edit tab at the top of the Map Page.</li>';
|
|
|
+ $text .= '<li><p><b>Integration with Drupal Views</b>: <a href="http://drupal.org/project/views">Drupal Views</a> is
|
|
|
+ a powerful tool that allows the site administrator to create lists or basic searching forms of Chado content.
|
|
|
+ It provides a graphical interface within Drupal to allow the site admin to directly query the Chado database
|
|
|
+ and create custom lists without PHP programming or customization of Tripal source code. Views can also
|
|
|
+ be created to filter content that has not yet been synced with Druapl in order to protect access to non
|
|
|
+ published data (only works if Chado was installed using Tripal). You can see a list of available pre-existing
|
|
|
+ Views <a href="' . url('admin/build/views/') . '">here</a>, as well as create your own. </p></li>';
|
|
|
+ $text .= '<li><b>Basic Listing</b>: This module provides a basic <a href="' . url('maps') . '">map display
|
|
|
+ tool</a> for finding or listing maps in Chado. It does not require indexing for Drupal searching but relies
|
|
|
+ on Drupal Views. <a href="http://drupal.org/project/views">Drupal Views</a> must be installed.</li>';
|
|
|
+ $text .= '</ul>';
|
|
|
+
|
|
|
+ $text .= '<h3>Page Customizations</h3>';
|
|
|
+ $text .= '<p>There are several ways to customize the look-and-feel for the way Chado data is presented through Tripal.
|
|
|
+ Below is a description of several methods. These methods may be used in conjunction with one another to
|
|
|
+ provide fine-grained control.
|
|
|
+ <ul>
|
|
|
+
|
|
|
+ <li><p><b>Integration with Drupal Panels</b>: <a href="http://drupal.org/project/views">Drupal Panels</a>
|
|
|
+ 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,
|
|
|
+ Panels become useful if you prefer a layout that is different from the pre-set layouts. Chado content
|
|
|
+ is provided to Panels in the form of Drupal "blocks" which you can then place anywhere on a page using the
|
|
|
+ Panel\'s GUI.</p></li>
|
|
|
+
|
|
|
+ <li><p><b>Drupal\'s Content Construction Kit (CCK)</b>: the
|
|
|
+ <a href="http://drupal.org/project/cck">Content Construction Kit (CCK) </a> is a powerful way to add non-Chado content
|
|
|
+ to any page without need to edit template files or knowing PHP. You must first download and install CCK.
|
|
|
+ With CCK, the site administartor can create a new field to appear on the page. For example, currently,
|
|
|
+ the Chado publication module is not yet supported by Tripal. Therefore, the site administrator can add a text
|
|
|
+ field to the map pages. This content is not stored in Chado, but will appear on the map page. A field
|
|
|
+ added by CCK will also appear in the form when editing a map to allow users to manually enter the appropriate
|
|
|
+ text. If the default pre-set layout and themeing for Tripal is used, it is better to create the CCK element,
|
|
|
+ indicate that it is not to be shown (using the CCK interface), then manually add the new content type
|
|
|
+ where desired by editing the templates (as described below). If using Panels, the CCK field can be added to the
|
|
|
+ location desired using the Panels interface.</p></li>
|
|
|
+
|
|
|
+ <li><p><b>Drupal Node Templates</b>: The Tripal packages comes with a "theme_tripal" directory that contains the
|
|
|
+ themeing for Chado content. The map module has a template file for map "nodes" (Tripal map pages). This file
|
|
|
+ is named "node-chado_featuremap.tpl.php", and provides javascript, HTML and PHP code for display of the map
|
|
|
+ pages. You can edit this file to control which types of information (or which map "blocks") are displayed for maps. Be sure to
|
|
|
+ copy these template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
|
|
|
+ future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
|
|
|
+ for instructions on how to access variables and other Chado content within the template file.</p></li>
|
|
|
+
|
|
|
+ <li><p><b>Map "Block" Templates</b>: In the "theme_tripal" directory is a subdirectory named "tripal_featuremap".
|
|
|
+ Inside this directory is a set of templates that control distinct types of information for maps. For example,
|
|
|
+ there is a "base" template for displaying of data directly from the Chado map table. These templates are used both by Drupal blocks
|
|
|
+ for use in Drupal Panels (as described above) or for use in the default pre-set layout that the node template
|
|
|
+ provides (also desribed above). You can customize this template as you desire. Be sure to copy the
|
|
|
+ template to your primary theme directory for editing. Do not edit them in the "theme_tripal" directory as
|
|
|
+ future Tripal updates may overwrite your customizations. See the <a href="http://tripal.sourceforge.net/">Tripal website </a>
|
|
|
+ for instructions on how to access variables and other Chado content within the template files.</p></li>
|
|
|
+ </li>
|
|
|
+
|
|
|
+ <li><p><b>Adding Links to the "Resources" Sidebar</b>: If you use the pre-set default Tripal layout for theming, you
|
|
|
+ will see a "Resources" sidebar on each page. The links that appear on the sidebar are automatically generated
|
|
|
+ using Javascript for all of the map "Blocks" that appear on the page. If you want to add additional links
|
|
|
+ (e.g. a link to a views table showing all features of the current map) and you want that link to appear in the
|
|
|
+ "Resources" sidebar, simply edit the Drupal Node Template (as described above) and add the link to the
|
|
|
+ section at the bottom of the template file where the resources section is found.</p></li>
|
|
|
+
|
|
|
+ </ul>
|
|
|
+ </p>';
|
|
|
+
|
|
|
+ return $text;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Administrative settings form
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_admin() {
|
|
|
+ $form = array();
|
|
|
+
|
|
|
+ // before proceeding check to see if we have any
|
|
|
+ // currently processing jobs. If so, we don't want
|
|
|
+ // to give the opportunity to sync maps
|
|
|
+ $active_jobs = FALSE;
|
|
|
+ if (tripal_get_module_active_jobs('tripal_featuremap')) {
|
|
|
+ $active_jobs = TRUE;
|
|
|
+ }
|
|
|
+
|
|
|
+ // add the field set for syncing maps
|
|
|
+ if (!$active_jobs) {
|
|
|
+ get_tripal_featuremap_admin_form_sync_set($form);
|
|
|
+ get_tripal_featuremap_admin_form_cleanup_set($form);
|
|
|
+ get_tripal_featuremap_admin_form_reindex_set($form);
|
|
|
+ get_tripal_featuremap_admin_form_taxonomy_set($form);
|
|
|
+ get_tripal_featuremap_admin_form_cleanup_set($form);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $form['notice'] = array(
|
|
|
+ '#type' => 'fieldset',
|
|
|
+ '#title' => t('Feature Map Management Temporarily Unavailable')
|
|
|
+ );
|
|
|
+ $form['notice']['message'] = array(
|
|
|
+ '#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.'),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ return system_settings_form($form);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Implementation of hook_nodeapi().
|
|
|
+ * Display map information for associated features or organisms
|
|
|
+ * This function also provides contents for indexing
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_nodeapi(&$node, $op, $teaser, $page) {
|
|
|
+
|
|
|
+ switch ($op) {
|
|
|
+ // Note that this function only adds map view to an organism/feature
|
|
|
+ // node.
|
|
|
+ case 'view':
|
|
|
+ // add the map to the organism/feature search indexing
|
|
|
+ if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
|
|
|
+ $node->content['tripal_featuremap_index_version'] = array(
|
|
|
+ '#value' => theme('tripal_featuremap_search_index', $node),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
|
|
|
+ $node->content['tripal_featuremap_index_version'] = array(
|
|
|
+ '#value' => theme('tripal_featuremap_search_result', $node),
|
|
|
+ );
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ switch ($node->type) {
|
|
|
+ case 'chado_organism':
|
|
|
+ // Show map if the organism/feature is not at teaser view
|
|
|
+ $node->content['tripal_organism_maps'] = array(
|
|
|
+ '#value' => theme('tripal_organism_maps', $node),
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ case 'chado_feature':
|
|
|
+ // Show map if the organism/feature is not at teaser view
|
|
|
+ $node->content['tripal_feature_maps'] = array(
|
|
|
+ '#value' => theme('tripal_feature_maps', $node),
|
|
|
+ );
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * We need to let drupal know about our theme functions and their arguments.
|
|
|
+ * We create theme functions to allow users of the module to customize the
|
|
|
+ * look and feel of the output generated in this module
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_theme() {
|
|
|
+ return array(
|
|
|
+ 'tripal_featuremap_search_index' => array(
|
|
|
+ 'arguments' => array('node'),
|
|
|
+ ),
|
|
|
+ 'tripal_featuremap_search_result' => array(
|
|
|
+ 'arguments' => array('node'),
|
|
|
+ ),
|
|
|
+
|
|
|
+ 'tripal_organism_maps' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
+ 'template' => 'tripal_organism_maps',
|
|
|
+ ),
|
|
|
+ 'tripal_feature_maps' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
+ 'template' => 'tripal_feature_maps',
|
|
|
+ ),
|
|
|
+
|
|
|
+ 'tripal_featuremap_base' => array(
|
|
|
+ 'arguments' => array('node' => NULL),
|
|
|
+ 'template' => 'tripal_featuremap_base',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * This function is an extension of the chado_feature_view and
|
|
|
+ * chado_organism_view by providing the markup for the map object
|
|
|
+ * THAT WILL BE INDEXED.
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function theme_tripal_featuremap_search_index($node) {
|
|
|
+
|
|
|
+ if ($node->type == 'chado_organism') {
|
|
|
+ $content = "";
|
|
|
+
|
|
|
+ }
|
|
|
+ elseif ($node->type == 'chado_feature') {
|
|
|
+ $content = "";
|
|
|
+
|
|
|
+ }
|
|
|
+ return $content;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function get_tripal_featuremap_admin_form_cleanup_set(&$form) {
|
|
|
+ $form['cleanup'] = array(
|
|
|
+ '#type' => 'fieldset',
|
|
|
+ '#title' => t('Clean Up')
|
|
|
+ );
|
|
|
+ $form['cleanup']['description'] = array(
|
|
|
+ '#type' => 'item',
|
|
|
+ '#value' => t("With Drupal and chado residing in different databases ".
|
|
|
+ "it is possible that nodes in Drupal and maps in Chado become ".
|
|
|
+ "\"orphaned\". This can occur if an map node in Drupal is ".
|
|
|
+ "deleted but the corresponding chado map is not and/or vice ".
|
|
|
+ "versa. Click the button below to resolve these discrepancies."),
|
|
|
+ '#weight' => 1,
|
|
|
+ );
|
|
|
+ $form['cleanup']['button'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => t('Clean up orphaned maps'),
|
|
|
+ '#weight' => 2,
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function get_tripal_featuremap_admin_form_taxonomy_set(&$form) {
|
|
|
+ $form['taxonify'] = array(
|
|
|
+ '#type' => 'fieldset',
|
|
|
+ '#title' => t('Assign Drupal Taxonomy to Map Features')
|
|
|
+ );
|
|
|
+
|
|
|
+ // get the list of maps
|
|
|
+ $sql = "SELECT * FROM {featuremap} ORDER BY uniquename";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $lib_rset = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+
|
|
|
+ // iterate through all of the maps
|
|
|
+ $lib_boxes = array();
|
|
|
+ while ($map = db_fetch_object($lib_rset)) {
|
|
|
+ $lib_boxes[$map->map_id] = "$map->name";
|
|
|
+ }
|
|
|
+
|
|
|
+ $form['taxonify']['description'] = array(
|
|
|
+ '#type' => 'item',
|
|
|
+ '#value' => t("Drupal allows for assignment of \"taxonomy\" or catagorical terms to " .
|
|
|
+ "nodes. These terms allow for advanced filtering during searching. This option allows ".
|
|
|
+ "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."),
|
|
|
+ '#weight' => 1,
|
|
|
+ );
|
|
|
+
|
|
|
+ $form['taxonify']['tx-maps'] = array(
|
|
|
+ '#title' => t('Maps'),
|
|
|
+ '#type' => t('checkboxes'),
|
|
|
+ '#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."),
|
|
|
+ '#required' => FALSE,
|
|
|
+ '#prefix' => '<div id="lib_boxes">',
|
|
|
+ '#suffix' => '</div>',
|
|
|
+ '#options' => $lib_boxes,
|
|
|
+ '#weight' => 2
|
|
|
+ );
|
|
|
+ $form['taxonify']['tx-button'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => t('Set Feature Taxonomy'),
|
|
|
+ '#weight' => 3
|
|
|
+ );
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function get_tripal_featuremap_admin_form_reindex_set(&$form) {
|
|
|
+ // define the fieldsets
|
|
|
+ $form['reindex'] = array(
|
|
|
+ '#type' => 'fieldset',
|
|
|
+ '#title' => t('Reindex Map Features')
|
|
|
+ );
|
|
|
+
|
|
|
+ // get the list of maps
|
|
|
+ $sql = "SELECT * FROM {featuremap} ORDER BY uniquename";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $lib_rset = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+
|
|
|
+ // iterate through all of the maps
|
|
|
+ $lib_boxes = array();
|
|
|
+ while ($map = db_fetch_object($lib_rset)) {
|
|
|
+ $lib_boxes[$map->map_id] = "$map->name";
|
|
|
+ }
|
|
|
+ $form['reindex']['description'] = array(
|
|
|
+ '#type' => 'item',
|
|
|
+ '#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."),
|
|
|
+ '#weight' => 1,
|
|
|
+ );
|
|
|
+
|
|
|
+ $form['reindex']['re-maps'] = array(
|
|
|
+ '#title' => t('Maps'),
|
|
|
+ '#type' => t('checkboxes'),
|
|
|
+ '#description' => t("Check the maps whoee features you want to reindex. Note: this list contains all maps, even those that may not be synced."),
|
|
|
+ '#required' => FALSE,
|
|
|
+ '#prefix' => '<div id="lib_boxes">',
|
|
|
+ '#suffix' => '</div>',
|
|
|
+ '#options' => $lib_boxes,
|
|
|
+ '#weight' => 2,
|
|
|
+ );
|
|
|
+ $form['reindex']['re-button'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => t('Reindex Features'),
|
|
|
+ '#weight' => 3,
|
|
|
+ );
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function get_tripal_featuremap_admin_form_sync_set(&$form) {
|
|
|
+ // define the fieldsets
|
|
|
+ $form['sync'] = array(
|
|
|
+ '#type' => 'fieldset',
|
|
|
+ '#title' => t('Sync Maps')
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ // get the list of maps
|
|
|
+ $sql = "SELECT * FROM {featuremap} ORDER BY uniquename";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $lib_rset = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+
|
|
|
+ // if we've added any maps to the list that can be synced
|
|
|
+ // then we want to build the form components to allow the user
|
|
|
+ // to select one or all of them. Otherwise, just present
|
|
|
+ // a message stating that all maps are currently synced.
|
|
|
+ $lib_boxes = array();
|
|
|
+ $added = 0;
|
|
|
+ while ($map = db_fetch_object($lib_rset)) {
|
|
|
+ // check to see if the map is already present as a node in drupal.
|
|
|
+ // if so, then skip it.
|
|
|
+ $sql = "SELECT * FROM {chado_featuremap} WHERE map_id = %d";
|
|
|
+ if (!db_fetch_object(db_query($sql, $map->map_id))) {
|
|
|
+ $lib_boxes[$map->map_id] = "$map->name";
|
|
|
+ $added++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // if we have maps we need to add to the checkbox then
|
|
|
+ // build that form element
|
|
|
+ if ($added > 0) {
|
|
|
+ $lib_boxes['all'] = "All Maps";
|
|
|
+
|
|
|
+ $form['reindex']['description'] = array(
|
|
|
+ '#type' => 'item',
|
|
|
+ '#value' => t("This option allows for the creation of Drupal content for maps in chado. Only the selected maps will be synced."),
|
|
|
+ '#weight' => 1,
|
|
|
+ );
|
|
|
+
|
|
|
+
|
|
|
+ $form['sync']['maps'] = array(
|
|
|
+ '#title' => t('Available Maps'),
|
|
|
+ '#type' => t('checkboxes'),
|
|
|
+ '#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."),
|
|
|
+ '#required' => FALSE,
|
|
|
+ '#prefix' => '<div id="lib_boxes">',
|
|
|
+ '#suffix' => '</div>',
|
|
|
+ '#options' => $lib_boxes,
|
|
|
+ '#weight' => 2,
|
|
|
+ );
|
|
|
+ $form['sync']['button'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => t('Sync Maps'),
|
|
|
+ '#weight' => 3,
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // we don't have any maps to select from
|
|
|
+ else {
|
|
|
+ $form['sync']['value'] = array(
|
|
|
+ '#value' => t('All maps in Chado are currently synced with Drupal.')
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_admin_validate($form, &$form_state) {
|
|
|
+ global $user; // we need access to the user info
|
|
|
+ $job_args = array();
|
|
|
+
|
|
|
+ // Submit the Sync Job if selected
|
|
|
+ if ($form_state['values']['op'] == t('Sync Maps')) {
|
|
|
+
|
|
|
+ // check to see if the user wants to sync chado and drupal. If
|
|
|
+ // so then we need to register a job to do so with tripal
|
|
|
+ $maps = $form_state['values']['maps'];
|
|
|
+ $do_all = FALSE;
|
|
|
+ $to_sync = array();
|
|
|
+
|
|
|
+ foreach ($maps as $map_id) {
|
|
|
+ if (preg_match("/^all$/i", $map_id)) {
|
|
|
+ $do_all = TRUE;
|
|
|
+ }
|
|
|
+ if ($map_id and preg_match("/^\d+$/i", $map_id)) {
|
|
|
+ // get the map info
|
|
|
+ $sql = "SELECT * FROM {Map} WHERE map_id = %d";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $map = db_fetch_object(db_query($sql, $map_id));
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ $to_sync[$map_id] = $map->name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // submit the job to the tripal job manager
|
|
|
+ if ($do_all) {
|
|
|
+ tripal_add_job('Sync all maps', 'tripal_featuremap', 'tripal_featuremap_sync_maps', $job_args, $user->uid);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ foreach ($to_sync as $map_id => $name) {
|
|
|
+ $job_args[0] = $map_id;
|
|
|
+ tripal_add_job("Sync map: $name", 'tripal_featuremap', 'tripal_featuremap_sync_maps', $job_args, $user->uid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // -------------------------------------
|
|
|
+ // Submit the Reindex Job if selected
|
|
|
+ if ($form_state['values']['op'] == t('Reindex Features')) {
|
|
|
+ $maps = $form_state['values']['re-maps'];
|
|
|
+ foreach ($maps as $map_id) {
|
|
|
+ if ($map_id and preg_match("/^\d+$/i", $map_id)) {
|
|
|
+ // get the map info
|
|
|
+ $sql = "SELECT * FROM {Map} WHERE map_id = %d";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $map = db_fetch_object(db_query($sql, $map_id));
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ $job_args[0] = $map_id;
|
|
|
+ tripal_add_job("Reindex features for map: $map->name", 'tripal_featuremap',
|
|
|
+ 'tripal_featuremap_reindex_features', $job_args, $user->uid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // -------------------------------------
|
|
|
+ // Submit the Taxonomy Job if selected
|
|
|
+ if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
|
|
|
+ $maps = $form_state['values']['tx-maps'];
|
|
|
+ foreach ($maps as $map_id) {
|
|
|
+ if ($map_id and preg_match("/^\d+$/i", $map_id)) {
|
|
|
+ // get the map info
|
|
|
+ $sql = "SELECT * FROM {Map} WHERE map_id = %d";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $map = db_fetch_object(db_query($sql, $map_id));
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ $job_args[0] = $map_id;
|
|
|
+ tripal_add_job("Set taxonomy for features in map: $map->name", 'tripal_featuremap',
|
|
|
+ 'tripal_featuremap_taxonify_features', $job_args, $user->uid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // -------------------------------------
|
|
|
+ // Submit the Cleanup Job if selected
|
|
|
+ if ($form_state['values']['op'] == t('Clean up orphaned maps')) {
|
|
|
+ tripal_add_job('Cleanup orphaned maps', 'tripal_featuremap',
|
|
|
+ 'tripal_featuremap_cleanup', $job_args, $user->uid);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_cron() {
|
|
|
+
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * CHADO_LIBRARY NODE FUNCTIONS
|
|
|
+ *
|
|
|
+ * The following function proves access control for users trying to
|
|
|
+ * perform actions on data managed by this module
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_map_access($op, $node, $account) {
|
|
|
+ if ($op == 'create') {
|
|
|
+ if (!user_access('create chado_featuremap content', $account)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($op == 'update') {
|
|
|
+ if (!user_access('edit any chado_featuremap content', $account) &&
|
|
|
+ !user_access('edit own chado_featuremap content', $account)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ if (user_access('edit own chado_featuremap content', $account) &&
|
|
|
+ $account->uid != $node->uid) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($op == 'delete') {
|
|
|
+ if (!user_access('delete any chado_featuremap content', $account) &&
|
|
|
+ !user_access('delete own chado_featuremap content', $account)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ if (user_access('delete own chado_featuremap content', $account) &&
|
|
|
+ $account->uid != $node->uid) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+/**
|
|
|
+ * validates submission of form when adding or updating a map node
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function chado_featuremap_validate($node) {
|
|
|
+ $lib = 0;
|
|
|
+ // check to make sure the unique name on the map is unique
|
|
|
+ // before we try to insert into chado.
|
|
|
+ if ($node->map_id) {
|
|
|
+ $sql = "SELECT * FROM ".
|
|
|
+ "{Map} WHERE ".
|
|
|
+ "uniquename = '%s' ".
|
|
|
+ "AND NOT map_id = %d";
|
|
|
+ $previous_db = tripal_db_set_active('chado');
|
|
|
+ $lib = db_fetch_object(db_query($sql, $node->uniquename,
|
|
|
+ $node->map_id));
|
|
|
+ tripal_db_set_active($previous_db);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $sql = "SELECT * FROM ".
|
|
|
+ "{Map} ".
|
|
|
+ "WHERE uniquename = '%s'";
|
|
|
+ $previous_db = tripal_db_set_active('chado');
|
|
|
+ $lib = db_fetch_object(db_query($sql, $node->uniquename));
|
|
|
+ tripal_db_set_active($previous_db);
|
|
|
+ }
|
|
|
+ if ($lib) {
|
|
|
+ form_set_error('uniquename', t('The unique map name already exists. '.
|
|
|
+ 'Please choose another'));
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * When a new chado_featuremap node is created we also need to add information
|
|
|
+ * to our chado_featuremap table. This function is called on insert of a new node
|
|
|
+ * of type 'chado_featuremap' and inserts the necessary information.
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function chado_featuremap_insert($node) {
|
|
|
+
|
|
|
+ if ($node->map_id) {
|
|
|
+ $map['map_id'] = $node->map_id;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // get the map type id
|
|
|
+ $values = array(
|
|
|
+ 'cv_id' => array(
|
|
|
+ 'name' => 'tripal'
|
|
|
+ ),
|
|
|
+ 'name' => $node->map_type
|
|
|
+ );
|
|
|
+ $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
|
|
|
+
|
|
|
+ $values = array(
|
|
|
+ 'name' => $node->title,
|
|
|
+ 'uniquename' => $node->uniquename,
|
|
|
+ 'organism_id' => $node->organism_id,
|
|
|
+ 'type_id' => $type[0]->cvterm_id
|
|
|
+ );
|
|
|
+ $map = tripal_core_chado_insert('map', $values);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($map) {
|
|
|
+ // add the description property
|
|
|
+ tripal_featuremap_insert_property($map['map_id'], 'map_description', $node->map_description);
|
|
|
+
|
|
|
+ // make sure the entry for this feature doesn't already exist in the chado_featuremap table
|
|
|
+ // if it doesn't exist then we want to add it.
|
|
|
+ $map_id = chado_get_id_for_node('map', $node) ;
|
|
|
+ if (!$map_id) {
|
|
|
+ // next add the item to the drupal table
|
|
|
+ $sql = "INSERT INTO {chado_featuremap} (nid, vid, map_id) ".
|
|
|
+ "VALUES (%d, %d, %d)";
|
|
|
+ db_query($sql, $node->nid, $node->vid, $map['map_id']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ drupal_set_message(t('Unable to add map.', 'warning'));
|
|
|
+ watchdog('tripal_featuremap',
|
|
|
+ 'Insert feature: Unable to create map where values: %values',
|
|
|
+ array('%values' => print_r($values, TRUE)),
|
|
|
+ WATCHDOG_WARNING
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ * Update nodes
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function chado_featuremap_update($node) {
|
|
|
+ if ($node->revision) {
|
|
|
+ // TODO -- decide what to do about revisions
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $map_id = chado_get_id_for_node('map', $node) ;
|
|
|
+
|
|
|
+ // get the map type id
|
|
|
+ $values = array(
|
|
|
+ 'cv_id' => array(
|
|
|
+ 'name' => 'tripal'
|
|
|
+ ),
|
|
|
+ 'name' => $node->map_type
|
|
|
+ );
|
|
|
+ $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
|
|
|
+
|
|
|
+ // update the map record
|
|
|
+ $match = array(
|
|
|
+ 'map_id' => $map_id,
|
|
|
+ );
|
|
|
+ $values = array(
|
|
|
+ 'name' => $node->title,
|
|
|
+ 'uniquename' => $node->uniquename,
|
|
|
+ 'organism_id' => $node->organism_id,
|
|
|
+ 'type_id' => $type[0]->cvterm_id
|
|
|
+ );
|
|
|
+ $status = tripal_core_chado_update('map', $match, $values);
|
|
|
+
|
|
|
+ tripal_featuremap_update_property($map_id, 'map_description', $node->map_description);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * Add the map as a taxonomy term for associating with map_features
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_add_taxonomy($node, $map_id) {
|
|
|
+
|
|
|
+ //include the file containing the required functions. We only have to
|
|
|
+ // do this because Drupal 6 fails to do this globally for us and
|
|
|
+ // the drupal_execute function below won't work
|
|
|
+ module_load_include('inc', 'taxonomy', 'taxonomy.admin');
|
|
|
+
|
|
|
+ /* // get the vocabulary id
|
|
|
+ $vocabularies = taxonomy_get_vocabularies();
|
|
|
+ $vid = NULL;
|
|
|
+ foreach($vocabularies as $vocab){
|
|
|
+ if($vocab->name == 'DNA Maps'){
|
|
|
+ $vid = $vocab->vid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!$vid){ */
|
|
|
+ // add the vocabulary
|
|
|
+ $vocab_form['values']['name'] = 'DNA Maps';
|
|
|
+ $vocab_form['values']['description'] = 'Allows for associating/searching of map features by map name';
|
|
|
+ $vocab_form['values']['help'] = '';
|
|
|
+ $vocab_form['values']['module'] = 'taxonomy';
|
|
|
+ drupal_execute('taxonomy_form_vocabulary', $vocab_form);
|
|
|
+ return;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // make sure this term doesn't already exist. If it doesn't then add it
|
|
|
+ if ($vid) {
|
|
|
+ $tree = taxonomy_get_tree($vid);
|
|
|
+ $found = 0;
|
|
|
+ foreach ($tree as $term) {
|
|
|
+ if ($term->name == $node->title) {
|
|
|
+ $found = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // add the term to the vocabulary
|
|
|
+ if (!$found) {
|
|
|
+ $form_state = array();
|
|
|
+ $form_state['values']['name'] = $node->title;
|
|
|
+ $form_state['values']['description'] = $map_id;
|
|
|
+ drupal_execute('taxonomy_form_term', $form_state, $vid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * When editing or creating a new node of type 'chado_featuremap' we need
|
|
|
+ * a form. This function creates the form that will be used for this.
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function chado_featuremap_form($node) {
|
|
|
+ $form = array();
|
|
|
+
|
|
|
+ $map = $node->map;
|
|
|
+
|
|
|
+ // get the default values
|
|
|
+ $uniquename = $node->uniquename;
|
|
|
+ if (!$uniquename) {
|
|
|
+ $uniquename = $map->uniquename;
|
|
|
+ }
|
|
|
+ $map_type = $node->map_type;
|
|
|
+ if (!$map_type) {
|
|
|
+ $map_type = $map->type_id->name;
|
|
|
+ }
|
|
|
+ $organism_id = $node->organism_id;
|
|
|
+ if (!$organism_id) {
|
|
|
+ $organism_id = $map->organism_id->organism_id;
|
|
|
+ }
|
|
|
+ $map_description = $node->map_description;
|
|
|
+ if (!$map_description) {
|
|
|
+ $libprop = tripal_featuremap_get_property($map->map_id, 'map_description');
|
|
|
+ $map_description = $libprop->value;
|
|
|
+ }
|
|
|
+
|
|
|
+ // keep track of the map id if we have. If we do have one then
|
|
|
+ // this is an update as opposed to an insert.
|
|
|
+ $form['map_id'] = array(
|
|
|
+ '#type' => 'value',
|
|
|
+ '#value' => $map->map_id,
|
|
|
+ );
|
|
|
+
|
|
|
+ $form['title']= array(
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#title' => t('Map Title'),
|
|
|
+ '#description' => t('Please enter the title for this map. '.
|
|
|
+ 'This appears at the top of the map page.'),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $node->title,
|
|
|
+ '#weight' => 1
|
|
|
+ );
|
|
|
+
|
|
|
+ $form['uniquename']= array(
|
|
|
+ '#type' => 'textfield',
|
|
|
+ '#title' => t('Unique Map Name'),
|
|
|
+ '#description' => t('Please enter a unique name for this map'),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $uniquename,
|
|
|
+ '#weight' => 2
|
|
|
+ );
|
|
|
+
|
|
|
+ // These map types should not be hard coded, but for now the are...
|
|
|
+ $map_types = array();
|
|
|
+ $map_types[''] = '';
|
|
|
+ $map_types['cdna_map'] = 'cDNA Map';
|
|
|
+ $map_types['bac_map'] = 'BAC Map';
|
|
|
+ $map_types['fosmid_map'] = 'FOSMID Map';
|
|
|
+ $map_types['cosmid_map'] = 'COSMID Map';
|
|
|
+ $map_types['yac_map'] = 'YAC Map';
|
|
|
+
|
|
|
+
|
|
|
+ $form['map_type'] = array(
|
|
|
+ '#title' => t('Map Type'),
|
|
|
+ '#type' => t('select'),
|
|
|
+ '#description' => t("Choose the map type."),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $map_type,
|
|
|
+ '#options' => $map_types,
|
|
|
+ '#weight' => 3
|
|
|
+ );
|
|
|
+
|
|
|
+ // get the list of organisms
|
|
|
+ $sql = "SELECT * FROM {Organism}";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $org_rset = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+
|
|
|
+ $organisms = array();
|
|
|
+ $organisms[''] = '';
|
|
|
+ while ($organism = db_fetch_object($org_rset)) {
|
|
|
+ $organisms[$organism->organism_id] =
|
|
|
+ "$organism->genus $organism->species ($organism->common_name)";
|
|
|
+ }
|
|
|
+
|
|
|
+ $form['organism_id'] = array(
|
|
|
+ '#title' => t('Organism'),
|
|
|
+ '#type' => t('select'),
|
|
|
+ '#description' => t("Choose the organism with which this map is ".
|
|
|
+ "associated."),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $organism_id,
|
|
|
+ '#options' => $organisms,
|
|
|
+ '#weight' => 4,
|
|
|
+ );
|
|
|
+
|
|
|
+ $form['map_description']= array(
|
|
|
+ '#type' => 'textarea',
|
|
|
+ '#title' => t('Map Description'),
|
|
|
+ '#description' => t('A brief description of the map'),
|
|
|
+ '#required' => TRUE,
|
|
|
+ '#default_value' => $map_description,
|
|
|
+ '#weight' => 5
|
|
|
+ );
|
|
|
+
|
|
|
+ return $form;
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_sync_maps($map_id = NULL, $job_id = NULL) {
|
|
|
+
|
|
|
+ global $user;
|
|
|
+ $page_content = '';
|
|
|
+
|
|
|
+ // get the list of maps and create new nodes
|
|
|
+ if (!$map_id) {
|
|
|
+ $sql = "SELECT * FROM {Map} L";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $results = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $sql = "SELECT * FROM {Map} L WHERE map_id = %d";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $results = db_query($sql, $map_id);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ }
|
|
|
+
|
|
|
+ // We'll use the following SQL statement for checking if the map
|
|
|
+ // already exists as a drupal node.
|
|
|
+ $sql = "SELECT * FROM {chado_featuremap} ".
|
|
|
+ "WHERE map_id = %d";
|
|
|
+
|
|
|
+ while ($map = db_fetch_object($results)) {
|
|
|
+
|
|
|
+ // check if this map already exists in the drupal database. if it
|
|
|
+ // does then skip this map and go to the next one.
|
|
|
+ if (!db_fetch_object(db_query($sql, $map->map_id))) {
|
|
|
+
|
|
|
+ $new_node = new stdClass();
|
|
|
+ $new_node->type = 'chado_featuremap';
|
|
|
+ $new_node->uid = $user->uid;
|
|
|
+ $new_node->title = "$map->name";
|
|
|
+ $new_node->map_id = $map->map_id;
|
|
|
+ $new_node->organism_id = $map->organism_id;
|
|
|
+ $new_node->uniquename = $map->uniquename;
|
|
|
+ $new_node->type_id = $map->type_id;
|
|
|
+
|
|
|
+ node_validate($new_node);
|
|
|
+ $errors = form_get_errors();
|
|
|
+ if (!$errors) {
|
|
|
+ $node = node_submit($new_node);
|
|
|
+ node_save($node);
|
|
|
+ if ($node->nid) {
|
|
|
+ print "Added " . $map->name . "\n";
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ print "ERROR: Unable to create " . $map->name . "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ print "ERROR: Unable to create " . $map->name . "\n" . print_r($errors, TRUE) . "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ print "Skipped " . $map->name . "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $page_content;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * When a node is requested by the user this function is called to allow us
|
|
|
+ * to add auxiliary data to the node object.
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function chado_featuremap_load($node) {
|
|
|
+ // get the feature details from chado
|
|
|
+ $map_id = chado_get_id_for_node('map', $node);
|
|
|
+
|
|
|
+ $values = array('map_id' => $map_id);
|
|
|
+ $map = tripal_core_generate_chado_var('map', $values);
|
|
|
+
|
|
|
+ $additions = new stdClass();
|
|
|
+ $additions->map = $map;
|
|
|
+ return $additions;
|
|
|
+
|
|
|
+}
|
|
|
+/**
|
|
|
+ * This function customizes the view of the chado_featuremap node. It allows
|
|
|
+ * us to generate the markup. This function is required for node [Preview]
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function chado_featuremap_view($node, $teaser = FALSE, $page = FALSE) {
|
|
|
+ // use drupal's default node view:
|
|
|
+ if (!$teaser) {
|
|
|
+
|
|
|
+ $node = node_prepare($node, $teaser);
|
|
|
+ }
|
|
|
+ return $node;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_feature_set_taxonomy($map_id = NULL) {
|
|
|
+
|
|
|
+ //TO DO : return usable error if vocabs don't exist
|
|
|
+ // get the list of vocabularies and find our two vocabularies of interest
|
|
|
+ $vocabularies = taxonomy_get_vocabularies();
|
|
|
+ $vid = NULL;
|
|
|
+ foreach ($vocabularies as $vocab) {
|
|
|
+ if ($vocab->name == 'Map') {
|
|
|
+ $vid = $vocab->vid;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!$vid) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // We'll use the following SQL statement for getting the node info
|
|
|
+ if ($map_id) {
|
|
|
+ print "Finding features for map with ID: $map_id\n";
|
|
|
+ $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
|
|
|
+ "FROM {map_feature} LF ".
|
|
|
+ "INNER JOIN Map L ON LF.map_id = L.map_id ".
|
|
|
+ "WHERE L.map_id = $map_id ".
|
|
|
+ "ORDER BY LF.feature_id";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $features = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ print "Finding features for all maps\n";
|
|
|
+ $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
|
|
|
+ "FROM {map_feature} LF ".
|
|
|
+ "INNER JOIN Map L ON LF.map_id = L.map_id ".
|
|
|
+ "ORDER BY LF.feature_id";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $features = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ }
|
|
|
+
|
|
|
+ $node_sql = "SELECT * FROM {chado_feature} CF ".
|
|
|
+ " INNER JOIN {node} N ON CF.nid = N.nid ".
|
|
|
+ "WHERE feature_id = %d";
|
|
|
+
|
|
|
+ // iterate through the features and add the taxonomy
|
|
|
+ while ($feature = db_fetch_object($features)) {
|
|
|
+ $node = db_fetch_object(db_query($node_sql, $feature->feature_id));
|
|
|
+ $tags["$vid"] = $feature->libname;
|
|
|
+ $terms['tags'] = $tags;
|
|
|
+ taxonomy_node_save($node, $terms);
|
|
|
+ print "Updated $feature->feature_id as $feature->libname\n";
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_reindex_features($map_id = NULL, $job_id = NULL) {
|
|
|
+ $i = 0;
|
|
|
+
|
|
|
+ // if the caller provided a map_id then get all of the features
|
|
|
+ // associated with the map. Otherwise get all sequences assoicated
|
|
|
+ // with all maps.
|
|
|
+ if ($map_id) {
|
|
|
+ $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
|
|
|
+ " FROM {map_feature} LF ".
|
|
|
+ " INNER JOIN Map L ON LF.map_id = L.map_id ".
|
|
|
+ "WHERE L.map_id = $map_id ".
|
|
|
+ "ORDER BY LF.feature_id";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $results = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
|
|
|
+ " FROM {map_feature} LF ".
|
|
|
+ " INNER JOIN Map L ON LF.map_id = L.map_id ".
|
|
|
+ "ORDER BY LF.feature_id";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $results = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ }
|
|
|
+
|
|
|
+ // load into ids array
|
|
|
+ $count = 0;
|
|
|
+ $ids = array();
|
|
|
+ while ($id = db_fetch_object($results)) {
|
|
|
+ $ids[$count] = $id->feature_id;
|
|
|
+ $count++;
|
|
|
+ }
|
|
|
+
|
|
|
+ $interval = intval($count * 0.01);
|
|
|
+ foreach ($ids as $feature_id) {
|
|
|
+ // update the job status every 1% features
|
|
|
+ if ($job_id and $i % interval == 0) {
|
|
|
+ tripal_job_set_progress($job_id, intval(($i/$count)*100));
|
|
|
+ }
|
|
|
+ tripal_feature_sync_feature($feature_id);
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_taxonify_features($map_id = NULL, $job_id = NULL) {
|
|
|
+ $i = 0;
|
|
|
+
|
|
|
+ // if the caller provided a map_id then get all of the features
|
|
|
+ // associated with the map. Otherwise get all sequences assoicated
|
|
|
+ // with all maps.
|
|
|
+ if ($map_id) {
|
|
|
+ $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
|
|
|
+ " FROM {map_feature} LF ".
|
|
|
+ " INNER JOIN Map L ON LF.map_id = L.map_id ".
|
|
|
+ "WHERE L.map_id = $map_id ".
|
|
|
+ "ORDER BY LF.feature_id";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $results = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $sql = "SELECT LF.feature_id, L.map_id, L.name as libname ".
|
|
|
+ " FROM {map_feature} LF ".
|
|
|
+ " INNER JOIN Map L ON LF.map_id = L.map_id ".
|
|
|
+ "ORDER BY LF.feature_id";
|
|
|
+ $previous_db = tripal_db_set_active('chado'); // use chado database
|
|
|
+ $results = db_query($sql);
|
|
|
+ tripal_db_set_active($previous_db); // now use drupal database
|
|
|
+ }
|
|
|
+
|
|
|
+ // load into ids array
|
|
|
+ $count = 0;
|
|
|
+ $ids = array();
|
|
|
+ while ($id = db_fetch_object($results)) {
|
|
|
+ $ids[$count] = $id->feature_id;
|
|
|
+ $count++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // make sure our vocabularies are set before proceeding
|
|
|
+ tripal_feature_set_vocabulary();
|
|
|
+
|
|
|
+ // use this SQL for getting the nodes
|
|
|
+ $nsql = "SELECT * FROM {chado_feature} CF ".
|
|
|
+ " INNER JOIN {node} N ON N.nid = CF.nid ".
|
|
|
+ "WHERE feature_id = %d";
|
|
|
+
|
|
|
+ // iterate through the features and set the taxonomy
|
|
|
+ $interval = intval($count * 0.01);
|
|
|
+ foreach ($ids as $feature_id) {
|
|
|
+ // update the job status every 1% features
|
|
|
+ if ($job_id and $i % interval == 0) {
|
|
|
+ tripal_job_set_progress($job_id, intval(($i/$count)*100));
|
|
|
+ }
|
|
|
+ $node = db_fetch_object(db_query($nsql, $feature_id));
|
|
|
+ tripal_feature_set_taxonomy($node, $feature_id);
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+}
|
|
|
+/**
|
|
|
+ * Delete data from drupal and chado databases when a node is deleted
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function chado_featuremap_delete(&$node) {
|
|
|
+
|
|
|
+ $map_id = chado_get_id_for_node('map', $node);
|
|
|
+
|
|
|
+ // if we don't have a map id for this node then this isn't a node of
|
|
|
+ // type chado_featuremap or the entry in the chado_featuremap table was lost.
|
|
|
+ if (!$map_id){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Remove data from {chado_featuremap}, {node} and {node_revisions} tables of
|
|
|
+ // drupal database
|
|
|
+ $sql_del = "DELETE FROM {chado_featuremap} ".
|
|
|
+ "WHERE nid = %d ".
|
|
|
+ "AND vid = %d";
|
|
|
+ db_query($sql_del, $node->nid, $node->vid);
|
|
|
+ $sql_del = "DELETE FROM {node} ".
|
|
|
+ "WHERE nid = %d ".
|
|
|
+ "AND vid = %d";
|
|
|
+ db_query($sql_del, $node->nid, $node->vid);
|
|
|
+ $sql_del = "DELETE FROM {node_revisions} ".
|
|
|
+ "WHERE nid = %d ".
|
|
|
+ "AND vid = %d";
|
|
|
+ db_query($sql_del, $node->nid, $node->vid);
|
|
|
+
|
|
|
+ // Remove data from map and mapprop tables of chado database as well
|
|
|
+ $previous_db = tripal_db_set_active('chado');
|
|
|
+ db_query("DELETE FROM {map} WHERE map_id = %d", $map_id);
|
|
|
+ db_query("DELETE FROM {mapprop} WHERE map_id = %d", $map_id);
|
|
|
+ tripal_db_set_active($previous_db);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Display block with maps
|
|
|
+ * @param op - parameter to define the phase being called for the block
|
|
|
+ * @param delta - id of the block to return (ignored when op is list)
|
|
|
+ * @param edit - when op is save, contains the submitted form data
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_block($op = 'list', $delta = '0', $edit = array()) {
|
|
|
+ switch ($op) {
|
|
|
+ case 'list':
|
|
|
+
|
|
|
+ $blocks['libreferences']['info'] = t('Tripal Map References');
|
|
|
+ $blocks['libreferences']['cache'] = BLOCK_NO_CACHE;
|
|
|
+
|
|
|
+ $blocks['libbase']['info'] = t('Tripal Map Details');
|
|
|
+ $blocks['libbase']['cache'] = BLOCK_NO_CACHE;
|
|
|
+
|
|
|
+ $blocks['libsynonyms']['info'] = t('Tripal Map Synonyms');
|
|
|
+ $blocks['libsynonyms']['cache'] = BLOCK_NO_CACHE;
|
|
|
+
|
|
|
+ $blocks['libproperties']['info'] = t('Tripal Map Properties');
|
|
|
+ $blocks['libproperties']['cache'] = BLOCK_NO_CACHE;
|
|
|
+
|
|
|
+ $blocks['featurelibs']['info'] = t('Tripal Feature Maps');
|
|
|
+ $blocks['featurelibs']['cache'] = BLOCK_NO_CACHE;
|
|
|
+
|
|
|
+ $blocks['orglibs']['info'] = t('Tripal Organism Maps');
|
|
|
+ $blocks['orglibs']['cache'] = BLOCK_NO_CACHE;
|
|
|
+
|
|
|
+ return $blocks;
|
|
|
+
|
|
|
+ case 'view':
|
|
|
+ if (user_access('access chado_featuremap content') and arg(0) == 'node' and is_numeric(arg(1))) {
|
|
|
+ $nid = arg(1);
|
|
|
+ $node = node_load($nid);
|
|
|
+
|
|
|
+ $block = array();
|
|
|
+ switch ($delta) {
|
|
|
+ case 'libreferences':
|
|
|
+ $block['subject'] = t('References');
|
|
|
+ $block['content'] = theme('tripal_featuremap_references', $node);
|
|
|
+ break;
|
|
|
+ case 'libbase':
|
|
|
+ $block['subject'] = t('Map Details');
|
|
|
+ $block['content'] = theme('tripal_featuremap_base', $node);
|
|
|
+ break;
|
|
|
+ case 'libsynonyms':
|
|
|
+ $block['subject'] = t('Synonyms');
|
|
|
+ $block['content'] = theme('tripal_featuremap_synonyms', $node);
|
|
|
+ break;
|
|
|
+ case 'libproperties':
|
|
|
+ $block['subject'] = t('Properties');
|
|
|
+ $block['content'] = theme('tripal_featuremap_properties', $node);
|
|
|
+ break;
|
|
|
+ case 'featurelibs':
|
|
|
+ $block['subject'] = t('Maps');
|
|
|
+ $block['content'] = theme('tripal_feature_maps', $node);
|
|
|
+ break;
|
|
|
+ case 'orglibs':
|
|
|
+ $block['subject'] = t('Maps');
|
|
|
+ $block['content'] = theme('tripal_organism_maps', $node);
|
|
|
+ break;
|
|
|
+ default :
|
|
|
+ }
|
|
|
+ return $block;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Remove orphaned drupal nodes
|
|
|
+ *
|
|
|
+ * @param $dummy
|
|
|
+ * Not Used -kept for backwards compatibility
|
|
|
+ * @param $job_id
|
|
|
+ * The id of the tripal job executing this function
|
|
|
+ *
|
|
|
+ * @ingroup tripal_featuremap
|
|
|
+ */
|
|
|
+function tripal_featuremap_cleanup($dummy = NULL, $job_id = NULL) {
|
|
|
+
|
|
|
+ return tripal_core_clean_orphaned_nodes('map', $job_id);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/************************************************************************
|
|
|
+ */
|
|
|
+function theme_tripal_featuremap_search_result($node) {
|
|
|
+
|
|
|
+}
|
|
|
+
|