Tripal v1.0 (6.x-1.0)
Feature

Classes

class  views_handler_field_residues

Modules

 FASTA Feature Loader
 GFF3 Feature Loader

Functions

 tripal_analysis_block ($op= 'list', $delta=0, $edit=array())
 tripal_feature_get_custom_tables ($table=NULL)
if(isset($arguments['i'])) tripal_features_reindex ($max_sync, $job_id=NULL)
 tripal_feature_index_feature ($feature_id, $nid)
 tripal_feature_sync_features ($max_sync=0, $organism_id=NULL, $feature_types=NULL, $job_id=NULL)
 tripal_feature_sync_feature ($feature_id)
 tripal_feature_add_ALL_dbreferences_page ($node)
 tripal_feature_add_ONE_dbreference_form ($form_state, $node)
 tripal_feature_add_ONE_dbreference_form_validate ($form, &$form_state)
 tripal_feature_add_ONE_dbreference_form_submit ($form, &$form_state)
 tripal_feature_edit_ALL_dbreferences_page ($node)
 tripal_feature_edit_ALL_db_references_form ($form_state, $node)
 tripal_feature_edit_ALL_db_references_form_submit ($form, &$form_state)
 tripal_feature_update_db_reference ($dbxref_id, $db_id, $accession)
 tripal_feature_delete_db_reference ($dbxref_id)
 theme_tripal_feature_edit_ALL_db_references_form ($form)
 list_dbreferences_for_node ($db_references)
 tripal_feature_edit_ALL_properties_page ($node)
 tripal_feature_add_ONE_property_form ($form_state, $node, $expand)
 tripal_feature_add_ONE_property_form_validate ($form, &$form_state)
 tripal_feature_add_ONE_property_form_submit ($form, &$form_state)
 tripal_feature_edit_ALL_properties_form ($form_state, $node, $properties)
 tripal_feature_edit_ALL_properties_form_submit ($form, &$form_state)
 theme_tripal_feature_edit_ALL_properties_form ($form)
 tripal_feature_list_properties_for_node ($properties)
 tripal_feature_add_ALL_relationships_page ($node)
 tripal_feature_add_ONE_relationship_form ($form_state, $node)
 tripal_feature_add_ONE_relationship_form_validate ($form, &$form_state)
 tripal_feature_add_ONE_relationship_form_submit ($form, &$form_state)
 tripal_feature_edit_ALL_relationships_page ($node)
 tripal_feature_edit_ALL_relationships_form ($form_state, $node)
 tripal_feature_edit_ALL_relationships_form_validate ($form, &$form_state)
 tripal_feature_edit_ALL_relationships_form_submit ($form, &$form_state)
 tripal_feature_update_relationship ($stock_relationship_id, $subject_id, $cvterm_id, $object_id)
 tripal_feature_delete_relationship ($stock_relationship_id)
 theme_tripal_feature_edit_ALL_relationships_form ($form)
 tripal_feature_list_relationships_for_node ($feature_name, $subject_relationships, $object_relationships)
 tripal_feature_implement_back_to_feature_button ($form_state, $nid)
 tripal_feature_implement_back_to_feature_button_submit ($form, $form_state)
 tripal_feature_implement_add_chado_properties_progress ($current)
 tripal_feature_implement_add_chado_properties_navigate ($form_state, $step, $nid)
 tripal_feature_implement_add_chado_properties_navigate_submit ($form, $form_state)
 tripal_feature_is_obsolete_form ($node, $stock_id)
 tripal_feature_is_obsolete_form_submit ($form, &$form_state)
 tripal_feature_admin ()
 tripal_feature_admin_validate ($form, &$form_state)
 get_tripal_feature_admin_form_cleanup_set (&$form)
 get_tripal_feature_admin_form_reindex_set (&$form)
 get_tripal_feature_admin_form_taxonomy_set (&$form)
 tripal_features_set_taxonomy ($max_sync=0, $job_id=NULL)
 tripal_feature_set_taxonomy ($node, $feature_id)
 tripal_features_cleanup ($dummy=NULL, $job_id=NULL)
 theme_tripal_feature_search_index ($node)
 theme_tripal_feature_search_results ($node)
 tripal_feature_set_vocabulary ()
 tripal_feature_init ()
 tripal_feature_views_api ()
 tripal_feature_help ($path, $arg)
 tripal_feature_node_info ()
 tripal_feature_perm ()
 chado_feature_access ($op, $node, $account)
 tripal_feature_menu ()
 tf_node_load ($nid)
 tripal_feature_theme ()
 tripal_feature_block ($op= 'list', $delta=0, $edit=array())
 chado_feature_insert ($node)
 chado_feature_update ($node)
 chado_feature_delete ($node)
 chado_feature_add_synonyms ($synonyms, $feature_id)
 chado_feature_add_gbaccession ($accession, $feature_id)
 chado_feature_form ($node, $param)
 chado_feature_validate ($node)
 chado_feature_load ($node)
 tripal_feature_load_organism ($organism_id)
 tripal_feature_load_synonyms ($feature_id)
 tripal_feature_load_properties ($feature_id)
 tripal_feature_load_references ($feature_id)
 tripal_feature_load_featurelocs ($feature_id, $side= 'as_parent', $aggregate=1)
 tripal_feature_sort_locations ($a, $b)
 tripal_feature_load_relationships ($feature_id, $side= 'as_subject')
 tripal_feature_get_aggregate_relationships ($feature_id, $substitute=1, $levels=0, $base_type_id=NULL, $depth=0)
 tripal_feature_load_featureloc_sequences ($feature_id, $featurelocs)
 tripal_feature_get_matched_alignments ($feature)
 tripal_feature_load_organism_feature_counts ($organism)
 tripal_feature_load_organism_feature_browser ($organism)
 tripal_feature_load_library_feature_browser ($library)
 tripal_feature_load_analysis_feature_browser ($analysis)
 tripal_feature_sort_rel_objects ($a, $b)
 tripal_feature_sort_rel_parts_by_start ($a, $b)
 tripal_feature_sort_rel_parts_by_end ($a, $b)
 tripal_feature_color_sequence ($sequence, $parts, $defline)
 chado_feature_view ($node, $teaser=FALSE, $page=FALSE)
 tripal_feature_nodeapi (&$node, $op, $teaser, $page)
 tripal_feature_preprocess_tripal_feature_relationships (&$variables)
 tripal_feature_preprocess_tripal_feature_alignments (&$variables)
 tripal_feature_preprocess_tripal_organism_feature_counts (&$variables)
 tripal_feature_preprocess_tripal_organism_feature_browser (&$variables)
 tripal_feature_preprocess_tripal_library_feature_browser (&$variables)
 tripal_feature_preprocess_tripal_analysis_feature_browser (&$variables)
 tripal_feature_cv_chart ($chart_id)
 tripal_feature_cv_tree ($tree_id)
 tripal_feature_del_vocabulary ()
 tripal_feature_return_fasta ($feature, $desc)
 tripal_feature_job_describe_args ($callback, $args)

Detailed Description

Provides functions for managing chado features including creating details pages for each feature


Function Documentation

chado_feature_access ( op,
node,
account 
)

Set the permission types that the module uses.

