tripal_chado.install 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  1. <?php
  2. function tripal_chado_install() {
  3. // The foreign key specification doesn't really add one to the
  4. // Drupal schema, it is just used internally, but we want one.
  5. db_query('
  6. ALTER TABLE {tripal_custom_tables}
  7. ADD CONSTRAINT tripal_custom_tables_fk1
  8. FOREIGN KEY (mview_id) REFERENCES {tripal_mviews} (mview_id)
  9. ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
  10. ');
  11. /////////////////////////////////////////////////////////////////////////////
  12. // Chado CV Module
  13. /////////////////////////////////////////////////////////////////////////////
  14. // Add the cv_root_mview.
  15. tripal_cv_add_cv_root_mview();
  16. // Add defaults to the tables that correlate OBO files/references with
  17. // a chado CV.
  18. tripal_cv_add_obo_defaults();
  19. // Add the Chado ontology CV.
  20. $obo_path = '{tripal_chado}/files/cv_property.obo';
  21. $obo_id = tripal_insert_obo('Chado CV Properties', $obo_path);
  22. tripal_submit_obo_job(array('obo_id' => $obo_id));
  23. // Create the temp table we will use for loading OBO files.
  24. tripal_cv_create_tripal_obo_temp();
  25. /////////////////////////////////////////////////////////////////////////////
  26. // Chado Organism Module
  27. /////////////////////////////////////////////////////////////////////////////
  28. tripal_insert_cv(
  29. 'organism_property',
  30. 'Contains properties for organisms'
  31. );
  32. // set the default vocabularies
  33. tripal_set_default_cv('organismprop', 'type_id', 'organism_property');
  34. /////////////////////////////////////////////////////////////////////////////
  35. // Chado CompAnalysis Module
  36. /////////////////////////////////////////////////////////////////////////////
  37. // we may need the analysisfeatureprop table if it doesn't already exist
  38. tripal_analysis_create_analysisfeatureprop();
  39. // add cvterms
  40. tripal_analysis_add_cvterms();
  41. // add materialized views
  42. tripal_analysis_add_mview_analysis_organism();
  43. // set the default vocabularies
  44. tripal_set_default_cv('analysisprop', 'type_id', 'analysis_property');
  45. /////////////////////////////////////////////////////////////////////////////
  46. // Chado Contact Module
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Add the contactprop table to Chado.
  49. tripal_contact_add_custom_tables();
  50. // Add loading of the the tripal contact ontology to the job queue.
  51. $obo_path = '{tripal_chado}/files/tcontact.obo';
  52. $obo_id = tripal_insert_obo('Tripal Contacts', $obo_path);
  53. tripal_submit_obo_job(array('obo_id' => $obo_id));
  54. // Add cvterms for relationship types.
  55. tripal_contact_add_cvs();
  56. // Set the default vocabularies.
  57. tripal_set_default_cv('contact', 'type_id', 'tripal_contact');
  58. tripal_set_default_cv('contactprop', 'type_id', 'tripal_contact');
  59. tripal_set_default_cv('contact_relationship', 'type_id', 'contact_relationship');
  60. /////////////////////////////////////////////////////////////////////////////
  61. // Chado Feature Module
  62. /////////////////////////////////////////////////////////////////////////////
  63. // Note: the feature_property OBO that came with Chado v1.2 should not
  64. // be automatically installed. Some of the terms are duplicates of
  65. // others in better maintained vocabularies. New Tripal sites should
  66. // use those.
  67. // $obo_path = '{tripal_feature}/files/feature_property.obo';
  68. // $obo_id = tripal_insert_obo('Chado Feature Properties', $obo_path);
  69. // tripal_submit_obo_job(array('obo_id' => $obo_id));
  70. // Add the materialized view.
  71. tripal_feature_add_organism_count_mview();
  72. // Add the custom tables.
  73. tripal_feature_add_tripal_gff_temp_table();
  74. tripal_feature_add_tripal_gffcds_temp_table();
  75. tripal_feature_add_tripal_gffprotein_temp_table();
  76. // Add the vocabularies used by the feature module.
  77. tripal_feature_add_cvs();
  78. // Set the default vocabularies.
  79. tripal_set_default_cv('feature', 'type_id', 'sequence');
  80. tripal_set_default_cv('featureprop', 'type_id', 'feature_property');
  81. tripal_set_default_cv('feature_relationship', 'type_id', 'feature_relationship');
  82. /////////////////////////////////////////////////////////////////////////////
  83. // Chado Map Module
  84. /////////////////////////////////////////////////////////////////////////////
  85. // add the featuremapprop table to Chado
  86. tripal_featuremap_add_custom_tables();
  87. // Add cvterms
  88. tripal_featuremap_add_cvs();
  89. tripal_featuremap_add_cvterms();
  90. // set the default vocabularies
  91. tripal_set_default_cv('featuremapprop', 'type_id', 'featuremap_property');
  92. tripal_set_default_cv('featureposprop', 'type_id', 'featurepos_property');
  93. tripal_set_default_cv('featuremap', 'unittype_id', 'featuremap_units');
  94. /////////////////////////////////////////////////////////////////////////////
  95. // Chado Library Module
  96. /////////////////////////////////////////////////////////////////////////////
  97. // add the materialized view
  98. tripal_library_add_mview_library_feature_count();
  99. // add cvterms
  100. tripal_library_add_cvs();
  101. tripal_library_add_cvterms();
  102. // set the default vocabularies
  103. tripal_set_default_cv('libraryprop', 'type_id', 'library_property');
  104. tripal_set_default_cv('library', 'type_id', 'library_type');
  105. /////////////////////////////////////////////////////////////////////////////
  106. // Chado NatDiv Module
  107. /////////////////////////////////////////////////////////////////////////////
  108. // add cvterms
  109. tripal_natural_diversity_add_cvterms();
  110. /////////////////////////////////////////////////////////////////////////////
  111. // Chado Project Module
  112. /////////////////////////////////////////////////////////////////////////////
  113. tripal_project_add_cvs();
  114. tripal_project_add_cvterms();
  115. // set the default vocabularies
  116. tripal_set_default_cv('projectprop', 'type_id', 'project_property');
  117. tripal_set_default_cv('project_relationship', 'type_id', 'project_relationship');
  118. /////////////////////////////////////////////////////////////////////////////
  119. // Chado Pub Module
  120. /////////////////////////////////////////////////////////////////////////////
  121. global $base_path;
  122. // add loading of the the tripal pub ontology to the job queue
  123. $obo_path = '{tripal}/files/tpub.obo';
  124. $obo_id = tripal_insert_obo('Tripal Publication', $obo_path);
  125. tripal_submit_obo_job(array('obo_id' => $obo_id));
  126. tripal_pub_add_cvs();
  127. // add the custom tables
  128. tripal_pub_add_custom_tables();
  129. // set the default vocabularies
  130. tripal_set_default_cv('pub', 'type_id', 'tripal_pub');
  131. tripal_set_default_cv('pubprop', 'type_id', 'tripal_pub');
  132. tripal_set_default_cv('pub_relationship', 'type_id', 'pub_relationship');
  133. /////////////////////////////////////////////////////////////////////////////
  134. // Chado Stock Module
  135. /////////////////////////////////////////////////////////////////////////////
  136. // add some controlled vocabularies
  137. tripal_stock_add_cvs();
  138. // set the default vocabularies
  139. tripal_set_default_cv('stock', 'type_id', 'stock_type');
  140. tripal_set_default_cv('stockprop', 'type_id', 'stock_property');
  141. tripal_set_default_cv('stock_relationship', 'type_id', 'stock_relationship');
  142. // add the materialized view
  143. tripal_stock_add_organism_count_mview();
  144. /////////////////////////////////////////////////////////////////////////////
  145. // Entity Bundles
  146. /////////////////////////////////////////////////////////////////////////////
  147. // Unfortunately, some Chado base tables do not have a type_id, so we must
  148. // take special action for those tables. These include: organism and
  149. // analysis. Until we can find an appropriate controlled vocabulary
  150. // that is well supported by the community with types for these tables we
  151. // will have to use in-house terms.
  152. // Add a term to be used for an inherent 'type_id' for the organism table.
  153. tripal_insert_cvterm(array(
  154. 'id' => 'local:organism',
  155. 'name' => 'organism',
  156. 'definition' => 'An individual form of life, such as a bacterium, protist, ' .
  157. 'fungus, plant, or animal, composed of a single cell or a complex of cells ' .
  158. 'in which organelles or organs work together to carry out the various ' .
  159. 'processes of life. (American Heritage® Dictionary of the English ' .
  160. 'Language, Fifth Edition. Copyright © 2011 by Houghton Mifflin ' .
  161. 'Harcourt Publishing Company).',
  162. 'cv_name' => 'local',
  163. ));
  164. // Add a term to be used for an inherent 'type_id' for the organism table.
  165. tripal_insert_cvterm(array(
  166. 'id' => 'local:analysis',
  167. 'name' => 'analysis',
  168. 'definition' => 'A process as a method of studying the nature of something ' .
  169. 'or of determining its essential features and their relations. ' .
  170. '(Random House Kernerman Webster\'s College Dictionary, © 2010 K ' .
  171. 'Dictionaries Ltd).',
  172. 'cv_name' => 'local',
  173. ));
  174. tripal_insert_cvterm(array(
  175. 'id' => 'local:project',
  176. 'name' => 'project',
  177. 'definition' => 'A plan or proposal for accomplishing something. ' .
  178. '(American Heritage® Dictionary of the English Language, Fifth Edition. ' .
  179. 'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
  180. 'cv_name' => 'local',
  181. ));
  182. // For the TripalBundle entities we will want to associate the cvterm_id,
  183. // and the chado table and field that it maps to. We will use a few
  184. // variables to do this:
  185. tripal_insert_variable('chado_cvterm_id', 'The cvterm_id that a TripalBundle maps to.');
  186. tripal_insert_variable('chado_table', 'The name of the table to which a TripalBundle maps.');
  187. tripal_insert_variable('chado_column', 'The name of the column within the table that a TripalBundle maps to.');
  188. // We want to provide a set of commonly used entity types by default. This
  189. // way when a user first installs Tripal there are some commonly used
  190. // formats.
  191. module_load_include('inc', 'tripal', 'api/tripal.api');
  192. module_load_include('inc', 'tripal', 'includes/tripal.admin');
  193. // Create the 'Organism' entity type. This uses the local:organism term.
  194. $error = '';
  195. $term = array('name' => 'organism', 'cv_id' => array('name' => 'local'));
  196. $cvterm = chado_generate_var('cvterm', $term);
  197. if (!tripal_create_bundle('local', 'organism', 'organism', $error)) {
  198. throw new Exception($error);
  199. }
  200. // Create the 'Analysis' entity type. This uses the local:analysis term.
  201. $error = '';
  202. $term = array('name' => 'analysis', 'cv_id' => array('name' => 'local'));
  203. $cvterm = chado_generate_var('cvterm', $term);
  204. if (!tripal_create_bundle('local', 'analysis', 'analysis', $error)) {
  205. throw new Exception($error);
  206. }
  207. // Create the 'Project' entity type. This uses the local:project term.
  208. $error = '';
  209. $term = array('name' => 'project', 'cv_id' => array('name' => 'local'));
  210. $cvterm = chado_generate_var('cvterm', $term);
  211. if (!tripal_create_bundle('local', 'project', 'project', $error)) {
  212. throw new Exception($error);
  213. }
  214. }
  215. /**
  216. * Creates a materialized view that stores the type & number of stocks per organism
  217. *
  218. * @ingroup tripal_stock
  219. */
  220. function tripal_stock_add_organism_count_mview() {
  221. $view_name = 'organism_stock_count';
  222. $comment = 'Stores the type and number of stocks per organism';
  223. $schema = array(
  224. 'description' => $comment,
  225. 'table' => $view_name,
  226. 'fields' => array(
  227. 'organism_id' => array(
  228. 'type' => 'int',
  229. 'not null' => TRUE,
  230. ),
  231. 'genus' => array(
  232. 'type' => 'varchar',
  233. 'length' => '255',
  234. 'not null' => TRUE,
  235. ),
  236. 'species' => array(
  237. 'type' => 'varchar',
  238. 'length' => '255',
  239. 'not null' => TRUE,
  240. ),
  241. 'common_name' => array(
  242. 'type' => 'varchar',
  243. 'length' => '255',
  244. 'not null' => FALSE,
  245. ),
  246. 'num_stocks' => array(
  247. 'type' => 'int',
  248. 'not null' => TRUE,
  249. ),
  250. 'cvterm_id' => array(
  251. 'type' => 'int',
  252. 'not null' => TRUE,
  253. ),
  254. 'stock_type' => array(
  255. 'type' => 'varchar',
  256. 'length' => '255',
  257. 'not null' => TRUE,
  258. ),
  259. ),
  260. 'indexes' => array(
  261. 'organism_stock_count_idx1' => array('organism_id'),
  262. 'organism_stock_count_idx2' => array('cvterm_id'),
  263. 'organism_stock_count_idx3' => array('stock_type'),
  264. ),
  265. );
  266. $sql = "
  267. SELECT
  268. O.organism_id, O.genus, O.species, O.common_name,
  269. count(S.stock_id) as num_stocks,
  270. CVT.cvterm_id, CVT.name as stock_type
  271. FROM organism O
  272. INNER JOIN stock S ON O.Organism_id = S.organism_id
  273. INNER JOIN cvterm CVT ON S.type_id = CVT.cvterm_id
  274. GROUP BY
  275. O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
  276. ";
  277. tripal_add_mview($view_name, 'tripal_stock', $schema, $sql, $comment);
  278. }
  279. /**
  280. * Add cvs related to publications
  281. *
  282. * @ingroup tripal_pub
  283. */
  284. function tripal_stock_add_cvs() {
  285. // Add cv for relationship types
  286. tripal_insert_cv(
  287. 'stock_relationship',
  288. 'Contains types of relationships between stocks.'
  289. );
  290. tripal_insert_cv(
  291. 'stock_property',
  292. 'Contains properties for stocks.'
  293. );
  294. tripal_insert_cv(
  295. 'stock_type',
  296. 'Contains a list of types for stocks.'
  297. );
  298. }
  299. /**
  300. * Implementation of hook_schema().
  301. *
  302. * @ingroup tripal_pub
  303. */
  304. function tripal_chado_tripal_pub_import_schema() {
  305. return array(
  306. 'fields' => array(
  307. 'pub_import_id' => array(
  308. 'type' => 'serial',
  309. 'not null' => TRUE
  310. ),
  311. 'name' => array(
  312. 'type' => 'varchar',
  313. 'length' => 255,
  314. 'not null' => TRUE
  315. ),
  316. 'criteria' => array(
  317. 'type' => 'text',
  318. 'size' => 'normal',
  319. 'not null' => TRUE,
  320. 'description' => 'Contains a serialized PHP array containing the search criteria'
  321. ),
  322. 'disabled' => array(
  323. 'type' => 'int',
  324. 'unsigned' => TRUE,
  325. 'not NULL' => TRUE,
  326. 'default' => 0
  327. ),
  328. 'do_contact' => array(
  329. 'type' => 'int',
  330. 'unsigned' => TRUE,
  331. 'not NULL' => TRUE,
  332. 'default' => 0
  333. ),
  334. ),
  335. 'primary key' => array('pub_import_id'),
  336. 'indexes' => array(
  337. 'name' => array('name')
  338. ),
  339. );
  340. }
  341. /**
  342. * Add custom table related to publications
  343. * - pubauthor_contact
  344. *
  345. * @ingroup tripal_pub
  346. */
  347. function tripal_pub_add_custom_tables() {
  348. $schema = array (
  349. 'table' => 'pubauthor_contact',
  350. 'fields' => array (
  351. 'pubauthor_contact_id' => array (
  352. 'type' => 'serial',
  353. 'not null' => true,
  354. ),
  355. 'contact_id' => array (
  356. 'type' => 'int',
  357. 'not null' => true,
  358. ),
  359. 'pubauthor_id' => array (
  360. 'type' => 'int',
  361. 'not null' => true,
  362. ),
  363. ),
  364. 'primary key' => array (
  365. 0 => 'pubauthor_contact_id',
  366. ),
  367. 'unique keys' => array (
  368. 'pubauthor_contact_c1' => array (
  369. 0 => 'contact_id',
  370. 1 => 'pubauthor_id',
  371. ),
  372. ),
  373. 'foreign keys' => array (
  374. 'contact' => array (
  375. 'table' => 'contact',
  376. 'columns' => array (
  377. 'contact_id' => 'contact_id',
  378. ),
  379. ),
  380. 'pubauthor' => array (
  381. 'table' => 'pubauthor',
  382. 'columns' => array (
  383. 'pubauthor_id' => 'pubauthor_id',
  384. ),
  385. ),
  386. ),
  387. );
  388. chado_create_custom_table('pubauthor_contact', $schema, TRUE);
  389. }
  390. /**
  391. * Add cvs related to publications
  392. *
  393. * @ingroup tripal_pub
  394. */
  395. function tripal_pub_add_cvs() {
  396. // Add the cv for pub properties
  397. tripal_insert_cv(
  398. 'tripal_pub',
  399. 'A heirarchical set of terms for describing a publication. It is intended to be used as the default vocabularies in Tripal for publication types and contact properties.'
  400. );
  401. // Add the cv for pub types
  402. tripal_insert_cv(
  403. 'pub_type',
  404. 'Contains types of publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
  405. );
  406. // Add the cv for pub properties
  407. tripal_insert_cv(
  408. 'pub_property',
  409. 'Contains properties for publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
  410. );
  411. // Add cv for relationship types
  412. tripal_insert_cv(
  413. 'pub_relationship',
  414. 'Contains types of relationships between publications.'
  415. );
  416. }
  417. /**
  418. * Add cvs pertaining to projects
  419. *
  420. * @ingroup tripal_project
  421. */
  422. function tripal_project_add_cvs() {
  423. // Add the cv for project properties
  424. tripal_insert_cv(
  425. 'project_property',
  426. 'Contains properties for projects'
  427. );
  428. // Add cv for relationship types
  429. tripal_insert_cv(
  430. 'project_relationship',
  431. 'Contains Types of relationships between projects.'
  432. );
  433. }
  434. /**
  435. * Add cvterms pertaining to projects
  436. *
  437. * @ingroup tripal_project
  438. */
  439. function tripal_project_add_cvterms() {
  440. // Insert cvterm 'Project Description' into cvterm table of chado
  441. // database. This CV term is used to keep track of the project
  442. // description in the projectprop table.
  443. tripal_insert_cvterm(
  444. array(
  445. 'name' => 'Project Description',
  446. 'definition' => 'Description of a project',
  447. 'cv_name' => 'project_property',
  448. 'is_relationship' => 0,
  449. 'db_name' => 'tripal'
  450. ),
  451. array('update_existing' => TRUE)
  452. );
  453. }
  454. /**
  455. * Add cvterms related to natural diversity
  456. *
  457. * @ingroup tripal_natural_diversity
  458. */
  459. function tripal_natural_diversity_add_cvterms(){
  460. // add cvterms for the nd_experiment_types
  461. tripal_insert_cvterm(
  462. array(
  463. 'name' => 'Genotyping',
  464. 'definition' => 'An experiment where genotypes of individuals are identified.',
  465. 'cv_name' => 'nd_experiment_types',
  466. 'is_relationship' => 0,
  467. 'db_name' => 'tripal'
  468. ),
  469. array('update_existing' => TRUE)
  470. );
  471. tripal_insert_cvterm(
  472. array(
  473. 'name' => 'Phenotyping',
  474. 'definition' => 'An experiment where phenotypes of individuals are identified.',
  475. 'cv_name' => 'nd_experiment_types',
  476. 'is_relationship' => 0,
  477. 'db_name' => 'tripal'
  478. ),
  479. array('update_existing' => TRUE)
  480. );
  481. tripal_insert_cvterm(
  482. array(
  483. 'name' => 'Location',
  484. 'definition' => 'The name of the location.',
  485. 'cv_name' => 'nd_geolocation_property',
  486. 'is_relationship' => 0,
  487. 'db_name' => 'tripal'
  488. ),
  489. array('update_existing' => TRUE)
  490. );
  491. }
  492. /**
  493. * Adds a materialized view keeping track of the type of features associated with each library
  494. *
  495. * @ingroup tripal_library
  496. */
  497. function tripal_library_add_mview_library_feature_count(){
  498. $view_name = 'library_feature_count';
  499. $comment = 'Provides count of feature by type that are associated with all libraries';
  500. $schema = array(
  501. 'table' => $view_name,
  502. 'description' => $comment,
  503. 'fields' => array(
  504. 'library_id' => array(
  505. 'type' => 'int',
  506. 'not null' => TRUE,
  507. ),
  508. 'name' => array(
  509. 'type' => 'varchar',
  510. 'length' => 255,
  511. 'not null' => TRUE,
  512. ),
  513. 'num_features' => array(
  514. 'type' => 'int',
  515. 'not null' => TRUE,
  516. ),
  517. 'feature_type' => array(
  518. 'type' => 'varchar',
  519. 'length' => 255,
  520. 'not null' => TRUE,
  521. ),
  522. ),
  523. 'indexes' => array(
  524. 'library_feature_count_idx1' => array('library_id'),
  525. ),
  526. );
  527. $sql = "
  528. SELECT
  529. L.library_id, L.name,
  530. count(F.feature_id) as num_features,
  531. CVT.name as feature_type
  532. FROM library L
  533. INNER JOIN library_feature LF ON LF.library_id = L.library_id
  534. INNER JOIN feature F ON LF.feature_id = F.feature_id
  535. INNER JOIN cvterm CVT ON F.type_id = CVT.cvterm_id
  536. GROUP BY L.library_id, L.name, CVT.name
  537. ";
  538. tripal_add_mview($view_name, 'tripal_library', $schema, $sql, $comment);
  539. }
  540. /**
  541. * Adds cvterms needed for the library module
  542. *
  543. * @ingroup tripal_library
  544. */
  545. function tripal_library_add_cvterms() {
  546. // Insert cvterm 'library_description' into cvterm table of chado
  547. // database. This CV term is used to keep track of the library
  548. // description in the libraryprop table.
  549. tripal_insert_cvterm(
  550. array(
  551. 'name' => 'Library Description',
  552. 'definition' => 'Description of a library',
  553. 'cv_name' => 'library_property',
  554. 'is_relationship' => 0,
  555. 'db_name' => 'tripal'
  556. ),
  557. array('update_existing' => TRUE)
  558. );
  559. // add cvterms for the map unit types
  560. tripal_insert_cvterm(
  561. array(
  562. 'name' => 'cdna_library',
  563. 'definition' => 'cDNA library',
  564. 'cv_name' => 'library_type',
  565. 'is_relationship' => 0,
  566. 'db_name' => 'tripal'
  567. ),
  568. array('update_existing' => TRUE)
  569. );
  570. tripal_insert_cvterm(
  571. array(
  572. 'name' => 'bac_library',
  573. 'definition' => 'Bacterial Artifical Chromsome (BAC) library',
  574. 'cv_name' => 'library_type',
  575. 'is_relationship' => 0,
  576. 'db_name' => 'tripal'
  577. ),
  578. array('update_existing' => TRUE)
  579. );
  580. tripal_insert_cvterm(
  581. array(
  582. 'name' => 'fosmid_library',
  583. 'definition' => 'Fosmid library',
  584. 'cv_name' => 'library_type',
  585. 'is_relationship' => 0,
  586. 'db_name' => 'tripal'
  587. ),
  588. array('update_existing' => TRUE)
  589. );
  590. tripal_insert_cvterm(
  591. array(
  592. 'name' => 'cosmid_library',
  593. 'definition' => 'Cosmid library',
  594. 'cv_name' => 'library_type',
  595. 'is_relationship' => 0,
  596. 'db_name' => 'tripal'
  597. ),
  598. array('update_existing' => TRUE)
  599. );
  600. tripal_insert_cvterm(
  601. array(
  602. 'name' => 'yac_library',
  603. 'definition' => 'Yeast Artificial Chromosome (YAC) library',
  604. 'cv_name' => 'library_type',
  605. 'is_relationship' => 0,
  606. 'db_name' => 'tripal'
  607. ),
  608. array('update_existing' => TRUE)
  609. );
  610. tripal_insert_cvterm(
  611. array(
  612. 'name' => 'genomic_library',
  613. 'definition' => 'Genomic Library',
  614. 'cv_name' => 'library_type',
  615. 'is_relationship' => 0,
  616. 'db_name' => 'tripal'
  617. ),
  618. array('update_existing' => TRUE)
  619. );
  620. }
  621. /**
  622. * Adds new CV's used by this module
  623. *
  624. * @ingroup tripal_library
  625. */
  626. function tripal_library_add_cvs(){
  627. tripal_insert_cv(
  628. 'library_property',
  629. 'Contains properties for libraries.'
  630. );
  631. tripal_insert_cv(
  632. 'library_type',
  633. 'Contains terms for types of libraries (e.g. BAC, cDNA, FOSMID, etc).'
  634. );
  635. }
  636. /**
  637. * Add custom tables needed by the feature map module
  638. * - featuremapprop
  639. * - featuremap_dbxref
  640. * - featureposprop
  641. *
  642. * @ingroup tripal_featuremap
  643. */
  644. function tripal_featuremap_add_custom_tables(){
  645. // add the featuremaprop table to Chado
  646. $schema = array (
  647. 'table' => 'featuremapprop',
  648. 'fields' => array (
  649. 'featuremapprop_id' => array (
  650. 'type' => 'serial',
  651. 'not null' => true,
  652. ),
  653. 'featuremap_id' => array (
  654. 'type' => 'int',
  655. 'not null' => true,
  656. ),
  657. 'type_id' => array (
  658. 'type' => 'int',
  659. 'not null' => true,
  660. ),
  661. 'value' => array (
  662. 'type' => 'text',
  663. 'not null' => false,
  664. ),
  665. 'rank' => array (
  666. 'type' => 'int',
  667. 'not null' => true,
  668. 'default' => 0,
  669. ),
  670. ),
  671. 'primary key' => array (
  672. 0 => 'featuremapprop_id',
  673. ),
  674. 'unique keys' => array (
  675. 'featuremapprop_c1' => array (
  676. 0 => 'featuremap_id',
  677. 1 => 'type_id',
  678. 2 => 'rank',
  679. ),
  680. ),
  681. 'indexes' => array (
  682. 'featuremapprop_idx1' => array (
  683. 0 => 'featuremap_id',
  684. ),
  685. 'featuremapprop_idx2' => array (
  686. 0 => 'type_id',
  687. ),
  688. ),
  689. 'foreign keys' => array (
  690. 'cvterm' => array (
  691. 'table' => 'cvterm',
  692. 'columns' => array (
  693. 'type_id' => 'cvterm_id',
  694. ),
  695. ),
  696. 'featuremap' => array (
  697. 'table' => 'featuremap',
  698. 'columns' => array (
  699. 'featuremap_id' => 'featuremap_id',
  700. ),
  701. ),
  702. ),
  703. );
  704. chado_create_custom_table('featuremapprop', $schema, TRUE);
  705. // add the featuremap_dbxref table to Chado
  706. $schema = array (
  707. 'table' => 'featuremap_dbxref',
  708. 'fields' => array (
  709. 'featuremap_dbxref_id' => array (
  710. 'type' => 'serial',
  711. 'not null' => true,
  712. ),
  713. 'featuremap_id' => array (
  714. 'type' => 'int',
  715. 'not null' => true,
  716. ),
  717. 'dbxref_id' => array (
  718. 'type' => 'int',
  719. 'not null' => true,
  720. ),
  721. ),
  722. 'primary key' => array (
  723. 0 => 'featuremap_dbxref_id',
  724. ),
  725. 'unique keys' => array (
  726. 'featuremap_dbxref_c1' => array (
  727. 0 => 'featuremap_id',
  728. 1 => 'dbxref_id',
  729. ),
  730. ),
  731. 'indexes' => array (
  732. 'featuremap_dbxref_idx1' => array (
  733. 0 => 'featuremap_dbxref_id',
  734. ),
  735. 'featuremap_dbxref_idx2' => array (
  736. 0 => 'dbxref_id',
  737. ),
  738. ),
  739. 'foreign keys' => array (
  740. 'dbxref' => array (
  741. 'table' => 'dbxref',
  742. 'columns' => array (
  743. 'dbxref_id' => 'dbxref_id',
  744. ),
  745. ),
  746. 'featuremap' => array (
  747. 'table' => 'featuremap',
  748. 'columns' => array (
  749. 'featuremap_id' => 'featuremap_id',
  750. ),
  751. ),
  752. ),
  753. 'referring_tables' => NULL,
  754. );
  755. chado_create_custom_table('featuremap_dbxref', $schema, TRUE);
  756. $schema = array (
  757. 'table' => 'featureposprop',
  758. 'fields' => array (
  759. 'featureposprop_id' => array (
  760. 'type' => 'serial',
  761. 'not null' => true,
  762. ),
  763. 'featurepos_id' => array (
  764. 'type' => 'int',
  765. 'not null' => true,
  766. ),
  767. 'type_id' => array (
  768. 'type' => 'int',
  769. 'not null' => true,
  770. ),
  771. 'value' => array (
  772. 'type' => 'text',
  773. 'not null' => false,
  774. ),
  775. 'rank' => array (
  776. 'type' => 'int',
  777. 'not null' => true,
  778. 'default' => 0,
  779. ),
  780. ),
  781. 'primary key' => array (
  782. 0 => 'featureposprop_id',
  783. ),
  784. 'unique keys' => array (
  785. 'featureposprop_id' => array (
  786. 0 => 'featurepos_id',
  787. 1 => 'type_id',
  788. 2 => 'rank',
  789. ),
  790. ),
  791. 'indexes' => array (
  792. 'featureposprop_c1' => array (
  793. 0 => 'featurepos_id',
  794. ),
  795. 'featureposprop_idx2' => array (
  796. 0 => 'type_id',
  797. ),
  798. ),
  799. 'foreign keys' => array (
  800. 'cvterm' => array (
  801. 'table' => 'cvterm',
  802. 'columns' => array (
  803. 'type_id' => 'cvterm_id',
  804. ),
  805. ),
  806. 'featurepos' => array (
  807. 'table' => 'featurepos',
  808. 'columns' => array (
  809. 'featurepos_id' => 'featurepos_id',
  810. ),
  811. ),
  812. ),
  813. );
  814. chado_create_custom_table('featureposprop', $schema, TRUE);
  815. }
  816. /**
  817. * Add cv terms needed by the featuremap module
  818. *
  819. * @ingroup tripal_featuremap
  820. */
  821. function tripal_featuremap_add_cvterms() {
  822. // add cvterms for the map unit types
  823. tripal_insert_cvterm(
  824. array(
  825. 'name' => 'cM',
  826. 'definition' => 'Centimorgan units',
  827. 'cv_name' => 'featuremap_units',
  828. 'is_relationship' => 0,
  829. 'db_name' => 'tripal'
  830. ),
  831. array('update_existing' => TRUE)
  832. );
  833. tripal_insert_cvterm(
  834. array(
  835. 'name' => 'bp',
  836. 'definition' => 'Base pairs units',
  837. 'cv_name' => 'featuremap_units',
  838. 'is_relationship' => 0,
  839. 'db_name' => 'tripal'
  840. ),
  841. array('update_existing' => TRUE)
  842. );
  843. tripal_insert_cvterm(
  844. array(
  845. 'name' => 'bin_unit',
  846. 'definition' => 'The bin unit',
  847. 'cv_name' => 'featuremap_units',
  848. 'is_relationship' => 0,
  849. 'db_name' => 'tripal'
  850. ),
  851. array('update_existing' => TRUE)
  852. );
  853. tripal_insert_cvterm(
  854. array(
  855. 'name' => 'marker_order',
  856. 'definition' => 'Units simply to define marker order.',
  857. 'cv_name' => 'featuremap_units',
  858. 'is_relationship' => 0,
  859. 'db_name' => 'tripal'
  860. ),
  861. array('update_existing' => TRUE)
  862. );
  863. tripal_insert_cvterm(
  864. array(
  865. 'name' => 'undefined',
  866. 'definition' => 'A catch-all for an undefined unit type',
  867. 'cv_name' => 'featuremap_units',
  868. 'is_relationship' => 0,
  869. 'db_name' => 'tripal'
  870. ),
  871. array('update_existing' => TRUE)
  872. );
  873. // featurepos properties
  874. tripal_insert_cvterm(
  875. array(
  876. 'name' => 'start',
  877. 'definition' => 'The start coordinate for a map feature.',
  878. 'cv_name' => 'featurepos_property',
  879. 'is_relationship' => 0,
  880. 'db_name' => 'tripal'
  881. ),
  882. array('update_existing' => TRUE)
  883. );
  884. tripal_insert_cvterm(
  885. array(
  886. 'name' => 'stop',
  887. 'definition' => 'The end coordinate for a map feature',
  888. 'cv_name' => 'featurepos_property',
  889. 'is_relationship' => 0,
  890. 'db_name' => 'tripal'
  891. ),
  892. array('update_existing' => TRUE)
  893. );
  894. // add cvterms for map properties
  895. tripal_insert_cvterm(
  896. array(
  897. 'name' => 'Map Dbxref',
  898. 'definition' => 'A unique identifer for the map in a remote database. The '
  899. . 'format is a database abbreviation and a unique accession separated '
  900. . 'by a colon. (e.g. Gramene:tsh1996a)',
  901. 'cv_name' => 'featuremap_property',
  902. 'is_relationship' => 0,
  903. 'db_name' => 'tripal'
  904. ),
  905. array('update_existing' => TRUE)
  906. );
  907. tripal_insert_cvterm(
  908. array(
  909. 'name' => 'Map Type',
  910. 'definition' => 'The type of Map (e.g. QTL, Physical, etc.)',
  911. 'cv_name' => 'featuremap_property',
  912. 'is_relationship' => 0,
  913. 'db_name' => 'tripal'
  914. ),
  915. array('update_existing' => TRUE)
  916. );
  917. tripal_insert_cvterm(
  918. array(
  919. 'name' => 'Genome Group',
  920. 'definition' => '',
  921. 'cv_name' => 'featuremap_property',
  922. 'is_relationship' => 0,
  923. 'db_name' => 'tripal'
  924. ),
  925. array('update_existing' => TRUE)
  926. );
  927. tripal_insert_cvterm(
  928. array(
  929. 'name' => 'URL',
  930. 'definition' => 'A univeral resource locator (URL) reference where the '
  931. . 'publication can be found. For maps found online, this would be '
  932. . 'the web address for the map.',
  933. 'cv_name' => 'featuremap_property',
  934. 'is_relationship' => 0,
  935. 'db_name' => 'tripal'
  936. ),
  937. array('update_existing' => TRUE)
  938. );
  939. tripal_insert_cvterm(
  940. array(
  941. 'name' => 'Population Type',
  942. 'definition' => 'A brief description of the population type used to generate '
  943. . 'the map (e.g. RIL, F2, BC1, etc).',
  944. 'cv_name' => 'featuremap_property',
  945. 'is_relationship' => 0,
  946. 'db_name' => 'tripal'
  947. ),
  948. array('update_existing' => TRUE)
  949. );
  950. tripal_insert_cvterm(
  951. array(
  952. 'name' => 'Population Size',
  953. 'definition' => 'The size of the population used to construct the map.',
  954. 'cv_name' => 'featuremap_property',
  955. 'is_relationship' => 0,
  956. 'db_name' => 'tripal'
  957. ),
  958. array('update_existing' => TRUE)
  959. );
  960. tripal_insert_cvterm(
  961. array(
  962. 'name' => 'Methods',
  963. 'definition' => 'A brief description of the methods used to construct the map.',
  964. 'cv_name' => 'featuremap_property',
  965. 'is_relationship' => 0,
  966. 'db_name' => 'tripal'
  967. ),
  968. array('update_existing' => TRUE)
  969. );
  970. tripal_insert_cvterm(
  971. array(
  972. 'name' => 'Software',
  973. 'definition' => 'The software used to construct the map.',
  974. 'cv_name' => 'featuremap_property',
  975. 'is_relationship' => 0,
  976. 'db_name' => 'tripal'
  977. ),
  978. array('update_existing' => TRUE)
  979. );
  980. }
  981. /**
  982. * Add cvs needed by the featuremap module
  983. *
  984. * @ingroup tripal_featuremap
  985. */
  986. function tripal_featuremap_add_cvs() {
  987. tripal_insert_cv(
  988. 'featuremap_units',
  989. 'Contains map unit types for the unittype_id column of the featuremap table.'
  990. );
  991. tripal_insert_cv(
  992. 'featurepos_property',
  993. 'Contains terms map properties.'
  994. );
  995. tripal_insert_cv(
  996. 'featuremap_property',
  997. 'Contains positional types for the feature positions'
  998. );
  999. }
  1000. /**
  1001. * Add cvs related to features
  1002. *
  1003. * @ingroup tripal_pub
  1004. */
  1005. function tripal_feature_add_cvs() {
  1006. // Add cv for relationship types
  1007. tripal_insert_cv(
  1008. 'feature_relationship',
  1009. 'Contains types of relationships between features.'
  1010. );
  1011. // The feature_property CV may already exists. It comes with Chado, but
  1012. // we need to add it just in case it doesn't get added before the feature
  1013. // module is installed. But as of Tripal v3.0 the Chado version of this
  1014. // vocabulary is no longer loaded by default.
  1015. tripal_insert_cv(
  1016. 'feature_property',
  1017. 'Stores properties about features'
  1018. );
  1019. // the feature type vocabulary should be the sequence ontology, and even though
  1020. // this ontology should get loaded we will create it here just so that we can
  1021. // set the default vocabulary for the feature.type_id field
  1022. tripal_insert_cv(
  1023. 'sequence',
  1024. 'The Sequence Ontology'
  1025. );
  1026. }
  1027. function tripal_feature_add_tripal_gff_temp_table() {
  1028. $schema = array(
  1029. 'table' => 'tripal_gff_temp',
  1030. 'fields' => array(
  1031. 'feature_id' => array(
  1032. 'type' => 'int',
  1033. 'not null' => TRUE,
  1034. ),
  1035. 'organism_id' => array(
  1036. 'type' => 'int',
  1037. 'not null' => TRUE,
  1038. ),
  1039. 'uniquename' => array(
  1040. 'type' => 'text',
  1041. 'not null' => TRUE,
  1042. ),
  1043. 'type_name' => array(
  1044. 'type' => 'varchar',
  1045. 'length' => '1024',
  1046. 'not null' => TRUE,
  1047. ),
  1048. ),
  1049. 'indexes' => array(
  1050. 'tripal_gff_temp_idx0' => array('feature_id'),
  1051. 'tripal_gff_temp_idx0' => array('organism_id'),
  1052. 'tripal_gff_temp_idx1' => array('uniquename'),
  1053. ),
  1054. 'unique keys' => array(
  1055. 'tripal_gff_temp_uq0' => array('feature_id'),
  1056. 'tripal_gff_temp_uq1' => array('uniquename', 'organism_id', 'type_name'),
  1057. ),
  1058. );
  1059. chado_create_custom_table('tripal_gff_temp', $schema, TRUE);
  1060. }
  1061. /**
  1062. *
  1063. */
  1064. function tripal_feature_add_tripal_gffcds_temp_table($skip_recreate = TRUE) {
  1065. $schema = array(
  1066. 'table' => 'tripal_gffcds_temp',
  1067. 'fields' => array(
  1068. 'feature_id' => array(
  1069. 'type' => 'int',
  1070. 'not null' => TRUE,
  1071. ),
  1072. 'parent_id' => array(
  1073. 'type' => 'int',
  1074. 'not null' => TRUE,
  1075. ),
  1076. 'phase' => array(
  1077. 'type' => 'int',
  1078. 'not null' => TRUE,
  1079. ),
  1080. 'strand' => array(
  1081. 'type' => 'int',
  1082. 'not null' => TRUE,
  1083. ),
  1084. 'fmin' => array(
  1085. 'type' => 'int',
  1086. 'not null' => TRUE,
  1087. ),
  1088. 'fmax' => array(
  1089. 'type' => 'int',
  1090. 'not null' => TRUE,
  1091. ),
  1092. ),
  1093. 'indexes' => array(
  1094. 'tripal_gff_temp_idx0' => array('feature_id'),
  1095. 'tripal_gff_temp_idx0' => array('parent_id'),
  1096. ),
  1097. );
  1098. chado_create_custom_table('tripal_gffcds_temp', $schema, $skip_recreate);
  1099. }
  1100. /**
  1101. *
  1102. */
  1103. function tripal_feature_add_tripal_gffprotein_temp_table() {
  1104. $schema = array(
  1105. 'table' => 'tripal_gffprotein_temp',
  1106. 'fields' => array(
  1107. 'feature_id' => array(
  1108. 'type' => 'int',
  1109. 'not null' => TRUE,
  1110. ),
  1111. 'parent_id' => array(
  1112. 'type' => 'int',
  1113. 'not null' => TRUE,
  1114. ),
  1115. 'fmin' => array(
  1116. 'type' => 'int',
  1117. 'not null' => TRUE,
  1118. ),
  1119. 'fmax' => array(
  1120. 'type' => 'int',
  1121. 'not null' => TRUE,
  1122. ),
  1123. ),
  1124. 'indexes' => array(
  1125. 'tripal_gff_temp_idx0' => array('feature_id'),
  1126. 'tripal_gff_temp_idx0' => array('parent_id'),
  1127. ),
  1128. 'unique keys' => array(
  1129. 'tripal_gff_temp_uq0' => array('feature_id'),
  1130. ),
  1131. );
  1132. chado_create_custom_table('tripal_gffprotein_temp', $schema, TRUE);
  1133. }
  1134. /**
  1135. * Creates a materialized view that stores the type & number of features per organism
  1136. *
  1137. * @ingroup tripal_feature
  1138. */
  1139. function tripal_feature_add_organism_count_mview() {
  1140. $view_name = 'organism_feature_count';
  1141. $comment = 'Stores the type and number of features per organism';
  1142. $schema = array(
  1143. 'description' => $comment,
  1144. 'table' => $view_name,
  1145. 'fields' => array(
  1146. 'organism_id' => array(
  1147. 'type' => 'int',
  1148. 'not null' => TRUE,
  1149. ),
  1150. 'genus' => array(
  1151. 'type' => 'varchar',
  1152. 'length' => '255',
  1153. 'not null' => TRUE,
  1154. ),
  1155. 'species' => array(
  1156. 'type' => 'varchar',
  1157. 'length' => '255',
  1158. 'not null' => TRUE,
  1159. ),
  1160. 'common_name' => array(
  1161. 'type' => 'varchar',
  1162. 'length' => '255',
  1163. 'not null' => FALSE,
  1164. ),
  1165. 'num_features' => array(
  1166. 'type' => 'int',
  1167. 'not null' => TRUE,
  1168. ),
  1169. 'cvterm_id' => array(
  1170. 'type' => 'int',
  1171. 'not null' => TRUE,
  1172. ),
  1173. 'feature_type' => array(
  1174. 'type' => 'varchar',
  1175. 'length' => '255',
  1176. 'not null' => TRUE,
  1177. ),
  1178. ),
  1179. 'indexes' => array(
  1180. 'organism_feature_count_idx1' => array('organism_id'),
  1181. 'organism_feature_count_idx2' => array('cvterm_id'),
  1182. 'organism_feature_count_idx3' => array('feature_type'),
  1183. ),
  1184. );
  1185. $sql = "
  1186. SELECT
  1187. O.organism_id, O.genus, O.species, O.common_name,
  1188. count(F.feature_id) as num_features,
  1189. CVT.cvterm_id, CVT.name as feature_type
  1190. FROM organism O
  1191. INNER JOIN feature F ON O.Organism_id = F.organism_id
  1192. INNER JOIN cvterm CVT ON F.type_id = CVT.cvterm_id
  1193. GROUP BY
  1194. O.Organism_id, O.genus, O.species, O.common_name, CVT.cvterm_id, CVT.name
  1195. ";
  1196. tripal_add_mview($view_name, 'tripal_feature', $schema, $sql, $comment);
  1197. }
  1198. /**
  1199. * Adds any cvs needed by this module.
  1200. *
  1201. * @ingroup tripal_contact
  1202. */
  1203. function tripal_contact_add_cvs() {
  1204. // Add the cv for contact properties. This is a default vocabulary in the event
  1205. // that a user does not want to use the tripal_contact vocabulary
  1206. tripal_insert_cv(
  1207. 'contact_property',
  1208. 'Contains properties for contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
  1209. );
  1210. // add the cv for the contact type. This is a default vocabulary in the event
  1211. // that a user does not want to use the tripal_contact vocabulary
  1212. tripal_insert_cv(
  1213. 'contact_type',
  1214. 'Contains types of contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
  1215. );
  1216. // Add the cv for the tripal_contact vocabulary which is loaded via the OBO
  1217. tripal_insert_cv(
  1218. 'tripal_contact',
  1219. 'A heirarchical set of terms for describing a contact. It is intended to be used as the default vocabularies in Tripal for contact types and contact properties.'
  1220. );
  1221. // add the cv for contact relationships
  1222. tripal_insert_cv(
  1223. 'contact_relationship',
  1224. 'Contains types of relationships between contacts.'
  1225. );
  1226. }
  1227. /**
  1228. * Add any custom tables needed by this module.
  1229. * - Contactprop: keep track of properties of contact
  1230. *
  1231. * @ingroup tripal_contact
  1232. */
  1233. function tripal_contact_add_custom_tables(){
  1234. $schema = array (
  1235. 'table' => 'contactprop',
  1236. 'fields' => array (
  1237. 'contactprop_id' => array (
  1238. 'type' => 'serial',
  1239. 'not null' => true,
  1240. ),
  1241. 'contact_id' => array (
  1242. 'type' => 'int',
  1243. 'not null' => true,
  1244. ),
  1245. 'type_id' => array (
  1246. 'type' => 'int',
  1247. 'not null' => true,
  1248. ),
  1249. 'value' => array (
  1250. 'type' => 'text',
  1251. 'not null' => false,
  1252. ),
  1253. 'rank' => array (
  1254. 'type' => 'int',
  1255. 'not null' => true,
  1256. 'default' => 0,
  1257. ),
  1258. ),
  1259. 'primary key' => array (
  1260. 0 => 'contactprop_id',
  1261. ),
  1262. 'unique keys' => array (
  1263. 'contactprop_c1' => array (
  1264. 0 => 'contact_id',
  1265. 1 => 'type_id',
  1266. 2 => 'rank',
  1267. ),
  1268. ),
  1269. 'indexes' => array (
  1270. 'contactprop_idx1' => array (
  1271. 0 => 'contact_id',
  1272. ),
  1273. 'contactprop_idx2' => array (
  1274. 0 => 'type_id',
  1275. ),
  1276. ),
  1277. 'foreign keys' => array (
  1278. 'cvterm' => array (
  1279. 'table' => 'cvterm',
  1280. 'columns' => array (
  1281. 'type_id' => 'cvterm_id',
  1282. ),
  1283. ),
  1284. 'contact' => array (
  1285. 'table' => 'contact',
  1286. 'columns' => array (
  1287. 'contact_id' => 'contact_id',
  1288. ),
  1289. ),
  1290. ),
  1291. );
  1292. chado_create_custom_table('contactprop', $schema, TRUE);
  1293. }
  1294. /**
  1295. * Create a legacy custom chado table (analysisfeatureprop) to store properties of
  1296. * analysisfeature links.
  1297. *
  1298. * @ingroup tripal_analysis
  1299. */
  1300. function tripal_analysis_create_analysisfeatureprop() {
  1301. // Create analysisfeatureprop table in chado. This is needed for Chado
  1302. // version 1.11, the table exists in Chado 1.2.
  1303. if (!db_table_exists('chado.analysisfeatureprop')) {
  1304. $sql = "
  1305. CREATE TABLE {analysisfeatureprop} (
  1306. analysisfeatureprop_id SERIAL PRIMARY KEY,
  1307. analysisfeature_id INTEGER NOT NULL,
  1308. type_id INTEGER NOT NULL,
  1309. value TEXT,
  1310. rank INTEGER NOT NULL,
  1311. CONSTRAINT analysisfeature_id_type_id_rank UNIQUE (analysisfeature_id, type_id, rank),
  1312. CONSTRAINT analysisfeatureprop_analysisfeature_id_fkey FOREIGN KEY (analysisfeature_id) REFERENCES {analysisfeature}(analysisfeature_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
  1313. CONSTRAINT analysisfeatureprop_type_id_fkey FOREIGN KEY (type_id) REFERENCES {cvterm}(cvterm_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
  1314. )
  1315. ";
  1316. chado_query($sql);
  1317. }
  1318. }
  1319. /**
  1320. * Creates a view showing the link between an organism & it's analysis through associated features.
  1321. *
  1322. * @ingroup tripal_analysis
  1323. */
  1324. function tripal_analysis_add_mview_analysis_organism() {
  1325. $view_name = 'analysis_organism';
  1326. $comment = t('This view is for associating an organism (via it\'s associated features) to an analysis.');
  1327. // this is the SQL used to identify the organism to which an analsysis
  1328. // has been used. This is obtained though the analysisfeature -> feature -> organism
  1329. // joins
  1330. $sql = "
  1331. SELECT DISTINCT A.analysis_id, O.organism_id
  1332. FROM analysis A
  1333. INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id
  1334. INNER JOIN feature F ON AF.feature_id = F.feature_id
  1335. INNER JOIN organism O ON O.organism_id = F.organism_id
  1336. ";
  1337. // the schema array for describing this view
  1338. $schema = array(
  1339. 'table' => $view_name,
  1340. 'description' => $comment,
  1341. 'fields' => array(
  1342. 'analysis_id' => array(
  1343. 'type' => 'int',
  1344. 'not null' => TRUE,
  1345. ),
  1346. 'organism_id' => array(
  1347. 'type' => 'int',
  1348. 'not null' => TRUE,
  1349. ),
  1350. ),
  1351. 'indexes' => array(
  1352. 'networkmod_qtl_indx0' => array('analysis_id'),
  1353. 'networkmod_qtl_indx1' => array('organism_id'),
  1354. ),
  1355. 'foreign keys' => array(
  1356. 'analysis' => array(
  1357. 'table' => 'analysis',
  1358. 'columns' => array(
  1359. 'analysis_id' => 'analysis_id',
  1360. ),
  1361. ),
  1362. 'organism' => array(
  1363. 'table' => 'organism',
  1364. 'columns' => array(
  1365. 'organism_id' => 'organism_id',
  1366. ),
  1367. ),
  1368. ),
  1369. );
  1370. // add the view
  1371. tripal_add_mview($view_name, 'tripal_analysis', $schema, $sql, $comment);
  1372. }
  1373. /**
  1374. * Adds controlled vocabulary terms needed by this module.
  1375. *
  1376. * @ingroup tripal_analysis
  1377. */
  1378. function tripal_analysis_add_cvterms() {
  1379. tripal_insert_cv(
  1380. 'tripal_analysis',
  1381. 'Terms used for managing analyses in Tripal'
  1382. );
  1383. // add analysis_date. This is no longer used (as far as we can tell) but we don't
  1384. // get rid of it in case it is used, so just keep it in the Tripal CV
  1385. tripal_insert_cvterm(
  1386. array(
  1387. 'name' => 'analysis_date',
  1388. 'definition' => 'The date that an analysis was performed.',
  1389. 'cv_name' => 'tripal',
  1390. 'is_relationship' => 0,
  1391. 'db_name' => 'tripal'
  1392. ),
  1393. array('update_existing' => TRUE)
  1394. );
  1395. // add analysis_short_name. This is no longer used (as far as we can tell) but we don't
  1396. // get rid of it in case it is used, so just keep it in the Tripal CV
  1397. tripal_insert_cvterm(
  1398. array(
  1399. 'name' => 'analysis_short_name',
  1400. 'definition' => 'A computer legible (no spaces or special characters) '
  1401. . 'abbreviation for the analysis.',
  1402. 'cv_name' => 'tripal',
  1403. 'is_relationship' => 0,
  1404. 'db_name' => 'tripal'
  1405. ),
  1406. array('update_existing' => TRUE)
  1407. );
  1408. // the 'analysis_property' vocabulary is for user definable properties wo we
  1409. // will add an 'Analysis Type' to this vocubulary
  1410. tripal_insert_cvterm(
  1411. array(
  1412. 'name' => 'Analysis Type',
  1413. 'definition' => 'The type of analysis that was performed.',
  1414. 'cv_name' => 'analysis_property',
  1415. 'is_relationship' => 0,
  1416. 'db_name' => 'tripal'
  1417. ),
  1418. array('update_existing' => TRUE)
  1419. );
  1420. }
  1421. /**
  1422. * Implementation of hook_uninstall().
  1423. *
  1424. * @ingroup tripal
  1425. */
  1426. function tripal_chado_uninstall() {
  1427. // Drop the foreign key between tripal_custom_tables and tripal_mviews
  1428. // so that Drupal can then drop the tables
  1429. db_query('
  1430. ALTER TABLE {tripal_custom_tables}
  1431. DROP CONSTRAINT tripal_custom_tables_fk1 CASCADE
  1432. ');
  1433. }
  1434. /**
  1435. * Table definition for the tripal_cv_obo table
  1436. * @param $schema
  1437. */
  1438. function tripal_chado_tripal_cv_obo_schema() {
  1439. return array(
  1440. 'fields' => array(
  1441. 'obo_id' => array(
  1442. 'type' => 'serial',
  1443. 'unsigned' => TRUE,
  1444. 'not null' => TRUE
  1445. ),
  1446. 'name' => array(
  1447. 'type' => 'varchar',
  1448. 'length' => 255
  1449. ),
  1450. 'path' => array(
  1451. 'type' => 'varchar',
  1452. 'length' => 1024
  1453. ),
  1454. ),
  1455. 'indexes' => array(
  1456. 'tripal_cv_obo_idx1' => array('obo_id'),
  1457. ),
  1458. 'primary key' => array('obo_id'),
  1459. );
  1460. }
  1461. /**
  1462. * * Table definition for the tripal_cv_defaults table
  1463. * @param unknown $schema
  1464. */
  1465. function tripal_chado_tripal_cv_defaults_schema() {
  1466. return array(
  1467. 'fields' => array(
  1468. 'cv_default_id' => array(
  1469. 'type' => 'serial',
  1470. 'unsigned' => TRUE,
  1471. 'not null' => TRUE
  1472. ),
  1473. 'table_name' => array(
  1474. 'type' => 'varchar',
  1475. 'length' => 128,
  1476. 'not null' => TRUE,
  1477. ),
  1478. 'field_name' => array(
  1479. 'type' => 'varchar',
  1480. 'length' => 128,
  1481. 'not null' => TRUE,
  1482. ),
  1483. 'cv_id' => array(
  1484. 'type' => 'int',
  1485. 'not null' => TRUE,
  1486. )
  1487. ),
  1488. 'indexes' => array(
  1489. 'tripal_cv_defaults_idx1' => array('table_name', 'field_name'),
  1490. ),
  1491. 'unique keys' => array(
  1492. 'tripal_cv_defaults_unq1' => array('table_name', 'field_name', 'cv_id'),
  1493. ),
  1494. 'primary key' => array('cv_default_id')
  1495. );
  1496. }
  1497. /**
  1498. * Add a materialized view of root terms for all chado cvs. This is needed for viewing cv trees
  1499. *
  1500. * @ingroup tripal_cv
  1501. */
  1502. function tripal_cv_add_cv_root_mview() {
  1503. $mv_name = 'cv_root_mview';
  1504. $comment = 'A list of the root terms for all controlled vocabularies. This is needed for viewing CV trees';
  1505. $schema = array(
  1506. 'table' => $mv_name,
  1507. 'description' => $comment,
  1508. 'fields' => array(
  1509. 'name' => array(
  1510. 'type' => 'varchar',
  1511. 'length' => 255,
  1512. 'not null' => TRUE,
  1513. ),
  1514. 'cvterm_id' => array(
  1515. 'type' => 'int',
  1516. 'not null' => TRUE,
  1517. ),
  1518. 'cv_id' => array(
  1519. 'type' => 'int',
  1520. 'not null' => TRUE,
  1521. ),
  1522. 'cv_name' => array(
  1523. 'type' => 'varchar',
  1524. 'length' => 255,
  1525. 'not null' => TRUE,
  1526. ),
  1527. ),
  1528. 'indexes' => array(
  1529. 'cv_root_mview_indx1' => array('cvterm_id'),
  1530. 'cv_root_mview_indx2' => array('cv_id'),
  1531. ),
  1532. );
  1533. $sql = "
  1534. SELECT DISTINCT CVT.name,CVT.cvterm_id, CV.cv_id, CV.name
  1535. FROM cvterm_relationship CVTR
  1536. INNER JOIN cvterm CVT on CVTR.object_id = CVT.cvterm_id
  1537. INNER JOIN cv CV on CV.cv_id = CVT.cv_id
  1538. WHERE CVTR.object_id not in
  1539. (SELECT subject_id FROM cvterm_relationship)
  1540. ";
  1541. // Create the MView
  1542. tripal_add_mview($mv_name, 'tripal_cv', $schema, $sql, $comment);
  1543. }
  1544. /**
  1545. * Add's defaults to the tripal_cv_obo table
  1546. *
  1547. * @ingroup tripal_cv
  1548. */
  1549. function tripal_cv_add_obo_defaults() {
  1550. // Insert commonly used ontologies into the tables.
  1551. $ontologies = array(
  1552. array('Relationship Ontology', 'http://purl.obolibrary.org/obo/ro.obo'),
  1553. // array('Relationship Ontology (older deprecated version)', 'http://www.obofoundry.org/ro/ro.obo'),
  1554. array('Sequence Ontology', 'https://github.com/The-Sequence-Ontology/SO-Ontologies/blob/master/so-xp-simple.obo'),
  1555. array('Gene Ontology', 'http://www.geneontology.org/ontology/gene_ontology.obo'),
  1556. // array('Cell Ontology', 'https://raw.githubusercontent.com/obophenotype/cell-ontology/master/cl.obo'),
  1557. // array('Plant Structure Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_anatomy.obo?view=co'),
  1558. // array('Plant Growth and Development Stages Ontology', 'http://palea.cgrb.oregonstate.edu/viewsvn/Poc/trunk/ontology/OBO_format/po_temporal.obo?view=co')
  1559. );
  1560. foreach ($ontologies as $o) {
  1561. db_query("INSERT INTO {tripal_cv_obo} (name,path) VALUES (:name, :path)", array(':name' => $o[0], ':path' => $o[1]));
  1562. }
  1563. }
  1564. /**
  1565. * Creates a temporary table to store obo details while loading an obo file
  1566. *
  1567. * @ingroup tripal_cv
  1568. */
  1569. function tripal_cv_create_tripal_obo_temp() {
  1570. // the tripal_obo_temp table is used for temporary housing of records when loading OBO files
  1571. // we create it here using plain SQL because we want it to be in the chado schema but we
  1572. // do not want to use the Tripal Custom Table API because we don't want it to appear in the
  1573. // list of custom tables. It needs to be available for the Tripal Chado API so we create it
  1574. // here and then define it in the tripal_cv/api/tripal_cv.schema.api.inc
  1575. if (!db_table_exists('chado.tripal_obo_temp')) {
  1576. $sql = "
  1577. CREATE TABLE {tripal_obo_temp} (
  1578. id character varying(255) NOT NULL,
  1579. stanza text NOT NULL,
  1580. type character varying(50) NOT NULL,
  1581. CONSTRAINT tripal_obo_temp_uq0 UNIQUE (id)
  1582. );
  1583. ";
  1584. chado_query($sql);
  1585. $sql = "CREATE INDEX tripal_obo_temp_idx0 ON {tripal_obo_temp} USING btree (id)";
  1586. chado_query($sql);
  1587. $sql = "CREATE INDEX tripal_obo_temp_idx1 ON {tripal_obo_temp} USING btree (type)";
  1588. chado_query($sql);
  1589. }
  1590. }
  1591. /**
  1592. * Implements hook_schema().
  1593. */
  1594. function tripal_chado_schema() {
  1595. // Links TripalEntity entities to the chado record.
  1596. $schema['chado_entity'] = tripal_chado_chado_entity_schema();
  1597. $schema['tripal_mviews'] = tripal_chado_tripal_mviews_schema();
  1598. $schema['tripal_custom_tables'] = tripal_chado_tripal_custom_tables_schema();
  1599. $schema['tripal_cv_obo'] = tripal_chado_tripal_cv_obo_schema();
  1600. $schema['tripal_cv_defaults'] = tripal_chado_tripal_cv_defaults_schema();
  1601. $schema['tripal_pub_import'] = tripal_chado_tripal_pub_import_schema();
  1602. // if this module is already installed and enabled, then we want to provide
  1603. // the schemas for all of the custom tables. This will allow Views to
  1604. // see the schemas. We check if the module is installed because during
  1605. // installation we don't want to make these custom tables available as we don't
  1606. // want them created in the Drupal database. The custom tables go in the
  1607. // Chado database.
  1608. if (db_table_exists('tripal_custom_tables')) {
  1609. $sql = 'SELECT * FROM {tripal_custom_tables}';
  1610. $results = db_query($sql);
  1611. foreach ($results as $custom) {
  1612. $schema[$custom->table_name] = unserialize($custom->schema);
  1613. }
  1614. }
  1615. return $schema;
  1616. }
  1617. /**
  1618. * @section
  1619. * Schema Definitions.
  1620. */
  1621. /**
  1622. * Describes the Tripal Custom Tables (tripal_custom_tables) table
  1623. * This keeps track of tables created by Tripal and stored in chado that may or may not
  1624. * also be materialized views.
  1625. *
  1626. * @ingroup tripal
  1627. */
  1628. function tripal_chado_tripal_custom_tables_schema() {
  1629. return array(
  1630. 'fields' => array(
  1631. 'table_id' => array(
  1632. 'type' => 'serial',
  1633. 'unsigned' => TRUE,
  1634. 'not NULL' => TRUE
  1635. ),
  1636. 'table_name' => array(
  1637. 'type' => 'varchar',
  1638. 'length' => 255,
  1639. 'not NULL' => TRUE
  1640. ),
  1641. 'schema' => array(
  1642. 'type' => 'text',
  1643. 'not NULL' => TRUE
  1644. ),
  1645. 'mview_id' => array(
  1646. 'type' => 'int',
  1647. 'not NULL' => FALSE
  1648. )
  1649. ),
  1650. 'indexes' => array(
  1651. 'table_id' => array('table_id'),
  1652. ),
  1653. 'primary key' => array('table_id'),
  1654. 'foreign keys' => array(
  1655. 'tripal_mviews' => array(
  1656. 'table' => 'tripal_mviews',
  1657. 'columns' => array(
  1658. 'mview_id' => 'mview_id'
  1659. ),
  1660. ),
  1661. ),
  1662. );
  1663. }
  1664. /**
  1665. * Describes the Tripal Materialized View (tripal_mviews) table
  1666. * This table keeps track of all materialized views created by Tripal and stored in chado
  1667. *
  1668. * @ingroup tripal
  1669. */
  1670. function tripal_chado_tripal_mviews_schema() {
  1671. return array(
  1672. 'fields' => array(
  1673. 'mview_id' => array(
  1674. 'type' => 'serial',
  1675. 'unsigned' => TRUE,
  1676. 'not NULL' => TRUE
  1677. ),
  1678. 'name' => array(
  1679. 'type' => 'varchar',
  1680. 'length' => 255,
  1681. 'not NULL' => TRUE
  1682. ),
  1683. 'modulename' => array(
  1684. 'type' => 'varchar',
  1685. 'length' => 50,
  1686. 'not NULL' => TRUE,
  1687. 'description' => 'The module name that provides the callback for this job'
  1688. ),
  1689. 'mv_table' => array(
  1690. 'type' => 'varchar',
  1691. 'length' => 128,
  1692. 'not NULL' => FALSE
  1693. ),
  1694. 'mv_specs' => array(
  1695. 'type' => 'text',
  1696. 'size' => 'normal',
  1697. 'not NULL' => FALSE
  1698. ),
  1699. 'mv_schema' => array(
  1700. 'type' => 'text',
  1701. 'size' => 'normal',
  1702. 'not NULL' => FALSE
  1703. ),
  1704. 'indexed' => array(
  1705. 'type' => 'text',
  1706. 'size' => 'normal',
  1707. 'not NULL' => FALSE
  1708. ),
  1709. 'query' => array(
  1710. 'type' => 'text',
  1711. 'size' => 'normal',
  1712. 'not NULL' => TRUE
  1713. ),
  1714. 'special_index' => array(
  1715. 'type' => 'text',
  1716. 'size' => 'normal',
  1717. 'not NULL' => FALSE
  1718. ),
  1719. 'last_update' => array(
  1720. 'type' => 'int',
  1721. 'not NULL' => FALSE,
  1722. 'description' => 'UNIX integer time'
  1723. ),
  1724. 'status' => array(
  1725. 'type' => 'text',
  1726. 'size' => 'normal',
  1727. 'not NULL' => FALSE
  1728. ),
  1729. 'comment' => array(
  1730. 'type' => 'text',
  1731. 'size' => 'normal',
  1732. 'not NULL' => FALSE
  1733. ),
  1734. ),
  1735. 'indexes' => array(
  1736. 'mview_id' => array('mview_id')
  1737. ),
  1738. 'unique keys' => array(
  1739. 'mv_table' => array('mv_table'),
  1740. 'mv_name' => array('name'),
  1741. ),
  1742. 'primary key' => array('mview_id'),
  1743. );
  1744. }
  1745. /**
  1746. * Links Biological Data Entities to the chado "base" table the data is stored in.
  1747. * This is where we would specify that a particular gene maps to the record in the
  1748. * chado.feature table with a feature_id=2432;
  1749. */
  1750. function tripal_chado_chado_entity_schema() {
  1751. $schema = array(
  1752. 'description' => 'The linker table that associates an enitity from the public.tripal_entity table with a "base" record in Chado',
  1753. 'fields' => array(
  1754. 'chado_entity_id' => array(
  1755. 'description' => 'The primary identifier for this table.',
  1756. 'type' => 'serial',
  1757. 'unsigned' => TRUE,
  1758. 'not null' => TRUE,
  1759. ),
  1760. 'entity_id' => array(
  1761. 'description' => 'The unique entity id.',
  1762. 'type' => 'int',
  1763. 'not null' => TRUE,
  1764. ),
  1765. 'record_id' => array(
  1766. 'description' => 'The unique numerical identifier for the record that this entity is associated with (e.g. feature_id, stock_id, library_id, etc.).',
  1767. 'type' => 'int',
  1768. 'not null' => TRUE,
  1769. ),
  1770. 'data_table' => array(
  1771. 'description' => 'Indicates the table in Chado that this term services (e.g. feature, stock, library, etc.)',
  1772. 'type' => 'varchar',
  1773. 'length' => 128,
  1774. 'not null' => TRUE,
  1775. 'default' => '',
  1776. ),
  1777. 'type_table' => array(
  1778. 'description' => 'Sometimes the record in the data table doesn’t have a field that specifies the record type. For example, an analysis type is stored in the analysisprop table. If the data_table does have a type field then this value will be the same as the data_table.',
  1779. 'type' => 'varchar',
  1780. 'length' => 128,
  1781. 'not null' => TRUE,
  1782. 'default' => '',
  1783. ),
  1784. 'field' => array(
  1785. 'description' => 'The name of the field in the typetable that contains the cvterm record.',
  1786. 'type' => 'varchar',
  1787. 'length' => 128,
  1788. 'not null' => FALSE,
  1789. 'default' => ''
  1790. ),
  1791. ),
  1792. 'indexes' => array(
  1793. 'record_id' => array('record_id'),
  1794. 'entity_id' => array('entity_id'),
  1795. 'data_table' => array('data_table'),
  1796. ),
  1797. 'unique keys' => array(
  1798. 'record' => array('data_table', 'record_id'),
  1799. 'entity_id' => array('entity_id'),
  1800. ),
  1801. 'primary key' => array('chado_entity_id'),
  1802. );
  1803. return $schema;
  1804. }