function tripal_feature_gff3_load_form_validate

2.x tripal_feature.gff_loader.inc tripal_feature_gff3_load_form_validate($form, &$form_state)
1.x gff_loader.inc tripal_feature_gff3_load_form_validate($form, &$form_state)

Validate the GFF3 loading job form

Related topics

File

tripal_feature/includes/tripal_feature.gff_loader.inc, line 263
Provides gff3 loading functionality. Creates features based on their specification in a GFF3 file.

Code

function tripal_feature_gff3_load_form_validate($form, &$form_state) {

  $gff_file = trim($form_state['values']['gff_file']);
  $organism_id = $form_state['values']['organism_id'];
  $target_organism_id = $form_state['values']['target_organism_id'];
  $target_type = trim($form_state['values']['target_type']);
  $create_target = $form_state['values']['create_target'];
  $create_organism = $form_state['values']['create_organism'];
  $add_only = $form_state['values']['add_only'];
  $update = $form_state['values']['update'];
  $refresh = 0; //$form_state['values']['refresh'];
  $remove = 0; //$form_state['values']['remove'];
  $use_transaction = $form_state['values']['use_transaction'];
  $line_number = trim($form_state['values']['line_number']);
  $landmark_type = trim($form_state['values']['landmark_type']);
  $alt_id_attr = trim($form_state['values']['alt_id_attr']);
  $re_mrna = trim($form_state['values']['re_mrna']);
  $re_protein = trim($form_state['values']['re_protein']);



  // check to see if the file is located local to Drupal
  $gff_file = trim($gff_file);
  $dfile = $_SERVER['DOCUMENT_ROOT'] . base_path() . $gff_file;
  if (!file_exists($dfile)) {
    // if not local to Drupal, the file must be someplace else, just use
    // the full path provided
    $dfile = $gff_file;
  }
  if (!file_exists($dfile)) {
    form_set_error('gff_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."));
  }

  // @coder-ignore: there are no functions being called here
  if (($add_only AND ($update OR $refresh OR $remove)) OR 
    ($update AND ($add_only OR $refresh OR $remove)) OR 
    ($refresh AND ($update OR $add_only OR $remove)) OR 
    ($remove AND ($update OR $refresh OR $add_only))) {
    form_set_error('add_only', t("Please select only one checkbox from the import options section"));
  }

  if ($line_number and !is_numeric($line_number) or $line_number < 0) {
    form_set_error('line_number', t("Please provide an integer line number greater than zero."));
  }

  if (!($re_mrna and $re_protein) and ($re_mrna or $re_protein)) {
    form_set_error('re_uname', t("You must provide both a regular expression for mRNA and a replacement string for protein"));
  }

  // check the regular expression to make sure it is valid
  set_error_handler(function() {
  }, E_WARNING);
  $result_re = preg_match("/" . $re_mrna . "/", null);
  $result = preg_replace("/" . $re_mrna . "/", $re_protein, null);
  restore_error_handler();
  if ($result_re === FALSE) {
    form_set_error('re_mrna', 'Invalid regular expression.');
  }
  else if ($result === FALSE) {
    form_set_error('re_protein', 'Invalid replacement string.');
  }
}