Definition at line 123 of file tripal_feature.module.

                                                    {
  if ($op == 'create') {
    if (!user_access('create chado_feature content', $account)) {
      return FALSE;
      }
  }

  if ($op == 'update') {
    if (!user_access('edit chado_feature content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'delete') {
    if (!user_access('delete chado_feature content', $account)) {
      return FALSE;
    }
  }
  if ($op == 'view') {
    if (!user_access('access chado_feature content', $account)) {
      return FALSE;
    }
  }
  return NULL;
}
chado_feature_add_gbaccession ( accession,
feature_id 
)

Definition at line 715 of file tripal_feature.module.

                                                                {

  // use chado database

  // remove any old accession from genbank dbEST
  $fdbxref_dsql = "DELETE FROM {feature_dbxref} ".
                 "WHERE feature_id = %d and dbxref_id IN ".
                 "   (SELECT DBX.dbxref_id FROM {dbxref} DBX ".
                 "    INNER JOIN DB  ON DB.db_id = DBX.db_id ".
                 "    INNER JOIN feature_dbxref FDBX ON DBX.dbxref_id = FDBX.dbxref_id ".
                 "    WHERE DB.name = 'DB:Genbank' and FDBX.feature_id = %d)";
  if (!chado_query($fdbxref_dsql, $feature_id, $feature_id)) {
    $error .= "Could not remove accession from feature. ";
  }

  // if we don't have an accession number to add then just return
  if (!$accession) {
    return;
  }
  // get the db_id
  $db_sql = "SELECT db_id FROM {DB} ".
            "WHERE name = 'DB:Genbank_est'";
  $db = db_fetch_object(chado_query($db_sql));

  // check to see if we have this accession number already in the database
  // if so then don't add it again. it messes up drupal if the insert fails.
  // It is possible for the accession number to be present and not the feature
  $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
                "WHERE db_id = %d and accession = '%s'";
  $dbxref = db_fetch_object(chado_query($dbxref_sql, $db->db_id, $accession));
  if (!$dbxref) {
    // add the accession number
    $dbxref_isql = "INSERT INTO {dbxref} (db_id,accession) ".
                   "  VALUES (%d, '%s') ";
    if (!chado_query($dbxref_isql, $db->db_id, $accession)) {
      $error .= 'Could not add accession as a database reference ';
    }
    // get the dbxref_id for the just added accession number
    $dbxref_sql = "SELECT dbxref_id FROM {dbxref} ".
                  "WHERE db_id = %d and accession = '%s'";
    $dbxref = db_fetch_object(chado_query($dbxref_sql, $db->db_id, $accession));
  }


  // associate the accession number with the feature
  $feature_dbxref_isql = "INSERT INTO {feature_dbxref} (feature_id,dbxref_id) ".
                         "  VALUES (%d, %d) ";
  if (!chado_query($feature_dbxref_isql, $feature_id, $dbxref->dbxref_id)) {
    $error .= 'Could not add feature database reference. ';
  }

  return $error;
}
chado_feature_add_synonyms ( synonyms,
feature_id 
)

Definition at line 651 of file tripal_feature.module.

                                                            {

  // make sure we only have a single space between each synonym
  $synonyms = preg_replace("/[\s\n\r]+/", " ", $synonyms);
  // split the synonyms into an array based on a space as the delimieter
  $syn_array = array();
  $syn_array = explode(" ", $synonyms);


  // remove any old synonyms
  $feature_syn_dsql = "DELETE FROM {feature_synonym} WHERE feature_id = %d";
  if (!chado_query($feature_syn_dsql, $feature_id)) {
    $error .= "Could not remove synonyms from feature. ";
  }

  // return if we don't have any synonmys to add
  if (!$synonyms) {
    return;
  }
  // iterate through each synonym and add it to the database
  foreach ($syn_array as $syn) {
    // skip this item if it's empty
    if (!$syn) {
    break; }

    // check to see if we have this accession number already in the database
    // if so then don't add it again. it messes up drupal if the insert fails.
    // It is possible for the accession number to be present and not the feature
    $synonym_sql = "SELECT synonym_id FROM {synonym} ".
                   "WHERE name = '%s'";
    $synonym = db_fetch_object(chado_query($synonym_sql, $syn));
    if (!$synonym) {
      $synonym_isql = "INSERT INTO {synonym} (name,synonym_sgml,type_id) ".
                      "VALUES ('%s','%s', ".
                      "   (SELECT cvterm_id ".
                      "    FROM {CVTerm} CVT ".
                      "    INNER JOIN CV ON CVT.cv_id = CV.cv_id ".
                      "    WHERE CV.name = 'feature_property' and CVT.name = 'synonym'))";
      if (!chado_query($synonym_isql, $syn, $syn)) {
        $error .= "Could not add synonym. ";
      }
      // now get the synonym we just added
      $synonym_sql = "SELECT synonym_id FROM {synonym} ".
                     "WHERE name = '%s'";
      $synonym = db_fetch_object(chado_query($synonym_sql, $syn));
    }

    // now add in our new sysnonym
    $feature_syn_isql = "INSERT INTO {feature_synonym} (synonym_id,feature_id,pub_id) ".
                        "VALUES (%d,%d,1)";
    if (!chado_query($feature_syn_isql, $synonym->synonym_id, $feature_id)) {
      $error .= "Could not add synonyms to feature. ";
    }
  }

  // return to the drupal database
  return $error;

}
chado_feature_delete ( node)

Definition at line 612 of file tripal_feature.module.

                                     {

  $feature_id  = chado_get_id_for_node('feature', $node);
  
  // if we don't have a library id for this node then this isn't a node of
  // type chado_library or the entry in the chado_library table was lost.
  if (!$feature_id) {
    return;
  }

  // remove the drupal content
  $sql_del = "DELETE FROM {chado_feature} ".
             "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 data from feature tables of chado database.  This will
  // cause a cascade delete and remove all data in referencing tables
  // for this feature
  chado_query("DELETE FROM {feature} WHERE feature_id = %d", $feature_id);

  drupal_set_message(t("The feature and all associated data were removed from") .
  "chado");

}
chado_feature_form ( node,
param 
)

Definition at line 774 of file tripal_feature.module.

                                           {

  $type = node_get_types('type', $node);
  $form = array();

  $feature = $node->feature;

  // add the residues to the feature object
  $feature = tripal_core_expand_chado_vars($feature, 'field', 'feature.residues');

  // if the node has synonyms then use that as the form may be returning
  // from an error.  Otherwise try to find synonyms from the database
  $synonyms = $node->synonyms;
  $feature = tripal_core_expand_chado_vars($feature, 'table', 'feature_synonym');
  $feature_synonyms = $feature->feature_synonym;
  if (!$synonyms) {
    if (!is_array($feature_synonyms)) {
      $synonyms = $feature_synonyms->synonym_id->name;
    }
    elseif (is_array($feature_synonyms)) {
      foreach ($feature_synonyms as $index => $synonym) {
        $synonyms .= $synonym->synonym_id->name . "\n";
      }
    }
  }

  $analyses = $node->analyses;
  $references = $node->references;

  // We need to pass above variables for preview to show
  $form['feature'] = array(
    '#type' => 'value',
    '#value' => $feature
  );
  // This field is read when previewing a node
  $form['synonyms'] = array(
    '#type' => 'value',
    '#value' => $synonyms
  );
  // This field is read when previewing a node
  $form['analyses'] = array(
    '#type' => 'value',
    '#value' => $analyses
  );
  // This field is read when previewing a node
  $form['references'] = array(
    '#type' => 'value',
    '#value' => $references
  );

  // keep track of the feature id if we have one.  If we do have one then
  // this would indicate an update as opposed to an insert.
  $form['feature_id'] = array(
    '#type' => 'value',
    '#value' => $feature->feature_id,
  );

  $form['title']= array(
    '#type' => 'textfield',
    '#title' => t('Title'),
    '#required' => TRUE,
    '#default_value' => $node->title,
    '#description' => t('The title must be a unique identifier for this feature.  It is recommended to use a combination of uniquename, organism and feature type in the title as this is guranteed to be unique.'),
    '#weight' => 1,
    '#maxlength' => 255
  );

  $form['uniquename']= array(
    '#type' => 'textfield',
    '#title' => t('Unique Feature Name'),
    '#required' => TRUE,
    '#default_value' => $feature->uniquename,
    '#description' => t('Enter a unique name for this feature.  This name must be unique for the organism and feature type.'),
    '#weight' => 1,
    '#maxlength' => 255
  );

  $form['fname']= array(
    '#type' => 'textfield',
    '#title' => t('Feature Name'),
    '#required' => TRUE,
    '#default_value' => $feature->name,
    '#description' => t('Enter the name used by humans to refer to this feature.'),
    '#weight' => 1,
    '#maxlength' => 255
  );

  // get the list of supported feature types
  $ftypes = array();
  $ftypes[''] = '';
  $supported_ftypes = split("[ \n]", variable_get('tripal_feature_type_setting', 'gene mRNA EST contig'));
  foreach ($supported_ftypes as $ftype) {
    $ftypes["$ftype"] = $ftype;
  }

  $form['feature_type'] = array(
   '#title'       => t('Feature Type'),
   '#type'        => t('select'),
   '#description' => t("Choose the feature type."),
   '#required'    => TRUE,
   '#default_value' => $feature->type_id->name,
   '#options'     => $ftypes,
   '#weight'      => 2
  );
  
  // get the list of organisms
  $sql = "SELECT * FROM {Organism} ORDER BY genus, species";
  $org_rset = chado_query($sql);
  $organisms = array();
  $organisms[''] = '';
  while ($organism = db_fetch_object($org_rset)) {
    $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 with which this feature is associated"),
    '#required'    => TRUE,
    '#default_value' => $feature->organism_id->organism_id,
    '#options'     => $organisms,
    '#weight'      => 3,
  );

  // Get synonyms
  if ($synonyms) {
    if (is_array($synonyms)) {
      foreach ($synonyms as $synonym) {
        $syn_text .= "$synonym->name\n";
      }
    }
    else {
      $syn_text = $synonyms;
    }
  }
  $form['synonyms']= array(
    '#type' => 'textarea',
    '#title' => t('Synonyms'),
    '#required' => FALSE,
    '#default_value' => $syn_text,
    '#description' => t('Enter alternate names (synonmys) for this feature to help in searching and identification. You may enter as many alternate names as needed separated by spaces or on different lines.'),
    '#weight' => 5,
  );

  $form['residues']= array(
    '#type' => 'textarea',
    '#title' => t('Residues'),
    '#required' => FALSE,
    '#default_value' => $feature->residues,
    '#description' => t('Enter the nucelotide sequences for this feature'),
    '#weight' => 6
  );

  $checked = '';
  if ($feature->is_obsolete == 't') {
    $checked = '1';
  }
  $form['is_obsolete']= array(
    '#type' => 'checkbox',
    '#title' => t('Is Obsolete'),
    '#required' => FALSE,
    '#default_value' => $checked,
    '#description' => t('Check this box if this sequence should be retired and no longer included in further analysis.'),
    '#weight' => 8
  );
  return $form;
}
chado_feature_insert ( node)

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

Definition at line 487 of file tripal_feature.module.

                                     {
  // remove spaces, newlines from residues
  $residues = preg_replace("/[\n\r\s]/", "", $node->residues);
  $obsolete = 'FALSE';
  if ($node->is_obsolete) {
    $obsolete = 'TRUE';
  }
  
  // check to see if we are inserting a duplicate record.
  $values = array(
    'cv_id' => array(
      'name' => 'sequence'
    ),
    'name' => $node->feature_type
  );
  $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);
  $values = array(
    'organism_id' => $node->organism_id,
    'name' => $node->fname,
    'uniquename' => $node->uniquename,
    'residues' => $residues,
    'seqlen' => drupal_strlen($residues),
    'is_obsolete' => $obsolete,
    'type_id' => $type[0]->cvterm_id,
    'md5checksum' => md5($residues)
  );    
  $options = array('is_duplicate' => TRUE, 'has_record' => TRUE);
  $exists = tripal_core_chado_select('feature', array('*'), $values, $options);
  
  // if the record is not a duplicate then add it
  if (!$exists) {
    $istatus = tripal_core_chado_insert('feature', $values);
    if (!$istatus) {
      drupal_set_message(t('Unable to add feature.'), 'warning');
      watchdog('tripal_feature', 'Insert feature: Unable to create feature where values: %values',
        array('%values' => print_r($values, TRUE)), WATCHDOG_WARNING);
    }
  }
  
  // now get the newly added record
  $values = array(
    'organism_id' => $node->organism_id,
    'uniquename' => $node->uniquename,
    'type_id' => $type[0]->cvterm_id,
  );
  $feature = tripal_core_chado_select('feature', array('feature_id'), $values);
  
  // add the genbank accession and synonyms
  chado_feature_add_synonyms($node->synonyms, $feature[0]->feature_id);

  // make sure the entry for this feature doesn't already exist in the chado_feature table
  // if it doesn't exist then we want to add it.
  $node_check_sql = "SELECT * FROM {chado_feature} " .
                    "WHERE feature_id = '%s'";
  $node_check = db_fetch_object(db_query($node_check_sql, $feature[0]->feature_id));
  if (!$node_check) {
    // next add the item to the drupal table
    $sql = "INSERT INTO {chado_feature} (nid, vid, feature_id, sync_date) ".
           "VALUES (%d, %d, %d, " . time() . ")";
      db_query($sql, $node->nid, $node->vid, $feature[0]->feature_id);
  }
}
chado_feature_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 989 of file tripal_feature.module.

                                   {  

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

  $values = array('feature_id' => $feature_id);
  $feature = tripal_core_generate_chado_var('feature', $values);
  
  if (strcmp($feature->name, $feature->uniquename)==0) {
     $node->title = $feature->name . " (" . $feature->type_id->name . ") " . $feature->organism_id->genus . " " . $feature->organism_id->species ;
  }

  $additions = new stdClass();
  $additions->feature = $feature;
  return $additions;
}
chado_feature_update ( node)

Definition at line 555 of file tripal_feature.module.

                                     {
  if ($node->revision) {
    // there is no way to handle revisions in Chado but leave
    // this here just to make not we've addressed it.
  }

  $residues = preg_replace("/[\n\r\s]/", "", $node->residues);
  $obsolete = 'FALSE';
  if ($node->is_obsolete) {
    $obsolete = 'TRUE';
  }

  // get the feature type id
  $values = array(
    'cv_id' => array(
      'name' => 'sequence'
      ),
    'name' => $node->feature_type
  );
  $type = tripal_core_chado_select('cvterm', array('cvterm_id'), $values);

  $feature_id = chado_get_id_for_node('feature', $node) ;

  if (sizeof($type) > 0) {
    $match = array(
      'feature_id' => $feature_id,
    );
    $values = array(
      'organism_id' => $node->organism_id,
      'name' => $node->fname,
      'uniquename' => $node->uniquename,
      'residues' => $residues,
      'seqlen' => drupal_strlen($residues),
      'is_obsolete' => $obsolete,
      'type_id' => $type[0]->cvterm_id,
      'md5checksum' => md5($residues)
    );
    $options = array('return_record' => TRUE);
    $status = tripal_core_chado_update('feature', $match, $values, $options);

    // add the genbank synonyms
    chado_feature_add_synonyms($node->synonyms, $feature_id);
  }
  else {
    drupal_set_message(t('Unable to update feature.'), 'warning');
    watchdog('tripal_feature',
    'Update feature: Unable to update feature where values: %values',
    array('%values' => print_r($values, TRUE)),
    WATCHDOG_WARNING
    );
  }  
}
chado_feature_validate ( node)

Definition at line 945 of file tripal_feature.module.

                                       {
  $result = 0;

  // if this is an update, we want to make sure that a different feature for
  // the organism doesn't already have this uniquename. We don't want to give
  // two sequences the same uniquename
  if ($node->feature_id) {
    $sql = "SELECT *
            FROM {Feature} F
              INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
            WHERE uniquename = '%s'
             AND organism_id = %d AND CVT.name = '%s' AND NOT feature_id = %d";
    $result = db_fetch_object(chado_query($sql, $node->uniquename, $node->organism_id, $node->feature_type, $node->feature_id));
    if ($result) {
      form_set_error('uniquename', t("Feature update cannot proceed. The feature name '$node->uniquename' is not unique for this organism. Please provide a unique name for this feature."));
    }
  }

  // if this is an insert then we just need to make sure this name doesn't
  // already exist for this organism if it does then we need to throw an error
  else {
    $sql = "SELECT *
            FROM {Feature} F
              INNER JOIN {cvterm} CVT ON F.type_id = CVT.cvterm_id
            WHERE uniquename = '%s'
             AND organism_id = %d AND CVT.name = '%s'";
    $result = db_fetch_object(chado_query($sql, $node->uniquename, $node->organism_id, $node->feature_type));
    if ($result) {
      form_set_error('uniquename', t("Feature insert cannot proceed. The feature name '$node->uniquename' already exists for this organism. Please provide a unique name for this feature."));
    }
  }

  // we don't allow a genbank accession number for a contig
  if ($node->feature_type == 'contig' and $node->gbaccession) {
    form_set_error('gbaccession', t("Contigs cannot have a genbank accession number.  Please change the feature type or remove the accession number"));
  }

}
chado_feature_view ( node,
teaser = FALSE,
page = FALSE 
)

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

Definition at line 1853 of file tripal_feature.module.

                                                                   {

  if (!$teaser) {
    // use drupal's default node view:
    $node = node_prepare($node, $teaser);

    // if we're building the node for searching then
    // we want to handle this within the module and
    // not allow theme customization.  We don't want to
    // index all items (such as DNA sequence).
    if ($node->build_mode == NODE_BUILD_SEARCH_INDEX) {
      $node->content['index_version'] = array(
        '#value' => theme('tripal_feature_search_index', $node),
        '#weight' => 1,
      );
    }
    elseif ($node->build_mode == NODE_BUILD_SEARCH_RESULT) {
      $node->content['index_version'] = array(
        '#value' => theme('tripal_feature_search_results', $node),
        '#weight' => 1,
      );
    }
    else {
       // do nothing here, let the theme derived template handle display
    }
  }

  return $node;
}
get_tripal_feature_admin_form_cleanup_set ( &$  form)

Definition at line 232 of file tripal_feature.admin.inc.

                                                           {
  $form['cleanup'] = array(
    '#type' => 'fieldset',
    '#title' => t('Clean Up'),
    '#collapsible' => 1,
    '#collapsed' => 1 ,
  );
  $form['cleanup']['description'] = array(
    '#type' => 'item',
    '#value' => t("With Drupal and chado residing in different databases ".
      "it is possible that nodes in Drupal and features in Chado become ".
      "\"orphaned\".  This can occur if a feature node in Drupal is ".
      "deleted but the corresponding chado feature is not and/or vice ".
      "versa.  The Cleanup function will also remove nodes for features ".
      "that are not in the list of allowed feature types as specified ".
      "above.  This is helpful when a feature type needs to be ".
      "removed but was previously present as Drupal nodes. ".
      "Click the button below to resolve these discrepancies."),
    '#weight' => 1,
  );
  $form['cleanup']['button'] = array(
    '#type' => 'submit',
    '#value' => t('Clean up orphaned features'),
    '#weight' => 2,
  );
}
get_tripal_feature_admin_form_reindex_set ( &$  form)

Definition at line 264 of file tripal_feature.admin.inc.

                                                           {
  $form['reindex'] = array(
    '#type' => 'fieldset',
    '#title' => t('Index/Reindex'),
    '#collapsible' => 1,
    '#collapsed' => 1 ,
  );
  $form['reindex']['description'] = array(
     '#type' => 'item',
     '#value' => t("Indexing or reindexing of nodes is required for Drupal's full text searching. ".
        "Index features for the first time to allow for searching of content, and later when content for features ".
        "is updated.  Depending on the number of features this may take ".
        "quite a while. Click the button below to begin reindexing of ".
        "features. "),
     '#weight' => 1,
  );
  $form['reindex']['button'] = array(
    '#type' => 'submit',
    '#value' => t('Reindex all feature nodes'),
    '#weight' => 2,
  );
}
get_tripal_feature_admin_form_taxonomy_set ( &$  form)

Definition at line 292 of file tripal_feature.admin.inc.

                                                            {

  $form['taxonomy'] = array(
    '#type' => 'fieldset',
    '#title' => t('Set Taxonomy'),
    '#collapsible' => 1,
    '#collapsed' => 1 ,
  );

  $form['taxonomy']['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."),
     '#weight' => 1,
  );
  $tax_options = array(
    'organism' => t('Organism name'),
    'feature_type'  => t('Feature Type (e.g. EST, mRNA, etc.)'),
    'analysis' => t('Analysis Name'),
    'library'  => t('Library Name'),
  );
  $form['taxonomy']['tax_classes'] = array(
   '#title'       => t('Available Taxonomic Classes'),
   '#type'        => t('checkboxes'),
   '#description' => t("Please select the class of terms to assign to ".
      "chado features"),
   '#required'    => FALSE,
   '#prefix'      => '<div id="taxclass_boxes">',
   '#suffix'      => '</div>',
   '#options'     => $tax_options,
   '#weight'      => 2,
   '#default_value' => variable_get('tax_classes', ''),
  );
  $form['taxonomy']['button'] = array(
    '#type' => 'submit',
    '#value' => t('Set/Reset Taxonomy for all feature nodes'),
    '#weight' => 3,
  );

}
list_dbreferences_for_node ( db_references)

Definition at line 339 of file tripal_feature-db_references.inc.

                                                    {

  if (!empty($db_references) ) {
    $output = '<table>';
    $output .= '<tr><th>Database</th><th>Accession</th></tr>';

    foreach ($db_references as $db) {
        $output .= '<tr><td>' . $db->db_name . '</td><td>' . $db->accession . '</td></tr>';
    } // end of foreach db reference

    $output .= '</table>';

  }
  else {
    $output = 'No Database References Added to the Current Feature';
  }

  return $output;
}
tf_node_load ( nid)

Implements Menu wildcard_load hook Purpose: Allows the node ID of a chado feature to be dynamically pulled from the path. The node is loaded from this node ID and supplied to the page as an arguement

Definition at line 292 of file tripal_feature.module.

                            {
  if (is_numeric($nid)) {
    $node = node_load($nid);
    if ($node->type == 'chado_feature') {
      return $node;
    }
  }
  return FALSE;
}
theme_tripal_feature_edit_ALL_db_references_form ( form)

Definition at line 310 of file tripal_feature-db_references.inc.

                                                                 {
  $output = '';

  $output .= '<br /><fieldset>';
  $output .= '<legend>Edit Existing Database References<span class="form-optional" title="This field is optional">(optional)</span></legend>';
  $output .= '<p>Below is a list of already existing database references, one per line. When entering a database reference, the accession '
         .'is a unique identifier for this feature in the specified database.</p>';
  $output .= '<table>';
  $output .= '<tr><th>#</th><th>Database</th><th>Accession</th><th></th></tr>';

  for ($i=1; $i<=$form['num_db_references']['#value']; $i++) {
    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td><td>'
             . drupal_render($form["database-$i"]) . '</td><td>'
         . drupal_render($form["accession-$i"]) . '</td><td>'
         . drupal_render($form["submit-$i"]) . '</td></tr>';
  }

  $output .= '</table><br />';
  $output .= drupal_render($form);
  $output .= '</fieldset>';

  return $output;
}
theme_tripal_feature_edit_ALL_properties_form ( form)

Definition at line 275 of file tripal_feature-properties.inc.

                                                              {
  $output = '';

  $output .= '<br /><fieldset>';
  $output .= '<legend>Edit Already Existing Properties<span class="form-optional" title="This field is optional">(optional)</span></legend>';
  $output .= '<p>Below is a list of already existing properties for this feature, one property per line. The type refers to the type of '
         .'property and the value is the value for that property. </p>';
  $output .= '<table>';
  $output .= '<tr><th>#</th><th>Type</th><th>Value</th><th></th></tr>';

  for ($i=0; $i<=$form['num_properties']['#value']; $i++) {
    if (isset($form["num-$i"])) {
      $output .= '<tr><td>' . ($i+1) . '</td><td>' . drupal_render($form["num-$i"]["type-$i"]) . '</td><td>' . drupal_render($form["num-$i"]["value-$i"]) . '</td><td>' . drupal_render($form["num-$i"]["delete-$i"]) . '</td></tr>';
      unset($form["num-$i"]);
    }
  }

  $output .= '</table><br />';
  $output .= drupal_render($form);
  $output .= '</fieldset>';

  return $output;
}
theme_tripal_feature_edit_ALL_relationships_form ( form)

Definition at line 498 of file tripal_feature-relationships.inc.

                                                                 {
  $output = '';

  $output .= '<br /><fieldset>';
  $output .= '<legend>Edit Already Existing Relationships<span class="form-optional" title="This field is optional">(optional)</span></legend>';
  $output .= '<p>Each relationship for this stock is listed below, one per line. The textboxes indicating '
        .'the subject and object of the relationship can contain the uniquename, name, database '
      .'reference or synonym of a stock of the same organism.</p>';
  $output .= '<table>';
  $output .= '<tr><th>#</th><th>Subject</th><th>Type</th><th>Object</th><th></th></tr>';

  for ($i=1; $i <= $form['num_relationships']['#value']; $i++) {
    $output .= '<tr><td>' . drupal_render($form["num-$i"]) . '</td>' .
              '<td>' . drupal_render($form["subject_id-$i"]) . '</td>' .
              '<td>' . drupal_render($form["type_id-$i"]) . '</td>' .
                '<td>' . drupal_render($form["object_id-$i"]) . '</td>' .
              '<td>' . drupal_render($form["submit-$i"]) . '</td></tr>';
  }

  $output .= '</table><br />';
  $output .= drupal_render($form);
  $output .= '</fieldset>';

  return $output;
}
theme_tripal_feature_search_index ( node)

This function is an extension of the chado_feature_view by providing the markup for the feature object THAT WILL BE INDEXED.

Definition at line 552 of file tripal_feature.admin.inc.

                                                  {
  $feature = $node->feature;
  $content = '';

  // get the accession prefix
  $aprefix = variable_get('chado_feature_accession_prefix', 'ID');

  $content .= "<h1>$feature->uniquename</h1>. ";
  $content .= "<strong>$aprefix$feature->feature_id.</strong> ";
  $content .= "$feature->cvname ";
  $content .= "$feature->common_name ";

  // add the synonyms of this feature to the text for searching
  $synonyms = $node->synonyms;
  if (count($synonyms) > 0) {
    foreach ($synonyms as $result) {
      $content .= "$result->name ";
    }
  }

  return $content;
}
theme_tripal_feature_search_results ( node)

This function is an extension of the chado_feature_view by providing the markup for the feature object THAT WILL BE INDEXED.

Definition at line 581 of file tripal_feature.admin.inc.

                                                    {
  $feature = $node->feature;
  $content = '';

  // get the accession prefix
  $aprefix = variable_get('chado_feature_accession_prefix', 'ID');

  $content .= "Feature Name: <h1>$feature->uniquename</h1>. ";
  $content .= "<strong>Accession: $aprefix$feature->feature_id.</strong>";
  $content .= "Type: $feature->cvname. ";
  $content .= "Organism: $feature->common_name. ";

  // add the synonyms of this feature to the text for searching
  $synonyms = $node->synonyms;
  if (count($synonyms) > 0) {
    $content .= "Synonyms: ";
    foreach ($synonyms as $result) {
      $content .= "$result->name, ";
    }
  }

  return $content;
}
tripal_analysis_block ( op = 'list',
delta = 0,
edit = array() 
)

Definition at line 661 of file tripal_analysis.module.

                                                                        {
  switch ($op) {
    case 'list':
      $blocks['base']['info'] = t('Tripal Analysis Details');
      $blocks['base']['cache'] = BLOCK_NO_CACHE;
      
      $blocks['featureblast']['info'] = t('Tripal Feature Analyses');
      $blocks['featureblast']['cache'] = BLOCK_NO_CACHE;
      
      return $blocks;

  case 'view':
    if (user_access('access chado_analysis content') and arg(0) == 'node' and is_numeric(arg(1))) {
      $nid = arg(1);
      $node = node_load($nid);

      $block = array();
      switch ($delta) {       
        case 'base':
          $block['subject'] = t('Analysis Details');
          $block['content'] = theme('tripal_analysis_base', $node);
          break;
        case 'tripal_feature_analyses':
          $block['subject'] = t('Feature Analyses');
          $block['content'] = theme('tripal_feature_analyses', $node);
          break;
        default :
      }
      return $block;
    }
  }
}
tripal_feature_add_ALL_dbreferences_page ( node)

Definition at line 13 of file tripal_feature-db_references.inc.

                                                         {
  $output = '';

  $output .= tripal_feature_implement_add_chado_properties_progress('db_references') . '<br />';
  $output .= '<b>All Database References should strictly pertain to THE CURRENT Individual</b><br />';
  $output .= '<br /><b>Current Database References</b><br />';
  $output .= list_dbreferences_for_node($node->db_references);
  $output .= '<br /><br />';
  $output .= drupal_get_form('tripal_feature_add_ONE_dbreference_form', $node);
  $output .= '<br />';
  $output .= drupal_get_form('tripal_feature_implement_add_chado_properties_navigate', 'db_references', $node->nid);
  return $output;
}
tripal_feature_add_ALL_relationships_page ( node)

Definition at line 12 of file tripal_feature-relationships.inc.

                                                          {
  $output = '';

  $output .= tripal_feature_implement_add_chado_properties_progress('relationships') . '<br />';
  $output .= '<b>All Relationships should include the CURRENT Individual (' . $node->uniquename . ')</b><br />';
  $output .= '<br /><b>Current Relationships</b><br />';
  $output .= list_relationships_for_node($node->uniquename, $node->subject_relationships, $node->object_relationships);
  $output .= '<br /><br />';
  $output .= drupal_get_form('tripal_feature_add_ONE_relationship_form', $node);
  $output .= '<br />';
  $output .= drupal_get_form('tripal_feature_implement_add_chado_properties_navigate', 'relationships', $node->nid);
  return $output;
}
tripal_feature_add_ONE_dbreference_form ( form_state,
node 
)

Implements Hook_form() Handles adding of Database References to features

Definition at line 33 of file tripal_feature-db_references.inc.

                                                                     {

  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid
  );

  $form['feature_id'] = array(
    '#type' => 'hidden',
    '#value' => $node->feature->feature_id,
  );

  $form['add_dbreference'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add Database References') . '<span class="form-optional" title="This field is optional">(optional)</span>',
  );

  $form['add_dbreference']['accession'] = array(
    '#type' => 'textfield',
    '#title' => t('Accession'),
    '#required' => TRUE,
  );

  $form['add_dbreference']['description'] = array(
    '#type' => 'textarea',
    '#title' => t('Description of Reference') . '<span class="form-optional" title="This field is optional">+</span>',
    '#description' => t('Optionally enter a description about the database accession.'),
  );

  $db_options = tripal_db_get_db_options();
  $db_options[0] = 'Select a Database';
  ksort($db_options);
  $form['add_dbreference']['db_id'] = array(
    '#type' => 'select',
    '#title' => t('Database'),
    '#options' => $db_options,
    '#required' => TRUE,
  );

  $form['add_dbreference']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add Database Reference')
  );

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

