blast_ui.install 9.0 KB

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