class NewickImporter

Hierarchy

Expanded class hierarchy of NewickImporter

File

tripal_chado/includes/TripalImporter/NewickImporter.inc, line 3

View source
class NewickImporter extends TripalImporter {

  /**
   * The name of this loader.  This name will be presented to the site
   * user.
   */
  public static $name = 'Newick Tree Loader';

  /**
   * The machine name for this loader. This name will be used to construct
   * the URL for the loader.
   */
  public static $machine_name = 'chado_newick_loader';

  /**
   * A brief description for this loader.  This description will be
   * presented to the site user.
   */
  public static $description = 'Load Newick formatted phylogenetic trees.';

  /**
   * An array containing the extensions of allowed file types.
   */
  public static $file_types =['tree' 'txt'];

  /**
   * Provides information to the user about the file upload.  Typically this
   * may include a description of the file types allowed.
   */
  public static $upload_description = 'Please provide the Newick formatted tree file.  The file must have a .txt or .tree extension.';

  /**
   * The title that should appear above the file upload section.
   */
  public static $upload_title = 'Newick Upload';

  /**
   * Text that should appear on the button at the bottom of the importer
   * form.
   */
  public static $button_text = 'Import Newick file';


  /**
   * Indicates the methods that the file uploader will support.
   */
  public static $methods =[
  // Allow the user to upload a file to the server.
  'file_upload' TRUE
    // Allow the user to provide the path on the Tripal server for the file.
    'file_local' TRUE
    // Allow the user to provide a remote URL for the file.
    'file_remote' TRUE
    ];

