123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632 |
- <?php
- /**
- * @defgroup tripal_library Library
- * @{
- * Provides functions for managing chado libraries including creating details pages for each library
- * @}
- * @ingroup tripal_modules
- */
- require('api/tripal_library.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_library
- */
- function tripal_library_help($path, $arg) {
- $output = '';
- switch ($path) {
- case "admin/help#tripal_library":
- $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_library
- */
- function tripal_library_node_info() {
- $nodes = array();
- $nodes['chado_library'] = array(
- 'name' => t('Library'),
- 'module' => 'chado_library',
- 'description' => t('A library from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Library'),
- 'has_body' => FALSE,
- 'body_label' => t('Library 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_library
- */
- function tripal_library_perm() {
- return array(
- 'access chado_library content',
- 'create chado_library content',
- 'delete chado_library content',
- 'edit chado_library content',
- );
- }
- /**
- * Set the permission types that the module uses.
- *
- * @ingroup tripal_library
- */
- function chado_library_access($op, $node, $account) {
- if ($op == 'create') {
- if (!user_access('create chado_library content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'update') {
- if (!user_access('edit chado_library content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete chado_library content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'view') {
- if (!user_access('access chado_library 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_library
- */
- function tripal_library_menu() {
- $items = array();
- // The administative settings menu
- $items['admin/tripal/tripal_library'] = array(
- 'title' => 'Libraries',
- 'description' => 'Basic Description of Tripal Library Module Functionality',
- 'page callback' => 'tripal_library_module_description_page',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- $items['admin/tripal/tripal_library/configuration'] = array(
- 'title' => 'Configuration',
- 'description' => 'Manage integration of Chado libraries including associated features.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_library_admin'),
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_NORMAL_ITEM,
- );
- // Synchronizing libraries from Chado to Drupal
- $items['chado_sync_libraries'] = array(
- 'title' => 'Sync Data',
- 'page callback' => 'tripal_library_sync_libraries',
- 'access arguments' => array('access administration pages'),
- 'type' => MENU_CALLBACK
- );
- // Displaying libraries
- $items['libraries'] = array(
- 'menu_name' => ('primary-links'), //Enable the 'Library' primary link
- 'title' => 'DNA Libraries',
- 'page callback' => 'tripal_library_show_libraries',
- 'access arguments' => array('access chado_library 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_library
- */
- function tripal_library_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
- /**
- * Purpose: Provide Guidance to new Tripal Admin
- *
- * @return HTML Formatted text
- *
- * @ingroup tripal_library
- */
- function tripal_library_module_description_page() {
- $text = '';
- $text .= '<h3>Tripal Library Administrative Tools Quick Links:</h3>';
- $text .= "<ul>
- <li><a href=\"" . url("admin/tripal/tripal_library/configuration") . "\">Library Configuration</a></li>
- </ul>";
- $text .= '<h3>Module Description:</h3>';
- $text .= '<p>The Tripal Library module is an interface for the Chado Library module which groups features (sequences) into genetic libraries.
- This module provides support for visualization of "library" pages, editing and updating.</p>';
- $text .= '<h3>Setup Instructions:</h3>';
- $text .= '<ol>';
- $text .= '<li><p><b>Set Permissions</b>: The library module supports the Drupal user permissions interface for
- controlling access to library content and functions. These permissions include viewing,
- creating, editing or administering of
- library 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 library 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 Libraries</b>: Near the top of the ' . l('Library Configuration page', 'admin/tripal/tripal_library/configuration') . ' there is
- a Sync Libraries section which provides list of libraries currently in chado which can be sync\'d.
- Simply select the libraries you would like to create Drupal/Tripal pages for and click Sync Libraries.</p></li>';
- $text .= '</ol>';
- $text .= '<h3>Features of this Module:</h3>';
- $text .= '<ul>';
- $text .= '<li><b>Add/Edit/Delete Libraries</b>: Libraries with no associated features can be created ' . l('here', 'node/add/chado-library') . ' but it is
- recommended to create the library using the feature loader. For example, when you load FASTA files using the Tripal loader you are
- given the option of specifying a library for all created features. Existing Libraries (regardless of the method used to create them) can be
- edited or deleted by clicking the Edit tab at the top of the Library 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('libraries') . '">library display
- tool</a> for finding or listing libraries 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 library 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 library pages. This content is not stored in Chado, but will appear on the library page. A field
- added by CCK will also appear in the form when editing a library 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 library module has a template file for library "nodes" (Tripal library pages). This file
- is named "node-chado_library.tpl.php", and provides javascript, HTML and PHP code for display of the library
- pages. You can edit this file to control which types of information (or which library "blocks") are displayed for libraries. 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>Library "Block" Templates</b>: In the "theme_tripal" directory is a subdirectory named "tripal_library".
- Inside this directory is a set of templates that control distinct types of information for libraries. For example,
- there is a "base" template for displaying of data directly from the Chado library 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 library "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 library) 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_library
- */
- function tripal_library_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 libraries
- $active_jobs = FALSE;
- if (tripal_get_module_active_jobs('tripal_library')) {
- $active_jobs = TRUE;
- }
- // add the field set for syncing libraries
- if (!$active_jobs) {
- get_tripal_library_admin_form_sync_set($form);
- get_tripal_library_admin_form_cleanup_set($form);
- get_tripal_library_admin_form_reindex_set($form);
- get_tripal_library_admin_form_taxonomy_set($form);
- get_tripal_library_admin_form_cleanup_set($form);
- }
- else {
- $form['notice'] = array(
- '#type' => 'fieldset',
- '#title' => t('Library Management Temporarily Unavailable')
- );
- $form['notice']['message'] = array(
- '#value' => t('Currently, library 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 library information for associated features or organisms
- * This function also provides contents for indexing
- *
- * @ingroup tripal_library
- */
- function tripal_library_nodeapi(&$node, $op, $teaser, $page) {
- switch ($op) {
- // Note that this function only adds library view to an organism/feature
- // node.
- case 'view':
- // add the library to the organism/feature search indexing
- if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
- $node->content['tripal_library_index_version'] = array(
- '#value' => theme('tripal_library_search_index', $node),
- );
- }
- elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
- $node->content['tripal_library_index_version'] = array(
- '#value' => theme('tripal_library_search_result', $node),
- );
- }
- else {
- switch ($node->type) {
- case 'chado_organism':
- // Show library if the organism/feature is not at teaser view
- $node->content['tripal_organism_libraries'] = array(
- '#value' => theme('tripal_organism_libraries', $node),
- );
- break;
- case 'chado_feature':
- // Show library if the organism/feature is not at teaser view
- $node->content['tripal_feature_libraries'] = array(
- '#value' => theme('tripal_feature_libraries', $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_library
- */
- function tripal_library_theme() {
- return array(
- 'tripal_library_library_table' => array(
- 'arguments' => array('libraries'),
- ),
- 'tripal_library_search_index' => array(
- 'arguments' => array('node'),
- ),
- 'tripal_library_search_result' => array(
- 'arguments' => array('node'),
- ),
- 'tripal_organism_libraries' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_organism_libraries',
- ),
- 'tripal_feature_libraries' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_feature_libraries',
- ),
- 'tripal_library_base' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_base',
- ),
- 'tripal_library_synonyms' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_synonyms',
- ),
- 'tripal_library_references' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_references',
- ),
- 'tripal_library_properties' => array(
- 'arguments' => array('node' => NULL),
- 'template' => 'tripal_library_properties',
- ),
- );
- }
- /**
- * This function is an extension of the chado_feature_view and
- * chado_organism_view by providing the markup for the library object
- * THAT WILL BE INDEXED.
- *
- * @ingroup tripal_library
- */
- function theme_tripal_library_search_index($node) {
- if ($node->type == 'chado_organism') {
- $content = "";
- // get the libraries for the organism
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {library} L ".
- "WHERE L.organism_id = %d";
- $libraries = array();
- $results = db_query($sql, $node->organism->organism_id);
- while ($library = db_fetch_object($results)) {
- // get the description
- $sql = "SELECT * FROM {libraryprop} LP ".
- " INNER JOIN CVTerm CVT ON CVT.cvterm_id = LP.type_id ".
- "WHERE LP.library_id = $library->library_id ".
- " AND CVT.name = 'library_description'";
- $desc = db_fetch_object(db_query($sql));
- $library->description = $desc->value;
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
- if (count($libraries) > 0) {
- foreach ($libraries as $library) {
- $content .= "$library->name ";
- $content .= "$library->description";
- };
- }
- // Provide library names to show in a feature page
- }
- elseif ($node->type == 'chado_feature') {
- $content = "";
- $organism_id = $node->feature->organism_id;
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {library} L ".
- " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
- "WHERE LF.feature_id = " . $node->feature->feature_id;
- $libraries = array();
- $results = db_query($sql);
- while ($library = db_fetch_object($results)) {
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
- if (count($libraries) > 0) {
- $lib_additions = array();
- foreach ($libraries as $library) {
- $content .= $library->name;
- };
- }
- }
- return $content;
- }
- /**
- * This function shows library information on an organism/feature node
- *
- * @ingroup tripal_library
- */
- function theme_tripal_library_node_libraries($node) {
- $content = "";
- // Show library information in a expandable box for a organism page.
- // Make sure we have $node->organism_id. In the case of creating a new
- // organism, the organism_id is not created until we save. This will cause
- // an error when users preview the creation without a $node->organism_id
- if ($node->type == 'chado_organism' && $node->organism_id) {
- $box_status = variable_get("tripal_library-box-libraries", "menu_off");
- if (strcmp($box_status, "menu_off")==0) {
- return get_tripal_library_organism_libraries($node->nid);
- }
- }
- // Provide library names to show in a feature page.
- // Make sure we have $node->feature->feature_id or there will be an error
- // when a feature is previewed at its creation
- elseif ($node->type == 'chado_feature' && $node->feature->feature_id) {
- $organism_id = $node->feature->organism_id;
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {library} L ".
- " INNER JOIN Library_feature LF ON L.library_id = LF.library_id ".
- "WHERE LF.feature_id = " . $node->feature->feature_id;
- $libraries = array();
- $results = db_query($sql);
- while ($library = db_fetch_object($results)) {
- $libraries[] = $library;
- }
- tripal_db_set_active($previous_db);
- if (count($libraries) > 0) {
- $lib_additions = array();
- foreach ($libraries as $library) {
- $sql = "SELECT nid FROM {chado_library} WHERE library_id = %d";
- $lib_nid = db_result(db_query($sql, $library->library_id));
- if ($lib_nid) {
- $lib_url = url("node/$lib_nid");
- }
- $lib_additions[$lib_url] = $library->name;
- };
- $node->lib_additions = $lib_additions;
- }
- }
- return $content;
- }
- /**
- *
- *
- * @ingroup tripal_library
- */
- function get_tripal_library_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 libraries in Chado become ".
- "\"orphaned\". This can occur if an library node in Drupal is ".
- "deleted but the corresponding chado library 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 libraries'),
- '#weight' => 2,
- );
- }
- /**
- *
- *
- * @ingroup tripal_library
- */
- function get_tripal_library_admin_form_taxonomy_set(&$form) {
- $form['taxonify'] = array(
- '#type' => 'fieldset',
- '#title' => t('Assign Drupal Taxonomy to Library Features')
- );
- // get the list of libraries
- $sql = "SELECT * FROM {Library} 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 libraries
- $lib_boxes = array();
- while ($library = db_fetch_object($lib_rset)) {
- $lib_boxes[$library->library_id] = "$library->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 libraries 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-libraries'] = array(
- '#title' => t('Libraries'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the libraries whose features you want to reset taxonomy. Note: this list contains all libraries, 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_library
- */
- function get_tripal_library_admin_form_reindex_set(&$form) {
- // define the fieldsets
- $form['reindex'] = array(
- '#type' => 'fieldset',
- '#title' => t('Reindex Library Features')
- );
- // get the list of libraries
- $sql = "SELECT * FROM {Library} 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 libraries
- $lib_boxes = array();
- while ($library = db_fetch_object($lib_rset)) {
- $lib_boxes[$library->library_id] = "$library->name";
- }
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#value' => t("This option allows for reindexing of only those features that belong to the selected libraries below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
- '#weight' => 1,
- );
- $form['reindex']['re-libraries'] = array(
- '#title' => t('Libraries'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the libraries whoee features you want to reindex. Note: this list contains all libraries, 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_library
- */
- function get_tripal_library_admin_form_sync_set(&$form) {
- // define the fieldsets
- $form['sync'] = array(
- '#type' => 'fieldset',
- '#title' => t('Sync Libraries')
- );
- // get the list of libraries
- $sql = "SELECT * FROM {Library} 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 libraries 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 libraries are currently synced.
- $lib_boxes = array();
- $added = 0;
- while ($library = db_fetch_object($lib_rset)) {
- // check to see if the library is already present as a node in drupal.
- // if so, then skip it.
- $sql = "SELECT * FROM {chado_library} WHERE library_id = %d";
- if (!db_fetch_object(db_query($sql, $library->library_id))) {
- $lib_boxes[$library->library_id] = "$library->name";
- $added++;
- }
- }
- // if we have libraries we need to add to the checkbox then
- // build that form element
- if ($added > 0) {
- $lib_boxes['all'] = "All Libraries";
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#value' => t("This option allows for the creation of Drupal content for libraries in chado. Only the selected libraries will be synced."),
- '#weight' => 1,
- );
- $form['sync']['libraries'] = array(
- '#title' => t('Available Libraries'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the libraries you want to sync. Drupal content will be created for each of the libraries listed above. Select 'All Libraries' 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 Libraries'),
- '#weight' => 3,
- );
- }
- // we don't have any libraries to select from
- else {
- $form['sync']['value'] = array(
- '#value' => t('All libraries in Chado are currently synced with Drupal.')
- );
- }
- }
- /**
- *
- * @ingroup tripal_library
- */
- function tripal_library_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 Libraries')) {
- // 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
- $libraries = $form_state['values']['libraries'];
- $do_all = FALSE;
- $to_sync = array();
- foreach ($libraries as $library_id) {
- if (preg_match("/^all$/i", $library_id)) {
- $do_all = TRUE;
- }
- if ($library_id and preg_match("/^\d+$/i", $library_id)) {
- // get the library info
- $sql = "SELECT * FROM {Library} WHERE library_id = %d";
- $previous_db = tripal_db_set_active('chado'); // use chado database
- $library = db_fetch_object(db_query($sql, $library_id));
- tripal_db_set_active($previous_db); // now use drupal database
- $to_sync[$library_id] = $library->name;
- }
- }
- // submit the job to the tripal job manager
- if ($do_all) {
- tripal_add_job('Sync all libraries', 'tripal_library', 'tripal_library_sync_libraries', $job_args, $user->uid);
- }
- else{
- foreach ($to_sync as $library_id => $name) {
- $job_args[0] = $library_id;
- tripal_add_job("Sync library: $name", 'tripal_library', 'tripal_library_sync_libraries', $job_args, $user->uid);
- }
- }
- }
- // -------------------------------------
- // Submit the Reindex Job if selected
- if ($form_state['values']['op'] == t('Reindex Features')) {
- $libraries = $form_state['values']['re-libraries'];
- foreach ($libraries as $library_id) {
- if ($library_id and preg_match("/^\d+$/i", $library_id)) {
- // get the library info
- $sql = "SELECT * FROM {Library} WHERE library_id = %d";
- $previous_db = tripal_db_set_active('chado'); // use chado database
- $library = db_fetch_object(db_query($sql, $library_id));
- tripal_db_set_active($previous_db); // now use drupal database
- $job_args[0] = $library_id;
- tripal_add_job("Reindex features for library: $library->name", 'tripal_library',
- 'tripal_library_reindex_features', $job_args, $user->uid);
- }
- }
- }
- // -------------------------------------
- // Submit the Taxonomy Job if selected
- if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
- $libraries = $form_state['values']['tx-libraries'];
- foreach ($libraries as $library_id) {
- if ($library_id and preg_match("/^\d+$/i", $library_id)) {
- // get the library info
- $sql = "SELECT * FROM {Library} WHERE library_id = %d";
- $previous_db = tripal_db_set_active('chado'); // use chado database
- $library = db_fetch_object(db_query($sql, $library_id));
- tripal_db_set_active($previous_db); // now use drupal database
- $job_args[0] = $library_id;
- tripal_add_job("Set taxonomy for features in library: $library->name", 'tripal_library',
- 'tripal_library_taxonify_features', $job_args, $user->uid);
- }
- }
- }
- // -------------------------------------
- // Submit the Cleanup Job if selected
- if ($form_state['values']['op'] == t('Clean up orphaned libraries')) {
- tripal_add_job('Cleanup orphaned libraries', 'tripal_library',
- 'tripal_library_cleanup', $job_args, $user->uid);
- }
- }
- /**
- *
- * @ingroup tripal_library
- */
- function tripal_library_show_libraries() {
- // Show libraries stored in Drupal's {chado_library} table
- $sql = "SELECT COUNT(library_id) FROM {chado_library}";
- $no_libs = db_result(db_query($sql));
- if ($no_libs != 0) {
- $libraries = get_chado_libraries();
- if ($no_libs != count($libraries)) {
- drupal_set_message(t("Synchronization needed."));
- }
- return theme('tripal_library_library_table', $libraries);
- }
- else {
- return t("No library exists. Please contact administrators to ".
- "synchronize libraries.");
- }
- }
- /**
- *
- * @ingroup tripal_library
- */
- function tripal_library_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_library
- */
- function tripal_library_library_access($op, $node, $account) {
- if ($op == 'create') {
- if (!user_access('create chado_library content', $account)) {
- return FALSE;
- }
- }
- if ($op == 'update') {
- if (!user_access('edit any chado_library content', $account) &&
- !user_access('edit own chado_library content', $account)) {
- return FALSE;
- }
- if (user_access('edit own chado_library content', $account) &&
- $account->uid != $node->uid) {
- return FALSE;
- }
- }
- if ($op == 'delete') {
- if (!user_access('delete any chado_library content', $account) &&
- !user_access('delete own chado_library content', $account)) {
- return FALSE;
- }
- if (user_access('delete own chado_library content', $account) &&
- $account->uid != $node->uid) {
- return FALSE;
- }
- }
- return NULL;
- }
- /**
- * validates submission of form when adding or updating a library node
- *
- * @ingroup tripal_library
- */
- function chado_library_validate($node) {
- $lib = 0;
- // check to make sure the unique name on the library is unique
- // before we try to insert into chado.
- if ($node->library_id) {
- $sql = "SELECT * FROM ".
- "{Library} WHERE ".
- "uniquename = '%s' ".
- "AND NOT library_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $lib = db_fetch_object(db_query($sql, $node->uniquename,
- $node->library_id));
- tripal_db_set_active($previous_db);
- }
- else {
- $sql = "SELECT * FROM ".
- "{Library} ".
- "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 library name already exists. '.
- 'Please choose another'));
- }
- }
- /**
- * When a new chado_library node is created we also need to add information
- * to our chado_library table. This function is called on insert of a new node
- * of type 'chado_library' and inserts the necessary information.
- *
- * @ingroup tripal_library
- */
- function chado_library_insert($node) {
- if ($node->library_id) {
- $library['library_id'] = $node->library_id;
- }
- else {
- // get the library type id
- $values = array(
- 'cv_id' => array(
- 'name' => 'tripal'
- ),
- 'name' => $node->library_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
- );
- $library = tripal_core_chado_insert('library', $values);
- }
- if ($library) {
- // add the description property
- tripal_library_insert_property($library['library_id'], 'library_description', $node->library_description);
- // make sure the entry for this feature doesn't already exist in the chado_library table
- // if it doesn't exist then we want to add it.
- $library_id = chado_get_id_for_node('library', $node) ;
- if (!$library_id) {
- // next add the item to the drupal table
- $sql = "INSERT INTO {chado_library} (nid, vid, library_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql, $node->nid, $node->vid, $library['library_id']);
- }
- }
- else {
- drupal_set_message(t('Unable to add library.', 'warning'));
- watchdog('tripal_library',
- 'Insert feature: Unable to create library where values: %values',
- array('%values' => print_r($values, TRUE)),
- WATCHDOG_WARNING
- );
- }
- }
- /**
- * Update nodes
- *
- * @ingroup tripal_library
- */
- function chado_library_update($node) {
- if ($node->revision) {
- // TODO -- decide what to do about revisions
- }
- else {
- $library_id = chado_get_id_for_node('library', $node) ;
- // get the library type id
- $values = array(
- 'cv_id' => array(
- 'name' => 'tripal'
- ),
- 'name' => $node->library_type
- );
- $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
- // update the library record
- $match = array(
- 'library_id' => $library_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('library', $match, $values);
- tripal_library_update_property($library_id, 'library_description', $node->library_description);
- }
- }
- /**
- * Add the library as a taxonomy term for associating with library_features
- *
- * @ingroup tripal_library
- */
- function tripal_library_add_taxonomy($node, $library_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 Libraries'){
- $vid = $vocab->vid;
- }
- }
- if(!$vid){ */
- // add the vocabulary
- $vocab_form['values']['name'] = 'DNA Libraries';
- $vocab_form['values']['description'] = 'Allows for associating/searching of library features by library 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'] = $library_id;
- drupal_execute('taxonomy_form_term', $form_state, $vid);
- }
- }
- }
- /**
- * When editing or creating a new node of type 'chado_library' we need
- * a form. This function creates the form that will be used for this.
- *
- * @ingroup tripal_library
- */
- function chado_library_form($node) {
- $form = array();
- $library = $node->library;
- // get the default values
- $uniquename = $node->uniquename;
- if (!$uniquename) {
- $uniquename = $library->uniquename;
- }
- $library_type = $node->library_type;
- if (!$library_type) {
- $library_type = $library->type_id->name;
- }
- $organism_id = $node->organism_id;
- if (!$organism_id) {
- $organism_id = $library->organism_id->organism_id;
- }
- $library_description = $node->library_description;
- if (!$library_description) {
- $libprop = tripal_library_get_property($library->library_id, 'library_description');
- $library_description = $libprop->value;
- }
- // keep track of the library id if we have. If we do have one then
- // this is an update as opposed to an insert.
- $form['library_id'] = array(
- '#type' => 'value',
- '#value' => $library->library_id,
- );
- $form['title']= array(
- '#type' => 'textfield',
- '#title' => t('Library Title'),
- '#description' => t('Please enter the title for this library. '.
- 'This appears at the top of the library page.'),
- '#required' => TRUE,
- '#default_value' => $node->title,
- '#weight' => 1
- );
- $form['uniquename']= array(
- '#type' => 'textfield',
- '#title' => t('Unique Library Name'),
- '#description' => t('Please enter a unique name for this library'),
- '#required' => TRUE,
- '#default_value' => $uniquename,
- '#weight' => 2
- );
- // These library types should not be hard coded, but for now the are...
- $library_types = array();
- $library_types[''] = '';
- $library_types['cdna_library'] = 'cDNA Library';
- $library_types['bac_library'] = 'BAC Library';
- $library_types['fosmid_library'] = 'FOSMID Library';
- $library_types['cosmid_library'] = 'COSMID Library';
- $library_types['yac_library'] = 'YAC Library';
- $form['library_type'] = array(
- '#title' => t('Library Type'),
- '#type' => t('select'),
- '#description' => t("Choose the library type."),
- '#required' => TRUE,
- '#default_value' => $library_type,
- '#options' => $library_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 library is ".
- "associated."),
- '#required' => TRUE,
- '#default_value' => $organism_id,
- '#options' => $organisms,
- '#weight' => 4,
- );
- $form['library_description']= array(
- '#type' => 'textarea',
- '#title' => t('Library Description'),
- '#description' => t('A brief description of the library'),
- '#required' => TRUE,
- '#default_value' => $library_description,
- '#weight' => 5
- );
- return $form;
- }
- /**
- *
- *
- * @ingroup tripal_library
- */
- function tripal_library_sync_libraries($library_id = NULL, $job_id = NULL) {
- global $user;
- $page_content = '';
- // get the list of libraries and create new nodes
- if (!$library_id) {
- $sql = "SELECT * FROM {Library} 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 {Library} L WHERE library_id = %d";
- $previous_db = tripal_db_set_active('chado'); // use chado database
- $results = db_query($sql, $library_id);
- tripal_db_set_active($previous_db); // now use drupal database
- }
- // We'll use the following SQL statement for checking if the library
- // already exists as a drupal node.
- $sql = "SELECT * FROM {chado_library} ".
- "WHERE library_id = %d";
- while ($library = db_fetch_object($results)) {
- // check if this library already exists in the drupal database. if it
- // does then skip this library and go to the next one.
- if (!db_fetch_object(db_query($sql, $library->library_id))) {
- $new_node = new stdClass();
- $new_node->type = 'chado_library';
- $new_node->uid = $user->uid;
- $new_node->title = "$library->name";
- $new_node->library_id = $library->library_id;
- $new_node->organism_id = $library->organism_id;
- $new_node->uniquename = $library->uniquename;
- $new_node->type_id = $library->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 " . $library->name . "\n";
- }
- else {
- print "ERROR: Unable to create " . $library->name . "\n";
- }
- }
- else {
- print "ERROR: Unable to create " . $library->name . "\n" . print_r($errors, TRUE) . "\n";
- }
- }
- else {
- print "Skipped " . $library->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_library
- */
- function chado_library_load($node) {
- // get the feature details from chado
- $library_id = chado_get_id_for_node('library', $node);
- $values = array('library_id' => $library_id);
- $library = tripal_core_generate_chado_var('library', $values);
- $additions = new stdClass();
- $additions->library = $library;
- return $additions;
- }
- /**
- * This function customizes the view of the chado_library node. It allows
- * us to generate the markup. This function is required for node [Preview]
- *
- * @ingroup tripal_library
- */
- function chado_library_view($node, $teaser = FALSE, $page = FALSE) {
- // use drupal's default node view:
- if (!$teaser) {
- $node = node_prepare($node, $teaser);
- // If Hook_view() is called by Hook_form(), we'll only have orgnism_id
- // but not genus/species/common_name. We need to get those from chado
- // database so they will show up in preview
- if (!$node->genus) {
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
- $data = db_fetch_object(db_query($sql, $node->organism_id));
- $node->genus = $data->genus;
- $node->species = $data->species;
- $node->common_name = $data->common_name;
- tripal_db_set_active($previous_db);
- }
- }
- return $node;
- }
- /**
- * This function creates the html markup for the library table.
- * It can be overridden in the theme for the site by adding a php
- * method in the template.php file named
- * [theme_name]_tripal_library_library_table(&$libraries)
- *
- * @ingroup tripal_library
- */
- function theme_tripal_library_library_table($libraries) {
- // cycle through the libraries and build the libraries page
- $output = "<div id=\"libraries\">";
- $output .= '<table>';
- $output .= "<tr>";
- $output .= "<th>Name</th>";
- $output .= "<th>Type</th>";
- $output .= "<th>Organism</th>";
- $output .= "<th>Description</th>";
- $output .= "</tr>";
- foreach ($libraries as $library) {
- $lib_url = url("node/$library->node_id");
- $output .= "<tr>";
- $output .= "<td>".
- " <a href=\"$lib_url\">$library->name</a>".
- "</td>";
- if (strcasecmp($library->type_name, 'bac_library') == 0) {
- $output .= "<td>BAC</td>";
- }
- elseif (strcasecmp($library->type_name, 'cdna_library') == 0) {
- $output .= "<td>cDNA</td>";
- }
- else{
- $output .= "<td>$library->type_name</td>";
- }
- $output .= "<td nowrap>".
- " $library->common_name".
- "</td>";
- $description = $library->library_description;
- $output .= "<td>$description</td>";
- $output .= "</tr>";
- }
- $output .= "</table>";
- $output .= "</div>";
- return $output;
- }
- /**
- *
- * @ingroup tripal_library
- */
- function tripal_library_feature_set_taxonomy($library_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 == 'Library') {
- $vid = $vocab->vid;
- }
- }
- if (!$vid) {
- return;
- }
- // We'll use the following SQL statement for getting the node info
- if ($library_id) {
- print "Finding features for library with ID: $library_id\n";
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- "FROM {library_feature} LF ".
- "INNER JOIN Library L ON LF.library_id = L.library_id ".
- "WHERE L.library_id = $library_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 libraries\n";
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- "FROM {library_feature} LF ".
- "INNER JOIN Library L ON LF.library_id = L.library_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_library
- */
- function tripal_library_reindex_features($library_id = NULL, $job_id = NULL) {
- $i = 0;
- // if the caller provided a library_id then get all of the features
- // associated with the library. Otherwise get all sequences assoicated
- // with all libraries.
- if ($library_id) {
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- " FROM {library_feature} LF ".
- " INNER JOIN Library L ON LF.library_id = L.library_id ".
- "WHERE L.library_id = $library_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.library_id, L.name as libname ".
- " FROM {library_feature} LF ".
- " INNER JOIN Library L ON LF.library_id = L.library_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_library
- */
- function tripal_library_taxonify_features($library_id = NULL, $job_id = NULL) {
- $i = 0;
- // if the caller provided a library_id then get all of the features
- // associated with the library. Otherwise get all sequences assoicated
- // with all libraries.
- if ($library_id) {
- $sql = "SELECT LF.feature_id, L.library_id, L.name as libname ".
- " FROM {library_feature} LF ".
- " INNER JOIN Library L ON LF.library_id = L.library_id ".
- "WHERE L.library_id = $library_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.library_id, L.name as libname ".
- " FROM {library_feature} LF ".
- " INNER JOIN Library L ON LF.library_id = L.library_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_library
- */
- function chado_library_delete(&$node) {
- $library_id = chado_get_id_for_node('library', $node);
-
- // if we don't have a library id for this node then this isn't a node of
- // type chado_library or the entry in the chado_library table was lost.
- if (!$library_id) {
- return;
- }
-
- // Remove data from {chado_library}, {node} and {node_revisions} tables of
- // drupal database
- $sql_del = "DELETE FROM {chado_library} ".
- "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 library and libraryprop tables of chado database as well
- $previous_db = tripal_db_set_active('chado');
- db_query("DELETE FROM {library} WHERE library_id = %d", $library_id);
- db_query("DELETE FROM {libraryprop} WHERE library_id = %d", $library_id);
- tripal_db_set_active($previous_db);
- }
- /**
- * Display block with libraries
- * @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_library
- */
- function tripal_library_block($op = 'list', $delta = '0', $edit = array()) {
- switch ($op) {
- case 'list':
- $blocks['libreferences']['info'] = t('Tripal Library References');
- $blocks['libreferences']['cache'] = BLOCK_NO_CACHE;
- $blocks['libbase']['info'] = t('Tripal Library Details');
- $blocks['libbase']['cache'] = BLOCK_NO_CACHE;
- $blocks['libsynonyms']['info'] = t('Tripal Library Synonyms');
- $blocks['libsynonyms']['cache'] = BLOCK_NO_CACHE;
- $blocks['libproperties']['info'] = t('Tripal Library Properties');
- $blocks['libproperties']['cache'] = BLOCK_NO_CACHE;
- $blocks['featurelibs']['info'] = t('Tripal Feature Libraries');
- $blocks['featurelibs']['cache'] = BLOCK_NO_CACHE;
- $blocks['orglibs']['info'] = t('Tripal Organism Libraries');
- $blocks['orglibs']['cache'] = BLOCK_NO_CACHE;
- return $blocks;
- case 'view':
- if (user_access('access chado_library 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_library_references', $node);
- break;
- case 'libbase':
- $block['subject'] = t('Library Details');
- $block['content'] = theme('tripal_library_base', $node);
- break;
- case 'libsynonyms':
- $block['subject'] = t('Synonyms');
- $block['content'] = theme('tripal_library_synonyms', $node);
- break;
- case 'libproperties':
- $block['subject'] = t('Properties');
- $block['content'] = theme('tripal_library_properties', $node);
- break;
- case 'featurelibs':
- $block['subject'] = t('Libraries');
- $block['content'] = theme('tripal_feature_libraries', $node);
- break;
- case 'orglibs':
- $block['subject'] = t('Libraries');
- $block['content'] = theme('tripal_organism_libraries', $node);
- break;
- default :
- }
- return $block;
- }
- }
- }
- /**
- * This function uses library_id's of all drupal library nodes as input and
- * pull the library information (name, uniquename, type, genus, species,
- * common_name, description) from chado database. The return type is an object
- * array that stores sorted $library objects
- *
- * This function is DEPRECATED
- * Please use tripal_core_chado_generate_vars
- *
- * @ingroup tripal_library_api
- */
- function get_chado_libraries() {
- $sql_drupal = "SELECT COUNT (library_id) FROM {chado_library}";
- $no_libs = db_result(db_query($sql_drupal));
- if ($no_libs != 0) {
- // Get library_id's from drupal
- $sql = "SELECT library_id, nid FROM {chado_library}";
- $result = db_query($sql);
- $previous_db = tripal_db_set_active('chado');
- // Get library info from chado's library, organism, and cvterm tables
- $sql_info = "SELECT L.name, uniquename, genus, species, common_name, ".
- " CVT.name as type_name ".
- "FROM {Library} L ".
- "INNER JOIN Organism O ON L.organism_id = O.organism_id ".
- "INNER JOIN CVTerm CVT ON L.type_id = CVT.cvterm_id ".
- "WHERE library_id=%d";
- // Get library description from libraryprop if there is any
- $sql_desc = "SELECT value ".
- "FROM {Libraryprop} LP ".
- "INNER JOIN CVTerm CVT ON LP.type_id = CVT.cvterm_id ".
- "WHERE library_id = %d AND CVT.name = 'library_description'";
- $libraries = array();
- while ($data = db_fetch_object($result)) {
- $library = db_fetch_object(db_query($sql_info, $data->library_id));
- $library->node_id = $data->nid;
- $desc = db_fetch_object(db_query($sql_desc, $data->library_id))->value;
- if ($desc) {
- $library->library_description = $desc;
- }
- else {
- $library->library_description = "NA";
- }
- // Use uniquename as the key so we can sort by uniquename later
- $key = drupal_strtolower($library->uniquename);
- $libraries [$key] = $library;
- }
- tripal_db_set_active($previous_db);
- //Sort libraries by uniquename
- ksort($libraries, SORT_STRING);
- return $libraries;
- }
- }
- /**
- * 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_library
- */
- function tripal_library_cleanup($dummy = NULL, $job_id = NULL) {
- return tripal_core_clean_orphaned_nodes('library', $job_id);
-
- }
- /************************************************************************
- */
- function theme_tripal_library_search_result($node) {
- }
|