tripal_featuremap.install 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /**
  3. * @file
  4. * @todo Add file header description
  5. */
  6. /**
  7. * Implementation of hook_install().
  8. *
  9. * @ingroup tripal_featuremap
  10. */
  11. function tripal_featuremap_install() {
  12. // create the module's data directory
  13. tripal_create_moddir('tripal_featuremap');
  14. // create the tables that correlate drupal nodes with chado
  15. // features, maps, etc....
  16. drupal_install_schema('tripal_featuremap');
  17. // add the featuremapprop table to Chado
  18. tripal_featuremap_add_custom_tables();
  19. // Add cvterms
  20. tripal_featuremap_add_cvterms();
  21. }
  22. /**
  23. * Implementation of hook_schema().
  24. *
  25. * @ingroup tripal_featuremap
  26. */
  27. function tripal_featuremap_schema() {
  28. $schema = tripal_featuremap_get_schemas();
  29. return $schema;
  30. }
  31. /**
  32. * Implementation of hook_uninstall().
  33. *
  34. * @ingroup tripal_featuremap
  35. */
  36. function tripal_featuremap_uninstall() {
  37. drupal_uninstall_schema('tripal_featuremap');
  38. // Get the list of nodes to remove
  39. $sql_lib_id = "SELECT nid, vid ".
  40. "FROM {node} ".
  41. "WHERE type='chado_featuremap'";
  42. $result = db_query($sql_lib_id);
  43. while ($node = db_fetch_object($result)) {
  44. node_delete($node->nid);
  45. }
  46. }
  47. /**
  48. * This function simply defines all tables needed for the module to work
  49. * correctly. By putting the table definitions in a separate function we
  50. * can easily provide the entire list for hook_install or individual
  51. * tables for an update.
  52. *
  53. * @ingroup tripal_featuremap
  54. */
  55. function tripal_featuremap_get_schemas() {
  56. $schema = array();
  57. $schema['chado_featuremap'] = array(
  58. 'fields' => array(
  59. 'vid' => array(
  60. 'type' => 'int',
  61. 'unsigned' => TRUE,
  62. 'not null' => TRUE,
  63. 'default' => 0
  64. ),
  65. 'nid' => array(
  66. 'type' => 'int',
  67. 'unsigned' => TRUE,
  68. 'not null' => TRUE,
  69. 'default' => 0
  70. ),
  71. 'featuremap_id' => array(
  72. 'type' => 'int',
  73. 'not null' => TRUE,
  74. 'default' => 0
  75. )
  76. ),
  77. 'indexes' => array(
  78. 'featuremap_id' => array('featuremap_id')
  79. ),
  80. 'unique keys' => array(
  81. 'nid_vid' => array('nid', 'vid'),
  82. 'vid' => array('vid')
  83. ),
  84. 'primary key' => array('nid'),
  85. );
  86. return $schema;
  87. }
  88. /**
  89. * Implementation of hook_requirements().
  90. */
  91. function tripal_featuremap_requirements($phase) {
  92. $requirements = array();
  93. if ($phase == 'install') {
  94. // make sure chado is installed
  95. if (!tripal_core_is_chado_installed()) {
  96. $requirements ['tripal_featuremap'] = array(
  97. 'title' => "tripal_featuremap",
  98. 'value' => "ERROR: Chado most be installed before this module can be enabled",
  99. 'severity' => REQUIREMENT_ERROR,
  100. );
  101. }
  102. }
  103. return $requirements;
  104. }
  105. /*
  106. *
  107. */
  108. function tripal_featuremap_add_cvterms() {
  109. // add cvterms for the map unit types
  110. tripal_cv_add_cvterm(array('name' => 'cM','def' => 'Centimorgan units'),
  111. 'tripal_featuremap', 0, 1, 'tripal');
  112. tripal_cv_add_cvterm(array('name' => 'bp','def' => 'Base pairs units'),
  113. 'tripal_featuremap', 0, 1, 'tripal');
  114. tripal_cv_add_cvterm(array('name' => 'bin_unit','def' => 'The bin unit'),
  115. 'tripal_featuremap', 0, 1, 'tripal');
  116. tripal_cv_add_cvterm(array('name' => 'marker_order','def' => 'Units simply to define marker order.'),
  117. 'tripal_featuremap', 0, 1, 'tripal');
  118. tripal_cv_add_cvterm(array('name' => 'undefined','def' => 'A catch-all for an undefined unit type'),
  119. 'tripal_featuremap', 0, 1, 'tripal');
  120. // add cvterms for map properties
  121. tripal_cv_add_cvterm(array('name' => 'Map Dbxref','def' => 'A unique identifer for the map in a remote database. The format is a database abbreviation and a unique accession separated by a colon. (e.g. Gramene:tsh1996a)'),
  122. 'featuremap_property', 0, 1, 'tripal');
  123. tripal_cv_add_cvterm(array('name' => 'Map Type','def' => 'The type of Map (e.g. QTL, Physical, etc.)'),
  124. 'featuremap_property', 0, 1, 'tripal');
  125. tripal_cv_add_cvterm(array('name' => 'Genome Group','def' => ''),
  126. 'featuremap_property', 0, 1, 'tripal');
  127. tripal_cv_add_cvterm(array('name' => 'URL','def' => 'A univeral resource locator (URL) reference where the publication can be found. For maps found online, this would be the web address for the map.'),
  128. 'featuremap_property', 0, 1, 'tripal');
  129. tripal_cv_add_cvterm(array('name' => 'Population Type','def' => 'A brief descriptoin of the population type used to generate the map (e.g. RIL, F2, BC1, etc).'),
  130. 'featuremap_property', 0, 1, 'tripal');
  131. tripal_cv_add_cvterm(array('name' => 'Population Size','def' => 'The size of the population used to construct the map.'),
  132. 'featuremap_property', 0, 1, 'tripal');
  133. tripal_cv_add_cvterm(array('name' => 'Methods','def' => 'A brief description of the methods used to construct the map.'),
  134. 'featuremap_property', 0, 1, 'tripal');
  135. tripal_cv_add_cvterm(array('name' => 'Software','def' => 'The software used to construct the map.'),
  136. 'featuremap_property', 0, 1, 'tripal');
  137. }
  138. /*
  139. *
  140. */
  141. function tripal_featuremap_add_custom_tables(){
  142. // add the featuremaprop table to Chado
  143. $schema = array (
  144. 'table' => 'featuremapprop',
  145. 'fields' => array (
  146. 'featuremapprop_id' => array (
  147. 'type' => 'serial',
  148. 'not null' => true,
  149. ),
  150. 'featuremap_id' => array (
  151. 'type' => 'int',
  152. 'not null' => true,
  153. ),
  154. 'type_id' => array (
  155. 'type' => 'int',
  156. 'not null' => true,
  157. ),
  158. 'value' => array (
  159. 'type' => 'text',
  160. 'not null' => false,
  161. ),
  162. 'rank' => array (
  163. 'type' => 'int',
  164. 'not null' => true,
  165. 'default' => 0,
  166. ),
  167. ),
  168. 'primary key' => array (
  169. 0 => 'featuremapprop_id',
  170. ),
  171. 'unique keys' => array (
  172. 'featuremapprop_c1' => array (
  173. 0 => 'featuremap_id',
  174. 1 => 'type_id',
  175. 2 => 'rank',
  176. ),
  177. ),
  178. 'indexes' => array (
  179. 'featuremapprop_idx1' => array (
  180. 0 => 'featuremap_id',
  181. ),
  182. 'featuremapprop_idx2' => array (
  183. 0 => 'type_id',
  184. ),
  185. ),
  186. 'foreign keys' => array (
  187. 'cvterm' => array (
  188. 'table' => 'cvterm',
  189. 'columns' => array (
  190. 'type_id' => 'cvterm_id',
  191. ),
  192. ),
  193. 'featuremap' => array (
  194. 'table' => 'featuremap',
  195. 'columns' => array (
  196. 'featuremap_id' => 'featuremap_id',
  197. ),
  198. ),
  199. ),
  200. );
  201. tripal_core_create_custom_table(&$ret, 'featuremapprop', $schema, TRUE);
  202. // add the featuremap_dbxref table to Chado
  203. $schema = array (
  204. 'table' => 'featuremap_dbxref',
  205. 'fields' => array (
  206. 'featuremap_dbxref_id' => array (
  207. 'type' => 'serial',
  208. 'not null' => true,
  209. ),
  210. 'featuremap_id' => array (
  211. 'type' => 'int',
  212. 'not null' => true,
  213. ),
  214. 'dbxref_id' => array (
  215. 'type' => 'int',
  216. 'not null' => true,
  217. ),
  218. ),
  219. 'primary key' => array (
  220. 0 => 'featuremap_dbxref_id',
  221. ),
  222. 'unique keys' => array (
  223. 'featuremap_dbxref_c1' => array (
  224. 0 => 'featuremap_id',
  225. 1 => 'dbxref_id',
  226. ),
  227. ),
  228. 'indexes' => array (
  229. 'featuremap_dbxref_idx1' => array (
  230. 0 => 'featuremap_dbxref_id',
  231. ),
  232. 'featuremap_dbxref_idx2' => array (
  233. 0 => 'dbxref_id',
  234. ),
  235. ),
  236. 'foreign keys' => array (
  237. 'dbxref' => array (
  238. 'table' => 'dbxref',
  239. 'columns' => array (
  240. 'dbxref_id' => 'dbxref_id',
  241. ),
  242. ),
  243. 'featuremap' => array (
  244. 'table' => 'featuremap',
  245. 'columns' => array (
  246. 'featuremap_id' => 'featuremap_id',
  247. ),
  248. ),
  249. ),
  250. 'referring_tables' => NULL,
  251. );
  252. tripal_core_create_custom_table(&$ret, 'featuremap_dbxref', $schema, TRUE);
  253. }
  254. /**
  255. * Update for Drupal 6.x, Tripal 1.1, FeatureMap Module 1.1
  256. * This update adds a new featuremapprop and featuremap_dbxref tables and
  257. * CV terms for the featuremap_property CV
  258. *
  259. */
  260. function tripal_featuremap_update_6100() {
  261. tripal_featuremap_add_custom_tables();
  262. tripal_featuremap_add_cvterms();
  263. $ret = array(
  264. '#finished' => 1,
  265. );
  266. return $ret;
  267. }