tripal_chado.install 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. <?php
  2. function tripal_chado_install() {
  3. // // The foreign key specification doesn't really add one to the
  4. // // Drupal schema, it is just used internally, but we want one.
  5. // db_query('
  6. // ALTER TABLE {tripal_custom_tables}
  7. // ADD CONSTRAINT tripal_custom_tables_fk1
  8. // FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
  9. // ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
  10. // ');
  11. if (chado_is_installed()) {
  12. // For an upgraded site we need to move some vocabulary terms over
  13. // to the new 'local' vocabulary:
  14. tripal_insert_db(array(
  15. 'name' => 'local',
  16. 'description' => variable_get('site_name', 'This site.'),
  17. ));
  18. // Move the library properties out of the tripal database and into the
  19. // local database.
  20. $sql = "
  21. UPDATE {dbxref}
  22. SET db_id = (SELECT db_id FROM {db} WHERE name = 'local')
  23. WHERE dbxref_id IN (
  24. SELECT DISTINCT CVT.dbxref_id
  25. FROM {cvterm} CVT
  26. INNER JOIN {cv} CV ON CV.cv_id = CVT.cv_id
  27. WHERE CV.name IN (
  28. 'library_property',
  29. 'library_type',
  30. 'project_property',
  31. 'nd_experiment_types',
  32. 'nd_geolocation_property',
  33. 'tripal_analysis'
  34. )
  35. )
  36. ";
  37. chado_query($sql);
  38. }
  39. }
  40. /**
  41. * Implementation of hook_uninstall().
  42. *
  43. * @ingroup tripal
  44. */
  45. function tripal_chado_uninstall() {
  46. // // Drop the foreign key between tripal_custom_tables and tripal_mviews
  47. // // so that Drupal can then drop the tables
  48. // db_query('
  49. // ALTER TABLE {tripal_custom_tables}
  50. // DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
  51. // ');
  52. variable_set('tripal_chado_is_prepared', FALSE);
  53. }
  54. function tripal_chado_chado_semweb_schema(){
  55. return array(
  56. 'fields' => array(
  57. 'chado_semweb_id' => array(
  58. 'type' => 'serial',
  59. 'not null' => TRUE
  60. ),
  61. 'chado_table' => array(
  62. 'type' => 'varchar',
  63. 'length ' => 128,
  64. 'not null' => TRUE
  65. ),
  66. 'chado_column' => array(
  67. 'type' => 'text',
  68. 'length ' => 128,
  69. 'not null' => TRUE
  70. ),
  71. 'cvterm_id' => array(
  72. 'type' => 'int',
  73. ),
  74. ),
  75. 'primary key' => array(
  76. 0 => 'chado_semweb_id',
  77. ),
  78. 'indexes' => array(
  79. 'chado_semweb_id_idx1' => array('cvterm_id'),
  80. 'chado_semweb_id_idx2' => array('chado_column'),
  81. 'chado_semweb_id_idx3' => array('chado_table'),
  82. ),
  83. 'unique keys' => array(
  84. 'chado_semweb_uq1' => array('chado_table', 'chado_column'),
  85. ),
  86. );
  87. }
  88. /**
  89. * Table definition for the tripal_cv_obo table
  90. * @param $schema
  91. */
  92. function tripal_chado_tripal_cv_obo_schema() {
  93. return array(
  94. 'fields' => array(
  95. 'obo_id' => array(
  96. 'type' => 'serial',
  97. 'unsigned' => TRUE,
  98. 'not null' => TRUE
  99. ),
  100. 'name' => array(
  101. 'type' => 'varchar',
  102. 'length' => 255
  103. ),
  104. 'path' => array(
  105. 'type' => 'varchar',
  106. 'length' => 1024
  107. ),
  108. ),
  109. 'indexes' => array(
  110. 'tripal_cv_obo_idx1' => array('obo_id'),
  111. ),
  112. 'primary key' => array('obo_id'),
  113. );
  114. }
  115. /**
  116. *
  117. */
  118. function tripal_chado_enable() {
  119. // If Tripal v2 is already installed, then when the module is first enabled
  120. // after an upgade, the installation of this module will try and recreate
  121. // some of the tables created with tripal_core and the installation will fail.
  122. // Therefore, the tables were temporarily moved out of the way to preserve
  123. // the data. Now we'll move them back.
  124. tripal_chado_upgrade_v2_v3_enable();
  125. }
  126. /**
  127. * Implements hook_schema().
  128. */
  129. function tripal_chado_schema() {
  130. // If Tripal v2 is already installed, then when the module is first enabled
  131. // after an upgade, the installation of this module will try and recreate
  132. // some of the tables created with tripal_core and the installation will fail.
  133. // Therefore, we need to temporarily move those tables out of the way, let
  134. // the module install and then move them back.
  135. $migrated = variable_get('tripal_v2_upgrade_v3_check_chado', FALSE);
  136. if (!$migrated) {
  137. try {
  138. tripal_chado_upgrade_v2_v3_pre_enable();
  139. variable_set('tripal_v2_upgrade_v3_check_chado', TRUE);
  140. }
  141. catch(Exception $e) {
  142. watchdog_exception('tripal_chado', $e);
  143. }
  144. }
  145. // Links TripalEntity entities to the chado record.
  146. $schema['chado_bundle'] = tripal_chado_chado_bundle_schema();
  147. $schema['chado_semweb'] = tripal_chado_chado_semweb_schema();
  148. $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();
  149. $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();
  150. $schema['tripal_cv_obo'] = tripal_chado_tripal_cv_obo_schema();
  151. $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();
  152. // if this module is already installed and enabled, then we want to provide
  153. // the schemas for all of the custom tables. This will allow Views to
  154. // see the schemas. We check if the module is installed because during
  155. // installation we don't want to make these custom tables available as we don't
  156. // want them created in the Drupal database. The custom tables go in the
  157. // Chado database.
  158. if (db_table_exists('tripal_custom_tables')) {
  159. $sql = 'SELECT * FROM {tripal_custom_tables}';
  160. $results = db_query($sql);
  161. foreach ($results as $custom) {
  162. $schema[$custom->table_name] = unserialize($custom->schema);
  163. }
  164. }
  165. // Map cvterm usage to chado tables
  166. $schema['chado_cvterm_mapping'] = tripal_chado_chado_cvterm_mapping_schema();
  167. // When a chado Tripal content type is created, a linking table is also created to
  168. // link the entity to it's record in chado (@see tripal_chado_bundle_create() ).
  169. // This table is created via db_create_table() but in order to expose it to
  170. // the Drupal Schema API, we also need to define each one here.
  171. if (db_table_exists('chado_bundle')) {
  172. $resource = db_query('SELECT tb.name FROM chado_bundle cb LEFT JOIN tripal_bundle tb ON tb.id=cb.bundle_id');
  173. foreach ($resource as $r) {
  174. $bundle_name = $r->name;
  175. // This makes an assumption about the name of the linking table.
  176. // @todo: Switch to chado_get_bundle_entity_table($bundle).
  177. $chado_entity_table = 'chado_' . $bundle_name;
  178. $schema[$chado_entity_table] = array(
  179. 'description' => 'The linker table that associates TripalEntities with Chado records for entities of type ' . $bundle_name . '.',
  180. 'fields' => array(
  181. 'mapping_id' => array(
  182. 'type' => 'serial',
  183. 'not null' => TRUE
  184. ),
  185. 'entity_id' => array(
  186. 'description' => 'The unique entity id.',
  187. 'type' => 'int',
  188. 'not null' => TRUE,
  189. ),
  190. 'record_id' => array(
  191. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  192. 'type' => 'int',
  193. 'not null' => TRUE,
  194. ),
  195. 'nid' => array(
  196. 'description' => 'Optional. For linking nid to the entity when migrating Tripal v2 content',
  197. 'type' => 'int',
  198. )
  199. ),
  200. 'primary key' => array(
  201. 'mapping_id',
  202. ),
  203. 'indexes' => array(
  204. 'record_id' => array('record_id'),
  205. 'entity_id' => array('entity_id'),
  206. 'nid' => array('nid'),
  207. ),
  208. 'unique keys' => array(
  209. 'table_record' => array('record_id'),
  210. 'entity_id' => array('entity_id'),
  211. ),
  212. );
  213. }
  214. }
  215. return $schema;
  216. }
  217. /**
  218. * This function should be executed only one time during upgrade of v2 to v3.
  219. */
  220. function tripal_chado_upgrade_v2_v3_pre_enable() {
  221. // If Tripal v2 is already installed, then when the module is first enabled
  222. // after an upgade, the installation of this module will try and recreate
  223. // some of the tables created with tripal_core and the installation will fail.
  224. // Therefore, we need to temporarily move those tables out of the way, let
  225. // the module install and then move them back.
  226. if (db_table_exists('tripal_mviews')) {
  227. // Move the tripal_mviews table out of the way.
  228. $sql = "ALTER TABLE tripal_mviews RENAME TO tripal_mviews2";
  229. db_query($sql);
  230. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_name_key'")->fetchField()) {
  231. $sql = "ALTER INDEX tripal_mviews_mv_name_key RENAME TO tripal_mviews_mv_name_key2";
  232. }
  233. else {
  234. $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_name_key2 ON tripal_mviews2 USING btree (name)";
  235. }
  236. db_query($sql);
  237. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_table_key'")->fetchField()) {
  238. $sql = "ALTER INDEX tripal_mviews_mv_table_key RENAME TO tripal_mviews_mv_table_key2";
  239. }
  240. else {
  241. $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_table_key2 ON tripal_mviews2 USING btree (mv_table)";
  242. }
  243. db_query($sql);
  244. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mview_id_idx'")->fetchField()) {
  245. $sql = "ALTER INDEX tripal_mviews_mview_id_idx RENAME TO tripal_mviews_mview_id_idx2";
  246. }
  247. else {
  248. $sql = "CREATE INDEX tripal_mviews_mview_id_idx2 ON tripal_mviews2 USING btree (mview_id)";
  249. }
  250. db_query($sql);
  251. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_pkey'")->fetchField()) {
  252. $sql = "ALTER INDEX tripal_mviews_pkey RENAME TO tripal_mviews_pkey2";
  253. }
  254. else {
  255. $sql = "CREATE UNIQUE INDEX tripal_mviews_pkey2 ON tripal_mviews2 USING btree (mview_id)";
  256. }
  257. db_query($sql);
  258. }
  259. if (db_table_exists('tripal_custom_tables')) {
  260. // Move the tripal_custom_tables table out of the way.
  261. $sql = "ALTER TABLE tripal_custom_tables RENAME TO tripal_custom_tables2";
  262. db_query($sql);
  263. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_pkey'")->fetchField()) {
  264. $sql = "ALTER INDEX tripal_custom_tables_pkey RENAME TO tripal_custom_tables_pkey2";
  265. }
  266. else {
  267. $sql = "CREATE UNIQUE INDEX tripal_custom_tables_pkey2 ON tripal_custom_tables2 USING btree (table_id)";
  268. }
  269. db_query($sql);
  270. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_table_id_idx'")->fetchField()) {
  271. $sql = "ALTER INDEX tripal_custom_tables_table_id_idx RENAME TO tripal_custom_tables_table_id_idx2";
  272. }
  273. else {
  274. $sql = "CREATE INDEX tripal_custom_tables_table_id_idx2 ON tripal_custom_tables2 USING btree (table_id)";
  275. }
  276. db_query($sql);
  277. }
  278. if (db_table_exists('tripal_cv_obo')) {
  279. // Move the tripal_cv_obo table out of the way.
  280. $sql = "ALTER TABLE tripal_cv_obo RENAME TO tripal_cv_obo2";
  281. db_query($sql);
  282. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_obo_id_idx'")->fetchField()) {
  283. $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx RENAME TO tripal_cv_obo_obo_id_idx2";
  284. }
  285. else if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_tripal_cv_obo_idx1_idx'")->fetchField()) {
  286. $sql = "ALTER INDEX tripal_cv_obo_tripal_cv_obo_idx1_idx RENAME TO tripal_cv_obo_obo_id_idx2";
  287. }
  288. else {
  289. $sql = "CREATE INDEX tripal_cv_obo_obo_id_idx2 ON tripal_cv_obo2 USING btree (obo_id)";
  290. }
  291. db_query($sql);
  292. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey'")->fetchField()) {
  293. $sql = "ALTER INDEX tripal_cv_obo_pkey RENAME TO tripal_cv_obo_pkey2";
  294. }
  295. else {
  296. $sql = "CREATE UNIQUE INDEX tripal_cv_obo_pkey2 ON tripal_cv_obo2 USING btree (obo_id)";
  297. }
  298. db_query($sql);
  299. }
  300. if (db_table_exists('tripal_pub_import')) {
  301. // Move the tripal_pub_import table out of the way.
  302. $sql = "ALTER TABLE tripal_pub_import RENAME TO tripal_pub_import2";
  303. db_query($sql);
  304. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_name_idx'")->fetchField()) {
  305. $sql = "ALTER INDEX tripal_pub_import_name_idx RENAME TO tripal_pub_import_name_idx2";
  306. }
  307. else {
  308. $sql = "CREATE INDEX tripal_pub_import_name_idx2 ON tripal_pub_import2 USING btree (name)";
  309. }
  310. db_query($sql);
  311. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_pkey'")->fetchField()) {
  312. $sql = "ALTER INDEX tripal_pub_import_pkey RENAME TO tripal_pub_import_pkey2";
  313. }
  314. else {
  315. $sql = "CREATE UNIQUE INDEX tripal_pub_import_pkey2 ON tripal_pub_import2 USING btree (pub_import_id)";
  316. }
  317. db_query($sql);
  318. }
  319. }
  320. /**
  321. * This function should be executed only one time during upgrade of v2 to v3.
  322. */
  323. function tripal_chado_upgrade_v2_v3_enable() {
  324. // If Tripal v2 is already installed, the installation of this module
  325. // will try and recreate some of the tables created with tripal_core and the
  326. // installation will fail. Therefore, in the install we renamed it. Now
  327. // we want to move it back.
  328. if (db_table_exists('tripal_mviews2')) {
  329. // tripal_mviews
  330. $sql = "DROP TABLE tripal_mviews";
  331. db_query($sql);
  332. $sql = "ALTER TABLE tripal_mviews2 RENAME to tripal_mviews";
  333. db_query($sql);
  334. $sql = "ALTER INDEX tripal_mviews_mv_name_key2 RENAME TO tripal_mviews_mv_name_key";
  335. db_query($sql);
  336. $sql = "ALTER INDEX tripal_mviews_mv_table_key2 RENAME TO tripal_mviews_mv_table_key";
  337. db_query($sql);
  338. $sql = "ALTER INDEX tripal_mviews_mview_id_idx2 RENAME TO tripal_mviews_mview_id_idx";
  339. db_query($sql);
  340. $sql = "ALTER INDEX tripal_mviews_pkey2 RENAME TO tripal_mviews_pkey";
  341. db_query($sql);
  342. }
  343. // tripal_custom_tables
  344. if (db_table_exists('tripal_custom_tables2')) {
  345. $sql = "DROP TABLE tripal_custom_tables";
  346. db_query($sql);
  347. $sql = "ALTER TABLE tripal_custom_tables2 RENAME to tripal_custom_tables";
  348. db_query($sql);
  349. $sql = "ALTER INDEX tripal_custom_tables_pkey2 RENAME TO tripal_custom_tables_pkey";
  350. db_query($sql);
  351. $sql = "ALTER INDEX tripal_custom_tables_table_id_idx2 RENAME TO tripal_custom_tables_table_id_idx";
  352. db_query($sql);
  353. }
  354. // tripal_cv_obo
  355. if (db_table_exists('tripal_cv_obo2')) {
  356. $sql = "DROP TABLE tripal_cv_obo";
  357. db_query($sql);
  358. $sql = "ALTER TABLE tripal_cv_obo2 RENAME to tripal_cv_obo";
  359. db_query($sql);
  360. $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx2 RENAME TO tripal_cv_obo_obo_id_idx";
  361. db_query($sql);
  362. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey2'")->fetchField()) {
  363. $sql = "ALTER INDEX tripal_cv_obo_pkey2 RENAME TO tripal_cv_obo_pkey";
  364. }
  365. db_query($sql);
  366. }
  367. // tripal_pub_import
  368. if (db_table_exists('tripal_pub_import2')) {
  369. $sql = "DROP TABLE tripal_pub_import";
  370. db_query($sql);
  371. $sql = "ALTER TABLE tripal_pub_import2 RENAME to tripal_pub_import";
  372. db_query($sql);
  373. $sql = "ALTER INDEX tripal_pub_import_name_idx2 RENAME TO tripal_pub_import_name_idx";
  374. db_query($sql);
  375. $sql = "ALTER INDEX tripal_pub_import_pkey2 RENAME TO tripal_pub_import_pkey";
  376. db_query($sql);
  377. }
  378. }
  379. /**
  380. * @section
  381. * Schema Definitions.
  382. */
  383. /**
  384. * Implementation of hook_schema().
  385. *
  386. * @ingroup tripal_pub
  387. */
  388. function tripal_chado_tripal_pub_import_schema() {
  389. return array(
  390. 'fields' => array(
  391. 'pub_import_id' => array(
  392. 'type' => 'serial',
  393. 'not null' => TRUE
  394. ),
  395. 'name' => array(
  396. 'type' => 'varchar',
  397. 'length' => 255,
  398. 'not null' => TRUE
  399. ),
  400. 'criteria' => array(
  401. 'type' => 'text',
  402. 'size' => 'normal',
  403. 'not null' => TRUE,
  404. 'description' => 'Contains a serialized PHP array containing the search criteria'
  405. ),
  406. 'disabled' => array(
  407. 'type' => 'int',
  408. 'unsigned' => TRUE,
  409. 'not NULL' => TRUE,
  410. 'default' => 0
  411. ),
  412. 'do_contact' => array(
  413. 'type' => 'int',
  414. 'unsigned' => TRUE,
  415. 'not NULL' => TRUE,
  416. 'default' => 0
  417. ),
  418. ),
  419. 'primary key' => array('pub_import_id'),
  420. 'indexes' => array(
  421. 'name' => array('name')
  422. ),
  423. );
  424. }
  425. /**
  426. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  427. * This keeps track of tables created by Tripal and stored in chado that may or may not
  428. * also be materialized views.
  429. *
  430. * @ingroup tripal
  431. */
  432. function tripal_chado_tripal_custom_tables_schema() {
  433. return array(
  434. 'fields' => array(
  435. 'table_id' => array(
  436. 'type' => 'serial',
  437. 'unsigned' => TRUE,
  438. 'not NULL' => TRUE
  439. ),
  440. 'table_name' => array(
  441. 'type' => 'varchar',
  442. 'length' => 255,
  443. 'not NULL' => TRUE
  444. ),
  445. 'schema' => array(
  446. 'type' => 'text',
  447. 'not NULL' => TRUE
  448. ),
  449. 'mview_id' => array(
  450. 'type' => 'int',
  451. 'not NULL' => FALSE
  452. )
  453. ),
  454. 'indexes' => array(
  455. 'table_id' => array('table_id'),
  456. ),
  457. 'primary key' => array('table_id'),
  458. 'foreign keys' => array(
  459. 'tripal_mviews' => array(
  460. 'table' => 'tripal_mviews',
  461. 'columns' => array(
  462. 'mview_id' => 'mview_id'
  463. ),
  464. ),
  465. ),
  466. );
  467. }
  468. /**
  469. * Describes the Tripal Materialized View (tripal_mviews) table
  470. * This table keeps track of all materialized views created by Tripal and stored in chado
  471. *
  472. * @ingroup tripal
  473. */
  474. function tripal_chado_tripal_mviews_schema() {
  475. return array(
  476. 'fields' => array(
  477. 'mview_id' => array(
  478. 'type' => 'serial',
  479. 'unsigned' => TRUE,
  480. 'not NULL' => TRUE
  481. ),
  482. 'name' => array(
  483. 'type' => 'varchar',
  484. 'length' => 255,
  485. 'not NULL' => TRUE
  486. ),
  487. 'modulename' => array(
  488. 'type' => 'varchar',
  489. 'length' => 50,
  490. 'not NULL' => TRUE,
  491. 'description' => 'The module name that provides the callback for this job'
  492. ),
  493. 'mv_table' => array(
  494. 'type' => 'varchar',
  495. 'length' => 128,
  496. 'not NULL' => FALSE
  497. ),
  498. 'mv_specs' => array(
  499. 'type' => 'text',
  500. 'size' => 'normal',
  501. 'not NULL' => FALSE
  502. ),
  503. 'mv_schema' => array(
  504. 'type' => 'text',
  505. 'size' => 'normal',
  506. 'not NULL' => FALSE
  507. ),
  508. 'indexed' => array(
  509. 'type' => 'text',
  510. 'size' => 'normal',
  511. 'not NULL' => FALSE
  512. ),
  513. 'query' => array(
  514. 'type' => 'text',
  515. 'size' => 'normal',
  516. 'not NULL' => TRUE
  517. ),
  518. 'special_index' => array(
  519. 'type' => 'text',
  520. 'size' => 'normal',
  521. 'not NULL' => FALSE
  522. ),
  523. 'last_update' => array(
  524. 'type' => 'int',
  525. 'not NULL' => FALSE,
  526. 'description' => 'UNIX integer time'
  527. ),
  528. 'status' => array(
  529. 'type' => 'text',
  530. 'size' => 'normal',
  531. 'not NULL' => FALSE
  532. ),
  533. 'comment' => array(
  534. 'type' => 'text',
  535. 'size' => 'normal',
  536. 'not NULL' => FALSE
  537. ),
  538. ),
  539. 'indexes' => array(
  540. 'mview_id' => array('mview_id')
  541. ),
  542. 'unique keys' => array(
  543. 'mv_table' => array('mv_table'),
  544. 'mv_name' => array('name'),
  545. ),
  546. 'primary key' => array('mview_id'),
  547. );
  548. }
  549. /**
  550. * Links Biological Data Entities to the chado "base" table the data is stored in.
  551. * This is where we would specify that a particular gene maps to the record in the
  552. * chado.feature table with a feature_id=2432;
  553. */
  554. function tripal_chado_chado_bundle_schema() {
  555. $schema = array(
  556. 'description' => 'Describes how a bundle maps data to Chado',
  557. 'fields' => array(
  558. 'chado_bundle_id' => array(
  559. 'description' => 'The primary identifier for this table.',
  560. 'type' => 'serial',
  561. 'unsigned' => TRUE,
  562. 'not null' => TRUE,
  563. ),
  564. 'bundle_id' => array(
  565. 'description' => 'The unique entity id.',
  566. 'type' => 'int',
  567. 'not null' => TRUE,
  568. ),
  569. 'data_table' => array(
  570. 'description' => 'The table in Chado that this term services (e.g. feature, stock, library, etc.)',
  571. 'type' => 'varchar',
  572. 'length' => 128,
  573. 'not null' => TRUE,
  574. 'default' => '',
  575. ),
  576. 'type_linker_table' => array(
  577. 'description' => 'If a linker table (e.g. cvterm/prop) is needed to uniquely identify a content type then that table name is provided here.',
  578. 'type' => 'varchar',
  579. 'length' => 128,
  580. 'not null' => FALSE,
  581. 'default' => '',
  582. ),
  583. 'type_column' => array(
  584. 'description' => 'The column in the data table or linker table that distinguishes the data type. This must be in a foreign key relationship to the cvterm table.',
  585. 'type' => 'varchar',
  586. 'length' => 128,
  587. 'not null' => FALSE,
  588. 'default' => '',
  589. ),
  590. 'type_id' => array(
  591. 'description' => 'If a type_column is set then this is the cvterm_id of the data type that this bundle maps to.',
  592. 'type' => 'varchar',
  593. 'length' => 128,
  594. 'not null' => TRUE,
  595. 'default' => '',
  596. ),
  597. 'type_value' => array(
  598. 'description' => 'If a property table is used for a linker, then the value that should be matched to identify this content type is stored here.',
  599. 'type' => 'text',
  600. 'not null' => FALSE,
  601. 'default' => '',
  602. )
  603. ),
  604. 'indexes' => array(
  605. 'bundle_id' => array('bundle_id'),
  606. 'data_table' => array('data_table'),
  607. ),
  608. 'unique keys' => array(
  609. 'record' => array('bundle_id'),
  610. ),
  611. 'primary key' => array('chado_bundle_id'),
  612. );
  613. return $schema;
  614. }
  615. /**
  616. * Tripal cvterm mapping schema
  617. * Map cvterms to chado tables that use them
  618. */
  619. function tripal_chado_chado_cvterm_mapping_schema() {
  620. $schema = array (
  621. 'table' => 'chado_cvterm_mapping',
  622. 'fields' => array (
  623. 'mapping_id' => array(
  624. 'type' => 'serial',
  625. 'not null' => TRUE
  626. ),
  627. 'cvterm_id' => array (
  628. 'type' => 'int',
  629. 'not null' => TRUE
  630. ),
  631. 'chado_table' => array (
  632. 'type' => 'varchar',
  633. 'length' => 128,
  634. 'not null' => TRUE
  635. ),
  636. 'chado_field' => array (
  637. 'type' => 'varchar',
  638. 'length' => 128,
  639. 'not null' => FALSE
  640. ),
  641. ),
  642. 'primary key' => array (
  643. 0 => 'mapping_id'
  644. ),
  645. 'unique key' => array(
  646. 'cvterm_id',
  647. ),
  648. 'indexes' => array(
  649. 'tripal_cvterm2table_idx1' => array('cvterm_id'),
  650. 'tripal_cvterm2table_idx2' => array('chado_table'),
  651. 'tripal_cvterm2table_idx3' => array('chado_table', 'chado_field'),
  652. ),
  653. );
  654. return $schema;
  655. }
  656. /**
  657. * Fixes the phase on the tripal_gffcds_temp table used for importing GFF files, and fixes the db.name term mapping.
  658. *
  659. */
  660. function tripal_chado_update_7300() {
  661. try {
  662. if (chado_table_exists('tripal_gffcds_temp')) {
  663. chado_query("ALTER TABLE {tripal_gffcds_temp} ALTER COLUMN phase DROP NOT NULL;");
  664. }
  665. $term = tripal_insert_cvterm(array(
  666. 'id' => 'data:1048',
  667. 'name' => 'Database ID',
  668. 'cv_name' => 'EDAM',
  669. 'definition' => 'An identifier of a biological or bioinformatics database.',
  670. ));
  671. tripal_associate_chado_semweb_term('db', 'name', $term);
  672. }
  673. catch (\PDOException $e) {
  674. $error = $e->getMessage();
  675. throw new DrupalUpdateException('Could not fix phase on tripal_gffcds_temp table: '. $error);
  676. }
  677. }
  678. /**
  679. * Divides chado_entity table for better integration with views.
  680. */
  681. function tripal_chado_update_7301() {
  682. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.bundle');
  683. try {
  684. $transaction = db_transaction();
  685. $query = db_select('chado_bundle', 'CB');
  686. $query->join('tripal_bundle', 'TB', 'TB.id = CB.bundle_id');
  687. $query->fields('CB', array('data_table'));
  688. $query->fields('TB', array('name'));
  689. $cbundles = $query->execute();
  690. // If the table for the bundle doesn't exist then create one, and then
  691. // move all of the records from the chado_entity table to it.
  692. while($cbundle = $cbundles->fetchObject()) {
  693. $cbundle_table = chado_get_bundle_entity_table($cbundle);
  694. if (!db_table_exists($cbundle_table)) {
  695. // Create the bundle table.
  696. tripal_chado_create_bundle_table($cbundle);
  697. // Now move the records over.
  698. $sql = "
  699. INSERT INTO {$cbundle_table} (entity_id, record_id, nid)
  700. SELECT CE.entity_id, CE.record_id, CE.nid
  701. FROM {chado_entity} CE
  702. INNER JOIN {tripal_entity} TE ON CE.entity_id = TE.id
  703. WHERE TE.bundle = :bundle
  704. ";
  705. db_query($sql, array(':bundle' => $cbundle->name));
  706. }
  707. }
  708. // Now remove the chado_entity table.
  709. db_drop_table('chado_entity');
  710. }
  711. catch (\PDOException $e) {
  712. $transaction->rollback();
  713. $error = $e->getMessage();
  714. throw new DrupalUpdateException('Could not perform update: '. $error);
  715. }
  716. }
  717. /**
  718. * Corrections to the EDAM database.
  719. */
  720. function tripal_chado_update_7302(){
  721. try {
  722. // Add the term for the field.
  723. tripal_insert_db(array(
  724. 'name' => 'format',
  725. 'description' => 'A defined way or layout of representing and structuring data in a computer file, blob, string, message, or elsewhere. The main focus in EDAM lies on formats as means of structuring data exchanged between different tools or resources. ',
  726. 'url' => 'http://edamontology.org/page',
  727. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  728. ));
  729. tripal_insert_db(array(
  730. 'name' => 'operation',
  731. 'description' => 'A function that processes a set of inputs and results in a set of outputs, or associates arguments (inputs) with values (outputs). Special cases are: a) An operation that consumes no input (has no input arguments).',
  732. 'url' => 'http://edamontology.org/page',
  733. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  734. ));
  735. tripal_insert_db(array(
  736. 'name' => 'topic',
  737. 'description' => 'A category denoting a rather broad domain or field of interest, of study, application, work, data, or technology. Topics have no clearly defined borders between each other.',
  738. 'url' => 'http://edamontology.org/page',
  739. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  740. ));
  741. tripal_insert_cv(
  742. 'EDAM',
  743. 'EDAM is an ontology of well established, familiar concepts that are prevalent within bioinformatics, including types of data and data identifiers, data formats, operations and topics. EDAM is a simple ontology - essentially a set of terms with synonyms and definitions - organised into an intuitive hierarchy for convenient use by curators, software developers and end-users. EDAM is suitable for large-scale semantic annotations and categorization of diverse bioinformatics resources. EDAM is also suitable for diverse application including for example within workbenches and workflow-management systems, software distributions, and resource registries.'
  744. );
  745. }
  746. catch (\PDOException $e) {
  747. $transaction->rollback();
  748. $error = $e->getMessage();
  749. throw new DrupalUpdateException('Could not perform update: '. $error);
  750. }
  751. }
  752. /**
  753. * Fixes inconsistency with Chado v1.3 update if was applied.
  754. */
  755. function tripal_chado_update_7303() {
  756. try {
  757. $chado_version = chado_get_version();
  758. if ($chado_version == '1.3') {
  759. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.setup');
  760. tripal_chado_fix_v1_3_custom_tables();
  761. }
  762. }
  763. catch (\PDOException $e) {
  764. $transaction->rollback();
  765. $error = $e->getMessage();
  766. throw new DrupalUpdateException('Could not perform update: '. $error);
  767. }
  768. }
  769. /**
  770. * Add some new controlled vocabulary terms.
  771. */
  772. function tripal_chado_update_7304() {
  773. try {
  774. $term = tripal_insert_cvterm(array(
  775. 'id' => 'SIO:001080',
  776. 'name' => 'vocabulary',
  777. 'cv_name' => 'SIO',
  778. 'definition' => 'A vocabulary is a collection of terms.',
  779. ));
  780. tripal_associate_chado_semweb_term('cvterm', 'cv_id', $term);
  781. $term = tripal_insert_cvterm(array(
  782. 'id' => 'data:2976',
  783. 'name' => 'Protein sequence',
  784. 'cv_name' => 'EDAM',
  785. 'definition' => 'One or more protein sequences, possibly with associated annotation.',
  786. ));
  787. $term = tripal_insert_cvterm(array(
  788. 'id' => 'local:fmin',
  789. 'name' => 'minimal boundary',
  790. 'definition' => 'The leftmost, minimal boundary in the linear range ' .
  791. 'represented by the feature location. Sometimes this is called ' .
  792. 'start although this is confusing because it does not necessarily ' .
  793. 'represent the 5-prime coordinate.',
  794. 'cv_name' => 'local',
  795. ));
  796. tripal_associate_chado_semweb_term('featureloc', 'fmin', $term);
  797. $term = tripal_insert_cvterm(array(
  798. 'id' => 'local:fmax',
  799. 'name' => 'maximal boundary',
  800. 'definition' => 'The rightmost, maximal boundary in the linear range ' .
  801. 'represented by the featureloc. Sometimes this is called end although ' .
  802. 'this is confusing because it does not necessarily represent the ' .
  803. '3-prime coordinate',
  804. 'cv_name' => 'local',
  805. ));
  806. tripal_associate_chado_semweb_term('featureloc', 'fmax', $term);
  807. $term = tripal_insert_cvterm(array(
  808. 'id' => 'data:2336',
  809. 'name' => 'Translation phase specification',
  810. 'cv_name' => 'EDAM',
  811. 'definition' => 'Phase for translation of DNA (0, 1 or 2) relative to a fragment of the coding sequence.',
  812. ));
  813. tripal_associate_chado_semweb_term('featureloc', 'phase', $term);
  814. $term = tripal_insert_cvterm(array(
  815. 'id' => 'data:3002',
  816. 'name' => 'Annotation track',
  817. 'cv_name' => 'EDAM',
  818. 'definition' => 'Annotation of one particular positional feature on a ' .
  819. 'biomolecular (typically genome) sequence, suitable for import and ' .
  820. 'display in a genome browser. Synonym: Sequence annotation track.',
  821. ));
  822. tripal_associate_chado_semweb_term('featureloc', 'srcfeature_id', $term);
  823. }
  824. catch (\PDOException $e) {
  825. $transaction->rollback();
  826. $error = $e->getMessage();
  827. throw new DrupalUpdateException('Could not perform update: '. $error);
  828. }
  829. }
  830. /**
  831. * Adding missing cv/db details and cvterms.
  832. */
  833. function tripal_chado_update_7305() {
  834. try {
  835. tripal_insert_db(array(
  836. 'name' => 'rdfs',
  837. 'description' => 'Resource Description Framework Schema',
  838. 'url' => 'https://www.w3.org/TR/rdf-schema/',
  839. 'urlprefix' => 'https://www.w3.org/TR/rdf-schema/#ch_{accession}',
  840. ));
  841. tripal_insert_cv('rdfs', 'Resource Description Framework Schema');
  842. tripal_insert_db(array(
  843. 'name' => 'SO',
  844. 'description' => 'The sequence ontology.',
  845. 'url' => 'http://www.sequenceontology.org/',
  846. 'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',
  847. ));
  848. tripal_insert_cv('sequence', 'The sequence ontology.');
  849. tripal_insert_db(array(
  850. 'name' => 'TAXRANK',
  851. 'description' => 'A vocabulary of taxonomic ranks (species, family, phylum, etc)',
  852. 'url' => 'http://www.obofoundry.org/ontology/taxrank.html',
  853. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  854. ));
  855. tripal_insert_cv('taxonomic_rank', 'A vocabulary of taxonomic ranks (species, family, phylum, etc)');
  856. tripal_insert_db(array(
  857. 'name' => 'hydra',
  858. 'description' => 'A Vocabulary for Hypermedia-Driven Web APIs',
  859. 'url' => 'https://www.hydra-cg.com/spec/latest/core/',
  860. 'urlprefix' => 'https://www.hydra-cg.com/spec/latest/core/#{db}:{accession}',
  861. ));
  862. tripal_insert_cv(
  863. 'hydra',
  864. 'A Vocabulary for Hypermedia-Driven Web APIs.'
  865. );
  866. tripal_insert_db(array(
  867. 'name' => 'dc',
  868. 'description' => 'DCMI Metadata Terms.',
  869. 'url' => 'http://purl.org/dc/dcmitype/',
  870. 'urlprefix' => 'http://purl.org/dc/terms/{accession}',
  871. ));
  872. tripal_insert_cv(
  873. 'dc',
  874. 'DCMI Metadata Terms.'
  875. );
  876. $term = tripal_insert_cvterm(array(
  877. 'id' => 'dc:Service',
  878. 'name' => 'Service',
  879. 'cv_name' => 'dc',
  880. 'definition' => 'A system that provides one or more functions.',
  881. ));
  882. $name = tripal_insert_cvterm(array(
  883. 'id' => 'hydra:Collection',
  884. 'name' => 'Collection',
  885. 'cv_name' => 'hydra',
  886. 'definition' => 'A collection holding references to a number of related resources.',
  887. ));
  888. $name = tripal_insert_cvterm(array(
  889. 'id' => 'hydra:member',
  890. 'name' => 'member',
  891. 'cv_name' => 'hydra',
  892. 'definition' => 'A member of the collection',
  893. ));
  894. $name = tripal_insert_cvterm(array(
  895. 'id' => 'hydra:description',
  896. 'name' => 'description',
  897. 'cv_name' => 'hydra',
  898. 'definition' => 'A description.',
  899. ));
  900. $name = tripal_insert_cvterm(array(
  901. 'id' => 'hydra:totalItems',
  902. 'name' => 'totalItems',
  903. 'cv_name' => 'hydra',
  904. 'definition' => 'The total number of items referenced by a collection.',
  905. ));
  906. $name = tripal_insert_cvterm(array(
  907. 'id' => 'hydra:title',
  908. 'name' => 'title',
  909. 'cv_name' => 'hydra',
  910. 'definition' => 'A title, often used along with a description.',
  911. ));
  912. $name = tripal_insert_cvterm(array(
  913. 'id' => 'hydra:PartialCollectionView',
  914. 'name' => 'PartialCollectionView',
  915. 'cv_name' => 'hydra',
  916. 'definition' => 'A PartialCollectionView describes a partial view of a Collection. Multiple PartialCollectionViews can be connected with the the next/previous properties to allow a client to retrieve all members of the collection.',
  917. ));
  918. $term = tripal_insert_cvterm(array(
  919. 'id' => 'schema:ItemPage',
  920. 'name' => 'ItemPage',
  921. 'cv_name' => 'schema',
  922. 'definition' => 'A page devoted to a single item, such as a particular product or hotel.',
  923. ));
  924. global $base_path;
  925. tripal_insert_db(array(
  926. 'name' => 'null',
  927. 'description' => 'No online database.',
  928. 'url' => $base_path . 'cv/lookup/null',
  929. 'urlprefix' => $base_path. 'cv/lookup/{db}/{accession}',
  930. ));
  931. tripal_insert_db(array(
  932. 'name' => 'local',
  933. 'description' => 'Terms created for this site.',
  934. 'url' => $base_path . 'cv/lookup/local',
  935. 'urlprefix' => $base_path . 'cv/lookup/{db}/{accession}',
  936. ));
  937. $term = tripal_insert_cvterm(array(
  938. 'id' => 'local:rank',
  939. 'name' => 'rank',
  940. 'definition' => 'A taxonmic rank',
  941. 'cv_name' => 'local',
  942. ));
  943. }
  944. catch (\PDOException $e) {
  945. $transaction->rollback();
  946. $error = $e->getMessage();
  947. throw new DrupalUpdateException('Could not perform update: '. $error);
  948. }
  949. }
  950. /**
  951. * Add cvterm mapping for the Map entity type
  952. */
  953. function tripal_chado_update_7306() {
  954. try {
  955. $identifier = array(
  956. 'cv_id' => array('name' => 'EDAM'),
  957. 'name' => 'Map'
  958. );
  959. $cvterm = tripal_get_cvterm($identifier);
  960. tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'featuremap', NULL);
  961. }
  962. catch (\PDOException $e) {
  963. $error = $e->getMessage();
  964. throw new DrupalUpdateException('Could not perform update: '. $error);
  965. }
  966. }
  967. /**
  968. * Add cvterm mapping for the Publication entity type
  969. */
  970. function tripal_chado_update_7307() {
  971. try {
  972. $identifier = array(
  973. 'cv_id' => array('name' => 'tripal_pub'),
  974. 'name' => 'Publication'
  975. );
  976. $cvterm = tripal_get_cvterm($identifier);
  977. tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'pub', NULL);
  978. }
  979. catch (\PDOException $e) {
  980. $error = $e->getMessage();
  981. throw new DrupalUpdateException('Could not perform update: '. $error);
  982. }
  983. }
  984. /**
  985. * Add cvterm mapping for the analysis.sourcversion and analysis.sourcename.
  986. */
  987. function tripal_chado_update_7308() {
  988. try {
  989. $term = tripal_insert_cvterm(array(
  990. 'id' => 'IAO:0000129',
  991. 'name' => 'version number',
  992. 'cv_name' => 'IAO',
  993. 'definition' => 'A version number is an ' .
  994. 'information content entity which is a sequence of characters ' .
  995. 'borne by part of each of a class of manufactured products or its ' .
  996. 'packaging and indicates its order within a set of other products ' .
  997. 'having the same name.',
  998. ));
  999. tripal_associate_chado_semweb_term('analysis', 'sourceversion', $term);
  1000. tripal_associate_chado_semweb_term(NULL, 'version', $term);
  1001. $term = tripal_insert_cvterm(array(
  1002. 'id' => 'schema:name',
  1003. 'name' => 'name',
  1004. 'cv_name' => 'schema',
  1005. 'definition' => 'The name of the item.',
  1006. ));
  1007. tripal_associate_chado_semweb_term('analysis', 'sourcename', $term);
  1008. $term = tripal_insert_cvterm(array(
  1009. 'id' => 'data:2091',
  1010. 'name' => 'Accession',
  1011. 'cv_name' => 'EDAM',
  1012. 'definition' => 'A persistent (stable) and unique identifier, typically identifying an object (entry) from a database.',
  1013. ));
  1014. tripal_associate_chado_semweb_term('dbxref', 'accession', $term);
  1015. }
  1016. catch (\PDOException $e) {
  1017. $error = $e->getMessage();
  1018. throw new DrupalUpdateException('Could not perform update: '. $error);
  1019. }
  1020. }
  1021. /**
  1022. * Add cvterm 'annotation' and maps to cvterm linking tables.
  1023. */
  1024. function tripal_chado_update_7309() {
  1025. try {
  1026. $term = tripal_insert_cvterm(array(
  1027. 'id' => 'SIO:001166',
  1028. 'name' => 'annotation',
  1029. 'cv_name' => 'SIO',
  1030. 'definition' => 'An annotation is a written explanatory or critical description, or other in-context information (e.g., pattern, motif, link), that has been associated with data or other types of information.',
  1031. ));
  1032. tripal_associate_chado_semweb_term('feature_cvterm', 'cvterm_id', $term);
  1033. tripal_associate_chado_semweb_term('analysis_cvterm', 'cvterm_id', $term);
  1034. tripal_associate_chado_semweb_term('cell_line_cvterm', 'cvterm_id', $term);
  1035. tripal_associate_chado_semweb_term('environment_cvterm', 'cvterm_id', $term);
  1036. tripal_associate_chado_semweb_term('expression_cvterm', 'cvterm_id', $term);
  1037. tripal_associate_chado_semweb_term('library_cvterm', 'cvterm_id', $term);
  1038. tripal_associate_chado_semweb_term('organism_cvterm', 'cvterm_id', $term);
  1039. tripal_associate_chado_semweb_term('phenotype_cvterm', 'cvterm_id', $term);
  1040. tripal_associate_chado_semweb_term('stock_cvterm', 'cvterm_id', $term);
  1041. tripal_associate_chado_semweb_term('stock_relationship_cvterm', 'cvterm_id', $term);
  1042. $term = tripal_insert_cvterm(array(
  1043. 'id' => 'SIO:000281',
  1044. 'name' => 'negation',
  1045. 'cv_name' => 'SIO',
  1046. 'definition' => 'NOT is a logical operator in that has the value true if its operand is false.',
  1047. ));
  1048. tripal_associate_chado_semweb_term('feature_cvterm', 'is_not', $term);
  1049. tripal_associate_chado_semweb_term('analysis_cvterm', 'is_not', $term);
  1050. tripal_associate_chado_semweb_term('organism_cvterm', 'is_not', $term);
  1051. tripal_associate_chado_semweb_term('stock_cvterm', 'is_not', $term);
  1052. }
  1053. catch (\PDOException $e) {
  1054. $error = $e->getMessage();
  1055. throw new DrupalUpdateException('Could not perform update: '. $error);
  1056. }
  1057. }
  1058. /**
  1059. * Adds the 'OBCS' and rank order term.
  1060. */
  1061. function tripal_chado_update_7310() {
  1062. try {
  1063. tripal_insert_db(array(
  1064. 'name' => 'OBCS',
  1065. 'description' => 'Ontology of Biological and Clinical Statistics.',
  1066. 'url' => 'https://github.com/obcs/obcs',
  1067. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  1068. ));
  1069. tripal_insert_cv(
  1070. 'OBCS',
  1071. 'Ontology of Biological and Clinical Statistics.'
  1072. );
  1073. $term = tripal_insert_cvterm(array(
  1074. 'id' => 'OBCS:0000117',
  1075. 'name' => 'rank order',
  1076. 'cv_name' => 'OBCS',
  1077. 'definition' => 'A data item that represents an arrangement according to a rank, i.e., the position of a particular case relative to other cases on a defined scale.',
  1078. ));
  1079. tripal_associate_chado_semweb_term(NULL, 'rank', $term);
  1080. }
  1081. catch (\PDOException $e) {
  1082. $error = $e->getMessage();
  1083. throw new DrupalUpdateException('Could not perform update: '. $error);
  1084. }
  1085. }
  1086. /**
  1087. * Fix a mistake with the association of the term with featureloc.fmin.
  1088. */
  1089. function tripal_chado_update_7311() {
  1090. try {
  1091. $term = tripal_insert_cvterm(array(
  1092. 'id' => 'local:fmin',
  1093. 'name' => 'minimal boundary',
  1094. 'definition' => 'The leftmost, minimal boundary in the linear range ' .
  1095. 'represented by the feature location. Sometimes this is called ' .
  1096. 'start although this is confusing because it does not necessarily ' .
  1097. 'represent the 5-prime coordinate.',
  1098. 'cv_name' => 'local',
  1099. ));
  1100. tripal_associate_chado_semweb_term('featureloc', 'fmin', $term);
  1101. }
  1102. catch (\PDOException $e) {
  1103. $error = $e->getMessage();
  1104. throw new DrupalUpdateException('Could not perform update: '. $error);
  1105. }
  1106. }
  1107. /**
  1108. * Associates a local term with the pub.miniref column.
  1109. */
  1110. function tripal_chado_update_7312() {
  1111. try {
  1112. $term = tripal_insert_cvterm(array(
  1113. 'id' => 'local:miniref',
  1114. 'name' => 'Mini-ref',
  1115. 'definition' => 'A small in-house unique identifier for a publication.',
  1116. 'cv_name' => 'local',
  1117. ));
  1118. tripal_associate_chado_semweb_term('pub', 'miniref', $term);
  1119. $term = tripal_insert_cvterm(array(
  1120. 'id' => 'schema:url',
  1121. 'name' => 'url',
  1122. 'cv_name' => 'schema',
  1123. 'definition' => 'URL of the item.',
  1124. ));
  1125. tripal_associate_chado_semweb_term('db', 'url', $term);
  1126. }
  1127. catch (\PDOException $e) {
  1128. $error = $e->getMessage();
  1129. throw new DrupalUpdateException('Could not perform update: '. $error);
  1130. }
  1131. }