function tripal_library_taxonify_features

1.x tripal_library.admin.inc tripal_library_taxonify_features($library_id = NULL, $job_id = NULL)

Related topics

1 string reference to 'tripal_library_taxonify_features'

File

tripal_library/includes/tripal_library.admin.inc, line 516

Code

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";
    $results = chado_query($sql);
  }
  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";
    $results = chado_query($sql);
  }

  // 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++;
  }
}