function tripal_feature_fasta_load_form_validate

2.x tripal_feature.fasta_loader.inc tripal_feature_fasta_load_form_validate($form, &$form_state)
1.x fasta_loader.inc tripal_feature_fasta_load_form_validate($form, &$form_state)

Related topics

File

tripal_feature/includes/fasta_loader.inc, line 274
@todo Add file header description

Code

function tripal_feature_fasta_load_form_validate($form, &$form_state) {
  $fasta_file = trim($form_state['values']['fasta_file']);
  $organism_id = $form_state['values']['organism_id'];
  $type = trim($form_state['values']['seqtype']);
  $method = trim($form_state['values']['method']);
  $match_type = trim($form_state['values']['match_type']);
  $library_id = $form_state['values']['library_id'];
  $re_name = trim($form_state['values']['re_name']);
  $re_uname = trim($form_state['values']['re_uname']);
  $re_accession = trim($form_state['values']['re_accession']);
  $db_id = $form_state['values']['db_id'];
  $rel_type = $form_state['values']['rel_type'];
  $re_subject = trim($form_state['values']['re_subject']);
  $parent_type = trim($form_state['values']['parent_type']);

  if ($method == 0) {
    $method = 'Insert only';
  }
  if ($method == 1) {
    $method = 'Update only';
  }
  if ($method == 2) {
    $method = 'Insert and update';
  }

  if ($match_type == 0) {
    $match_type = 'Name';
  }

  if ($match_type == 1) {
    $match_type = 'Unique name';
  }


  if ($re_name and !$re_uname and strcmp($match_type, 'Unique name') == 0) {
    form_set_error('re_uname', t("You must provide a regular expression to identify the sequence unique name"));
  }

  if (!$re_name and $re_uname and strcmp($match_type, 'Name') == 0) {
    form_set_error('re_name', t("You must provide a regular expression to identify the sequence name"));
  }

  // check to see if the file is located local to Drupal
  $fasta_file = trim($fasta_file);
  $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $fasta_file;
  if (!file_exists($dfile)) {
    // if not local to Drupal, the file must be someplace else, just use
    // the full path provided
    $dfile = $fasta_file;
  }
  if (!file_exists($dfile)) {
    form_set_error('fasta_file', t("Cannot find the file on the system. Check that the file exists or that the web server has permissions to read the file."));
  }

  // make sure if a relationship is specified that all fields are provided.
  if (($rel_type or $parent_type) and !$re_subject) {
    form_set_error('re_subject', t("Please provide a regular expression for the parent"));
  }
  if (($rel_type or $re_subject) and !$parent_type) {
    form_set_error('parent_type', t("Please provide a SO term for the parent"));
  }
  if (($parent_type or $re_subject) and !$rel_type) {
    form_set_error('rel_type', t("Please select a relationship type"));
  }


  // make sure if a database is specified that all fields are provided
  if ($db_id and !$re_accession) {
    form_set_error('re_accession', t("Please provide a regular expression for the accession"));
  }
  if ($re_accession and !$db_id) {
    form_set_error('db_id', t("Please select a database"));
  }

  // check to make sure the types exists
  $cvtermsql = "SELECT CVT.cvterm_id
               FROM {cvterm} CVT
                  INNER JOIN {cv} CV on CVT.cv_id = CV.cv_id
                  LEFT JOIN {cvtermsynonym} CVTS on CVTS.cvterm_id = CVT.cvterm_id
               WHERE cv.name = '%s' and (CVT.name = '%s' or CVTS.synonym = '%s')";
  $cvterm = db_fetch_object(chado_query($cvtermsql, 'sequence', $type, $type));
  if (!$cvterm) {
    form_set_error('type', t("The Sequence Ontology (SO) term selected for the sequence type is not available in the database. Please check spelling or select another."));
  }
  if ($rel_type) {
    $cvterm = db_fetch_object(chado_query($cvtermsql, 'sequence', $parent_type, $parent_type));
    if (!$cvterm) {
      form_set_error('parent_type', t("The Sequence Ontology (SO) term selected for the parent relationship is not available in the database. Please check spelling or select another."));
    }
  }

  // check to make sure the 'relationship' and 'sequence' ontologies are loaded
  $form_state['storage']['dfile'] = $dfile;
}