Definition at line 114 of file tripal_feature-db_references.inc.

                                                                             {

  $db_id = $form_state['values']['db_id'];
  $accession = $form_state['values']['accession'];
  $description = $form_state['values']['description'];
  $feature_id = $form_state['values']['feature_id'];
  $nid = $form_state['values']['nid'];

  // create dbxref
  $isql =  "INSERT INTO {dbxref} (db_id, accession, description) VALUES (%d, '%s', '%s')";
  chado_query($isql, $db_id, $accession, $description);

  //create feature_dbxref
  $dbxref = tripal_db_get_dbxref( array('db_id' => array('type' => 'INT', 'value' => $form_state['values']['db_id']),
                     'accession' => array('type' => 'STRING', 'exact' => TRUE, 'value' => $form_state['values']['accession']) ) );

  if (!empty($dbxref->dbxref_id)) {
      $isql = "INSERT INTO {feature_dbxref} (feature_id, dbxref_id) VALUES (%d, %d)";
      chado_query($isql, $feature_id, $dbxref->dbxref_id);
      drupal_set_message(t('Successfully Added Database Reference'));
      drupal_goto('node/' . $nid);
  }
  else {
    drupal_set_message(t('Database reference NOT successfully created...'), 'error');
  } //end of if dbxref was created successfully

}
tripal_feature_add_ONE_dbreference_form_validate ( form,
&$  form_state 
)

Definition at line 85 of file tripal_feature-db_references.inc.

                                                                               {

  $db_id = $form_state['values']['db_id'];
  $accession = $form_state['values']['accession'];
  $description = $form_state['values']['description'];
  $feature_id = $form_state['values']['feature_id'];
  $nid = $form_state['values']['nid'];

  // Check database is valid db_id in chado
  $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {db} WHERE db_id=%d", $db_id));
  if ($tmp_obj->count != 1) {
    form_set_error('database', 'The database you selected is not valid. Please choose another one.');
  }

  // Check Accession is unique for database
  $sql = "SELECT count(*) as count FROM {dbxref} WHERE accession='%s' and db_id = %d";
  $tmp_obj = db_fetch_object(chado_query($sql, $accession, $db_id));

  if ($tmp_obj->count > 0) {
    form_set_error('accession', 'This accession has already been assigned to another feature in the selected database.');
  }

}
tripal_feature_add_ONE_property_form ( form_state,
node,
expand 
)

Definition at line 36 of file tripal_feature-properties.inc.

                                                                           {
  $form = array();
  $feature_id = $node->feature->feature_id;

  $form['add_properties'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add Property'),
    '#collapsible' => TRUE,
    '#collapsed' => ($expand) ? FALSE : TRUE,
  );

  $form['prop_nid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid
  );

  $form['add_properties']['feature_id'] = array(
    '#type' => 'value',
    '#value' => $feature_id,
    '#required' => TRUE
  );

  // right now this defaults to the 'feature_property' CV
  // but in the future it should be more flexible
  $form['cv_name'] = array(
    '#type' => 'hidden',
    '#value' => 'feature_property'
  );

  // get the list of property types
  $prop_type_options = array();
  $columns = array('cvterm_id', 'name');
  $values = array(
    'cv_id' => array(
      'name' => $form['cv_name']['#value'],
    )
  );
  $results = tripal_core_chado_select('cvterm', $columns, $values);
  foreach ($results as $r) {
    $prop_type_options[$r->name] = $r->name;
  }

  $form['add_properties']['property'] = array(
    '#type' => 'select',
    '#title' => t('Type of Property'),
    '#options' => $prop_type_options,
  );

  $form['add_properties']['prop_value'] = array(
    '#type' => 'textfield',
    '#title' => t('Value'),
  );

  $form['add_properties']['submit-add'] = array(
    '#type' => 'submit',
    '#value' => t('Add Property')
  );

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

Definition at line 124 of file tripal_feature-properties.inc.

                                                                          {
  $feature_id = $form_state['values']['feature_id'];
  $property = $form_state['values']['property'];
  $value = $form_state['values']['prop_value'];
  $cv_name = $form_state['values']['cv_name'];

  $succes = tripal_feature_insert_property($feature_id, $property, $value, 0, $cv_name);
  if ($succes) {
    drupal_set_message(t("Successfully Added Property: %property => %value", array('%property' => $property), array('%value' => $value)));
  }
  else {
    drupal_set_message(t("Failed to Add Property: %property => %value", array('%property' => $property), array('%value' => $value)));
  }
}
tripal_feature_add_ONE_property_form_validate ( form,
&$  form_state 
)

Definition at line 102 of file tripal_feature-properties.inc.

                                                                            {

  // Only Require if Adding Property
  if ($form_state['clicked_button']['#value'] == t('Add Property') ) {

    // Check that there is a feature
    if ( $form_state['values']['feature_id'] <= 0 ) {
      form_set_error('feature_id', 'There is no associated feature.');
    }

    // Check that Selected a type
    if ( !$form_state['values']['property']) {
      form_set_error('property', 'Please select a type of property.');
    }
  }
}
tripal_feature_add_ONE_relationship_form ( form_state,
node 
)

Implements Hook_form() Handles adding of Relationships to Features

Definition at line 32 of file tripal_feature-relationships.inc.

                                                                      {

  $feature_id = $node->feature_id;
  $organism_id = $node->organism->organism_id;
  $_SESSION['organism'] = $organism_id; //needed for autocomplete enter feature to work

  $form['rel_nid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid
  );

  $form['add_relationships'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add Relationships') . '<span class="form-optional" title="This field is optional">(optional)</span>',
  );

  $form['add_relationships']['description'] = array(
    '#type' => 'item',
    '#value' => t('Relationships are specified as follows: (Subject) (Type of Relationship) (Object). For example, X part_of Y, where X & Y are genomic features.')
  );

  $form['add_relationships']['subject_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Subject'),
    '#description' => 'The Uniquename, Name, Database Reference or Synonym of a Feature can be used here',
  );

  $cv = tripal_cv_get_cv_by_name('relationship');
  $type_options = tripal_cv_get_cvterm_options($cv->cv_id);
  $type_options[0] = 'Select a Type';
  ksort($type_options);
  $form['add_relationships']['type_id'] = array(
    '#type' => 'select',
    '#title' => t('Type of Relationship'),
    '#options' => $type_options

  );

  $form['add_relationships']['object_id'] = array(
    '#type' => 'textfield',
    '#title' => t('Object'),
    '#description' => 'The Uniquename, Name, Database Reference or Synonym of a Feature can be used here',
  );

  $form['add_relationships']['r_description'] = array(
    '#type' => 'textarea',
    '#title' => t('Notes on the relationship') . '<span class="form-optional" title="This field is optional">+</span>',
    '#description' => t('Should not include Genotypes and Phenotypes'),
  );

  $form['add_relationships']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Add a Relationship')
  );

  $form['add_relationships']['r_feature_id'] = array(
    '#type' => 'value',
    '#value' => $feature_id,
    '#required' => TRUE

  );

  $form['add_relationships']['r_feature_uniquename'] = array(
    '#type' => 'value',
    '#value' => $node->uniquename,
    '#required' => TRUE
  );

  return $form;

}
tripal_feature_add_ONE_relationship_form_submit ( form,
&$  form_state 
)

Definition at line 188 of file tripal_feature-relationships.inc.

                                                                              {

  if ($form_state['values']['subject_id'] > 0) {
    $previous_db = db_set_active('chado');
    db_query(
      "INSERT INTO {stock_relationship} (subject_id, type_id, object_id, value) VALUES (%d, %d, %d, '%s')",
      $form_state['values']['subject_id'],
      $form_state['values']['type_id'],
      $form_state['values']['object_id'],
      $form_state['values']['r_description']
    );
    db_set_active($previous_db);

    drupal_set_message(t('Successfully Added Relationship.'));
  } //end of insert relationship

}
tripal_feature_add_ONE_relationship_form_validate ( form,
&$  form_state 
)

