Tripal v1.0 (6.x-1.0)
syncFeatures.inc File Reference

Go to the source code of this file.

Functions

if(isset($arguments['f'])) tripal_feature_sync_form ()
 tripal_feature_sync_form_validate ($form, &$form_state)
 tripal_feature_sync_form_submit ($form, &$form_state)
 tripal_feature_set_urls ($job_id=NULL)
 tripal_feature_set_feature_url ($node, $feature)
 tripal_feature_sync_features ($max_sync=0, $organism_id=NULL, $feature_types=NULL, $job_id=NULL)
 tripal_feature_sync_feature ($feature_id)

Variables

 $arguments = getopt("f:")

Detailed Description

Definition in file syncFeatures.inc.


Function Documentation

tripal_feature_set_feature_url ( node,
feature 
)

Definition at line 143 of file syncFeatures.inc.

                                                         {

  // determine which URL alias to use
  $alias_type = variable_get('chado_feature_url', 'internal ID');
  $aprefix = variable_get('chado_feature_accession_prefix', 'ID');  
  $genus = preg_replace('/\s/', '_', strtolower($feature->genus));
  $species = preg_replace('/\s/', '_', strtolower($feature->species));    
  switch ($alias_type) {
    case 'feature name':
      $url_alias = $feature->name;
      break;
    case 'feature unique name':
      $url_alias = $feature->uniquename;
      break;
    case 'genus_species_uqname':
      $url_alias = $genus . "/" . $genus . "_" . $species . "/" . $feature->uniquename;
      break;
    case 'genus species name':
      $url_alias = $genus . "/" . $genus . "_" . $species . "/" . $feature->name;
      break;
    default:
      $url_alias = "$aprefix$feature->feature_id";
  }
  print "Setting URL alias for $feature->name: node/$node->nid => $url_alias\n";
  // remove any previous alias
  db_query("DELETE FROM {url_alias} WHERE src = '%s'", "node/$node->nid");
  // add the new alias
  path_set_alias("node/$node->nid", $url_alias);
}
tripal_feature_set_urls ( job_id = NULL)

Definition at line 124 of file syncFeatures.inc.

                                                 {
  // first get the list of features that have been synced
  $sql = "SELECT * FROM {chado_feature}";
  $nodes = db_query($sql);
  while ($node = db_fetch_object($nodes)) {
    // now get the feature details
    $sql = "SELECT * 
            FROM feature F
              INNER JOIN organism O on O.organism_id = F.organism_id
            WHERE F.feature_id = %d";     
    $feature = db_fetch_object(chado_query($sql, $node->feature_id));
    if ($feature) {
      tripal_feature_set_feature_url($node, $feature);
    }
  }
}
if (isset($arguments['f'])) tripal_feature_sync_form ( )

Definition at line 38 of file syncFeatures.inc.

                                    {

  $form['description'] = array(
  '#type' => 'item',
  '#value' => t("Add feature types, optionally select an organism and ".
     "click the 'Sync all Features' button to create Drupal ".
     "content for features in chado. Only features of the types listed ".
     "below in the Feature Types box will be synced. You may limit the ".
     "features to be synced by a specific organism. Depending on the ".
     "number of features in the chado database this may take a long ".
     "time to complete. "),
  );

  $form['feature_types'] = array(
    '#title'       => t('Feature Types'),
    '#type'        => 'textarea',
    '#description' => t('Enter the names of the sequence types that the ".
       "site will support with independent pages.  Pages for these data ".
       "types will be built automatically for features that exist in the ".
       "chado database.  The names listed here should be spearated by ".
       "spaces or entered separately on new lines. The names must match ".
       "exactly (spelling and case) with terms in the sequence ontology'),
    '#required'    => TRUE,
    '#default_value' => variable_get('chado_sync_feature_types', 'gene contig'),
  );

  // get the list of organisms
  $sql = "SELECT * FROM {organism} ORDER BY genus, species";
  $orgs = tripal_organism_get_synced();
  $organisms[] = '';
  foreach ($orgs as $organism) {
    $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 for which features set above will be synced. Only organisms which also have been synced will appear in this list."),
    '#options'     => $organisms,
  );


  $form['button'] = array(
    '#type' => 'submit',
    '#value' => t('Sync all Features'),
    '#weight' => 3,
  );

  return $form;
}
tripal_feature_sync_form_submit ( form,
&$  form_state 
)

Definition at line 99 of file syncFeatures.inc.

                                                              {

  global $user;

  $organism_id   = $form_state['values']['organism_id'];
  $feature_types = $form_state['values']['feature_types'];

  $job_args = array(0, $organism_id, $feature_types);

  if ($organism_id) {
    $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $organism_id));
    $title = "Sync all features for " .  $organism[0]->genus . " " . $organism[0]->species;
  }
  else {
    $title = t('Sync all features for all synced organisms');
  }

  variable_set('chado_sync_feature_types', $feature_types);

  tripal_add_job($title, 'tripal_feature',
    'tripal_feature_sync_features', $job_args, $user->uid);
}
tripal_feature_sync_form_validate ( form,
&$  form_state 
)

Definition at line 90 of file syncFeatures.inc.

                                                                {
  $organism_id   = $form_state['values']['organism_id'];
  $feature_types = $form_state['values']['feature_types'];

  // nothing to do
}

Variable Documentation

$arguments = getopt("f:")

Definition at line 13 of file syncFeatures.inc.

 All Classes Files Functions Variables