blast_ui.install 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <?php
  2. /**
  3. * @file
  4. * .install file of BLAST UI.
  5. *
  6. * Contains hooks to handle installation of this module.
  7. *
  8. * Specifically, a database table (blastdb) is created to store additional information
  9. * related to blast database nodes such as the name/path to the NCBI BLAST database files
  10. * and the type (protein or nucleotide) of the database.
  11. */
  12. use Drupal\node\Entity\Node;
  13. /**
  14. * Implements hook_install().
  15. *
  16. * @see tripal.info
  17. */
  18. function blast_ui_install() {
  19. // Retreives the Drupal relative directory for a Tripal module.
  20. tripal_create_files_dir('tripal_blast');
  21. }
  22. /**
  23. * Implements hook_uninstall().
  24. */
  25. function blast_ui_uninstall() {
  26. // Remove all nodes of type blastdb
  27. $query = \Drupal::entityQuery('node')
  28. // Restrict to BLASTDB nodes.
  29. ->condition('bundle', 'blastdb')
  30. // Restrict to Published nodes.
  31. ->condition('status', 1)
  32. // Restrict to nodes the current user has permission to view.
  33. ->addTag('node_access');
  34. $entities = $query->execute();
  35. // Get all BlastDB nodes and delete them
  36. $nodes = Node::loadMultiple(array_keys($entities['node']));
  37. foreach ($nodes as $node) {
  38. print "Delete node " . $node->title . "\n";
  39. $nrs = node_revision_list($node);
  40. foreach ($nrs as $nr) {
  41. node_revision_delete($nr->vid);
  42. }
  43. node_delete($node->nid);
  44. }
  45. }
  46. /**
  47. * Implements hook_schema().
  48. * Create the blastdb database table for storing addditional info related to blastdb nodes.
  49. *
  50. * NOTE: This hook is called via Drupal magic during the installation process and no longer
  51. * needs to be called explicitly in hook_install().
  52. */
  53. function blast_ui_schema() {
  54. // A table to keep extra information related to blastdb nodes.
  55. $schema['blastdb'] = array(
  56. 'description' => t('The base table for blastdb node'),
  57. 'fields' => array(
  58. 'nid' => array(
  59. 'description' => t('The primary identifier for a node.'),
  60. 'type' => 'serial',
  61. 'unsigned' => true,
  62. 'not null' => true,
  63. ),
  64. 'name' => array(
  65. 'description' => t('The human-readable name of the blast database.'),
  66. 'type' => 'varchar',
  67. 'length' => 255,
  68. 'not null' => true,
  69. ),
  70. 'path' => array(
  71. 'description' => t('The full path and filename prefix of the blast database.'),
  72. 'type' => 'varchar',
  73. 'length' => 1023,
  74. 'not null' => true,
  75. ),
  76. 'dbtype' => array(
  77. 'description' => t('Type of the blast database. Should be either n for nucleotide or p for protein.'),
  78. 'type' => 'varchar',
  79. 'length' => 15,
  80. 'not null' => true,
  81. ),
  82. 'dbxref_id_regex' => array(
  83. 'description' => t('The Regular Expression to use to extract the id from the FASTA header of the BLAST database hit.'),
  84. 'type' => 'text',
  85. ),
  86. 'dbxref_db_id' => array(
  87. 'description' => t('The Database records from this BLAST Database reference.'),
  88. 'type' => 'int',
  89. ),
  90. 'dbxref_linkout_type' => array(
  91. 'description' => t('Type of linkout to be used for this database reference.'),
  92. 'type' => 'varchar',
  93. 'length' => 50,
  94. 'not null' => true,
  95. 'default' => 'link'
  96. ),
  97. 'cvitjs_enabled' => array(
  98. 'description' => t('Indicate if CViTjs should be used to display hits on a whole genome'),
  99. 'type' => 'int',
  100. 'not null' => false,
  101. 'default' => 0
  102. ),
  103. ),
  104. 'indexes' => array(
  105. 'name' => array('name'),
  106. ),
  107. 'primary key' => array('nid'),
  108. 'unique keys' => array(
  109. 'nid' => array('nid'),
  110. ),
  111. );
  112. // BLAST JOBS
  113. // ------------------------
  114. // Keeps track of additional information related to tripal blast jobs.
  115. $schema['blastjob'] = array(
  116. 'description' => t('Keeps track of additional information related to tripal blast jobs.'),
  117. 'fields' => array(
  118. 'job_id' => array(
  119. 'description' => t('The Tripal job_id for the blast job.'),
  120. 'type' => 'int',
  121. 'unsigned' => true,
  122. 'not null' => true,
  123. ),
  124. 'blast_program' => array(
  125. 'description' => t('The program to use to run the blast (ie: blastn, blastp, etc.).'),
  126. 'type' => 'varchar',
  127. 'length' => 20,
  128. 'not null' => true,
  129. ),
  130. 'target_blastdb' => array(
  131. 'description' => t('The nid of the blastdb used to search against; NULL if target was uploaded.'),
  132. 'type' => 'int',
  133. 'unsigned' => true,
  134. ),
  135. 'target_file' => array(
  136. 'description' => t('The absolute path to the uploaded blast database after it was run through makeblastdb; NULL if target was NOT uploaded.'),
  137. 'type' => 'text',
  138. ),
  139. 'query_file' => array(
  140. 'description' => t('The absolute path to the query file.'),
  141. 'type' => 'text',
  142. ),
  143. 'result_filestub' => array(
  144. 'description' => t('The absolute path and filename (without extension) of the blast results.'),
  145. 'type' => 'text',
  146. ),
  147. 'options' => array(
  148. '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.'),
  149. 'type' => 'text',
  150. ),
  151. ),
  152. 'primary key' => array('job_id'),
  153. 'foreign keys' => array(
  154. 'job_id' => array(
  155. 'table' => 'tripal_jobs',
  156. 'columns' => array(
  157. 'job_id' => 'job_id',
  158. ),
  159. ),
  160. ),
  161. );
  162. return $schema;
  163. }
  164. // UPDATES:
  165. /**
  166. * Make BlastDB type more readable & support Link-outs for BLAST Hits.
  167. */
  168. function blast_ui_update_7101() {
  169. // Changing the length of the type field to allow it to be more readable.
  170. db_change_field('blastdb', 'dbtype', 'dbtype',
  171. array(
  172. 'description' => t('Type of the blast database. Should be either n for nucleotide or p for protein.'),
  173. 'type' => 'varchar',
  174. 'length' => 15,
  175. 'not null' => true,
  176. )
  177. );
  178. // Add fields related to Link-outs
  179. db_add_field(
  180. 'blastdb',
  181. 'dbxref_id_regex',
  182. array(
  183. 'description' => t('The Regular Expression to use to extract the id from the FASTA header of the BLAST database hit.'),
  184. 'type' => 'text',
  185. )
  186. );
  187. db_add_field(
  188. 'blastdb',
  189. 'dbxref_db_id',
  190. array(
  191. 'description' => t('The Database records from this BLAST Database reference.'),
  192. 'type' => 'int',
  193. )
  194. );
  195. }
  196. /**
  197. * Support complex types of link-outs such as GBrowse & JBrowse coordinate links.
  198. */
  199. function blast_ui_update_7102() {
  200. db_add_field(
  201. 'blastdb',
  202. 'dbxref_linkout_type',
  203. array(
  204. 'description' => t('Type of linkout to be used for this database reference.'),
  205. 'type' => 'varchar',
  206. 'length' => 50,
  207. 'not null' => true,
  208. 'default' => 'link'
  209. )
  210. );
  211. }
  212. /**
  213. * Add saving of blast job information for recent job list & resubmit functionality.
  214. */
  215. function blast_ui_update_7103() {
  216. $schema = array();
  217. // Keeps track of additional information related to tripal blast jobs.
  218. $schema['blastjob'] = array(
  219. 'description' => t('Keeps track of additional information related to tripal blast jobs.'),
  220. 'fields' => array(
  221. 'job_id' => array(
  222. 'description' => t('The Tripal job_id for the blast job.'),
  223. 'type' => 'int',
  224. 'unsigned' => true,
  225. 'not null' => true,
  226. ),
  227. 'blast_program' => array(
  228. 'description' => t('The program to use to run the blast (ie: blastn, blastp, etc.).'),
  229. 'type' => 'varchar',
  230. 'length' => 20,
  231. 'not null' => true,
  232. ),
  233. 'target_blastdb' => array(
  234. 'description' => t('The nid of the blastdb used to search against; NULL if target was uploaded.'),
  235. 'type' => 'int',
  236. 'unsigned' => true,
  237. ),
  238. 'target_file' => array(
  239. 'description' => t('The absolute path to the uploaded blast database after it was run through makeblastdb; NULL if target was NOT uploaded.'),
  240. 'type' => 'text',
  241. ),
  242. 'query_file' => array(
  243. 'description' => t('The absolute path to the query file.'),
  244. 'type' => 'text',
  245. ),
  246. 'result_filestub' => array(
  247. 'description' => t('The absolute path and filename (without extension) of the blast results.'),
  248. 'type' => 'text',
  249. ),
  250. 'options' => array(
  251. '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.'),
  252. 'type' => 'text',
  253. ),
  254. ),
  255. 'primary key' => array('job_id'),
  256. 'foreign keys' => array(
  257. 'job_id' => array(
  258. 'table' => 'tripal_jobs',
  259. 'columns' => array(
  260. 'job_id' => 'job_id',
  261. ),
  262. ),
  263. ),
  264. );
  265. // First create the tables.
  266. db_create_table('blastjob', $schema['blastjob']);
  267. }
  268. /**
  269. * Add fields to blastp table for CViTjs support.
  270. */
  271. function blast_ui_update_7104() {
  272. db_add_field(
  273. 'blastdb',
  274. 'cvitjs_enabled',
  275. array(
  276. 'description' => t('Indicate if CViTjs should be used to display hits on a whole genome'),
  277. 'type' => 'int',
  278. 'not null' => false,
  279. 'default' => 0
  280. )
  281. );
  282. }