Definition at line 109 of file tripal_feature-relationships.inc.

                                                                                {

  //Require Validation if adding
  if ($form_state['clicked_button']['#value'] == t('Add a Relationship') ) {

    // check valid feature selected for subject
    $criteria = array('unknown' => array('value' => $form_state['values']['subject_id'],
                                          'columns' => array('name', 'uniquename', 'accession', 'synonym') ));
    $subject_results = get_chado_stocks($criteria, 'ANY', $_SESSION['organism']);
    if (sizeof($subject_results) > 1) {
      $links= array();
      for ($i=0; $i<sizeof($subject_results); $i++) {
      $links[] = l($i+1, "node/" . $subject_results[$i]->nid); }
      $message = t("Too many features match '%object'! Please refine your input to match
        ONLY ONE feature. <br />To aid in this process, here are the features that
        match your initial input: %features",
        array('%object' => $form_state['values']['subject_id'],
          '%features' => join(', ', $links)
        )
      );
      form_set_error('subject_id', $message);
    }
    elseif (sizeof($subject_results) < 1) {
      form_set_error('subject_id', t("There are no features matching your input. Please check your input for typos and/or lookup the feature <a href='!url'>here</a>", array('!url' => url('features'))));
    }
    elseif (sizeof($subject_results) == 1) {
      $form_state['values']['subject_id'] = $subject_results[0]->stock_id;
    }

    // check valid stock selected for object
    $criteria = array('unknown' => array('value' => $form_state['values']['object_id'],
                                          'columns' => array('name', 'uniquename', 'accession', 'synonym') ));
    $object_results = get_chado_stocks($criteria, 'ANY', $_SESSION['organism']);
    if (sizeof($object_results) > 1) {
      $links= array();
      for ($i=0; $i<sizeof($object_results); $i++) {
      $links[] = l($i+1, "node/" . $object_results[$i]->nid); }
      $message = t("Too many features match '%object'! Please refine your input to match
        ONLY ONE stock. <br />To aid in this process, here are the stocks that match
        your initial input: %features",
        array('%object' => $form_state['values']['object_id'],
        '%features' => join(', ', $links)
        )
      );
      form_set_error('object_id', $message);
    }
    elseif (sizeof($object_results) < 1) {
      form_set_error('object_id', t("There are no features matching your input. Please check your input for typos and/or lookup the feature <a href='!url'>here</a>", array('!url' => url('features'))));
    }
    elseif (sizeof($object_results) == 1) {
      $form_state['values']['object_id'] = $object_results[0]->stock_id;
    }

    // check valid type selected
    if ($form_state['values']['type_id'] == 0) {
      form_set_error('type_id', 'Please select a type of relationship.');
    }
    else {
      $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d", $form_state['values']['type_id']));

      if ($tmp_obj->count != 1) {
        form_set_error('type_id', 'The type you selected is not valid. Please choose another one.');
      }
    }

    // check either subject or object is the current stock
    if ( $subject_results[0]->nid != $form_state['values']['rel_nid'] ) {
      if ( $object_results[0]->nid != $form_state['values']['rel_nid'] ) {
        form_set_error('subject_id', 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
      }
    }
  } //end of require validation if adding relationship
}
tripal_feature_admin ( )

Definition at line 13 of file tripal_feature.admin.inc.

                                {

  // 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_feature')) {
    $active_jobs = TRUE;
  }
  if (!$active_jobs) {

    get_tripal_feature_admin_form_url_set($form);

    $form['browser'] = array(
       '#type' => 'fieldset',
       '#title' => t('Feature Browser'),
       '#collapsible' => 1,
       '#collapsed' => 1 ,
    );
    $allowedoptions1  = array(
      'show_feature_browser' => "Show the feature browser on the organism page. The browser loads when page loads. This may be slow for large sites.",
      'hide_feature_browser' => "Hide the feature browser on the organism page. Disables the feature browser completely.",
    );
  //      $allowedoptions ['allow_feature_browser'] = "Allow loading of the feature browsing through AJAX. For large sites the initial page load will be quick with the feature browser loading afterwards.";

    $form['browser']['browser_desc'] = array(
       '#type'        => 'markup',
       '#value' => 'A feature browser can be added to an organism page to allow users to quickly '.
          'access a feature.  This will most likely not be the ideal mechanism for accessing feature '.
          'information, especially for large sites, but it will alow users exploring the site (such '.
          'as students) to better understand the data types available on the site.',

    );
    $form['browser']['feature_types'] = array(
       '#title'       => t('Feature Types'),
       '#type'        => 'textarea',
       '#description' => t("Enter the Sequence Ontology (SO) terms for the feature types that " .
                           "will be shown in the feature browser."),
       '#default_value' => variable_get('chado_browser_feature_types', 'gene contig'),
    );


    $form['browser']['browse_features'] = array(
       '#title' => 'Feature Browser on Organism Page',
       '#type' => 'radios',
       '#options' => $allowedoptions1,
       '#default_value' => variable_get('tripal_feature_browse_setting', 'show_feature_browser'),
    );

    $form['browser']['browse_features_library'] = array(
      '#title' => 'Feature Browser on Library Page',
      '#type' => 'radios',
      '#options' => array(
        'show_feature_browser' => "Show the feature browse on the library page. The browser loads when page loads. This may be slow for large sites.",
        'hide_feature_browser' => "Hide the feature browser on the library page. Disables the feature browser completely.",
      ),
      '#default_value' => variable_get('tripal_library_feature_browse_setting', 'show_feature_browser'),
    );

    $form['browser']['browse_features_analysis'] = array(
      '#title' => 'Feature Browser on Analysis Page',
      '#type' => 'radios',
      '#options' => array(
        'show_feature_browser' => "Show the feature browse on the analysis page. The browser loads when page loads. This may be slow for large sites.",
        'hide_feature_browser' => "Hide the feature browser on the analysis page. Disables the feature browser completely.",
      ),
     '#default_value' => variable_get('tripal_analysis_feature_browse_setting', 'show_feature_browser'),
    );

    $form['browser']['set_browse_button'] = array(
       '#type' => 'submit',
       '#value' => t('Set Browser'),
       '#weight' => 2,
    );


    $form['feature_edit'] = array(
       '#type' => 'fieldset',
       '#title' => t('Feature Editing'),
       '#collapsible' => 1,
       '#collapsed' => 1 ,
    );

    $form['feature_edit']['browser_desc'] = array(
       '#type'        => 'markup',
       '#value' => 'When editing or creating a feature, a user must provide the feature type. '.
                   'The Sequence Ontology list is very large, therefore, to simply the list of types for the user, the following '.
                   'textbox allows you to specify which features types can be used. This list of terms will appear in the '.
                   'feature type drop down list of the feature creation/edit form.',

    );
    $form['feature_edit']['feature_edit_types'] = array(
       '#title'       => t('Feature Types'),
       '#type'        => 'textarea',
       '#description' => t("Enter the Sequence Ontology (SO) terms for the allowed feature types when creating or editing features."),
       '#default_value' => variable_get('chado_edit_feature_types', 'gene contig EST mRNA'),
    );

    $form['feature_edit']['set_feature_types'] = array(
       '#type' => 'submit',
       '#value' => t('Set Feature Types'),
    );

    $form['summary'] = array(
       '#type' => 'fieldset',
       '#title' => t('Feature Summary Report'),
       '#collapsible' => 1,
       '#collapsed' => 1 ,
    );
    $allowedoptions2 ['show_feature_summary'] = "Show the feature summary on the organism page. The summary loads when page loads.";
    $allowedoptions2 ['hide_feature_summary'] = "Hide the feature summary on the organism page. Disables the feature summary.";

    $form['summary']['feature_summary'] = array(
       '#title' => 'Feature Summary on Organism Page',
       '#description' => 'A feature summary can be added to an organism page to allow users to see the '.
          'type and quantity of features available for the organism.',
       '#type' => 'radios',
       '#options' => $allowedoptions2,
       '#default_value' => variable_get('tripal_feature_summary_setting', 'show_feature_summary'),
    );
    $form['summary']['feature_mapping'] = array(
       '#title' => 'Map feature types',
       '#description' => t('You may specify which Sequence Ontology (SO) terms to show in the '.
          'feature summary report by listing them in the following text area.   Enter one per line. '.
          'If left blank, all SO terms for all features will be shown in the report. Only those terms '.
          'listed below will be shown in the report. Terms will appear in the report in the same order listed. To rename a '.
          'SO term to be more human readable form, use an \'=\' sign after the SO term (e.g. \'polypeptide = Protein\')'),
       '#type' => 'textarea',
       '#rows' => 15,
       '#default_value' => variable_get('tripal_feature_summary_report_mapping', ''),
    );
    $form['summary']['set_summary_button'] = array(
       '#type' => 'submit',
       '#value' => t('Set Summary'),
       '#weight' => 2,
    );

    get_tripal_feature_admin_form_taxonomy_set($form);
    get_tripal_feature_admin_form_reindex_set($form);
    get_tripal_feature_admin_form_cleanup_set($form);
  }
  else {
    $form['notice'] = array(
       '#type' => 'fieldset',
       '#title' => t('Feature Management Temporarily Unavailable')
    );
    $form['notice']['message'] = array(
       '#value' => t('Currently, feature 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);
}
tripal_feature_admin_validate ( form,
&$  form_state 
)

Definition at line 175 of file tripal_feature.admin.inc.

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

  variable_set('chado_browser_feature_types', $form_state['values']['feature_types']);

  // if the user wants to sync up the chado features then
  // add the job to the management queue
  switch ($form_state['values']['op']) {

    case  t('Sync all Features') :
      tripal_add_job('Sync all features', 'tripal_feature',
        'tripal_feature_sync_features', $job_args, $user->uid);
    break;

    case t('Set/Reset Taxonomy for all feature nodes') :
    tripal_add_job('Set all feature taxonomy', 'tripal_feature',
      'tripal_features_set_taxonomy', $job_args, $user->uid);
    break;

    case t('Reindex all feature nodes') :
    tripal_add_job('Reindex all features', 'tripal_feature',
      'tripal_features_reindex', $job_args, $user->uid);
    break;

    case t('Clean up orphaned features') :
    tripal_add_job('Cleanup orphaned features', 'tripal_feature',
      'tripal_features_cleanup', $job_args, $user->uid);
    break;

    case t('Set Browser') :
      variable_set('tripal_feature_browse_setting', $form_state['values']['browse_features']);
      variable_set('tripal_library_feature_browse_setting', $form_state['values']['browse_features_library']);
      variable_set('tripal_analysis_feature_browse_setting', $form_state['values']['browse_features_analysis']);
    break;

    case t('Set Feature Types') :
      variable_set('tripal_feature_type_setting', $form_state['values']['feature_edit_types']);
    break;

    case t('Set Summary') :
      variable_set('tripal_feature_summary_setting', $form_state['values']['feature_summary']);
      variable_set('tripal_feature_summary_report_mapping', $form_state['values']['feature_mapping']);
    break;

    case t('Set Feature URLs') :
      variable_set('chado_feature_url', $form_state['values']['feature_url']);
      tripal_add_job('Set Feature URLs', 'tripal_feature',
        'tripal_feature_set_urls', $job_args, $user->uid);
    break;
    }
}
tripal_feature_block ( op = 'list',
delta = 0,
edit = array() 
)

Definition at line 376 of file tripal_feature.module.

                                                                       {
  switch ($op) {
    case 'list':
      $blocks['references']['info'] = t('Tripal Feature References');
      $blocks['references']['cache'] = BLOCK_NO_CACHE;

      $blocks['base']['info'] = t('Tripal Feature Details');
      $blocks['base']['cache'] = BLOCK_NO_CACHE;

      $blocks['sequence']['info'] = t('Tripal Feature Sequence');
      $blocks['sequence']['cache'] = BLOCK_NO_CACHE;

      $blocks['featureloc_sequences']['info'] = t('Tripal Feature Annotated Sequence');
      $blocks['featureloc_sequences']['cache'] = BLOCK_NO_CACHE;

      $blocks['synonyms']['info'] = t('Tripal Feature Synonyms');
      $blocks['synonyms']['cache'] = BLOCK_NO_CACHE;

      $blocks['properties']['info'] = t('Tripal Feature Properties');
      $blocks['properties']['cache'] = BLOCK_NO_CACHE;;

      $blocks['terms']['info'] = t('Tripal Annotated Terms');
      $blocks['terms']['cache'] = BLOCK_NO_CACHE;;

      $blocks['alignments']['info'] = t('Tripal Feature Alignments');
      $blocks['alignments']['cache'] = BLOCK_NO_CACHE;
      
      $blocks['relationships']['info'] = t('Tripal Feature Relationships');
      $blocks['relationships']['cache'] = BLOCK_NO_CACHE;

      $blocks['org_feature_counts']['info'] = t('Tripal Organism Feature Counts');
      $blocks['org_feature_counts']['cache'] = BLOCK_NO_CACHE;

      $blocks['org_feature_browser']['info'] = t('Tripal Organism Feature Browser');
      $blocks['org_feature_browser']['cache'] = BLOCK_NO_CACHE;

      return $blocks;

  case 'view':
    if (user_access('access chado_feature content') and arg(0) == 'node' and is_numeric(arg(1))) {
      $nid = arg(1);
      $node = node_load($nid);

      $block = array();
      switch ($delta) {
        case 'references':
          $block['subject'] = t('References');
          $block['content'] = theme('tripal_feature_references', $node);
          break;
        case 'base':
          $block['subject'] = t('Feature Details');
          $block['content'] = theme('tripal_feature_base', $node);
          break;
        case 'synonyms':
          $block['subject'] = t('Synonyms');
          $block['content'] = theme('tripal_feature_synonyms', $node);
          break;
        case 'properties':
          $block['subject'] = t('Properties');
          $block['content'] = theme('tripal_feature_properties', $node);
          break;
        case 'terms':
          $block['subject'] = t('Annotated Terms');
          $block['content'] = theme('tripal_feature_terms', $node);
          break;
        case 'sequence':
          $block['subject'] = t('Sequence');
          $block['content'] = theme('tripal_feature_sequence', $node);
          break;
        case 'featureloc_sequences':
          $block['subject'] = t('Formatted Sequences');
          $block['content'] = theme('tripal_feature_featureloc_sequences', $node);
          break;
        case 'alignments':
          $block['subject'] = t('Alignments');
          $block['content'] = theme('tripal_feature_alignments', $node);
          break;
        case 'relationships':
          $block['subject'] = t('Relationships');
          $block['content'] = theme('tripal_feature_relationships', $node);
          break;
        case 'org_feature_counts':
          $block['subject'] = t('Feature Type Summary');
          $block['content'] = theme('tripal_organism_feature_counts', $node);
          break;
        case 'org_feature_browser':
          $block['subject'] = t('Feature Browser');
          $block['content'] = theme('tripal_organism_feature_browser', $node);
          break;
        case 'library_feature_browser':
          $block['subject'] = t('Library Feature Browser');
          $block['content'] = theme('tripal_library_feature_browser', $node);
          break;
        case 'analysis_feature_browser':
          $block['subject'] = t('Analysis Feature Browser');
          $block['content'] = theme('tripal_analysis_feature_browser', $node);
          break;
        default :
      }
      return $block;
    }

  }
}
tripal_feature_color_sequence ( sequence,
parts,
defline 
)

Definition at line 1765 of file tripal_feature.module.

                                                                    {


  $types = array();
  // first get the list of types so we can create a color legend
  foreach ($parts as $index => $t) {
    foreach ($t as $type_name => $details) {
       $types[$type_name] = 1;
    }
  }

  $newseq .= "<div id=\"tripal_feature-featureloc_sequence-legend\">Legend: ";
  foreach ($types as $type_name => $present) {
    $newseq .= "<span id=\"tripal_feature-legend-$type_name\" class=\"tripal_feature-legend-item tripal_feature-featureloc_sequence-$type_name\" script=\"\">$type_name</span>";
  }
  $newseq .= "</div>Hold the cursor over a type above to highlight its positions in the sequence below. The colors in the sequence below merge when types overlap.";


  // set the background color of the rows based on the type
  $pos = 0;
  $newseq .= "<pre id=\"tripal_feature-featureloc_sequence\">";
  $newseq .= ">$defline\n";
  
  // iterate through the parts. They should be in order.
  $ends = array();
  foreach ($parts as $index => $types) {
  
    // get the start for this part.  All types in this part start at the 
    // same position so we only need the first record
    foreach ($types as $type => $child) {
      $start = $child['start'];
      break;
    }
  
    // add in the sequence up to the start of this part
    for ($i = $pos; $i < $start; $i++) {    
      $newseq .= $sequence{$pos};
      $seqcount++;
      if ($seqcount % 50 == 0) {
        $newseq .= "\n";
      }
      if (array_key_exists($pos, $ends)) {
        foreach ($ends[$pos] as $end) {
          $newseq .= "</span>";
        }
      }
      $pos++;
    }

    // we want to sort the parts by their end. We want the span tag to
    // to be added in the order the parts end. 
    usort($types, 'tripal_feature_sort_rel_parts_by_end');
    
    // now add the child span for all types that start at this position  
    foreach ($types as $type) {
      $class = "tripal_feature-featureloc_sequence-" . $type['type'];
      $newseq .= "<span class=\"$class\">";
      // add the end position
      $end = $type['end'];
      $ends[$end][] = $end;
    }         
  }
  
  // add in rest of the sequence
  for ($i = $pos; $i <= strlen($sequence); $i++) {    
    $newseq .= $sequence{$pos};
    $seqcount++;
    if ($seqcount % 50 == 0) {
      $newseq .= "\n";
    }
    if (array_key_exists($pos, $ends)) {
      foreach ($ends[$pos] as $end) {
        $newseq .= "</span>";
      }
    }
    $pos++;
  }

  $newseq .= "</pre>";
  return $newseq;
}
tripal_feature_cv_chart ( chart_id)

Definition at line 2070 of file tripal_feature.module.

                                            {

  // we only want the chart to show feature types setup by the admin
  $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
  $where = '';
  if ($temp) {
    $temp = explode("\n", $temp);
    foreach ($temp as $key => $value) {
      $temp2 = explode("=", $value);
      $feature_type = rtrim($temp2[0]);
      $where .= "CNT.feature_type = '$feature_type' OR \n";
    }
    if ($where) {
      $where = drupal_substr($where, 0, -5);  # remove OR from the end
      $where = "($where) AND";
    }
  }

  $organism_id = preg_replace("/^tripal_feature_cv_chart_(\d+)$/", "$1", $chart_id);

  // The CV module will create the JSON array necessary for buillding a
  // pie chart using jgChart and Google Charts.  We have to pass to it
  // a table that contains count information, tell it which column
  // contains the cvterm_id and provide a filter for getting the
  // results we want from the table.
  $options = array(
    count_mview      => 'organism_feature_count',
    cvterm_id_column => 'cvterm_id',
    count_column     => 'num_features',
    size             => '550x200',
    filter           => "$where CNT.organism_id = $organism_id",
  );
  return $options;
}
tripal_feature_cv_tree ( tree_id)

Definition at line 2110 of file tripal_feature.module.

                                          {

  // The CV module will create the JSON array necessary for buillding a
  // pie chart using jgChart and Google Charts.  We have to pass to it
  // a table that contains count information, tell it which column
  // contains the cvterm_id and provide a filter for getting the
  // results we want from the table.
  $organism_id = preg_replace("/^tripal_feature_cv_tree_(\d+)$/", "$1", $tree_id);
  $options = array(
    cv_id            => tripal_cv_get_cv_id('sequence'),
    count_mview      => 'organism_feature_count',
    cvterm_id_column => 'cvterm_id',
    count_column     => 'num_features',
    filter           => "CNT.organism_id = $organism_id",
    label            => 'Features',
  );
  return $options;
}
tripal_feature_del_vocabulary ( )

Definition at line 2136 of file tripal_feature.module.

                                         {
  //include the file containing the required functions for adding taxonomy vocabs
  module_load_include('inc', 'taxonomy', 'taxonomy.admin');

  // get the vocabularies
  $vocabularies = taxonomy_get_vocabularies();

  // These taxonomic terms are hard coded because we
  // know we have these relationships in the chado tables
  // through foreign key relationships.  The tripal
  // modules that correspond to these chado "modules" don't
  // need to be installed for the taxonomy to work.
  foreach ($vocabularies as $vocab) {
    if ($vocab->name == 'Feature Type') {
      taxonomy_del_vocabulary($vocab->vid);
    }
    if ($vocab->name == 'Organism') {
      taxonomy_del_vocabulary($vocab->vid);
    }
    if ($vocab->name == 'Library') {
      taxonomy_del_vocabulary($vocab->vid);
    }
    if ($vocab->name == 'Analysis') {
      taxonomy_del_vocabulary($vocab->vid);
    }
  }

}
tripal_feature_delete_db_reference ( dbxref_id)

Definition at line 292 of file tripal_feature-db_references.inc.

                                                        {

  chado_query(
    "DELETE FROM {dbxref} WHERE dbxref_id=%d",
    $dbxref_id
  );

  chado_query(
    "DELETE FROM {feature_dbxref} WHERE dbxref_id=%d",
    $dbxref_id
  );
}
tripal_feature_delete_relationship ( stock_relationship_id)

Definition at line 482 of file tripal_feature-relationships.inc.

                                                                    {

  $previous_db = db_set_active('chado');
  db_query(
    "DELETE FROM {stock_relationship} WHERE stock_relationship_id=%d",
    $stock_relationship_id
  );
  db_set_active($previous_db);

}
tripal_feature_edit_ALL_db_references_form ( form_state,
node 
)

Implements Hook_form() Handles adding of DB References to Features

Definition at line 166 of file tripal_feature-db_references.inc.

                                                                        {
  $form = array();

  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid
  );

  $i=0;

  $feature = $node->feature;
  $references = tripal_feature_load_references($feature->feature_id);

  // pre populate the database options
  $db_options = tripal_db_get_db_options();
  $db_options[0] = 'Select a Database';
  ksort($db_options);

  if (sizeof($references) != 0) {
    foreach ($references as $ref) {
      $i++;
      $form["num-$i"] = array(
        '#type' => 'fieldset',
        '#title' => t("Database Reference") . " $i"
      );

      $form["num-$i"]["accession-$i"] = array(
        '#type' => 'textfield',
        '#title' => t('Accession'),
        '#size' => 30,
        '#required' => TRUE,
        '#default_value' => $ref->accession
      );

      $form["num-$i"]["db_id-$i"] = array(
        '#type' => 'select',
        '#title' => t('Database'),
        '#options' => $db_options,
        '#required' => TRUE,
        '#default_value' => $ref->db_id
      );


      $form["num-$i"]["dbxref_id-$i"] = array(
        '#type' => 'hidden',
        '#value' => $ref->dbxref_id
      );

      $form["num-$i"]["delete-$i"] = array(
        '#type' => 'submit',
        '#value' => t("Delete"),
        '#name' => "delete-$i",
      );

      }

      $form['num_db_references'] = array(
        '#type' => 'hidden',
        '#value' => $i
      );

      $form["submit-edits"] = array(
        '#type' => 'submit',
        '#value' => t('Update All References')
      );
  } //end of foreach db ref
  return $form;
}
tripal_feature_edit_ALL_db_references_form_submit ( form,
&$  form_state 
)

Definition at line 240 of file tripal_feature-db_references.inc.

                                                                                {

  $num_refs = $form_state['values']['num_db_references'];
  $action = $form_state['clicked_button']['#value'];
  $button = $form_state['clicked_button']['#name'];
  $nid = $form_state['values']['nid'];

  if (strcmp($action, 'Update All References')==0) {
    for ($i=1; $i<=$num_refs; $i++) {
    $dbxref_id = $form_state['values']["dbxref_id-$i"];
    $db_id = $form_state['values']["db_id-$i"];
    $accession = $form_state['values']["accession-$i"];
      tripal_feature_update_db_reference($dbxref_id, $db_id, $accession);
    }
    drupal_set_message(t("Updated all Database References"));
    drupal_goto('node/' . $nid);
  }
  elseif (strcmp($action, 'Delete')==0) {
    if (preg_match('/delete-(\d+)/', $button, $matches) ) {
      $i = $matches[1];
      $dbxref_id = $form_state['values']["dbxref_id-$i"];
      tripal_feature_delete_db_reference($dbxref_id);
      drupal_set_message(t("Deleted Database Reference"));
      drupal_goto('node/' . $nid);
    }
    else {
      drupal_set_message(t("Could not remove database reference:"), 'error');
    }
    }
  else {
    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
  }

}
tripal_feature_edit_ALL_dbreferences_page ( node)

Definition at line 148 of file tripal_feature-db_references.inc.

                                                          {
  $output = '';

  $output .= drupal_get_form('tripal_feature_edit_ALL_db_references_form', $node);
  $output .= '<br />';
  $output .= drupal_get_form('tripal_feature_add_ONE_dbreference_form', $node);
  $output .= '<br />';
  $output .= drupal_get_form('tripal_feature_implement_back_to_feature_button', $node->nid);

  return $output;
}
tripal_feature_edit_ALL_properties_form ( form_state,
node,
properties 
)

Implements Hook_form() Handles adding of Properties for features

Definition at line 145 of file tripal_feature-properties.inc.

                                                                                  {
  $form = array();
  $feature_id = $node->feature->feature_id;

  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid
  );

  $form['add_properties']['feature_id'] = array(
    '#type' => 'value',
    '#value' => $feature_id,
    '#required' => TRUE
  );

  // right now this defaults to the 'feature_property' CV
  // but in the future it should be more flexible
  $form['cv_name'] = array(
    '#type' => 'hidden',
    '#value' => 'feature_property'
  );

  if (sizeof($properties)) {

    // build the select box options for the property name
    $prop_type_options = array();
    $columns = array('cvterm_id', 'name');
    $values = array(
      'cv_id' => array(
        'name' => $form['cv_name']['#value']
      )
    );
    $results = tripal_core_chado_select('cvterm', $columns, $values);
    foreach ($results as $r) {
      $prop_type_options[$r->name] = $r->name;
    }

    // iterate through all of the properties and create a set of form elements
  foreach ($properties as $i => $property) {
    $form["num-$i"] = array(
      '#type' => 'fieldset',
      '#value' => "Property $i"
    );
    $form["num-$i"]["id-$i"] = array(
      '#type' => 'hidden',
      '#value' => $property->featureprop_id
    );
    $default = array_search($property->type, $prop_type_options);
    $form["num-$i"]["type-$i"] = array(
      '#type' => 'select',
      '#options' => $prop_type_options,
      '#default_value' => $property->type_id->name
    );
    $form["num-$i"]["value-$i"] = array(
      '#type' => 'textfield',
      '#default_value' => $property->value
    );
    $form["num-$i"]["delete-$i"] = array(
      '#type' => 'submit',
      '#value' => t("Delete"),
      '#name' => "delete-$i",
    );
    } //end of foreach property

    $form['num_properties'] = array(
      '#type' => 'hidden',
      '#value' => $i
    );

    $form["submit-edits"] = array(
      '#type' => 'submit',
      '#value' => t('Update All Properties')
    );
  }

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

Definition at line 228 of file tripal_feature-properties.inc.

                                                                             {

  $cv_name = $form_state['values']['cv_name'];
  $feature_id = $form_state['values']["feature_id"];
  $all_good = 1;

  // if the update button was clicked then do the update
  if ($form_state['clicked_button']['#value'] == t('Update All Properties') ) {
    // iterate through each of the properties and set each one
    for ($i=1; $i<=$form_state['values']['num_properties']; $i++) {
      $featureprop_id = $form_state['values']["id-$i"];
      $property = $form_state['values']["type-$i"];
      $value = $form_state['values']["value-$i"];
      $success = tripal_feature_update_property_by_id($featureprop_id, $property, $value, $cv_name);
      if (!$success) {
        drupal_set_message(t("Failed to Update Property: %property => %value", array('%property' => $property), array('%value' => $value)));
        $all_good = 0;
      }
    }
    if ($all_good) {
      drupal_set_message(t("Updated all Properties"));
    }
    drupal_goto('node/' . $form_state['values']['nid']);
  }
  // if the delete button was clicked then remove the property
  elseif (preg_match('/delete-(\d+)/', $form_state['clicked_button']['#name'], $matches) ) {
    $i = $matches[1];
    $featureprop_id = $form_state['values']["id-$i"];
    $property = $form_state['values']["type-$i"];
    $value = $form_state['values']["value-$i"];
    $success = tripal_feature_delete_property_by_id($featureprop_id);
    if ($success) {
      drupal_set_message(t("Deleted Property"));
    }
    else {
      drupal_set_message(t("Unable to Delete Property"));
    }
  }
  else {
    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
  }
}
tripal_feature_edit_ALL_properties_page ( node)

Definition at line 12 of file tripal_feature-properties.inc.

                                                        {
  $output = '';

  // get the list of properties for this feature
  $values  = array('feature_id' => $node->feature->feature_id);
  $options = array('order_by' => array('type_id' => 'ASC', 'rank' => 'ASC'));
  $properties = tripal_core_generate_chado_var('featureprop', $values, $options);
  $properties = tripal_core_expand_chado_vars($properties, 'field', 'featureprop.value');

  $expand_add = (sizeof($properties)) ? FALSE : TRUE;

  // add the appopriate form sections
  $output .= drupal_get_form('tripal_feature_add_ONE_property_form', $node, $expand_add);
  $output .= drupal_get_form('tripal_feature_edit_ALL_properties_form', $node, $properties);
  $output .= drupal_get_form('tripal_feature_implement_back_to_feature_button', $node->nid);

  return $output;
}
tripal_feature_edit_ALL_relationships_form ( form_state,
node 
)

Implements Hook_form() Handles adding of Properties & Synonyms to Stocks

Definition at line 229 of file tripal_feature-relationships.inc.

                                                                        {
  $form = array();

  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $node->nid
  );

  $form['r_feature_uniquename'] = array(
    '#type' => 'hidden',
    '#value' => $node->uniquename
  );

  $i=0;

  $feature = $node->feature;
  $orelationships = tripal_feature_load_relationships($feature->feature_id, 'as_object');
  $srelationships = tripal_feature_load_relationships($feature->feature_id, 'as_subject');
  $relationships = array_merge($orelationships, $srelationships);

  if (sizeof($relationships) != 0) {
    foreach ($relationships as $r) {

      $i++;
      $form["num-$i"] = array(
        '#type' => 'fieldset',
        '#title' => t("Relationship %i", array('%i' => $i)),
      );

      $form["num-$i"]["id-$i"] = array(
        '#type' => 'hidden',
        '#value' => $r->stock_relationship_id
      );

      //Enter relationship specific fields
      if ( !empty($r->subject_id) ) {
        $default = $r->subject_uniquename;
        $description = l($r->subject_name, 'node/' . $r->subject_nid);
      }
      else {
        $default = $node->uniquename;
        $description = "Current Feature";
      }
      $description .= " (" . $r->subject_type . ")";
      $form["num-$i"]["subject_id-$i"] = array(
        '#type' => 'textfield',
        //'#title' => t('Subject'),
        '#required'   => TRUE,
        '#size' => 30,
        '#default_value' => $default,
        '#description' => t('%description', array('%description' => $description)),
      );

      $cv = tripal_cv_get_cv_by_name('relationship');
      $type_options = tripal_cv_get_cvterm_options($cv->cv_id);
      ksort($type_options);
      $form["num-$i"]["type_id-$i"] = array(
        '#type' => 'select',
        //'#title' => t('Type of Relationship'),
        '#options' => $type_options,
        '#required' => TRUE,
        '#default_value' => $r->relationship_type_id
      );

      if (!empty($r->object_id) ) {
        $default = $r->object_uniquename;
        $description = l($r->object_name, 'node/' . $r->object_nid);
      }
      else {
        $default = $node->uniquename;
        $description = 'Current Feature';
      }
      $description .= " (" . $r->object_type . ")";
      $form["num-$i"]["object_id-$i"] = array(
        '#type' => 'textfield',
        //'#title' => t('Object'),
        '#required'   => TRUE,
        '#size' => 30,
        '#default_value' => $default,
        '#description' => $description
      );

      $form["num-$i"]["delete-$i"] = array(
        '#type' => 'submit',
        '#value' => t("Delete"),
        '#name' => "delete-$i",
      );

    } //end of foreach relationship
    $form['num_relationships'] = array(
      '#type' => 'hidden',
      '#value' => $i
    );

    $form["submit-edits"] = array(
      '#type' => 'submit',
      '#value' => t('Update All Relationships')
    );
  }
  else {
    $form["info"] = array(
      '#type' => 'markup',
      '#value' => t('No relationships currently exist for this feature.')
    );
  }

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

Definition at line 424 of file tripal_feature-relationships.inc.

                                                                                {

  if ($form_state['clicked_button']['#value'] == t('Update Relationships') ) {
    //Update all
    for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {

      //process stock textfields
      tripal_feature_update_relationship(
        $form_state['values']["id-$i"],
        $form_state['values']["subject_id-$i"],
        $form_state['values']["type_id-$i"],
        $form_state['values']["object_id-$i"]
      );
    }
    drupal_set_message(t("Updated all Relationships"));
    drupal_goto('node/' . $form_state['values']['nid']);

  }
  elseif ( preg_match('/Delete #(\d+)/', $form_state['clicked_button']['#value'], $matches) ) {

    $i = $matches[1];
    tripal_feature_delete_relationship($form_state['values']["id-$i"]);
    drupal_set_message(t("Deleted Relationship"));

  }
  elseif ($form_state['clicked_button']['#value'] == t('Back to Stock') ) {
    drupal_goto('node/' . $form_state['values']['nid']);
  }
  else {
    drupal_set_message(t("Unrecognized Button Pressed"), 'error');
  }

}
tripal_feature_edit_ALL_relationships_form_validate ( form,
&$  form_state 
)

Definition at line 343 of file tripal_feature-relationships.inc.

                                                                                  {

  // Only Require if Updating Relationships
  if ($form_state['clicked_button']['#value'] == t('Update All Relationships') ) {

    for ($i=1; $i<=$form_state['values']['num_relationships']; $i++) {

      // check valid stock selected for subject
      $criteria = array('unknown' => array('value' => $form_state['values']["subject_id-$i"],
                                          'columns' => array('name', 'uniquename', 'accession', 'synonym') ));
      $subject_results = get_chado_stocks($criteria, 'ANY', $_SESSION['organism']);
      if (sizeof($subject_results) > 1) {
        $links= array();
        for ($j=0; $j<sizeof($subject_results); $j++) {
        $links[] = l($j+1, "node/" . $subject_results[$j]->nid); }
        $message = t("Too many features match '%subject'!  Please refine your input to
          match ONLY ONE feature. <br /> To aid in this process, here are the features that
          match your initial input: %features",
          array('%subject' => $form_state['values']["subject_id-$i"],
            '%features' => join(', ', $links)
          )
        );
        form_set_error("subject_id-$i", $message);
      }
      elseif (sizeof($subject_results) < 1) {
        form_set_error("subject_id-$i", t("There are no features matching your input. Please check your input for typos and/or lookup the <a href='!url'>here</a>", array('!url' => url('features'))));
      }
      elseif (sizeof($subject_results) == 1) {
        $form_state['values']["subject_id-$i"] = $subject_results[0]->stock_id;
      }

      // check valid stock selected for object
      $criteria = array('unknown' => array('value' => $form_state['values']["object_id-$i"],
                                          'columns' => array('name', 'uniquename', 'accession', 'synonym') ));
      $object_results = get_chado_stocks($criteria, 'ANY' , $_SESSION['organism']);
      if (sizeof($object_results) > 1) {
        $links= array();
        for ($j=0; $j<sizeof($object_results); $j++) {
        $links[] = l($j+1, "node/" . $object_results[$j]->nid); }
        $message = "Too many stocks match '" . $form_state['values']["object_id-$i"] . "'! "
                 . "Please refine your input to match ONLY ONE stock. <br />"
                 . "To aid in this process, here are the stocks that match your initial input: "
                 . join(', ', $links);
        form_set_error("object_id-$i", $message);
      }
      elseif (sizeof($object_results) < 1) {
        form_set_error("object_id-$i", t("There are no features matching your input. Please check your input for typos and/or lookup the <a href='!url'>here</a>", array('!url' => url('features'))));
      }
      elseif (sizeof($object_results) == 1) {
        $form_state['values']["object_id-$i"] = $object_results[0]->stock_id;
      }

      // check valid type selected
      if ($form_state['values']["type_id-$i"] == 0) {
        form_set_error('type_id', 'Please select a type of relationship.');
      }
      else {
        $tmp_obj = db_fetch_object(chado_query("SELECT count(*) as count FROM {cvterm} WHERE cvterm_id=%d" , $form_state['values']["type_id-$i"]));

        if ($tmp_obj->count != 1) {
          form_set_error("type_id-$i", 'The type you selected is not valid. Please choose another one.');
        }
      }

      // check either subject or object is the current stock
      if ( $subject_results[0]->nid != $form_state['values']['nid'] ) {
        if ( $object_results[0]->nid != $form_state['values']['nid'] ) {
          form_set_error("subject_id-$i", 'Either Subject or Object must be the current stock (' . $form_state['values']['r_stock_uniquename'] . ').');
        }
      }

    } // end of for each relationship
  } //end of if updating relationships

}
tripal_feature_edit_ALL_relationships_page ( node)

Definition at line 211 of file tripal_feature-relationships.inc.

                                                           {
  $output = '';

  $output .= drupal_get_form('tripal_feature_edit_ALL_relationships_form', $node);
  $output .= '<br />';
  $output .= drupal_get_form('tripal_feature_add_ONE_relationship_form', $node);
  $output .= '<br />';
  $output .= drupal_get_form('tripal_feature_implement_back_to_feature_button', $node->nid);

  return $output;
}
tripal_feature_get_aggregate_relationships ( feature_id,
substitute = 1,
levels = 0,
base_type_id = NULL,
depth = 0 
)

Definition at line 1221 of file tripal_feature.module.

                                           {

  // we only want to recurse to as many levels deep as indicated by the
  // $levels variable, but only if this variable is > 0. If 0 then we
  // recurse until we reach the end of the relationships tree.
  if ($levels > 0 and $levels == $depth) {
    return NULL;
  }

  // first get the relationships for this feature
  $relationships = tripal_feature_load_relationships($feature_id, 'as_object');

  // next, iterate through these relationships and descend, adding in those
  // that are specified by the aggregator.
  $i=0;
  $new_relationships = array();
  foreach ($relationships as $rindex => $rel) {
    // set the base type id
    if (!$base_type_id) {
      $base_type_id = $rel->object_type_id;
    }
    // check to see if we have an aggregator for this base type
    $sql = "SELECT * FROM {tripal_feature_relagg} WHERE type_id = %d and rel_type_id = %d";
    $agg = db_fetch_object(db_query($sql, $base_type_id, $rel->subject_type_id));
    if ($agg) {
      // if we're not going to substitute the resulting relationships for the
      // parent then we need to add the parent to our list
      if (!$substitute) {
        $new_relationships[$i++] = $rel;
      }
      // recurse all relationships
      $agg_relationships = tripal_feature_get_aggregate_relationships(
        $rel->subject_id, $levels, $base_type_id, $depth++);
      // if we have an aggregate defined but we have no relationships beyond
      // this point then there's nothing we can substitute
      if (!$agg_relationships and $substitute) {
        $new_relationships[$i++] = $rel;
      }

      // merge all relationships into one array
      foreach ($agg_relationships as $aindex => $arel) {
        $new_relationships[$i++] = $arel;
      }
    }
    else {
      // if we don't have an aggregate then keep the current relationship
      $new_relationships[$i++] = $rel;
    }
    }
    return $new_relationships;
}
tripal_feature_get_custom_tables ( table = NULL)

This function defines the custom tables that will be created in the chado schema.

Definition at line 757 of file tripal_feature.api.inc.

                                                         {

 if (!$table or strcmp($table, 'tripal_gff_temp')==0) {
    $schema['tripal_gff_temp'] = array(
      'table' => 'tripal_gff_temp',
      'fields' => array(
        'feature_id' => array(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'organism_id' => array(
          'type' => 'int',
          'not null' => TRUE,
        ),
        'uniquename' => array(
          'type' => 'text',
          'not null' => TRUE,
        ),
        'type_name' => array(
          'type' => 'varchar',
          'length' => '1024',
          'not null' => TRUE,
        ),
      ),
      'indexes' => array(
        'tripal_gff_temp_idx0' => array('feature_id'),
        'tripal_gff_temp_idx0' => array('organism_id'),
        'tripal_gff_temp_idx1' => array('uniquename'),
      ),
      'unique keys' => array(
        'tripal_gff_temp_uq0' => array('feature_id'),
        'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
      ),
    );
  }
  return $schema;
}
tripal_feature_get_matched_alignments ( feature)

Definition at line 1400 of file tripal_feature.module.

                                                         {
  // This function is for features that align through an intermediate such
  // as 'EST_match' or 'match'.  This occurs in the case where two sequences
  // align but where one does not align perfectly.  Some ESTs may be in a contig
  // but not all of the EST.  Portions may overhang and not be included in the 
  // consensus if quality is bad.
  // For example:
  //
  //    Feature 1: Contig --------------------
  //    Feature 2: EST_match           -------
  //    Feature 3: EST                 ---------
  //
  // The feature provided to the function will always be the feature 1.  The 
  // featureloc columns prefixed with 'right' (e.g. right_fmin) belong to the 
  // alignment of feature 3 with feature 2
  // 
  // Features may align to more than one feature and are not matches. We do
  // not want to include these, so we have to filter on the SO terms:
  // match, or %_match
  //
   $sql = "SELECT  ".
          "   FL1.featureloc_id    as left_featureloc_id, ".
          "   FL1.srcfeature_id    as left_srcfeature_id, ".
          "   FL1.feature_id       as left_feature_id, ".
          "   FL1.fmin             as left_fmin, ".
          "   FL1.is_fmin_partial  as left_is_fmin_partial, ".
          "   FL1.fmax             as left_fmax, ".
          "   FL1.is_fmax_partial  as left_is_fmax_partial, ".
          "   FL1.strand           as left_strand,  ".
          "   FL1.phase            as left_phase, ".
          "   FL1.locgroup         as left_locgroup, ".
          "   FL1.rank             as left_rank, ".
          "   FL2.featureloc_id    as right_featureloc_id, ".
          "   FL2.srcfeature_id    as right_srcfeature_id, ".
          "   FL2.feature_id       as right_feature_id, ".
          "   FL2.fmin             as right_fmin, ".
          "   FL2.is_fmin_partial  as right_is_fmin_partial, ".
          "   FL2.fmax             as right_fmax, ".
          "   FL2.is_fmax_partial  as right_is_fmax_partial, ".
          "   FL2.strand           as right_strand,  ".
          "   FL2.phase            as right_phase, ".
          "   FL2.locgroup         as right_locgroup, ".
          "   FL2.rank             as right_rank ".
          "FROM feature F1 ".
          "  INNER JOIN featureloc FL1 on FL1.srcfeature_id = F1.feature_id ".
          "  INNER JOIN feature F2 on FL1.feature_id = F2.feature_id ".
          "  INNER JOIN featureloc FL2 on FL2.feature_id = F2.feature_id ".
          "  INNER JOIN feature F3 on FL2.srcfeature_id = F3.feature_id ".
          "  INNER JOIN cvterm CVT2 on F2.type_id = CVT2.cvterm_id ".
          "WHERE F1.feature_id = %d and NOT F3.feature_id = %d ".
          "  AND (CVT2.name = 'match' or CVT2.name like '%_match') ".
          "ORDER BY FL1.fmin";

   $results = chado_query($sql, $feature->feature_id, $feature->feature_id);
   
   // iterate through the results and add them to our featurelocs array
   $featurelocs = array();
   while ($fl = db_fetch_object($results)) {
      $featurelocs[] = $fl ;
   }   
   return $featurelocs;
}
tripal_feature_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 69 of file tripal_feature.module.

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

Definition at line 79 of file tripal_feature-secondary_tables.inc.

                                                                                          {
  $form = array();

  $form['current_step'] = array(
    '#type' => 'hidden',
    '#value' => $step
  );

  // Use this field to set all the steps and the path to each form
  // where each step is of the form name;path and each step is separated by ::
  $steps =array(
    'properties' => 'node/%node/properties',
    'db_references' => 'node/%node/db_references',
    'relationships' => 'node/%node/relationships'
  );
  $steps_value = array();
  foreach ($steps as $k => $v) {
  $steps_value[] = $k . ';' . $v; }
  $form['steps'] = array(
    '#type' => 'hidden',
    '#value' => implode('::', $steps_value)
  );

  $form['first_step'] = array(
    '#type' => 'hidden',
    '#value' => 'properties'
  );

  $form['last_step'] = array(
    '#type' => 'hidden',
    '#value' => 'relationships'
  );

  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $nid
  );

  if ($step != $form['first_step']['#value']) {
    $form['submit-prev'] = array(
      '#type' => 'submit',
      '#value' => t('Previous Step')
    );
  }

  if ($step != $form['last_step']['#value']) {
    $form['submit-next'] = array(
      '#type' => 'submit',
      '#value' => t('Next Step')
    );
  }

  if ($step == $form['last_step']['#value']) {
    $form['submit-finish'] = array(
      '#type' => 'submit',
      '#value' => t('Finish')
    );
  }

  return $form;
}
tripal_feature_implement_add_chado_properties_navigate_submit ( form,
form_state 
)

Definition at line 146 of file tripal_feature-secondary_tables.inc.

                                                                                           {

  $raw_steps = preg_split('/::/', $form_state['values']['steps']);

  $steps = array();
  $current_index = 'EMPTY';
  $i=0;

  foreach ($raw_steps as $raw_step) {
    $step = preg_split('/;/', $raw_step);
    $steps[$i] = $step;

    if ($step[0] == $form_state['values']['current_step']) {
      $current_index = $i;
    }

    $i++;
  }
  $num_steps = $i;

  if (strcmp($current_index, 'EMPTY') == 0) {
    // No Matching Step
    drupal_set_message(t('Could not determine next step - %currentstep, please contact the administrator', array('%currentstep' => $form_state['values']['current_step'])), 'error');
  }
  elseif ($current_index == 0) {
    $next_goto = $steps[$current_index+1][1];
  }
  elseif ($current_index == ($num_steps-1)) {
    $prev_goto = $steps[$current_index-1][1];
    $next_goto = 'node/%node';
  }
  else {
    $prev_goto = $steps[$current_index-1][1];
    $next_goto = $steps[$current_index+1][1];
  }

  if ($form_state['clicked_button']['#value'] == t('Previous Step') ) {
    //replace %node
    $prev_goto = preg_replace('/%node/', $form_state['values']['nid'], $prev_goto);
    $_REQUEST['destination'] = $prev_goto;
  }
  elseif ($form_state['clicked_button']['#value'] == t('Next Step') ) {
    $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
    $_REQUEST['destination'] = $next_goto;
  }
  elseif ($form_state['clicked_button']['#value'] == t('Finish') ) {
    $next_goto = preg_replace('/%node/', $form_state['values']['nid'], $next_goto);
    $_REQUEST['destination'] = $next_goto;
  }

}
tripal_feature_implement_add_chado_properties_progress ( current)

Definition at line 42 of file tripal_feature-secondary_tables.inc.

                                                                          {

    $value = '<div class="form_progress"><div class="form_progress-text">';

    if ($current == 'main') {
    $value .= '<span id="form-step-current">Create Basic Feature</span>'; }
    else { $value .= '<span id="form-step">Create Basic Stock</span>'; }

    $value .= '<span id="form-segway">  >>  </span>';

    if ($current == 'properties') {
    $value .= '<span id="form-step-current">Add Synonyms & Properties</span>'; }
    else { $value .= '<span id="form-step">Add Synonyms & Properties</span>'; }

    $value .= '<span id="form-segway">  >>  </span>';

    if ($current == 'db_references') {
    $value .= '<span id="form-step-current">Add Database References</span>'; }
    else { $value .= '<span id="form-step">Add Database References</span>'; }

    $value .= '<span id="form-segway">  >>  </span>';

    if ($current == 'relationships') {
    $value .= '<span id="form-step-current">Add Relationships</span>'; }
    else { $value .= '<span id="form-step">Add Relationships</span>'; }

    $value .= '</div></div>';

    return $value;

}
tripal_feature_implement_back_to_feature_button ( form_state,
nid 
)

Definition at line 12 of file tripal_feature-secondary_tables.inc.

                                                                            {
  $form = array();

  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $nid
  );

  $form["submit-back"] = array(
    '#type' => 'submit',
    '#value' => t('Back to Stock')
  );

  return $form;
}
tripal_feature_implement_back_to_feature_button_submit ( form,
form_state 
)

