ソースを参照

Setup install and libraries

Reynold Tan 3 年 前
コミット
20d05b2e65

+ 304 - 0
blast_ui.install

@@ -0,0 +1,304 @@
+<?php
+/**
+ * @file
+ * .install file of BLAST UI.
+ *
+ * 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\node\Entity\Node;
+
+/**
+ * Implements hook_install().
+ * 
+ * @see tripal.info
+ */
+function blast_ui_install() {
+  // Retreives the Drupal relative directory for a Tripal module.
+  tripal_create_files_dir('tripal_blast');
+}
+
+/**
+ * Implements hook_uninstall().
+ */
+function blast_ui_uninstall() {
+  // Remove all nodes of type blastdb 
+  $query = \Drupal::entityQuery('node')
+    // Restrict to BLASTDB nodes.
+    ->condition('bundle', 'blastdb')
+    // Restrict to Published nodes.
+    ->condition('status', 1)
+    // Restrict to nodes the current user has permission to view.
+    ->addTag('node_access');
+  
+  $entities = $query->execute();
+
+  // Get all BlastDB nodes and delete them
+  $nodes = Node::loadMultiple(array_keys($entities['node']));
+  foreach ($nodes as $node) {
+    print "Delete node " . $node->title . "\n";
+    $nrs = node_revision_list($node);
+    
+    foreach ($nrs as $nr) {
+      node_revision_delete($nr->vid);
+    }
+    node_delete($node->nid);
+  }
+}
+
+/**
+ * Implements hook_schema().
+ * Create the blastdb database table for storing addditional info related to blastdb nodes.
+ *
+ * NOTE: This hook is called via Drupal magic during the installation process and no longer
+ * needs to be called explicitly in hook_install().
+ */
+function blast_ui_schema() {
+  // A table to keep extra information related to blastdb nodes.
+  $schema['blastdb'] = array(
+    'description' => t('The base table for blastdb node'),
+    'fields' => array(
+      'nid' => array(
+        'description' => t('The primary identifier for a node.'),
+        'type' => 'serial',
+        'unsigned' => true,
+        'not null' => true,
+      ),
+      'name' => array(
+        'description' => t('The human-readable name of the blast database.'),
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => true,
+      ),
+      'path' => array(
+        'description' => t('The full path and filename prefix of the blast database.'),
+        'type' => 'varchar',
+        'length' => 1023,
+        'not null' => true,
+      ),
+      'dbtype' => array(
+        'description' => t('Type of the blast database. Should be either n for nucleotide or p for protein.'),
+        'type' => 'varchar',
+        'length' => 15,
+        'not null' => true,
+      ),
+      'dbxref_id_regex' => array(
+        'description' => t('The Regular Expression to use to extract the id from the FASTA header of the BLAST database hit.'),
+        'type' => 'text',
+      ),
+      'dbxref_db_id' => array(
+        'description' => t('The Database records from this BLAST Database reference.'),
+        'type' => 'int',
+      ),
+      'dbxref_linkout_type' => array(
+        'description' => t('Type of linkout to be used for this database reference.'),
+        'type' => 'varchar',
+        'length' => 50,
+        'not null' => true,
+        'default' => 'link'
+      ),
+      'cvitjs_enabled' => array(
+        'description' => t('Indicate if CViTjs should be used to display hits on a whole genome'),
+        'type' => 'int',
+        'not null' => false,
+        'default' => 0
+      ),
+    ),
+    
+    'indexes' => array(
+      'name' => array('name'),
+    ),
+    
+    'primary key' => array('nid'),
+    'unique keys' => array(
+       'nid' => array('nid'),
+    ),
+  );
+  
+  // 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;
+}
+
+
+// UPDATES:
+
+
+/**
+ * Make BlastDB type more readable & support Link-outs for BLAST Hits.
+ */
+function blast_ui_update_7101() {
+  // Changing the length of the type field to allow it to be more readable.
+  db_change_field('blastdb', 'dbtype', 'dbtype',
+    array(
+        'description' => t('Type of the blast database. Should be either n for nucleotide or p for protein.'),
+        'type' => 'varchar',
+        'length' => 15,
+        'not null' => true,
+    )
+  );
+
+  // Add fields related to Link-outs
+  db_add_field(
+    'blastdb',
+    'dbxref_id_regex',
+    array(
+      'description' => t('The Regular Expression to use to extract the id from the FASTA header of the BLAST database hit.'),
+      'type' => 'text',
+    )
+  );
+  db_add_field(
+    'blastdb',
+    'dbxref_db_id',
+    array(
+      'description' => t('The Database records from this BLAST Database reference.'),
+      'type' => 'int',
+    )
+  );
+}
+
+/**
+ * Support complex types of link-outs such as GBrowse & JBrowse coordinate links.
+ */
+function blast_ui_update_7102() {
+  db_add_field(
+    'blastdb',
+    'dbxref_linkout_type',
+    array(
+      'description' => t('Type of linkout to be used for this database reference.'),
+      'type' => 'varchar',
+      'length' => 50,
+      'not null' => true,
+      'default' => 'link'
+    )
+  );
+}
+
+/**
+ * Add saving of blast job information for recent job list & resubmit functionality.
+ */
+function blast_ui_update_7103() {
+  $schema = array();
+
+  // 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',
+        ),
+      ),
+    ),
+  );
+  
+  // First create the tables.
+  db_create_table('blastjob', $schema['blastjob']);
+}
+
+/**
+ * Add fields to blastp table for CViTjs support.
+ */
+function blast_ui_update_7104() {
+  db_add_field(
+    'blastdb',
+    'cvitjs_enabled',
+    array(
+      'description' => t('Indicate if CViTjs should be used to display hits on a whole genome'),
+      'type' => 'int',
+      'not null' => false,
+      'default' => 0
+    )
+  );
+}

