tripal_chado.setup.inc 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. <?php
  2. /**
  3. * @file
  4. * Functions to install chado schema through Drupal
  5. */
  6. /**
  7. * Prepares Chado for Tripal use
  8. */
  9. function tripal_chado_prepare_form($form, $form_state) {
  10. $form = array();
  11. if (variable_get('tripal_chado_is_prepared') == TRUE) {
  12. drupal_set_message('Your site is prepared.');
  13. }
  14. $form['instructions'] = array(
  15. '#type' => 'item',
  16. '#title' => 'Prepare Drupal for Chado.',
  17. '#description' => t("Before a Drupal site can use Chado (via Tripal), both
  18. Chado and Drupal must be prepared a bit more. Tripal will add some new
  19. materialized views, custom tables and controlled vocabularies to Chado.
  20. It will also add some management tables to Drupal and add some default
  21. content types for biological and ancillary data."),
  22. );
  23. $form['prepare-button'] = array(
  24. '#type' => 'submit',
  25. '#value' => t('Prepare this site'),
  26. '#name' => 'prepare-chado',
  27. );
  28. return $form;
  29. }
  30. /**
  31. * Submit function for the tripal_chado_prepare_form().
  32. *
  33. * @param $form
  34. * @param $form_state
  35. */
  36. function tripal_chado_prepare_form_submit($form, $form_state) {
  37. if ($form_state['clicked_button']['#name'] == "prepare-chado") {
  38. global $user;
  39. $args = array();
  40. $includes = array(
  41. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.setup'),
  42. );
  43. tripal_add_job('Prepare Chado', 'tripal_chado',
  44. 'tripal_chado_prepare_chado', $args,
  45. $user->uid, 10, $includes);
  46. }
  47. }
  48. /**
  49. * Submit function for the tripal_chado_prepare_form().
  50. *
  51. * @param $form
  52. * @param $form_state
  53. */
  54. function tripal_chado_prepare_drush_submit() {
  55. $args = array();
  56. $includes = array(
  57. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.setup'),
  58. );
  59. tripal_add_job('Prepare Chado', 'tripal_chado',
  60. 'tripal_chado_prepare_chado', $args,
  61. 1, 10, $includes);
  62. }
  63. /**
  64. *
  65. */
  66. function tripal_chado_load_ontologies() {
  67. // Insert commonly used ontologies into the tables.
  68. $ontologies = array(
  69. array(
  70. 'name' => 'Relationship Ontology (legacy)',
  71. 'path' => '{tripal_chado}/files/legacy_ro.obo',
  72. 'auto_load' => FALSE,
  73. 'cv_name' => 'ro',
  74. 'db_name' => 'RO',
  75. ),
  76. array(
  77. 'name' => 'Gene Ontology',
  78. 'path' => 'http://purl.obolibrary.org/obo/go.obo',
  79. 'auto_load' => FALSE,
  80. 'cv_name' => 'cellualar_component',
  81. 'db_name' => 'GO',
  82. ),
  83. array(
  84. 'name' => 'Taxonomic Rank',
  85. 'path' => 'http://purl.obolibrary.org/obo/taxrank.obo',
  86. 'auto_load' => TRUE,
  87. 'cv_name' => 'taxonomic_rank',
  88. 'db_name' => 'TAXRANK'
  89. ),
  90. array(
  91. 'name' => 'Tripal Contact',
  92. 'path' => '{tripal_chado}/files/tcontact.obo',
  93. 'auto_load' => TRUE,
  94. 'cv_name' => 'tripal_contact',
  95. 'db_name' => 'TContact'
  96. ),
  97. array(
  98. 'name' => 'Tripal Publication',
  99. 'path' => '{tripal_chado}/files/tpub.obo',
  100. 'auto_load' => TRUE,
  101. 'cv_name' => 'tripal_pub',
  102. 'db_name' => 'TPUB',
  103. ),
  104. array(
  105. 'name' => 'Sequence Ontology',
  106. 'path' => 'http://purl.obolibrary.org/obo/so.obo',
  107. 'auto_load' => TRUE,
  108. 'cv_name' => 'sequence',
  109. 'db_name' => 'SO',
  110. ),
  111. );
  112. module_load_include('inc', 'tripal_chado', 'includes/TripalImporter/OBOImporter');
  113. for ($i = 0; $i < count($ontologies); $i++) {
  114. $obo_id = chado_insert_obo($ontologies[$i]['name'], $ontologies[$i]['path']);
  115. if ($ontologies[$i]['auto_load'] == TRUE) {
  116. // Only load ontologies that are not already in the cv table.
  117. $cv = chado_get_cv(array('name' => $ontologies[$i]['cv_name']));
  118. $db = chado_get_db(array('name' => $ontologies[$i]['db_name']));
  119. if (!$cv or !$db) {
  120. print "Loading ontology: " . $ontologies[$i]['name'] . " ($obo_id)...\n";
  121. $obo_importer = new OBOImporter();
  122. $obo_importer->create(array('obo_id' => $obo_id));
  123. $obo_importer->run();
  124. $obo_importer->postRun();
  125. }
  126. else {
  127. print "Ontology already loaded (skipping): " . $ontologies[$i]['name'] . "...\n";
  128. }
  129. }
  130. }
  131. }
  132. /**
  133. * Prepares Chado for use by Tripal.
  134. */
  135. function tripal_chado_prepare_chado($job = NULL) {
  136. // Retrieve the job arguement in order to report progress.
  137. if (is_int($job)) {
  138. $job = new TripalJob();
  139. $job->load($job);
  140. }
  141. $report_progress = TRUE;
  142. if (!is_object($job)) {
  143. $report_progress = FALSE;
  144. }
  145. try {
  146. // We want to provide a set of commonly used entity types by default. This
  147. // way when a user first installs Tripal there are some commonly used
  148. // formats.
  149. module_load_include('inc', 'tripal', 'api/tripal.api');
  150. module_load_include('inc', 'tripal', 'includes/tripal.admin');
  151. module_load_include('inc', 'tripal_chado', 'includes/tripal_chado.semweb');
  152. // Get the effective version. Pass true as second argument
  153. // to warn the user if the current version is not compatible.
  154. $version = chado_get_version(FALSE, FALSE);
  155. // We want to force the version of Chado to be set properly.
  156. $real_version = chado_get_version(TRUE);
  157. // Create custom tables depending on the Chado version installed.
  158. drush_print("Creating Tripal Materialized Views and Custom Tables...");
  159. $chado_version = chado_get_version();
  160. if ($chado_version == '1.1') {
  161. tripal_chado_add_v1_1_custom_tables();
  162. tripal_chado_add_vx_x_custom_tables();
  163. }
  164. if ($chado_version == '1.2') {
  165. tripal_chado_add_v1_2_custom_tables();
  166. tripal_chado_add_vx_x_custom_tables();
  167. }
  168. if ($chado_version == '1.3') {
  169. tripal_chado_add_vx_x_custom_tables();
  170. tripal_chado_fix_v1_3_custom_tables();
  171. }
  172. if ($report_progress) {
  173. $job->setProgress(5);
  174. }
  175. // Import commonly used ontologies if needed.
  176. drush_print("Loading Ontologies...");
  177. tripal_chado_load_ontologies();
  178. drush_print('Populating materialized view cv_root_mview...');
  179. $mview_id = chado_get_mview_id('cv_root_mview');
  180. chado_populate_mview($mview_id);
  181. if ($report_progress) {
  182. $job->setProgress(50);
  183. }
  184. // Populate the semantic web associations for Chado tables/fields.
  185. drush_print("Making semantic connections for Chado tables/fields...");
  186. tripal_chado_populate_chado_semweb_table();
  187. if ($report_progress) {
  188. $job->setProgress(60);
  189. }
  190. // Initialize the population of the chado_cvterm_mapping table. This will
  191. // map existing data types already in Chado so that when users want to
  192. // add new content types it simplifies the form for them.
  193. drush_print("Map Chado Controlled vocabularies to Tripal Terms...");
  194. tripal_chado_map_cvterms();
  195. if ($report_progress) {
  196. $job->setProgress(70);
  197. }
  198. // Populate the mviews based on controlled vocabularies.
  199. drush_print('Populating materialized view db2cv_mview...');
  200. $mview_id = chado_get_mview_id('db2cv_mview');
  201. chado_populate_mview($mview_id);
  202. drush_print("Creating common Tripal Content Types...");
  203. drush_print("This may take awhile if you are upgrading a site that has lots of data...");
  204. if ($report_progress) {
  205. $job->setProgress(85);
  206. }
  207. tripal_chado_prepare_general_types($job);
  208. tripal_chado_prepare_genomic_types($job);
  209. tripal_chado_prepare_genetic_types($job);
  210. tripal_chado_prepare_germplasm_types($job);
  211. tripal_chado_prepare_expression_types($job);
  212. // Add the supported loaders
  213. variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
  214. // Set a variable to indicate the site is prepared.
  215. variable_set('tripal_chado_is_prepared', TRUE);
  216. if ($report_progress) {
  217. $job->setProgress(100);
  218. }
  219. }
  220. catch (Exception $e) {
  221. $job->logMessage($e);
  222. throw new Exception($e);
  223. }
  224. // Clear the Drupal menu cache so that the new content types have "add" links.
  225. menu_cache_clear_all();
  226. }
  227. /**
  228. * Creates the "General" category of content types.
  229. */
  230. function tripal_chado_prepare_general_types($job) {
  231. //
  232. // Create the 'Organism' entity type. This uses the obi:organism term.
  233. //
  234. $args = array(
  235. 'vocabulary' => 'OBI',
  236. 'accession' => '0100026',
  237. 'term_name' => 'organism',
  238. 'storage_args' => array(
  239. 'data_table' => 'organism',
  240. ),
  241. 'category' => 'General'
  242. );
  243. _tripal_chado_preapre_create_bundle($args, $job);
  244. //
  245. // Create the 'Analysis' entity type. This uses the local:analysis term.
  246. //
  247. $args = array(
  248. 'vocabulary' => 'operation',
  249. 'accession' => '2945',
  250. 'term_name' => 'Analysis',
  251. 'storage_args' => array(
  252. 'data_table' => 'analysis',
  253. ),
  254. 'category' => 'General'
  255. );
  256. _tripal_chado_preapre_create_bundle($args, $job);
  257. //
  258. // Create the 'Project' entity type. This uses the local:project term.
  259. //
  260. $args = array(
  261. 'vocabulary' => 'NCIT',
  262. 'accession' => 'C47885',
  263. 'term_name' => 'Project',
  264. 'storage_args' => array(
  265. 'data_table' => 'project',
  266. ),
  267. 'category' => 'General'
  268. );
  269. _tripal_chado_preapre_create_bundle($args, $job);
  270. //
  271. // Create the 'Study' entity type. This uses the local:project term.
  272. //
  273. $args = array(
  274. 'vocabulary' => 'SIO',
  275. 'accession' => '001066',
  276. 'term_name' => 'Study',
  277. 'storage_args' => array(
  278. 'data_table' => 'study',
  279. ),
  280. 'category' => 'General'
  281. );
  282. _tripal_chado_preapre_create_bundle($args, $job);
  283. //
  284. // Create the 'Contact' entity type. This uses the local:contact term.
  285. //
  286. $args = array(
  287. 'vocabulary' => 'local',
  288. 'accession' => 'contact',
  289. 'term_name' => 'contact',
  290. 'storage_args' => array(
  291. 'data_table' => 'contact',
  292. ),
  293. 'category' => 'General'
  294. );
  295. _tripal_chado_preapre_create_bundle($args, $job);
  296. //
  297. // Create the 'Publication' entity type.
  298. //
  299. $args = array(
  300. 'vocabulary' => 'TPUB',
  301. 'accession' => '0000002',
  302. 'term_name' => 'Publication',
  303. 'storage_args' => array(
  304. 'data_table' => 'pub',
  305. ),
  306. 'category' => 'General'
  307. );
  308. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  309. if (!$bundle) {
  310. // Import a publication so we get all of the properties before
  311. // creating the content type.
  312. chado_import_pub_by_dbxref('PMID:24163125');
  313. _tripal_chado_preapre_create_bundle($args, $job);
  314. // Now remove the publication that was added above.
  315. $values = array(
  316. 'dbxref_id' => array(
  317. 'accession' => '24163125',
  318. 'db_id' => array(
  319. 'name' => 'PMID',
  320. ),
  321. ),
  322. );
  323. $result = chado_select_record('pub_dbxref', array('pub_id'), $values);
  324. chado_delete_record('pub', array('pub_id' => $result[0]->pub_id));
  325. }
  326. //
  327. // Create the 'Protocol' entity type.
  328. //
  329. $args = array(
  330. 'vocabulary' => 'sep',
  331. 'accession' => '00101',
  332. 'term_name' => 'Protocol',
  333. 'storage_args' => array(
  334. 'data_table' => 'protocol',
  335. ),
  336. 'category' => 'General'
  337. );
  338. _tripal_chado_preapre_create_bundle($args, $job);
  339. }
  340. /**
  341. * Creates the "Genomic" category of content types.
  342. */
  343. function tripal_chado_prepare_genomic_types($job) {
  344. //
  345. // Create the 'Gene' entity type.
  346. //
  347. $args = array(
  348. 'vocabulary' => 'SO',
  349. 'accession' => '0000704',
  350. 'term_name' => 'gene',
  351. 'storage_args' => array(
  352. 'data_table' => 'feature',
  353. 'type_column' => 'type_id',
  354. ),
  355. 'category' => 'Genomic',
  356. );
  357. _tripal_chado_preapre_create_bundle($args, $job);
  358. //
  359. // Create the 'mRNA' entity type.
  360. //
  361. $args = array(
  362. 'vocabulary' => 'SO',
  363. 'accession' => '0000234',
  364. 'term_name' => 'mRNA',
  365. 'storage_args' => array(
  366. 'data_table' => 'feature',
  367. 'type_column' => 'type_id',
  368. ),
  369. 'category' => 'Genomic',
  370. );
  371. _tripal_chado_preapre_create_bundle($args, $job);
  372. //
  373. // Create the 'Phylogenetic tree' entity type.
  374. //
  375. $args = array(
  376. 'vocabulary' => 'data',
  377. 'accession' => '0872',
  378. 'term_name' => 'Phylogenetic tree',
  379. 'storage_args' => array(
  380. 'data_table' => 'phylotree',
  381. ),
  382. 'category' => 'Genomic',
  383. );
  384. _tripal_chado_preapre_create_bundle($args, $job);
  385. // Create the 'Physical Map' entity type.
  386. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  387. $args = array(
  388. 'vocabulary' => 'data',
  389. 'accession' => '1280',
  390. 'term_name' => 'Physical Map',
  391. 'storage_args' => array(
  392. 'data_table' => 'featuremap',
  393. 'type_linker_table' => 'featuremapprop',
  394. 'type_column' => 'type_id',
  395. 'type_id' => $cvterm->cvterm_id,
  396. 'type_value' => 'physical'
  397. ),
  398. 'category' => 'Genomic',
  399. );
  400. _tripal_chado_preapre_create_bundle($args, $job);
  401. // Create the 'DNA Library' entity type.
  402. $args = array(
  403. 'vocabulary' => 'NCIT',
  404. 'accession' => 'C16223',
  405. 'term_name' => 'DNA Library',
  406. 'storage_args' => array(
  407. 'data_table' => 'library',
  408. 'type_column' => 'type_id',
  409. ),
  410. 'category' => 'Genomic',
  411. );
  412. _tripal_chado_preapre_create_bundle($args, $job);
  413. // Create the 'Genome Assembly' entity type.
  414. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  415. $args = array(
  416. 'vocabulary' => 'operation',
  417. 'accession' => '0525',
  418. 'term_name' => 'Genome Assembly',
  419. 'storage_args' => array(
  420. 'data_table' => 'analysis',
  421. 'type_linker_table' => 'analysisprop',
  422. 'type_column' => 'type_id',
  423. 'type_id' => $cvterm->cvterm_id,
  424. 'type_value' => 'genome_assembly'
  425. ),
  426. 'category' => 'Genomic',
  427. );
  428. _tripal_chado_preapre_create_bundle($args, $job);
  429. // Create the 'Genome Annotation' entity type.
  430. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  431. $args = array(
  432. 'vocabulary' => 'operation',
  433. 'accession' => '0362',
  434. 'term_name' => 'Genome Annotation',
  435. 'storage_args' => array(
  436. 'data_table' => 'analysis',
  437. 'type_linker_table' => 'analysisprop',
  438. 'type_column' => 'type_id',
  439. 'type_id' => $cvterm->cvterm_id,
  440. 'type_value' => 'genome_annotation'
  441. ),
  442. 'category' => 'Genomic',
  443. );
  444. _tripal_chado_preapre_create_bundle($args, $job);
  445. // Create the 'Genome Annotation' entity type.
  446. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  447. $args = array(
  448. 'vocabulary' => 'local',
  449. 'accession' => 'Genome Project',
  450. 'term_name' => 'Genome Project',
  451. 'storage_args' => array(
  452. 'data_table' => 'project',
  453. 'type_linker_table' => 'projectprop',
  454. 'type_column' => 'type_id',
  455. 'type_id' => $cvterm->cvterm_id,
  456. 'type_value' => 'genome_project'
  457. ),
  458. 'category' => 'Genomic',
  459. );
  460. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  461. _tripal_chado_preapre_create_bundle($args, $job);
  462. }
  463. /**
  464. * Creates the "Expression" category of content types.
  465. */
  466. function tripal_chado_prepare_expression_types($job) {
  467. //
  468. // Create the 'biological sample' entity type.
  469. //
  470. $args = array(
  471. 'vocabulary' => 'sep',
  472. 'accession' => '00195',
  473. 'term_name' => 'biological sample',
  474. 'storage_args' => array(
  475. 'data_table' => 'biomaterial',
  476. ),
  477. 'Expression',
  478. );
  479. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  480. _tripal_chado_preapre_create_bundle($args, $job);
  481. //
  482. // Create the 'Assay' entity type.
  483. //
  484. $args = array(
  485. 'vocabulary' => 'OBI',
  486. 'accession' => '0000070',
  487. 'term_name' => 'Assay',
  488. 'storage_args' => array(
  489. 'data_table' => 'assay',
  490. ),
  491. 'Expression',
  492. );
  493. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  494. _tripal_chado_preapre_create_bundle($args, $job);
  495. //
  496. // Create the 'Array Design' entity type.
  497. //
  498. $args = array(
  499. 'vocabulary' => 'EFO',
  500. 'accession' => '0000269',
  501. 'term_name' => 'Assay Design',
  502. 'storage_args' => array(
  503. 'data_table' => 'arraydesign',
  504. ),
  505. 'Expression',
  506. );
  507. _tripal_chado_preapre_create_bundle($args, $job);
  508. }
  509. /**
  510. * Creates the "Germplasm/Breeding" category of content types.
  511. */
  512. function tripal_chado_prepare_germplasm_types($job) {
  513. //
  514. // Create the 'Phenotypic Trait' entity type.
  515. //
  516. /**
  517. * SPF: We need a bit more testing before we add this conteont type as
  518. * it resolves to the cvterm table. Currently, it can't be created.
  519. $args = array(
  520. 'vocabulary' => 'NCIT',
  521. 'accession' => 'C85496',
  522. 'term_name' => 'Phenotypic Trait',
  523. 'storage_args' => array(
  524. 'data_table' => 'cvterm',
  525. 'type_column' => 'type_id',
  526. ),
  527. 'category' => 'Germplasm/Breeding',
  528. );
  529. _tripal_chado_preapre_create_bundle($args, $job);
  530. */
  531. //
  532. // Create the 'Germplasm Accession' entity type.
  533. //
  534. $args = array(
  535. 'vocabulary' => 'CO_010',
  536. 'accession' => '0000044',
  537. 'term_name' => 'Germplasm Accession',
  538. 'storage_args' => array(
  539. 'data_table' => 'stock',
  540. 'type_column' => 'type_id',
  541. ),
  542. 'category' => 'Germplasm/Breeding',
  543. );
  544. _tripal_chado_preapre_create_bundle($args, $job);
  545. //
  546. // Create the 'Breeding Cross' entity type.
  547. //
  548. $args = array(
  549. 'vocabulary' => 'CO_010',
  550. 'accession' => '0000255',
  551. 'term_name' => 'Generated germplasm (breeding cross)',
  552. 'storage_args' => array(
  553. 'data_table' => 'stock',
  554. 'type_column' => 'type_id',
  555. ),
  556. 'category' => 'Germplasm/Breeding',
  557. );
  558. _tripal_chado_preapre_create_bundle($args, $job);
  559. //
  560. // Create the 'Germplasm Variety' entity type.
  561. //
  562. $args = array(
  563. 'vocabulary' => 'CO_010',
  564. 'accession' => '0000029',
  565. 'term_name' => 'Cultivar (germplasm variety)',
  566. 'storage_args' => array(
  567. 'data_table' => 'stock',
  568. 'type_column' => 'type_id',
  569. ),
  570. 'category' => 'Germplasm/Breeding',
  571. );
  572. _tripal_chado_preapre_create_bundle($args, $job);
  573. //
  574. // Create the 'Germplasm Variety' entity type.
  575. //
  576. $args = array(
  577. 'vocabulary' => 'CO_010',
  578. 'accession' => '0000162',
  579. 'term_name' => 'Recombinant Inbred Line',
  580. 'storage_args' => array(
  581. 'data_table' => 'stock',
  582. 'type_column' => 'type_id',
  583. ),
  584. 'category' => 'Germplasm/Breeding',
  585. );
  586. _tripal_chado_preapre_create_bundle($args, $job);
  587. }
  588. /**
  589. * Creates the "Genetic" category of content types.
  590. */
  591. function tripal_chado_prepare_genetic_types($job) {
  592. //
  593. // Create the 'Genetic Map' entity type.
  594. //
  595. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  596. $args = array(
  597. 'vocabulary' => 'data',
  598. 'accession' => '1278',
  599. 'term_name' => 'Genetic Map',
  600. 'storage_args' => array(
  601. 'data_table' => 'featuremap',
  602. 'type_linker_table' => 'featuremapprop',
  603. 'type_column' => 'type_id',
  604. 'type_id' => $cvterm->cvterm_id,
  605. 'type_value' => 'genetic'
  606. ),
  607. 'category' => 'Genetic',
  608. );
  609. _tripal_chado_preapre_create_bundle($args, $job);
  610. //
  611. // Create the 'QTL' entity type.
  612. //
  613. $args = array(
  614. 'vocabulary' => 'SO',
  615. 'accession' => '0000771',
  616. 'term_name' => 'QTL',
  617. 'storage_args' => array(
  618. 'data_table' => 'feature',
  619. 'type_column' => 'type_id',
  620. ),
  621. 'category' => 'Genetic',
  622. );
  623. _tripal_chado_preapre_create_bundle($args, $job);
  624. //
  625. // Create the 'Sequence Variant' entity type.
  626. //
  627. $args = array(
  628. 'vocabulary' => 'SO',
  629. 'accession' => '0001060',
  630. 'term_name' => 'Sequence Variant',
  631. 'storage_args' => array(
  632. 'data_table' => 'feature',
  633. 'type_column' => 'type_id',
  634. ),
  635. 'category' => 'Genetic',
  636. );
  637. _tripal_chado_preapre_create_bundle($args, $job);
  638. //
  639. // Create the 'Genetic Marker' entity type.
  640. //
  641. $args = array(
  642. 'vocabulary' => 'SO',
  643. 'accession' => '0001645',
  644. 'term_name' => 'Genetic Marker',
  645. 'storage_args' => array(
  646. 'data_table' => 'feature',
  647. 'type_column' => 'type_id',
  648. ),
  649. 'category' => 'Genetic',
  650. );
  651. _tripal_chado_preapre_create_bundle($args, $job);
  652. //
  653. // Create the 'Heritable Phenotypic Marker' entity type.
  654. //
  655. $args = array(
  656. 'vocabulary' => 'SO',
  657. 'accession' => '0001500',
  658. 'term_name' => 'Heritable Phenotypic Marker',
  659. 'storage_args' => array(
  660. 'data_table' => 'feature',
  661. 'type_column' => 'type_id',
  662. ),
  663. 'category' => 'Genetic',
  664. );
  665. _tripal_chado_preapre_create_bundle($args, $job);
  666. }
  667. /**
  668. * A helper function to consolidate the code used to create a bundle.
  669. */
  670. function _tripal_chado_preapre_create_bundle($args, $job) {
  671. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  672. if (!$bundle) {
  673. drush_print("Creating " . $args['term_name'] . "...");
  674. if (!tripal_create_bundle($args, $job)) {
  675. $msg = t('Error encountered creating !type Content Type.', ['!type' => $args['term_name']]);
  676. throw new Exception($msg);
  677. }
  678. }
  679. else {
  680. drush_print("Content type already created (skipping): " . $args['term_name'] . "...");
  681. }
  682. }
  683. /**
  684. * For Chado v1.1 Tripal provides some new custom tables.
  685. *
  686. * For Chado v1.2 or greater these tables are not needed as they are part of the
  687. * schema update.
  688. */
  689. function tripal_chado_add_v1_1_custom_tables(){
  690. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_v1_1');
  691. tripal_chado_add_analysisfeatureprop_table();
  692. }
  693. /**
  694. * For Chado v1.2 Tripal provides some new custom tables.
  695. *
  696. * For Chado v1.3 these tables are not needed as they are part of the
  697. * schema update.
  698. */
  699. function tripal_chado_add_v1_2_custom_tables(){
  700. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_v1.2');
  701. tripal_chado_add_contactprop_table();
  702. tripal_chado_add_featuremap_dbxref_table();
  703. tripal_chado_add_featuremapprop_table();
  704. tripal_chado_add_featureposprop_table();
  705. tripal_chado_add_pubauthor_contact_table();
  706. }
  707. /**
  708. * Add custom tables for any version of Chado.
  709. *
  710. * These are tables that Chado uses to manage the site (i.e. temporary
  711. * loading tables) and not for primary data storage.
  712. */
  713. function tripal_chado_add_vx_x_custom_tables(){
  714. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
  715. // Add in custom tables.
  716. tripal_chado_add_tripal_gff_temp_table();
  717. tripal_chado_add_tripal_gffcds_temp_table();
  718. tripal_chado_add_tripal_gffprotein_temp_table();
  719. tripal_chado_add_tripal_obo_temp_table();
  720. // Add in materialized views.
  721. tripal_chado_add_organism_stock_count_mview();
  722. tripal_chado_add_library_feature_count_mview();
  723. tripal_chado_add_organism_feature_count_mview();
  724. tripal_chado_add_analysis_organism_mview();
  725. tripal_chado_add_cv_root_mview_mview();
  726. tripal_chado_add_db2cv_mview_mview();
  727. }
  728. /**
  729. * Many of the custom tables created for Chado v1.2 are now in Chado v1.3.
  730. *
  731. * These tables need not be tracked by Tripal anymore as custom tables and
  732. * in some cases the Chado version has different columns so we need to
  733. * adjust them.
  734. */
  735. function tripal_chado_fix_v1_3_custom_tables() {
  736. // Update the featuremap_dbxref table by adding an is_current field.
  737. if (!chado_column_exists('featuremap_dbxref', 'is_current')) {
  738. chado_query("ALTER TABLE {featuremap_dbxref} ADD COLUMN is_current boolean DEFAULT true NOT NULL;");
  739. }
  740. // Remove the previously managed custom tables from the
  741. // tripal_custom_tables table.
  742. db_delete('tripal_custom_tables')
  743. ->condition('table_name', array('analysisfeatureprop', 'featuremap_dbxref', 'contactprop', 'featuremapprop', 'featureposprop', 'pubauthor_contact'))
  744. ->execute();
  745. }