Definition at line 33 of file tripal_feature-secondary_tables.inc.

                                                                                    {
  drupal_goto('node/' . $form_state['values']['nid']);
}
tripal_feature_index_feature ( feature_id,
nid 
)

Definition at line 137 of file indexFeatures.inc.

                                                         {
  #print "\tfeature $feature_id nid $nid\n";
  // return if we haven't been provided with a feature_id
  if (!$feature_id) {
    return 0;
  }

  // if we only have a feature_id then let's find a corresponding
  // node.  If we can't find a node then return.
  if (!$nid) {
    $nsql = "SELECT N.nid,N.title FROM {chado_feature} CF ".
            "  INNER JOIN {node} N ON N.nid = CF.nid ".
            "WHERE CF.feature_id = %d";
    $node = db_fetch_object(db_query($nsql, $feature_id));
    if (!$node) {
      return 0;
    }
    $node = node_load($node->nid);
  }
  else {
    $node = node_load($nid);
  }

  // node load the noad, the comments and the taxonomy and
  // index
  $node->build_mode = NODE_BUILD_SEARCH_INDEX;
  $node = node_build_content($node, FALSE, FALSE);
  $node->body = drupal_render($node->content);
  node_invoke_nodeapi($node, 'view', FALSE, FALSE);
  //   $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index');
  //   $node->body .= module_invoke('taxonomy','nodeapi', $node, 'update index');
  //   print "$node->title: $node->body\n";
  search_index($node->nid, 'node', $node->body);

  # $mem = memory_get_usage(TRUE);
  # $mb = $mem/1048576;
  # print "$mb mb\n";

  return 1;
}
tripal_feature_init ( )

