Tripal v1.0 (6.x-1.0)
Analysis Module

Functions

 tripal_analysis_register_child ($modulename)
 tripal_analysis_unregister_child ($modulename)
 tripal_analysis_admin ()
 get_tripal_analysis_admin_form_taxonomy_set (&$form)
 get_tripal_analysis_admin_form_reindex_set (&$form)
 get_tripal_analysis_admin_form_cleanup_set (&$form)
 get_tripal_analysis_admin_form_sync_set (&$form)
 tripal_analysis_admin_validate ($form, &$form_state)
 tripal_analysis_sync_analyses ($analysis_id=NULL, $job_id=NULL)
 tripal_analyses_cleanup ($dummy=NULL, $job_id=NULL)
 tripal_analysis_init ()
 tripal_analysis_menu ()
 tripal_analysis_node_info ()
 chado_analysis_insert ($node)
 chado_analysis_delete ($node)
 chado_analysis_update ($node)
 chado_analysis_form ($node)
 chado_analysis_load ($node)
 chado_analysis_view ($node, $teaser=FALSE, $page=FALSE)
 chado_analysis_validate ($node, &$form)
 tripal_analysis_validate ($node, &$form)
 tripal_analysis_help ($path, $arg)
 chado_analysis_access ($op, $node, $account)
 tripal_analysis_perm ()
 tripal_analysis_theme ()
 tripal_analysis_views_api ()

Detailed Description

Provides functions for managing chado analysis' including creating details pages for each one


Function Documentation

chado_analysis_access ( op,
node,
account 
)

The following function proves access control for users trying to perform actions on data managed by this module

