tripal_chado.install 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114
  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. // Fix the SOFP feature_property issue from the legacy feature_property.
  31. tripal_chado_fix_legacy_SOFP_7338();
  32. }
  33. tripal_insert_variable('bundle_category', 'Bundles can be categorized to allow for grouping');
  34. }
  35. /**
  36. * Implementation of hook_uninstall().
  37. *
  38. * @ingroup tripal
  39. */
  40. function tripal_chado_uninstall() {
  41. // // Drop the foreign key between tripal_custom_tables and tripal_mviews
  42. // // so that Drupal can then drop the tables
  43. // db_query('
  44. // ALTER TABLE {tripal_custom_tables}
  45. // DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
  46. // ');
  47. variable_set('tripal_chado_is_prepared', FALSE);
  48. }
  49. function tripal_chado_chado_semweb_schema(){
  50. return array(
  51. 'fields' => array(
  52. 'chado_semweb_id' => array(
  53. 'type' => 'serial',
  54. 'not null' => TRUE
  55. ),
  56. 'chado_table' => array(
  57. 'type' => 'varchar',
  58. 'length ' => 128,
  59. 'not null' => TRUE
  60. ),
  61. 'chado_column' => array(
  62. 'type' => 'text',
  63. 'length ' => 128,
  64. 'not null' => TRUE
  65. ),
  66. 'cvterm_id' => array(
  67. 'type' => 'int',
  68. ),
  69. ),
  70. 'primary key' => array(
  71. 0 => 'chado_semweb_id',
  72. ),
  73. 'indexes' => array(
  74. 'chado_semweb_id_idx1' => array('cvterm_id'),
  75. 'chado_semweb_id_idx2' => array('chado_column'),
  76. 'chado_semweb_id_idx3' => array('chado_table'),
  77. ),
  78. 'unique keys' => array(
  79. 'chado_semweb_uq1' => array('chado_table', 'chado_column'),
  80. ),
  81. );
  82. }
  83. /**
  84. * Table definition for the tripal_cv_obo table
  85. * @param $schema
  86. */
  87. function tripal_chado_tripal_cv_obo_schema() {
  88. return array(
  89. 'fields' => array(
  90. 'obo_id' => array(
  91. 'type' => 'serial',
  92. 'unsigned' => TRUE,
  93. 'not null' => TRUE
  94. ),
  95. 'name' => array(
  96. 'type' => 'varchar',
  97. 'length' => 255
  98. ),
  99. 'path' => array(
  100. 'type' => 'varchar',
  101. 'length' => 1024
  102. ),
  103. ),
  104. 'indexes' => array(
  105. 'tripal_cv_obo_idx1' => array('obo_id'),
  106. ),
  107. 'primary key' => array('obo_id'),
  108. );
  109. }
  110. /**
  111. *
  112. */
  113. function tripal_chado_enable() {
  114. // If Tripal v2 is already installed, then when the module is first enabled
  115. // after an upgade, the installation of this module will try and recreate
  116. // some of the tables created with tripal_core and the installation will fail.
  117. // Therefore, the tables were temporarily moved out of the way to preserve
  118. // the data. Now we'll move them back.
  119. tripal_chado_upgrade_v2_v3_enable();
  120. }
  121. /**
  122. * Implements hook_schema().
  123. */
  124. function tripal_chado_schema() {
  125. // If Tripal v2 is already installed, then when the module is first enabled
  126. // after an upgade, the installation of this module will try and recreate
  127. // some of the tables created with tripal_core and the installation will fail.
  128. // Therefore, we need to temporarily move those tables out of the way, let
  129. // the module install and then move them back.
  130. $migrated = variable_get('tripal_v2_upgrade_v3_check_chado', FALSE);
  131. if (!$migrated) {
  132. try {
  133. tripal_chado_upgrade_v2_v3_pre_enable();
  134. variable_set('tripal_v2_upgrade_v3_check_chado', TRUE);
  135. }
  136. catch(Exception $e) {
  137. watchdog_exception('tripal_chado', $e);
  138. }
  139. }
  140. // Links TripalEntity entities to the chado record.
  141. $schema['chado_bundle'] = tripal_chado_chado_bundle_schema();
  142. $schema['chado_semweb'] = tripal_chado_chado_semweb_schema();
  143. $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();
  144. $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();
  145. $schema['tripal_cv_obo'] = tripal_chado_tripal_cv_obo_schema();
  146. $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();
  147. // if this module is already installed and enabled, then we want to provide
  148. // the schemas for all of the custom tables. This will allow Views to
  149. // see the schemas. We check if the module is installed because during
  150. // installation we don't want to make these custom tables available as we don't
  151. // want them created in the Drupal database. The custom tables go in the
  152. // Chado database.
  153. if (db_table_exists('tripal_custom_tables')) {
  154. $sql = 'SELECT * FROM {tripal_custom_tables}';
  155. $results = db_query($sql);
  156. foreach ($results as $custom) {
  157. $schema[$custom->table_name] = unserialize($custom->schema);
  158. }
  159. }
  160. // Map cvterm usage to chado tables
  161. $schema['chado_cvterm_mapping'] = tripal_chado_chado_cvterm_mapping_schema();
  162. // When a chado Tripal content type is created, a linking table is also created to
  163. // link the entity to it's record in chado (@see tripal_chado_bundle_create() ).
  164. // This table is created via db_create_table() but in order to expose it to
  165. // the Drupal Schema API, we also need to define each one here.
  166. if (db_table_exists('chado_bundle')) {
  167. $resource = db_query('SELECT tb.name FROM chado_bundle cb LEFT JOIN tripal_bundle tb ON tb.id=cb.bundle_id');
  168. foreach ($resource as $r) {
  169. $bundle_name = $r->name;
  170. // This makes an assumption about the name of the linking table.
  171. // @todo: Switch to chado_get_bundle_entity_table($bundle).
  172. $chado_entity_table = 'chado_' . $bundle_name;
  173. $schema[$chado_entity_table] = array(
  174. 'description' => 'The linker table that associates TripalEntities with Chado records for entities of type ' . $bundle_name . '.',
  175. 'fields' => array(
  176. 'mapping_id' => array(
  177. 'type' => 'serial',
  178. 'not null' => TRUE
  179. ),
  180. 'entity_id' => array(
  181. 'description' => 'The unique entity id.',
  182. 'type' => 'int',
  183. 'not null' => TRUE,
  184. ),
  185. 'record_id' => array(
  186. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  187. 'type' => 'int',
  188. 'not null' => TRUE,
  189. ),
  190. 'nid' => array(
  191. 'description' => 'Optional. For linking nid to the entity when migrating Tripal v2 content',
  192. 'type' => 'int',
  193. )
  194. ),
  195. 'primary key' => array(
  196. 'mapping_id',
  197. ),
  198. 'indexes' => array(
  199. 'record_id' => array('record_id'),
  200. 'entity_id' => array('entity_id'),
  201. 'nid' => array('nid'),
  202. ),
  203. 'unique keys' => array(
  204. 'table_record' => array('record_id'),
  205. 'entity_id' => array('entity_id'),
  206. ),
  207. );
  208. }
  209. }
  210. return $schema;
  211. }
  212. /**
  213. * This function should be executed only one time during upgrade of v2 to v3.
  214. */
  215. function tripal_chado_upgrade_v2_v3_pre_enable() {
  216. // If Tripal v2 is already installed, then when the module is first enabled
  217. // after an upgade, the installation of this module will try and recreate
  218. // some of the tables created with tripal_core and the installation will fail.
  219. // Therefore, we need to temporarily move those tables out of the way, let
  220. // the module install and then move them back.
  221. if (db_table_exists('tripal_mviews')) {
  222. // Move the tripal_mviews table out of the way.
  223. $sql = "ALTER TABLE tripal_mviews RENAME TO tripal_mviews2";
  224. db_query($sql);
  225. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_name_key'")->fetchField()) {
  226. $sql = "ALTER INDEX tripal_mviews_mv_name_key RENAME TO tripal_mviews_mv_name_key2";
  227. }
  228. else {
  229. $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_name_key2 ON tripal_mviews2 USING btree (name)";
  230. }
  231. db_query($sql);
  232. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mv_table_key'")->fetchField()) {
  233. $sql = "ALTER INDEX tripal_mviews_mv_table_key RENAME TO tripal_mviews_mv_table_key2";
  234. }
  235. else {
  236. $sql = "CREATE UNIQUE INDEX tripal_mviews_mv_table_key2 ON tripal_mviews2 USING btree (mv_table)";
  237. }
  238. db_query($sql);
  239. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_mview_id_idx'")->fetchField()) {
  240. $sql = "ALTER INDEX tripal_mviews_mview_id_idx RENAME TO tripal_mviews_mview_id_idx2";
  241. }
  242. else {
  243. $sql = "CREATE INDEX tripal_mviews_mview_id_idx2 ON tripal_mviews2 USING btree (mview_id)";
  244. }
  245. db_query($sql);
  246. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_mviews_pkey'")->fetchField()) {
  247. $sql = "ALTER INDEX tripal_mviews_pkey RENAME TO tripal_mviews_pkey2";
  248. }
  249. else {
  250. $sql = "CREATE UNIQUE INDEX tripal_mviews_pkey2 ON tripal_mviews2 USING btree (mview_id)";
  251. }
  252. db_query($sql);
  253. }
  254. if (db_table_exists('tripal_custom_tables')) {
  255. // Move the tripal_custom_tables table out of the way.
  256. $sql = "ALTER TABLE tripal_custom_tables RENAME TO tripal_custom_tables2";
  257. db_query($sql);
  258. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_pkey'")->fetchField()) {
  259. $sql = "ALTER INDEX tripal_custom_tables_pkey RENAME TO tripal_custom_tables_pkey2";
  260. }
  261. else {
  262. $sql = "CREATE UNIQUE INDEX tripal_custom_tables_pkey2 ON tripal_custom_tables2 USING btree (table_id)";
  263. }
  264. db_query($sql);
  265. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_custom_tables_table_id_idx'")->fetchField()) {
  266. $sql = "ALTER INDEX tripal_custom_tables_table_id_idx RENAME TO tripal_custom_tables_table_id_idx2";
  267. }
  268. else {
  269. $sql = "CREATE INDEX tripal_custom_tables_table_id_idx2 ON tripal_custom_tables2 USING btree (table_id)";
  270. }
  271. db_query($sql);
  272. }
  273. if (db_table_exists('tripal_cv_obo')) {
  274. // Move the tripal_cv_obo table out of the way.
  275. $sql = "ALTER TABLE tripal_cv_obo RENAME TO tripal_cv_obo2";
  276. db_query($sql);
  277. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_obo_id_idx'")->fetchField()) {
  278. $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx RENAME TO tripal_cv_obo_obo_id_idx2";
  279. }
  280. else if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_tripal_cv_obo_idx1_idx'")->fetchField()) {
  281. $sql = "ALTER INDEX tripal_cv_obo_tripal_cv_obo_idx1_idx RENAME TO tripal_cv_obo_obo_id_idx2";
  282. }
  283. else {
  284. $sql = "CREATE INDEX tripal_cv_obo_obo_id_idx2 ON tripal_cv_obo2 USING btree (obo_id)";
  285. }
  286. db_query($sql);
  287. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey'")->fetchField()) {
  288. $sql = "ALTER INDEX tripal_cv_obo_pkey RENAME TO tripal_cv_obo_pkey2";
  289. }
  290. else {
  291. $sql = "CREATE UNIQUE INDEX tripal_cv_obo_pkey2 ON tripal_cv_obo2 USING btree (obo_id)";
  292. }
  293. db_query($sql);
  294. }
  295. if (db_table_exists('tripal_pub_import')) {
  296. // Move the tripal_pub_import table out of the way.
  297. $sql = "ALTER TABLE tripal_pub_import RENAME TO tripal_pub_import2";
  298. db_query($sql);
  299. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_name_idx'")->fetchField()) {
  300. $sql = "ALTER INDEX tripal_pub_import_name_idx RENAME TO tripal_pub_import_name_idx2";
  301. }
  302. else {
  303. $sql = "CREATE INDEX tripal_pub_import_name_idx2 ON tripal_pub_import2 USING btree (name)";
  304. }
  305. db_query($sql);
  306. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_pub_import_pkey'")->fetchField()) {
  307. $sql = "ALTER INDEX tripal_pub_import_pkey RENAME TO tripal_pub_import_pkey2";
  308. }
  309. else {
  310. $sql = "CREATE UNIQUE INDEX tripal_pub_import_pkey2 ON tripal_pub_import2 USING btree (pub_import_id)";
  311. }
  312. db_query($sql);
  313. }
  314. }
  315. /**
  316. * This function should be executed only one time during upgrade of v2 to v3.
  317. */
  318. function tripal_chado_upgrade_v2_v3_enable() {
  319. // If Tripal v2 is already installed, the installation of this module
  320. // will try and recreate some of the tables created with tripal_core and the
  321. // installation will fail. Therefore, in the install we renamed it. Now
  322. // we want to move it back.
  323. if (db_table_exists('tripal_mviews2')) {
  324. // tripal_mviews
  325. $sql = "DROP TABLE tripal_mviews";
  326. db_query($sql);
  327. $sql = "ALTER TABLE tripal_mviews2 RENAME to tripal_mviews";
  328. db_query($sql);
  329. $sql = "ALTER INDEX tripal_mviews_mv_name_key2 RENAME TO tripal_mviews_mv_name_key";
  330. db_query($sql);
  331. $sql = "ALTER INDEX tripal_mviews_mv_table_key2 RENAME TO tripal_mviews_mv_table_key";
  332. db_query($sql);
  333. $sql = "ALTER INDEX tripal_mviews_mview_id_idx2 RENAME TO tripal_mviews_mview_id_idx";
  334. db_query($sql);
  335. $sql = "ALTER INDEX tripal_mviews_pkey2 RENAME TO tripal_mviews_pkey";
  336. db_query($sql);
  337. }
  338. // tripal_custom_tables
  339. if (db_table_exists('tripal_custom_tables2')) {
  340. $sql = "DROP TABLE tripal_custom_tables";
  341. db_query($sql);
  342. $sql = "ALTER TABLE tripal_custom_tables2 RENAME to tripal_custom_tables";
  343. db_query($sql);
  344. $sql = "ALTER INDEX tripal_custom_tables_pkey2 RENAME TO tripal_custom_tables_pkey";
  345. db_query($sql);
  346. $sql = "ALTER INDEX tripal_custom_tables_table_id_idx2 RENAME TO tripal_custom_tables_table_id_idx";
  347. db_query($sql);
  348. }
  349. // tripal_cv_obo
  350. if (db_table_exists('tripal_cv_obo2')) {
  351. $sql = "DROP TABLE tripal_cv_obo";
  352. db_query($sql);
  353. $sql = "ALTER TABLE tripal_cv_obo2 RENAME to tripal_cv_obo";
  354. db_query($sql);
  355. $sql = "ALTER INDEX tripal_cv_obo_obo_id_idx2 RENAME TO tripal_cv_obo_obo_id_idx";
  356. db_query($sql);
  357. if (db_query("SELECT 1 FROM pg_indexes WHERE indexname = 'tripal_cv_obo_pkey2'")->fetchField()) {
  358. $sql = "ALTER INDEX tripal_cv_obo_pkey2 RENAME TO tripal_cv_obo_pkey";
  359. }
  360. db_query($sql);
  361. }
  362. // tripal_pub_import
  363. if (db_table_exists('tripal_pub_import2')) {
  364. $sql = "DROP TABLE tripal_pub_import";
  365. db_query($sql);
  366. $sql = "ALTER TABLE tripal_pub_import2 RENAME to tripal_pub_import";
  367. db_query($sql);
  368. $sql = "ALTER INDEX tripal_pub_import_name_idx2 RENAME TO tripal_pub_import_name_idx";
  369. db_query($sql);
  370. $sql = "ALTER INDEX tripal_pub_import_pkey2 RENAME TO tripal_pub_import_pkey";
  371. db_query($sql);
  372. }
  373. }
  374. /**
  375. * @section
  376. * Schema Definitions.
  377. */
  378. /**
  379. * Implementation of hook_schema().
  380. *
  381. * @ingroup tripal_pub
  382. */
  383. function tripal_chado_tripal_pub_import_schema() {
  384. return array(
  385. 'fields' => array(
  386. 'pub_import_id' => array(
  387. 'type' => 'serial',
  388. 'not null' => TRUE
  389. ),
  390. 'name' => array(
  391. 'type' => 'varchar',
  392. 'length' => 255,
  393. 'not null' => TRUE
  394. ),
  395. 'criteria' => array(
  396. 'type' => 'text',
  397. 'size' => 'normal',
  398. 'not null' => TRUE,
  399. 'description' => 'Contains a serialized PHP array containing the search criteria'
  400. ),
  401. 'disabled' => array(
  402. 'type' => 'int',
  403. 'unsigned' => TRUE,
  404. 'not NULL' => TRUE,
  405. 'default' => 0
  406. ),
  407. 'do_contact' => array(
  408. 'type' => 'int',
  409. 'unsigned' => TRUE,
  410. 'not NULL' => TRUE,
  411. 'default' => 0
  412. ),
  413. ),
  414. 'primary key' => array('pub_import_id'),
  415. 'indexes' => array(
  416. 'name' => array('name')
  417. ),
  418. );
  419. }
  420. /**
  421. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  422. * This keeps track of tables created by Tripal and stored in chado that may or may not
  423. * also be materialized views.
  424. *
  425. * @ingroup tripal
  426. */
  427. function tripal_chado_tripal_custom_tables_schema() {
  428. return array(
  429. 'fields' => array(
  430. 'table_id' => array(
  431. 'type' => 'serial',
  432. 'unsigned' => TRUE,
  433. 'not NULL' => TRUE
  434. ),
  435. 'table_name' => array(
  436. 'type' => 'varchar',
  437. 'length' => 255,
  438. 'not NULL' => TRUE
  439. ),
  440. 'schema' => array(
  441. 'type' => 'text',
  442. 'not NULL' => TRUE
  443. ),
  444. 'mview_id' => array(
  445. 'type' => 'int',
  446. 'not NULL' => FALSE
  447. )
  448. ),
  449. 'indexes' => array(
  450. 'table_id' => array('table_id'),
  451. ),
  452. 'primary key' => array('table_id'),
  453. 'foreign keys' => array(
  454. 'tripal_mviews' => array(
  455. 'table' => 'tripal_mviews',
  456. 'columns' => array(
  457. 'mview_id' => 'mview_id'
  458. ),
  459. ),
  460. ),
  461. );
  462. }
  463. /**
  464. * Describes the Tripal Materialized View (tripal_mviews) table
  465. * This table keeps track of all materialized views created by Tripal and stored in chado
  466. *
  467. * @ingroup tripal
  468. */
  469. function tripal_chado_tripal_mviews_schema() {
  470. return array(
  471. 'fields' => array(
  472. 'mview_id' => array(
  473. 'type' => 'serial',
  474. 'unsigned' => TRUE,
  475. 'not NULL' => TRUE
  476. ),
  477. 'name' => array(
  478. 'type' => 'varchar',
  479. 'length' => 255,
  480. 'not NULL' => TRUE
  481. ),
  482. 'modulename' => array(
  483. 'type' => 'varchar',
  484. 'length' => 50,
  485. 'not NULL' => TRUE,
  486. 'description' => 'The module name that provides the callback for this job'
  487. ),
  488. 'mv_table' => array(
  489. 'type' => 'varchar',
  490. 'length' => 128,
  491. 'not NULL' => FALSE
  492. ),
  493. 'mv_specs' => array(
  494. 'type' => 'text',
  495. 'size' => 'normal',
  496. 'not NULL' => FALSE
  497. ),
  498. 'mv_schema' => array(
  499. 'type' => 'text',
  500. 'size' => 'normal',
  501. 'not NULL' => FALSE
  502. ),
  503. 'indexed' => array(
  504. 'type' => 'text',
  505. 'size' => 'normal',
  506. 'not NULL' => FALSE
  507. ),
  508. 'query' => array(
  509. 'type' => 'text',
  510. 'size' => 'normal',
  511. 'not NULL' => TRUE
  512. ),
  513. 'special_index' => array(
  514. 'type' => 'text',
  515. 'size' => 'normal',
  516. 'not NULL' => FALSE
  517. ),
  518. 'last_update' => array(
  519. 'type' => 'int',
  520. 'not NULL' => FALSE,
  521. 'description' => 'UNIX integer time'
  522. ),
  523. 'status' => array(
  524. 'type' => 'text',
  525. 'size' => 'normal',
  526. 'not NULL' => FALSE
  527. ),
  528. 'comment' => array(
  529. 'type' => 'text',
  530. 'size' => 'normal',
  531. 'not NULL' => FALSE
  532. ),
  533. ),
  534. 'indexes' => array(
  535. 'mview_id' => array('mview_id')
  536. ),
  537. 'unique keys' => array(
  538. 'mv_table' => array('mv_table'),
  539. 'mv_name' => array('name'),
  540. ),
  541. 'primary key' => array('mview_id'),
  542. );
  543. }
  544. /**
  545. * Links Biological Data Entities to the chado "base" table the data is stored in.
  546. * This is where we would specify that a particular gene maps to the record in the
  547. * chado.feature table with a feature_id=2432;
  548. */
  549. function tripal_chado_chado_bundle_schema() {
  550. $schema = array(
  551. 'description' => 'Describes how a bundle maps data to Chado',
  552. 'fields' => array(
  553. 'chado_bundle_id' => array(
  554. 'description' => 'The primary identifier for this table.',
  555. 'type' => 'serial',
  556. 'unsigned' => TRUE,
  557. 'not null' => TRUE,
  558. ),
  559. 'bundle_id' => array(
  560. 'description' => 'The unique entity id.',
  561. 'type' => 'int',
  562. 'not null' => TRUE,
  563. ),
  564. 'data_table' => array(
  565. 'description' => 'The table in Chado that this term services (e.g. feature, stock, library, etc.)',
  566. 'type' => 'varchar',
  567. 'length' => 128,
  568. 'not null' => TRUE,
  569. 'default' => '',
  570. ),
  571. 'type_linker_table' => array(
  572. 'description' => 'If a linker table (e.g. cvterm/prop) is needed to uniquely identify a content type then that table name is provided here.',
  573. 'type' => 'varchar',
  574. 'length' => 128,
  575. 'not null' => FALSE,
  576. 'default' => '',
  577. ),
  578. 'type_column' => array(
  579. '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.',
  580. 'type' => 'varchar',
  581. 'length' => 128,
  582. 'not null' => FALSE,
  583. 'default' => '',
  584. ),
  585. 'type_id' => array(
  586. 'description' => 'If a type_column is set then this is the cvterm_id of the data type that this bundle maps to.',
  587. 'size' => 'big',
  588. 'type' => 'int',
  589. ),
  590. 'type_value' => array(
  591. '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.',
  592. 'type' => 'text',
  593. 'not null' => FALSE,
  594. 'default' => '',
  595. ),
  596. 'base_type_id' => array(
  597. '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.',
  598. 'size' => 'big',
  599. 'type' => 'int',
  600. )
  601. ),
  602. 'indexes' => array(
  603. 'bundle_id' => array('bundle_id'),
  604. 'data_table' => array('data_table'),
  605. ),
  606. 'unique keys' => array(
  607. 'record' => array('bundle_id'),
  608. ),
  609. 'primary key' => array('chado_bundle_id'),
  610. );
  611. return $schema;
  612. }
  613. /**
  614. * Tripal cvterm mapping schema
  615. * Map cvterms to chado tables that use them
  616. */
  617. function tripal_chado_chado_cvterm_mapping_schema() {
  618. $schema = array (
  619. 'table' => 'chado_cvterm_mapping',
  620. 'fields' => array (
  621. 'mapping_id' => array(
  622. 'type' => 'serial',
  623. 'not null' => TRUE
  624. ),
  625. 'cvterm_id' => array (
  626. 'type' => 'int',
  627. 'not null' => TRUE
  628. ),
  629. 'chado_table' => array (
  630. 'type' => 'varchar',
  631. 'length' => 128,
  632. 'not null' => TRUE
  633. ),
  634. 'chado_field' => array (
  635. 'type' => 'varchar',
  636. 'length' => 128,
  637. 'not null' => FALSE
  638. ),
  639. ),
  640. 'primary key' => array (
  641. 0 => 'mapping_id'
  642. ),
  643. 'unique key' => array(
  644. 'cvterm_id',
  645. ),
  646. 'indexes' => array(
  647. 'tripal_cvterm2table_idx1' => array('cvterm_id'),
  648. 'tripal_cvterm2table_idx2' => array('chado_table'),
  649. 'tripal_cvterm2table_idx3' => array('chado_table', 'chado_field'),
  650. ),
  651. );
  652. return $schema;
  653. }
  654. /**
  655. * Fixes a problem with the legacy feature_property/SOFP
  656. * ontology loaded with previous verions of Chado and all terms are
  657. * relationships.
  658. *
  659. * This function is called by the tripal_chado_install() for a
  660. * new Tripal setup, and the tripal_chado_update_7338 for an existing
  661. * site.
  662. */
  663. function tripal_chado_fix_legacy_SOFP_7338() {
  664. $sofp = chado_get_db(['name' => 'SOFP']);
  665. $fp = chado_get_cv(['name' => 'feature_property']);
  666. // No need to update unless the SOFP db exists
  667. if (!$sofp || !$fp) {
  668. return;
  669. }
  670. $terms = chado_select_record('cvterm', ['cvterm_id', 'name'], [
  671. 'dbxref_id' => [
  672. 'db_id' => [
  673. 'name' => 'SOFP',
  674. ],
  675. ],
  676. 'cv_id' => ['name' => 'feature_property'],
  677. ]);
  678. if (empty($terms)) {
  679. return;
  680. }
  681. foreach ($terms as $term) {
  682. $id = $term->cvterm_id;
  683. $name = $term->name;
  684. if ($name == 'linked_to') {
  685. continue;
  686. }
  687. chado_update_record('cvterm', ['cvterm_id' => $id], ['is_relationshiptype' => 0]);
  688. }
  689. // Repopulate the mview.
  690. $mview_id = chado_get_mview_id('db2cv_mview');
  691. global $user;
  692. tripal_add_job(
  693. 'Repopulating db2cv to fix legacy SOFP',
  694. 'tripal_chado',
  695. 'chado_populate_mview',
  696. [$mview_id],
  697. $user->uid
  698. );
  699. }
  700. /**
  701. * Fixes the phase on the tripal_gffcds_temp table used for importing GFF files, and fixes the db.name term mapping.
  702. *
  703. */
  704. function tripal_chado_update_7300() {
  705. try {
  706. if (chado_table_exists('tripal_gffcds_temp')) {
  707. chado_query("ALTER TABLE {tripal_gffcds_temp} ALTER COLUMN phase DROP NOT NULL;");
  708. }
  709. $term = chado_insert_cvterm(array(
  710. 'id' => 'data:1048',
  711. 'name' => 'Database ID',
  712. 'cv_name' => 'EDAM',
  713. 'definition' => 'An identifier of a biological or bioinformatics database.',
  714. ));
  715. chado_associate_semweb_term('db', 'name', $term);
  716. }
  717. catch (\PDOException $e) {
  718. $error = $e->getMessage();
  719. throw new DrupalUpdateException('Could not fix phase on tripal_gffcds_temp table: '. $error);
  720. }
  721. }
  722. /**
  723. * Divides chado_entity table for better integration with views.
  724. */
  725. function tripal_chado_update_7301() {
  726. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.bundle');
  727. try {
  728. $transaction = db_transaction();
  729. $query = db_select('chado_bundle', 'CB');
  730. $query->join('tripal_bundle', 'TB', 'TB.id = CB.bundle_id');
  731. $query->fields('CB', array('data_table'));
  732. $query->fields('TB', array('name'));
  733. $cbundles = $query->execute();
  734. // If the table for the bundle doesn't exist then create one, and then
  735. // move all of the records from the chado_entity table to it.
  736. while($cbundle = $cbundles->fetchObject()) {
  737. $cbundle_table = chado_get_bundle_entity_table($cbundle);
  738. if (!db_table_exists($cbundle_table)) {
  739. // Create the bundle table.
  740. tripal_chado_create_bundle_table($cbundle);
  741. // Now move the records over.
  742. $sql = "
  743. INSERT INTO {$cbundle_table} (entity_id, record_id, nid)
  744. SELECT CE.entity_id, CE.record_id, CE.nid
  745. FROM {chado_entity} CE
  746. INNER JOIN {tripal_entity} TE ON CE.entity_id = TE.id
  747. WHERE TE.bundle = :bundle
  748. ";
  749. db_query($sql, array(':bundle' => $cbundle->name));
  750. }
  751. }
  752. // Now remove the chado_entity table.
  753. db_drop_table('chado_entity');
  754. }
  755. catch (\PDOException $e) {
  756. $transaction->rollback();
  757. $error = $e->getMessage();
  758. throw new DrupalUpdateException('Could not perform update: '. $error);
  759. }
  760. }
  761. /**
  762. * Corrections to the EDAM database.
  763. */
  764. function tripal_chado_update_7302(){
  765. try {
  766. // Add the term for the field.
  767. chado_insert_db(array(
  768. 'name' => 'format',
  769. '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. ',
  770. 'url' => 'http://edamontology.org/page',
  771. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  772. ));
  773. chado_insert_db(array(
  774. 'name' => 'operation',
  775. '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).',
  776. 'url' => 'http://edamontology.org/page',
  777. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  778. ));
  779. chado_insert_db(array(
  780. 'name' => 'topic',
  781. '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.',
  782. 'url' => 'http://edamontology.org/page',
  783. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  784. ));
  785. chado_insert_cv(
  786. 'EDAM',
  787. '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.'
  788. );
  789. }
  790. catch (\PDOException $e) {
  791. $transaction->rollback();
  792. $error = $e->getMessage();
  793. throw new DrupalUpdateException('Could not perform update: '. $error);
  794. }
  795. }
  796. /**
  797. * Fixes inconsistency with Chado v1.3 update if was applied.
  798. */
  799. function tripal_chado_update_7303() {
  800. try {
  801. $chado_version = chado_get_version();
  802. if ($chado_version == '1.3') {
  803. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.setup');
  804. tripal_chado_fix_v1_3_custom_tables();
  805. }
  806. }
  807. catch (\PDOException $e) {
  808. $transaction->rollback();
  809. $error = $e->getMessage();
  810. throw new DrupalUpdateException('Could not perform update: '. $error);
  811. }
  812. }
  813. /**
  814. * Add some new controlled vocabulary terms.
  815. */
  816. function tripal_chado_update_7304() {
  817. try {
  818. $term = chado_insert_cvterm(array(
  819. 'id' => 'SIO:001080',
  820. 'name' => 'vocabulary',
  821. 'cv_name' => 'SIO',
  822. 'definition' => 'A vocabulary is a collection of terms.',
  823. ));
  824. chado_associate_semweb_term('cvterm', 'cv_id', $term);
  825. $term = chado_insert_cvterm(array(
  826. 'id' => 'data:2976',
  827. 'name' => 'Protein sequence',
  828. 'cv_name' => 'EDAM',
  829. 'definition' => 'One or more protein sequences, possibly with associated annotation.',
  830. ));
  831. $term = chado_insert_cvterm(array(
  832. 'id' => 'local:fmin',
  833. 'name' => 'minimal boundary',
  834. 'definition' => 'The leftmost, minimal boundary in the linear range ' .
  835. 'represented by the feature location. Sometimes this is called ' .
  836. 'start although this is confusing because it does not necessarily ' .
  837. 'represent the 5-prime coordinate.',
  838. 'cv_name' => 'local',
  839. ));
  840. chado_associate_semweb_term('featureloc', 'fmin', $term);
  841. $term = chado_insert_cvterm(array(
  842. 'id' => 'local:fmax',
  843. 'name' => 'maximal boundary',
  844. 'definition' => 'The rightmost, maximal boundary in the linear range ' .
  845. 'represented by the featureloc. Sometimes this is called end although ' .
  846. 'this is confusing because it does not necessarily represent the ' .
  847. '3-prime coordinate',
  848. 'cv_name' => 'local',
  849. ));
  850. chado_associate_semweb_term('featureloc', 'fmax', $term);
  851. $term = chado_insert_cvterm(array(
  852. 'id' => 'data:2336',
  853. 'name' => 'Translation phase specification',
  854. 'cv_name' => 'EDAM',
  855. 'definition' => 'Phase for translation of DNA (0, 1 or 2) relative to a fragment of the coding sequence.',
  856. ));
  857. chado_associate_semweb_term('featureloc', 'phase', $term);
  858. $term = chado_insert_cvterm(array(
  859. 'id' => 'data:3002',
  860. 'name' => 'Annotation track',
  861. 'cv_name' => 'EDAM',
  862. 'definition' => 'Annotation of one particular positional feature on a ' .
  863. 'biomolecular (typically genome) sequence, suitable for import and ' .
  864. 'display in a genome browser. Synonym: Sequence annotation track.',
  865. ));
  866. chado_associate_semweb_term('featureloc', 'srcfeature_id', $term);
  867. }
  868. catch (\PDOException $e) {
  869. $transaction->rollback();
  870. $error = $e->getMessage();
  871. throw new DrupalUpdateException('Could not perform update: '. $error);
  872. }
  873. }
  874. /**
  875. * Adding missing cv/db details and cvterms.
  876. */
  877. function tripal_chado_update_7305() {
  878. try {
  879. chado_insert_db(array(
  880. 'name' => 'rdfs',
  881. 'description' => 'Resource Description Framework Schema',
  882. 'url' => 'https://www.w3.org/TR/rdf-schema/',
  883. 'urlprefix' => 'https://www.w3.org/TR/rdf-schema/#ch_{accession}',
  884. ));
  885. chado_insert_cv('rdfs', 'Resource Description Framework Schema');
  886. chado_insert_db(array(
  887. 'name' => 'SO',
  888. 'description' => 'The sequence ontology.',
  889. 'url' => 'http://www.sequenceontology.org/',
  890. 'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',
  891. ));
  892. chado_insert_cv('sequence', 'The sequence ontology.');
  893. chado_insert_db(array(
  894. 'name' => 'TAXRANK',
  895. 'description' => 'A vocabulary of taxonomic ranks (species, family, phylum, etc)',
  896. 'url' => 'http://www.obofoundry.org/ontology/taxrank.html',
  897. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  898. ));
  899. chado_insert_cv('taxonomic_rank', 'A vocabulary of taxonomic ranks (species, family, phylum, etc)');
  900. chado_insert_db(array(
  901. 'name' => 'hydra',
  902. 'description' => 'A Vocabulary for Hypermedia-Driven Web APIs',
  903. 'url' => 'http://www.w3.org/ns/hydra/core',
  904. 'urlprefix' => 'http://www.w3.org/ns/hydra/core#{accession}',
  905. ));
  906. chado_insert_cv(
  907. 'hydra',
  908. 'A Vocabulary for Hypermedia-Driven Web APIs.'
  909. );
  910. chado_insert_db(array(
  911. 'name' => 'dc',
  912. 'description' => 'DCMI Metadata Terms.',
  913. 'url' => 'http://purl.org/dc/dcmitype/',
  914. 'urlprefix' => 'http://purl.org/dc/terms/{accession}',
  915. ));
  916. chado_insert_cv(
  917. 'dc',
  918. 'DCMI Metadata Terms.'
  919. );
  920. $term = chado_insert_cvterm(array(
  921. 'id' => 'dc:Service',
  922. 'name' => 'Service',
  923. 'cv_name' => 'dc',
  924. 'definition' => 'A system that provides one or more functions.',
  925. ));
  926. $name = chado_insert_cvterm(array(
  927. 'id' => 'hydra:Collection',
  928. 'name' => 'Collection',
  929. 'cv_name' => 'hydra',
  930. 'definition' => 'A collection holding references to a number of related resources.',
  931. ));
  932. $name = chado_insert_cvterm(array(
  933. 'id' => 'hydra:member',
  934. 'name' => 'member',
  935. 'cv_name' => 'hydra',
  936. 'definition' => 'A member of the collection',
  937. ));
  938. $name = chado_insert_cvterm(array(
  939. 'id' => 'hydra:description',
  940. 'name' => 'description',
  941. 'cv_name' => 'hydra',
  942. 'definition' => 'A description.',
  943. ));
  944. $name = chado_insert_cvterm(array(
  945. 'id' => 'hydra:totalItems',
  946. 'name' => 'totalItems',
  947. 'cv_name' => 'hydra',
  948. 'definition' => 'The total number of items referenced by a collection.',
  949. ));
  950. $name = chado_insert_cvterm(array(
  951. 'id' => 'hydra:title',
  952. 'name' => 'title',
  953. 'cv_name' => 'hydra',
  954. 'definition' => 'A title, often used along with a description.',
  955. ));
  956. $name = chado_insert_cvterm(array(
  957. 'id' => 'hydra:PartialCollectionView',
  958. 'name' => 'PartialCollectionView',
  959. 'cv_name' => 'hydra',
  960. '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.',
  961. ));
  962. $term = chado_insert_cvterm(array(
  963. 'id' => 'schema:ItemPage',
  964. 'name' => 'ItemPage',
  965. 'cv_name' => 'schema',
  966. 'definition' => 'A page devoted to a single item, such as a particular product or hotel.',
  967. ));
  968. global $base_path;
  969. chado_insert_db(array(
  970. 'name' => 'null',
  971. 'description' => 'No online database.',
  972. 'url' => $base_path . 'cv/lookup/null',
  973. 'urlprefix' => $base_path. 'cv/lookup/{db}/{accession}',
  974. ));
  975. chado_insert_db(array(
  976. 'name' => 'local',
  977. 'description' => 'Terms created for this site.',
  978. 'url' => $base_path . 'cv/lookup/local',
  979. 'urlprefix' => $base_path . 'cv/lookup/{db}/{accession}',
  980. ));
  981. $term = chado_insert_cvterm(array(
  982. 'id' => 'local:rank',
  983. 'name' => 'rank',
  984. 'definition' => 'A taxonmic rank',
  985. 'cv_name' => 'local',
  986. ));
  987. }
  988. catch (\PDOException $e) {
  989. $transaction->rollback();
  990. $error = $e->getMessage();
  991. throw new DrupalUpdateException('Could not perform update: '. $error);
  992. }
  993. }
  994. /**
  995. * Add cvterm mapping for the Map entity type
  996. */
  997. function tripal_chado_update_7306() {
  998. try {
  999. $identifier = array(
  1000. 'cv_id' => array('name' => 'EDAM'),
  1001. 'name' => 'Map'
  1002. );
  1003. $cvterm = chado_get_cvterm($identifier);
  1004. tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'featuremap', NULL);
  1005. }
  1006. catch (\PDOException $e) {
  1007. $error = $e->getMessage();
  1008. throw new DrupalUpdateException('Could not perform update: '. $error);
  1009. }
  1010. }
  1011. /**
  1012. * Add cvterm mapping for the Publication entity type
  1013. */
  1014. function tripal_chado_update_7307() {
  1015. try {
  1016. $identifier = array(
  1017. 'cv_id' => array('name' => 'tripal_pub'),
  1018. 'name' => 'Publication'
  1019. );
  1020. $cvterm = chado_get_cvterm($identifier);
  1021. tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'pub', NULL);
  1022. }
  1023. catch (\PDOException $e) {
  1024. $error = $e->getMessage();
  1025. throw new DrupalUpdateException('Could not perform update: '. $error);
  1026. }
  1027. }
  1028. /**
  1029. * Add cvterm mapping for the analysis.sourcversion and analysis.sourcename.
  1030. */
  1031. function tripal_chado_update_7308() {
  1032. try {
  1033. $term = chado_insert_cvterm(array(
  1034. 'id' => 'IAO:0000129',
  1035. 'name' => 'version number',
  1036. 'cv_name' => 'IAO',
  1037. 'definition' => 'A version number is an ' .
  1038. 'information content entity which is a sequence of characters ' .
  1039. 'borne by part of each of a class of manufactured products or its ' .
  1040. 'packaging and indicates its order within a set of other products ' .
  1041. 'having the same name.',
  1042. ));
  1043. chado_associate_semweb_term('analysis', 'sourceversion', $term);
  1044. chado_associate_semweb_term(NULL, 'version', $term);
  1045. $term = chado_insert_cvterm(array(
  1046. 'id' => 'schema:name',
  1047. 'name' => 'name',
  1048. 'cv_name' => 'schema',
  1049. 'definition' => 'The name of the item.',
  1050. ));
  1051. chado_associate_semweb_term('analysis', 'sourcename', $term);
  1052. $term = chado_insert_cvterm(array(
  1053. 'id' => 'data:2091',
  1054. 'name' => 'Accession',
  1055. 'cv_name' => 'EDAM',
  1056. 'definition' => 'A persistent (stable) and unique identifier, typically identifying an object (entry) from a database.',
  1057. ));
  1058. chado_associate_semweb_term('dbxref', 'accession', $term);
  1059. }
  1060. catch (\PDOException $e) {
  1061. $error = $e->getMessage();
  1062. throw new DrupalUpdateException('Could not perform update: '. $error);
  1063. }
  1064. }
  1065. /**
  1066. * Add cvterm 'annotation' and maps to cvterm linking tables.
  1067. */
  1068. function tripal_chado_update_7309() {
  1069. try {
  1070. $term = chado_insert_cvterm(array(
  1071. 'id' => 'SIO:001166',
  1072. 'name' => 'annotation',
  1073. 'cv_name' => 'SIO',
  1074. '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.',
  1075. ));
  1076. chado_associate_semweb_term('feature_cvterm', 'cvterm_id', $term);
  1077. chado_associate_semweb_term('analysis_cvterm', 'cvterm_id', $term);
  1078. chado_associate_semweb_term('cell_line_cvterm', 'cvterm_id', $term);
  1079. chado_associate_semweb_term('environment_cvterm', 'cvterm_id', $term);
  1080. chado_associate_semweb_term('expression_cvterm', 'cvterm_id', $term);
  1081. chado_associate_semweb_term('library_cvterm', 'cvterm_id', $term);
  1082. chado_associate_semweb_term('organism_cvterm', 'cvterm_id', $term);
  1083. chado_associate_semweb_term('phenotype_cvterm', 'cvterm_id', $term);
  1084. chado_associate_semweb_term('stock_cvterm', 'cvterm_id', $term);
  1085. chado_associate_semweb_term('stock_relationship_cvterm', 'cvterm_id', $term);
  1086. $term = chado_insert_cvterm(array(
  1087. 'id' => 'SIO:000281',
  1088. 'name' => 'negation',
  1089. 'cv_name' => 'SIO',
  1090. 'definition' => 'NOT is a logical operator in that has the value true if its operand is false.',
  1091. ));
  1092. chado_associate_semweb_term('feature_cvterm', 'is_not', $term);
  1093. chado_associate_semweb_term('analysis_cvterm', 'is_not', $term);
  1094. chado_associate_semweb_term('organism_cvterm', 'is_not', $term);
  1095. chado_associate_semweb_term('stock_cvterm', 'is_not', $term);
  1096. }
  1097. catch (\PDOException $e) {
  1098. $error = $e->getMessage();
  1099. throw new DrupalUpdateException('Could not perform update: '. $error);
  1100. }
  1101. }
  1102. /**
  1103. * Adds the 'OBCS' and rank order term.
  1104. */
  1105. function tripal_chado_update_7310() {
  1106. try {
  1107. chado_insert_db(array(
  1108. 'name' => 'OBCS',
  1109. 'description' => 'Ontology of Biological and Clinical Statistics.',
  1110. 'url' => 'https://github.com/obcs/obcs',
  1111. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  1112. ));
  1113. chado_insert_cv(
  1114. 'OBCS',
  1115. 'Ontology of Biological and Clinical Statistics.'
  1116. );
  1117. $term = chado_insert_cvterm(array(
  1118. 'id' => 'OBCS:0000117',
  1119. 'name' => 'rank order',
  1120. 'cv_name' => 'OBCS',
  1121. '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.',
  1122. ));
  1123. chado_associate_semweb_term(NULL, 'rank', $term);
  1124. }
  1125. catch (\PDOException $e) {
  1126. $error = $e->getMessage();
  1127. throw new DrupalUpdateException('Could not perform update: '. $error);
  1128. }
  1129. }
  1130. /**
  1131. * Fix a mistake with the association of the term with featureloc.fmin.
  1132. */
  1133. function tripal_chado_update_7311() {
  1134. try {
  1135. $term = chado_insert_cvterm(array(
  1136. 'id' => 'local:fmin',
  1137. 'name' => 'minimal boundary',
  1138. 'definition' => 'The leftmost, minimal boundary in the linear range ' .
  1139. 'represented by the feature location. Sometimes this is called ' .
  1140. 'start although this is confusing because it does not necessarily ' .
  1141. 'represent the 5-prime coordinate.',
  1142. 'cv_name' => 'local',
  1143. ));
  1144. chado_associate_semweb_term('featureloc', 'fmin', $term);
  1145. }
  1146. catch (\PDOException $e) {
  1147. $error = $e->getMessage();
  1148. throw new DrupalUpdateException('Could not perform update: '. $error);
  1149. }
  1150. }
  1151. /**
  1152. * Associates a local term with the pub.miniref column.
  1153. */
  1154. function tripal_chado_update_7312() {
  1155. try {
  1156. $term = chado_insert_cvterm(array(
  1157. 'id' => 'local:miniref',
  1158. 'name' => 'Mini-ref',
  1159. 'definition' => 'A small in-house unique identifier for a publication.',
  1160. 'cv_name' => 'local',
  1161. ));
  1162. chado_associate_semweb_term('pub', 'miniref', $term);
  1163. $term = chado_insert_cvterm(array(
  1164. 'id' => 'schema:url',
  1165. 'name' => 'url',
  1166. 'cv_name' => 'schema',
  1167. 'definition' => 'URL of the item.',
  1168. ));
  1169. chado_associate_semweb_term('db', 'url', $term);
  1170. }
  1171. catch (\PDOException $e) {
  1172. $error = $e->getMessage();
  1173. throw new DrupalUpdateException('Could not perform update: '. $error);
  1174. }
  1175. }
  1176. /**
  1177. * Run the cvtermpath for the Tripal Pub and Contact ontologies.
  1178. */
  1179. function tripal_chado_update_7313() {
  1180. try {
  1181. $cv = chado_get_cv(array('name' => 'tripal_pub'));
  1182. chado_update_cvtermpath($cv->cv_id);
  1183. $cv = chado_get_cv(array('name' => 'tripal_contact'));
  1184. chado_update_cvtermpath($cv->cv_id);
  1185. }
  1186. catch (\PDOException $e) {
  1187. $error = $e->getMessage();
  1188. throw new DrupalUpdateException('Could not perform update: '. $error);
  1189. }
  1190. }
  1191. /**
  1192. * Adds a local term for the featuremap.feature_id column.
  1193. */
  1194. function tripal_chado_update_7314() {
  1195. try {
  1196. $term = chado_insert_cvterm(array(
  1197. 'name' => 'Reference Feature',
  1198. 'definition' => 'A genomic or genetic feature on which other features are mapped.',
  1199. 'cv_name' => 'local',
  1200. 'is_relationship' => 0,
  1201. 'db_name' => 'local'
  1202. ));
  1203. chado_associate_semweb_term('featurepos', 'map_feature_id', $term);
  1204. }
  1205. catch (\PDOException $e) {
  1206. $error = $e->getMessage();
  1207. throw new DrupalUpdateException('Could not perform update: '. $error);
  1208. }
  1209. }
  1210. /**
  1211. * Fixes a mistake with the schema:additionalType term.
  1212. */
  1213. function tripal_chado_update_7315() {
  1214. try {
  1215. $term = chado_insert_cvterm(array(
  1216. 'id' => 'schema:additionalType',
  1217. 'name' => 'additionalType',
  1218. 'cv_name' => 'schema',
  1219. '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.',
  1220. ));
  1221. 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.'));
  1222. }
  1223. catch (\PDOException $e) {
  1224. $error = $e->getMessage();
  1225. throw new DrupalUpdateException('Could not perform update: '. $error);
  1226. }
  1227. }
  1228. /**
  1229. * Adds the email term for potential use with contact properties.
  1230. */
  1231. function tripal_chado_update_7316() {
  1232. try {
  1233. $term = chado_insert_cvterm(array(
  1234. 'id' => 'SIO:001323',
  1235. 'name' => 'email address',
  1236. 'cv_name' => 'SIO',
  1237. 'definition' => 'an email address is an identifier to send mail to particular electronic mailbox.',
  1238. ));
  1239. }
  1240. catch (\PDOException $e) {
  1241. $error = $e->getMessage();
  1242. throw new DrupalUpdateException('Could not perform update: '. $error);
  1243. }
  1244. }
  1245. /**
  1246. * Support for the biomaterial table.
  1247. */
  1248. function tripal_chado_update_7317() {
  1249. try {
  1250. $term = chado_insert_cvterm(array(
  1251. 'id' => 'OBI:0100026',
  1252. 'name' => 'organism',
  1253. 'cv_name' => 'obi',
  1254. '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.',
  1255. ));
  1256. chado_associate_semweb_term('biomaterial', 'taxon_id', $term);
  1257. $term = chado_insert_cvterm(array(
  1258. 'id' => 'local:contact',
  1259. 'name' => 'contact',
  1260. 'definition' => 'An entity (e.g. individual or organization) through ' .
  1261. 'whom a person can gain access to information, favors, ' .
  1262. 'influential people, and the like.',
  1263. 'cv_name' => 'local',
  1264. ));
  1265. chado_associate_semweb_term('biomaterial', 'biosourceprovider_id', $term);
  1266. }
  1267. catch (\PDOException $e) {
  1268. $error = $e->getMessage();
  1269. throw new DrupalUpdateException('Could not perform update: '. $error);
  1270. }
  1271. }
  1272. /**
  1273. * Adding biological sample term for biomaterial entities.
  1274. */
  1275. function tripal_chado_update_7318() {
  1276. try {
  1277. chado_insert_db(array(
  1278. 'name' => 'sep',
  1279. 'description' => 'Sample processing and separation techniques.',
  1280. 'url' => 'http://psidev.info/index.php?q=node/312',
  1281. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  1282. ));
  1283. chado_insert_cv('sep','A structured controlled vocabulary for the annotation of sample processing and separation techniques in scientific experiments.');
  1284. $term = chado_insert_cvterm(array(
  1285. 'id' => 'sep:00195',
  1286. 'name' => 'biological sample',
  1287. 'cv_name' => 'sep',
  1288. 'definition' => 'A biological sample analysed by a particular technology.',
  1289. ));
  1290. }
  1291. catch (\PDOException $e) {
  1292. $error = $e->getMessage();
  1293. throw new DrupalUpdateException('Could not perform update: '. $error);
  1294. }
  1295. }
  1296. /**
  1297. * Adding new Analysis term.
  1298. */
  1299. function tripal_chado_update_7319() {
  1300. try {
  1301. $term = chado_insert_cvterm(array(
  1302. 'id' => 'operation:2945',
  1303. 'name' => 'Analysis',
  1304. 'cv_name' => 'EDAM',
  1305. 'definition' => 'Apply analytical methods to existing data of a specific type.',
  1306. ));
  1307. }
  1308. catch (\PDOException $e) {
  1309. $error = $e->getMessage();
  1310. throw new DrupalUpdateException('Could not perform update: '. $error);
  1311. }
  1312. }
  1313. /**
  1314. * Adding Phylogenetic Tree content type.
  1315. */
  1316. function tripal_chado_update_7320() {
  1317. try {
  1318. // Associate the Analysis term with the analysis_id of the phylotree table.
  1319. $term = chado_get_cvterm(array('id' => 'operation:2945'));
  1320. chado_associate_semweb_term('phylotree', 'analysis_id', $term);
  1321. $term = chado_insert_cvterm(array(
  1322. 'id' => 'data:0872',
  1323. 'name' => 'Phylogenetic tree',
  1324. 'cv_name' => 'EDAM',
  1325. '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.',
  1326. ));
  1327. $term = chado_insert_cvterm(array(
  1328. 'id' => 'data:3272',
  1329. 'name' => 'Species tree',
  1330. 'cv_name' => 'EDAM',
  1331. 'definition' => 'A phylogenetic tree that reflects phylogeny of the taxa from which the characters (used in calculating the tree) were sampled.',
  1332. ));
  1333. $term = chado_insert_cvterm(array(
  1334. 'id' => 'data:3271',
  1335. 'name' => 'Gene tree',
  1336. 'cv_name' => 'EDAM',
  1337. 'definition' => 'A phylogenetic tree that is an estimate of the character\'s phylogeny.',
  1338. ));
  1339. $term = chado_insert_cvterm(array(
  1340. 'id' => 'operation:0567',
  1341. 'name' => 'Phylogenetic tree visualisation',
  1342. 'cv_name' => 'EDAM',
  1343. 'definition' => 'A phylogenetic tree that is an estimate of the character\'s phylogeny.',
  1344. ));
  1345. // Create the 'Phylogenetic tree' content type.
  1346. $error = '';
  1347. $args = array(
  1348. 'vocabulary' => 'data',
  1349. 'accession' => '0872',
  1350. 'term_name' => 'Phylogenetic tree',
  1351. 'storage_args' => array(
  1352. 'data_table' => 'phylotree',
  1353. )
  1354. );
  1355. $term = tripal_load_term_entity(array('vocabulary' => 'data', 'accession' => '0872'));
  1356. if ($term) {
  1357. $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
  1358. }
  1359. if (!$term or !$bundle) {
  1360. if (!tripal_create_bundle($args)) {
  1361. throw new Exception('Error Encountered creating "Phylogenetic tree" Tripal Content Type.');
  1362. }
  1363. }
  1364. }
  1365. catch (\PDOException $e) {
  1366. $error = $e->getMessage();
  1367. throw new DrupalUpdateException('Could not perform update: '. $error);
  1368. }
  1369. }
  1370. /**
  1371. * Updating details for local ontologies.
  1372. */
  1373. function tripal_chado_update_7321() {
  1374. try {
  1375. chado_insert_db(array(
  1376. 'name' => 'TPUB',
  1377. 'description' => 'Tripal Publication Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
  1378. 'url' => '/cv/lookup/TPUB',
  1379. 'urlprefix' => '/cv/lookup/TPUB/{accession}',
  1380. ));
  1381. chado_insert_cv('tripal_pub', 'Tripal Publication Ontology. A temporary ontology until a more formal appropriate ontology an be identified.');
  1382. chado_insert_db(array(
  1383. 'name' => 'rdf',
  1384. 'description' => 'Resource Description Framework',
  1385. 'url' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns',
  1386. 'urlprefix' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  1387. ));
  1388. chado_insert_cv(
  1389. 'rdf',
  1390. 'Resource Description Framework'
  1391. );
  1392. chado_insert_db(array(
  1393. 'name' => 'rdfs',
  1394. 'description' => 'Resource Description Framework Schema',
  1395. 'url' => 'https://www.w3.org/TR/rdf-schema/',
  1396. 'urlprefix' => 'http://www.w3.org/2000/01/rdf-schema#{accession}',
  1397. ));
  1398. chado_insert_db(array(
  1399. 'name' => 'hydra',
  1400. 'description' => 'A Vocabulary for Hypermedia-Driven Web APIs',
  1401. 'url' => 'http://www.w3.org/ns/hydra/core',
  1402. 'urlprefix' => 'http://www.w3.org/ns/hydra/core#{accession}',
  1403. ));
  1404. chado_insert_cv(
  1405. 'hydra',
  1406. 'A Vocabulary for Hypermedia-Driven Web APIs.'
  1407. );
  1408. }
  1409. catch (\PDOException $e) {
  1410. $error = $e->getMessage();
  1411. throw new DrupalUpdateException('Could not perform update: '. $error);
  1412. }
  1413. }
  1414. /**
  1415. * Fixing the SWO, TPUB and TContact vocabulary URLs
  1416. */
  1417. function tripal_chado_update_7322() {
  1418. try {
  1419. chado_insert_db(array(
  1420. 'name' => 'TPUB',
  1421. 'description' => 'Tripal Publication Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
  1422. 'url' => 'cv/lookup/TPUB',
  1423. 'urlprefix' => 'cv/lookup/TPUB/{accession}',
  1424. ));
  1425. chado_insert_db(array(
  1426. 'name' => 'TContact',
  1427. 'description' => 'Tripal Contact Ontology. A temporary ontology until a more formal appropriate ontology an be identified.',
  1428. 'url' => 'cv/lookup/TContact',
  1429. 'urlprefix' => 'cv/lookup/TContact/{accession}',
  1430. ));
  1431. chado_insert_cv('tripal_contact', 'Tripal Contact Ontology. A temporary ontology until a more formal appropriate ontology an be identified.');
  1432. chado_insert_db(array(
  1433. 'name' => 'SWO',
  1434. 'description' => 'Software Ontology',
  1435. 'url' => 'http://purl.obolibrary.org/obo/swo',
  1436. 'urlprefix' => 'http://www.ebi.ac.uk/swo/',
  1437. ));
  1438. }
  1439. catch (\PDOException $e) {
  1440. $error = $e->getMessage();
  1441. throw new DrupalUpdateException('Could not perform update: '. $error);
  1442. }
  1443. }
  1444. /**
  1445. * Adding the db2cv materialized view.
  1446. */
  1447. function tripal_chado_update_7323() {
  1448. try {
  1449. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
  1450. tripal_chado_add_db2cv_mview_mview();
  1451. drupal_set_message('Populating materialized view db2cv_mview...');
  1452. $mview_id = chado_get_mview_id('db2cv_mview');
  1453. chado_populate_mview($mview_id);
  1454. drupal_set_message('Populating materialized view cv_root_mview...');
  1455. $mview_id = chado_get_mview_id('cv_root_mview');
  1456. chado_populate_mview($mview_id);
  1457. }
  1458. catch (\PDOException $e) {
  1459. $error = $e->getMessage();
  1460. throw new DrupalUpdateException('Could not perform update: '. $error);
  1461. }
  1462. }
  1463. /**
  1464. * Updating the db2cv materialized view.
  1465. */
  1466. function tripal_chado_update_7324() {
  1467. try {
  1468. if (chado_table_exists(db2cv_mview) and !chado_column_exists('db2cv_mview', 'num_terms')) {
  1469. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
  1470. // Remove the old mview.
  1471. $mview_id = chado_get_mview_id('db2cv_mview');
  1472. chado_delete_mview($mview_id);
  1473. // Readd the mview.
  1474. tripal_chado_add_db2cv_mview_mview();
  1475. drupal_set_message('Populating materialized view db2cv_mview...');
  1476. $mview_id = chado_get_mview_id('db2cv_mview');
  1477. chado_populate_mview($mview_id);
  1478. }
  1479. }
  1480. catch (\PDOException $e) {
  1481. $error = $e->getMessage();
  1482. throw new DrupalUpdateException('Could not perform update: '. $error);
  1483. }
  1484. }
  1485. /**
  1486. * Adding additional vocabulary term mapping to Chado table columns.
  1487. */
  1488. function tripal_chado_update_7325() {
  1489. try {
  1490. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
  1491. tripal_chado_populate_chado_semweb_table();
  1492. }
  1493. catch (\PDOException $e) {
  1494. $error = $e->getMessage();
  1495. throw new DrupalUpdateException('Could not perform update: '. $error);
  1496. }
  1497. }
  1498. /**
  1499. * Adding a "Company" term.
  1500. */
  1501. function tripal_chado_update_7326() {
  1502. try {
  1503. // The Company term is missing for the Tripal Contact ontology, but is
  1504. // useful for the arraydesign.manufacturer which is an FK to Contact.
  1505. // It seems better to use a term from a curated ontology than to add to
  1506. // Tripal Contact.
  1507. $term = chado_insert_cvterm(array(
  1508. 'id' => 'NCIT:C54131',
  1509. 'name' => 'Company',
  1510. 'cv_name' => 'ncit',
  1511. 'definition' => 'Any formal business entity for profit, which may be a corporation, a partnership, association or individual proprietorship. [ NCI http://dictionary.law.com ]',
  1512. ));
  1513. }
  1514. catch (\PDOException $e) {
  1515. $error = $e->getMessage();
  1516. throw new DrupalUpdateException('Could not perform update: '. $error);
  1517. }
  1518. }
  1519. /**
  1520. * Adding terms for sequence visualization.
  1521. */
  1522. function tripal_chado_update_7327() {
  1523. try {
  1524. $term = chado_insert_cvterm(array(
  1525. 'id' => 'operation:0564',
  1526. 'name' => 'Sequence visualisation',
  1527. 'cv_name' => 'EDAM',
  1528. 'definition' => 'Visualise, format or render a molecular sequence or sequences such as a sequence alignment, possibly with sequence features or properties shown.',
  1529. ));
  1530. }
  1531. catch (\PDOException $e) {
  1532. $error = $e->getMessage();
  1533. throw new DrupalUpdateException('Could not perform update: '. $error);
  1534. }
  1535. }
  1536. /**
  1537. * Don't count relationship cvterms as ontology roots.
  1538. */
  1539. function tripal_chado_update_7328() {
  1540. try {
  1541. $mv_name = 'cv_root_mview';
  1542. // Remove the old mview.
  1543. $mview_id = chado_get_mview_id($mv_name);
  1544. chado_delete_mview($mview_id);
  1545. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
  1546. // Re-add the mview.
  1547. tripal_chado_add_cv_root_mview_mview();
  1548. $mview_id = chado_get_mview_id($mv_name);
  1549. chado_populate_mview($mview_id);
  1550. }
  1551. catch (\PDOException $e) {
  1552. $error = $e->getMessage();
  1553. throw new DrupalUpdateException('Could not perform update: '. $error);
  1554. }
  1555. }
  1556. /**
  1557. * Fixing the chado_bundle.type_id type.
  1558. */
  1559. function tripal_chado_update_7329() {
  1560. try {
  1561. db_change_field('chado_bundle', 'type_id', 'type_id', [
  1562. 'description' => 'If a type_column is set then this is the cvterm_id of the data type that this bundle maps to.',
  1563. 'size' => 'big',
  1564. 'type' => 'int',
  1565. ]);
  1566. }
  1567. catch (\PDOException $e) {
  1568. $error = $e->getMessage();
  1569. throw new DrupalUpdateException('Could not perform update: '. $error);
  1570. }
  1571. }
  1572. /**
  1573. * Associates categories with content types.
  1574. */
  1575. function tripal_chado_update_7330() {
  1576. try {
  1577. tripal_insert_variable('bundle_category', 'Bundles can be categorized to allow for grouping');
  1578. $bundles = [
  1579. 'General' => [
  1580. // Organism
  1581. 'OBI:0100026',
  1582. // Analyis
  1583. 'operation:2945',
  1584. // Project
  1585. 'NCIT:C47885',
  1586. // Study
  1587. 'SIO:001066',
  1588. // Contact
  1589. 'local:contact',
  1590. // Publication
  1591. 'TPUB:0000002',
  1592. // Protocol
  1593. 'sep:00101',
  1594. ],
  1595. 'Genomic' => [
  1596. // Gene
  1597. 'SO:0000704',
  1598. // mRNA
  1599. 'SO:0000234',
  1600. // Phylogenetci Tree
  1601. 'data:0872',
  1602. // Physical Map
  1603. 'data:1280',
  1604. // DNA Library
  1605. 'NCIT:C16223',
  1606. // Genome Assembly
  1607. 'operation:0525',
  1608. // Genome Annotation
  1609. 'operation:0362',
  1610. // Genome Project
  1611. 'local:Genome Project',
  1612. ],
  1613. 'Genetic' => [
  1614. // Genetic Map
  1615. 'data:1278',
  1616. // QTL
  1617. 'SO:0000771',
  1618. // Sequence Variant
  1619. 'SO:0001060',
  1620. // Genetic Marker
  1621. 'SO:0001645',
  1622. // Heritable Phenotypic Marker
  1623. 'SO:0001500',
  1624. ],
  1625. 'Germplasm/Breeding' => [
  1626. // Germplasm Accession
  1627. 'CO_010:0000044',
  1628. // Breeding Cross
  1629. 'CO_010:0000255',
  1630. // Cutlivar
  1631. 'CO_010:0000029',
  1632. // Recombinant Inbred Line
  1633. 'CO_010:0000162',
  1634. ],
  1635. 'Expression' => [
  1636. // Biological Sample
  1637. 'sep:00195',
  1638. // Assay
  1639. 'OBI:0000070',
  1640. // Array Design
  1641. 'EFO:0000269',
  1642. ]
  1643. ];
  1644. foreach ($bundles as $category => $accessions) {
  1645. foreach ($accessions as $accession) {
  1646. $bundle = tripal_load_bundle_entity(['accession' => $accession]);
  1647. if ($bundle) {
  1648. tripal_set_bundle_variable('bundle_category', $bundle->id, $category);
  1649. }
  1650. }
  1651. }
  1652. }
  1653. catch (\PDOException $e) {
  1654. $error = $e->getMessage();
  1655. throw new DrupalUpdateException('Could not perform update: '. $error);
  1656. }
  1657. }
  1658. /**
  1659. * Adds a base_type_id to the chado_bundle table.
  1660. */
  1661. function tripal_chado_update_7331() {
  1662. try {
  1663. if (!db_field_exists('chado_bundle', 'base_type_id')) {
  1664. db_add_field('chado_bundle', 'base_type_id', [
  1665. '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.',
  1666. 'size' => 'big',
  1667. 'type' => 'int',
  1668. ]);
  1669. }
  1670. }
  1671. catch (\PDOException $e) {
  1672. $error = $e->getMessage();
  1673. throw new DrupalUpdateException('Could not perform update: '. $error);
  1674. }
  1675. }
  1676. /**
  1677. * Adds additional vocabs for the OBO Importer.
  1678. */
  1679. function tripal_chado_update_7332() {
  1680. try {
  1681. // We have to add the db and cv in case the user hasn't yet prepared Chado.
  1682. // If they have prepared Chado then no harm done.
  1683. chado_insert_db([
  1684. 'name' => 'NCIT',
  1685. 'description' => 'NCI Thesaurus OBO Edition.',
  1686. 'url' => 'http://purl.obolibrary.org/obo/ncit.owl',
  1687. 'urlprefix' => ' http://purl.obolibrary.org/obo/{db}_{accession}',
  1688. ]);
  1689. chado_insert_cv(
  1690. 'ncit',
  1691. 'The NCIt OBO Edition project aims to increase integration of the NCIt with OBO Library ontologies. NCIt is a reference terminology that includes broad coverage of the cancer domain, including cancer related diseases, findings and abnormalities. NCIt OBO Edition releases should be considered experimental.'
  1692. );
  1693. $term = chado_insert_cvterm([
  1694. 'id' => 'NCIT:C25693',
  1695. 'name' => 'Subgroup',
  1696. 'cv_name' => 'ncit',
  1697. 'definition' => 'A subdivision of a larger group with members often exhibiting similar characteristics. [ NCI ]',
  1698. ]);
  1699. // Add the rdfs:comment vocabulary.
  1700. chado_insert_db(array(
  1701. 'name' => 'rdfs',
  1702. 'description' => 'Resource Description Framework Schema',
  1703. 'url' => 'https://www.w3.org/TR/rdf-schema/',
  1704. 'urlprefix' => 'http://www.w3.org/2000/01/rdf-schema#{accession}',
  1705. ));
  1706. chado_insert_cv(
  1707. 'rdfs',
  1708. 'Resource Description Framework Schema'
  1709. );
  1710. $name = chado_insert_cvterm(array(
  1711. 'id' => 'rdfs:comment',
  1712. 'name' => 'comment',
  1713. 'cv_name' => 'rdfs',
  1714. 'definition' => 'A human-readable description of a resource\'s name.',
  1715. ));
  1716. }
  1717. catch (\PDOException $e) {
  1718. $error = $e->getMessage();
  1719. throw new DrupalUpdateException('Could not perform update: '. $error);
  1720. }
  1721. }
  1722. /**
  1723. * Renames the TContact vocabulary database entry to TCONTACT as it should be.
  1724. */
  1725. function tripal_chado_update_7333() {
  1726. try {
  1727. chado_update_record('db', ['name' => 'TContact'], ['name' => 'TCONTACT']);
  1728. }
  1729. catch (\PDOException $e) {
  1730. $error = $e->getMessage();
  1731. throw new DrupalUpdateException('Could not perform update: '. $error);
  1732. }
  1733. }
  1734. /**
  1735. * SQL Fix for the db2cv_mview materialized view.
  1736. */
  1737. function tripal_chado_update_7334() {
  1738. try {
  1739. $query = '
  1740. SELECT DISTINCT CV.cv_id, CV.name as cvname, DB.db_id, DB.name as dbname,
  1741. COUNT(CVT.cvterm_id) as num_terms
  1742. FROM cv CV
  1743. INNER JOIN cvterm CVT on CVT.cv_id = CV.cv_id
  1744. INNER JOIN dbxref DBX on DBX.dbxref_id = CVT.dbxref_id
  1745. INNER JOIN db DB on DB.db_id = DBX.db_id
  1746. WHERE CVT.is_relationshiptype = 0 and CVT.is_obsolete = 0
  1747. GROUP BY CV.cv_id, CV.name, DB.db_id, DB.name
  1748. ORDER BY DB.name
  1749. ';
  1750. $mview_id = tripal_get_mview_id('db2cv_mview');
  1751. if($mview_id) {
  1752. $sql = "UPDATE {tripal_mviews} set query = :query WHERE mview_id = :mview_id";
  1753. db_query($sql, [':query' => $query, ':mview_id' => $mview_id]);
  1754. }
  1755. }
  1756. catch (\PDOException $e) {
  1757. $error = $e->getMessage();
  1758. throw new DrupalUpdateException('Could not perform update: '. $error);
  1759. }
  1760. }
  1761. /**
  1762. * SQL Fix for the cv_root_mview materialized view.
  1763. */
  1764. function tripal_chado_update_7335() {
  1765. try {
  1766. $query = '
  1767. SELECT DISTINCT CVT.name, CVT.cvterm_id, CV.cv_id, CV.name
  1768. FROM cvterm CVT
  1769. LEFT JOIN cvterm_relationship CVTR ON CVT.cvterm_id = CVTR.subject_id
  1770. INNER JOIN cvterm_relationship CVTR2 ON CVT.cvterm_id = CVTR2.object_id
  1771. INNER JOIN cv CV on CV.cv_id = CVT.cv_id
  1772. WHERE CVTR.subject_id is NULL and
  1773. CVT.is_relationshiptype = 0 and CVT.is_obsolete = 0
  1774. ';
  1775. $mview_id = tripal_get_mview_id('cv_root_mview');
  1776. if($mview_id) {
  1777. $sql = "UPDATE {tripal_mviews} set query = :query WHERE mview_id = :mview_id";
  1778. db_query($sql, [':query' => $query, ':mview_id' => $mview_id]);
  1779. }
  1780. }
  1781. catch (\PDOException $e) {
  1782. $error = $e->getMessage();
  1783. throw new DrupalUpdateException('Could not perform update: '. $error);
  1784. }
  1785. }
  1786. /**
  1787. * Use correct contact field when linked via linker table.
  1788. */
  1789. function tripal_chado_update_7336() {
  1790. try {
  1791. $bundles = field_info_instances('TripalEntity');
  1792. foreach ($bundles as $bundle_name => $fields) {
  1793. $bundle = tripal_load_bundle_entity(['name' => $bundle_name]);
  1794. $base = $bundle->data_table;
  1795. $contact_table = $base . '_contact';
  1796. if (chado_table_exists($contact_table)) {
  1797. $field_name = $base . '_contact';
  1798. $instance_info = field_info_instance('TripalEntity', $field_name, $bundle_name);
  1799. if ($instance_info) {
  1800. $instance_info['type'] = 'chado_linker__contact';
  1801. $instance_info['widget']['type'] = 'chado_linker__contact_widget';
  1802. $instance_info['formatter']['type'] = 'chado_linker__contact_widget';
  1803. field_update_instance($instance_info);
  1804. }
  1805. }
  1806. }
  1807. }
  1808. catch (\PDOException $e) {
  1809. $error = $e->getMessage();
  1810. throw new DrupalUpdateException('Could not perform update: '. $error);
  1811. }
  1812. }
  1813. /**
  1814. * Update the NCBITaxon DB entry.
  1815. */
  1816. function tripal_chado_update_7337(){
  1817. try {
  1818. chado_insert_db(array(
  1819. 'name' => 'NCBITaxon',
  1820. 'description' => 'NCBI organismal classification.',
  1821. 'url' => 'http://www.berkeleybop.org/ontologies/ncbitaxon/',
  1822. 'urlprefix' => 'https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id={accession}',
  1823. ));
  1824. }
  1825. catch (\PDOException $e) {
  1826. $error = $e->getMessage();
  1827. throw new DrupalUpdateException('Could not perform update: '. $error);
  1828. }
  1829. }
  1830. /**
  1831. * Modify the term name for Sequence Variant, Genetic Marker, and Heritable Phenotypic Marker to match the corresponding SO term.
  1832. */
  1833. function tripal_chado_update_7338() {
  1834. $terms = [
  1835. [
  1836. 'vocabulary' => 'SO',
  1837. 'label' => 'Sequence Variant',
  1838. 'term' => 'sequence_variant',
  1839. 'accession' => '0001060',
  1840. ],
  1841. [
  1842. 'vocabulary' => 'SO',
  1843. 'label' => 'Genetic Marker',
  1844. 'term' => 'genetic_marker',
  1845. 'accession' => '0001645',
  1846. ],
  1847. [
  1848. 'vocabulary' => 'SO',
  1849. 'label' => 'Heritable Phenotypic Marker',
  1850. 'term' => 'heritable_phenotypic_marker',
  1851. 'accession' => '0001500',
  1852. ],
  1853. [
  1854. 'vocabulary' => 'SIO',
  1855. 'label' => 'Study',
  1856. 'term' => 'study',
  1857. 'accession' => '001066',
  1858. ],
  1859. [
  1860. 'vocabulary' => 'sep',
  1861. 'label' => 'Biological Sample',
  1862. 'term' => ' biological sample',
  1863. 'accession' => '00195',
  1864. ],
  1865. [
  1866. 'vocabulary' => 'OBI',
  1867. 'label' => 'Assay',
  1868. 'term' => 'assay',
  1869. 'accession' => '0000070',
  1870. ],
  1871. [
  1872. 'vocabulary' => 'data',
  1873. 'label' => 'Genetic Map',
  1874. 'term' => 'Genetic map',
  1875. 'accession' => '1278',
  1876. ],
  1877. [
  1878. 'vocabulary' => 'operation',
  1879. 'label' => 'Genome Annotation',
  1880. 'term' => 'Genome annotation',
  1881. 'accession' => '0362',
  1882. ],
  1883. [
  1884. 'vocabulary' => 'operation',
  1885. 'label' => 'Genome Assembly',
  1886. 'term' => 'Genome assembly',
  1887. 'accession' => '0525',
  1888. ],
  1889. [
  1890. 'vocabulary' => 'CO_010',
  1891. 'label' => 'Generated Germplasm (Breeding Cross)',
  1892. 'term' => 'generated germplasm',
  1893. 'accession' => '0000255',
  1894. ],
  1895. [
  1896. 'vocabulary' => 'CO_010',
  1897. 'label' => 'Cultivar (Germplasm Variety)',
  1898. 'term' => 'cultivar',
  1899. 'accession' => '0000029',
  1900. ],
  1901. [
  1902. 'vocabulary' => 'CO_010',
  1903. 'label' => 'Germplasm Accession',
  1904. 'term' => 'accession',
  1905. 'accession' => '0000044',
  1906. ],
  1907. [
  1908. 'vocabulary' => 'data',
  1909. 'label' => 'Physical Map',
  1910. 'term' => 'Physical map',
  1911. 'accession' => '1280',
  1912. ],
  1913. [
  1914. 'vocabulary' => 'sep',
  1915. 'label' => 'Protocol',
  1916. 'term' => ' protocol',
  1917. 'accession' => '00101',
  1918. ],
  1919. [
  1920. 'vocabulary' => 'CO_010',
  1921. 'label' => 'Recombinant Inbred Line',
  1922. 'term' => '414 inbred line',
  1923. 'accession' => '0000162',
  1924. ],
  1925. ];
  1926. try {
  1927. foreach ($terms as $term) {
  1928. $label = $term['label'];
  1929. $termName = $term['term'];
  1930. $accession = $term['accession'];
  1931. $vocabulary = $term['vocabulary']; #shortname, ie, chado.db
  1932. $term = tripal_load_term_entity([
  1933. 'vocabulary' => $vocabulary,
  1934. 'accession' => $accession
  1935. ]);
  1936. if (!$term) {
  1937. continue;
  1938. }
  1939. $term->name = $termName;
  1940. $term->save();
  1941. $bundle = tripal_load_bundle_entity(['term_id' => $term->id]);
  1942. if (!$bundle) {
  1943. continue;
  1944. }
  1945. $bundle->label = $label;
  1946. $bundle->save();
  1947. }
  1948. } catch (\PDOException $e) {
  1949. $error = $e->getMessage();
  1950. throw new DrupalUpdateException('Could not perform update: '. $error);
  1951. }
  1952. }
  1953. /**
  1954. * Adds the "Sequence record" cvterm for the data__sequence_record field.
  1955. */
  1956. function tripal_chado_update_7339() {
  1957. try {
  1958. chado_insert_cvterm([
  1959. 'id' => 'data:0849',
  1960. 'name' => 'Sequence record',
  1961. 'cv_name' => 'EDAM',
  1962. 'definition' => 'A molecular sequence and associated metadata.',
  1963. ]);
  1964. drupal_set_message("\n\nNOTE: This update includes a new \"Sequences\" field. It compiles both primary sequences and sequences extracted from the reference into a single list. For mRNA it provides gene, full length mRNA, CDS and protein sequences (if available). Please consider using this new field and disabling other sequence fields.\n\n");
  1965. } catch (\PDOException $e) {
  1966. $error = $e->getMessage();
  1967. throw new DrupalUpdateException('Could not perform update: '. $error);
  1968. }
  1969. }
  1970. /**
  1971. * Adds the "FASTA definition" cvterm for the data__sequence_record field.
  1972. */
  1973. function tripal_chado_update_7340() {
  1974. try {
  1975. chado_insert_cvterm([
  1976. 'name' => 'fasta_definition',
  1977. 'definition' => 'The definition line for a FASTA formatted sequence',
  1978. 'cv_name' => 'local',
  1979. 'is_relationship' => 0,
  1980. 'db_name' => 'local',
  1981. ]);
  1982. } catch (\PDOException $e) {
  1983. $error = $e->getMessage();
  1984. throw new DrupalUpdateException('Could not perform update: '. $error);
  1985. }
  1986. }