Definition at line 35 of file tripal_feature.module.

                               {

  drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_feature.js');
  drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_feature.css');
}
tripal_feature_is_obsolete_form ( node,
stock_id 
)

Implements Hook_form() Handles setting the is_obsolete property of stocks

Definition at line 204 of file tripal_feature-secondary_tables.inc.

                                                           {

  $form['make_obsolete'] = array(
    '#type' => 'submit',
    '#value' => t('Mark Stock as Obsolete')
  );

  $form['make_obsolete_stock_id'] = array(
    '#type' => 'value',
    '#value' => $stock_id,
    '#required' => TRUE
  );

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

Definition at line 225 of file tripal_feature-secondary_tables.inc.

                                                                     {

  $previous_db = db_set_active('chado');
  db_query(
    "UPDATE {stock} SET is_obsolete='t' WHERE stock_id=%d",
    $form_state['values']['make_obsolete_stock_id']
  );
  db_set_active($previous_db);

}
tripal_feature_job_describe_args ( callback,
args 
)

Definition at line 2184 of file tripal_feature.module.

                                                            {

  $new_args = array();
  if ($callback == 'tripal_feature_load_fasta') {
    $new_args['FASTA file'] = $args[0];
    $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
    $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
    $new_args['Sequence Type'] = $args[2];
    $new_args['Name Match Type'] = $args[14];
    $new_args['Name RE'] = $args[4];
    $new_args['Unique Name RE'] = $args[5];   

    // add in the relationship arguments
    $new_args['Relationship Type'] = $args[8];
    $new_args['Relationship Parent RE'] = $args[9];
    $new_args['Relationship Parent Type'] = $args[10];

    // add in the database reference arguments
    if ($args[7]) {
      $db = tripal_core_chado_select('db', array('name'), array('db_id' => $args[7]));
    }
    $new_args['Database Reference'] = $db[0]->name;
    $new_args['Accession RE'] = $args[6];
    $new_args['Method'] = $args[11];

    // add in the analysis
    if ($args[13]) {
      $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[13]));
    }
    $new_args['Analysis'] = $analysis[0]->name;
  }
  if ($callback == 'tripal_feature_delete_features') {
    if ($args[0]) {
      $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
      $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
    }
    else {
      $new_args['Organism'] = '';
    }

    if ($args[1]) {
      $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[1]));
      $new_args['Analysis'] = $analysis[0]->name;
    }
    else {
      $new_args['Analysis'] = '';
    }

    $new_args['Sequence Type'] = $args[2];
    $new_args['Is Unique Name'] = $args[3];
    $new_args['Features Names'] = $args[4];

  }
  elseif ($callback == 'tripal_feature_load_gff3') {
    
    $new_args['GFF File'] = $args[0];
    $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[1]));
    $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
    $analysis = tripal_core_chado_select('analysis', array('name'), array('analysis_id' => $args[2]));
    $new_args['Analysis'] = $analysis[0]->name;   
    $new_args['Use a Transaction'] = ($args[7] == 1) ? "Yes" : "No";
    $new_args['Import only new features'] = ($args[3] == 1) ? "Yes" : "No";
    $new_args['Import all and update'] = ($args[4] == 1) ? "Yes" : "No";
    $new_args['Import all and replace'] = ($args[5] == 1) ? "Yes" : "No";
    $new_args['Delete features'] = ($args[6] == 1) ? "Yes" : "No";
    $target_organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[8]));
    $new_args['Target organism'] = $target_organism[0]->genus . " " . $target_organism[0]->species;
    $new_args['Target type'] = $args[9];
    $new_args['Create target'] = ($args[10] == 1) ? "Yes" : "No";
    $new_args['Starting line'] = $args[11];
    $new_args['Landmark Type'] = $args[12];
    $new_args['Alternate ID attribute'] = $args[13];
  }
  if ($callback == 'tripal_feature_sync_features') {
    if ($args[0]) {
      $organism = tripal_core_chado_select('organism', array('genus', 'species'), array('organism_id' => $args[0]));
      $new_args['Organism'] = $organism[0]->genus . " " . $organism[0]->species;
    }
    else {
      $new_args['Organism'] = '';
    }
    $new_args['Feature Types'] = $args[1];
  }
  return $new_args;
}
tripal_feature_list_properties_for_node ( properties)

Definition at line 304 of file tripal_feature-properties.inc.

                                                              {

  if (!empty($properties)) {
    $output = '<table>';
    $output .= '<tr><th>Type</th><th>Value</th></tr>';


    if (!empty($properties) ) {
      foreach ($properties as $p) {
        $output .= '<tr><td>' . $p->type . '</td><td>' . $p->value . '</td></tr>';
      } // end of foreach property
    }

    $output .= '</table>';

  }
  else {
    $output = 'No properties exist for the current feature';
  }

  return $output;
}
tripal_feature_list_relationships_for_node ( feature_name,
subject_relationships,
object_relationships 
)

Definition at line 529 of file tripal_feature-relationships.inc.

                                                                                                                  {

  if (!empty($subject_relationships) OR !empty($object_relationships) ) {
    $output = '<table>';
    $output .= '<tr><th>Subject</th><th>Relationship Type</th><th>Object</th></tr>';

    if (!empty($subject_relationships) ) {
      foreach ($subject_relationships as $s) {
        $output .= '<tr><td>' . $s->subject_name . '</td><td>' . $s->relationship_type . '</td><td>' . $feature_name . '</td></tr>';
      }
    }

    if (!empty($object_relationships) ) {
      foreach ($object_relationships as $o) {
        $output .= '<tr><td>' . $feature_name . '</td><td>' . $o->relationship_type . '</td><td>' . $o->object_name . '</td></tr>';
      } // end of foreach property
    }

    $output .= '</table>';
  }
  else {
    $output = 'No Relationships For the Current Feature';
  }

  return $output;

}
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.

Definition at line 1665 of file tripal_feature.module.

                                                                 {

  // 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 );
}
tripal_feature_load_featureloc_sequences ( feature_id,
featurelocs 
)

Definition at line 1278 of file tripal_feature.module.

                                                                             {

  // if we don't have any featurelocs then no point in continuing
  if (!$featurelocs) {
    return array();
  }

  // get the list of relationships (including any aggregators) and iterate
  // through each one to find information needed to color-code the reference sequence
  $relationships = tripal_feature_get_aggregate_relationships($feature_id);
  if (!$relationships) {
    return array();
  }


  // iterate through each of the realtionships features and get their
  // locations
  foreach ($relationships as $rindex => $rel) {
    // get the featurelocs for each of the relationship features
    $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
    foreach ($rel_featurelocs as $rfindex => $rel_featureloc) {
      // keep track of this unique source feature
      $src = $rel_featureloc->src_feature_id ."-". $rel_featureloc->src_cvterm_id;

      // copy over the results to the relationship object.  Since there can
      // be more than one feature location for each relationship feature we
      // use the '$src' variable to keep track of these.
      $rel->featurelocs->$src->src_uniquename = $rel_featureloc->src_uniquename;
      $rel->featurelocs->$src->src_cvterm_id  = $rel_featureloc->src_cvterm_id;
      $rel->featurelocs->$src->src_cvname     = $rel_featureloc->src_cvname;
      $rel->featurelocs->$src->fmin           = $rel_featureloc->fmin;
      $rel->featurelocs->$src->fmax           = $rel_featureloc->fmax;
      $rel->featurelocs->$src->src_name       = $rel_featureloc->src_name;

      // keep track of the individual parts for each relationship
      $start = $rel->featurelocs->$src->fmin;
      $end   = $rel->featurelocs->$src->fmax;
      $type  = $rel->subject_type;
      $rel_locs[$src]['parts'][$start][$type]['start'] = $start;
      $rel_locs[$src]['parts'][$start][$type]['end']   = $end;
      $rel_locs[$src]['parts'][$start][$type]['type']  = $type;
    }
  }

  // the featurelocs array provided to the function contains the locations
  // where this feature is found.   We want to get the sequence for each
  // location and then annotate it with the parts found from the relationships
  // locations determiend above.
  $sql = "SELECT substring(residues from %d for %d) as residues ".
         "FROM {feature} ".
         "WHERE feature_id = %d";
  $floc_sequences = array();
  foreach ($featurelocs as $featureloc) {
   
    // build the src name so we can keep track of the different parts for each feature
    $src = $featureloc->srcfeature_id->feature_id ."-". $featureloc->srcfeature_id->type_id->cvterm_id;

    // orient the parts to the beginning of the feature sequence
    if (!empty($rel_locs[$src]['parts'])) {
      $parts = $rel_locs[$src]['parts'];
      $rparts = array();  // we will fill this up if we're on the reverse strand

      foreach ($parts as $start => $types) {
        foreach ($types as $type_name => $type) { 
          if ($featureloc->strand >= 0) {
             // this is on the forward strand.  We need to convert the start on the src feature to the 
             // start on this feature's sequence
             $parts[$start][$type_name]['start'] = $parts[$start][$type_name]['start'] - $featureloc->fmin;
             $parts[$start][$type_name]['end']   = $parts[$start][$type_name]['end'] - $featureloc->fmin;          
             $parts[$start][$type_name]['type']  = $type_name;
          } 
          else {
             // this is on the reverse strand.  We need to swap the start and stop and calculate from the 
             // begining of the reverse sequence
             $size = ($featureloc->fmax - $featureloc->fmin);
             $start_orig = $parts[$start][$type_name]['start'];
             $end_orig = $parts[$start][$type_name]['end'];
             $new_start = $size - ($end_orig - $featureloc->fmin);
             $new_end = $size - ($start_orig - $featureloc->fmin);
             
             $rparts[$new_start][$type_name]['start'] = $new_start;
             $rparts[$new_start][$type_name]['end']   = $new_end;
             $rparts[$new_start][$type_name]['type']  = $type_name;
          }
        }
      }
      
      // now sort the parts
      // if we're on the reverse strand we need to resort
      if ($featureloc->strand >= 0) {
        usort($parts, 'tripal_feature_sort_rel_parts_by_start');         
      } 
      else {
        usort($rparts, 'tripal_feature_sort_rel_parts_by_start');
        $parts = $rparts;
      }
      
      $floc_sequences[$src]['src'] = $src;
      $floc_sequences[$src]['type'] = $featureloc->feature_id->type_id->name;
      $sequence = db_fetch_object(chado_query($sql, $featureloc->fmin + 1, ($featureloc->fmax - $featureloc->fmin), $featureloc->srcfeature_id->feature_id));
      $residues = $sequence->residues;
      if ($featureloc->strand < 0) {
         $residues = tripal_feature_reverse_complement($residues);
      }
      $strand = '.';
      if ($featureloc->strand == 1) {
        $strand = '+';
      }
      elseif ($featureloc->strand == -1) {
        $strand = '-';
      }
      $defline = $featureloc->feature_id->name . " " . $featureloc->srcfeature_id->name . ":" . ($featureloc->fmin + 1) . ".." . $featureloc->fmax . " " . $strand;
      $floc_sequences[$src]['formatted_seq'] =  tripal_feature_color_sequence($residues, $parts, $defline);
    }
  }
  return $floc_sequences;
}
tripal_feature_load_featurelocs ( feature_id,
side = 'as_parent',
aggregate = 1 
)

Definition at line 1090 of file tripal_feature.module.

                                                                                           {

  $sql = "SELECT
           F.name, F.feature_id, F.uniquename,
           FS.name as src_name,
           FS.feature_id as src_feature_id,
           FS.uniquename as src_uniquename,
           CVT.name as cvname, CVT.cvterm_id,
           CVTS.name as src_cvname, CVTS.cvterm_id as src_cvterm_id,
           FL.fmin, FL.fmax, FL.is_fmin_partial, FL.is_fmax_partial,FL.strand,
           FL.phase
         FROM {featureloc} FL
            INNER JOIN {feature} F on FL.feature_id = F.feature_id
            INNER JOIN {feature} FS on FS.feature_id = FL.srcfeature_id
            INNER JOIN {cvterm} CVT on F.type_id = CVT.cvterm_id
            INNER JOIN {cvterm} CVTS on FS.type_id = CVTS.cvterm_id
         ";
  if (strcmp($side, 'as_parent')==0) {
    $sql .= "WHERE FL.srcfeature_id = %d ";
  }
  if (strcmp($side, 'as_child')==0) {
    $sql .= "WHERE FL.feature_id = %d ";
  }

  $flresults = chado_query($sql, $feature_id);

  // copy the results into an array
  $i=0;
  $featurelocs = array();
  while ($loc = db_fetch_object($flresults)) {
    // if a drupal node exists for this feature then add the nid to the
    // results object
    $sql = 'SELECT nid FROM {chado_feature} WHERE feature_id = %d';

    $ffeature = db_fetch_object(db_query($sql, $loc->feature_id));
    $sfeature = db_fetch_object(db_query($sql, $loc->src_feature_id));
    $loc->fnid = $ffeature->nid;
    $loc->snid = $sfeature->nid;
    // add the result to the array
    $featurelocs[$i++] = $loc;
  }

  // Add the relationship feature locs if aggregate is turned on
  if ($aggregate and strcmp($side, 'as_parent')==0) {
    // get the relationships for this feature without substituting any children
    // for the parent. We want all relationships
    $relationships = tripal_feature_get_aggregate_relationships($feature_id, 0);
    foreach ($relationships as $rindex => $rel) {
      // get the featurelocs for each of the relationship features
      $rel_featurelocs = tripal_feature_load_featurelocs($rel->subject_id, 'as_child', 0);
      foreach ($rel_featurelocs as $findex => $rfloc) {
        $featurelocs[$i++] = $rfloc;
      }
    }
  }

  usort($featurelocs, 'tripal_feature_sort_locations');
  return $featurelocs;
}
tripal_feature_load_library_feature_browser ( library)

This generates the Feature Browser 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.

Definition at line 1603 of file tripal_feature.module.

                                                               {

  // 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_library_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 {library_feature} LF on F.feature_id = LF.feature_id ".
            "  INNER JOIN {library} L on LF.library_id = L.library_id ".
          "WHERE LF.library_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 {library_feature} LF on F.feature_id = LF.feature_id ".
            "  INNER JOIN {library} L on LF.library_id = L.library_id ".
          "WHERE LF.library_id = %d and ($where_cvt) ".
          "GROUP BY L.library_id ";

  $previous_db = tripal_db_set_active('chado');  // use chado database
  $org_features = pager_query($sql, 10, 0, $csql, $library->library_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 );
}
tripal_feature_load_organism ( organism_id)

Definition at line 1010 of file tripal_feature.module.

                                                    {
  // add organism details
  $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
  $organism = db_fetch_object(chado_query($sql, $organism_id));
  return $organism;
}
tripal_feature_load_organism_feature_browser ( organism)

Definition at line 1548 of file tripal_feature.module.

                                                                 {

  if (!$organism) {
    return array();
  }

  // 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_feature_browse_setting', 'show_feature_browser');
  if (strcmp($show_browser, 'show_feature_browser')!=0) {
    return array('enabled' => FALSE);
  }

  // get the list of available sequence ontology terms for which
  // we will build drupal pages from features in chado.  If a feature
  // is not one of the specified typse we won't build a node for it.
  $allowed_types = variable_get('chado_browser_feature_types', 'EST contig');
  $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);
  $so_terms = split(' ', $allowed_types);

  // perform the query
  $values = array(
    'organism_id' => $organism->organism_id,
    'type_id' => array(
      'name' => $so_terms
    ),
  );
  $columns = array('feature_id', 'name', 'uniquename', 'type_id');
  $options = array(
    'pager' => array('limit' => 10, 'element' => 0),
    'order_by' => array('name' => 'ASC'),
  );  
  $features = tripal_core_chado_select('feature', $columns, $values, $options);
  $pager = theme('pager');

  // add the node ids and types
  $nsql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
  $tsql = "SELECT name FROM {cvterm} WHERE cvterm_id = %d";
  foreach ($features as $feature) {
    $node = db_fetch_object(db_query($nsql, $feature->feature_id));
    $type = db_fetch_object(chado_query($tsql, $feature->type_id));
    $feature->nid = $node->nid;
    $feature->type_name = $type->name;
  }

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

Definition at line 1467 of file tripal_feature.module.

                                                                {

  // 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_counts = variable_get('tripal_feature_summary_setting', 'show_feature_summary');
  if (strcmp($show_counts, 'show_feature_summary')!=0) {
    return array('enabled' => FALSE );
  }


  $args = array();
  $names = array();
  $order = array();

  // build the where clause for the SQL statement if we have a custom term list
  // we'll also keep track of the names the admin provided (if any) and the
  // order that the terms should appear.
  $is_custom = 0;
  $temp = rtrim(variable_get('tripal_feature_summary_report_mapping', ''));
  $where = '';
  if ($temp) {
    $is_custom = 1;
    $temp = explode("\n", $temp);
    foreach ($temp as $key => $value) {
      // separate the key value pairs
      $temp2 = explode("=", $value);
      $feature_type = rtrim($temp2[0]);
      $args[] = $feature_type;
      $order[] = $feature_type;
      // if a new name is provided then use that otherwise just
      // use the feature type
      if (count($temp2) == 2) {
        $names[] = rtrim($temp2[1]);
      }
      else {
        $names[] = $feature_type;
      }
      $where .= "OFC.feature_type = '%s' OR \n";
    }
    if ($where) {
      $where = drupal_substr($where, 0, -5);  # remove OR from the end
      $where = "($where) AND";
    }
  }

  // get the feature counts.  This is dependent on a materialized view
  // installed with the organism module
  $sql = "
    SELECT OFC.num_features,OFC.feature_type,CVT.definition
    FROM {organism_feature_count} OFC
      INNER JOIN {cvterm} CVT on OFC.cvterm_id = CVT.cvterm_id
    WHERE $where organism_id = %d
    ORDER BY num_features desc
  ";
  $args[] = $organism->organism_id;
  $org_features = chado_query($sql, $args);

  // iterate through the types
  $types = array();
  while ($type = db_fetch_object($org_features)) {
    $types[$type->feature_type] = $type;
    // if we don't have an order this means we didn't go through the loop
    // above to set the names, so do that now
    if (!$is_custom) {
      $names[] = $type->feature_type;
      $order[] = $type->feature_type;
    }
  }

  # now reorder the types
  $ordered_types = array();
  foreach ($order as $type) {
    $ordered_types[] = $types[$type];
  }
  return array( 'types' => $ordered_types, 'names' => $names, 'enabled' => TRUE );
}
tripal_feature_load_properties ( feature_id)

