tripal_chado.semweb.inc 32 KB

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