1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048 |
- <?php
- require_once "tripal_organism.api.inc";
- function tripal_organism_node_info() {
- $nodes = array();
- $nodes['chado_organism'] = array(
- 'name' => t('Organism'),
- 'module' => 'chado_organism',
- 'description' => t('An organism from the chado database'),
- 'has_title' => FALSE,
- 'title_label' => t('Organism'),
- 'has_body' => FALSE,
- 'body_label' => t('Organism Description'),
- 'locked' => TRUE
- );
- return $nodes;
- }
- function tripal_organism_block($op = 'list', $delta = '0', $edit = array()){
- switch($op){
- case 'list':
- $blocks[0]['info'] = t('Organisms');
- return $blocks;
- case 'view':
- if(user_access('access chado_organism content')){
-
- $sql = "SELECT COUNT(organism_id) FROM {chado_organism}";
- $no_orgs = db_result(db_query ($sql));
- if($no_orgs != 0) {
- $organisms = get_chado_organisms();
- foreach($organisms as $organism){
-
- $items[] = l($organism->common_name,
- 'node/'.$organism->node_id);
- }
- } else {
- $items[] = t("No organism exists.");
- }
- $block['subject'] = t('Organisms');
-
- $block['content'] = theme('item_list', $items);
- }
- return $block;
- }
- }
- function tripal_organism_menu() {
- $items = array();
- $items['organisms'] = array(
- 'menu_name' => ('primary-links'),
- 'title' => t('Organisms'),
- 'page callback' => 'tripal_organism_show_organisms',
- 'access arguments' => array('access chado_organism content'),
- 'type' => MENU_NORMAL_ITEM
- );
-
- $items['admin/tripal/tripal_organism'] = array(
- 'title' => 'Organisms',
- 'description' => 'Manage integration of Chado organisms including associated features',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('tripal_organism_admin'),
- 'access arguments' => array('administer site configuration'),
- 'type' => MENU_NORMAL_ITEM,
- );
- return $items;
- }
- function chado_organism_access($op, $node, $account){
- if ($op == 'create') {
- return user_access('create chado_organism content', $account);
- }
- if ($op == 'update') {
- if (user_access('edit chado_organism content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'delete') {
- if (user_access('delete chado_organism content', $account)) {
- return TRUE;
- }
- }
- if ($op == 'view') {
- if (user_access('access chado_organism content', $account)) {
- return TRUE;
- }
- }
- return FALSE;
- }
- function tripal_organism_perm(){
- return array(
- 'access chado_organism content',
- 'create chado_organism content',
- 'delete chado_organism content',
- 'edit chado_organism content',
- );
- }
- function tripal_organism_admin () {
- $form = array();
-
-
-
- $active_jobs = FALSE;
- if(tripal_get_module_active_jobs('tripal_organism')){
- $active_jobs = TRUE;
- }
-
- if(!$active_jobs){
- get_tripal_organism_admin_form_sync_set($form);
- get_tripal_organism_admin_form_reindex_set($form);
- get_tripal_organism_admin_form_taxonomy_set($form);
- get_tripal_organism_admin_form_cleanup_set($form);
- } else {
- $form['notice'] = array(
- '#type' => 'fieldset',
- '#title' => t('Organism Management Temporarily Unavailable')
- );
- $form['notice']['message'] = array(
- '#value' => t('Currently, organism 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);
- }
- function get_tripal_organism_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 organisms in Chado become ".
- "\"orphaned\". This can occur if an organism node in Drupal is ".
- "deleted but the corresponding chado organism 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 organisms'),
- '#weight' => 2,
- );
- }
- function get_tripal_organism_admin_form_taxonomy_set(&$form) {
- $form['taxonify'] = array(
- '#type' => 'fieldset',
- '#title' => t('Assign Drupal Taxonomy to Organism Features')
- );
-
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
- $previous_db = tripal_db_set_active('chado');
- $org_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $org_boxes = array();
- while($organism = db_fetch_object($org_rset)){
- $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
- }
- $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 organisms 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-organisms'] = array (
- '#title' => t('Organisms'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the organisms whose features you want to reset taxonomy. Note: this list contains all organisms, even those that may not be synced."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $org_boxes,
- '#weight' => 2
- );
- $form['taxonify']['tx-button'] = array(
- '#type' => 'submit',
- '#value' => t('Set Feature Taxonomy'),
- '#weight' => 3
- );
- }
- function get_tripal_organism_admin_form_reindex_set(&$form) {
-
- $form['reindex'] = array(
- '#type' => 'fieldset',
- '#title' => t('Reindex Organism Features')
- );
-
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
- $previous_db = tripal_db_set_active('chado');
- $org_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $org_boxes = array();
- while($organism = db_fetch_object($org_rset)){
- $org_boxes[$organism->organism_id] = "$organism->genus $organism->species";
- }
- $form['reindex']['description'] = array(
- '#type' => 'item',
- '#value' => t("This option allows for reindexing of only those features that belong to the selected organisms below. All other features will be unaffected. To reindex all features in the site see the Feature Administration page."),
- '#weight' => 1,
- );
- $form['reindex']['re-organisms'] = array (
- '#title' => t('Organisms'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the organisms whoee features you want to reindex. Note: this list contains all organisms, even those that may not be synced."),
- '#required' => FALSE,
- '#prefix' => '<div id="lib_boxes">',
- '#suffix' => '</div>',
- '#options' => $org_boxes,
- '#weight' => 2,
- );
- $form['reindex']['re-button'] = array(
- '#type' => 'submit',
- '#value' => t('Reindex Features'),
- '#weight' => 3,
- );
- }
- function get_tripal_organism_admin_form_sync_set (&$form) {
-
- $form['sync'] = array(
- '#type' => 'fieldset',
- '#title' => t('Sync Organisms')
- );
-
-
-
- $active_jobs = FALSE;
- if(tripal_get_module_active_jobs('tripal_organism')){
- $active_jobs = TRUE;
- }
- if(!$active_jobs){
-
- $sql = "SELECT * FROM {Organism} ORDER BY genus,species";
- $previous_db = tripal_db_set_active('chado');
- $org_rset = db_query($sql);
- tripal_db_set_active($previous_db);
-
-
-
-
- $org_boxes = array();
- $added = 0;
- while($organism = db_fetch_object($org_rset)){
-
-
- $sql = "SELECT * FROM {chado_organism} WHERE organism_id = %d";
- if(!db_fetch_object(db_query($sql,$organism->organism_id))){
- $org_boxes[$organism->organism_id] = "$organism->genus $organism->species ($organism->common_name)";
- $added++;
- }
- }
-
-
- if($added > 0){
- $org_boxes['all'] = "All Organisms";
- $form['sync']['organisms'] = array (
- '#title' => t('Available Organisms'),
- '#type' => t('checkboxes'),
- '#description' => t("Check the organisms you want to sync. Drupal content will be created for each of the organisms listed above. Select 'All Organisms' to sync all of them."),
- '#required' => FALSE,
- '#prefix' => '<div id="org_boxes">',
- '#suffix' => '</div>',
- '#options' => $org_boxes,
- );
- $form['sync']['button'] = array(
- '#type' => 'submit',
- '#value' => t('Submit Sync Job')
- );
- }
-
- else {
- $form['sync']['value'] = array(
- '#value' => t('All organisms in Chado are currently synced with Drupal.')
- );
- }
- }
-
- else {
- $form['sync']['value'] = array(
- '#value' => t('Currently, jobs exist related to chado organisms. Please check back later for organisms that can by synced once these jobs have finished. You can view the status of pending jobs in the Tripal jobs page.')
- );
- }
- }
- function tripal_organism_admin_validate($form, &$form_state) {
- global $user;
- $job_args = array();
- if ($form_state['values']['op'] == t('Submit Sync Job')) {
-
-
- $organisms = $form_state['values']['organisms'];
- $do_all = FALSE;
- $to_sync = array();
- foreach ($organisms as $organism_id){
- if(preg_match("/^all$/i",$organism_id)){
- $do_all = TRUE;
- }
- if($organism_id and preg_match("/^\d+$/i",$organism_id)){
-
- $sql = "SELECT * FROM {Organism} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($sql,$organism_id));
- tripal_db_set_active($previous_db);
- $to_sync[$organism_id] = "$organism->genus $organism->species";
- }
- }
-
- if($do_all){
- tripal_add_job('Sync all organisms','tripal_organism',
- 'tripal_organism_sync_organisms',$job_args,$user->uid);
- }
- else{
- foreach($to_sync as $organism_id => $name){
- $job_args[0] = $organism_id;
- tripal_add_job("Sync organism: $name",'tripal_organism',
- 'tripal_organism_sync_organisms',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Reindex Features')) {
- $organisms = $form_state['values']['re-organisms'];
- foreach ($organisms as $organism_id){
- if($organism_id and preg_match("/^\d+$/i",$organism_id)){
-
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($sql,$organism_id));
- tripal_db_set_active($previous_db);
- $job_args[0] = $organism_id;
- tripal_add_job("Reindex features for organism: $organism->genus ".
- "$organism->species",'tripal_organism',
- 'tripal_organism_reindex_features',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
- $organisms = $form_state['values']['tx-organisms'];
- foreach ($organisms as $organism_id){
- if($organism_id and preg_match("/^\d+$/i",$organism_id)){
-
- $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($sql,$organism_id));
- tripal_db_set_active($previous_db);
- $job_args[0] = $organism_id;
- tripal_add_job("Set taxonomy for features in organism: ".
- "$organism->genus $organism->species",'tripal_organism',
- 'tripal_organism_taxonify_features',$job_args,$user->uid);
- }
- }
- }
-
-
- if ($form_state['values']['op'] == t('Clean up orphaned organisms')) {
- tripal_add_job('Cleanup orphaned organisms','tripal_organism',
- 'tripal_organisms_cleanup',$job_args,$user->uid);
- }
- }
- function tripal_organism_theme () {
- return array(
- 'tripal_organism_organism_page' => array (
- 'arguments' => array('organisms'),
- ),
- );
- }
- function tripal_organism_cron (){
-
-
-
- }
- function chado_organism_insert($node){
-
- $o_sql = "SELECT organism_id ".
- "FROM {Organism} ".
- "WHERE genus = '%s' ".
- "AND species = '%s'";
- $previous_db = tripal_db_set_active('chado');
- $organism = db_fetch_object(db_query($o_sql, $node->genus,$node->species));
- tripal_db_set_active($previous_db);
-
- if(!$organism){
-
- $sql = "INSERT INTO {organism} ".
- " (abbreviation, genus, species,common_name,comment) VALUES ".
- " ('%s','%s','%s','%s','%s')";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql,$node->abbreviation, $node->genus,
- $node->species,$node->common_name,$node->description);
-
- $organism = db_fetch_object(db_query($o_sql, $node->genus,$node->species));
- tripal_db_set_active($previous_db);
- }
-
-
- $node_check_sql = "SELECT * FROM {chado_organism} ".
- "WHERE organism_id = %d";
- $node_check = db_fetch_object(db_query($node_check_sql,
- $organism->organism_id));
- if(!$node_check){
-
- $sql = "INSERT INTO {chado_organism} (nid, vid, organism_id) ".
- "VALUES (%d, %d, %d)";
- db_query($sql,$node->nid,$node->vid,$organism->organism_id);
- }
- $record = new stdClass();
- $record->title = "$node->genus $node->species";
- $record->nid = $node->nid;
- drupal_write_record('node',$record,'nid');
- drupal_write_record('node_revisions',$record,'nid');
- }
- function chado_organism_delete($node){
-
-
- $sql_drupal = "SELECT organism_id ".
- "FROM {chado_organism} ".
- "WHERE nid = %d ".
- "AND vid = %d";
- $organism_id = db_result(db_query($sql_drupal, $node->nid, $node->vid));
-
- $sql_del = "DELETE FROM {chado_organism} ".
- "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);
-
-
- $sql = "SELECT feature_id FROM {feature} WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $check_feature = db_result(db_query($sql, $organism_id));
- $sql = "SELECT library_id FROM {library} WHERE organism_id = %d";
- $check_lib = db_result(db_query($sql, $organism_id));
- if ($check_lib == 0 && $check_feature == 0) {
-
-
- db_query("DELETE FROM {organism} WHERE organism_id = %d", $organism_id);
- db_query("DELETE FROM {organism_dbxref} WHERE organism_id = %d",
- $organism_id);
- db_query("DELETE FROM {organismprop} WHERE organism_id = %d",
- $organism_id);
- } else {
- drupal_set_message("Organism deleted from drupal. Warning: at least one ".
- "library or feature depends on this organism. It was ".
- "not removed from chado.");
- }
- tripal_db_set_active($previous_db);
- }
- function chado_organism_validate($node){
-
-
- if (isset($_FILES['files']) && $_FILES['files']['name']['organism-image'] &&
- is_uploaded_file($_FILES['files']['tmp_name']['organism-image'])) {
- $dest = file_directory_path() . "/tripal/tripal_organism/images";
- $validators = array(
- 'file_validate_is_image' => array(),
- );
- file_check_directory($dest,FILE_CREATE_DIRECTORY,'organism-image');
- if(!$file = file_save_upload('organism-image',$validators,$dest)){
- drupal_set_message("Organism image was not uploaded.");
- }
-
- file_move($file->filepath,$dest . "/".$node->genus."_".$node->species.".jpg",FILE_EXISTS_REPLACE);
- }
- }
- function chado_organism_update($node){
- if($node->revision){
-
- } else {
-
- $sql = "SELECT organism_id ".
- "FROM {chado_organism} ".
- "WHERE nid = %d";
- $org = db_fetch_object(db_query($sql, $node->nid));
- $sql = "UPDATE {organism} ".
- " SET comment = '%s', ".
- " abbreviation = '%s', ".
- " genus = '%s', ".
- " species = '%s', ".
- " common_name = '%s' ".
- "WHERE organism_id = %d ";
- $previous_db = tripal_db_set_active('chado');
- db_query($sql,$node->description, $node->abbreviation, $node->genus,
- $node->species,$node->common_name,$org->organism_id);
- tripal_db_set_active($previous_db);
-
-
- $record = new stdClass();
- $record->title = "$node->genus $node->species";
- $record->nid = $node->nid;
- drupal_write_record('node',$record,'nid');
- drupal_write_record('node_revisions',$record,'nid');
- }
- }
- function chado_organism_form ($node, $param){
- $type = node_get_types('type',$node);
- $form = array();
- $form['#attributes']['enctype'] = 'multipart/form-data';
- $form['abbreviation']= array(
- '#type' => 'textfield',
- '#title' => t('Abbreviation'),
- '#required' => TRUE,
- '#default_value' => $node->abbreviation,
- '#weight' => 3
- );
- $form['genus']= array(
- '#type' => 'textfield',
- '#title' => t('Genus'),
- '#required' => TRUE,
- '#default_value' => $node->genus,
- '#weight' => 1
- );
- $form['species']= array(
- '#type' => 'textfield',
- '#title' => t('Species'),
- '#required' => TRUE,
- '#default_value' => $node->species,
- '#weight' => 2
- );
- $form['common_name']= array(
- '#type' => 'textfield',
- '#title' => t('Common Name'),
- '#required' => TRUE,
- '#default_value' => $node->common_name,
- '#weight' => 4
- );
- $form['description']= array(
- '#type' => 'textarea',
- '#rows' => 15,
- '#title' => t('Description'),
- '#required' => TRUE,
- '#default_value' => check_plain($node->description),
- '#weight' => 5
- );
- $form['organism-image']= array(
- '#type' => 'file',
- '#title' => t('Organism Image'),
- '#description' => 'Add an image for this organism',
- '#weight' => 6
- );
- return $form;
- }
- function chado_organism_load($node){
-
- $sql = "SELECT organism_id FROM {chado_organism} WHERE vid = %d";
- $org_node = db_fetch_object(db_query($sql, $node->vid));
- $previous_db = tripal_db_set_active('chado');
-
- if ($org_node->organism_id) {
- $sql = "SELECT O.organism_id,O.genus,O.species, ".
- " O.common_name, O.comment as description, O.abbreviation ".
- "FROM {Organism} O ".
- "WHERE O.Organism_id = $org_node->organism_id";
- $organism = db_fetch_object(db_query($sql));
- $additions->organism_id = $org_node->organism_id;
- }
- $additions->abbreviation = $organism->abbreviation;
- $additions->genus = $organism->genus;
- $additions->species = $organism->species;
- $additions->common_name = $organism->common_name;
- $additions->description = $organism->description;
- tripal_db_set_active($previous_db);
- return $additions;
- }
- function chado_organism_view ($node, $teaser = FALSE, $page = FALSE) {
-
- $node = node_prepare($node, $teaser);
- return $node;
- }
- function tripal_organism_sync_organisms ($organism_id = NULL, $job_id = NULL){
- global $user;
- $page_content = '';
- if(!$organism_id){
- $sql = "SELECT * FROM {Organism} O";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
- } else {
- $sql = "SELECT * FROM {Organism} L WHERE organism_id = %d";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql,$organism_id);
- tripal_db_set_active($previous_db);
- }
-
-
- $sql = "SELECT * FROM {chado_organism} ".
- "WHERE organism_id = %d";
- while($organism = db_fetch_object($results)){
-
-
- if(!db_fetch_object(db_query($sql,$organism->organism_id))){
- $new_node = new stdClass();
- $new_node->type = 'chado_organism';
- $new_node->uid = $user->uid;
- $new_node->title = "$organism->genus $organism->species";
- $new_node->organism_id = $organism->organism_id;
- $new_node->genus = $organism->genus;
- $new_node->species = $organism->species;
- $new_node->description = '';
- node_validate($new_node);
- if(!form_get_errors()){
- $node = node_submit($new_node);
- node_save($node);
- if($node->nid){
- $page_content .= "Added $organism->common_name<br>";
- }
- }
- } else {
- $page_content .= "Skipped $organism->common_name<br>";
- }
- }
- return $page_content;
- }
- function tripal_organism_help($path, $arg) {
- $output = '';
- switch ($path) {
- case "admin/help#tripal_organism":
- $output = '<p>'.
- t("Displays links to nodes created on this date").
- '</p>';
- break;
- }
- return $output;
- }
- function tripal_organism_show_organisms (){
-
- $sql = "SELECT COUNT(organism_id) FROM {chado_organism}";
- $no_orgs = db_result(db_query ($sql));
- if($no_orgs != 0) {
- $organisms = get_chado_organisms ();
- return theme('tripal_organism_organism_page', $organisms);
- } else {
- return t("No organism exists. Please contact administrators to ".
- "synchronize organisms.");
- }
- }
- function theme_tripal_organism_organism_page($organisms) {
- $output = "<br><a id=\"tripal_expandableBox_toggle_button\" onClick=\"toggleExpandableBoxes()\">[-] Collapse All</a>";
- foreach($organisms as $organism){
-
- $org_url = url("node/$organism->node_id");
-
-
- $output .= "<div class=\"tripal_chado_organism-info-box\" style=\"padding:5px\">
- <div class=\"tripal_expandableBox\">
- <h3>$organism->common_name</h3>
- </div>
- <div class=\"tripal_expandableBoxContent\">
- <span>
- <table class=\"tripal_chado_analysis_content\">
- <tr><td>
- Name: <a href=\"$org_url\">$organism->common_name</a>
- </td></tr>
- <tr><td>
- Genus: $organism->genus
- </td></tr>
- <tr><td>
- Species: $organism->species
- </td></tr>
- <tr><td>
- Description: $organism->comment
- </td></tr>
- </table>
- </span>
- </div>
- </div>";
- }
- return $output;
- }
- function get_chado_organisms() {
- $sql_drupal = "SELECT COUNT (organism_id) FROM {chado_organism}";
- $no_orgs = db_result(db_query($sql_drupal));
- if ($no_orgs != 0) {
- $sql = "SELECT organism_id, nid FROM {chado_organism}";
- $result = db_query($sql);
- $previous_db = tripal_db_set_active('chado');
- $sql = "SELECT genus, species, common_name, comment ".
- "FROM {Organism} ".
- "WHERE organism_id=%d";
- $organisms = array();
- $count = 0;
- while ($data = db_fetch_object($result)) {
- $organism = db_fetch_object(db_query($sql, $data->organism_id));
- $organism->node_id = $data->nid;
-
-
-
- $key = strtolower($organism->common_name).$count;
- $organisms [$key] = $organism;
- $count ++;
- }
- tripal_db_set_active($previous_db);
-
- ksort($organisms, SORT_STRING);
- return $organisms;
- }
- }
- function tripal_organism_reindex_features ($organism_id = NULL, $job_id = NULL){
- $i = 0;
- if(!$organism_id){
- return;
- }
- $sql = "SELECT * ".
- "FROM {feature} ".
- "WHERE organism_id = $organism_id ".
- "ORDER BY feature_id";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $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){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- tripal_feature_sync_feature ($feature_id);
- $i++;
- }
- }
- function tripal_organism_taxonify_features ($organism_id = NULL, $job_id = NULL){
- $i = 0;
- if(!$organism_id){
- return;
- }
- $sql = "SELECT * ".
- "FROM {feature} ".
- "WHERE organism_id = $organism_id ".
- "ORDER BY feature_id";
- $previous_db = tripal_db_set_active('chado');
- $results = db_query($sql);
- tripal_db_set_active($previous_db);
-
- $count = 0;
- $ids = array();
- while($id = db_fetch_object($results)){
- $ids[$count] = $id->feature_id;
- $count++;
- }
-
- tripal_feature_set_vocabulary();
-
- $nsql = "SELECT * FROM {chado_feature} CF ".
- " INNER JOIN {node} N ON N.nid = CF.nid ".
- "WHERE feature_id = %d";
-
- $interval = intval($count * 0.01);
- foreach($ids as $feature_id){
-
- 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++;
- }
- }
- function tripal_organism_get_synced() {
-
- $dsql = "SELECT * FROM {chado_organism}";
- $orgs = db_query($dsql);
-
- $csql = "SELECT * FROM {Organism} ".
- "WHERE organism_id = %d";
- $org_list = array();
-
- while($org = db_fetch_object($orgs)){
- $previous_db = tripal_db_set_active('chado');
- $info = db_fetch_object(db_query($csql,$org->organism_id));
- tripal_db_set_active($previous_db);
- $org_list[] = $info;
- }
- return $org_list;
- }
- function tripal_organisms_cleanup($dummy = NULL, $job_id = NULL) {
-
- $dsql = "SELECT * FROM {node} WHERE type = 'chado_organism' order by nid";
- $nsql = "SELECT * FROM {node} WHERE nid = %d";
- $csql = "SELECT * FROM {chado_organism} where nid = %d ";
- $cosql= "SELECT * FROM {chado_organism}";
- $tsql = "SELECT * FROM {Organism} O ".
- "WHERE organism_id = %d";
-
- $results = db_query($dsql);
- $count = 0;
- $nodes = array();
- while($node = db_fetch_object($results)){
- $nodes[$count] = $node;
- $count++;
- }
-
- $results = db_query($cosql);
- $cnodes = array();
- while($node = db_fetch_object($results)){
- $cnodes[$count] = $node;
- $count++;
- }
- $interval = intval($count * 0.01);
-
- foreach($nodes as $nid){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
-
-
- $organism = db_fetch_object(db_query($csql,$nid->nid));
- if(!$organism){
- node_delete($nid->nid);
- $message = "Missing in chado_organism table.... DELETING: $nid->nid\n";
- watchdog('tripal_organism',$message,array(),WATCHDOG_WARNING);
- continue;
- }
- $i++;
- }
-
- foreach($cnodes as $nid){
-
- if($job_id and $i % $interval == 0){
- tripal_job_set_progress($job_id,intval(($i/$count)*100));
- }
- $node = db_fetch_object(db_query($nsql,$nid->nid));
- if(!$node){
- db_query("DELETE FROM {chado_organism} WHERE nid = $nid->nid");
- $message = "chado_organism missing node.... DELETING: $nid->nid\n";
- watchdog('tripal_organism',$message,array(),WATCHDOG_WARNING);
- }
- $i++;
- }
- return '';
- }
-
- function tripal_organism_views_api() {
- return array(
- 'api' => 2.0,
- );
- }
|