Definition at line 1042 of file tripal_feature.module.

                                                     {

  $sql = "SELECT CVT.name as cvname, FS.type_id, FS.value, FS.rank,
           CVT.definition, CVT.is_obsolete,
           DBX.dbxref_id,DBX.accession,DB.name as dbname,
           DB.urlprefix, DB.description as db_description, DB.url
         FROM {featureprop} FS
           INNER JOIN {cvterm} CVT ON FS.type_id = CVT.cvterm_id
           INNER JOIN {dbxref} DBX ON CVT.dbxref_id = DBX.dbxref_id
           INNER JOIN {db} DB      ON DB.db_id = DBX.db_id
         WHERE FS.feature_id = %d
         ORDER BY FS.rank ASC";
  $results = chado_query($sql, $feature_id);
  $i=0;
  $properties = array();
  while ($property = db_fetch_object($results)) {
    $properties[$i++] = $property;
  }
  return $properties;
}
tripal_feature_load_references ( feature_id)

Definition at line 1067 of file tripal_feature.module.

                                                     {

  $sql = "SELECT F.uniquename,F.Feature_id,DBX.accession,DB.description as dbdesc, ".
        "   DB.db_id, DB.name as db_name, DB.urlprefix,DBX.dbxref_id ".
        "FROM {feature} F ".
        "  INNER JOIN {feature_dbxref} FDBX on F.feature_id = FDBX.feature_id ".
        "  INNER JOIN {dbxref} DBX on DBX.dbxref_id = FDBX.dbxref_id ".
        "  INNER JOIN {db} on DB.db_id = DBX.db_id ".
        "WHERE F.feature_id = %d ".
        "ORDER BY DB.name ";
  $results = chado_query($sql, $feature_id);
  $references = array();
  $i=0;
  while ($accession = db_fetch_object($results)) {
    $references[$i++] = $accession;
  }
  return $references;
}
tripal_feature_load_relationships ( feature_id,
side = 'as_subject' 
)

Definition at line 1162 of file tripal_feature.module.

                                                                              {
  // get the relationships for this feature.  The query below is used for both
  // querying the object and subject relationships
  $sql = "SELECT
           FS.name as subject_name,
           FS.uniquename as subject_uniquename,
           CVTS.name as subject_type,
           CVTS.cvterm_id as subject_type_id,
           FR.subject_id,
           FR.type_id as relationship_type_id,
           CVT.name as rel_type,
           FO.name as object_name,
           FO.uniquename as object_uniquename,
           CVTO.name as object_type,
           CVTO.cvterm_id as object_type_id,
           FR.object_id,
           FR.rank
         FROM {feature_relationship} FR
           INNER JOIN {cvterm} CVT ON FR.type_id = CVT.cvterm_id
           INNER JOIN {feature} FS ON FS.feature_id = FR.subject_id
           INNER JOIN {feature} FO ON FO.feature_id = FR.object_id
           INNER JOIN {cvterm} CVTO ON FO.type_id = CVTO.cvterm_id
           INNER JOIN {cvterm} CVTS ON FS.type_id = CVTS.cvterm_id
  ";
  if (strcmp($side, 'as_object')==0) {
    $sql .= " WHERE FR.object_id = %d";
  }
  if (strcmp($side, 'as_subject')==0) {
    $sql .= " WHERE FR.subject_id = %d";
  }
  $sql .= " ORDER BY FR.rank";

  // get the relationships
  $results = chado_query($sql, $feature_id);


  // iterate through the relationships, put these in an array and add
  // in the Drupal node id if one exists
  $i=0;
  $nodesql = "SELECT nid FROM {chado_feature} WHERE feature_id = %d";
  $relationships = array();
  while ($rel = db_fetch_object($results)) {
    $node = db_fetch_object(db_query($nodesql, $rel->subject_id));
    if ($node) {
      $rel->subject_nid = $node->nid;
    }
    $node = db_fetch_object(db_query($nodesql, $rel->object_id));
    if ($node) {
      $rel->object_nid = $node->nid;
    }
    $relationships[$i++] = $rel;
  }
  return $relationships;
}
tripal_feature_load_synonyms ( feature_id)

Definition at line 1021 of file tripal_feature.module.

                                                   {

  $sql = "SELECT S.name ".
        "FROM {Feature_Synonym} FS ".
        "  INNER JOIN {Synonym} S ".
        "    ON FS.synonym_id = S.Synonym_id ".
        "WHERE FS.feature_id = %d ".
        "ORDER BY S.name ";
  $results = chado_query($sql, $feature_id);
  $synonyms = array();
  $i=0;
  while ($synonym = db_fetch_object($results)) {
    $synonyms[$i++] = $synonym;
  }
  return $synonyms;
}
tripal_feature_menu ( )

Menu items are automatically added for the new node types created by this module to the 'Create Content' Navigation menu item. This function adds more menu items needed for this module.

$items['node/tf_node/tf_properties'] = array( 'title' => t('Add Properties & Synonyms'), 'description' => t('Settings for Features'), 'page callback' => 'tripal_feature_add_ALL_property_page', 'page arguments' => array(1), 'access arguments' => array('create chado_feature content'), 'type' => MENU_CALLBACK );

$items['node/tf_node/tf_db_references'] = array( 'title' => t('Add Database References'), 'description' => t('Settings for Features'), 'page callback' => 'tripal_feature_add_ALL_dbreferences_page', 'page arguments' => array(1), 'access arguments' => array('create chado_feature content'), 'type' => MENU_CALLBACK );

$items['node/tf_node/tf_relationships'] = array( 'title' => t('Add Relationships'), 'description' => t('Settings for Features'), 'page callback' => 'tripal_feature_add_ALL_relationships_page', 'page arguments' => array(1), 'access arguments' => array('create chado_feature content'), 'type' => MENU_CALLBACK );

$items['node/tf_node/tf_edit_relationships'] = array( 'title' => t('Edit Relationships'), 'description' => t('Settings for Feature'), 'page callback' => 'tripal_feature_edit_ALL_relationships_page', 'page arguments' => array(1), 'access arguments' => array('edit chado_feature content'), 'type' => MENU_LOCAL_TASK, 'weight' => 9, );

