tripal_chado.semweb.inc 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  1. <?php
  2. /**
  3. * Adds defaults to the chado_semweb table.
  4. */
  5. function tripal_chado_populate_chado_semweb_table() {
  6. // Add in all tables and fields into the chado_semweb table.
  7. $chado_tables = chado_get_table_names(TRUE);
  8. foreach ($chado_tables as $chado_table) {
  9. tripal_add_chado_semweb_table($chado_table);
  10. }
  11. // TODO: should this code be in the tripal_chado module? Some of these terms
  12. // are used solely by web services (e.g. rdfs:label) and are not used to
  13. // map chado terms to vocabularies.
  14. // Perhaps we should have an API for working with terms where these can be
  15. // inserted.
  16. // Now set defaults!
  17. tripal_chado_populate_vocab_EDAM();
  18. tripal_chado_populate_vocab_ERO();
  19. tripal_chado_populate_vocab_FOAF();
  20. tripal_chado_populate_vocab_IAO();
  21. tripal_chado_populate_vocab_LOCAL();
  22. tripal_chado_populate_vocab_NCBITAXON();
  23. tripal_chado_populate_vocab_OBI();
  24. tripal_chado_populate_vocab_OGI();
  25. tripal_chado_populate_vocab_RDFS();
  26. tripal_chado_populate_vocab_SBO();
  27. tripal_chado_populate_vocab_SCHEMA();
  28. tripal_chado_populate_vocab_SIO();
  29. tripal_chado_populate_vocab_SO();
  30. tripal_chado_populate_vocab_SWO();
  31. tripal_chado_populate_vocab_TAXRANK();
  32. tripal_chado_populate_vocab_TPUB();
  33. tripal_chado_populate_vocab_UO();
  34. }
  35. /**
  36. * Adds the friend of a friend database and terms.
  37. */
  38. function tripal_chado_populate_vocab_FOAF() {
  39. tripal_insert_cv('foaf','Friend of a Friend');
  40. tripal_insert_db(array(
  41. 'name' => 'foaf',
  42. 'description' => 'Friend of a Friend',
  43. 'url' => 'http://www.foaf-project.org/',
  44. 'urlprefix' => 'http://xmlns.com/foaf/spec/#',
  45. ));
  46. tripal_insert_cv('foaf','Friend of a Friend. A dictionary of people-related terms that can be used in structured data).');
  47. }
  48. /**
  49. * Adds the RDFS database and terms.
  50. */
  51. function tripal_chado_populate_vocab_RDFS() {
  52. tripal_insert_db(array(
  53. 'name' => 'rdfs',
  54. 'description' => 'Resource Description Framework Schema',
  55. 'url' => 'https://www.w3.org/TR/rdf-schema/',
  56. 'urlprefix' => 'https://www.w3.org/TR/rdf-schema/#ch_',
  57. ));
  58. tripal_insert_cv('rdfs','Resource Description Framework Schema');
  59. $name = tripal_insert_cvterm(array(
  60. 'id' => 'rdfs:type',
  61. 'name' => 'type',
  62. 'cv_name' => 'rdfs',
  63. 'definition' => 'The type of resource.',
  64. ));
  65. $name = tripal_insert_cvterm(array(
  66. 'id' => 'rdfs:label',
  67. 'name' => 'label',
  68. 'cv_name' => 'rdfs',
  69. 'definition' => 'A human-readable version of a resource\'s name.',
  70. ));
  71. }
  72. /**
  73. * Adds the Schema.org database and terms.
  74. */
  75. function tripal_chado_populate_vocab_SCHEMA() {
  76. tripal_insert_db(array(
  77. 'name' => 'schema',
  78. 'description' => 'Schema.org.',
  79. 'url' => 'https://schema.org/',
  80. 'urlprefix' => 'https://schema.org/{accession}',
  81. ));
  82. tripal_insert_cv('schema','Schema.org. Schema.org is sponsored by Google, Microsoft, Yahoo and Yandex. The vocabularies are developed by an open community process.');
  83. $term = tripal_insert_cvterm(array(
  84. 'id' => 'schema:name',
  85. 'name' => 'name',
  86. 'cv_name' => 'schema',
  87. 'definition' => 'The name of the item.',
  88. ));
  89. tripal_associate_chado_semweb_term(NULL, 'name', $term);
  90. $term = tripal_insert_cvterm(array(
  91. 'id' => 'schema:alternateName',
  92. 'name' => 'alternateName',
  93. 'cv_name' => 'schema',
  94. 'definition' => 'An alias for the item.',
  95. ));
  96. $term = tripal_insert_cvterm(array(
  97. 'id' => 'schema:comment',
  98. 'name' => 'comment',
  99. 'cv_name' => 'schema',
  100. 'definition' => 'Comments, typically from users.',
  101. ));
  102. tripal_associate_chado_semweb_term(NULL, 'comment', $term);
  103. $term = tripal_insert_cvterm(array(
  104. 'id' => 'schema:description',
  105. 'name' => 'description',
  106. 'cv_name' => 'schema',
  107. 'definition' => 'A description of the item.',
  108. ));
  109. tripal_associate_chado_semweb_term(NULL, 'description', $term);
  110. tripal_associate_chado_semweb_term('organism', 'comment', $term);
  111. $term = tripal_insert_cvterm(array(
  112. 'id' => 'schema:publication',
  113. 'name' => 'publication',
  114. 'cv_name' => 'schema',
  115. 'definition' => 'A publication event associated with the item.',
  116. ));
  117. tripal_associate_chado_semweb_term(NULL, 'pub_id', $term);
  118. $term = tripal_insert_cvterm(array(
  119. 'id' => 'schema:url',
  120. 'name' => 'url',
  121. 'cv_name' => 'schema',
  122. 'definition' => 'URL of the item.',
  123. ));
  124. tripal_associate_chado_semweb_term('db', 'URL', $term);
  125. }
  126. /**
  127. * Adds the SemanticScience database and terms.
  128. */
  129. function tripal_chado_populate_vocab_SIO() {
  130. tripal_insert_db(array(
  131. 'name' => 'SIO',
  132. 'description' => 'Semanticscience Integrated Ontology.',
  133. 'url' => 'http://sio.semanticscience.org/',
  134. 'urlprefix' => 'http://semanticscience.org/resource/{db}_{accession}',
  135. ));
  136. tripal_insert_cv('SIO',' The Semanticscience Integrated Ontology (SIO) provides a simple, integrated ontology of types and relations for rich description of objects, processes and their attributes.');
  137. $term = tripal_insert_cvterm(array(
  138. 'id' => 'SIO:000493',
  139. 'name' => 'clause',
  140. 'cv_name' => 'SIO',
  141. 'definition' => 'A clause consists of a subject and a predicate.',
  142. ));
  143. }
  144. /**
  145. * Adds the EDAM database and terms.
  146. */
  147. function tripal_chado_populate_vocab_EDAM() {
  148. tripal_insert_db(array(
  149. 'name' => 'data',
  150. 'description' => 'Bioinformatics operations, data types, formats, identifiers and topics.',
  151. 'url' => 'http://edamontology.org/page',
  152. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  153. ));
  154. tripal_insert_db(array(
  155. 'name' => 'EDAM',
  156. 'description' => 'Bioinformatics operations, data types, formats, identifiers and topics.',
  157. 'url' => 'http://edamontology.org/page',
  158. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  159. ));
  160. tripal_insert_cv('data','Bioinformatics operations, data types, formats, identifiers and topics.');
  161. $term = tripal_insert_cvterm(array(
  162. 'id' => 'data:1249',
  163. 'name' => 'Sequence length',
  164. 'cv_name' => 'EDAM',
  165. 'definition' => 'The size (length) of a sequence, subsequence or region in a sequence, or range(s) of lengths.',
  166. ));
  167. tripal_associate_chado_semweb_term('feature', 'seqlen', $term);
  168. $term = tripal_insert_cvterm(array(
  169. 'id' => 'data:2190',
  170. 'name' => 'Sequence checksum',
  171. 'cv_name' => 'EDAM',
  172. 'definition' => 'A fixed-size datum calculated (by using a hash function) for a molecular sequence, typically for purposes of error detection or indexing.',
  173. ));
  174. tripal_associate_chado_semweb_term('feature', 'md5checksum', $term);
  175. $term = tripal_insert_cvterm(array(
  176. 'id' => 'data:2091',
  177. 'name' => 'Accession',
  178. 'cv_name' => 'EDAM',
  179. 'definition' => 'A persistent (stable) and unique identifier, typically identifying an object (entry) from a database.',
  180. ));
  181. tripal_associate_chado_semweb_term(NULL, 'dbxref_id', $term);
  182. $term = tripal_insert_cvterm(array(
  183. 'id' => 'data:2044',
  184. 'name' => 'Sequence',
  185. 'cv_name' => 'EDAM',
  186. 'definition' => 'One or more molecular sequences, possibly with associated annotation..',
  187. ));
  188. tripal_associate_chado_semweb_term('feature', 'residues', $term);
  189. $term = tripal_insert_cvterm(array(
  190. 'id' => 'data:0842',
  191. 'name' => 'Identifier',
  192. 'cv_name' => 'EDAM',
  193. 'definition' => 'A text token, number or something else which identifies an entity, but which may not be persistent (stable) or unique (the same identifier may identify multiple things).',
  194. ));
  195. tripal_associate_chado_semweb_term(NULL, 'uniquename', $term);
  196. $term = tripal_insert_cvterm(array(
  197. 'id' => 'data:2968',
  198. 'name' => 'Image',
  199. 'cv_name' => 'EDAM',
  200. 'definition' => 'Biological or biomedical data has been rendered into an image, typically for display on screen.',
  201. ));
  202. tripal_associate_chado_semweb_term(NULL, 'eimage_id', $term);
  203. $term = tripal_insert_cvterm(array(
  204. 'id' => 'data:1274',
  205. 'name' => 'Map',
  206. 'cv_name' => 'EDAM',
  207. 'definition' => 'A map of (typically one) DNA sequence annotated with positional or non-positional features.',
  208. ));
  209. tripal_associate_chado_semweb_term(NULL, 'eimage_id', $term);
  210. $term = tripal_insert_cvterm(array(
  211. 'id' => 'data:1278',
  212. 'name' => 'Genetic map',
  213. 'cv_name' => 'EDAM',
  214. 'definition' => 'A map showing the relative positions of genetic markers in a nucleic acid sequence, based on estimation of non-physical distance such as recombination frequencies.',
  215. ));
  216. tripal_associate_chado_semweb_term('featuremap', 'featuremap_id', $term);
  217. $term = tripal_insert_cvterm(array(
  218. 'id' => 'data:1280',
  219. 'name' => 'Physical map',
  220. 'cv_name' => 'EDAM',
  221. 'definition' => 'A map of DNA (linear or circular) annotated with physical features or landmarks such as restriction sites, cloned DNA fragments, genes or genetic markers, along with the physical distances between them. Distance in a physical map is measured in base pairs. A physical map might be ordered relative to a reference map (typically a genetic map) in the process of genome sequencing.',
  222. ));
  223. tripal_associate_chado_semweb_term('featuremap', 'featuremap_id', $term);
  224. $term = tripal_insert_cvterm(array(
  225. 'id' => 'data:2012',
  226. 'name' => 'Sequence coordinates',
  227. 'cv_name' => 'EDAM',
  228. 'definition' => 'A position in a map (for example a genetic map), either a single position (point) or a region / interval.',
  229. ));
  230. $term = tripal_insert_cvterm(array(
  231. 'id' => 'data:1056',
  232. 'name' => 'Databse name',
  233. 'cv_name' => 'EDAM',
  234. 'definition' => 'The name of a biological or bioinformatics database.',
  235. ));
  236. tripal_associate_chado_semweb_term('db', 'name', $term);
  237. }
  238. /**
  239. * Adds the Eagle-i Resource Ontology database and terms.
  240. */
  241. function tripal_chado_populate_vocab_ERO() {
  242. tripal_insert_db(array(
  243. 'name' => 'ERO',
  244. 'description' => 'The Eagle-I Research Resource Ontology',
  245. 'url' => 'http://purl.bioontology.org/ontology/ERO',
  246. 'urlprefix' => 'http://purl.bioontology.org/ontology/ERO/{db}:{accession}',
  247. ));
  248. tripal_insert_cv('ero','The Eagle-I Research Resource Ontology models research resources such instruments. protocols, reagents, animal models and biospecimens. It has been developed in the context of the eagle-i project (http://eagle-i.net/).');
  249. $term = tripal_insert_cvterm(array(
  250. 'id' => 'ERO:0001716',
  251. 'name' => 'database',
  252. 'cv_name' => 'ero',
  253. 'definition' => 'A database is an organized collection of data, today typically in digital form.',
  254. ));
  255. }
  256. /**
  257. * Adds the Information Artifact Ontology database and terms.
  258. */
  259. function tripal_chado_populate_vocab_OBI() {
  260. tripal_insert_db(array(
  261. 'name' => 'OBI',
  262. 'description' => 'The Ontology for Biomedical Investigation.',
  263. 'url' => 'http://obi-ontology.org/page/Main_Page',
  264. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  265. ));
  266. tripal_insert_cv('obi','Ontology for Biomedical Investigation. The Ontology for Biomedical Investigations (OBI) is build in a collaborative, international effort and will serve as a resource for annotating biomedical investigations, including the study design, protocols and instrumentation used, the data generated and the types of analysis performed on the data. This ontology arose from the Functional Genomics Investigation Ontology (FuGO) and will contain both terms that are common to all biomedical investigations, including functional genomics investigations and those that are more domain specific.');
  267. $term = tripal_insert_cvterm(array(
  268. 'id' => 'OBI:0100026',
  269. 'name' => 'organism',
  270. 'cv_name' => 'obi',
  271. 'definition' => 'A material entity that is an individual living system, such as animal, plant, bacteria or virus, that is capable of replicating or reproducing, growth and maintenance in the right environment. An organism may be unicellular or made up, like humans, of many billions of cells divided into specialized tissues and organs.',
  272. ));
  273. tripal_associate_chado_semweb_term(NULL, 'organism_id', $term);
  274. }
  275. /**
  276. * Adds the Ontology for genetic interval database and terms.
  277. */
  278. function tripal_chado_populate_vocab_OGI() {
  279. tripal_insert_db(array(
  280. 'name' => 'OGI',
  281. 'description' => 'Ontology for genetic interval.',
  282. 'url' => 'http://purl.bioontology.org/ontology/OGI',
  283. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  284. ));
  285. tripal_insert_cv('obi','Ontology for Biomedical Investigation. The Ontology for Biomedical Investigations (OBI) is build in a collaborative, international effort and will serve as a resource for annotating biomedical investigations, including the study design, protocols and instrumentation used, the data generated and the types of analysis performed on the data. This ontology arose from the Functional Genomics Investigation Ontology (FuGO) and will contain both terms that are common to all biomedical investigations, including functional genomics investigations and those that are more domain specific.');
  286. $term = tripal_insert_cvterm(array(
  287. 'id' => 'OGI:0000021',
  288. 'name' => 'location on map',
  289. 'cv_name' => 'ogi',
  290. 'definition' => '',
  291. ));
  292. tripal_associate_chado_semweb_term(NULL, 'organism_id', $term);
  293. }
  294. /**
  295. * Adds the Information Artifact Ontology database and terms.
  296. */
  297. function tripal_chado_populate_vocab_IAO() {
  298. tripal_insert_db(array(
  299. 'name' => 'IAO',
  300. 'description' => 'The Information Artifact Ontology (IAO).',
  301. 'url' => 'https://github.com/information-artifact-ontology/IAO/',
  302. 'urlprefix' => 'http://purl.obolibrary.org/obo/IAO_',
  303. ));
  304. tripal_insert_cv('IAO','Information Artifact Ontology is a new ' .
  305. 'ontology of information entities, originally driven by work by the ' .
  306. 'OBI digital entity and realizable information entity branch.');
  307. $term = tripal_insert_cvterm(array(
  308. 'id' => 'IAO:0000115',
  309. 'name' => 'definition',
  310. 'cv_name' => 'iao',
  311. 'definition' => 'The official OBI definition, explaining the meaning of ' .
  312. 'a class or property. Shall be Aristotelian, formalized and normalized. ' .
  313. 'Can be augmented with colloquial definitions.',
  314. ));
  315. tripal_associate_chado_semweb_term(NULL, 'definition', $term);
  316. $term = tripal_insert_cvterm(array(
  317. 'id' => 'IAO:0000129',
  318. 'name' => 'version number',
  319. 'cv_name' => 'IAO',
  320. 'definition' => 'A version number is an ' .
  321. 'information content entity which is a sequence of characters ' .
  322. 'borne by part of each of a class of manufactured products or its ' .
  323. 'packaging and indicates its order within a set of other products ' .
  324. 'having the same name.',
  325. ));
  326. tripal_associate_chado_semweb_term('analysis', 'programversion', $term);
  327. $term = tripal_insert_cvterm(array(
  328. 'id' => 'IAO:0000064',
  329. 'name' => 'algorithm',
  330. 'cv_name' => 'IAO',
  331. 'definition' => 'An algorithm is a set of instructions for performing a paticular calculation.',
  332. ));
  333. tripal_associate_chado_semweb_term('analysis', 'algorithm', $term);
  334. }
  335. /**
  336. * Adds terms to the 'local' database.
  337. *
  338. * These are terms where an appropriate match could not be found in any other
  339. * ontology.
  340. */
  341. function tripal_chado_populate_vocab_LOCAL() {
  342. tripal_insert_db(array(
  343. 'name' => 'local',
  344. 'description' => 'Terms created for this site.',
  345. 'url' => '/cv/lookup',
  346. 'urlprefix' => '/cv/lookup/{db}/{accession}',
  347. ));
  348. $term = tripal_insert_cvterm(array(
  349. 'id' => 'local:timelastmodified',
  350. 'name' => 'time_last_modified',
  351. 'cv_name' => 'local',
  352. 'definition' => 'The time at which the record was last modified.',
  353. ));
  354. tripal_associate_chado_semweb_term(NULL, 'timelastmodified', $term);
  355. $term = tripal_insert_cvterm(array(
  356. 'id' => 'local:timeaccessioned',
  357. 'name' => 'time_accessioned',
  358. 'cv_name' => 'local',
  359. 'definition' => 'The time at which the record was first added.',
  360. ));
  361. tripal_associate_chado_semweb_term(NULL, 'timeaccessioned', $term);
  362. $term = tripal_insert_cvterm(array(
  363. 'id' => 'local:timeexecuted',
  364. 'name' => 'time_executed',
  365. 'cv_name' => 'local',
  366. 'definition' => 'The time when the task was executed.',
  367. ));
  368. tripal_associate_chado_semweb_term(NULL, 'timeexecuted', $term);
  369. $term = tripal_insert_cvterm(array(
  370. 'id' => 'local:infraspecific_type',
  371. 'name' => 'infraspecific_type',
  372. 'definition' => 'The connector type (e.g. subspecies, varietas, forma, etc.) for the infraspecific name',
  373. 'cv_name' => 'local',
  374. ));
  375. tripal_associate_chado_semweb_term('organism', 'type_id', $term);
  376. $term = tripal_insert_cvterm(array(
  377. 'id' => 'local:abbreviation',
  378. 'name' => 'abbreviation',
  379. 'cv_name' => 'local',
  380. 'definition' => 'A shortened name (or abbreviation) for the item.'
  381. ));
  382. tripal_associate_chado_semweb_term('organism', 'abbreviation', $term);
  383. $term = tripal_insert_cvterm(array(
  384. 'id' => 'local:expression',
  385. 'name' => 'expression',
  386. 'definition' => 'Curated expression data',
  387. 'cv_name' => 'local',
  388. ));
  389. $term = tripal_insert_cvterm(array(
  390. 'id' => 'local:is_analysis',
  391. 'name' => 'is_analysis',
  392. 'definition' => 'Indicates if this feature was predicted computationally using another feature.',
  393. 'cv_name' => 'local',
  394. ));
  395. tripal_associate_chado_semweb_term('feature', 'is_analysis', $term);
  396. $term = tripal_insert_cvterm(array(
  397. 'id' => 'local:is_obsolete',
  398. 'name' => 'is_obsolete',
  399. 'definition' => 'Indicates if this record is obsolete.',
  400. 'cv_name' => 'local',
  401. ));
  402. tripal_associate_chado_semweb_term(NULL, 'is_obsolete', $term);
  403. $term = tripal_insert_cvterm(array(
  404. 'id' => 'local:relationship_subject',
  405. 'name' => 'clause subject',
  406. 'definition' => 'The subject of a relationship clause.',
  407. 'cv_name' => 'local',
  408. ));
  409. tripal_associate_chado_semweb_term(NULL, 'subject_id', $term);
  410. tripal_associate_chado_semweb_term(NULL, 'subject_reagent_id', $term);
  411. tripal_associate_chado_semweb_term(NULL, 'subject_project_id', $term);
  412. $term = tripal_insert_cvterm(array(
  413. 'id' => 'local:relationship_object',
  414. 'name' => 'clause predicate',
  415. 'definition' => 'The object of a relationship clause.',
  416. 'cv_name' => 'local',
  417. ));
  418. tripal_associate_chado_semweb_term(NULL, 'object_id', $term);
  419. tripal_associate_chado_semweb_term(NULL, 'object_reagent_id', $term);
  420. tripal_associate_chado_semweb_term(NULL, 'object_project_id', $term);
  421. $term = tripal_insert_cvterm(array(
  422. 'id' => 'local:relationship_type',
  423. 'name' => 'relationship type',
  424. 'definition' => 'The relationship type.',
  425. 'cv_name' => 'local',
  426. ));
  427. tripal_associate_chado_semweb_term('acquisition_relationship', 'type_id', $term);
  428. tripal_associate_chado_semweb_term('biomaterial_relationship', 'type_id', $term);
  429. tripal_associate_chado_semweb_term('cell_line_relationship', 'type_id', $term);
  430. tripal_associate_chado_semweb_term('contact_relationship', 'type_id', $term);
  431. tripal_associate_chado_semweb_term('element_relationship', 'type_id', $term);
  432. tripal_associate_chado_semweb_term('elementresult_relationship', 'type_id', $term);
  433. tripal_associate_chado_semweb_term('feature_relationship', 'type_id', $term);
  434. tripal_associate_chado_semweb_term('nd_reagent_relationship', 'type_id', $term);
  435. tripal_associate_chado_semweb_term('phylonode_relationship', 'type_id', $term);
  436. tripal_associate_chado_semweb_term('project_relationship', 'type_id', $term);
  437. tripal_associate_chado_semweb_term('pub_relationship', 'type_id', $term);
  438. tripal_associate_chado_semweb_term('quantification_relationship', 'type_id', $term);
  439. tripal_associate_chado_semweb_term('stock_relationship', 'type_id', $term);
  440. }
  441. /**
  442. * Adds the Systems Biology Ontology database and terms.
  443. */
  444. function tripal_chado_populate_vocab_SBO() {
  445. tripal_insert_db(array(
  446. 'name' => 'SBO',
  447. 'description' => 'Systems Biology.',
  448. 'url' => 'http://www.ebi.ac.uk/sbo/main/',
  449. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  450. ));
  451. tripal_insert_cv('sbo','Systems Biology. Terms commonly used in Systems Biology, and in particular in computational modeling.');
  452. $dbxref = tripal_insert_cvterm(array(
  453. 'id' => 'SBO:0000358',
  454. 'name' => 'phenotype',
  455. 'cv_name' => 'sbo',
  456. 'definition' => 'A biochemical network can generate phenotypes or affects biological processes. Such processes can take place at different levels and are independent of the biochemical network itself.',
  457. ));
  458. $dbxref = tripal_insert_cvterm(array(
  459. 'id' => 'SBO:0000554',
  460. 'name' => 'database cross reference',
  461. 'cv_name' => 'sbo',
  462. 'definition' => 'An annotation which directs one to information contained within a database.',
  463. ));
  464. $relationship = tripal_insert_cvterm(array(
  465. 'id' => 'SBO:0000374',
  466. 'name' => 'relationship',
  467. 'cv_name' => 'sbo',
  468. 'definition' => 'Connectedness between entities and/or interactions representing their relatedness or influence.',
  469. ));
  470. }
  471. /**
  472. * Adds the Sequence Ontology
  473. */
  474. function tripal_chado_populate_vocab_SO() {
  475. tripal_insert_db(array(
  476. 'name' => 'SO',
  477. 'description' => 'Sequence Ontology',
  478. 'url' => 'http://www.sequenceontology.org',
  479. 'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',
  480. ));
  481. tripal_insert_cv('sequence','The Sequence Ontology.');
  482. }
  483. /**
  484. * Adds the Software Ontology database and terms.
  485. */
  486. function tripal_chado_populate_vocab_SWO() {
  487. tripal_insert_db(array(
  488. 'name' => 'SWO',
  489. 'description' => 'Software Ontology',
  490. 'url' => 'http://theswo.sourceforge.net/',
  491. 'urlprefix' => '',
  492. ));
  493. tripal_insert_cv('swo','Software Ontology. An ontology representation of the NCBI organismal taxonomy.');
  494. $term = tripal_insert_cvterm(array(
  495. 'id' => 'SWO:0000001',
  496. 'name' => 'software',
  497. 'cv_name' => 'swo',
  498. 'definition' => 'Computer software, or generally just software, is any ' .
  499. 'set of machine-readable instructions (most often in the form of a ' .
  500. 'computer program) that conform to a given syntax (sometimes ' .
  501. 'referred to as a language) that is interpretable by a given ' .
  502. 'processor and that directs a computer\'s processor to perform ' .
  503. 'specific operations.',
  504. ));
  505. tripal_associate_chado_semweb_term('analysis', 'program', $term);
  506. }
  507. /**
  508. * Adds the pub table mapping.
  509. */
  510. function tripal_chado_populate_vocab_TPUB() {
  511. $term = tripal_get_cvterm(array('id' => 'TPUB:0000039'));
  512. tripal_associate_chado_semweb_term('pub', 'title', $term);
  513. $term = tripal_get_cvterm(array('id' => 'TPUB:0000243'));
  514. tripal_associate_chado_semweb_term('pub', 'volumetitle', $term);
  515. $term = tripal_get_cvterm(array('id' => 'TPUB:0000042'));
  516. tripal_associate_chado_semweb_term('pub', 'volume', $term);
  517. $term = tripal_get_cvterm(array('id' => 'TPUB:0000256'));
  518. tripal_associate_chado_semweb_term('pub', 'series_name', $term);
  519. $term = tripal_get_cvterm(array('id' => 'TPUB:0000043'));
  520. tripal_associate_chado_semweb_term('pub', 'issue', $term);
  521. $term = tripal_get_cvterm(array('id' => 'TPUB:0000059'));
  522. tripal_associate_chado_semweb_term('pub', 'pyear', $term);
  523. $term = tripal_get_cvterm(array('id' => 'TPUB:0000044'));
  524. tripal_associate_chado_semweb_term('pub', 'pages', $term);
  525. $term = tripal_get_cvterm(array('id' => 'TPUB:0000244'));
  526. tripal_associate_chado_semweb_term('pub', 'publisher', $term);
  527. $term = tripal_get_cvterm(array('id' => 'TPUB:0000245'));
  528. tripal_associate_chado_semweb_term('pub', 'pubplace', $term);
  529. }
  530. /**
  531. * Adds the Uni Ontology database, terms and mappings.
  532. */
  533. function tripal_chado_populate_vocab_UO() {
  534. tripal_insert_db(array(
  535. 'name' => 'UO',
  536. 'description' => 'Units of Measurement Ontology',
  537. 'url' => 'http://purl.obolibrary.org/obo/uo',
  538. 'urlprefix' => 'http://purl.obolibrary.org/obo/TAXRANK_',
  539. ));
  540. tripal_insert_cv('uo','Units of Measurement Ontology');
  541. $term = tripal_insert_cvterm(array(
  542. 'id' => 'UO:0000000',
  543. 'name' => 'unit',
  544. 'cv_name' => 'uo',
  545. 'description' => 'A unit of measurement is a standardized quantity of a physical quality.'
  546. ));
  547. tripal_associate_chado_semweb_term('featuremap', 'unittype_id', $term);
  548. }
  549. /**
  550. * Adds the Taxonomic Rank Ontology database and terms.
  551. */
  552. function tripal_chado_populate_vocab_TAXRANK() {
  553. tripal_insert_db(array(
  554. 'name' => 'TAXRANK',
  555. 'description' => 'Taxonomic rank vocabulary.',
  556. 'url' => 'https://github.com/phenoscape/taxrank',
  557. 'urlprefix' => 'http://purl.obolibrary.org/obo/TAXRANK_',
  558. ));
  559. tripal_insert_cv('taxrank','Taxonomic rank vocabulary. A vocabulary of taxonomic ranks (species, family, phylum, etc).');
  560. $term = tripal_insert_cvterm(array(
  561. 'id' => 'TAXRANK:0000005',
  562. 'name' => 'genus',
  563. 'cv_name' => 'taxonomic_rank',
  564. 'description' => 'Taxonomic rank of Genus'
  565. ));
  566. tripal_associate_chado_semweb_term('organism', 'genus', $term);
  567. $term = tripal_insert_cvterm(array(
  568. 'id' => 'TAXRANK:0000006',
  569. 'name' => 'species',
  570. 'cv_name' => 'taxonomic_rank',
  571. 'description' => 'Taxonomic rank of species.'
  572. ));
  573. tripal_associate_chado_semweb_term('organism', 'species', $term);
  574. $term = tripal_insert_cvterm(array(
  575. 'id' => 'TAXRANK:0000045',
  576. 'name' => 'infraspecies',
  577. 'cv_name' => 'taxonomic_rank',
  578. 'description' => 'Taxonomic infraspecies name.'
  579. ));
  580. tripal_associate_chado_semweb_term('organism', 'infraspecific_name', $term);
  581. }
  582. /**
  583. * Adds the NCBI Taxon vocabulary database and terms.
  584. */
  585. function tripal_chado_populate_vocab_NCBITAXON() {
  586. tripal_insert_db(array(
  587. 'name' => 'NCBITaxon',
  588. 'description' => 'NCBI organismal classification.',
  589. 'url' => 'http://www.berkeleybop.org/ontologies/ncbitaxon/',
  590. 'urlprefix' => 'http://purl.obolibrary.org/obo/ncbitaxon#',
  591. ));
  592. tripal_insert_cv('ncbitaxon','NCBI organismal classification. An ontology representation of the NCBI organismal taxonomy.');
  593. $term = tripal_insert_cvterm(array(
  594. 'id' => 'NCBITaxon:common_name',
  595. 'name' => 'common name',
  596. 'cv_name' => 'ncbitaxon',
  597. ));
  598. tripal_associate_chado_semweb_term('organism', 'common_name', $term);
  599. }
  600. /**
  601. * Adds defaults to the chado_semweb table.
  602. */
  603. function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
  604. if (array_key_exists('values', $form_state)) {
  605. $chado_table = $form_state['values']['chado_table'];
  606. }
  607. $chado_tables = chado_get_table_names(TRUE);
  608. $chado_tables = array_merge(array('Select a Chado Table'), $chado_tables);
  609. // Make sure the table name exists. If not, reset it.
  610. $chado_table = in_array($chado_table, $chado_tables) ? $chado_table: NULL;
  611. $form['chado_table'] = array(
  612. '#type' => 'select',
  613. '#title' => 'Chado Table',
  614. '#description' => t('Select a chado table to set web services terms used for its columns.'),
  615. '#options' => $chado_tables,
  616. '#default_value' => $chado_table,
  617. '#ajax' => array(
  618. 'callback' => "tripal_chado_semweb_form_ajax_callback",
  619. 'wrapper' => "tripal-chado-semweb-form",
  620. 'effect' => 'fade',
  621. 'method' => 'replace'
  622. ),
  623. );
  624. // If the user has selected a chado table, then we need to
  625. // show the columns for setting terms.
  626. if ($chado_table) {
  627. $schema = chado_get_schema($chado_table);
  628. $pk = $schema['primary key'][0];
  629. // $cv_default = db_select('tripal_cv_defaults', 'tc')
  630. // ->fields('tc', array('field_name'))
  631. // ->condition('table_name', $chado_table)
  632. // ->execute()
  633. // ->fetchField();
  634. $columns = $schema['fields'];
  635. $headers = array(
  636. 'Field Name',
  637. 'Vocabulary',
  638. array(
  639. 'data' => 'Name',
  640. 'nowrap' => TRUE,
  641. ),
  642. 'Term',
  643. 'Term Description',
  644. 'Action'
  645. );
  646. $rows = array();
  647. foreach ($columns AS $column => $detail) {
  648. // Do not show column if it's the primary key or default cv
  649. if ($column != $pk && $column != $cv_default) {
  650. $cvterm_id =
  651. db_select('chado_semweb', 'cs')
  652. ->fields('cs', array('cvterm_id'))
  653. ->condition('chado_table', $chado_table)
  654. ->condition('chado_column', $column)
  655. ->execute()
  656. ->fetchField();
  657. $sw_voc = '';
  658. $sw_term = '';
  659. $sw_desc = '';
  660. $sw_accession = '';
  661. if($cvterm_id) {
  662. $term = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
  663. $sw_voc = $term->cv_id->name;
  664. $sw_term = $term->name;
  665. $sw_accession = l($term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession,
  666. 'cv/lookup/' . $term->dbxref_id->db_id->name . '/' . $term->dbxref_id->accession,
  667. array('attributes' => array('target' => '_blank')));
  668. $sw_desc = $term->definition;
  669. }
  670. $rows[] = array(
  671. $column,
  672. $sw_voc,
  673. $sw_term,
  674. $sw_accession,
  675. $sw_desc,
  676. array(
  677. 'data' => l('Edit', '/admin/tripal/storage/chado/semweb/edit/' . $chado_table . '/' . $column) . ' | ' .
  678. l('Reset', '/admin/tripal/storage/chado/semweb/reset/' . $chado_table . '/' . $column),
  679. 'nowrap' => TRUE,
  680. ),
  681. );
  682. }
  683. }
  684. $output = theme('table', array(
  685. 'header' => $headers,
  686. 'rows' => $rows,
  687. ));
  688. $form['table'] = array(
  689. '#markup' => $output
  690. );
  691. }
  692. $form['#prefix'] = '<div id="tripal-chado-semweb-form">';
  693. $form['#suffix'] = '</div>';
  694. return $form;
  695. }
  696. /**
  697. * Implements hook_form()
  698. * Edit terms used by the semantic web
  699. *
  700. * @param $form
  701. * @param $form_state
  702. * @param $table
  703. * @param $column
  704. * @return $form
  705. */
  706. function tripal_chado_semweb_edit_form($form, &$form_state, $table = NULL, $column = NULL) {
  707. $term_name = array_key_exists('values', $form_state) ? $form_state['values']['term_name'] : '';
  708. $form['chado_table'] = array(
  709. '#markup' => 'Term used for the <strong>' . t($column) . '</strong> column of the chado <strong>' . t($table) . '</strong> table:',
  710. );
  711. $form['table_name'] = array(
  712. '#type' => 'value',
  713. '#value' => $table
  714. );
  715. $form['column'] = array(
  716. '#type' => 'value',
  717. '#value' => $column
  718. );
  719. // If no term has been selected yet then provide the auto complete field.
  720. $form['term_name'] = array(
  721. '#title' => t('Term'),
  722. '#type' => 'textfield',
  723. '#description' => t("The content type must be the name of a term in
  724. a controlled vocabulary and the controlled vocabulary should
  725. already be loaded into Tripal. For example, to create a content
  726. type for storing 'genes', use the 'gene' term from the
  727. Sequence Ontology (SO)."),
  728. '#required' => TRUE,
  729. '#default_value' => $term_name,
  730. '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
  731. );
  732. $form['select_button'] = array(
  733. '#type' => 'button',
  734. '#value' => t('Lookup Term'),
  735. '#name' => 'select_cvterm',
  736. '#ajax' => array(
  737. 'callback' => "tripal_chado_semweb_form_ajax_callback",
  738. 'wrapper' => "tripal-chado-semweb-edit-form",
  739. 'effect' => 'fade',
  740. 'method' => 'replace'
  741. ),
  742. );
  743. if ($term_name) {
  744. $form['terms_list'] = array(
  745. '#type' => 'fieldset',
  746. '#title' => t('Matching Terms'),
  747. '#description' => t('Please select the term the best matches the
  748. content type you want to create. If the same term exists in
  749. multiple vocabularies you will see more than one option below.')
  750. );
  751. $match = array(
  752. 'name' => $term_name,
  753. );
  754. $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
  755. $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
  756. $num_terms = 0;
  757. foreach ($terms as $term) {
  758. // Save the user a click by setting the default value as 1 if there's
  759. // only one matching term.
  760. $default = FALSE;
  761. $attrs = array();
  762. if ($num_terms == 0 and count($terms) == 1) {
  763. $default = TRUE;
  764. $attrs = array('checked' => 'checked');
  765. }
  766. $form['terms_list']['term-' . $term->cvterm_id] = array(
  767. '#type' => 'checkbox',
  768. '#title' => $term->name,
  769. '#default_value' => $default,
  770. '#attributes' => $attrs,
  771. '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
  772. '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '. ' .
  773. '<br><b>Definition:</b> ' . $term->definition,
  774. );
  775. $num_terms++;
  776. }
  777. if ($num_terms == 0) {
  778. $form['terms_list']['none'] = array(
  779. '#type' => 'item',
  780. '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
  781. );
  782. }
  783. // Add in the button for the cases of no terms or too many.
  784. $form['submit_button'] = array(
  785. '#type' => 'submit',
  786. '#value' => t('Use this term'),
  787. '#name' => 'use_cvterm'
  788. );
  789. }
  790. $form['cancel_button'] = array(
  791. '#type' => 'button',
  792. '#value' => t('Cancel'),
  793. '#name' => 'cancel_button',
  794. '#limit_validation_errors' => array()
  795. );
  796. $form['#prefix'] = '<div id = "tripal-chado-semweb-edit-form">';
  797. $form['#suffix'] = '</div>';
  798. return $form;
  799. }
  800. /**
  801. * Implements hook_form_validate()
  802. *
  803. * Validate function for editing the semantic web term
  804. *
  805. * @param unknown $form
  806. * @param unknown $form_state
  807. */
  808. function tripal_chado_semweb_edit_form_validate($form, &$form_state) {
  809. if (array_key_exists('clicked_button', $form_state)) {
  810. if ($form_state['clicked_button']['#name'] =='use_cvterm') {
  811. $cvterm_id = NULL;
  812. // Make sure we have a cvterm selected
  813. $num_selected = 0;
  814. foreach ($form_state['values'] as $key => $value) {
  815. $matches = array();
  816. if (preg_match("/^term-(\d+)$/", $key, $matches) and
  817. $form_state['values']['term-' . $matches[1]]) {
  818. $cvterm_id = $matches[1];
  819. $num_selected++;
  820. }
  821. }
  822. if ($num_selected == 0) {
  823. form_set_error('', 'Please select at least one term.');
  824. }
  825. else if ($num_selected > 1) {
  826. form_set_error('term-' . $cvterm_id, 'Please select only one term from the list below.');
  827. }
  828. else {
  829. $form_state['values']['#selected_cvterm_id'] = $cvterm_id;
  830. }
  831. }
  832. else if ($form_state['clicked_button']['#name'] =='cancel_button') {
  833. $table_name = $form_state['values']['table_name'];
  834. drupal_goto('/admin/tripal/storage/chado/semweb/' . $table_name);
  835. }
  836. }
  837. }
  838. /**
  839. * Implements hook_form_submit()
  840. *
  841. * Submit function for editing the semantic web term
  842. *
  843. * @param unknown $form
  844. * @param unknown $form_state
  845. */
  846. function tripal_chado_semweb_edit_form_submit($form, &$form_state) {
  847. if (array_key_exists('clicked_button', $form_state) && $form_state['clicked_button']['#name'] =='use_cvterm') {
  848. $table_name = $form_state['values']['table_name'];
  849. $column = $form_state['values']['column'];
  850. $cvterm_id = $form_state['values']['#selected_cvterm_id'];
  851. // Check if there is already a record
  852. $record_id =
  853. db_select('chado_semweb', 'cs')
  854. ->fields('cs', array('chado_semweb_id'))
  855. ->condition('chado_table', $table_name)
  856. ->condition('chado_column', $column)
  857. ->execute()
  858. ->fetchField();
  859. // If the record exists, update it
  860. if ($record_id) {
  861. db_update('chado_semweb')
  862. ->fields(array(
  863. 'cvterm_id' => $cvterm_id
  864. ))
  865. ->condition('chado_semweb_id', $record_id)
  866. ->execute();
  867. }
  868. // Otherwise, insert a new record
  869. else {
  870. db_insert('chado_semweb')
  871. ->fields(array(
  872. 'chado_table' => $table_name,
  873. 'chado_column' => $column,
  874. 'cvterm_id' => $cvterm_id
  875. ))
  876. ->execute();
  877. }
  878. drupal_set_message('The term settings have been saved.');
  879. drupal_goto('/admin/tripal/storage/chado/semweb/' . $table_name);
  880. }
  881. }
  882. /**
  883. * Implements hook_form()
  884. * Reset term used by semantic web
  885. *
  886. * @param $form
  887. * @param $form_state
  888. * @param $table
  889. * @param $column
  890. * @return $form
  891. */
  892. function tripal_chado_semweb_reset_form($form, &$form_state, $table = NULL, $column = NULL) {
  893. $term_name = array_key_exists('values', $form_state) ? $form_state['values']['term_name'] : '';
  894. $form['chado_table'] = array(
  895. '#markup' => 'Are you sure you want to remove the use of this term? ',
  896. );
  897. $form['table_name'] = array(
  898. '#type' => 'value',
  899. '#value' => $table
  900. );
  901. $form['column'] = array(
  902. '#type' => 'value',
  903. '#value' => $column
  904. );
  905. $form['submit_button'] = array(
  906. '#type' => 'submit',
  907. '#value' => t('Reset'),
  908. '#name' => 'reset_term'
  909. );
  910. $form['cancel_button'] = array(
  911. '#type' => 'button',
  912. '#value' => t('Cancel'),
  913. '#name' => 'cancel_button',
  914. '#limit_validation_errors' => array()
  915. );
  916. return $form;
  917. }
  918. /**
  919. * Implements hook_form_validate()
  920. *
  921. * Validate function for resetting the semantic web term
  922. *
  923. * @param unknown $form
  924. * @param unknown $form_state
  925. */
  926. function tripal_chado_semweb_reset_form_validate($form, &$form_state) {
  927. if (array_key_exists('clicked_button', $form_state)) {
  928. if ($form_state['clicked_button']['#name'] =='use_cvterm') {
  929. $cvterm_id = NULL;
  930. // Make sure we have a cvterm selected
  931. $num_selected = 0;
  932. foreach ($form_state['values'] as $key => $value) {
  933. $matches = array();
  934. if (preg_match("/^term-(\d+)$/", $key, $matches) and
  935. $form_state['values']['term-' . $matches[1]]) {
  936. $cvterm_id = $matches[1];
  937. $num_selected++;
  938. }
  939. }
  940. if ($num_selected == 0) {
  941. form_set_error('', 'Please select at least one term.');
  942. }
  943. else if ($num_selected > 1) {
  944. form_set_error('term-' . $cvterm_id, 'Please select only one term from the list below.');
  945. }
  946. else {
  947. $form_state['values']['#selected_cvterm_id'] = $cvterm_id;
  948. }
  949. }
  950. else if ($form_state['clicked_button']['#name'] =='cancel_button') {
  951. $table_name = $form_state['values']['table_name'];
  952. drupal_goto('/admin/tripal/storage/chado/semweb/' . $table_name);
  953. }
  954. }
  955. }
  956. /**
  957. * Implements hook_form_submit()
  958. *
  959. * Submit function for editing the semantic web term
  960. *
  961. * @param unknown $form
  962. * @param unknown $form_state
  963. */
  964. function tripal_chado_semweb_reset_form_submit($form, &$form_state) {
  965. if (array_key_exists('clicked_button', $form_state) && $form_state['clicked_button']['#name'] =='reset_term') {
  966. $table_name = $form_state['values']['table_name'];
  967. $column = $form_state['values']['column'];
  968. // Check if there is already a record
  969. $record_id =
  970. db_select('chado_semweb', 'cs')
  971. ->fields('cs', array('chado_semweb_id'))
  972. ->condition('chado_table', $table_name)
  973. ->condition('chado_column', $column)
  974. ->execute()
  975. ->fetchField();
  976. // If the record exists, reset it
  977. if ($record_id) {
  978. db_update('chado_semweb')
  979. ->fields(array(
  980. 'cvterm_id' => NULL
  981. ))
  982. ->condition('chado_semweb_id', $record_id)
  983. ->execute();
  984. }
  985. drupal_set_message('The term settings have been reset.');
  986. drupal_goto('/admin/tripal/storage/chado/semweb/' . $table_name);
  987. }
  988. }
  989. /**
  990. *
  991. */
  992. function tripal_chado_semweb_form_ajax_callback($form, $form_state) {
  993. return $form;
  994. }