tripal_featuremap.install 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. 'featuremap_units', 0, 1, 'tripal');
  112. tripal_cv_add_cvterm(array('name' => 'bp','def' => 'Base pairs units'),
  113. 'featuremap_units', 0, 1, 'tripal');
  114. tripal_cv_add_cvterm(array('name' => 'bin_unit','def' => 'The bin unit'),
  115. 'featuremap_units', 0, 1, 'tripal');
  116. tripal_cv_add_cvterm(array('name' => 'marker_order','def' => 'Units simply to define marker order.'),
  117. 'featuremap_units', 0, 1, 'tripal');
  118. tripal_cv_add_cvterm(array('name' => 'undefined','def' => 'A catch-all for an undefined unit type'),
  119. 'featuremap_units', 0, 1, 'tripal');
  120. tripal_cv_add_cvterm(array('name' => 'start','def' => 'The start coordinate for a map feature.'),
  121. 'featurepos_property', 0, 1, 'tripal');
  122. tripal_cv_add_cvterm(array('name' => 'stop','def' => 'The end coordinate for a map feature'),
  123. 'featurepos_property', 0, 1, 'tripal');
  124. // add cvterms for map properties
  125. 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)'),
  126. 'featuremap_property', 0, 1, 'tripal');
  127. tripal_cv_add_cvterm(array('name' => 'Map Type','def' => 'The type of Map (e.g. QTL, Physical, etc.)'),
  128. 'featuremap_property', 0, 1, 'tripal');
  129. tripal_cv_add_cvterm(array('name' => 'Genome Group','def' => ''),
  130. 'featuremap_property', 0, 1, 'tripal');
  131. 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.'),
  132. 'featuremap_property', 0, 1, 'tripal');
  133. 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).'),
  134. 'featuremap_property', 0, 1, 'tripal');
  135. tripal_cv_add_cvterm(array('name' => 'Population Size','def' => 'The size of the population used to construct the map.'),
  136. 'featuremap_property', 0, 1, 'tripal');
  137. tripal_cv_add_cvterm(array('name' => 'Methods','def' => 'A brief description of the methods used to construct the map.'),
  138. 'featuremap_property', 0, 1, 'tripal');
  139. tripal_cv_add_cvterm(array('name' => 'Software','def' => 'The software used to construct the map.'),
  140. 'featuremap_property', 0, 1, 'tripal');
  141. }
  142. /*
  143. *
  144. */
  145. function tripal_featuremap_add_custom_tables(){
  146. // add the featuremaprop table to Chado
  147. $schema = array (
  148. 'table' => 'featuremapprop',
  149. 'fields' => array (
  150. 'featuremapprop_id' => array (
  151. 'type' => 'serial',
  152. 'not null' => true,
  153. ),
  154. 'featuremap_id' => array (
  155. 'type' => 'int',
  156. 'not null' => true,
  157. ),
  158. 'type_id' => array (
  159. 'type' => 'int',
  160. 'not null' => true,
  161. ),
  162. 'value' => array (
  163. 'type' => 'text',
  164. 'not null' => false,
  165. ),
  166. 'rank' => array (
  167. 'type' => 'int',
  168. 'not null' => true,
  169. 'default' => 0,
  170. ),
  171. ),
  172. 'primary key' => array (
  173. 0 => 'featuremapprop_id',
  174. ),
  175. 'unique keys' => array (
  176. 'featuremapprop_c1' => array (
  177. 0 => 'featuremap_id',
  178. 1 => 'type_id',
  179. 2 => 'rank',
  180. ),
  181. ),
  182. 'indexes' => array (
  183. 'featuremapprop_idx1' => array (
  184. 0 => 'featuremap_id',
  185. ),
  186. 'featuremapprop_idx2' => array (
  187. 0 => 'type_id',
  188. ),
  189. ),
  190. 'foreign keys' => array (
  191. 'cvterm' => array (
  192. 'table' => 'cvterm',
  193. 'columns' => array (
  194. 'type_id' => 'cvterm_id',
  195. ),
  196. ),
  197. 'featuremap' => array (
  198. 'table' => 'featuremap',
  199. 'columns' => array (
  200. 'featuremap_id' => 'featuremap_id',
  201. ),
  202. ),
  203. ),
  204. );
  205. tripal_core_create_custom_table($ret, 'featuremapprop', $schema, TRUE);
  206. // add the featuremap_dbxref table to Chado
  207. $schema = array (
  208. 'table' => 'featuremap_dbxref',
  209. 'fields' => array (
  210. 'featuremap_dbxref_id' => array (
  211. 'type' => 'serial',
  212. 'not null' => true,
  213. ),
  214. 'featuremap_id' => array (
  215. 'type' => 'int',
  216. 'not null' => true,
  217. ),
  218. 'dbxref_id' => array (
  219. 'type' => 'int',
  220. 'not null' => true,
  221. ),
  222. ),
  223. 'primary key' => array (
  224. 0 => 'featuremap_dbxref_id',
  225. ),
  226. 'unique keys' => array (
  227. 'featuremap_dbxref_c1' => array (
  228. 0 => 'featuremap_id',
  229. 1 => 'dbxref_id',
  230. ),
  231. ),
  232. 'indexes' => array (
  233. 'featuremap_dbxref_idx1' => array (
  234. 0 => 'featuremap_dbxref_id',
  235. ),
  236. 'featuremap_dbxref_idx2' => array (
  237. 0 => 'dbxref_id',
  238. ),
  239. ),
  240. 'foreign keys' => array (
  241. 'dbxref' => array (
  242. 'table' => 'dbxref',
  243. 'columns' => array (
  244. 'dbxref_id' => 'dbxref_id',
  245. ),
  246. ),
  247. 'featuremap' => array (
  248. 'table' => 'featuremap',
  249. 'columns' => array (
  250. 'featuremap_id' => 'featuremap_id',
  251. ),
  252. ),
  253. ),
  254. 'referring_tables' => NULL,
  255. );
  256. tripal_core_create_custom_table($ret, 'featuremap_dbxref', $schema, TRUE);
  257. $schema = array (
  258. 'table' => 'featureposprop',
  259. 'fields' => array (
  260. 'featureposprop_id' => array (
  261. 'type' => 'serial',
  262. 'not null' => true,
  263. ),
  264. 'featurepos_id' => array (
  265. 'type' => 'int',
  266. 'not null' => true,
  267. ),
  268. 'type_id' => array (
  269. 'type' => 'int',
  270. 'not null' => true,
  271. ),
  272. 'value' => array (
  273. 'type' => 'text',
  274. 'not null' => false,
  275. ),
  276. 'rank' => array (
  277. 'type' => 'int',
  278. 'not null' => true,
  279. 'default' => 0,
  280. ),
  281. ),
  282. 'primary key' => array (
  283. 0 => 'featureposprop_id',
  284. ),
  285. 'unique keys' => array (
  286. 'featureposprop_id' => array (
  287. 0 => 'featurepos_id',
  288. 1 => 'type_id',
  289. 2 => 'rank',
  290. ),
  291. ),
  292. 'indexes' => array (
  293. 'featureposprop_c1' => array (
  294. 0 => 'featurepos_id',
  295. ),
  296. 'featureposprop_idx2' => array (
  297. 0 => 'type_id',
  298. ),
  299. ),
  300. 'foreign keys' => array (
  301. 'cvterm' => array (
  302. 'table' => 'cvterm',
  303. 'columns' => array (
  304. 'type_id' => 'cvterm_id',
  305. ),
  306. ),
  307. 'featurepos' => array (
  308. 'table' => 'featurepos',
  309. 'columns' => array (
  310. 'featurepos_id' => 'featurepos_id',
  311. ),
  312. ),
  313. ),
  314. );
  315. tripal_core_create_custom_table($ret, 'featureposprop', $schema, TRUE);
  316. }
  317. /**
  318. * Update for Drupal 6.x, Tripal 1.1, FeatureMap Module 1.1
  319. * This update adds a new featuremapprop, featureposprop, and featuremap_dbxref tables and
  320. * CV terms for the featuremap_property CV
  321. *
  322. */
  323. function tripal_featuremap_update_6100() {
  324. tripal_featuremap_add_custom_tables();
  325. tripal_featuremap_add_cvterms();
  326. $ret = array(
  327. '#finished' => 1,
  328. );
  329. return $ret;
  330. }