function tripal_feature_load_analysis_feature_browser

1.x tripal_feature.module tripal_feature_load_analysis_feature_browser($analysis)

This generates the Feature Browse which can optionally be included on library pages and shows all features belonging to the given library. This Browse can be shown/hidden on the Feature Configuration page.

Related topics

1 call to tripal_feature_load_analysis_feature_browser()
tripal_feature_preprocess_tripal_analysis_feature_browser in tripal_feature/tripal_feature.module
Preprocessor function for the Analysis Feature Browser

File

tripal_feature/tripal_feature.module, line 1618
@todo Add file header description

Code

function tripal_feature_load_analysis_feature_browser($analysis) {

  // don't show the browser if the settings in the admin page is turned off
  // instead return the array indicating the status of the browser
  $show_browser = variable_get('tripal_analysis_feature_browse_setting', 'show_feature_browser');
  if (strcmp($show_browser, 'show_feature_browser') != 0) {
    return array('enabled' => FALSE);
  }

  // get a list of feature types to include in the browser
  $allowed_types = variable_get('chado_browser_feature_types', 'EST contig');
  $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
  $so_terms = split(' ', $allowed_types);
  $where_cvt = "";
  foreach ($so_terms as $term) {
    $where_cvt .= "CVT.name = '$term' OR ";
  }
  $where_cvt = drupal_substr($where_cvt, 0, drupal_strlen($where_cvt) -3); # strip trailing 'OR'

  // get the features for this library
  $sql = "SELECT F.name,F.feature_id,F.uniquename,CVT.name as cvname " .
    "FROM {feature} F " .
    "  INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id " .
    "  INNER JOIN {analysisfeature} AF on F.feature_id = AF.feature_id " .
    "  INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id " .
    "WHERE A.analysis_id = %d and ($where_cvt) " .
    "ORDER BY feature_id ASC";

  // the counting SQL
  $csql = "SELECT count(*) " .
    "FROM {feature} F" .
    "  INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id " .
    "  INNER JOIN {analysisfeature} AF on F.feature_id = AF.feature_id " .
    "  INNER JOIN {analysis} A on AF.analysis_id = A.analysis_id " .
    "WHERE A.analysis_id = %d and ($where_cvt) " .
    "GROUP BY A.analysis_id ";

  $previous_db = tripal_db_set_active('chado'); // use chado database
  $org_features = pager_query($sql, 10, 0, $csql, $analysis->analysis_id);
  tripal_db_set_active($previous_db); // now use drupal database
  $pager = theme('pager');

  // prepare the query that will lookup node ids
  $sql = "SELECT nid FROM {chado_feature} " .
    "WHERE feature_id = %d";
  $i = 0;
  $features = array();
  while ($feature = db_fetch_object($org_features)) {
    $node = db_fetch_object(db_query($sql, $feature->feature_id));
    $feature->nid = $node->nid;
    $features[$i++] = $feature;
  }

  return array('features' => $features, 'pager' => $pager, 'enabled' => TRUE);
}