Definition at line 590 of file tripal_analysis.module.

                                                     {

  if ($op == 'create') {
    if (!user_access('create chado_analysis content', $account)) {
      return FALSE;
      }
  }
  if ($op == 'update') {
    if (!user_access('edit chado_analysis content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'delete') {
    if (!user_access('delete chado_analysis content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'view') {
    if (!user_access('access chado_analysis content', $account)) {
      return FALSE;
      }
  }
    return NULL;
}
chado_analysis_delete ( node)

Removes analysis from the chado database

Parameters:
$nodeThe node object specifying which chado record to delete

Definition at line 176 of file tripal_analysis.module.

                                      {
  $analysis_id = chado_get_id_for_node('analysis', $node);
  
  // if we don't have an organism id for this node then this isn't a node of
  // type chado_organism or the entry in the chado_organism table was lost.
  if (!$analysis_id) {
    return;
  }

  // Remove data from the {chado_analysis}, {node}, and {node_revisions} tables
  $sql_del = "DELETE FROM {chado_analysis} ".
              "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 from analysis and analysisprop tables of chado database as well
  chado_query("DELETE FROM {analysis} WHERE analysis_id = %d", $analysis_id);
}
chado_analysis_form ( node)

When editing or creating a new node of type 'chado_analysis' we need a form. This function creates the form that will be used for this.

Definition at line 269 of file tripal_analysis.module.

                                    {

  $analysis = $node->analysis;

  // add in the description column. It is a text field and may not be included
  // if the text is too big.
  $analysis = tripal_core_expand_chado_vars($analysis, 'field', 'analysis.description');

  // get form defaults
  $analysis_id = $node->analysis_id;
  if (!$analysis_id) {
    $analysis_id = $analysis->analysis_id;
  }
  $analysisname = $node->analysisname;
  if (!$analysisname) {
    $analysisname = $analysis->name;
  }
  $program = $node->program;
  if (!$program) {
    $program = $analysis->program;
  }
  $programversion = $node->programversion;
  if (!$programversion) {
    $programversion = $analysis->programversion;
  }
  $algorithm = $node->algorithm;
  if (!$algorithm) {
    $algorithm = $analysis->algorithm;
  }
  $sourcename = $node->sourcename;
  if (!$sourcename) {
    $sourcename = $analysis->sourcename;
  }
  $sourceversion = $node->sourceversion;
  if (!$sourceversion) {
    $sourceversion = $analysis->sourceversion;
  }
  $sourceuri = $node->sourceuri;
  if (!$sourceuri) {
    $sourceuri = $analysis->sourceuri;
  }
  $timeexecuted = $node->timeexecuted;
  if (!$timeexecuted) {
    $timeexecuted = $analysis->timeexecuted;
  }
  $description = $node->description;
  if (!$description) {
    $description = $analysis->description;
  }
  $form = array();
  $form['title']= array(
      '#type' => 'hidden',
      '#default_value' => $node->title,
  );
  $form['analysis_id']= array(
      '#type' => 'hidden',
      '#default_value' => $analysis_id,
  );
  $form['analysisname']= array(
      '#type' => 'textfield',
      '#title' => t('Analysis Name'),
      '#required' => TRUE,
      '#default_value' => $analysisname,
      '#description' => t("This should be a brief name that
         describes the analysis succintly. This name will helps the user find analyses."),
  );
  $form['program']= array(
      '#type' => 'textfield',
      '#title' => t('Program'),
      '#required' => TRUE,
      '#default_value' => $program,
      '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan."),
  );
  $form['programversion']= array(
      '#type' => 'textfield',
      '#title' => t('Program Version'),
      '#required' => TRUE,
      '#default_value' => $programversion,
      '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter 'n/a' if no version is available."),
  );
  $form['algorithm']= array(
      '#type' => 'textfield',
      '#title' => t('Algorithm'),
      '#required' => FALSE,
      '#default_value' => $algorithm,
      '#description' => t("Algorithm name, e.g. blast."),
  );
  $form['sourcename']= array(
      '#type' => 'textfield',
      '#title' => t('Source Name'),
      '#required' => TRUE,
      '#default_value' => $sourcename,
      '#description' => t('The name of the source data.  This could be a file name, data set name or a
           small description for how the data was collected.  For long descriptions use the description field below'),

  );
  $form['sourceversion']= array(
      '#type' => 'textfield',
      '#title' => t('Source Version'),
      '#required' => FALSE,
      '#default_value' => $sourceversion,
      '#description' => t('If the source dataset has a version, include it here'),
  );
  $form['sourceuri']= array(
      '#type' => 'textfield',
      '#title' => t('Source URI'),
      '#required' => FALSE,
      '#default_value' => $sourceuri,
      '#description' => t("This is a permanent URL or URI for the source of the analysis.
         Someone could recreate the analysis directly by going to this URI and
         fetching the source data (e.g. the blast database, or the training model)."),
  );
  // Get time saved in chado
  $default_time = $timeexecuted;
  $year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
  $month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
  $day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
  // If the time is not set, use current time
  if (!$default_time) {
    $default_time = time();
    $year = format_date($default_time, 'custom', 'Y');
    $month = format_date($default_time, 'custom', 'n');
    $day = format_date($default_time, 'custom', 'j');
  }
  $form['timeexecuted']= array(
      '#type' => 'date',
      '#title' => t('Time Executed'),
      '#required' => TRUE,
      '#default_value' => array(
         'year' => $year,
         'month' => $month,
         'day' => $day,
      ),
  );
  $form['description']= array(
      '#type' => 'textarea',
      '#rows' => 15,
      '#title' => t('Materials & Methods (Description and/or Program Settings)'),
      '#required' => FALSE,
      '#default_value' => $description,
      '#description' => t('Please provide all necessary information to allow
         someone to recreate the analysis, including materials and methods
         for collection of the source data and performing the analysis'),
  );

  return $form;
}
chado_analysis_insert ( node)

When a new chado_analysis node is created we also need to add information to our chado_analysis table. This function is called on insert of a new node of type 'chado_analysis' and inserts the necessary information.

Definition at line 95 of file tripal_analysis.module.

                                      {
  global $user;

  // Create a timestamp so we can insert it into the chado database
  $time = $node->timeexecuted;
  $month = $time['month'];
  $day = $time['day'];
  $year = $time['year'];
  $timestamp = $month . '/' . $day . '/' . $year;

  // If this analysis already exists then don't recreate it in chado
  $analysis_id = $node->analysis_id;
  if ($analysis_id) {
    $values = array('analysis_id' => $node->analysis_id);
    $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
    if($result and count($result) > 0) {
      $analysis = $result[0];
    }
  }
  
  // If the analysis doesn't exist then let's create it in chado.
  if (!$analysis) {
      // insert and then get the newly inserted analysis record
      $values = array(
          'name' => $node->analysisname,
          'description' => $node->description,
          'program' => $node->program,
          'programversion' => $node->programversion,
          'algorithm' => $node->algorithm,
          'sourcename' => $node->sourcename,
          'sourceversion' => $node->sourceversion,
          'sourceuri' => $node->sourceuri,
          'timeexecuted' => $timestamp
      );
      if (tripal_core_chado_insert('analysis', $values)) {
        $analysis = tripal_core_chado_select('analysis', array('*'), $values);
        $analysis_id = $analysis[0]->analysis_id;
      }
  }

  // Make sure the entry for this analysis doesn't already exist in the
  // chado_analysis table if it doesn't exist then we want to add it.
  $node_check_sql = "SELECT * FROM {chado_analysis} ".
                     "WHERE analysis_id = %d";
  $node_check = db_fetch_object(db_query($node_check_sql, $analysis_id));
  if (!$node_check) {
    // next add the item to the drupal table
    $sql = "INSERT INTO {chado_analysis} (nid, vid, analysis_id) ".
             "VALUES (%d, %d, %d)";
    db_query($sql, $node->nid, $node->vid, $analysis_id);
    // Create a title for the analysis node using the unique keys so when the
    // node is saved, it will have a title
    $record = new stdClass();
    // If the analysis has a name, use it as the node title. If not, construct
    // the title using program, programversion, and sourcename
    if ($node->analysisname) {
      $record->title = $node->analysisname;
    }
    else {
      //Construct node title as "program (version)
      $record->title = "$node->program ($node->programversion)";
    }
    $record->nid = $node->nid;
    drupal_write_record('node', $record, 'nid');
    drupal_write_record('node_revisions', $record, 'nid');
  }

   // add the analysis to the node object for
   // use by other analysis modules that may be using this function
    $node->analysis = $analysis;
    $node->analysis_id = $analysis_id; // we need to set this for children
}
chado_analysis_load ( node)

When a node is requested by the user this function is called to allow us to add auxiliary data to the node object.

Definition at line 423 of file tripal_analysis.module.

                                    {

   // get the feature details from chado
  $analysis_id = chado_get_id_for_node('analysis', $node);

  $values = array('analysis_id' => $analysis_id);
  $analysis = tripal_core_generate_chado_var('analysis', $values);

  $additions = new stdClass();
  $additions->analysis = $analysis;
  return $additions;
}
chado_analysis_update ( node)

Update analyses

Parameters:
$nodeThe updated node object

Definition at line 211 of file tripal_analysis.module.

                                      {
  global $user;
  if ($node->revision) {
    // TODO -- decide what to do about revisions
  }
  // Create a timestamp so we can insert it into the chado database
  $time = $node->timeexecuted;
  $month = $time['month'];
  $day = $time['day'];
  $year = $time['year'];
  $timestamp = $month . '/' . $day . '/' . $year;

  // get the analysis_id for this node:
  $sql = "SELECT analysis_id ".
           "FROM {chado_analysis} ".
           "WHERE nid = %d";
  $analysis_id = db_fetch_object(db_query($sql, $node->nid))->analysis_id;

  $sql = "UPDATE {analysis} ".
           "SET name = '%s', ".
           "    description = '%s', ".
           "    program = '%s', ".
           "    programversion = '%s', ".
           "    algorithm = '%s', ".
           "    sourcename = '%s', ".
           "    sourceversion = '%s', ".
           "    sourceuri = '%s', ".
           "    timeexecuted = '%s' ".
           "WHERE analysis_id = %d ";

  chado_query($sql, $node->analysisname, $node->description, $node->program,
    $node->programversion, $node->algorithm, $node->sourcename,
    $node->sourceversion, $node->sourceuri, $timestamp, $analysis_id);

  // Create a title for the analysis node using the unique keys so when the
  // node is saved, it will have a title
  $record = new stdClass();
  // If the analysis has a name, use it as the node title. If not, construct
  // the title using program, programversion, and sourcename
  if ($node->analysisname) {
    $record->title = $node->analysisname;
  }
  else {
    //Construct node title as "program (version)
    $record->title = "$node->program ($node->programversion)";
  }

  $record->nid = $node->nid;
  drupal_write_record('node', $record, 'nid');
  drupal_write_record('node_revisions', $record, 'nid');
}
chado_analysis_validate ( node,
&$  form 
)

Validates the user input before creating an analysis node

Definition at line 467 of file tripal_analysis.module.

                                                {
   // use the analysis parent to validate the node
  tripal_analysis_validate($node, $form);
}
chado_analysis_view ( node,
teaser = FALSE,
page = FALSE 
)

This function customizes the view of the chado_analysis node. It allows us to generate the markup.

Definition at line 442 of file tripal_analysis.module.

                                                                    {
  // use drupal's default node view:
  if (!$teaser) {
    $node = node_prepare($node, $teaser);
    // When previewing a node submitting form, it shows 'Array' instead of
    // correct date format. We need to format the date here
    $time = $node->timeexecuted;
    if (is_array($time)) {
      $month = $time['month'];
      $day = $time['day'];
      $year = $time['year'];
      $timestamp = $year . '-' . $month . '-' . $day;
      $node->timeexecuted = $timestamp;
    }
  }
  return $node;
}
get_tripal_analysis_admin_form_cleanup_set ( &$  form)

The "Clean-up orphaned analysis & nodes" Form

Parameters:
$formThe administrative form as it is currently
Returns:
A form API array describing an administrative form

Definition at line 198 of file tripal_analysis.admin.inc.

                                                            {
  $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 analyses in Chado become ".
          "\"orphaned\".  This can occur if an analysis node in Drupal is ".
          "deleted but the corresponding chado analysis 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 analyses'),
      '#weight' => 2,
  );
}
get_tripal_analysis_admin_form_reindex_set ( &$  form)

The "Reindex Analysis Nodes" form

Parameters:
$formThe administrative form as it is currently
Returns:
A form API array describing an administrative form

Definition at line 148 of file tripal_analysis.admin.inc.

                                                            {
  // define the fieldsets
  $form['reindex'] = array(
      '#type' => 'fieldset',
      '#title' => t('Reindex Analysis Features')
  );

  // get the list of libraries
  $sql = "SELECT * FROM {analysis} ORDER BY name";
  $lib_rset = chado_query($sql);

  // iterate through all of the libraries
  $lib_boxes = array();
  while ($analysis = db_fetch_object($lib_rset)) {
    $lib_boxes[$analysis->analysis_id] = "$analysis->name";
  }
  $form['reindex']['description'] = array(
       '#type' => 'item',
       '#value' => t("This option allows for reindexing of only those features that belong to the selected analyses below. All other features will be unaffected.  To reindex all features in the site see the Feature Administration page."),
     '#weight' => 1,
  );

  $form['reindex']['re-analyses'] = array(
     '#title'       => t('Libraries'),
     '#type'        => t('checkboxes'),
     '#description' => t("Check the analyses whoee features you want to reindex. Note: this list contains all analyses, 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,
  );
}
get_tripal_analysis_admin_form_sync_set ( &$  form)

The "sync Analysis in chado with drupal" form

Parameters:
$formThe administrative form as it is currently
Returns:
A form API array describing an administrative form

Definition at line 230 of file tripal_analysis.admin.inc.

                                                         {
  // define the fieldsets
  $form['sync'] = array(
      '#type' => 'fieldset',
      '#title' => t('Sync Analyses')
  );

  // before proceeding check to see if we have any
  // currently processing jobs. If so, we don't want
  // to give the opportunity to sync analyses
  $active_jobs = FALSE;
  if (tripal_get_module_active_jobs('tripal_analysis')) {
    $active_jobs = TRUE;
  }

  if (!$active_jobs) {

    // get the list of analyses
    $sql = "SELECT * FROM {analysis} ORDER BY name";
    $ana_rset = chado_query($sql);

    // if we've added any analyses 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 analyses are currently synced.
    $ana_boxes = array();
    $added = 0;
    while ($analysis = db_fetch_object($ana_rset)) {
      // check to see if the analysis is already present as a node in drupal.
      // if so, then skip it.
      $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = %d";
      if (!db_fetch_object(db_query($sql, $analysis->analysis_id))) {
        $ana_boxes[$analysis->analysis_id] = "$analysis->name";
        $added++;
      }
    }

    // if we have analyses we need to add to the checkbox then
    // build that form element
    if ($added > 0) {
      $ana_boxes['all'] = "All analyses";

      $form['sync']['analyses'] = array(
           '#title'       => t('Available analyses'),
           '#type'        => t('checkboxes'),
           '#description' => t("Check the analyses you want to sync.  Drupal ".
              "content will be created for each of the analyses listed above. ".
              "Select 'All analyses' to sync all of them."),
           '#required'    => FALSE,
           '#prefix'      => '<div id="ana_boxes">',
           '#suffix'      => '</div>',
           '#options'     => $ana_boxes,
      );
      $form['sync']['button'] = array(
            '#type' => 'submit',
            '#value' => t('Submit Sync Job')
      );
    }
    // we don't have any analyses to select from
    else {
      $form['sync']['value'] = array(
            '#value' => t('All analyses in Chado are currently synced with Drupal.')
      );
    }
  }
  // we don't want to present a form since we have an active job running
  else {
    $form['sync']['value'] = array(
          '#value' => t('Currently, jobs exist related to chado analyses. Please check back later for analyses that can by synced once these jobs have finished.  You can view the status of pending jobs in the Tripal jobs page.')
    );
  }
}
get_tripal_analysis_admin_form_taxonomy_set ( &$  form)

Displays the Set Drupal Taxonomy for Analysis Features From

Parameters:
$formThe administrative form as it is currently
Returns:
A form API array describing an administrative form

Definition at line 96 of file tripal_analysis.admin.inc.

                                                             {
  $form['taxonify'] = array(
      '#type' => 'fieldset',
      '#title' => t('Assign Drupal Taxonomy to Analysis Features')
  );

  // get the list of analyses
  $sql = "SELECT * FROM {analysis} ORDER BY name";
  $lib_rset = chado_query($sql);

  // iterate through all of the libraries
  $lib_boxes = array();
  while ($analysis = db_fetch_object($lib_rset)) {
    $lib_boxes[$analysis->analysis_id] = "$analysis->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 analyses 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-analyses'] = array(
     '#title'       => t('Analyses'),
     '#type'        => t('checkboxes'),
     '#description' => t("Check the analyses whose features you want to reset taxonomy.  Note: this list contains all analyses, 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
  );
}
tripal_analyses_cleanup ( dummy = NULL,
job_id = NULL 
)

Remove orphaned drupal nodes

Parameters:
$dummyNot Used -kept for backwards compatibility
$job_idThe id of the tripal job executing this function

Definition at line 532 of file tripal_analysis.admin.inc.

                                                                {

  return tripal_core_clean_orphaned_nodes('analysis', $job_id);
  
}
tripal_analysis_admin ( )

Administration page callbacks for the Tripal Analysis module

We have defined a hook_get_settings() function. When a sub-module is enabled, we'll look for this function to provide a form for the administrative setting.

Returns:
A form API array describing an administrative form

Definition at line 21 of file tripal_analysis.admin.inc.

                                 {
  // Create a new administrative form. We'll add main functions to the form
  // first (Sync, Reindex, Clean, Taxonify). Thereafter, any sub-module that
  // has a setting will be added.
  $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_organism')) {
    $active_jobs = TRUE;
  }

  // add the field set for syncing libraries
  if (!$active_jobs) {
    // add the field set for syncing analyses
    get_tripal_analysis_admin_form_sync_set($form);
//    get_tripal_analysis_admin_form_reindex_set($form);
//    get_tripal_analysis_admin_form_taxonomy_set($form);
    get_tripal_analysis_admin_form_cleanup_set($form);
  }
  else {
    $form['notice'] = array(
       '#type' => 'fieldset',
       '#title' => t('Analysis Management Temporarily Unavailable')
    );
    $form['notice']['message'] = array(
          '#value' => t('Currently, analysis 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.'),
    );
  }

  // Add sub-module settings. Pull all sub-module information from
  // {tripal_analysis} table
  $sql = "SELECT modulename FROM {tripal_analysis}";
  $result = db_query($sql);
  $counter = 0;  //keep track of the number of sub-modules
  while ($data = db_fetch_object($result)) {

    // Check if the hook_get_settings() function is already defined.
    $func = $data->modulename . "_get_settings";
    $functions = get_defined_functions();
    $settings;
    foreach ($functions['user'] as $function) {
      if ($function == $func) {
        $settings = $func();
      }
    }

    // Add sub-module's specific settings to the administrative view
    if ($settings) {
      // Define a fieldset for the sub-module
      $form["field$counter"] = array(
            '#type' => 'fieldset',
            '#title' => "$settings->title",
            '#collapsible' => TRUE
      );
      $form["field$counter"]["$settings->title"] = $settings->form;
    }
    $counter ++;
  }
  return system_settings_form($form);
}
tripal_analysis_admin_validate ( form,
&$  form_state 
)

Validate the administrative form

Parameters:
$formThe form API array of the form to be validated The user submitted values

Definition at line 314 of file tripal_analysis.admin.inc.

                                                             {
  global $user;  // we need access to the user info
  $job_args = array();

  if ($form_state['values']['op'] == t('Submit Sync Job')) {

    // 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
    $analyses = $form_state['values']['analyses'];
    $do_all = FALSE;
    $to_sync = array();

    foreach ($analyses as $analysis_id) {
      if (preg_match("/^all$/i", $analysis_id)) {
        $do_all = TRUE;
      }
      if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
        // get the list of analyses
        $sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
        $analysis = db_fetch_object(chado_query($sql, $analysis_id));
        $to_sync[$analysis_id] = $analysis->name;
      }
    }

    // submit the job the tripal job manager
    if ($do_all) {
      tripal_add_job('Sync all analyses', 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
    }
    else{
      foreach ($to_sync as $analysis_id => $name) {
        $job_args[0] = $analysis_id;
        tripal_add_job("Sync analysis: $name", 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid);
      }
    }
  }
  // -------------------------------------
  // Submit the Reindex Job if selected
  if ($form_state['values']['op'] == t('Reindex Features')) {
    global $user;  // we need access to the user info
    $job_args = array();
    $analyses = $form_state['values']['re-analyses'];
    foreach ($analyses as $analysis_id) {
      if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
        // get the analysis info
        $sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
        $analysis = db_fetch_object(chado_query($sql, $analysis_id));
        $job_args[0] = $analysis_id;
        tripal_add_job("Reindex features for analysis: $analysis->name", 'tripal_analysis',
             'tripal_analysis_reindex_features', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the Taxonomy Job if selected
  if ($form_state['values']['op'] == t('Set Feature Taxonomy')) {
    global $user;  // we need access to the user info
    $job_args = array();
    $analyses = $form_state['values']['tx-analyses'];
    foreach ($analyses as $analysis_id) {
      if ($analysis_id and preg_match("/^\d+$/i", $analysis_id)) {
        // get the analysis info
        $sql = "SELECT * FROM {analysis} WHERE analysis_id = %d";
        $analysis = db_fetch_object(chado_query($sql, $analysis_id));
        $job_args[0] = $analysis_id;
        tripal_add_job("Set taxonomy for features in analysis: $analysis->name", 'tripal_analysis',
             'tripal_analysis_taxonify_features', $job_args, $user->uid);
      }
    }
  }

  // -------------------------------------
  // Submit the Cleanup Job if selected
  if ($form_state['values']['op'] == t('Clean up orphaned analyses')) {
    tripal_add_job('Cleanup orphaned analyses', 'tripal_analysis',
         'tripal_analyses_cleanup', $job_args, $user->uid);
  }
}
tripal_analysis_help ( path,
arg 
)

Display help and module information

Parameters:
pathwhich path of the site we're displaying help
argarray that holds the current path as would be returned from arg() function
Returns:
help text for the path

Definition at line 572 of file tripal_analysis.module.

                                           {
  $output = '';
  switch ($path) {
    case "admin/help#tripal_analysis":
      $output = '<p>' .
      t("Displays links to nodes created on this date") .
                '</p>';
      break;
  }
  return $output;
}
tripal_analysis_init ( )

Add tripal javascript to page headers

Definition at line 26 of file tripal_analysis.module.

                                {
  drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_analysis.js');
}
tripal_analysis_menu ( )

Implementation of hook_menu(). Entry points and paths of the module

Definition at line 36 of file tripal_analysis.module.

                                {
  //Sync analysis
  $items['chado_sync_analyses'] = array(
     'title' => 'Sync Data',
     'page callback' => 'tripal_analysis_sync_analyses',
     'access arguments' => array('administer tripal analyses'),
     'type' => MENU_CALLBACK
  );
  // Tripal Analysis administrative settings
  $items['admin/tripal/tripal_analysis'] = array(
      'title' => 'Analyses',
      'description' => 'Basic Description of Tripal Analysis Module Functionality.',
      'page callback' => 'theme',
      'page arguments' => array('tripal_analysis_admin'),
      'access arguments' => array('administer tripal analyses'),
      'type' => MENU_NORMAL_ITEM,
      'file' => 'includes/tripal_analysis.admin.inc',
  );

  $items['admin/tripal/tripal_analysis/configuration'] = array(
      'title' => 'Configuration',
      'description' => 'Settings for the displays of analysis results.',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('tripal_analysis_admin'),
      'access arguments' => array('administer tripal analyses'),
      'type' => MENU_NORMAL_ITEM,
      'file' => 'includes/tripal_analysis.admin.inc',
  );
  return $items;
}
tripal_analysis_node_info ( )

Provide information to drupal about the node types that we're creating in this module

Definition at line 73 of file tripal_analysis.module.

                                     {
  $nodes = array();
  $nodes['chado_analysis'] = array(
      'name' => t('Analysis'),
      'module' => 'chado_analysis',
      'description' => t('An analysis from the chado database'),
      'has_title' => FALSE,
      'title_label' => t('Analysis'),
      'has_body' => FALSE,
      'body_label' => t('Analysis Description'),
      'locked' => TRUE
  );
  return $nodes;
}
tripal_analysis_perm ( )

Set the permission types that the chado module uses. Essentially we want permissionis that protect creation, editing and deleting of chado data objects

Definition at line 622 of file tripal_analysis.module.

                                {
  return array(
    'access chado_analysis content',
    'create chado_analysis content',
    'delete chado_analysis content',
    'edit chado_analysis content',
    'administer tripal analyses',
  );
}
tripal_analysis_register_child ( modulename)

Register tripal_analysis sub-modules

Parameters:
$modulenameThe name of the module to be registered as a tripal analysis submodule

Definition at line 18 of file tripal_analysis.api.inc.

                                                     {
  $sql = "SELECT * FROM {tripal_analysis} WHERE modulename = '%s'";
  if(!db_result($sql, $modulename)) {
    $sql = "INSERT INTO {tripal_analysis} (modulename) VALUES ('%s')";
    db_query($sql, $modulename);
  }
}
tripal_analysis_sync_analyses ( analysis_id = NULL,
job_id = NULL 
)

Synchronize analyses from chado to drupal

Definition at line 398 of file tripal_analysis.admin.inc.

                                                                            {
  global $user;
  $page_content = '';

  if (!$analysis_id) {
    $sql = "SELECT Analysis_id, name, description, program, ".
        "  programversion, algorithm, sourcename, sourceversion, sourceuri, ".
          "  timeexecuted ".
          "FROM {Analysis} ";
    $results = chado_query($sql);
  }
  else {
    $sql = "SELECT Analysis_id, name, description, program, ".
         "  programversion, algorithm, sourcename, sourceversion, sourceuri, ".
          "  timeexecuted ".
          "FROM {Analysis} ".
          "WHERE analysis_id = %d";
    $results = chado_query($sql, $analysis_id);
  }


  // We'll use the following SQL statement for checking if the analysis
  // already exists as a drupal node.
  $sql = "SELECT * FROM {chado_analysis} ".
          "WHERE analysis_id = %d";

  while ($analysis = db_fetch_object($results)) {
        print "syncing analysis ";
        print $analysis->name;
        print ", ";
        print $analysis->analysis_id;
        print "\n";

    // check if this analysis already exists in the drupal database. if it
    // does then skip this analysis and go to the next one.
    if (!db_fetch_object(db_query($sql, $analysis->analysis_id))) {

      $new_node = new stdClass();

      // try to access analysis type for this analysis
      $sql = "SELECT * FROM {analysisprop}
                    WHERE analysis_id = %d
                    AND type_id =
                        (SELECT cvterm_id from {cvterm} where name = '%s')
            ";
      $analysis_type = db_fetch_object(chado_query($sql, $analysis->analysis_id, "analysis_type"));

      // Get the type of analysis using cvterm_id
            // Current possibilities: kegg, unigene, interpro, blast
      if ($analysis_type) {

        // This is a unigene analysis
        if ($analysis_type->value == 'tripal_analysis_unigene') {
          $new_node->type = 'chado_analysis_unigene';
        // This is a blast analysis
        }
        elseif ($analysis_type->value == 'tripal_analysis_blast') {
          $new_node->type = 'chado_analysis_blast';
         // This is a interpro analysis
        }
        elseif ($analysis_type->value == 'tripal_analysis_interpro') {
          $new_node->type = 'chado_analysis_interpro';
         // This is a kegg analysis
        }
        elseif ($analysis_type->value == 'tripal_analysis_kegg' ) {
          $new_node->type = 'chado_analysis_kegg';
        }
        else {
          $new_node->type = 'chado_analysis';
        }
      // If it doesn't exist, this analysis is generic
      }
      else {
        $new_node->type = 'chado_analysis';
      }

      print "analysis type is $new_node->type\n";

      $new_node->uid = $user->uid;
      $new_node->analysis_id = $analysis->analysis_id;
      $new_node->analysisname = $analysis->name;
      $new_node->description = $analysis->description;
      $new_node->program = $analysis->program;
      $new_node->programversion = $analysis->programversion;
      $new_node->algorithm = $analysis->algorithm;
      $new_node->sourcename = $analysis->sourcename;
      $new_node->sourceversion = $analysis->sourceversion;
      $new_node->sourceuri = $analysis->sourceuri;
      $new_node->timeexecuted = $analysis->timeexecuted;

      // If the analysis has a name, use it as the node title. If not,
      // construct the title using program, programversion, and sourcename
      if ($new_node->analysisname) {
        $new_node->title = $new_node->analysisname;
      }
      else {
        //Construct node title as "program (version)"
        $new_node->title = "$analysis->program ($analysis->programversion)";
      }

      node_validate($new_node);

            $errors = form_get_errors();

            if ($errors) {
                print_r($errors);
            }
            else{
      // if(!form_get_errors()){
        $node = node_submit($new_node);
        node_save($node);

        if ($node->nid) {
          $page_content .= "Added $new_node->title<br />";
        }
      }
    }
    else {
      $page_content .= "Skipped $new_node->title<br />";
    }
  }
  return $page_content;
}
tripal_analysis_theme ( )

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

Definition at line 639 of file tripal_analysis.module.

                                 {
  return array(
    'tripal_analysis_base' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_analysis_base',
    ),
    'tripal_feature_analyses' => array(
      'template' => 'tripal_feature_analyses',  
      'arguments' =>  array('node' => NULL),  
    ),
    'tripal_analysis_admin' => array(
      'template' => 'tripal_analysis_admin',  
      'arguments' =>  array(NULL),  
      'path' => drupal_get_path('module', 'tripal_analysis') . '/theme', 
    ),
  );
}
tripal_analysis_unregister_child ( modulename)

Un-register a tripal analysis sub-module

Parameters:
$modulenameThe name of the module to un-register

Definition at line 34 of file tripal_analysis.api.inc.

                                                       {
  if (db_table_exists('tripal_analysis')) {
      $sql = "DELETE FROM {tripal_analysis} WHERE modulename = '%s'";
      db_query($sql, $modulename);
  }
}
tripal_analysis_validate ( node,
&$  form 
)

This validation is being used for three activities: CASE A: Update a node that exists in both drupal and chado CASE B: Synchronizing a node from chado to drupal CASE C: Inserting a new node that exists in niether drupal nor chado

Definition at line 480 of file tripal_analysis.module.

                                                 {
  
 
  // Only nodes being updated will have an nid already
  if (!is_null($node->nid)) {    
    // CASE A: We are validating a form for updating an existing node
    
    // get the existing node    
    $values = array('analysis_id' => $node->analysis_id);      
    $result = tripal_core_chado_select('analysis', array('*'), $values);
    $analysis = $result[0];
      
    // if the name has changed make sure it doesn't conflict with an existing name
    if($analysis->name != $node->analysisname) {
      $values = array('name' => $node->analysisname);
      $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
      if($result and count($result) > 0) {
        form_set_error('analysisname', 'Cannot update the analysis with this analysis name. An analysis with this name already exists.');
        return;
      }  
    }
    
    // if the unique constraint has changed check to make sure it doesn't conflict with an
    // existing record
    if($analysis->program != $node->program or $analysis->programversion != $node->programversion or 
       $analysis->sourcename != $node->sourcename) {
      $values = array(
        'program' => $node->program,
        'programversion' => $node->programversion,
        'sourcename' => $node->sourcename,
      );
      $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
      if ($result and count($result) > 0) {
        if ($analysis->program != $node->program) {
          $field = 'program';  
        }
        if ($analysis->programversion != $node->programversion) {
          $field = 'programversion';  
        }
        if ($analysis->sourcename != $node->sourcename) {
          $field = 'sourcename';  
        }
        form_set_error($field, 'Cannot update the analysis with this program,
          program version and source name. An analysis with these values already exists.');
        return;
      }  
    }
  }
  else{
    // To differentiate if we are syncing or creating a new analysis altogther, see if an
    // analysis_id already exists
    if ($node->analysis_id and $node->analysis_id != 0) {
      // CASE B: Synchronizing a node from chado to drupal
      // we don't need to do anything.
    }
    else {
      // CASE C: We are validating a form for inserting a new node
      // The unique constraint for the chado analysis table is: program, programversion, sourcename
      $values = array(
        'program' => $node->program,
        'programversion' => $node->programversion,
        'sourcename' => $node->sourcename,
      );
      $analysis = tripal_core_chado_select('analysis', array('analysis_id'), $values);
      if ($analysis and count($analysis) > 0) {
        form_set_error('program', 'Cannot add the analysis with this program,
          program version and source name. An analysis with these values already exists.');
        return;
      }
      
      // make sure we have a unique analysis name. This is not a requirement 
      // for the analysis table but we use the analysis name for the Drupal node
      // title, so it should be unique      
      $values = array('name' => $node->analysisname);
      $result = tripal_core_chado_select('analysis', array('analysis_id'), $values);
      if($result and count($result) > 0) {
        form_set_error('analysisname', 'Cannot add the analysis with this analysis name. An analysis with this name already exists.');
        return;
      }
    }
  }
}
tripal_analysis_views_api ( )

Implements hook_views_api() Purpose: Essentially this hook tells drupal that there is views support for for this module which then includes tripal_analysis.views.inc where all the views integration code is

Definition at line 732 of file tripal_analysis.module.

                                     {
    return array(
    'api' => 2.0,
  );
}
 All Classes Files Functions Variables