Definition at line 154 of file tripal_feature.module.

                               {
  $items = array();

  // the administative settings menu
  $items['admin/tripal/tripal_feature'] = array(
    'title' => 'Features',
    'description' => 'Basic Description of Tripal Organism Module Functionality',
    'page callback' => 'theme',
    'page arguments' => array('tripal_feature_admin'),
    'access arguments' => array('administer tripal features'),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/tripal/tripal_feature/configuration'] = array(
    'title' => 'Feature Configuration',
    'description' => 'Settings for Chado Features',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_feature_admin'),
    'access arguments' => array('administer tripal features'),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/tripal/tripal_feature/fasta_loader'] = array(
    'title' => 'Import a multi-FASTA file',
    'description' => 'Load sequences from a multi-FASTA file into Chado',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_feature_fasta_load_form'),
    'access arguments' => array('administer tripal features'),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/tripal/tripal_feature/gff3_load'] = array(
    'title' => 'Import a GFF3 file',
    'description' => 'Import a GFF3 file into Chado',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_feature_gff3_load_form'),
    'access arguments' => array('administer tripal features'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['admin/tripal/tripal_feature/delete'] = array(
    'title' => ' Delete Features',
    'description' => 'Delete multiple features from Chado',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_feature_delete_form'),
    'access arguments' => array('administer tripal features'),
    'type' => MENU_NORMAL_ITEM,
  );

  $items['admin/tripal/tripal_feature/sync'] = array(
    'title' => ' Sync Features',
    'description' => 'Sync features from Chado with Drupal',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('tripal_feature_sync_form'),
    'access arguments' => array('administer tripal features'),
    'type' => MENU_NORMAL_ITEM,
  );

  // Adding Secondary Properties

  //Edit/Deleting Secondary Properties-------------
  $items['node/%tf_node/edit_feature_properties'] = array(
    'title' => 'Edit Properties',
    'description' => 'Settings for Features',
    'page callback' => 'tripal_feature_edit_ALL_properties_page',
    'page arguments' => array(1),
    'access arguments' => array('edit chado_feature content'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 8,
  );
  $items['node/%tf_node/tf_edit_db_references'] = array(
    'title' => 'Edit References',
    'description' => 'Settings for Feature',
    'page callback' => 'tripal_feature_edit_ALL_dbreferences_page',
    'page arguments' => array(1),
    'access arguments' => array('edit chado_feature content'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 10,
  ); 

  // the menu link for addressing any feature (by name, uniquename, synonym)
  $items['feature/%'] = array(
    'title' => 'Matched Features',
    'description' => 'Shows all features that match the provided ID.  If multiple features match even by name, uniquename or synonym then a page is presented to allow the user to select which one they intended.',
    'page callback' => 'tripal_feature_match_features_page',
    'page arguments' => array(1),
    'access arguments' => array('access chado_feature content'),
    'type' => MENU_NORMAL_ITEM,
  );
  
  return $items;
}
tripal_feature_node_info ( )

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

Definition at line 85 of file tripal_feature.module.

                                    {
  $nodes = array();

  $nodes['chado_feature'] = array(
    'name' => t('Feature'),
    'module' => 'chado_feature',
    'description' => t('A feature from the chado database'),
    'has_title' => FALSE,
    'title_label' => t('Feature'),
    'has_body' => FALSE,
    'body_label' => t('Feature Description'),
    'locked' => TRUE
  );
  return $nodes;
}
tripal_feature_nodeapi ( &$  node,
op,
teaser,
page 
)

Display feature information for associated organisms. This function also provides contents for indexing

Definition at line 1889 of file tripal_feature.module.

                                                             {

  switch ($op) {
    // Note that this function only adds feature view to an organism node.
    // The view of a feature node is controled by the theme *.tpl file
    case 'view':
      switch ($node->type) {
        case 'chado_organism':
        // Show feature browser
          $types_to_show = array('chado_organism', 'chado_library');
          if (in_array($node->type, $types_to_show, TRUE)) {
            $node->content['tripal_organism_feature_counts'] = array(
              '#value' => theme('tripal_organism_feature_counts', $node),
            );
            $node->content['tripal_organism_feature_browser'] = array(
              '#value' => theme('tripal_organism_feature_browser', $node),
            );
          }
        break;
      }
    break;
  }
}
tripal_feature_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 108 of file tripal_feature.module.

                               {
  return array(
    'access chado_feature content',
    'create chado_feature content',
    'delete chado_feature content',
    'edit chado_feature content',
    'administer tripal features',
  );
}
tripal_feature_preprocess_tripal_analysis_feature_browser ( &$  variables)

Preprocessor function for the Analysis Feature Browser

Definition at line 2060 of file tripal_feature.module.

                                                                                {
  $analysis = $variables['node']->analysis;
  $analysis->feature_browser = tripal_feature_load_analysis_feature_browser($analysis);
}
tripal_feature_preprocess_tripal_feature_alignments ( &$  variables)

Definition at line 1932 of file tripal_feature.module.

                                                                          {
  
  // we want to provide a new variable that contains the matched features.
  $feature = $variables['node']->feature;
  $feature = tripal_core_expand_chado_vars($feature, 'table', 'featureloc');
  
  // get alignments as child
  $cfeaturelocs = $feature->featureloc->feature_id;
  if (!$cfeaturelocs) {
     $cfeaturelocs = array();
  } 
  elseif (!is_array($cfeaturelocs)) { 
     $cfeaturelocs = array($cfeaturelocs); 
  }
  // get alignment as parent
  $pfeaturelocs = $feature->featureloc->srcfeature_id;
  if (!$pfeaturelocs) {
     $pfeaturelocs = array();
  } 
  elseif (!is_array($pfeaturelocs)) { 
     $pfeaturelocs = array($pfeaturelocs); 
  }

  // get matched alignments (those with an itermediate 'match' or 'EST_match', etc
  $mfeaturelocs = tripal_feature_get_matched_alignments($feature);
  $feature->matched_featurelocs = tripal_feature_get_matched_alignments($feature);
    
  // combine all three alignments into a single array for printing together in
  // a single list
  $alignments = array();
  foreach ($pfeaturelocs as $featureloc) {
     // if type is a 'match' then ignore it. We will handle those below
     if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
        continue;
     }
     $alignment = new stdClass();
     $alignment->record = $featureloc;
     $alignment->name = $featureloc->feature_id->name;
     $alignment->nid = $featureloc->feature_id->nid;
     $alignment->type = $featureloc->feature_id->type_id->name;
     $alignment->fmin = $featureloc->fmin;
     $alignment->fmax = $featureloc->fmax;
     $alignment->phase = $featureloc->phase;
     $alignment->strand = $featureloc->strand;
     $alignments[] = $alignment;
  }
  foreach ($cfeaturelocs as $featureloc) {
     // if type is a 'match' then ignore it. We will handle those below
     if (preg_match('/(^match$|^.*?_match|match_part)$/', $featureloc->feature_id->type_id->name)) {
        continue;
     }
     $alignment = new stdClass();
     $alignment->record = $featureloc;
     $alignment->name = $featureloc->srcfeature_id->name;
     $alignment->nid = $featureloc->srcfeature_id->nid;
     $alignment->type = $featureloc->srcfeature_id->type_id->name;
     $alignment->fmin = $featureloc->fmin;
     $alignment->is_fmin_partial = $featureloc->is_fmin_partial;
     $alignment->fmax = $featureloc->fmax;
     $alignment->is_fmax_partial = $featureloc->is_fmax_partial;
     $alignment->phase = $featureloc->phase;
     $alignment->strand = $featureloc->strand;
     $alignments[] = $alignment;
  }
  // in matching features, the left feature is always the feature
  // provided to this function. 
  foreach ($mfeaturelocs as $featureloc) {
     // get more information about the right feature
     $select = array('feature_id' => $featureloc->right_srcfeature_id);
     $rfeature = tripal_core_generate_chado_var('feature', $select);
     // now add to the list
     $alignment = new stdClass();
     $alignment->record = $featureloc;
     $alignment->right_feature = $rfeature;
     $alignment->name = $rfeature->name;
     $alignment->nid = $rfeature->nid;
     $alignment->type = $rfeature->type_id->name;
     $alignment->fmin = $featureloc->left_fmin;
     $alignment->is_fmin_partial = $featureloc->left_is_fmin_partial;
     $alignment->fmax = $featureloc->left_fmax;
     $alignment->is_fmax_partial = $featureloc->left_is_fmax_partial;
     $alignment->phase = $featureloc->left_phase;
     $alignment->strand = $featureloc->left_strand;
     $alignment->right_fmin = $featureloc->right_fmin;
     $alignment->right_is_fmin_partial = $featureloc->right_is_fmin_partial;
     $alignment->right_fmax = $featureloc->right_fmax;
     $alignment->right_is_fmax_partial = $featureloc->right_is_fmax_partial;
     $alignment->right_phase = $featureloc->right_phase;
     $alignment->right_strand = $featureloc->right_strand;
     $alignments[] = $alignment;
  }
  $feature->all_featurelocs = $alignments;
}
tripal_feature_preprocess_tripal_feature_relationships ( &$  variables)

Definition at line 1919 of file tripal_feature.module.

                                                                             {
  // we want to provide a new variable that contains the matched features.
  $feature = $variables['node']->feature;
   
  if (!$feature->all_relationships) {
    $feature->all_relationships = tripal_feature_get_feature_relationships($feature);  
  } 
}
tripal_feature_preprocess_tripal_library_feature_browser ( &$  variables)

Preprocessor function for the Library Feature Browser

Definition at line 2050 of file tripal_feature.module.

                                                                               {
  $library = $variables['node']->library;
  $library->feature_browser = tripal_feature_load_library_feature_browser($library);
}
tripal_feature_preprocess_tripal_organism_feature_browser ( &$  variables)

Definition at line 2040 of file tripal_feature.module.

                                                                                {
  $organism = $variables['node']->organism;
  $organism->feature_browser = tripal_feature_load_organism_feature_browser($organism);
}
tripal_feature_preprocess_tripal_organism_feature_counts ( &$  variables)

Definition at line 2030 of file tripal_feature.module.

                                                                               {
  $organism = $variables['node']->organism;
  $organism->feature_counts = tripal_feature_load_organism_feature_counts($organism);
}
tripal_feature_return_fasta ( feature,
desc 
)

Definition at line 2172 of file tripal_feature.module.

                                                      {
  $fasta  = ">" . variable_get('chado_feature_accession_prefix', 'ID') . "$feature->feature_id|$feature->name";
  $fasta .= " $desc\n";
  $fasta .= wordwrap($feature->residues, 50, "\n", TRUE);
  $fasta .= "\n\n";
  return $fasta;
}
tripal_feature_set_taxonomy ( node,
feature_id 
)

Definition at line 434 of file tripal_feature.admin.inc.

                                                         {

  // iterate through the taxonomy classes that have been
  // selected by the admin user and make sure we only set those
  $tax_classes = variable_get('tax_classes', '');
  $do_ft = 0;
  $do_op = 0;
  $do_lb = 0;
  $do_an = 0;
  foreach ($tax_classes as $class) {
    if (strcmp($class , 'organism')==0) {
      $do_op = 1;
    }
    if (strcmp($class, 'feature_type')==0) {
      $do_ft = 1;
    }
    if (strcmp($class, 'library')==0) {
      $do_lb = 1;
    }
    if (strcmp($class, 'analysis')==0) {
      $do_an = 1;
    }
  }


  // get the list of vocabularies and find our two vocabularies of interest
  $vocabularies = taxonomy_get_vocabularies();
  $ft_vid = NULL;
  $op_vid = NULL;
  $lb_vid = NULL;
  $an_vid = NULL;
  foreach ($vocabularies as $vocab) {
    if ($vocab->name == 'Feature Type') {
      $ft_vid = $vocab->vid;
    }
    if ($vocab->name == 'Organism') {
      $op_vid = $vocab->vid;
    }
    if ($vocab->name == 'Library') {
      $lb_vid = $vocab->vid;
    }
    if ($vocab->name == 'Analysis') {
      $an_vid = $vocab->vid;
    }
  }

  // get the cvterm and the organism for this feature
  $sql = "SELECT CVT.name AS cvname, O.genus, O.species ".
        "FROM {CVTerm} CVT ".
        "  INNER JOIN Feature F on F.type_id = CVT.cvterm_id ".
        "  INNER JOIN Organism O ON F.organism_id = O.organism_id ".
        "WHERE F.feature_id = $feature_id";
  $feature = db_fetch_object(chado_query($sql));

  // Set the feature type for this feature
  if ($do_ft && $ft_vid) {
    $tags["$ft_vid"] = "$feature->cvname";
  }
  // Set the organism for this feature type
  if ($do_op && $op_vid) {
    $tags["$op_vid"] = "$feature->genus $feature->species";
  }

  // get the library that this feature may belong to and add it as taxonomy
  if ($do_lb && $lb_vid) {
    $sql = "SELECT L.name ".
           "FROM {Library} L ".
           "  INNER JOIN Library_feature LF ON LF.library_id = L.library_id ".
           "WHERE LF.feature_id = %d ";
    $library = db_fetch_object(chado_query($sql, $feature_id));
    $tags["$lb_vid"] = "$library->name";
  }

  // now add the taxonomy to the node
  $terms['tags'] = $tags;
  taxonomy_node_save($node, $terms);
  //   print "Setting $node->name: " . implode(", ",$tags) . "\n";

  // get the analysis that this feature may belong to and add it as taxonomy
  // We'll add each one individually since there may be more than one analysis
  if ($do_an && $an_vid) {
    $sql = "SELECT A.name ".
           "FROM {Analysis} A ".
           "  INNER JOIN Analysisfeature AF ON AF.analysis_id = A.analysis_id ".
           "WHERE AF.feature_id = $feature_id ";
    $results = chado_query($sql);
    $analysis_terms = array();
    while ($analysis=db_fetch_object($results)) {
      $tags2["$an_vid"] = "$analysis->name";
      $terms['tags'] = $tags2;
      taxonomy_node_save($node, $terms);
    }
  }

}
tripal_feature_set_vocabulary ( )

Definition at line 611 of file tripal_feature.admin.inc.

                                         {

  //include the file containing the required functions for adding taxonomy vocabs
  module_load_include('inc', 'taxonomy', 'taxonomy.admin');

  // get the vocabularies so that we make sure we don't recreate
  // the vocabs that already exist
  $vocabularies = taxonomy_get_vocabularies();
  $ft_vid = NULL;
  $op_vid = NULL;
  $lb_vid = NULL;
  $an_vid = NULL;

  // These taxonomic terms are hard coded because we
  // konw we have these relationships in the chado tables
  // through foreign key relationships.  The tripal
  // modules that correspond to these chado "modules" don't
  // need to be installed for the taxonomy to work.
  foreach ($vocabularies as $vocab) {
    if ($vocab->name == 'Feature Type') {
      $ft_vid = $vocab->vid;
    }
    if ($vocab->name == 'Organism') {
      $op_vid = $vocab->vid;
    }
    if ($vocab->name == 'Library') {
      $lb_vid = $vocab->vid;
    }
    if ($vocab->name == 'Analysis') {
      $an_vid = $vocab->vid;
    }
  }

  if (!$ft_vid) {
    $form_state = array();
    $values = array(
       'name' => t('Feature Type'),
       'nodes' => array('chado_feature' => 'chado_feature'),
       'description' => t('The feature type (or SO cvterm for this feature).'),
       'help' => t('Select the term that matches the feature'),
       'tags' => 0,
       'hierarchy' => 1,
       'relations' => 1,
       'multiple' => 0,
       'required' => 0,
       'weight' => 1,
    );
    drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
    drupal_execute('taxonomy_form_vocabulary', $form_state);
  }

  if (!$op_vid) {
    $form_state = array();
    $values = array(
       'name' => t('Organism'),
       'nodes' => array('chado_feature' => 'chado_feature'),
       'description' => t('The organism to which this feature belongs.'),
       'help' => t('Select the term that matches the feature'),
       'tags' => 0,
       'hierarchy' => 1,
       'relations' => 1,
       'multiple' => 0,
       'required' => 0,
       'weight' => 2,
    );
    drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
    drupal_execute('taxonomy_form_vocabulary', $form_state);
  }

  if (!$lb_vid) {
    $form_state = array();
    $values = array(
       'name' => t('Library'),
       'nodes' => array('chado_feature' => 'chado_feature'),
       'description' => t('Chado features associated with a library are assigned the term associated with the library'),
       'help' => t('Select the term that matches the feature'),
       'tags' => 0,
       'hierarchy' => 1,
       'relations' => 1,
       'multiple' => 0,
       'required' => 0,
       'weight' => 3,
    );
    drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
    drupal_execute('taxonomy_form_vocabulary', $form_state);
  }

  if (!$an_vid) {
    $form_state = array();
    $values = array(
       'name' => t('Analysis'),
       'nodes' => array('chado_feature' => 'chado_feature'),
       'description' => t('Any analysis to which this feature belongs.'),
       'help' => t('Select the term that matches the feature'),
       'tags' => 0,
       'hierarchy' => 1,
       'relations' => 1,
       'multiple' => 1,
       'required' => 0,
       'weight' => 4,
    );
    drupal_execute('taxonomy_form_vocabulary', $form_state, $values);
    drupal_execute('taxonomy_form_vocabulary', $form_state);
  }
}
tripal_feature_sort_locations ( a,
b 
)

used to sort the feature locs by start position

Definition at line 1154 of file tripal_feature.module.

                                               {
  return strnatcmp($a->fmin, $b->fmin);
}
tripal_feature_sort_rel_objects ( a,
b 
)

used to sort the list of relationship objects by start position

Definition at line 1726 of file tripal_feature.module.

                                                 {
  return strnatcmp($a->fmin, $b->fmin);
}
tripal_feature_sort_rel_parts_by_end ( a,
b 
)

used to sort the list of relationship parts by start position

Definition at line 1752 of file tripal_feature.module.

                                                      {
  $val = strnatcmp($b['end'], $a['end']);
  if ($val == 0) {
     return strcmp($a['type'], $b['type']);
  }
  return $val;
}
tripal_feature_sort_rel_parts_by_start ( a,
b 
)

used to sort the list of relationship parts by start position

Definition at line 1735 of file tripal_feature.module.

                                                        {
  foreach ($a as $type_name => $details) {
     $astart = $a[$type_name]['start'];
     break;
  }
  foreach ($b as $type_name => $details) {
     $bstart = $b[$type_name]['start'];
     break;
  }
  return strnatcmp($astart, $bstart);
}
tripal_feature_sync_feature ( feature_id)

Definition at line 286 of file syncFeatures.inc.

                                                  {
  //print "\tSyncing feature $feature_id\n";

  global $user;
  $create_node = 1;   // set to 0 if the node exists and we just sync and not create

  // get the accession prefix
  $aprefix = variable_get('chado_feature_accession_prefix', 'ID');

  // if we don't have a feature_id then return
  if (!$feature_id) {
    drupal_set_message(t("Please provide a feature_id to sync"));
    return '';
  }

  // get information about this feature
  $fsql = "SELECT F.feature_id, F.name, F.uniquename,O.genus, ".
         "    O.species,CVT.name as cvname,F.residues,F.organism_id ".
         "FROM {FEATURE} F ".
         "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
         "  INNER JOIN Organism O ON F.organism_id = O.organism_ID ".
         "WHERE F.feature_id = %d";
  $feature = db_fetch_object(chado_query($fsql, $feature_id));

  // get the synonyms for this feature
  $synsql = "SELECT S.name ".
            "FROM {feature_synonym} FS ".
            "  INNER JOIN {synonym} S on FS.synonym_id = S.synonym_id ".
            "WHERE FS.feature_id = %d";
  $synonyms = chado_query($synsql, $feature_id);

  // now add these synonyms to the feature object as a single string
  $synstring = '';
  while ($synonym = db_fetch_object($synonyms)) {
    $synstring .= "$synonym->name\n";
  }
  $feature->synonyms = $synstring;

  // check to make sure that we don't have any nodes with this feature name as a title
  // but without a corresponding entry in the chado_feature table if so then we want to
  // clean up that node.  (If a node is found we don't know if it belongs to our feature or
  // not since features can have the same name/title.)
  $tsql =  "SELECT * FROM {node} N ".
           "WHERE title = '%s'";
  $cnsql = "SELECT * FROM {chado_feature} ".
           "WHERE nid = %d";
  $nodes = db_query($tsql, $feature->name);
  // cycle through all nodes that may have this title
  while ($node = db_fetch_object($nodes)) {
    $feature_nid = db_fetch_object(db_query($cnsql, $node->nid));
    if (!$feature_nid) {
      drupal_set_message(t("%feature_id: A node is present but the chado_feature entry is missing... correcting", array('%feature_id' => $feature_id)));
      node_delete($node->nid);
    }
  }

  // check if this feature already exists in the chado_feature table.
  // if we have a chado feature, we want to check to see if we have a node
  $cfsql = "SELECT * FROM {chado_feature} ".
           "WHERE feature_id = %d";
  // @coder-ignore: don't need to use db_rewrite_sql() since need all nodes regardless of access control
  $nsql =  "SELECT * FROM {node} N ".
           "WHERE nid = %d";
  $chado_feature = db_fetch_object(db_query($cfsql, $feature->feature_id));
  if ($chado_feature) {
    drupal_set_message(t("%feature_id: A chado_feature entry exists", array('%feature_id' => $feature_id)));
    $node = db_fetch_object(db_query($nsql, $chado_feature->nid));
    if (!$node) {
      // if we have a chado_feature but not a node then we have a problem and
      // need to cleanup
      drupal_set_message(t("%feature_id: The node is missing, but has a chado_feature entry... correcting", array('%feature_id' => $feature_id)));
      $df_sql = "DELETE FROM {chado_feature} WHERE feature_id = %d";
      db_query($df_sql, $feature_id);
    }
    else {
      drupal_set_message(t("%feature_id: A corresponding node exists", array('%feature_id' => $feature_id)));
      $create_node = 0;
    }
  }

  // if we've encountered an error then just return.
  if ($error_msg = db_error()) {
    //print "$error_msg\n";
    return '';
  }

  // if a drupal node does not exist for this feature then we want to
  // create one.  Note that the node_save call in this block
  // will call the hook_submit function which
  if ($create_node) {
    // get the organism for this feature
    $sql = "SELECT * FROM {organism} WHERE organism_id = %d";
    $organism = db_fetch_object(chado_query($sql, $feature->organism_id));

    drupal_set_message(t("%feature_id: Creating node $feature->name", array('%feature_id' => $feature_id)));
    $new_node = new stdClass();
    $new_node->type = 'chado_feature';
    $new_node->uid = $user->uid;
    $new_node->title = "$feature->name, $feature->uniquename ($feature->cvname) $organism->genus $organism->species";
    $new_node->fname = "$feature->name";
    $new_node->uniquename = "$feature->uniquename";
    $new_node->feature_id = $feature->feature_id;
    $new_node->residues = $feature->residues;
    $new_node->organism_id = $feature->organism_id;
    $new_node->feature_type = $feature->cvname;
    $new_node->synonyms = $feature->synonyms;

    // validate the node and if okay then submit
    node_validate($new_node);
    if ($errors = form_get_errors()) {
      print "Error encountered validating new node. Cannot sync\n";
      foreach ($errors as $key => $msg) {        
        watchdog('trp-fsync', "%msg", array('%msg' => $msg), 'error');
      }
      exit;
    }
    else {
      $node = node_submit($new_node);
      node_save($node);
    }
  }
  else {
    $node = $chado_feature;
  }


  // set the taxonomy for this node
  drupal_set_message(t("%feature_id ($node->nid): setting taxonomy", array('%feature_id' => $feature_id)));
  tripal_feature_set_taxonomy($node, $feature_id);

  // reindex the node
  // drupal_set_message(t("$feature_id( $node->nid): indexing"));
  // tripal_feature_index_feature ($feature_id,$node->nid);

  // set the URL alias for this node
  tripal_feature_set_feature_url($node, $feature);


  return '';
}
tripal_feature_sync_features ( max_sync = 0,
organism_id = NULL,
feature_types = NULL,
job_id = NULL 
)

Definition at line 177 of file syncFeatures.inc.

                                         {
  //print "Syncing features (max of $max_sync)\n";
  $i = 0;

  // get the list of available sequence ontology terms for which
  // we will build drupal pages from features in chado.  If a feature
  // is not one of the specified typse we won't build a node for it.
  if (!$feature_types) {
    $allowed_types = variable_get('chado_sync_feature_types', 'gene contig');
  }
  else {
    $allowed_types = $feature_types;
  }
  $allowed_types = preg_replace("/[\s\n\r]+/", " ", $allowed_types);

  print "Looking for features of type: $allowed_types\n";

  $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 list of organisms that are synced and only include features from
  // those organisms
  $orgs = tripal_organism_get_synced();
  $where_org = "";
  foreach ($orgs as $org) {
    if ($organism_id) {
      if ($org->organism_id and $org->organism_id == $organism_id) {
        $where_org .= "F.organism_id = $org->organism_id OR ";
      }
    }
    else {
    if ($org->organism_id) {
      $where_org .= "F.organism_id = $org->organism_id OR ";
    }
    }
  }
  $where_org = drupal_substr($where_org, 0, drupal_strlen($where_org)-3);  # strip trailing 'OR'

  // use this SQL statement to get the features that we're going to upload
  $sql = "SELECT feature_id ".
        "FROM {FEATURE} F ".
        "  INNER JOIN Cvterm CVT ON F.type_id = CVT.cvterm_id ".
        "  INNER JOIN CV on CV.cv_id = CVT.cv_id ".
        "WHERE ($where_cvt) AND ($where_org) AND CV.name = 'sequence' ".
        "ORDER BY feature_id";

  // get the list of features
  $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();

  // pre-create the SQL statement that will be used to check
  // if a feature has already been synced.  We skip features
  // that have been synced
  $sql = "SELECT * FROM {chado_feature} WHERE feature_id = %d";

  // Iterate through features that need to be synced
  $interval = intval($count * 0.01);
  if ($interval < 1) {
    $interval = 1;
  }
  $num_ids = sizeof($ids);
  $i = 0;
  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));
    }
    // if we have a maximum number to sync then stop when we get there
    // if not then just continue on
    if ($max_sync and $i == $max_sync) {
      return '';
    }
    if (!db_fetch_object(db_query($sql, $feature_id))) {

      # parsing all the features can cause memory overruns
      # we are not sure why PHP does not clean up the memory as it goes
      # to avoid this problem we will call this script through an
      # independent system call
      print "$i of $num_ids Syncing feature id: $feature_id\n";
      $cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/includes/syncFeatures.inc -f $feature_id ";
      system($cmd);

    }
    $i++;
  }

  return '';
}
tripal_feature_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 308 of file tripal_feature.module.

                                {
  return array(
    'tripal_feature_search_index' => array(
      'arguments' => array('node'),
    ),
    'tripal_feature_search_results' => array(
       'arguments' => array('node'),
    ),
    'tripal_organism_feature_browser' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_organism_feature_browser',
    ),
    'tripal_organism_feature_counts' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_organism_feature_counts',
    ),
    'tripal_feature_base' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_base',
    ),
    'tripal_feature_sequence' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_sequence',
    ),
    'tripal_feature_synonyms' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_synonyms',
    ),
    'tripal_feature_featureloc_sequences' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_featureloc_sequences',
    ),
    'tripal_feature_references' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_references',
    ),
    'tripal_feature_properties' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_properties',
    ),
    'tripal_feature_terms' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_terms',
    ),
    'tripal_feature_alignments' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_alignments',
    ),
    'tripal_feature_relationships' => array(
       'arguments' => array('node' => NULL),
       'template' => 'tripal_feature_relationships',
    ),
    'tripal_feature_edit_ALL_properties_form' => array(
      'arguments' => array('form' => NULL),
      'function' => 'theme_tripal_feature_edit_ALL_properties_form',
    ),
    'tripal_feature_admin' => array(
      'template' => 'tripal_feature_admin',  
      'arguments' =>  array(NULL),  
      'path' => drupal_get_path('module', 'tripal_feature') . '/theme' 
    ),
  );
}
tripal_feature_update_db_reference ( dbxref_id,
db_id,
accession 
)

Definition at line 280 of file tripal_feature-db_references.inc.

                                                                            {

  $sql =  "UPDATE {dbxref} SET db_id=%d, accession='%s' WHERE dbxref_id=%d";
  chado_query($sql, $db_id, $accession, $dbxref_id);

}
tripal_feature_update_relationship ( stock_relationship_id,
subject_id,
cvterm_id,
object_id 
)

Definition at line 463 of file tripal_feature-relationships.inc.

                                                                                                         {

  $previous_db = db_set_active('chado');
  db_query(
    "UPDATE {stock_relationship} SET subject_id=%d, type_id=%d, object_id=%d WHERE stock_relationship_id=%d",
    $subject_id,
    $cvterm_id,
    $object_id,
    $stock_relationship_id
  );
  db_set_active($previous_db);

}
tripal_feature_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_db.views.inc where all the views integration code is

Definition at line 50 of file tripal_feature.module.

                                    {
  return array(
    'api' => 2.0,
  );
}
tripal_features_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 541 of file tripal_feature.admin.inc.

                                                                {

  return tripal_core_clean_orphaned_nodes('feature', $job_id);
 
}
if (isset($arguments['i'])) tripal_features_reindex ( max_sync,
job_id = NULL 
)

tripal_feature_index_feature ($chado_feature->feature_id,$chado_feature->nid); parsing all the features can cause memory overruns we are not sure why PHP does not clean up the memory as it goes to avoid this problem we will call this script through an independent system call

Definition at line 61 of file indexFeatures.inc.

                                                            {
  $i = 0;

  // We register a shutdown function to ensure that the nodes
  // that are indexed will have proper entries in the search_totals
  // table.  Without these entries, the searching doesn't work
  // properly. This function may run for quite a while since
  // it must calculate the sum of the scores of all entries in
  // the search_index table.  In the case of common words like
  // 'contig', this will take quite a while
  register_shutdown_function('search_update_totals');

  // use this SQL statement to get the features that we're going to index. This
  // SQL statement is derived from the hook_search function in the Drupal API.
  // Essentially, this is the SQL statement that finds all nodes that need
  // reindexing, but adjusted to include the chado_feature
  $sql = "SELECT N.nid, N.title, CF.feature_id ".
        "FROM {node} N ".
        "  INNER JOIN chado_feature CF ON CF.nid = N.nid ";
  $results = db_query($sql);

  // load into ids array
  $count = 0;
  $chado_features = array();
  while ($chado_feature = db_fetch_object($results)) {
    $chado_features[$count] = $chado_feature;
    $count++;
  }

  // Iterate through features that need to be indexed
  $interval = intval($count * 0.01);
  if ($interval >= 0) {
    $interval = 1;
  }
  foreach ($chado_features as $chado_feature) {

    // update the job status every 1% features
    if ($job_id and $i % $interval == 0) {
      $prog = intval(($i/$count)*100);
      tripal_job_set_progress($job_id, $prog);
      print "$prog%\n";
    }

    // sync only the max requested
    if ($max_sync and $i == $max_sync) {
      return '';
    }
    $i++;

    $cmd = "php " . drupal_get_path('module', 'tripal_feature') . "/indexFeatures.php ";
    $cmd .= "-i $chado_feature->feature_id -n $chado_feature->nid ";

    # print "\t$cmd\n";
    # print "\tfeature id is $chado_feature->feature_id\n";
    # print "\tnid is $chado_feature->nid\n";
    # print "\n";

    system($cmd);
    }

  return '';
}
tripal_features_set_taxonomy ( max_sync = 0,
job_id = NULL 
)

Definition at line 393 of file tripal_feature.admin.inc.

                                                                     {

  // make sure our vocabularies are cleaned and reset before proceeding
  tripal_feature_del_vocabulary();
  tripal_feature_set_vocabulary();

  // iterate through all drupal feature nodes and set the taxonomy
  $results = db_query("SELECT * FROM {chado_feature}");
  $nsql =  "SELECT * FROM {node} ".
          "WHERE nid = %d";
  $i = 0;

  // load into ids array
  $count = 0;
  $chado_features = array();
  while ($chado_feature = db_fetch_object($results)) {
    $chado_features[$count] = $chado_feature;
    $count++;
  }

  // Iterate through features that need to be synced
  $interval = intval($count * 0.01);
  foreach ($chado_features as $chado_feature) {

  // update the job status every 1% features
  if ($job_id and $i % $interval == 0) {
    tripal_job_set_progress($job_id, intval(($i/$count)*100));
  }
  print "$i of $count: ";
  $node = db_fetch_object(db_query($nsql, $chado_feature->nid));
  tripal_feature_set_taxonomy($node, $chado_feature->feature_id);

  $i++;
  }
}
 All Classes Files Functions Variables