tripal_chado.setup.inc 25 KB

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