function chado_feature_validate

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

Related topics

File

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

Code

function chado_feature_validate($node) {
  $result = 0;

  // make sure the feature type is a real sequence ontology term
  $type = tripal_cv_get_cvterm_by_name($node->feature_type, NULL, 'sequence');
  if (!$type) {
    form_set_error('feature_type', t("The feature type is not a valid name from the Sequence Ontology."));
  }

  // 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"));
  }
}