+ 18 - 0
blast_ui.libraries.yml

@@ -0,0 +1,18 @@
+
+
+# Styles:
+
+
+# Style BLAST reports.
+style-blastreport:
+  version: v1.x
+  css:
+    theme:
+      css/style-blast-report.css: {}
+
+# Style BLAST input form.
+style-blastform:
+  version: v1.x
+  css:
+    theme:
+      css/style-blast-form.css: {}

+ 1 - 1
blast_ui.module

@@ -1,7 +1,7 @@
 <?php
 /**
  * @file
- * .module file of TripalD3.
+ * .module file of BLAST UI.
  */
 
 use Drupal\Core\Url;

+ 17 - 0
css/style-blast-forms.css

@@ -0,0 +1,17 @@
+/**
+ * @file
+ * Handles CSS Themeing of the BLAST input forms.
+ */
+
+
+div.center {
+  margin-left: auto;
+  margin-right: auto;
+  width: 70%;
+}
+
+.blastdb-extra-info {
+  padding: 10px;
+  border: 1px solid #be7;
+  background-color: #f8fff0;
+}

+ 112 - 0
css/style-blast-report.css

@@ -0,0 +1,112 @@
+/**
+ * @file
+ * Handles CSS Themeing of the BLAST Results
+ */
+
+
+/* -- Ensure users see lack of results. */
+p.blast-no-results {
+  color: red;
+  font-weight: bold;
+  font-style: italic;
+}
+
+/* -- Theme the table of results */
+table#blast_report th {
+  text-align: left;
+}
+
+table#blast_report tr td {
+  vertical-align : top;
+}
+
+table#blast_report tr.odd td {
+  cursor:pointer;
+  vertical-align : top;
+}
+
+table#blast_report .arrow {
+  background:transparent url('../images/arrows.png') no-repeat scroll 0px -16px;
+  width:16px;
+  height:16px;
+  display:block;
+}
+
+table#blast_report div.up {
+  background-position:0px 0px;
+}
+
+table#blast_report td.number, #blast_report th.number {
+  width: 10px;
+  border-left: none;
+}
+
+table#blast_report td.evalue, #blast_report th.evalue {
+  width: 100px;
+}
+
+table#blast_report td.arrow-col, #blast_report th.arrow-col {
+  width: 10px;
+  border-right: none;
+}
+
+
+/* -- Alignment */
+table#blast_report tr.alignment-row .title{
+  font-weight: bold;
+}
+
+table#blast_report tr.alignment-row .hsp-title{
+  padding-top: 15px;
+  font-weight: bold;
+}
+
+table#blast_report tr.alignment-row{
+  width: 100%;
+}
+
+table#blast_report .alignment {
+  width: 625px;
+}
+
+table#blast_report .alignment-title {
+  font-weight: bold;
+}
+
+table#blast_report div.alignment-row{
+  padding: 10px 30px;
+  font-family: monospace;
+  white-space: nowrap;
+}
+
+table#blast_report div.alignment-subrow{
+  padding-bottom: 15px;
+}
+
+
+/* CViTjs support */
+.blast-top:after {
+   clear: both;
+   display: table;
+   content: "";
+}
+
+.blast-job-info {
+  float: left;
+  margin-bottom: 25px;
+}
+
+.cvitjs {
+  float: left;
+  margin-top: 10px;
+  margin-bottom: 25px;
+}
+
+.cvitjs #cvit-div{
+  padding: 5px 0 0 0;
+}
+
+.report-table {
+  clear: both;
+  position: static;
+}

+ 52 - 0
src/Form/TripalBlastUIBlastSubmitForm copy 2.php

@@ -0,0 +1,52 @@
+<?php
+/**
+ * @file 
+ * Construct configuration form of this module.
+ */
+
+namespace Drupal\blast_ui\Form;
+
+use Drupal\Core\Form\ConfigFormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Defines TripalBlastUIBlastSubmitForm class.
+ * All-in-one BLAST submission form.
+ */
+class TripalBlastUIBlastSubmitForm extends ConfigFormBase {
+  const SETTINGS = 'blast_ui.settings';
+  
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'blast_ui_admin_settings';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getEditableConfigNames() {
+    return [
+      static::SETTINGS,
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   * Build form.
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+       
+    return parent::buildForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   * Save configuration.
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+
+    return parent::submitForm($form, $form_state);
+  }
+}

+ 52 - 0
src/Form/TripalBlastUIBlastSubmitForm copy.php

@@ -0,0 +1,52 @@
+<?php
+/**
+ * @file 
+ * Construct configuration form of this module.
+ */
+
+namespace Drupal\blast_ui\Form;
+
+use Drupal\Core\Form\ConfigFormBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Defines TripalBlastUIBlastSubmitForm class.
+ * All-in-one BLAST submission form.
+ */
+class TripalBlastUIBlastSubmitForm extends ConfigFormBase {
+  const SETTINGS = 'blast_ui.settings';
+  
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'blast_ui_admin_settings';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getEditableConfigNames() {
+    return [
+      static::SETTINGS,
+    ];
+  }
+
+  /**
+   * {@inheritdoc}
+   * Build form.
+   */
+  public function buildForm(array $form, FormStateInterface $form_state) {
+       
+    return parent::buildForm($form, $form_state);
+  }
+
+  /**
+   * {@inheritdoc}
+   * Save configuration.
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+
+    return parent::submitForm($form, $form_state);
+  }
+}