function chado_feature_form

2.x tripal_feature.chado_node.inc chado_feature_form($node, &$form_state)
3.x tripal_feature.chado_node.inc chado_feature_form($node, &$form_state)
1.x tripal_feature.module chado_feature_form($node, $param)

Related topics

File

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

Code

function chado_feature_form($node, $param) {

  $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.'),
    '#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.'),
    '#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.'),
    '#maxlength' => 255
  );

  // get the sequence ontology CV ID
  $values = array('name' => 'sequence');
  $cv = tripal_core_chado_select('cv', array('cv_id'), $values);
  $cv_id = $cv[0]->cv_id;

  $form['feature_type'] = array(
    '#title' => t('Feature Type'),
    '#type' => 'textfield',
    '#description' => t("Choose the feature type."),
    '#required' => TRUE,
    '#default_value' => $feature->type_id->name,
    '#autocomplete_path' => "admin/tripal/tripal_cv/cvterm/auto_name/$cv_id",
  );

  // 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,
  );

  // 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 each on different lines.'),
  );

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

  $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.'),
  );
  return $form;
}