tripal_chado.install 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622
  1. <?php
  2. function tripal_chado_install() {
  3. if (chado_is_installed()) {
  4. // For an upgraded site we need to move some vocabulary terms over
  5. // to the new 'local' vocabulary:
  6. chado_insert_db(array(
  7. 'name' => 'local',
  8. 'description' => variable_get('site_name', 'This site.'),
  9. ));
  10. // Move the library properties out of the tripal database and into the
  11. // local database.
  12. $sql = "
  13. UPDATE {dbxref}
  14. SET db_id = (SELECT db_id FROM {db} WHERE name = 'local')
  15. WHERE dbxref_id IN (
  16. SELECT DISTINCT CVT.dbxref_id
  17. FROM {cvterm} CVT
  18. INNER JOIN {cv} CV ON CV.cv_id = CVT.cv_id
  19. WHERE CV.name IN (
  20. 'library_property',
  21. 'library_type',
  22. 'project_property',
  23. 'nd_experiment_types',
  24. 'nd_geolocation_property',
  25. 'tripal_analysis'
  26. )
  27. )
  28. ";
  29. chado_query($sql);
  30. }
  31. }
  32. /**
  33. * Implementation of hook_uninstall().
  34. *
  35. * @ingroup tripal
  36. */
  37. function tripal_chado_uninstall() {
  38. // // Drop the foreign key between tripal_custom_tables and tripal_mviews
  39. // // so that Drupal can then drop the tables
  40. // db_query('
  41. // ALTER TABLE {tripal_custom_tables}
  42. // DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
  43. // ');
  44. variable_set('tripal_chado_is_prepared', FALSE);
  45. }
  46. function tripal_chado_chado_semweb_schema(){
  47. return array(
  48. 'fields' => array(
  49. 'chado_semweb_id' => array(
  50. 'type' => 'serial',
  51. 'not null' => TRUE
  52. ),
  53. 'chado_table' => array(
  54. 'type' => 'varchar',
  55. 'length ' => 128,
  56. 'not null' => TRUE
  57. ),
  58. 'chado_column' => array(
  59. 'type' => 'text',
  60. 'length ' => 128,
  61. 'not null' => TRUE
  62. ),
  63. 'cvterm_id' => array(
  64. 'type' => 'int',
  65. ),
  66. ),
  67. 'primary key' => array(
  68. 0 => 'chado_semweb_id',
  69. ),
  70. 'indexes' => array(
  71. 'chado_semweb_id_idx1' => array('cvterm_id'),
  72. 'chado_semweb_id_idx2' => array('chado_column'),
  73. 'chado_semweb_id_idx3' => array('chado_table'),
  74. ),
  75. 'unique keys' => array(
  76. 'chado_semweb_uq1' => array('chado_table', 'chado_column'),
  77. ),
  78. );
  79. }
  80. /**
  81. * Table definition for the tripal_cv_obo table
  82. * @param $schema
  83. */
  84. function tripal_chado_tripal_cv_obo_schema() {
  85. return array(
  86. 'fields' => array(
  87. 'obo_id' => array(
  88. 'type' => 'serial',
  89. 'unsigned' => TRUE,
  90. 'not null' => TRUE
  91. ),
  92. 'name' => array(
  93. 'type' => 'varchar',
  94. 'length' => 255
  95. ),
  96. 'path' => array(
  97. 'type' => 'varchar',
  98. 'length' => 1024
  99. ),
  100. ),
  101. 'indexes' => array(
  102. 'tripal_cv_obo_idx1' => array('obo_id'),
  103. ),
  104. 'primary key' => array('obo_id'),
  105. );
  106. }
  107. /**
  108. *
  109. */
  110. function tripal_chado_enable() {
  111. // If Tripal v2 is already installed, then when the module is first enabled
  112. // after an upgade, the installation of this module will try and recreate
  113. // some of the tables created with tripal_core and the installation will fail.
  114. // Therefore, the tables were temporarily moved out of the way to preserve
  115. // the data. Now we'll move them back.
  116. tripal_chado_upgrade_v2_v3_enable();
  117. }
  118. /**
  119. * Implements hook_schema().
  120. */
  121. function tripal_chado_schema() {
  122. // If Tripal v2 is already installed, then when the module is first enabled
  123. // after an upgade, the installation of this module will try and recreate
  124. // some of the tables created with tripal_core and the installation will fail.
  125. // Therefore, we need to temporarily move those tables out of the way, let
  126. // the module install and then move them back.
  127. $migrated = variable_get('tripal_v2_upgrade_v3_check_chado', FALSE);
  128. if (!$migrated) {
  129. try {
  130. tripal_chado_upgrade_v2_v3_pre_enable();
  131. variable_set('tripal_v2_upgrade_v3_check_chado', TRUE);
  132. }
  133. catch(Exception $e) {
  134. watchdog_exception('tripal_chado', $e);
  135. }
  136. }
  137. // Links TripalEntity entities to the chado record.
  138. $schema['chado_bundle'] = tripal_chado_chado_bundle_schema();
  139. $schema['chado_semweb'] = tripal_chado_chado_semweb_schema();
  140. $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();
  141. $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();
  142. $schema['tripal_cv_obo'] = tripal_chado_tripal_cv_obo_schema();
  143. $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();
  144. // if this module is already installed and enabled, then we want to provide
  145. // the schemas for all of the custom tables. This will allow Views to
  146. // see the schemas. We check if the module is installed because during
  147. // installation we don't want to make these custom tables available as we don't
  148. // want them created in the Drupal database. The custom tables go in the
  149. // Chado database.
  150. if (db_table_exists('tripal_custom_tables')) {
  151. $sql = 'SELECT * FROM {tripal_custom_tables}';
  152. $results = db_query($sql);
  153. foreach ($results as $custom) {
  154. $schema[$custom->table_name] = unserialize($custom->schema);
  155. }
  156. }
  157. // Map cvterm usage to chado tables
  158. $schema['chado_cvterm_mapping'] = tripal_chado_chado_cvterm_mapping_schema();
  159. // When a chado Tripal content type is created, a linking table is also created to
  160. // link the entity to it's record in chado (@see tripal_chado_bundle_create() ).
  161. // This table is created via db_create_table() but in order to expose it to
  162. // the Drupal Schema API, we also need to define each one here.
  163. if (db_table_exists('chado_bundle')) {
  164. $resource = db_query('SELECT tb.name FROM chado_bundle cb LEFT JOIN tripal_bundle tb ON tb.id=cb.bundle_id');
  165. foreach ($resource as $r) {
  166. $bundle_name = $r->name;
  167. // This makes an assumption about the name of the linking table.
  168. // @todo: Switch to chado_get_bundle_entity_table($bundle).
  169. $chado_entity_table = 'chado_' . $bundle_name;
  170. $schema[$chado_entity_table] = array(
  171. 'description' => 'The linker table that associates TripalEntities with Chado records for entities of type ' . $bundle_name . '.',
  172. 'fields' => array(
  173. 'mapping_id' => array(
  174. 'type' => 'serial',
  175. 'not null' => TRUE
  176. ),
  177. 'entity_id' => array(
  178. 'description' => 'The unique entity id.',
  179. 'type' => 'int',
  180. 'not null' => TRUE,
  181. ),
  182. 'record_id' => array(
  183. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  184. 'type' => 'int',
  185. 'not null' => TRUE,
  186. ),
  187. 'nid' => array(
  188. 'description' => 'Optional. For linking nid to the entity when migrating Tripal v2 content',
  189. 'type' => 'int',
  190. )
  191. ),
  192. 'primary key' => array(
  193. 'mapping_id',
  194. ),
  195. 'indexes' => array(
  196. 'record_id' => array('record_id'),
  197. 'entity_id' => array('entity_id'),
  198. 'nid' => array('nid'),
  199. ),
  200. 'unique keys' => array(
  201. 'table_record' => array('record_id'),
  202. 'entity_id' => array('entity_id'),
  203. ),
  204. );
  205. }
  206. }
  207. return $schema;
  208. }
  209. /**
  210. * This function should be executed only one time during upgrade of v2 to v3.
  211. */
  212. function tripal_chado_upgrade_v2_v3_pre_enable() {
  213. // If Tripal v2 is already installed, then when the module is first enabled
  214. // after an upgade, the installation of this module will try and recreate
  215. // some of the tables created with tripal_core and the installation will fail.
  216. // Therefore, we need to temporarily move those tables out of the way, let
  217. // the module install and then move them back.
  218. if (db_table_exists('tripal_mviews')) {
  219. // Move the tripal_mviews table out of the way.
  220. $sql = "ALTER TABLE tripal_mviews RENAME TO tripal_mviews2";
  221. db_query($sql);
  222. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_name_key'")->fetchField()) {
  223. $sql = "ALTER INDEX tripal_mviews_mv_name_key RENAME TO tripal_mviews_mv_name_key2";
  224. }
  225. else {
  226. $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_name_key2 ON tripal_mviews2 USING btree (name)";
  227. }
  228. db_query($sql);
  229. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_table_key'")->fetchField()) {
  230. $sql = "ALTER INDEX tripal_mviews_mv_table_key RENAME TO tripal_mviews_mv_table_key2";
  231. }
  232. else {
  233. $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_table_key2 ON tripal_mviews2 USING btree (mv_table)";
  234. }
  235. db_query($sql);
  236. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mview_id_idx'")->fetchField()) {
  237. $sql = "ALTER INDEX tripal_mviews_mview_id_idx RENAME TO tripal_mviews_mview_id_idx2";
  238. }
  239. else {
  240. $sql = "CREATE INDEX tripal_mviews_mview_id_idx2 ON tripal_mviews2 USING btree (mview_id)";
  241. }
  242. db_query($sql);
  243. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_pkey'")->fetchField()) {
  244. $sql = "ALTER INDEX tripal_mviews_pkey RENAME TO tripal_mviews_pkey2";
  245. }
  246. else {
  247. $sql = "CREATE UNIQUE INDEX tripal_mviews_pkey2 ON tripal_mviews2 USING btree (mview_id)";
  248. }
  249. db_query($sql);
  250. }
  251. if (db_table_exists('tripal_custom_tables')) {
  252. // Move the tripal_custom_tables table out of the way.
  253. $sql = "ALTER TABLE tripal_custom_tables RENAME TO tripal_custom_tables2";
  254. db_query($sql);
  255. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_pkey'")->fetchField()) {
  256. $sql = "ALTER INDEX tripal_custom_tables_pkey RENAME TO tripal_custom_tables_pkey2";
  257. }
  258. else {
  259. $sql = "CREATE UNIQUE INDEX tripal_custom_tables_pkey2 ON tripal_custom_tables2 USING btree (table_id)";
  260. }
  261. db_query($sql);
  262. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_table_id_idx'")->fetchField()) {
  263. $sql = "ALTER INDEX tripal_custom_tables_table_id_idx RENAME TO tripal_custom_tables_table_id_idx2";
  264. }
  265. else {
  266. $sql = "CREATE INDEX tripal_custom_tables_table_id_idx2 ON tripal_custom_tables2 USING btree (table_id)";
  267. }
  268. db_query($sql);
  269. }
  270. if (db_table_exists('tripal_cv_obo')) {
  271. // Move the tripal_cv_obo table out of the way.
  272. $sql = "ALTER TABLE tripal_cv_obo RENAME TO tripal_cv_obo2";
  273. db_query($sql);
  274. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_obo_id_idx'")->fetchField()) {
  275. $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx RENAME TO tripal_cv_obo_obo_id_idx2";
  276. }
  277. else if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_tripal_cv_obo_idx1_idx'")->fetchField()) {
  278. $sql = "ALTER INDEX tripal_cv_obo_tripal_cv_obo_idx1_idx RENAME TO tripal_cv_obo_obo_id_idx2";
  279. }
  280. else {
  281. $sql = "CREATE INDEX tripal_cv_obo_obo_id_idx2 ON tripal_cv_obo2 USING btree (obo_id)";
  282. }
  283. db_query($sql);
  284. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey'")->fetchField()) {
  285. $sql = "ALTER INDEX tripal_cv_obo_pkey RENAME TO tripal_cv_obo_pkey2";
  286. }
  287. else {
  288. $sql = "CREATE UNIQUE INDEX tripal_cv_obo_pkey2 ON tripal_cv_obo2 USING btree (obo_id)";
  289. }
  290. db_query($sql);
  291. }
  292. if (db_table_exists('tripal_pub_import')) {
  293. // Move the tripal_pub_import table out of the way.
  294. $sql = "ALTER TABLE tripal_pub_import RENAME TO tripal_pub_import2";
  295. db_query($sql);
  296. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_name_idx'")->fetchField()) {
  297. $sql = "ALTER INDEX tripal_pub_import_name_idx RENAME TO tripal_pub_import_name_idx2";
  298. }
  299. else {
  300. $sql = "CREATE INDEX tripal_pub_import_name_idx2 ON tripal_pub_import2 USING btree (name)";
  301. }
  302. db_query($sql);
  303. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_pkey'")->fetchField()) {
  304. $sql = "ALTER INDEX tripal_pub_import_pkey RENAME TO tripal_pub_import_pkey2";
  305. }
  306. else {
  307. $sql = "CREATE UNIQUE INDEX tripal_pub_import_pkey2 ON tripal_pub_import2 USING btree (pub_import_id)";
  308. }
  309. db_query($sql);
  310. }
  311. }
  312. /**
  313. * This function should be executed only one time during upgrade of v2 to v3.
  314. */
  315. function tripal_chado_upgrade_v2_v3_enable() {
  316. // If Tripal v2 is already installed, the installation of this module
  317. // will try and recreate some of the tables created with tripal_core and the
  318. // installation will fail. Therefore, in the install we renamed it. Now
  319. // we want to move it back.
  320. if (db_table_exists('tripal_mviews2')) {
  321. // tripal_mviews
  322. $sql = "DROP TABLE tripal_mviews";
  323. db_query($sql);
  324. $sql = "ALTER TABLE tripal_mviews2 RENAME to tripal_mviews";
  325. db_query($sql);
  326. $sql = "ALTER INDEX tripal_mviews_mv_name_key2 RENAME TO tripal_mviews_mv_name_key";
  327. db_query($sql);
  328. $sql = "ALTER INDEX tripal_mviews_mv_table_key2 RENAME TO tripal_mviews_mv_table_key";
  329. db_query($sql);
  330. $sql = "ALTER INDEX tripal_mviews_mview_id_idx2 RENAME TO tripal_mviews_mview_id_idx";
  331. db_query($sql);
  332. $sql = "ALTER INDEX tripal_mviews_pkey2 RENAME TO tripal_mviews_pkey";
  333. db_query($sql);
  334. }
  335. // tripal_custom_tables
  336. if (db_table_exists('tripal_custom_tables2')) {
  337. $sql = "DROP TABLE tripal_custom_tables";
  338. db_query($sql);
  339. $sql = "ALTER TABLE tripal_custom_tables2 RENAME to tripal_custom_tables";
  340. db_query($sql);
  341. $sql = "ALTER INDEX tripal_custom_tables_pkey2 RENAME TO tripal_custom_tables_pkey";
  342. db_query($sql);
  343. $sql = "ALTER INDEX tripal_custom_tables_table_id_idx2 RENAME TO tripal_custom_tables_table_id_idx";
  344. db_query($sql);
  345. }
  346. // tripal_cv_obo
  347. if (db_table_exists('tripal_cv_obo2')) {
  348. $sql = "DROP TABLE tripal_cv_obo";
  349. db_query($sql);
  350. $sql = "ALTER TABLE tripal_cv_obo2 RENAME to tripal_cv_obo";
  351. db_query($sql);
  352. $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx2 RENAME TO tripal_cv_obo_obo_id_idx";
  353. db_query($sql);
  354. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey2'")->fetchField()) {
  355. $sql = "ALTER INDEX tripal_cv_obo_pkey2 RENAME TO tripal_cv_obo_pkey";
  356. }
  357. db_query($sql);
  358. }
  359. // tripal_pub_import
  360. if (db_table_exists('tripal_pub_import2')) {
  361. $sql = "DROP TABLE tripal_pub_import";
  362. db_query($sql);
  363. $sql = "ALTER TABLE tripal_pub_import2 RENAME to tripal_pub_import";
  364. db_query($sql);
  365. $sql = "ALTER INDEX tripal_pub_import_name_idx2 RENAME TO tripal_pub_import_name_idx";
  366. db_query($sql);
  367. $sql = "ALTER INDEX tripal_pub_import_pkey2 RENAME TO tripal_pub_import_pkey";
  368. db_query($sql);
  369. }
  370. }
  371. /**
  372. * @section
  373. * Schema Definitions.
  374. */
  375. /**
  376. * Implementation of hook_schema().
  377. *
  378. * @ingroup tripal_pub
  379. */
  380. function tripal_chado_tripal_pub_import_schema() {
  381. return array(
  382. 'fields' => array(
  383. 'pub_import_id' => array(
  384. 'type' => 'serial',
  385. 'not null' => TRUE
  386. ),
  387. 'name' => array(
  388. 'type' => 'varchar',
  389. 'length' => 255,
  390. 'not null' => TRUE
  391. ),
  392. 'criteria' => array(
  393. 'type' => 'text',
  394. 'size' => 'normal',
  395. 'not null' => TRUE,
  396. 'description' => 'Contains a serialized PHP array containing the search criteria'
  397. ),
  398. 'disabled' => array(
  399. 'type' => 'int',
  400. 'unsigned' => TRUE,
  401. 'not NULL' => TRUE,
  402. 'default' => 0
  403. ),
  404. 'do_contact' => array(
  405. 'type' => 'int',
  406. 'unsigned' => TRUE,
  407. 'not NULL' => TRUE,
  408. 'default' => 0
  409. ),
  410. ),
  411. 'primary key' => array('pub_import_id'),
  412. 'indexes' => array(
  413. 'name' => array('name')
  414. ),
  415. );
  416. }
  417. /**
  418. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  419. * This keeps track of tables created by Tripal and stored in chado that may or may not
  420. * also be materialized views.
  421. *
  422. * @ingroup tripal
  423. */
  424. function tripal_chado_tripal_custom_tables_schema() {
  425. return array(
  426. 'fields' => array(
  427. 'table_id' => array(
  428. 'type' => 'serial',
  429. 'unsigned' => TRUE,
  430. 'not NULL' => TRUE
  431. ),
  432. 'table_name' => array(
  433. 'type' => 'varchar',
  434. 'length' => 255,
  435. 'not NULL' => TRUE
  436. ),
  437. 'schema' => array(
  438. 'type' => 'text',
  439. 'not NULL' => TRUE
  440. ),
  441. 'mview_id' => array(
  442. 'type' => 'int',
  443. 'not NULL' => FALSE
  444. )
  445. ),
  446. 'indexes' => array(
  447. 'table_id' => array('table_id'),
  448. ),
  449. 'primary key' => array('table_id'),
  450. 'foreign keys' => array(
  451. 'tripal_mviews' => array(
  452. 'table' => 'tripal_mviews',
  453. 'columns' => array(
  454. 'mview_id' => 'mview_id'
  455. ),
  456. ),
  457. ),
  458. );
  459. }
  460. /**
  461. * Describes the Tripal Materialized View (tripal_mviews) table
  462. * This table keeps track of all materialized views created by Tripal and stored in chado
  463. *
  464. * @ingroup tripal
  465. */
  466. function tripal_chado_tripal_mviews_schema() {
  467. return array(
  468. 'fields' => array(
  469. 'mview_id' => array(
  470. 'type' => 'serial',
  471. 'unsigned' => TRUE,
  472. 'not NULL' => TRUE
  473. ),
  474. 'name' => array(
  475. 'type' => 'varchar',
  476. 'length' => 255,
  477. 'not NULL' => TRUE
  478. ),
  479. 'modulename' => array(
  480. 'type' => 'varchar',
  481. 'length' => 50,
  482. 'not NULL' => TRUE,
  483. 'description' => 'The module name that provides the callback for this job'
  484. ),
  485. 'mv_table' => array(
  486. 'type' => 'varchar',
  487. 'length' => 128,
  488. 'not NULL' => FALSE
  489. ),
  490. 'mv_specs' => array(
  491. 'type' => 'text',
  492. 'size' => 'normal',
  493. 'not NULL' => FALSE
  494. ),
  495. 'mv_schema' => array(
  496. 'type' => 'text',
  497. 'size' => 'normal',
  498. 'not NULL' => FALSE
  499. ),
  500. 'indexed' => array(
  501. 'type' => 'text',
  502. 'size' => 'normal',
  503. 'not NULL' => FALSE
  504. ),
  505. 'query' => array(
  506. 'type' => 'text',
  507. 'size' => 'normal',
  508. 'not NULL' => TRUE
  509. ),
  510. 'special_index' => array(
  511. 'type' => 'text',
  512. 'size' => 'normal',
  513. 'not NULL' => FALSE
  514. ),
  515. 'last_update' => array(
  516. 'type' => 'int',
  517. 'not NULL' => FALSE,
  518. 'description' => 'UNIX integer time'
  519. ),
  520. 'status' => array(
  521. 'type' => 'text',
  522. 'size' => 'normal',
  523. 'not NULL' => FALSE
  524. ),
  525. 'comment' => array(
  526. 'type' => 'text',
  527. 'size' => 'normal',
  528. 'not NULL' => FALSE
  529. ),
  530. ),
  531. 'indexes' => array(
  532. 'mview_id' => array('mview_id')
  533. ),
  534. 'unique keys' => array(
  535. 'mv_table' => array('mv_table'),
  536. 'mv_name' => array('name'),
  537. ),
  538. 'primary key' => array('mview_id'),
  539. );
  540. }
  541. /**
  542. * Links Biological Data Entities to the chado "base" table the data is stored in.
  543. * This is where we would specify that a particular gene maps to the record in the
  544. * chado.feature table with a feature_id=2432;
  545. */
  546. function tripal_chado_chado_bundle_schema() {
  547. $schema = array(
  548. 'description' => 'Describes how a bundle maps data to Chado',
  549. 'fields' => array(
  550. 'chado_bundle_id' => array(
  551. 'description' => 'The primary identifier for this table.',
  552. 'type' => 'serial',
  553. 'unsigned' => TRUE,
  554. 'not null' => TRUE,
  555. ),
  556. 'bundle_id' => array(
  557. 'description' => 'The unique entity id.',
  558. 'type' => 'int',
  559. 'not null' => TRUE,
  560. ),
  561. 'data_table' => array(
  562. 'description' => 'The table in Chado that this term services (e.g. feature, stock, library, etc.)',
  563. 'type' => 'varchar',
  564. 'length' => 128,
  565. 'not null' => TRUE,
  566. 'default' => '',
  567. ),
  568. 'type_linker_table' => array(
  569. 'description' => 'If a linker table (e.g. cvterm/prop) is needed to uniquely identify a content type then that table name is provided here.',
  570. 'type' => 'varchar',
  571. 'length' => 128,
  572. 'not null' => FALSE,
  573. 'default' => '',
  574. ),
  575. 'type_column' => array(
  576. '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.',
  577. 'type' => 'varchar',
  578. 'length' => 128,
  579. 'not null' => FALSE,
  580. 'default' => '',
  581. ),
  582. 'type_id' => array(
  583. 'description' => 'If a type_column is set then this is the cvterm_id of the data type that this bundle maps to.',
  584. 'size' => 'big',
  585. 'type' => 'int',
  586. ),
  587. 'type_value' => array(
  588. '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.',
  589. 'type' => 'text',
  590. 'not null' => FALSE,
  591. 'default' => '',
  592. ),
  593. 'base_type_id' => array(
  594. 'description' => 'If a property table is used for a linker, and if the base table requires a type_id then this is the type that should be used on insert of new records in the base table.',
  595. 'size' => 'big',
  596. 'type' => 'int',
  597. )
  598. ),
  599. 'indexes' => array(
  600. 'bundle_id' => array('bundle_id'),
  601. 'data_table' => array('data_table'),
  602. ),
  603. 'unique keys' => array(
  604. 'record' => array('bundle_id'),
  605. ),
  606. 'primary key' => array('chado_bundle_id'),
  607. );
  608. return $schema;
  609. }
  610. /**
  611. * Tripal cvterm mapping schema
  612. * Map cvterms to chado tables that use them
  613. */
  614. function tripal_chado_chado_cvterm_mapping_schema() {
  615. $schema = array (
  616. 'table' => 'chado_cvterm_mapping',
  617. 'fields' => array (
  618. 'mapping_id' => array(
  619. 'type' => 'serial',
  620. 'not null' => TRUE
  621. ),
  622. 'cvterm_id' => array (
  623. 'type' => 'int',
  624. 'not null' => TRUE
  625. ),
  626. 'chado_table' => array (
  627. 'type' => 'varchar',
  628. 'length' => 128,
  629. 'not null' => TRUE
  630. ),
  631. 'chado_field' => array (
  632. 'type' => 'varchar',
  633. 'length' => 128,
  634. 'not null' => FALSE
  635. ),
  636. ),
  637. 'primary key' => array (
  638. 0 => 'mapping_id'
  639. ),
  640. 'unique key' => array(
  641. 'cvterm_id',
  642. ),
  643. 'indexes' => array(
  644. 'tripal_cvterm2table_idx1' => array('cvterm_id'),
  645. 'tripal_cvterm2table_idx2' => array('chado_table'),
  646. 'tripal_cvterm2table_idx3' => array('chado_table', 'chado_field'),
  647. ),
  648. );
  649. return $schema;
  650. }
  651. /**
  652. * Fixes the phase on the tripal_gffcds_temp table used for importing GFF files, and fixes the db.name term mapping.
  653. *
  654. */
  655. function tripal_chado_update_7300() {
  656. try {
  657. if (chado_table_exists('tripal_gffcds_temp')) {
  658. chado_query("ALTER TABLE {tripal_gffcds_temp} ALTER COLUMN phase DROP NOT NULL;");
  659. }
  660. $term = chado_insert_cvterm(array(
  661. 'id' => 'data:1048',
  662. 'name' => 'Database ID',
  663. 'cv_name' => 'EDAM',
  664. 'definition' => 'An identifier of a biological or bioinformatics database.',
  665. ));
  666. chado_associate_semweb_term('db', 'name', $term);
  667. }
  668. catch (\PDOException $e) {
  669. $error = $e->getMessage();
  670. throw new DrupalUpdateException('Could not fix phase on tripal_gffcds_temp table: '. $error);
  671. }
  672. }
  673. /**
  674. * Divides chado_entity table for better integration with views.
  675. */
  676. function tripal_chado_update_7301() {
  677. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.bundle');
  678. try {
  679. $transaction = db_transaction();
  680. $query = db_select('chado_bundle', 'CB');
  681. $query->join('tripal_bundle', 'TB', 'TB.id = CB.bundle_id');
  682. $query->fields('CB', array('data_table'));
  683. $query->fields('TB', array('name'));
  684. $cbundles = $query->execute();
  685. // If the table for the bundle doesn't exist then create one, and then
  686. // move all of the records from the chado_entity table to it.
  687. while($cbundle = $cbundles->fetchObject()) {
  688. $cbundle_table = chado_get_bundle_entity_table($cbundle);
  689. if (!db_table_exists($cbundle_table)) {
  690. // Create the bundle table.
  691. tripal_chado_create_bundle_table($cbundle);
  692. // Now move the records over.
  693. $sql = "
  694. INSERT INTO {$cbundle_table} (entity_id, record_id, nid)
  695. SELECT CE.entity_id, CE.record_id, CE.nid
  696. FROM {chado_entity} CE
  697. INNER JOIN {tripal_entity} TE ON CE.entity_id = TE.id
  698. WHERE TE.bundle = :bundle
  699. ";
  700. db_query($sql, array(':bundle' => $cbundle->name));
  701. }
  702. }
  703. // Now remove the chado_entity table.
  704. db_drop_table('chado_entity');
  705. }
  706. catch (\PDOException $e) {
  707. $transaction->rollback();
  708. $error = $e->getMessage();
  709. throw new DrupalUpdateException('Could not perform update: '. $error);
  710. }
  711. }
  712. /**
  713. * Corrections to the EDAM database.
  714. */
  715. function tripal_chado_update_7302(){
  716. try {
  717. // Add the term for the field.
  718. chado_insert_db(array(
  719. 'name' => 'format',
  720. '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. ',
  721. 'url' => 'http://edamontology.org/page',
  722. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  723. ));
  724. chado_insert_db(array(
  725. 'name' => 'operation',
  726. '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).',
  727. 'url' => 'http://edamontology.org/page',
  728. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  729. ));
  730. chado_insert_db(array(
  731. 'name' => 'topic',
  732. '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.',
  733. 'url' => 'http://edamontology.org/page',
  734. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  735. ));
  736. chado_insert_cv(
  737. 'EDAM',
  738. '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.'
  739. );
  740. }
  741. catch (\PDOException $e) {
  742. $transaction->rollback();
  743. $error = $e->getMessage();
  744. throw new DrupalUpdateException('Could not perform update: '. $error);
  745. }
  746. }
  747. /**
  748. * Fixes inconsistency with Chado v1.3 update if was applied.
  749. */
  750. function tripal_chado_update_7303() {
  751. try {
  752. $chado_version = chado_get_version();
  753. if ($chado_version == '1.3') {
  754. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.setup');
  755. tripal_chado_fix_v1_3_custom_tables();
  756. }
  757. }
  758. catch (\PDOException $e) {
  759. $transaction->rollback();
  760. $error = $e->getMessage();
  761. throw new DrupalUpdateException('Could not perform update: '. $error);
  762. }
  763. }
  764. /**
  765. * Add some new controlled vocabulary terms.
  766. */
  767. function tripal_chado_update_7304() {
  768. try {
  769. $term = chado_insert_cvterm(array(
  770. 'id' => 'SIO:001080',
  771. 'name' => 'vocabulary',
  772. 'cv_name' => 'SIO',
  773. 'definition' => 'A vocabulary is a collection of terms.',
  774. ));
  775. chado_associate_semweb_term('cvterm', 'cv_id', $term);
  776. $term = chado_insert_cvterm(array(
  777. 'id' => 'data:2976',
  778. 'name' => 'Protein sequence',
  779. 'cv_name' => 'EDAM',
  780. 'definition' => 'One or more protein sequences, possibly with associated annotation.',
  781. ));
  782. $term = chado_insert_cvterm(array(
  783. 'id' => 'local:fmin',
  784. 'name' => 'minimal boundary',
  785. 'definition' => 'The leftmost, minimal boundary in the linear range ' .
  786. 'represented by the feature location. Sometimes this is called ' .
  787. 'start although this is confusing because it does not necessarily ' .
  788. 'represent the 5-prime coordinate.',
  789. 'cv_name' => 'local',
  790. ));
  791. chado_associate_semweb_term('featureloc', 'fmin', $term);
  792. $term = chado_insert_cvterm(array(
  793. 'id' => 'local:fmax',
  794. 'name' => 'maximal boundary',
  795. 'definition' => 'The rightmost, maximal boundary in the linear range ' .
  796. 'represented by the featureloc. Sometimes this is called end although ' .
  797. 'this is confusing because it does not necessarily represent the ' .
  798. '3-prime coordinate',
  799. 'cv_name' => 'local',
  800. ));
  801. chado_associate_semweb_term('featureloc', 'fmax', $term);
  802. $term = chado_insert_cvterm(array(
  803. 'id' => 'data:2336',
  804. 'name' => 'Translation phase specification',
  805. 'cv_name' => 'EDAM',
  806. 'definition' => 'Phase for translation of DNA (0, 1 or 2) relative to a fragment of the coding sequence.',
  807. ));
  808. chado_associate_semweb_term('featureloc', 'phase', $term);
  809. $term = chado_insert_cvterm(array(
  810. 'id' => 'data:3002',
  811. 'name' => 'Annotation track',
  812. 'cv_name' => 'EDAM',
  813. 'definition' => 'Annotation of one particular positional feature on a ' .
  814. 'biomolecular (typically genome) sequence, suitable for import and ' .
  815. 'display in a genome browser. Synonym: Sequence annotation track.',
  816. ));
  817. chado_associate_semweb_term('featureloc', 'srcfeature_id', $term);
  818. }
  819. catch (\PDOException $e) {
  820. $transaction->rollback();
  821. $error = $e->getMessage();
  822. throw new DrupalUpdateException('Could not perform update: '. $error);
  823. }
  824. }
  825. /**
  826. * Adding missing cv/db details and cvterms.
  827. */
  828. function tripal_chado_update_7305() {
  829. try {
  830. chado_insert_db(array(
  831. 'name' => 'rdfs',
  832. 'description' => 'Resource Description Framework Schema',
  833. 'url' => 'https://www.w3.org/TR/rdf-schema/',
  834. 'urlprefix' => 'https://www.w3.org/TR/rdf-schema/#ch_{accession}',
  835. ));
  836. chado_insert_cv('rdfs', 'Resource Description Framework Schema');
  837. chado_insert_db(array(
  838. 'name' => 'SO',
  839. 'description' => 'The sequence ontology.',
  840. 'url' => 'http://www.sequenceontology.org/',
  841. 'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',
  842. ));
  843. chado_insert_cv('sequence', 'The sequence ontology.');
  844. chado_insert_db(array(
  845. 'name' => 'TAXRANK',
  846. 'description' => 'A vocabulary of taxonomic ranks (species, family, phylum, etc)',
  847. 'url' => 'http://www.obofoundry.org/ontology/taxrank.html',
  848. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  849. ));
  850. chado_insert_cv('taxonomic_rank', 'A vocabulary of taxonomic ranks (species, family, phylum, etc)');
  851. chado_insert_db(array(
  852. 'name' => 'hydra',
  853. 'description' => 'A Vocabulary for Hypermedia-Driven Web APIs',
  854. 'url' => 'http://www.w3.org/ns/hydra/core',
  855. 'urlprefix' => 'http://www.w3.org/ns/hydra/core#{accession}',
  856. ));
  857. chado_insert_cv(
  858. 'hydra',
  859. 'A Vocabulary for Hypermedia-Driven Web APIs.'
  860. );
  861. chado_insert_db(array(
  862. 'name' => 'dc',
  863. 'description' => 'DCMI Metadata Terms.',
  864. 'url' => 'http://purl.org/dc/dcmitype/',
  865. 'urlprefix' => 'http://purl.org/dc/terms/{accession}',
  866. ));
  867. chado_insert_cv(
  868. 'dc',
  869. 'DCMI Metadata Terms.'
  870. );
  871. $term = chado_insert_cvterm(array(
  872. 'id' => 'dc:Service',
  873. 'name' => 'Service',
  874. 'cv_name' => 'dc',
  875. 'definition' => 'A system that provides one or more functions.',
  876. ));
  877. $name = chado_insert_cvterm(array(
  878. 'id' => 'hydra:Collection',
  879. 'name' => 'Collection',
  880. 'cv_name' => 'hydra',
  881. 'definition' => 'A collection holding references to a number of related resources.',
  882. ));
  883. $name = chado_insert_cvterm(array(
  884. 'id' => 'hydra:member',
  885. 'name' => 'member',
  886. 'cv_name' => 'hydra',
  887. 'definition' => 'A member of the collection',
  888. ));
  889. $name = chado_insert_cvterm(array(
  890. 'id' => 'hydra:description',
  891. 'name' => 'description',
  892. 'cv_name' => 'hydra',
  893. 'definition' => 'A description.',
  894. ));
  895. $name = chado_insert_cvterm(array(
  896. 'id' => 'hydra:totalItems',
  897. 'name' => 'totalItems',
  898. 'cv_name' => 'hydra',
  899. 'definition' => 'The total number of items referenced by a collection.',
  900. ));
  901. $name = chado_insert_cvterm(array(
  902. 'id' => 'hydra:title',
  903. 'name' => 'title',
  904. 'cv_name' => 'hydra',
  905. 'definition' => 'A title, often used along with a description.',
  906. ));
  907. $name = chado_insert_cvterm(array(
  908. 'id' => 'hydra:PartialCollectionView',
  909. 'name' => 'PartialCollectionView',
  910. 'cv_name' => 'hydra',
  911. '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.',
  912. ));
  913. $term = chado_insert_cvterm(array(
  914. 'id' => 'schema:ItemPage',
  915. 'name' => 'ItemPage',
  916. 'cv_name' => 'schema',
  917. 'definition' => 'A page devoted to a single item, such as a particular product or hotel.',
  918. ));
  919. global $base_path;
  920. chado_insert_db(array(
  921. 'name' => 'null',
  922. 'description' => 'No online database.',
  923. 'url' => $base_path . 'cv/lookup/null',
  924. 'urlprefix' => $base_path. 'cv/lookup/{db}/{accession}',
  925. ));
  926. chado_insert_db(array(
  927. 'name' => 'local',
  928. 'description' => 'Terms created for this site.',
  929. 'url' => $base_path . 'cv/lookup/local',
  930. 'urlprefix' => $base_path . 'cv/lookup/{db}/{accession}',
  931. ));
  932. $term = chado_insert_cvterm(array(
  933. 'id' => 'local:rank',
  934. 'name' => 'rank',
  935. 'definition' => 'A taxonmic rank',
  936. 'cv_name' => 'local',
  937. ));
  938. }
  939. catch (\PDOException $e) {
  940. $transaction->rollback();
  941. $error = $e->getMessage();
  942. throw new DrupalUpdateException('Could not perform update: '. $error);
  943. }
  944. }
  945. /**
  946. * Add cvterm mapping for the Map entity type
  947. */
  948. function tripal_chado_update_7306() {
  949. try {
  950. $identifier = array(
  951. 'cv_id' => array('name' => 'EDAM'),
  952. 'name' => 'Map'
  953. );
  954. $cvterm = chado_get_cvterm($identifier);
  955. tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'featuremap', NULL);
  956. }
  957. catch (\PDOException $e) {
  958. $error = $e->getMessage();
  959. throw new DrupalUpdateException('Could not perform update: '. $error);
  960. }
  961. }
  962. /**
  963. * Add cvterm mapping for the Publication entity type
  964. */
  965. function tripal_chado_update_7307() {
  966. try {
  967. $identifier = array(
  968. 'cv_id' => array('name' => 'tripal_pub'),
  969. 'name' => 'Publication'
  970. );
  971. $cvterm = chado_get_cvterm($identifier);
  972. tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'pub', NULL);
  973. }
  974. catch (\PDOException $e) {
  975. $error = $e->getMessage();
  976. throw new DrupalUpdateException('Could not perform update: '. $error);
  977. }
  978. }
  979. /**
  980. * Add cvterm mapping for the analysis.sourcversion and analysis.sourcename.
  981. */
  982. function tripal_chado_update_7308() {
  983. try {
  984. $term = chado_insert_cvterm(array(
  985. 'id' => 'IAO:0000129',
  986. 'name' => 'version number',
  987. 'cv_name' => 'IAO',
  988. 'definition' => 'A version number is an ' .
  989. 'information content entity which is a sequence of characters ' .
  990. 'borne by part of each of a class of manufactured products or its ' .
  991. 'packaging and indicates its order within a set of other products ' .
  992. 'having the same name.',
  993. ));
  994. chado_associate_semweb_term('analysis', 'sourceversion', $term);
  995. chado_associate_semweb_term(NULL, 'version', $term);
  996. $term = chado_insert_cvterm(array(
  997. 'id' => 'schema:name',
  998. 'name' => 'name',
  999. 'cv_name' => 'schema',
  1000. 'definition' => 'The name of the item.',
  1001. ));
  1002. chado_associate_semweb_term('analysis', 'sourcename', $term);
  1003. $term = chado_insert_cvterm(array(
  1004. 'id' => 'data:2091',
  1005. 'name' => 'Accession',
  1006. 'cv_name' => 'EDAM',
  1007. 'definition' => 'A persistent (stable) and unique identifier, typically identifying an object (entry) from a database.',
  1008. ));
  1009. chado_associate_semweb_term('dbxref', 'accession', $term);
  1010. }
  1011. catch (\PDOException $e) {
  1012. $error = $e->getMessage();
  1013. throw new DrupalUpdateException('Could not perform update: '. $error);
  1014. }
  1015. }
  1016. /**
  1017. * Add cvterm 'annotation' and maps to cvterm linking tables.
  1018. */
  1019. function tripal_chado_update_7309() {
  1020. try {
  1021. $term = chado_insert_cvterm(array(
  1022. 'id' => 'SIO:001166',
  1023. 'name' => 'annotation',
  1024. 'cv_name' => 'SIO',
  1025. '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.',
  1026. ));
  1027. chado_associate_semweb_term('feature_cvterm', 'cvterm_id', $term);
  1028. chado_associate_semweb_term('analysis_cvterm', 'cvterm_id', $term);
  1029. chado_associate_semweb_term('cell_line_cvterm', 'cvterm_id', $term);
  1030. chado_associate_semweb_term('environment_cvterm', 'cvterm_id', $term);
  1031. chado_associate_semweb_term('expression_cvterm', 'cvterm_id', $term);
  1032. chado_associate_semweb_term('library_cvterm', 'cvterm_id', $term);
  1033. chado_associate_semweb_term('organism_cvterm', 'cvterm_id', $term);
  1034. chado_associate_semweb_term('phenotype_cvterm', 'cvterm_id', $term);
  1035. chado_associate_semweb_term('stock_cvterm', 'cvterm_id', $term);
  1036. chado_associate_semweb_term('stock_relationship_cvterm', 'cvterm_id', $term);
  1037. $term = chado_insert_cvterm(array(
  1038. 'id' => 'SIO:000281',
  1039. 'name' => 'negation',
  1040. 'cv_name' => 'SIO',
  1041. 'definition' => 'NOT is a logical operator in that has the value true if its operand is false.',
  1042. ));
  1043. chado_associate_semweb_term('feature_cvterm', 'is_not', $term);
  1044. chado_associate_semweb_term('analysis_cvterm', 'is_not', $term);
  1045. chado_associate_semweb_term('organism_cvterm', 'is_not', $term);
  1046. chado_associate_semweb_term('stock_cvterm', 'is_not', $term);
  1047. }
  1048. catch (\PDOException $e) {
  1049. $error = $e->getMessage();
  1050. throw new DrupalUpdateException('Could not perform update: '. $error);
  1051. }
  1052. }
  1053. /**
  1054. * Adds the 'OBCS' and rank order term.
  1055. */
  1056. function tripal_chado_update_7310() {
  1057. try {
  1058. chado_insert_db(array(
  1059. 'name' => 'OBCS',
  1060. 'description' => 'Ontology of Biological and Clinical Statistics.',
  1061. 'url' => 'https://github.com/obcs/obcs',
  1062. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  1063. ));
  1064. chado_insert_cv(
  1065. 'OBCS',
  1066. 'Ontology of Biological and Clinical Statistics.'
  1067. );
  1068. $term = chado_insert_cvterm(array(
  1069. 'id' => 'OBCS:0000117',
  1070. 'name' => 'rank order',
  1071. 'cv_name' => 'OBCS',
  1072. '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.',
  1073. ));
  1074. chado_associate_semweb_term(NULL, 'rank', $term);
  1075. }
  1076. catch (\PDOException $e) {
  1077. $error = $e->getMessage();
  1078. throw new DrupalUpdateException('Could not perform update: '. $error);
  1079. }
  1080. }
  1081. /**
  1082. * Fix a mistake with the association of the term with featureloc.fmin.
  1083. */
  1084. function tripal_chado_update_7311() {
  1085. try {
  1086. $term = chado_insert_cvterm(array(
  1087. 'id' => 'local:fmin',
  1088. 'name' => 'minimal boundary',
  1089. 'definition' => 'The leftmost, minimal boundary in the linear range ' .
  1090. 'represented by the feature location. Sometimes this is called ' .
  1091. 'start although this is confusing because it does not necessarily ' .
  1092. 'represent the 5-prime coordinate.',
  1093. 'cv_name' => 'local',
  1094. ));
  1095. chado_associate_semweb_term('featureloc', 'fmin', $term);
  1096. }
  1097. catch (\PDOException $e) {
  1098. $error = $e->getMessage();
  1099. throw new DrupalUpdateException('Could not perform update: '. $error);
  1100. }
  1101. }
  1102. /**
  1103. * Associates a local term with the pub.miniref column.
  1104. */
  1105. function tripal_chado_update_7312() {
  1106. try {
  1107. $term = chado_insert_cvterm(array(
  1108. 'id' => 'local:miniref',
  1109. 'name' => 'Mini-ref',
  1110. 'definition' => 'A small in-house unique identifier for a publication.',
  1111. 'cv_name' => 'local',
  1112. ));
  1113. chado_associate_semweb_term('pub', 'miniref', $term);
  1114. $term = chado_insert_cvterm(array(
  1115. 'id' => 'schema:url',
  1116. 'name' => 'url',
  1117. 'cv_name' => 'schema',
  1118. 'definition' => 'URL of the item.',
  1119. ));
  1120. chado_associate_semweb_term('db', 'url', $term);
  1121. }
  1122. catch (\PDOException $e) {
  1123. $error = $e->getMessage();
  1124. throw new DrupalUpdateException('Could not perform update: '. $error);
  1125. }
  1126. }
  1127. /**
  1128. * Run the cvtermpath for the Tripal Pub and Contact ontologies.
  1129. */
  1130. function tripal_chado_update_7313() {
  1131. try {
  1132. $cv = chado_get_cv(array('name' => 'tripal_pub'));
  1133. chado_update_cvtermpath($cv->cv_id);
  1134. $cv = chado_get_cv(array('name' => 'tripal_contact'));
  1135. chado_update_cvtermpath($cv->cv_id);
  1136. }
  1137. catch (\PDOException $e) {
  1138. $error = $e->getMessage();
  1139. throw new DrupalUpdateException('Could not perform update: '. $error);
  1140. }
  1141. }
  1142. /**
  1143. * Adds a local term for the featuremap.feature_id column.
  1144. */
  1145. function tripal_chado_update_7314() {
  1146. try {
  1147. $term = chado_insert_cvterm(array(
  1148. 'name' => 'Reference Feature',
  1149. 'definition' => 'A genomic or genetic feature on which other features are mapped.',
  1150. 'cv_name' => 'local',
  1151. 'is_relationship' => 0,
  1152. 'db_name' => 'local'
  1153. ));
  1154. chado_associate_semweb_term('featurepos', 'map_feature_id', $term);
  1155. }
  1156. catch (\PDOException $e) {
  1157. $error = $e->getMessage();
  1158. throw new DrupalUpdateException('Could not perform update: '. $error);
  1159. }
  1160. }
  1161. /**
  1162. * Fixes a mistake with the schema:additionalType term.
  1163. */
  1164. function tripal_chado_update_7315() {
  1165. try {
  1166. $term = chado_insert_cvterm(array(
  1167. 'id' => 'schema:additionalType',
  1168. 'name' => 'additionalType',
  1169. 'cv_name' => 'schema',
  1170. 'definition' => 'An additional type for the item, typically used for adding more specific types from external vocabularies in microdata syntax. This is a relationship between something and a class that the thing is in.',
  1171. ));
  1172. chado_delete_record('cv', array('name' => 'An additional type for the item, typically used for adding more specific types from external vocabularies in microdata syntax. This is a relationship between something and a class that the thing is in.'));
  1173. }
  1174. catch (\PDOException $e) {
  1175. $error = $e->getMessage();
  1176. throw new DrupalUpdateException('Could not perform update: '. $error);
  1177. }
  1178. }
  1179. /**
  1180. * Adds the email term for potential use with contact properties.
  1181. */
  1182. function tripal_chado_update_7316() {
  1183. try {
  1184. $term = chado_insert_cvterm(array(
  1185. 'id' => 'SIO:001323',
  1186. 'name' => 'email address',
  1187. 'cv_name' => 'SIO',
  1188. 'definition' => 'an email address is an identifier to send mail to particular electronic mailbox.',
  1189. ));
  1190. }
  1191. catch (\PDOException $e) {
  1192. $error = $e->getMessage();
  1193. throw new DrupalUpdateException('Could not perform update: '. $error);
  1194. }
  1195. }
  1196. /**
  1197. * Support for the biomaterial table.
  1198. */
  1199. function tripal_chado_update_7317() {
  1200. try {
  1201. $term = chado_insert_cvterm(array(
  1202. 'id' => 'OBI:0100026',
  1203. 'name' => 'organism',
  1204. 'cv_name' => 'obi',
  1205. 'definition' => 'A material entity that is an individual living system, such as animal, plant, bacteria or virus, that is capable of replicating or reproducing, growth and maintenance in the right environment. An organism may be unicellular or made up, like humans, of many billions of cells divided into specialized tissues and organs.',
  1206. ));
  1207. chado_associate_semweb_term('biomaterial', 'taxon_id', $term);
  1208. $term = chado_insert_cvterm(array(
  1209. 'id' => 'local:contact',
  1210. 'name' => 'contact',
  1211. 'definition' => 'An entity (e.g. individual or organization) through ' .
  1212. 'whom a person can gain access to information, favors, ' .
  1213. 'influential people, and the like.',
  1214. 'cv_name' => 'local',
  1215. ));
  1216. chado_associate_semweb_term('biomaterial', 'biosourceprovider_id', $term);
  1217. }
  1218. catch (\PDOException $e) {
  1219. $error = $e->getMessage();
  1220. throw new DrupalUpdateException('Could not perform update: '. $error);
  1221. }
  1222. }
  1223. /**
  1224. * Adding biological sample term for biomaterial entities.
  1225. */
  1226. function tripal_chado_update_7318() {
  1227. try {
  1228. chado_insert_db(array(
  1229. 'name' => 'sep',
  1230. 'description' => 'Sample processing and separation techniques.',
  1231. 'url' => 'http://psidev.info/index.php?q=node/312',
  1232. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  1233. ));
  1234. chado_insert_cv('sep','A structured controlled vocabulary for the annotation of sample processing and separation techniques in scientific experiments.');
  1235. $term = chado_insert_cvterm(array(
  1236. 'id' => 'sep:00195',
  1237. 'name' => 'biological sample',
  1238. 'cv_name' => 'sep',
  1239. 'definition' => 'A biological sample analysed by a particular technology.',
  1240. ));
  1241. }
  1242. catch (\PDOException $e) {
  1243. $error = $e->getMessage();
  1244. throw new DrupalUpdateException('Could not perform update: '. $error);
  1245. }
  1246. }
  1247. /**
  1248. * Adding new Analysis term.
  1249. */
  1250. function tripal_chado_update_7319() {
  1251. try {
  1252. $term = chado_insert_cvterm(array(
  1253. 'id' => 'operation:2945',
  1254. 'name' => 'Analysis',
  1255. 'cv_name' => 'EDAM',
  1256. 'definition' => 'Apply analytical methods to existing data of a specific type.',
  1257. ));
  1258. }
  1259. catch (\PDOException $e) {
  1260. $error = $e->getMessage();
  1261. throw new DrupalUpdateException('Could not perform update: '. $error);
  1262. }
  1263. }
  1264. /**
  1265. * Adding Phylogenetic Tree content type.
  1266. */
  1267. function tripal_chado_update_7320() {
  1268. try {
  1269. // Associate the Analysis term with the analysis_id of the phylotree table.
  1270. $term = chado_get_cvterm(array('id' => 'operation:2945'));
  1271. chado_associate_semweb_term('phylotree', 'analysis_id', $term);
  1272. $term = chado_insert_cvterm(array(
  1273. 'id' => 'data:0872',
  1274. 'name' => 'Phylogenetic tree',
  1275. 'cv_name' => 'EDAM',
  1276. 'definition' => 'The raw data (not just an image) from which a phylogenetic tree is directly generated or plotted, such as topology, lengths (in time or in expected amounts of variance) and a confidence interval for each length.',
  1277. ));
  1278. $term = chado_insert_cvterm(array(
  1279. 'id' => 'data:3272',
  1280. 'name' => 'Species tree',
  1281. 'cv_name' => 'EDAM',
  1282. 'definition' => 'A phylogenetic tree that reflects phylogeny of the taxa from which the characters (used in calculating the tree) were sampled.',
  1283. ));
  1284. $term = chado_insert_cvterm(array(
  1285. 'id' => 'data:3271',
  1286. 'name' => 'Gene tree',
  1287. 'cv_name' => 'EDAM',
  1288. 'definition' => 'A phylogenetic tree that is an estimate of the character\'s phylogeny.',
  1289. ));
  1290. $term = chado_insert_cvterm(array(
  1291. 'id' => 'operation:0567',
  1292. 'name' => 'Phylogenetic tree visualisation',
  1293. 'cv_name' => 'EDAM',
  1294. 'definition' => 'A phylogenetic tree that is an estimate of the character\'s phylogeny.',
  1295. ));
  1296. // Create the 'Phylogenetic tree' content type.
  1297. $error = '';
  1298. $args = array(
  1299. 'vocabulary' => 'data',
  1300. 'accession' => '0872',
  1301. 'term_name' => 'Phylogenetic tree',
  1302. 'storage_args' => array(
  1303. 'data_table' => 'phylotree',
  1304. )
  1305. );
  1306. $term = tripal_load_term_entity(array('vocabulary' => 'data', 'accession' => '0872'));
  1307. if ($term) {
  1308. $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
  1309. }
  1310. if (!$term or !$bundle) {
  1311. if (!tripal_create_bundle($args)) {
  1312. throw new Exception('Error Encountered creating "Phylogenetic tree" Tripal Content Type.');
  1313. }
  1314. }
  1315. }
  1316. catch (\PDOException $e) {
  1317. $error = $e->getMessage();
  1318. throw new DrupalUpdateException('Could not perform update: '. $error);
  1319. }
  1320. }
  1321. /**
  1322. * Updating details for local ontologies.
  1323. */
  1324. function tripal_chado_update_7321() {
  1325. try {
  1326. chado_insert_db(array(
  1327. 'name' => 'TPUB',
  1328. 'description' => 'Tripal Publiation Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
  1329. 'url' => '/cv/lookup/TPUB',
  1330. 'urlprefix' => '/cv/lookup/TPUB/{accession}',
  1331. ));
  1332. chado_insert_cv('tripal_pub', 'Tripal Publiation Ontology. A temporary ontology until a more formal appropriate ontology an be identified.');
  1333. chado_insert_db(array(
  1334. 'name' => 'rdf',
  1335. 'description' => 'Resource Description Framework',
  1336. 'url' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns',
  1337. 'urlprefix' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  1338. ));
  1339. chado_insert_cv(
  1340. 'rdf',
  1341. 'Resource Description Framework'
  1342. );
  1343. chado_insert_db(array(
  1344. 'name' => 'rdfs',
  1345. 'description' => 'Resource Description Framework Schema',
  1346. 'url' => 'https://www.w3.org/TR/rdf-schema/',
  1347. 'urlprefix' => 'http://www.w3.org/2000/01/rdf-schema#{accession}',
  1348. ));
  1349. chado_insert_db(array(
  1350. 'name' => 'hydra',
  1351. 'description' => 'A Vocabulary for Hypermedia-Driven Web APIs',
  1352. 'url' => 'http://www.w3.org/ns/hydra/core',
  1353. 'urlprefix' => 'http://www.w3.org/ns/hydra/core#{accession}',
  1354. ));
  1355. chado_insert_cv(
  1356. 'hydra',
  1357. 'A Vocabulary for Hypermedia-Driven Web APIs.'
  1358. );
  1359. }
  1360. catch (\PDOException $e) {
  1361. $error = $e->getMessage();
  1362. throw new DrupalUpdateException('Could not perform update: '. $error);
  1363. }
  1364. }
  1365. /**
  1366. * Fixing the SWO, TPUB and TContact vocabulary URLs
  1367. */
  1368. function tripal_chado_update_7322() {
  1369. try {
  1370. chado_insert_db(array(
  1371. 'name' => 'TPUB',
  1372. 'description' => 'Tripal Publiation Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
  1373. 'url' => 'cv/lookup/TPUB',
  1374. 'urlprefix' => 'cv/lookup/TPUB/{accession}',
  1375. ));
  1376. chado_insert_db(array(
  1377. 'name' => 'TContact',
  1378. 'description' => 'Tripal Contact Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
  1379. 'url' => 'cv/lookup/TContact',
  1380. 'urlprefix' => 'cv/lookup/TContact/{accession}',
  1381. ));
  1382. chado_insert_cv('tripal_contact', 'Tripal Contact Ontology. A temporary ontology until a more formal appropriate ontology an be identified.');
  1383. chado_insert_db(array(
  1384. 'name' => 'SWO',
  1385. 'description' => 'Software Ontology',
  1386. 'url' => 'http://purl.obolibrary.org/obo/swo',
  1387. 'urlprefix' => 'http://www.ebi.ac.uk/swo/',
  1388. ));
  1389. }
  1390. catch (\PDOException $e) {
  1391. $error = $e->getMessage();
  1392. throw new DrupalUpdateException('Could not perform update: '. $error);
  1393. }
  1394. }
  1395. /**
  1396. * Adding the db2cv materialized view.
  1397. */
  1398. function tripal_chado_update_7323() {
  1399. try {
  1400. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
  1401. tripal_chado_add_db2cv_mview_mview();
  1402. drupal_set_message('Populating materialized view db2cv_mview...');
  1403. $mview_id = chado_get_mview_id('db2cv_mview');
  1404. chado_populate_mview($mview_id);
  1405. drupal_set_message('Populating materialized view cv_root_mview...');
  1406. $mview_id = chado_get_mview_id('cv_root_mview');
  1407. chado_populate_mview($mview_id);
  1408. }
  1409. catch (\PDOException $e) {
  1410. $error = $e->getMessage();
  1411. throw new DrupalUpdateException('Could not perform update: '. $error);
  1412. }
  1413. }
  1414. /**
  1415. * Updating the db2cv materialized view.
  1416. */
  1417. function tripal_chado_update_7324() {
  1418. try {
  1419. if (chado_table_exists(db2cv_mview) and !chado_column_exists('db2cv_mview', 'num_terms')) {
  1420. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
  1421. // Remove the old mview.
  1422. $mview_id = chado_get_mview_id('db2cv_mview');
  1423. chado_delete_mview($mview_id);
  1424. // Readd the mview.
  1425. tripal_chado_add_db2cv_mview_mview();
  1426. drupal_set_message('Populating materialized view db2cv_mview...');
  1427. $mview_id = chado_get_mview_id('db2cv_mview');
  1428. chado_populate_mview($mview_id);
  1429. }
  1430. }
  1431. catch (\PDOException $e) {
  1432. $error = $e->getMessage();
  1433. throw new DrupalUpdateException('Could not perform update: '. $error);
  1434. }
  1435. }
  1436. /**
  1437. * Adding additional vocabulary term mapping to Chado table columns.
  1438. */
  1439. function tripal_chado_update_7325() {
  1440. try {
  1441. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
  1442. tripal_chado_populate_chado_semweb_table();
  1443. }
  1444. catch (\PDOException $e) {
  1445. $error = $e->getMessage();
  1446. throw new DrupalUpdateException('Could not perform update: '. $error);
  1447. }
  1448. }
  1449. /**
  1450. * Adding a "Company" term.
  1451. */
  1452. function tripal_chado_update_7326() {
  1453. try {
  1454. // The Company term is missing for the Tripal Contact ontology, but is
  1455. // useful for the arraydesign.manufacturer which is an FK to Contact.
  1456. // It seems better to use a term from a curated ontology than to add to
  1457. // Tripal Contact.
  1458. $term = chado_insert_cvterm(array(
  1459. 'id' => 'NCIT:C54131',
  1460. 'name' => 'Company',
  1461. 'cv_name' => 'ncit',
  1462. 'definition' => 'Any formal business entity for profit, which may be a corporation, a partnership, association or individual proprietorship. [ NCI http://dictionary.law.com ]',
  1463. ));
  1464. }
  1465. catch (\PDOException $e) {
  1466. $error = $e->getMessage();
  1467. throw new DrupalUpdateException('Could not perform update: '. $error);
  1468. }
  1469. }
  1470. /**
  1471. * Adding terms for sequence visualization.
  1472. */
  1473. function tripal_chado_update_7327() {
  1474. try {
  1475. $term = chado_insert_cvterm(array(
  1476. 'id' => 'operation:0564',
  1477. 'name' => 'Sequence visualisation',
  1478. 'cv_name' => 'EDAM',
  1479. 'definition' => 'Visualise, format or render a molecular sequence or sequences such as a sequence alignment, possibly with sequence features or properties shown.',
  1480. ));
  1481. }
  1482. catch (\PDOException $e) {
  1483. $error = $e->getMessage();
  1484. throw new DrupalUpdateException('Could not perform update: '. $error);
  1485. }
  1486. }
  1487. /**
  1488. * Don't count relationship cvterms as ontology roots.
  1489. */
  1490. function tripal_chado_update_7328() {
  1491. try {
  1492. $mv_name = 'cv_root_mview';
  1493. // Remove the old mview.
  1494. $mview_id = chado_get_mview_id($mv_name);
  1495. chado_delete_mview($mview_id);
  1496. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
  1497. // Re-add the mview.
  1498. tripal_chado_add_cv_root_mview_mview();
  1499. $mview_id = chado_get_mview_id($mv_name);
  1500. chado_populate_mview($mview_id);
  1501. }
  1502. catch (\PDOException $e) {
  1503. $error = $e->getMessage();
  1504. throw new DrupalUpdateException('Could not perform update: '. $error);
  1505. }
  1506. }
  1507. /**
  1508. * Fixing the chado_bundle.type_id type.
  1509. */
  1510. function tripal_chado_update_7329() {
  1511. try {
  1512. db_change_field('chado_bundle', 'type_id', 'type_id', [
  1513. 'description' => 'If a type_column is set then this is the cvterm_id of the data type that this bundle maps to.',
  1514. 'size' => 'big',
  1515. 'type' => 'int',
  1516. ]);
  1517. }
  1518. catch (\PDOException $e) {
  1519. $error = $e->getMessage();
  1520. throw new DrupalUpdateException('Could not perform update: '. $error);
  1521. }
  1522. }
  1523. # tripal_chado_update_7330 is in PR #596 and adds categories for content types.
  1524. /**
  1525. * Adds a base_type_id to the chado_bundle table.
  1526. */
  1527. function tripal_chado_update_7331() {
  1528. try {
  1529. if (!db_field_exists('chado_bundle', 'base_type_id')) {
  1530. db_add_field('chado_bundle', 'base_type_id', [
  1531. 'description' => 'If a property table is used for a linker, and if the base table requires a type_id then this is the type that should be used on insert of new records in the base table.',
  1532. 'size' => 'big',
  1533. 'type' => 'int',
  1534. ]);
  1535. }
  1536. }
  1537. catch (\PDOException $e) {
  1538. $error = $e->getMessage();
  1539. throw new DrupalUpdateException('Could not perform update: '. $error);
  1540. }
  1541. }