tripal_chado.setup.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  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. 'storage_args' => [
  312. 'data_table' => 'study',
  313. ],
  314. 'category' => 'General',
  315. ];
  316. _tripal_chado_prepare_create_bundle($args, $job);
  317. //
  318. // Create the 'Contact' entity type. This uses the local:contact term.
  319. //
  320. $args = [
  321. 'vocabulary' => 'local',
  322. 'accession' => 'contact',
  323. 'term_name' => 'contact',
  324. 'storage_args' => [
  325. 'data_table' => 'contact',
  326. ],
  327. 'category' => 'General',
  328. ];
  329. _tripal_chado_prepare_create_bundle($args, $job);
  330. //
  331. // Create the 'Publication' entity type.
  332. //
  333. $args = [
  334. 'vocabulary' => 'TPUB',
  335. 'accession' => '0000002',
  336. 'term_name' => 'Publication',
  337. 'storage_args' => [
  338. 'data_table' => 'pub',
  339. ],
  340. 'category' => 'General',
  341. ];
  342. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  343. if (!$bundle) {
  344. // Import a publication so we get all of the properties before
  345. // creating the content type.
  346. chado_import_pub_by_dbxref('PMID:24163125');
  347. _tripal_chado_prepare_create_bundle($args, $job);
  348. // Now remove the publication that was added above.
  349. $values = [
  350. 'dbxref_id' => [
  351. 'accession' => '24163125',
  352. 'db_id' => [
  353. 'name' => 'PMID',
  354. ],
  355. ],
  356. ];
  357. $result = chado_select_record('pub_dbxref', ['pub_id'], $values);
  358. chado_delete_record('pub', ['pub_id' => $result[0]->pub_id]);
  359. }
  360. //
  361. // Create the 'Protocol' entity type.
  362. //
  363. $args = [
  364. 'vocabulary' => 'sep',
  365. 'accession' => '00101',
  366. 'term_name' => 'Protocol',
  367. 'storage_args' => [
  368. 'data_table' => 'protocol',
  369. ],
  370. 'category' => 'General',
  371. ];
  372. _tripal_chado_prepare_create_bundle($args, $job);
  373. }
  374. /**
  375. * Creates the "Genomic" category of content types.
  376. */
  377. function tripal_chado_prepare_genomic_types($job) {
  378. //
  379. // Create the 'Gene' entity type.
  380. //
  381. $args = [
  382. 'vocabulary' => 'SO',
  383. 'accession' => '0000704',
  384. 'term_name' => 'gene',
  385. 'storage_args' => [
  386. 'data_table' => 'feature',
  387. 'type_column' => 'type_id',
  388. ],
  389. 'category' => 'Genomic',
  390. ];
  391. _tripal_chado_prepare_create_bundle($args, $job);
  392. //
  393. // Create the 'mRNA' entity type.
  394. //
  395. $args = [
  396. 'vocabulary' => 'SO',
  397. 'accession' => '0000234',
  398. 'term_name' => 'mRNA',
  399. 'storage_args' => [
  400. 'data_table' => 'feature',
  401. 'type_column' => 'type_id',
  402. ],
  403. 'category' => 'Genomic',
  404. ];
  405. _tripal_chado_prepare_create_bundle($args, $job);
  406. //
  407. // Create the 'Phylogenetic tree' entity type.
  408. //
  409. $args = [
  410. 'vocabulary' => 'data',
  411. 'accession' => '0872',
  412. 'term_name' => 'Phylogenetic tree',
  413. 'storage_args' => [
  414. 'data_table' => 'phylotree',
  415. ],
  416. 'category' => 'Genomic',
  417. ];
  418. _tripal_chado_prepare_create_bundle($args, $job);
  419. // Create the 'Physical Map' entity type.
  420. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  421. $args = [
  422. 'vocabulary' => 'data',
  423. 'accession' => '1280',
  424. 'term_name' => 'Physical Map',
  425. 'storage_args' => [
  426. 'data_table' => 'featuremap',
  427. 'type_linker_table' => 'featuremapprop',
  428. 'type_column' => 'type_id',
  429. 'type_id' => $cvterm->cvterm_id,
  430. 'type_value' => 'physical',
  431. ],
  432. 'category' => 'Genomic',
  433. ];
  434. _tripal_chado_prepare_create_bundle($args, $job);
  435. // Create the 'DNA Library' entity type.
  436. $args = [
  437. 'vocabulary' => 'NCIT',
  438. 'accession' => 'C16223',
  439. 'term_name' => 'DNA Library',
  440. 'storage_args' => [
  441. 'data_table' => 'library',
  442. 'type_column' => 'type_id',
  443. ],
  444. 'category' => 'Genomic',
  445. ];
  446. _tripal_chado_prepare_create_bundle($args, $job);
  447. // Create the 'Genome Assembly' entity type.
  448. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  449. $args = [
  450. 'vocabulary' => 'operation',
  451. 'accession' => '0525',
  452. 'term_name' => 'Genome Assembly',
  453. 'storage_args' => [
  454. 'data_table' => 'analysis',
  455. 'type_linker_table' => 'analysisprop',
  456. 'type_column' => 'type_id',
  457. 'type_id' => $cvterm->cvterm_id,
  458. 'type_value' => 'genome_assembly',
  459. ],
  460. 'category' => 'Genomic',
  461. ];
  462. _tripal_chado_prepare_create_bundle($args, $job);
  463. // Create the 'Genome Annotation' entity type.
  464. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  465. $args = [
  466. 'vocabulary' => 'operation',
  467. 'accession' => '0362',
  468. 'term_name' => 'Genome Annotation',
  469. 'storage_args' => [
  470. 'data_table' => 'analysis',
  471. 'type_linker_table' => 'analysisprop',
  472. 'type_column' => 'type_id',
  473. 'type_id' => $cvterm->cvterm_id,
  474. 'type_value' => 'genome_annotation',
  475. ],
  476. 'category' => 'Genomic',
  477. ];
  478. _tripal_chado_prepare_create_bundle($args, $job);
  479. // Create the 'Genome Annotation' entity type.
  480. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  481. $args = [
  482. 'vocabulary' => 'local',
  483. 'accession' => 'Genome Project',
  484. 'term_name' => 'Genome Project',
  485. 'storage_args' => [
  486. 'data_table' => 'project',
  487. 'type_linker_table' => 'projectprop',
  488. 'type_column' => 'type_id',
  489. 'type_id' => $cvterm->cvterm_id,
  490. 'type_value' => 'genome_project',
  491. ],
  492. 'category' => 'Genomic',
  493. ];
  494. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  495. _tripal_chado_prepare_create_bundle($args, $job);
  496. }
  497. /**
  498. * Creates the "Expression" category of content types.
  499. */
  500. function tripal_chado_prepare_expression_types($job) {
  501. //
  502. // Create the 'biological sample' entity type.
  503. //
  504. $args = [
  505. 'vocabulary' => 'sep',
  506. 'accession' => '00195',
  507. 'term_name' => 'biological sample',
  508. 'storage_args' => [
  509. 'data_table' => 'biomaterial',
  510. ],
  511. 'Expression',
  512. ];
  513. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  514. _tripal_chado_prepare_create_bundle($args, $job);
  515. //
  516. // Create the 'Assay' entity type.
  517. //
  518. $args = [
  519. 'vocabulary' => 'OBI',
  520. 'accession' => '0000070',
  521. 'term_name' => 'Assay',
  522. 'storage_args' => [
  523. 'data_table' => 'assay',
  524. ],
  525. 'Expression',
  526. ];
  527. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  528. _tripal_chado_prepare_create_bundle($args, $job);
  529. //
  530. // Create the 'Array Design' entity type.
  531. //
  532. $args = [
  533. 'vocabulary' => 'EFO',
  534. 'accession' => '0000269',
  535. 'term_name' => 'Assay Design',
  536. 'storage_args' => [
  537. 'data_table' => 'arraydesign',
  538. ],
  539. 'Expression',
  540. ];
  541. _tripal_chado_prepare_create_bundle($args, $job);
  542. }
  543. /**
  544. * Creates the "Germplasm/Breeding" category of content types.
  545. */
  546. function tripal_chado_prepare_germplasm_types($job) {
  547. //
  548. // Create the 'Phenotypic Trait' entity type.
  549. //
  550. /**
  551. * SPF: We need a bit more testing before we add this conteont type as
  552. * it resolves to the cvterm table. Currently, it can't be created.
  553. * $args = array(
  554. * 'vocabulary' => 'NCIT',
  555. * 'accession' => 'C85496',
  556. * 'term_name' => 'Phenotypic Trait',
  557. * 'storage_args' => array(
  558. * 'data_table' => 'cvterm',
  559. * 'type_column' => 'type_id',
  560. * ),
  561. * 'category' => 'Germplasm/Breeding',
  562. * );
  563. * _tripal_chado_prepare_create_bundle($args, $job);
  564. */
  565. //
  566. // Create the 'Germplasm Accession' entity type.
  567. //
  568. $args = [
  569. 'vocabulary' => 'CO_010',
  570. 'accession' => '0000044',
  571. 'term_name' => 'Germplasm Accession',
  572. 'storage_args' => [
  573. 'data_table' => 'stock',
  574. 'type_column' => 'type_id',
  575. ],
  576. 'category' => 'Germplasm/Breeding',
  577. ];
  578. _tripal_chado_prepare_create_bundle($args, $job);
  579. //
  580. // Create the 'Breeding Cross' entity type.
  581. //
  582. $args = [
  583. 'vocabulary' => 'CO_010',
  584. 'accession' => '0000255',
  585. 'term_name' => 'Generated germplasm (breeding cross)',
  586. 'storage_args' => [
  587. 'data_table' => 'stock',
  588. 'type_column' => 'type_id',
  589. ],
  590. 'category' => 'Germplasm/Breeding',
  591. ];
  592. _tripal_chado_prepare_create_bundle($args, $job);
  593. //
  594. // Create the 'Germplasm Variety' entity type.
  595. //
  596. $args = [
  597. 'vocabulary' => 'CO_010',
  598. 'accession' => '0000029',
  599. 'term_name' => 'Cultivar (germplasm variety)',
  600. 'storage_args' => [
  601. 'data_table' => 'stock',
  602. 'type_column' => 'type_id',
  603. ],
  604. 'category' => 'Germplasm/Breeding',
  605. ];
  606. _tripal_chado_prepare_create_bundle($args, $job);
  607. //
  608. // Create the 'Germplasm Variety' entity type.
  609. //
  610. $args = [
  611. 'vocabulary' => 'CO_010',
  612. 'accession' => '0000162',
  613. 'term_name' => 'Recombinant Inbred Line',
  614. 'storage_args' => [
  615. 'data_table' => 'stock',
  616. 'type_column' => 'type_id',
  617. ],
  618. 'category' => 'Germplasm/Breeding',
  619. ];
  620. _tripal_chado_prepare_create_bundle($args, $job);
  621. }
  622. /**
  623. * Creates the "Genetic" category of content types.
  624. */
  625. function tripal_chado_prepare_genetic_types($job) {
  626. //
  627. // Create the 'Genetic Map' entity type.
  628. //
  629. $cvterm = tripal_get_cvterm(['id' => 'rdfs:type']);
  630. $args = [
  631. 'vocabulary' => 'data',
  632. 'accession' => '1278',
  633. 'term_name' => 'Genetic Map',
  634. 'storage_args' => [
  635. 'data_table' => 'featuremap',
  636. 'type_linker_table' => 'featuremapprop',
  637. 'type_column' => 'type_id',
  638. 'type_id' => $cvterm->cvterm_id,
  639. 'type_value' => 'genetic',
  640. ],
  641. 'category' => 'Genetic',
  642. ];
  643. _tripal_chado_prepare_create_bundle($args, $job);
  644. //
  645. // Create the 'QTL' entity type.
  646. //
  647. $args = [
  648. 'vocabulary' => 'SO',
  649. 'accession' => '0000771',
  650. 'term_name' => 'QTL',
  651. 'storage_args' => [
  652. 'data_table' => 'feature',
  653. 'type_column' => 'type_id',
  654. ],
  655. 'category' => 'Genetic',
  656. ];
  657. _tripal_chado_prepare_create_bundle($args, $job);
  658. //
  659. // Create the 'Sequence Variant' entity type.
  660. //
  661. $args = [
  662. 'vocabulary' => 'SO',
  663. 'accession' => '0001060',
  664. 'term_name' => 'Sequence Variant',
  665. 'storage_args' => [
  666. 'data_table' => 'feature',
  667. 'type_column' => 'type_id',
  668. ],
  669. 'category' => 'Genetic',
  670. ];
  671. _tripal_chado_prepare_create_bundle($args, $job);
  672. //
  673. // Create the 'Genetic Marker' entity type.
  674. //
  675. $args = [
  676. 'vocabulary' => 'SO',
  677. 'accession' => '0001645',
  678. 'term_name' => 'Genetic Marker',
  679. 'storage_args' => [
  680. 'data_table' => 'feature',
  681. 'type_column' => 'type_id',
  682. ],
  683. 'category' => 'Genetic',
  684. ];
  685. _tripal_chado_prepare_create_bundle($args, $job);
  686. //
  687. // Create the 'Heritable Phenotypic Marker' entity type.
  688. //
  689. $args = [
  690. 'vocabulary' => 'SO',
  691. 'accession' => '0001500',
  692. 'term_name' => 'Heritable Phenotypic Marker',
  693. 'storage_args' => [
  694. 'data_table' => 'feature',
  695. 'type_column' => 'type_id',
  696. ],
  697. 'category' => 'Genetic',
  698. ];
  699. _tripal_chado_prepare_create_bundle($args, $job);
  700. }
  701. /**
  702. * A helper function to consolidate the code used to create a bundle.
  703. */
  704. function _tripal_chado_prepare_create_bundle($args, $job) {
  705. $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
  706. if (!$bundle) {
  707. drush_print("Creating " . $args['term_name'] . "...");
  708. if (!tripal_create_bundle($args, $job)) {
  709. $msg = t('Error encountered creating !type Content Type.', ['!type' => $args['term_name']]);
  710. throw new Exception($msg);
  711. }
  712. }
  713. else {
  714. // Update the bundle category in case it was set incorrectly.
  715. $category = array_key_exists('category', $args) ? $args['category'] : 'Other';
  716. tripal_set_bundle_variable('bundle_category', $bundle->id, $category);
  717. drush_print("Content type already created (skipping): " . $args['term_name'] . "...");
  718. }
  719. }
  720. /**
  721. * For Chado v1.1 Tripal provides some new custom tables.
  722. *
  723. * For Chado v1.2 or greater these tables are not needed as they are part of the
  724. * schema update.
  725. */
  726. function tripal_chado_add_v1_1_custom_tables() {
  727. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_v1_1');
  728. tripal_chado_add_analysisfeatureprop_table();
  729. }
  730. /**
  731. * For Chado v1.2 Tripal provides some new custom tables.
  732. *
  733. * For Chado v1.3 these tables are not needed as they are part of the
  734. * schema update.
  735. */
  736. function tripal_chado_add_v1_2_custom_tables() {
  737. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_v1.2');
  738. tripal_chado_add_contactprop_table();
  739. tripal_chado_add_featuremap_dbxref_table();
  740. tripal_chado_add_featuremapprop_table();
  741. tripal_chado_add_featureposprop_table();
  742. tripal_chado_add_pubauthor_contact_table();
  743. }
  744. /**
  745. * Add custom tables for any version of Chado.
  746. *
  747. * These are tables that Chado uses to manage the site (i.e. temporary
  748. * loading tables) and not for primary data storage.
  749. */
  750. function tripal_chado_add_vx_x_custom_tables() {
  751. module_load_include('inc', 'tripal_chado', 'includes/setup/tripal_chado.chado_vx_x');
  752. // Add in custom tables.
  753. tripal_chado_add_tripal_gff_temp_table();
  754. tripal_chado_add_tripal_gffcds_temp_table();
  755. tripal_chado_add_tripal_gffprotein_temp_table();
  756. tripal_chado_add_tripal_obo_temp_table();
  757. // Add in materialized views.
  758. tripal_chado_add_organism_stock_count_mview();
  759. tripal_chado_add_library_feature_count_mview();
  760. tripal_chado_add_organism_feature_count_mview();
  761. tripal_chado_add_analysis_organism_mview();
  762. tripal_chado_add_cv_root_mview_mview();
  763. tripal_chado_add_db2cv_mview_mview();
  764. }
  765. /**
  766. * Many of the custom tables created for Chado v1.2 are now in Chado v1.3.
  767. *
  768. * These tables need not be tracked by Tripal anymore as custom tables and
  769. * in some cases the Chado version has different columns so we need to
  770. * adjust them.
  771. */
  772. function tripal_chado_fix_v1_3_custom_tables() {
  773. // Update the featuremap_dbxref table by adding an is_current field.
  774. if (!chado_column_exists('featuremap_dbxref', 'is_current')) {
  775. chado_query("ALTER TABLE {featuremap_dbxref} ADD COLUMN is_current boolean DEFAULT true NOT NULL;");
  776. }
  777. // Remove the previously managed custom tables from the
  778. // tripal_custom_tables table.
  779. db_delete('tripal_custom_tables')
  780. ->condition('table_name', [
  781. 'analysisfeatureprop',
  782. 'featuremap_dbxref',
  783. 'contactprop',
  784. 'featuremapprop',
  785. 'featureposprop',
  786. 'pubauthor_contact',
  787. ])
  788. ->execute();
  789. }