  /**
   * @see TripalImporter::form()
   */
  public function form($form, &$form_state) {
    // Default values can come in the following ways:
    //
    // 1) as elements of the $node object.  This occurs when editing an existing phylotree
    // 2) in the $form_state['values'] array which occurs on a failed validation or
    //    ajax callbacks from non submit form elements
    // 3) in the $form_state['input'[ array which occurs on ajax callbacks from submit
    //    form elements and the form is being rebuilt
    //
    // set form field defaults
    $phylotree = NULL;
    $phylotree_id = NULL;
    $tree_name = '';
    $leaf_type = '';
    $analysis_id = '';
    $dbxref = '';
    $comment = '';
    $tree_required = TRUE;
    $tree_file = '';
    $name_re = '';
    $match = '';

    // If we are re constructing the form from a failed validation or ajax callback
    // then use the $form_state['values'] values.
    if (array_key_exists('values', $form_state) and isset($form_state['values']['tree_name'])) {
      $tree_name = $form_state['values']['tree_name'];
      $leaf_type = $form_state['values']['leaf_type'];
      $analysis_id = $form_state['values']['analysis_id'];
      $dbxref = $form_state['values']['dbxref'];
      $comment = $form_state['values']['description'];
    }
    // If we are re building the form from after submission (from ajax call) then
    // the values are in the $form_state['input'] array.
    if (array_key_exists('input', $form_state) and !empty($form_state['input'])) {
      $tree_name = $form_state['input']['tree_name'];
      $leaf_type = $form_state['input']['leaf_type'];
      $analysis_id = $form_state['input']['analysis_id'];
      $comment = $form_state['input']['description'];
      $dbxref = $form_state['input']['dbxref'];
    }

    $form['tree_name'] =[
    '#type' 'textfield'
      '#title' t('Tree Name')
      '#required' TRUE
      '#default_value' $tree_name
      '#description' t('Enter the name used to refer to this phylogenetic tree.')
      '#maxlength' 255
      ];

    $type_cv = tripal_get_default_cv('phylotree', 'type_id');
    $so_cv = chado_get_cv(['name' 'sequence']);
    $cv_id = $so_cv->cv_id;
    if (!$so_cv) {
      drupal_set_message('The Sequence Ontolgoy does not appear to be imported.
        Please import the Sequence Ontology before adding a tree.', 'error');
    }

    $form['leaf_type'] =[
    '#title' t('Tree Type')
      '#type' 'textfield'
      '#description' t("Choose the tree type. The type is
        a valid Sequence Ontology (SO) term. For example, trees derived
        from protein sequences should use the SO term 'polypeptide'.
        Alternatively, a phylotree can be used for representing a taxonomic
        tree. In this case, the word 'taxonomy' should be used.")
      '#required' TRUE
      '#default_value' $leaf_type
      '#autocomplete_path' "admin/tripal/legacy/tripal_cv/cvterm/auto_name/$cv_id"
      ];

    $form['dbxref'] =[
    '#title' t('Database Cross-Reference')
      '#type' 'textfield'
      '#description' t("Enter a database cross-reference of the form
        [DB name]:[accession]. The database name must already exist in the
        database. If the accession does not exist it is automatically added.")
      '#required' FALSE
      '#default_value' $dbxref
      ];

    $form['description'] =[
    '#type' 'textarea'
      '#title' t('Description')
      '#required' TRUE
      '#default_value' $comment
      '#description' t('Enter a description for this tree.')
      ];

    $form['name_re'] =[
    '#title' t('Feature Name Regular Expression')
      '#type' 'textfield'
      '#description' t('If this is a phylogenetic (non taxonomic) tree, then
          the tree nodes will be automatically associated with features. However,
          if the nodes in the tree file are not exactly as the names of features
          but have enough information to uniquely identify the feature then you
          may provide a regular expression that the importer will use to extract
          the feature names from the node names.')
      '#default_value' $name_re
      ];
    $form['match'] =[
    '#title' t('Use Unique Feature Name')
      '#type' 'checkbox'
      '#description' t('If this is a phylogenetic (non taxonomic tree) and the nodes ' . 'should match the unique name of the feature rather than the name of the feature ' . 'then select this box. If unselected the loader will try to match the feature ' . 'using the feature name.')
      '#default_value' $match
      ];

    return $form;
  }

  /**
   * @see TripalImporter::formValidate()
   */
  public function formValidate($form, &$form_state) {

    $values = $form_state['values'];

    $options =[
    'name' trim($values["tree_name"])
      'description' trim($values["description"])
      'analysis_id' $values["analysis_id"]
      'leaf_type' $values["leaf_type"]
      'tree_file' $this->arguments['files'][0]['file_path']
      'format' 'newick'
      'dbxref' trim($values["dbxref"])
      'match' $values["match"]
      'name_re' $values["name_re"]
      ];

    $errors =[];
    $warnings =[];

    chado_validate_phylotree('insert', $options, $errors, $warnings);

    // Now set form errors if any errors were detected.
    if (count($errors) > 0) {
      foreach ($errors as $field => $message) {
        if ($field == 'name') {
          $field = 'tree_name';
        }
        form_set_error($field, $message);
      }
    }
    // Add any warnings if any were detected
    if (count($warnings) > 0) {
      foreach ($warnings as $field => $message) {
        drupal_set_message($message, 'warning');
      }
    }
  }

  /**
   * @see TripalImporter::run()
   */
  public function run() {

    $arguments = $this->arguments['run_args'];

    $options = array(
      'name' => $this->arguments["tree_name"],
      'description' => $this->arguments["description"],
      'analysis_id' => $this->arguments["analysis_id"],
      'leaf_type' => $this->arguments["leaf_type"],
      'tree_file' => $this->arguments['files'][0]['file_path'],
      'format' => 'newick',
      'dbxref' => $this->arguments["dbxref"],
      'match' => $this->arguments["match"],
      'name_re' => $this->arguments["name_re"],
    );
    $errors = array();
    $warnings = array();
    chado_insert_phylotree($options, $errors, $warnings);
  }
}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
NewickImporter::$button_text public static property Text that should appear on the button at the bottom of the importer form. Overrides TripalImporter::$button_text
NewickImporter::$description public static property A brief description for this loader. This description will be presented to the site user. Overrides TripalImporter::$description
NewickImporter::$file_types public static property An array containing the extensions of allowed file types. Overrides TripalImporter::$file_types
NewickImporter::$machine_name public static property The machine name for this loader. This name will be used to construct the URL for the loader. Overrides TripalImporter::$machine_name
NewickImporter::$methods public static property Indicates the methods that the file uploader will support. Overrides TripalImporter::$methods
NewickImporter::$name public static property The name of this loader. This name will be presented to the site user. Overrides TripalImporter::$name
NewickImporter::$upload_description public static property Provides information to the user about the file upload. Typically this may include a description of the file types allowed. Overrides TripalImporter::$upload_description
NewickImporter::$upload_title public static property The title that should appear above the file upload section. Overrides TripalImporter::$upload_title
NewickImporter::form public function Overrides TripalImporter::form
NewickImporter::formValidate public function Overrides TripalImporter::formValidate
NewickImporter::run public function Overrides TripalImporter::run
TripalImporter::$arguments protected property The arguments needed for the importer. This is a list of key/value pairs in an associative array.
TripalImporter::$argument_list public static property The array of arguments used for this loader. Each argument should be a separate array containing a machine_name, name, and description keys. This information is used to build the help text for the loader.
TripalImporter::$cardinality public static property Indicates how many files are allowed to be uploaded. By default this is set to allow only one file. Change to any positive number. A value of zero indicates an unlimited number of uploaded files are allowed.
TripalImporter::$file_required public static property Indicates if the file must be provided. An example when it may not be necessary to require that the user provide a file for uploading if the loader keeps track of previous files and makes those available for selection.
TripalImporter::$import_id protected property The ID for this import record.
TripalImporter::$interval private property The interval when the job progress should be updated. Updating the job progress incurrs a database write which takes time and if it occurs to frequently can slow down the loader. This should be a value between 0 and 100 to indicate a percent interval…
TripalImporter::$is_prepared protected property Prior to running an importer it must be prepared to make sure the file is available. Preparing the importer will download all the necessary files. This value is set to TRUE after the importer is prepared for funning.
TripalImporter::$job protected property The job that this importer is associated with. This is needed for updating the status of the job.
TripalImporter::$menu_path public static property Be default, all loaders are automaticlly added to the Admin > Tripal > Data Laders menu. However, if this loader should be made available via a different menu path, then set it here. If the value is empty then the path will be the default.
TripalImporter::$num_handled private property The number of items that have been handled so far. This must never be below 0 and never exceed $total_items;
TripalImporter::$prev_update private property Each time the job progress is updated this variable gets set. It is used to calculate if the $interval has passed for the next update.
TripalImporter::$require_analysis public static property If the $use_analysis value is set above then this value indicates if the analysis should be required.
TripalImporter::$total_items private property The number of items that this importer needs to process. A progress can be calculated by dividing the number of items process by this number.
TripalImporter::$use_analysis public static property If the loader should require an analysis record. To maintain provenance we should always indiate where the data we are uploading comes from. The method that Tripal attempts to use for this by associating upload files with an analysis record. The…
TripalImporter::addItemsHandled protected function Adds to the count of the total number of items that have been handled.
TripalImporter::byID static public function Instantiates a new TripalImporter object using the import record ID.
TripalImporter::cleanFile public function Cleans up any temporary files that were created by the prepareFile().
TripalImporter::create public function Creates a new importer record.
TripalImporter::formSubmit public function Handles submission of the form elements.
TripalImporter::load public function Loads an existing import record into this object.
TripalImporter::logMessage public function Logs a message for the importer.
TripalImporter::postRun public function Performs the import.
TripalImporter::prepareFiles public function Prepares the importer files for execution.
TripalImporter::setInterval protected function Updates the percent interval when the job progress is updated.
TripalImporter::setItemsHandled protected function Sets the number of items that have been processed.
TripalImporter::setJob public function Associate this importer with the Tripal job that is running it.
TripalImporter::setTotalItems protected function Sets the total number if items to be processed.
TripalImporter::submitJob public function Submits the importer for execution as a job.
TripalImporter::__construct public function Instantiates a new TripalImporter object.