tripal/tripal_blast

View on GitHub
tripal_blast.install

Summary

Maintainability
Test Coverage
<?php
/**
 * @file
 * .install file of Tripal BLAST.
 *
 * Contains hooks to handle installation of this module.
 *
 * Specifically, a database table (blastdb) is created to store additional information
 * related to blast database nodes such as the name/path to the NCBI BLAST database files
 * and the type (protein or nucleotide) of the database.
 */

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\tripal_blast\TripalBlastDatabaseInterface;

/**
 * Implements hook_install().
 *
 * @see tripal.info
 */
function tripal_blast_install() {
  // Retreives the Drupal relative directory for a Tripal module.
  // @upgrade tripal_create_files_dir('tripal_blast');
}

/**
 * Implements hook_uninstall().
 */
function tripal_blast_uninstall() {
  // Delete configuration entity.
  $database_entity = \Drupal::entityTypeManager()->getStorage('tripalblastdatabase');
  $entity_query = $database_entity->getQuery();

  $blast_db = $entity_query
    ->condition('id', '>', 0)
    ->execute();

  // Load multiples or single item load($id)
  $db = $database_entity->loadMultiple($blast_db);
  foreach($db as $id => $db_obj) {
    $db_id = $db_obj->getId();

    $databae_entity->load($db_id)
      ->delete();
  }
}

/**
 * Implements hook_schema().
 * Create the blast job database table for storing blast job requests.
 */
function tripal_blast_schema() {
  // BLAST JOBS
  // ------------------------
  // Keeps track of additional information related to tripal blast jobs.
  $schema['blastjob'] = array(
    'description' => t('Keeps track of additional information related to tripal blast jobs.'),
    'fields' => array(
      'job_id' => array(
        'description' => t('The Tripal job_id for the blast job.'),
        'type' => 'int',
        'unsigned' => true,
        'not null' => true,
      ),
      'blast_program' => array(
        'description' => t('The program to use to run the blast (ie: blastn, blastp, etc.).'),
        'type' => 'varchar',
        'length' => 20,
        'not null' => true,
      ),
      'target_blastdb' => array(
        'description' => t('The nid of the blastdb used to search against; NULL if target was uploaded.'),
        'type' => 'int',
        'unsigned' => true,
      ),
      'target_file' => array(
        'description' => t('The absolute path to the uploaded blast database after it was run through makeblastdb; NULL if target was NOT uploaded.'),
        'type' => 'text',
      ),
      'query_file' => array(
        'description' => t('The absolute path to the query file.'),
        'type' => 'text',
      ),
      'result_filestub' => array(
        'description' => t('The absolute path and filename (without extension) of the blast results.'),
        'type' => 'text',
      ),
      'options' => array(
        'description' => t('A serialized array of options selected for the blast job where the key is the machine name of the option used when calling blast (ie: gapextend) and the value is the value of the option.'),
        'type' => 'text',
      ),
    ),
    'primary key' => array('job_id'),
    'foreign keys' => array(
      'job_id' => array(
        'table' => 'tripal_jobs',
        'columns' => array(
          'job_id' => 'job_id',
        ),
      ),
    ),
  );

  return $schema;
}