tripal_chado.semweb.inc 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748
  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_TCONTACT();
  33. tripal_chado_populate_vocab_TPUB();
  34. tripal_chado_populate_vocab_UO();
  35. }
  36. /**
  37. * Adds the friend of a friend database and terms.
  38. */
  39. function tripal_chado_populate_vocab_FOAF() {
  40. tripal_insert_cv('foaf','Friend of a Friend');
  41. tripal_insert_db(array(
  42. 'name' => 'foaf',
  43. 'description' => 'Friend of a Friend',
  44. 'url' => 'http://www.foaf-project.org/',
  45. 'urlprefix' => 'http://xmlns.com/foaf/spec/#',
  46. ));
  47. tripal_insert_cv('foaf','Friend of a Friend. A dictionary of people-related terms that can be used in structured data).');
  48. }
  49. /**
  50. * Adds the RDFS database and terms.
  51. */
  52. function tripal_chado_populate_vocab_RDFS() {
  53. tripal_insert_db(array(
  54. 'name' => 'rdfs',
  55. 'description' => 'Resource Description Framework Schema',
  56. 'url' => 'https://www.w3.org/TR/rdf-schema/',
  57. 'urlprefix' => 'https://www.w3.org/TR/rdf-schema/#ch_',
  58. ));
  59. tripal_insert_cv('rdfs','Resource Description Framework Schema');
  60. $name = tripal_insert_cvterm(array(
  61. 'id' => 'rdfs:type',
  62. 'name' => 'type',
  63. 'cv_name' => 'rdfs',
  64. 'definition' => 'The type of resource.',
  65. ));
  66. $name = tripal_insert_cvterm(array(
  67. 'id' => 'rdfs:label',
  68. 'name' => 'label',
  69. 'cv_name' => 'rdfs',
  70. 'definition' => 'A human-readable version of a resource\'s name.',
  71. ));
  72. }
  73. /**
  74. * Adds the Schema.org database and terms.
  75. */
  76. function tripal_chado_populate_vocab_SCHEMA() {
  77. tripal_insert_db(array(
  78. 'name' => 'schema',
  79. 'description' => 'Schema.org.',
  80. 'url' => 'https://schema.org/',
  81. 'urlprefix' => 'https://schema.org/{accession}',
  82. ));
  83. 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.');
  84. $term = tripal_insert_cvterm(array(
  85. 'id' => 'schema:name',
  86. 'name' => 'name',
  87. 'cv_name' => 'schema',
  88. 'definition' => 'The name of the item.',
  89. ));
  90. tripal_associate_chado_semweb_term(NULL, 'name', $term);
  91. $term = tripal_insert_cvterm(array(
  92. 'id' => 'schema:alternateName',
  93. 'name' => 'alternateName',
  94. 'cv_name' => 'schema',
  95. 'definition' => 'An alias for the item.',
  96. ));
  97. $term = tripal_insert_cvterm(array(
  98. 'id' => 'schema:comment',
  99. 'name' => 'comment',
  100. 'cv_name' => 'schema',
  101. 'definition' => 'Comments, typically from users.',
  102. ));
  103. tripal_associate_chado_semweb_term(NULL, 'comment', $term);
  104. $term = tripal_insert_cvterm(array(
  105. 'id' => 'schema:description',
  106. 'name' => 'description',
  107. 'cv_name' => 'schema',
  108. 'definition' => 'A description of the item.',
  109. ));
  110. tripal_associate_chado_semweb_term(NULL, 'description', $term);
  111. tripal_associate_chado_semweb_term('organism', 'comment', $term);
  112. $term = tripal_insert_cvterm(array(
  113. 'id' => 'schema:publication',
  114. 'name' => 'publication',
  115. 'cv_name' => 'schema',
  116. 'definition' => 'A publication event associated with the item.',
  117. ));
  118. tripal_associate_chado_semweb_term(NULL, 'pub_id', $term);
  119. $term = tripal_insert_cvterm(array(
  120. 'id' => 'schema:url',
  121. 'name' => 'url',
  122. 'cv_name' => 'schema',
  123. 'definition' => 'URL of the item.',
  124. ));
  125. tripal_associate_chado_semweb_term('db', 'URL', $term);
  126. // Typically the type_id field is used for distinguishing between records
  127. // but in the case that it isn't then we need to associate a term with it
  128. // An entity already has a type so if that type is not dicated by the
  129. // type_id field then what is in the type_id should therefore be an
  130. // "additionalType". Therefore we need to add and map this term to all
  131. // of the appropriate type_id fields.
  132. $term = tripal_insert_cvterm(array(
  133. 'id' => 'schema:additionalType',
  134. 'name' => 'additionalType',
  135. 'cv_name' => 'An additional type for the item, typically used for adding more specific types from external vocabularies in microdata syntax. This is a relationship between something and a class that the thing is in.',
  136. 'definition' => 'URL of the item.',
  137. ));
  138. $tables = chado_get_table_names(TRUE);
  139. foreach ($tables as $table) {
  140. $schema = chado_get_schema($table);
  141. // The type_id for the organism is infraspecific type, so don't make
  142. // the association for that type.
  143. if ($table == 'organism') {
  144. continue;
  145. }
  146. if (in_array("type_id", array_keys($schema['fields']))) {
  147. tripal_associate_chado_semweb_term($table, 'type_id', $term);
  148. }
  149. }
  150. }
  151. /**
  152. * Adds the SemanticScience database and terms.
  153. */
  154. function tripal_chado_populate_vocab_SIO() {
  155. tripal_insert_db(array(
  156. 'name' => 'SIO',
  157. 'description' => 'Semanticscience Integrated Ontology.',
  158. 'url' => 'http://sio.semanticscience.org/',
  159. 'urlprefix' => 'http://semanticscience.org/resource/{db}_{accession}',
  160. ));
  161. 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.');
  162. $term = tripal_insert_cvterm(array(
  163. 'id' => 'SIO:000493',
  164. 'name' => 'clause',
  165. 'cv_name' => 'SIO',
  166. 'definition' => 'A clause consists of a subject and a predicate.',
  167. ));
  168. $term = tripal_insert_cvterm(array(
  169. 'id' => 'SIO:000631',
  170. 'name' => 'references',
  171. 'cv_name' => 'SIO',
  172. 'definition' => 'references is a relation between one entity and the entity that it makes reference to by name, but is not described by it.',
  173. ));
  174. }
  175. /**
  176. * Adds the EDAM database and terms.
  177. */
  178. function tripal_chado_populate_vocab_EDAM() {
  179. tripal_insert_db(array(
  180. 'name' => 'data',
  181. 'description' => 'Bioinformatics operations, data types, formats, identifiers and topics.',
  182. 'url' => 'http://edamontology.org/page',
  183. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  184. ));
  185. tripal_insert_db(array(
  186. 'name' => 'EDAM',
  187. 'description' => 'Bioinformatics operations, data types, formats, identifiers and topics.',
  188. 'url' => 'http://edamontology.org/page',
  189. 'urlprefix' => 'http://edamontology.org/{db}_{accession}',
  190. ));
  191. tripal_insert_cv('data','Bioinformatics operations, data types, formats, identifiers and topics.');
  192. $term = tripal_insert_cvterm(array(
  193. 'id' => 'data:1249',
  194. 'name' => 'Sequence length',
  195. 'cv_name' => 'EDAM',
  196. 'definition' => 'The size (length) of a sequence, subsequence or region in a sequence, or range(s) of lengths.',
  197. ));
  198. tripal_associate_chado_semweb_term('feature', 'seqlen', $term);
  199. $term = tripal_insert_cvterm(array(
  200. 'id' => 'data:2190',
  201. 'name' => 'Sequence checksum',
  202. 'cv_name' => 'EDAM',
  203. 'definition' => 'A fixed-size datum calculated (by using a hash function) for a molecular sequence, typically for purposes of error detection or indexing.',
  204. ));
  205. tripal_associate_chado_semweb_term('feature', 'md5checksum', $term);
  206. $term = tripal_insert_cvterm(array(
  207. 'id' => 'data:2091',
  208. 'name' => 'Accession',
  209. 'cv_name' => 'EDAM',
  210. 'definition' => 'A persistent (stable) and unique identifier, typically identifying an object (entry) from a database.',
  211. ));
  212. tripal_associate_chado_semweb_term(NULL, 'dbxref_id', $term);
  213. $term = tripal_insert_cvterm(array(
  214. 'id' => 'data:2044',
  215. 'name' => 'Sequence',
  216. 'cv_name' => 'EDAM',
  217. 'definition' => 'One or more molecular sequences, possibly with associated annotation..',
  218. ));
  219. tripal_associate_chado_semweb_term('feature', 'residues', $term);
  220. $term = tripal_insert_cvterm(array(
  221. 'id' => 'data:0842',
  222. 'name' => 'Identifier',
  223. 'cv_name' => 'EDAM',
  224. '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).',
  225. ));
  226. tripal_associate_chado_semweb_term(NULL, 'uniquename', $term);
  227. $term = tripal_insert_cvterm(array(
  228. 'id' => 'data:2968',
  229. 'name' => 'Image',
  230. 'cv_name' => 'EDAM',
  231. 'definition' => 'Biological or biomedical data has been rendered into an image, typically for display on screen.',
  232. ));
  233. tripal_associate_chado_semweb_term(NULL, 'eimage_id', $term);
  234. $term = tripal_insert_cvterm(array(
  235. 'id' => 'data:1274',
  236. 'name' => 'Map',
  237. 'cv_name' => 'EDAM',
  238. 'definition' => 'A map of (typically one) DNA sequence annotated with positional or non-positional features.',
  239. ));
  240. tripal_associate_chado_semweb_term(NULL, 'eimage_id', $term);
  241. $term = tripal_insert_cvterm(array(
  242. 'id' => 'data:1278',
  243. 'name' => 'Genetic map',
  244. 'cv_name' => 'EDAM',
  245. '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.',
  246. ));
  247. tripal_associate_chado_semweb_term('featuremap', 'featuremap_id', $term);
  248. $term = tripal_insert_cvterm(array(
  249. 'id' => 'data:1280',
  250. 'name' => 'Physical map',
  251. 'cv_name' => 'EDAM',
  252. '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.',
  253. ));
  254. tripal_associate_chado_semweb_term('featuremap', 'featuremap_id', $term);
  255. $term = tripal_insert_cvterm(array(
  256. 'id' => 'data:2012',
  257. 'name' => 'Sequence coordinates',
  258. 'cv_name' => 'EDAM',
  259. 'definition' => 'A position in a map (for example a genetic map), either a single position (point) or a region / interval.',
  260. ));
  261. $term = tripal_insert_cvterm(array(
  262. 'id' => 'data:1056',
  263. 'name' => 'Database name',
  264. 'cv_name' => 'EDAM',
  265. 'definition' => 'The name of a biological or bioinformatics database.',
  266. ));
  267. tripal_associate_chado_semweb_term('db', 'name', $term);
  268. }
  269. /**
  270. * Adds the Eagle-i Resource Ontology database and terms.
  271. */
  272. function tripal_chado_populate_vocab_ERO() {
  273. tripal_insert_db(array(
  274. 'name' => 'ERO',
  275. 'description' => 'The Eagle-I Research Resource Ontology',
  276. 'url' => 'http://purl.bioontology.org/ontology/ERO',
  277. 'urlprefix' => 'http://purl.bioontology.org/ontology/ERO/{db}:{accession}',
  278. ));
  279. 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/).');
  280. $term = tripal_insert_cvterm(array(
  281. 'id' => 'ERO:0001716',
  282. 'name' => 'database',
  283. 'cv_name' => 'ero',
  284. 'definition' => 'A database is an organized collection of data, today typically in digital form.',
  285. ));
  286. }
  287. /**
  288. * Adds the Information Artifact Ontology database and terms.
  289. */
  290. function tripal_chado_populate_vocab_OBI() {
  291. tripal_insert_db(array(
  292. 'name' => 'OBI',
  293. 'description' => 'The Ontology for Biomedical Investigation.',
  294. 'url' => 'http://obi-ontology.org/page/Main_Page',
  295. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  296. ));
  297. 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.');
  298. $term = tripal_insert_cvterm(array(
  299. 'id' => 'OBI:0100026',
  300. 'name' => 'organism',
  301. 'cv_name' => 'obi',
  302. '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.',
  303. ));
  304. tripal_associate_chado_semweb_term(NULL, 'organism_id', $term);
  305. }
  306. /**
  307. * Adds the Ontology for genetic interval database and terms.
  308. */
  309. function tripal_chado_populate_vocab_OGI() {
  310. tripal_insert_db(array(
  311. 'name' => 'OGI',
  312. 'description' => 'Ontology for genetic interval.',
  313. 'url' => 'http://purl.bioontology.org/ontology/OGI',
  314. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  315. ));
  316. 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.');
  317. $term = tripal_insert_cvterm(array(
  318. 'id' => 'OGI:0000021',
  319. 'name' => 'location on map',
  320. 'cv_name' => 'ogi',
  321. 'definition' => '',
  322. ));
  323. tripal_associate_chado_semweb_term('featurepos', 'mappos', $term);
  324. }
  325. /**
  326. * Adds the Information Artifact Ontology database and terms.
  327. */
  328. function tripal_chado_populate_vocab_IAO() {
  329. tripal_insert_db(array(
  330. 'name' => 'IAO',
  331. 'description' => 'The Information Artifact Ontology (IAO).',
  332. 'url' => 'https://github.com/information-artifact-ontology/IAO/',
  333. 'urlprefix' => 'http://purl.obolibrary.org/obo/IAO_',
  334. ));
  335. tripal_insert_cv('IAO','Information Artifact Ontology is a new ' .
  336. 'ontology of information entities, originally driven by work by the ' .
  337. 'OBI digital entity and realizable information entity branch.');
  338. $term = tripal_insert_cvterm(array(
  339. 'id' => 'IAO:0000115',
  340. 'name' => 'definition',
  341. 'cv_name' => 'iao',
  342. 'definition' => 'The official OBI definition, explaining the meaning of ' .
  343. 'a class or property. Shall be Aristotelian, formalized and normalized. ' .
  344. 'Can be augmented with colloquial definitions.',
  345. ));
  346. tripal_associate_chado_semweb_term(NULL, 'definition', $term);
  347. $term = tripal_insert_cvterm(array(
  348. 'id' => 'IAO:0000129',
  349. 'name' => 'version number',
  350. 'cv_name' => 'IAO',
  351. 'definition' => 'A version number is an ' .
  352. 'information content entity which is a sequence of characters ' .
  353. 'borne by part of each of a class of manufactured products or its ' .
  354. 'packaging and indicates its order within a set of other products ' .
  355. 'having the same name.',
  356. ));
  357. tripal_associate_chado_semweb_term('analysis', 'programversion', $term);
  358. $term = tripal_insert_cvterm(array(
  359. 'id' => 'IAO:0000064',
  360. 'name' => 'algorithm',
  361. 'cv_name' => 'IAO',
  362. 'definition' => 'An algorithm is a set of instructions for performing a paticular calculation.',
  363. ));
  364. tripal_associate_chado_semweb_term('analysis', 'algorithm', $term);
  365. }
  366. /**
  367. * Adds terms to the 'local' database.
  368. *
  369. * These are terms where an appropriate match could not be found in any other
  370. * ontology.
  371. */
  372. function tripal_chado_populate_vocab_LOCAL() {
  373. tripal_insert_db(array(
  374. 'name' => 'null',
  375. 'description' => 'No online database.'
  376. ));
  377. tripal_insert_db(array(
  378. 'name' => 'local',
  379. 'description' => 'Terms created for this site.',
  380. 'url' => '/cv/lookup',
  381. 'urlprefix' => '/cv/lookup/{db}/{accession}',
  382. ));
  383. // ----------------
  384. // Add the various CV's that fall under the local DB.
  385. // ----------------
  386. tripal_insert_cv(
  387. 'local',
  388. 'Locally created terms.'
  389. );
  390. tripal_insert_cv(
  391. 'organism_property',
  392. 'A local vocabulary that contains locally defined properties for organisms'
  393. );
  394. tripal_insert_cv(
  395. 'tripal_phylogeny',
  396. 'Terms used by the Tripal phylotree module for phylogenetic and taxonomic trees.'
  397. );
  398. tripal_insert_cv(
  399. 'synonym_type',
  400. 'A local vocabulary that contains synonym types (e.g. exact, broad, narrow, related).'
  401. );
  402. // Add cv for relationship types
  403. tripal_insert_cv(
  404. 'feature_relationship',
  405. 'A local vocabulary that contains types of relationships between features.'
  406. );
  407. // The feature_property CV may already exists. It comes with Chado, but
  408. // we need to add it just in case it doesn't get added before the feature
  409. // module is installed. But as of Tripal v3.0 the Chado version of this
  410. // vocabulary is no longer loaded by default.
  411. tripal_insert_cv(
  412. 'feature_property',
  413. 'A local vocabulary that contains properties for genomic features'
  414. );
  415. // Add the cv for contact properties. This is a default vocabulary in the event
  416. // that a user does not want to use the tripal_contact vocabulary
  417. tripal_insert_cv(
  418. 'contact_property',
  419. 'A local vocabulary that contains properties for contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
  420. );
  421. // add the cv for the contact type. This is a default vocabulary in the event
  422. // that a user does not want to use the tripal_contact vocabulary
  423. tripal_insert_cv(
  424. 'contact_type',
  425. 'A local vocabulary that contains types of contacts. This can be used if the tripal_contact vocabulary (which is default for contacts in Tripal) is not desired.'
  426. );
  427. // Add the cv for the tripal_contact vocabulary which is loaded via the OBO
  428. tripal_insert_cv(
  429. 'tripal_contact',
  430. 'A local vocabulary that contains 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.'
  431. );
  432. // add the cv for contact relationships
  433. tripal_insert_cv(
  434. 'contact_relationship',
  435. 'A local vocabulary that contains types of relationships between contacts.'
  436. );
  437. tripal_insert_cv(
  438. 'featuremap_units',
  439. 'A local vocabulary that contains map unit types for the unittype_id column of the featuremap table.'
  440. );
  441. tripal_insert_cv(
  442. 'featurepos_property',
  443. 'A local vocabulary that contains terms map properties.'
  444. );
  445. tripal_insert_cv(
  446. 'featuremap_property',
  447. 'A local vocabulary that contains positional types for the feature positions'
  448. );
  449. tripal_insert_cv(
  450. 'library_property',
  451. 'A local vocabulary that contains properties for libraries.'
  452. );
  453. tripal_insert_cv(
  454. 'library_type',
  455. 'A local vocabulary that contains terms for types of libraries (e.g. BAC, cDNA, FOSMID, etc).'
  456. );
  457. // Add the cv for project properties
  458. tripal_insert_cv(
  459. 'project_property',
  460. 'A local vocabulary that contains properties for projects'
  461. );
  462. // Add cv for relationship types
  463. tripal_insert_cv(
  464. 'project_relationship',
  465. 'A local vocabulary that contains Types of relationships between projects.'
  466. );
  467. // Add the cv for pub properties
  468. tripal_insert_cv(
  469. 'tripal_pub',
  470. 'A local vocabulary that contains 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.'
  471. );
  472. // Add the cv for pub types
  473. tripal_insert_cv(
  474. 'pub_type',
  475. 'A local vocabulary that contains types of publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
  476. );
  477. // Add the cv for pub properties
  478. tripal_insert_cv(
  479. 'pub_property',
  480. 'A local vocabulary that contains properties for publications. This can be used if the tripal_pub vocabulary (which is default for publications in Tripal) is not desired.'
  481. );
  482. // Add cv for relationship types
  483. tripal_insert_cv(
  484. 'pub_relationship',
  485. 'A local vocabulary that contains types of relationships between publications.'
  486. );
  487. // Add cv for relationship types
  488. tripal_insert_cv(
  489. 'stock_relationship',
  490. 'A local vocabulary that contains types of relationships between stocks.'
  491. );
  492. tripal_insert_cv(
  493. 'stock_property',
  494. 'A local vocabulary that contains properties for stocks.'
  495. );
  496. tripal_insert_cv(
  497. 'stock_type',
  498. 'A local vocabulary that contains a list of types for stocks.'
  499. );
  500. tripal_insert_cv(
  501. 'tripal_analysis',
  502. 'A local vocabulary that contains terms used for analyses.'
  503. );
  504. //-----------------------------
  505. // Misc Terms
  506. //-----------------------------
  507. $term = tripal_insert_cvterm(array(
  508. 'id' => 'local:property',
  509. 'name' => 'property',
  510. 'cv_name' => 'local',
  511. 'definition' => 'A generic term indicating that represents an attribute, quality or characteristic of something.',
  512. ));
  513. //-----------------------------
  514. // Terms for base table fields
  515. //-----------------------------
  516. $term = tripal_insert_cvterm(array(
  517. 'id' => 'local:timelastmodified',
  518. 'name' => 'time_last_modified',
  519. 'cv_name' => 'local',
  520. 'definition' => 'The time at which the record was last modified.',
  521. ));
  522. tripal_associate_chado_semweb_term(NULL, 'timelastmodified', $term);
  523. $term = tripal_insert_cvterm(array(
  524. 'id' => 'local:timeaccessioned',
  525. 'name' => 'time_accessioned',
  526. 'cv_name' => 'local',
  527. 'definition' => 'The time at which the record was first added.',
  528. ));
  529. tripal_associate_chado_semweb_term(NULL, 'timeaccessioned', $term);
  530. $term = tripal_insert_cvterm(array(
  531. 'id' => 'local:timeexecuted',
  532. 'name' => 'time_executed',
  533. 'cv_name' => 'local',
  534. 'definition' => 'The time when the task was executed.',
  535. ));
  536. tripal_associate_chado_semweb_term(NULL, 'timeexecuted', $term);
  537. $term = tripal_insert_cvterm(array(
  538. 'id' => 'local:infraspecific_type',
  539. 'name' => 'infraspecific_type',
  540. 'definition' => 'The connector type (e.g. subspecies, varietas, forma, etc.) for the infraspecific name',
  541. 'cv_name' => 'local',
  542. ));
  543. tripal_associate_chado_semweb_term('organism', 'type_id', $term);
  544. $term = tripal_insert_cvterm(array(
  545. 'id' => 'local:abbreviation',
  546. 'name' => 'abbreviation',
  547. 'cv_name' => 'local',
  548. 'definition' => 'A shortened name (or abbreviation) for the item.'
  549. ));
  550. tripal_associate_chado_semweb_term('organism', 'abbreviation', $term);
  551. $term = tripal_insert_cvterm(array(
  552. 'id' => 'local:expression',
  553. 'name' => 'expression',
  554. 'definition' => 'Curated expression data',
  555. 'cv_name' => 'local',
  556. ));
  557. $term = tripal_insert_cvterm(array(
  558. 'id' => 'local:is_analysis',
  559. 'name' => 'is_analysis',
  560. 'definition' => 'Indicates if this feature was predicted computationally using another feature.',
  561. 'cv_name' => 'local',
  562. ));
  563. tripal_associate_chado_semweb_term('feature', 'is_analysis', $term);
  564. $term = tripal_insert_cvterm(array(
  565. 'id' => 'local:is_obsolete',
  566. 'name' => 'is_obsolete',
  567. 'definition' => 'Indicates if this record is obsolete.',
  568. 'cv_name' => 'local',
  569. ));
  570. tripal_associate_chado_semweb_term(NULL, 'is_obsolete', $term);
  571. //-----------------------------
  572. // Relationship Terms
  573. //-----------------------------
  574. $term = tripal_insert_cvterm(array(
  575. 'id' => 'local:relationship_subject',
  576. 'name' => 'clause subject',
  577. 'definition' => 'The subject of a relationship clause.',
  578. 'cv_name' => 'local',
  579. ));
  580. tripal_associate_chado_semweb_term(NULL, 'subject_id', $term);
  581. tripal_associate_chado_semweb_term(NULL, 'subject_reagent_id', $term);
  582. tripal_associate_chado_semweb_term(NULL, 'subject_project_id', $term);
  583. $term = tripal_insert_cvterm(array(
  584. 'id' => 'local:relationship_object',
  585. 'name' => 'clause predicate',
  586. 'definition' => 'The object of a relationship clause.',
  587. 'cv_name' => 'local',
  588. ));
  589. tripal_associate_chado_semweb_term(NULL, 'object_id', $term);
  590. tripal_associate_chado_semweb_term(NULL, 'object_reagent_id', $term);
  591. tripal_associate_chado_semweb_term(NULL, 'object_project_id', $term);
  592. $term = tripal_insert_cvterm(array(
  593. 'id' => 'local:relationship_type',
  594. 'name' => 'relationship type',
  595. 'definition' => 'The relationship type.',
  596. 'cv_name' => 'local',
  597. ));
  598. tripal_associate_chado_semweb_term('acquisition_relationship', 'type_id', $term);
  599. tripal_associate_chado_semweb_term('biomaterial_relationship', 'type_id', $term);
  600. tripal_associate_chado_semweb_term('cell_line_relationship', 'type_id', $term);
  601. tripal_associate_chado_semweb_term('contact_relationship', 'type_id', $term);
  602. tripal_associate_chado_semweb_term('element_relationship', 'type_id', $term);
  603. tripal_associate_chado_semweb_term('elementresult_relationship', 'type_id', $term);
  604. tripal_associate_chado_semweb_term('feature_relationship', 'type_id', $term);
  605. tripal_associate_chado_semweb_term('nd_reagent_relationship', 'type_id', $term);
  606. tripal_associate_chado_semweb_term('phylonode_relationship', 'type_id', $term);
  607. tripal_associate_chado_semweb_term('project_relationship', 'type_id', $term);
  608. tripal_associate_chado_semweb_term('pub_relationship', 'type_id', $term);
  609. tripal_associate_chado_semweb_term('quantification_relationship', 'type_id', $term);
  610. tripal_associate_chado_semweb_term('stock_relationship', 'type_id', $term);
  611. //-----------------------------
  612. // NCBI Organism Property Terms
  613. //-----------------------------
  614. // TODO: these probably have real terms we can use.
  615. $term = tripal_insert_cvterm(array(
  616. 'id' => 'locak:rank',
  617. 'name' => 'rank',
  618. 'definition' => 'A taxonmic rank',
  619. 'cv_name' => 'local',
  620. ));
  621. $terms = array(
  622. 'lineage',
  623. 'genetic_code',
  624. 'genetic_code_name',
  625. 'mitochondrial_genetic_code',
  626. 'mitochondrial_genetic_code_name',
  627. 'division',
  628. 'genbank_common_name',
  629. 'synonym',
  630. 'other_name',
  631. 'equivalent_name',
  632. 'anamorph'
  633. );
  634. $options = array('update_existing' => TRUE);
  635. foreach ($terms as $term) {
  636. $value = array(
  637. 'name' => $term,
  638. 'definition' => '',
  639. 'cv_name' => 'organism_property',
  640. 'is_relationship' => 0,
  641. 'db_name' => 'local'
  642. );
  643. tripal_insert_cvterm($value, $options);
  644. }
  645. //---------------------
  646. // Phylogeny Tree Terms
  647. //---------------------
  648. // Add the terms used to identify nodes in the tree.
  649. tripal_insert_cvterm(
  650. array(
  651. 'name' => 'phylo_leaf',
  652. 'definition' => 'A leaf node in a phylogenetic tree.',
  653. 'cv_name' => 'tripal_phylogeny',
  654. 'is_relationship' => 0,
  655. 'db_name' => 'local'
  656. ),
  657. array('update_existing' => TRUE)
  658. );
  659. // Add the terms used to identify nodes in the tree.
  660. tripal_insert_cvterm(array(
  661. 'name' => 'phylo_root',
  662. 'definition' => 'The root node of a phylogenetic tree.',
  663. 'cv_name' => 'tripal_phylogeny',
  664. 'is_relationship' => 0,
  665. 'db_name' => 'local'
  666. ));
  667. // Add the terms used to identify nodes in the tree.
  668. tripal_insert_cvterm(array(
  669. 'name' => 'phylo_interior',
  670. 'definition' => 'An interior node in a phylogenetic tree.',
  671. 'cv_name' => 'tripal_phylogeny',
  672. 'is_relationship' => 0,
  673. 'db_name' => 'local'
  674. ));
  675. // Add the terms used to identify nodes in the tree.
  676. tripal_insert_cvterm(array(
  677. 'name' => 'taxonomy',
  678. 'definition' => 'A term used to indicate if a phylotree is a taxonomic tree',
  679. 'cv_name' => 'tripal_phylogeny',
  680. 'is_relationship' => 0,
  681. 'db_name' => 'local'
  682. ));
  683. //---------------------
  684. // Synonym Types Terms
  685. //---------------------
  686. tripal_insert_cvterm(array(
  687. 'name' => 'exact',
  688. 'definition' => 'An exact equivalent; interchangeable with the term name.',
  689. 'cv_name' => 'synonym_type',
  690. 'db_name' => 'local',
  691. ), array('force_db_change' => TRUE));
  692. tripal_insert_cvterm(array(
  693. 'name' => 'broad',
  694. 'definition' => 'The synonym is broader than the name.',
  695. 'cv_name' => 'synonym_type',
  696. 'db_name' => 'local',
  697. ), array('force_db_change' => TRUE));
  698. tripal_insert_cvterm(array(
  699. 'name' => 'narrow',
  700. 'definition' => 'The synonym is narrower or more precise than the name.',
  701. 'cv_name' => 'synonym_type',
  702. 'db_name' => 'local',
  703. ), array('force_db_change' => TRUE));
  704. tripal_insert_cvterm(array(
  705. 'name' => 'related',
  706. 'definition' => 'The synonym is related in some way.',
  707. 'cv_name' => 'synonym_type',
  708. 'db_name' => 'local'
  709. ), array('force_db_change' => TRUE));
  710. //--------------
  711. // Project Terms
  712. //--------------
  713. // Insert cvterm 'Project Description' into cvterm table of chado
  714. // database. This CV term is used to keep track of the project
  715. // description in the projectprop table.
  716. tripal_insert_cvterm(array(
  717. 'name' => 'Project Description',
  718. 'definition' => 'Description of a project',
  719. 'cv_name' => 'project_property',
  720. 'db_name' => 'local'
  721. ), array('force_db_change' => TRUE));
  722. //--------------
  723. // Natural Diversity Terms
  724. //--------------
  725. // add cvterms for the nd_experiment_types
  726. tripal_insert_cvterm(array(
  727. 'name' => 'Genotyping',
  728. 'definition' => 'An experiment where genotypes of individuals are identified.',
  729. 'cv_name' => 'nd_experiment_types',
  730. 'db_name' => 'local'
  731. ), array('force_db_change' => TRUE));
  732. tripal_insert_cvterm(array(
  733. 'name' => 'Phenotyping',
  734. 'definition' => 'An experiment where phenotypes of individuals are identified.',
  735. 'cv_name' => 'nd_experiment_types',
  736. 'db_name' => 'local'
  737. ), array('force_db_change' => TRUE));
  738. tripal_insert_cvterm(array(
  739. 'name' => 'Location',
  740. 'definition' => 'The name of the location.',
  741. 'cv_name' => 'nd_geolocation_property',
  742. 'db_name' => 'local'
  743. ), array('force_db_change' => TRUE));
  744. //--------------
  745. // Library Terms
  746. //--------------
  747. // Insert cvterm 'library_description' into cvterm table of chado
  748. // database. This CV term is used to keep track of the library
  749. // description in the libraryprop table.
  750. tripal_insert_cvterm(array(
  751. 'id' => 'local:library_description',
  752. 'name' => 'Library Description',
  753. 'definition' => 'Description of a library',
  754. 'cv_name' => 'library_property',
  755. 'db_name' => 'local'
  756. ), array('force_db_change' => TRUE));
  757. // add cvterms for the map unit types
  758. tripal_insert_cvterm(array(
  759. 'id' => 'local:cdna_library',
  760. 'name' => 'cdna_library',
  761. 'definition' => 'cDNA library',
  762. 'cv_name' => 'library_type',
  763. 'db_name' => 'local'
  764. ), array('force_db_change' => TRUE));
  765. tripal_insert_cvterm(array(
  766. 'id' => 'local:bac_library',
  767. 'name' => 'bac_library',
  768. 'definition' => 'Bacterial Artifical Chromsome (BAC) library',
  769. 'cv_name' => 'library_type',
  770. 'db_name' => 'local'
  771. ), array('force_db_change' => TRUE));
  772. tripal_insert_cvterm(array(
  773. 'id' => 'local:fosmid_library',
  774. 'name' => 'fosmid_library',
  775. 'definition' => 'Fosmid library',
  776. 'cv_name' => 'library_type',
  777. 'db_name' => 'local'
  778. ), array('force_db_change' => TRUE));
  779. tripal_insert_cvterm(array(
  780. 'id' => 'local:cosmid_library',
  781. 'name' => 'cosmid_library',
  782. 'definition' => 'Cosmid library',
  783. 'cv_name' => 'library_type',
  784. 'db_name' => 'local'
  785. ), array('force_db_change' => TRUE));
  786. tripal_insert_cvterm(array(
  787. 'id' => 'local:yac_library',
  788. 'name' => 'yac_library',
  789. 'definition' => 'Yeast Artificial Chromosome (YAC) library',
  790. 'cv_name' => 'library_type',
  791. 'db_name' => 'local'
  792. ), array('force_db_change' => TRUE));
  793. tripal_insert_cvterm(array(
  794. 'id' => 'local:genomic_library',
  795. 'name' => 'genomic_library',
  796. 'definition' => 'Genomic Library',
  797. 'cv_name' => 'library_type',
  798. 'db_name' => 'local'
  799. ), array('force_db_change' => TRUE));
  800. //--------------
  801. // Feature Map
  802. //--------------
  803. // add cvterms for the map unit types
  804. tripal_insert_cvterm(array(
  805. 'name' => 'cM',
  806. 'definition' => 'Centimorgan units',
  807. 'cv_name' => 'featuremap_units',
  808. 'is_relationship' => 0,
  809. 'db_name' => 'local'
  810. ), array('force_db_change' => TRUE));
  811. tripal_insert_cvterm(array(
  812. 'name' => 'bp',
  813. 'definition' => 'Base pairs units',
  814. 'cv_name' => 'featuremap_units',
  815. 'is_relationship' => 0,
  816. 'db_name' => 'local'
  817. ), array('force_db_change' => TRUE));
  818. tripal_insert_cvterm(array(
  819. 'name' => 'bin_unit',
  820. 'definition' => 'The bin unit',
  821. 'cv_name' => 'featuremap_units',
  822. 'is_relationship' => 0,
  823. 'db_name' => 'local'
  824. ), array('force_db_change' => TRUE));
  825. tripal_insert_cvterm(array(
  826. 'name' => 'marker_order',
  827. 'definition' => 'Units simply to define marker order.',
  828. 'cv_name' => 'featuremap_units',
  829. 'is_relationship' => 0,
  830. 'db_name' => 'local'
  831. ), array('force_db_change' => TRUE));
  832. tripal_insert_cvterm(array(
  833. 'name' => 'undefined',
  834. 'definition' => 'A catch-all for an undefined unit type',
  835. 'cv_name' => 'featuremap_units',
  836. 'is_relationship' => 0,
  837. 'db_name' => 'local'
  838. ), array('force_db_change' => TRUE));
  839. // featurepos properties
  840. tripal_insert_cvterm(array(
  841. 'name' => 'start',
  842. 'definition' => 'The start coordinate for a map feature.',
  843. 'cv_name' => 'featurepos_property',
  844. 'is_relationship' => 0,
  845. 'db_name' => 'local'
  846. ), array('force_db_change' => TRUE));
  847. tripal_insert_cvterm(array(
  848. 'name' => 'stop',
  849. 'definition' => 'The end coordinate for a map feature',
  850. 'cv_name' => 'featurepos_property',
  851. 'is_relationship' => 0,
  852. 'db_name' => 'local'
  853. ), array('force_db_change' => TRUE));
  854. // add cvterms for map properties
  855. tripal_insert_cvterm(array(
  856. 'name' => 'Map Dbxref',
  857. 'definition' => 'A unique identifer for the map in a remote database. The '
  858. . 'format is a database abbreviation and a unique accession separated '
  859. . 'by a colon. (e.g. Gramene:tsh1996a)',
  860. 'cv_name' => 'featuremap_property',
  861. 'is_relationship' => 0,
  862. 'db_name' => 'local'
  863. ), array('force_db_change' => TRUE));
  864. tripal_insert_cvterm(array(
  865. 'name' => 'Map Type',
  866. 'definition' => 'The type of Map (e.g. QTL, Physical, etc.)',
  867. 'cv_name' => 'featuremap_property',
  868. 'is_relationship' => 0,
  869. 'db_name' => 'local'
  870. ), array('force_db_change' => TRUE));
  871. tripal_insert_cvterm(array(
  872. 'name' => 'Genome Group',
  873. 'definition' => '',
  874. 'cv_name' => 'featuremap_property',
  875. 'is_relationship' => 0,
  876. 'db_name' => 'local'
  877. ), array('force_db_change' => TRUE));
  878. tripal_insert_cvterm(array(
  879. 'name' => 'URL',
  880. 'definition' => 'A univeral resource locator (URL) reference where the '
  881. . 'publication can be found. For maps found online, this would be '
  882. . 'the web address for the map.',
  883. 'cv_name' => 'featuremap_property',
  884. 'is_relationship' => 0,
  885. 'db_name' => 'local'
  886. ), array('force_db_change' => TRUE));
  887. tripal_insert_cvterm(array(
  888. 'name' => 'Population Type',
  889. 'definition' => 'A brief description of the population type used to generate '
  890. . 'the map (e.g. RIL, F2, BC1, etc).',
  891. 'cv_name' => 'featuremap_property',
  892. 'is_relationship' => 0,
  893. 'db_name' => 'local'
  894. ), array('force_db_change' => TRUE));
  895. tripal_insert_cvterm(array(
  896. 'name' => 'Population Size',
  897. 'definition' => 'The size of the population used to construct the map.',
  898. 'cv_name' => 'featuremap_property',
  899. 'is_relationship' => 0,
  900. 'db_name' => 'local'
  901. ), array('force_db_change' => TRUE));
  902. tripal_insert_cvterm(array(
  903. 'name' => 'Methods',
  904. 'definition' => 'A brief description of the methods used to construct the map.',
  905. 'cv_name' => 'featuremap_property',
  906. 'is_relationship' => 0,
  907. 'db_name' => 'local'
  908. ), array('force_db_change' => TRUE));
  909. tripal_insert_cvterm(array(
  910. 'name' => 'Software',
  911. 'definition' => 'The software used to construct the map.',
  912. 'cv_name' => 'featuremap_property',
  913. 'is_relationship' => 0,
  914. 'db_name' => 'local'
  915. ), array('force_db_change' => TRUE));
  916. //--------------
  917. // Analysis Terms
  918. //--------------
  919. // add analysis_date. This is no longer used (as far as we can tell) but we don't
  920. // get rid of it in case it is used, so just keep it in the Tripal CV
  921. tripal_insert_cvterm(array(
  922. 'name' => 'analysis_date',
  923. 'definition' => 'The date that an analysis was performed.',
  924. 'cv_name' => 'tripal_analysis',
  925. 'is_relationship' => 0,
  926. 'db_name' => 'local'
  927. ), array('update_existing' => TRUE));
  928. // add analysis_short_name. This is no longer used (as far as we can tell) but we don't
  929. // get rid of it in case it is used, so just keep it in the Tripal CV
  930. tripal_insert_cvterm(array(
  931. 'name' => 'analysis_short_name',
  932. 'definition' => 'A computer legible (no spaces or special characters) '
  933. . 'abbreviation for the analysis.',
  934. 'cv_name' => 'tripal_analysis',
  935. 'is_relationship' => 0,
  936. 'db_name' => 'local'
  937. ), array('update_existing' => TRUE));
  938. // the 'analysis_property' vocabulary is for user definable properties wo we
  939. // will add an 'Analysis Type' to this vocubulary
  940. tripal_insert_cvterm(array(
  941. 'name' => 'Analysis Type',
  942. 'definition' => 'The type of analysis that was performed.',
  943. 'cv_name' => 'analysis_property',
  944. 'is_relationship' => 0,
  945. 'db_name' => 'local'
  946. ), array('update_existing' => TRUE));
  947. // Add a term to be used for an inherent 'type_id' for the organism table.
  948. tripal_insert_cvterm(array(
  949. 'id' => 'local:analysis',
  950. 'name' => 'analysis',
  951. 'definition' => 'A process as a method of studying the nature of something ' .
  952. 'or of determining its essential features and their relations. ' .
  953. '(Random House Kernerman Webster\'s College Dictionary, © 2010 K ' .
  954. 'Dictionaries Ltd).',
  955. 'cv_name' => 'local',
  956. ));
  957. // TODO: change this to foaf:Project
  958. tripal_insert_cvterm(array(
  959. 'id' => 'local:project',
  960. 'name' => 'project',
  961. 'definition' => 'A plan or proposal for accomplishing something. ' .
  962. '(American Heritage® Dictionary of the English Language, Fifth Edition. ' .
  963. 'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
  964. 'cv_name' => 'local',
  965. ));
  966. //--------------
  967. // Terms for Content Types
  968. //--------------
  969. tripal_insert_cvterm(array(
  970. 'id' => 'local:contact',
  971. 'name' => 'contact',
  972. 'definition' => 'An entity (e.g. individual or organization) through ' .
  973. 'whom a person can gain access to information, favors, ' .
  974. 'influential people, and the like.',
  975. 'cv_name' => 'local',
  976. ));
  977. tripal_insert_cvterm(array(
  978. 'id' => 'local:relationship',
  979. 'name' => 'relationship',
  980. 'definition' => 'The way in which two things are connected.',
  981. 'cv_name' => 'local',
  982. ));
  983. tripal_insert_cvterm(array(
  984. 'id' => 'local:biomaterial',
  985. 'name' => 'biomaterial',
  986. 'definition' => 'A biomaterial represents the MAGE concept of BioSource, BioSample, ' .
  987. 'and LabeledExtract. It is essentially some biological material (tissue, cells, serum) that ' .
  988. 'may have been processed. Processed biomaterials should be traceable back to raw ' .
  989. 'biomaterials via the biomaterialrelationship table.',
  990. 'cv_name' => 'local',
  991. ));
  992. }
  993. /**
  994. * Adds the Systems Biology Ontology database and terms.
  995. */
  996. function tripal_chado_populate_vocab_SBO() {
  997. tripal_insert_db(array(
  998. 'name' => 'SBO',
  999. 'description' => 'Systems Biology.',
  1000. 'url' => 'http://www.ebi.ac.uk/sbo/main/',
  1001. 'urlprefix' => 'http://purl.obolibrary.org/obo/{db}_{accession}',
  1002. ));
  1003. tripal_insert_cv('sbo','Systems Biology. Terms commonly used in Systems Biology, and in particular in computational modeling.');
  1004. $dbxref = tripal_insert_cvterm(array(
  1005. 'id' => 'SBO:0000358',
  1006. 'name' => 'phenotype',
  1007. 'cv_name' => 'sbo',
  1008. '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.',
  1009. ));
  1010. $dbxref = tripal_insert_cvterm(array(
  1011. 'id' => 'SBO:0000554',
  1012. 'name' => 'database cross reference',
  1013. 'cv_name' => 'sbo',
  1014. 'definition' => 'An annotation which directs one to information contained within a database.',
  1015. ));
  1016. $relationship = tripal_insert_cvterm(array(
  1017. 'id' => 'SBO:0000374',
  1018. 'name' => 'relationship',
  1019. 'cv_name' => 'sbo',
  1020. 'definition' => 'Connectedness between entities and/or interactions representing their relatedness or influence.',
  1021. ));
  1022. }
  1023. /**
  1024. * Adds the Sequence Ontology
  1025. */
  1026. function tripal_chado_populate_vocab_SO() {
  1027. tripal_insert_db(array(
  1028. 'name' => 'SO',
  1029. 'description' => 'Sequence Ontology',
  1030. 'url' => 'http://www.sequenceontology.org',
  1031. 'urlprefix' => 'http://www.sequenceontology.org/browser/current_svn/term/{db}:{accession}',
  1032. ));
  1033. tripal_insert_cv('sequence','The Sequence Ontology.');
  1034. // Add the terms we need for default content types. This needs to be
  1035. // done because the sequence ontology may not already be loaded but we
  1036. // still want to provide these default content types.
  1037. $term = tripal_insert_cvterm(array(
  1038. 'id' => 'SO:0000704',
  1039. 'name' => 'gene',
  1040. 'cv_name' => 'sequence',
  1041. 'definition' => 'A region (or regions) that includes all of the sequence elements necessary to encode a functional transcript. A gene may include regulatory regions, transcribed regions and/or other functional sequence regions. [SO:immuno_workshop]',
  1042. ));
  1043. $term = tripal_insert_cvterm(array(
  1044. 'id' => 'SO:0000234',
  1045. 'name' => 'mRNA',
  1046. 'cv_name' => 'sequence',
  1047. 'definition' => 'Messenger RNA is the intermediate molecule between DNA and protein. It includes UTR and coding sequences. It does not contain introns. [SO:ma]',
  1048. ));
  1049. }
  1050. /**
  1051. * Adds the Software Ontology database and terms.
  1052. */
  1053. function tripal_chado_populate_vocab_SWO() {
  1054. tripal_insert_db(array(
  1055. 'name' => 'SWO',
  1056. 'description' => 'Software Ontology',
  1057. 'url' => 'http://theswo.sourceforge.net/',
  1058. 'urlprefix' => '',
  1059. ));
  1060. tripal_insert_cv('swo','Software Ontology. An ontology representation of the NCBI organismal taxonomy.');
  1061. $term = tripal_insert_cvterm(array(
  1062. 'id' => 'SWO:0000001',
  1063. 'name' => 'software',
  1064. 'cv_name' => 'swo',
  1065. 'definition' => 'Computer software, or generally just software, is any ' .
  1066. 'set of machine-readable instructions (most often in the form of a ' .
  1067. 'computer program) that conform to a given syntax (sometimes ' .
  1068. 'referred to as a language) that is interpretable by a given ' .
  1069. 'processor and that directs a computer\'s processor to perform ' .
  1070. 'specific operations.',
  1071. ));
  1072. tripal_associate_chado_semweb_term('analysis', 'program', $term);
  1073. }
  1074. /**
  1075. * Adds the contact table mapping.
  1076. */
  1077. function tripal_chado_populate_vocab_TCONTACT() {
  1078. tripal_insert_db(array(
  1079. 'name' => 'TContact',
  1080. 'description' => 'The Tripal Contact controlled vocabulary.',
  1081. ));
  1082. }
  1083. /**
  1084. * Adds the pub table mappings.
  1085. */
  1086. function tripal_chado_populate_vocab_TPUB() {
  1087. tripal_insert_db(array(
  1088. 'name' => 'TPUB',
  1089. 'description' => 'The Tripal Publication controlled vocabulary.',
  1090. ));
  1091. // make sure we have our supported databases
  1092. tripal_insert_db(
  1093. array(
  1094. 'name' => 'PMID',
  1095. 'description' => 'PubMed',
  1096. 'url' => 'http://www.ncbi.nlm.nih.gov/pubmed',
  1097. 'urlprefix' => 'http://www.ncbi.nlm.nih.gov/pubmed/'
  1098. ),
  1099. array('update_existing' => TRUE)
  1100. );
  1101. tripal_insert_db(
  1102. array(
  1103. 'name' => 'AGL',
  1104. 'description' => 'USDA National Agricultural Library',
  1105. 'url' => 'http://agricola.nal.usda.gov/'
  1106. ),
  1107. array('update_existing' => TRUE)
  1108. );
  1109. $term = tripal_get_cvterm(array('id' => 'TPUB:0000039'));
  1110. tripal_associate_chado_semweb_term('pub', 'title', $term);
  1111. $term = tripal_get_cvterm(array('id' => 'TPUB:0000243'));
  1112. tripal_associate_chado_semweb_term('pub', 'volumetitle', $term);
  1113. $term = tripal_get_cvterm(array('id' => 'TPUB:0000042'));
  1114. tripal_associate_chado_semweb_term('pub', 'volume', $term);
  1115. $term = tripal_get_cvterm(array('id' => 'TPUB:0000256'));
  1116. tripal_associate_chado_semweb_term('pub', 'series_name', $term);
  1117. $term = tripal_get_cvterm(array('id' => 'TPUB:0000043'));
  1118. tripal_associate_chado_semweb_term('pub', 'issue', $term);
  1119. $term = tripal_get_cvterm(array('id' => 'TPUB:0000059'));
  1120. tripal_associate_chado_semweb_term('pub', 'pyear', $term);
  1121. $term = tripal_get_cvterm(array('id' => 'TPUB:0000044'));
  1122. tripal_associate_chado_semweb_term('pub', 'pages', $term);
  1123. $term = tripal_get_cvterm(array('id' => 'TPUB:0000244'));
  1124. tripal_associate_chado_semweb_term('pub', 'publisher', $term);
  1125. $term = tripal_get_cvterm(array('id' => 'TPUB:0000245'));
  1126. tripal_associate_chado_semweb_term('pub', 'pubplace', $term);
  1127. }
  1128. /**
  1129. * Adds the Uni Ontology database, terms and mappings.
  1130. */
  1131. function tripal_chado_populate_vocab_UO() {
  1132. tripal_insert_db(array(
  1133. 'name' => 'UO',
  1134. 'description' => 'Units of Measurement Ontology',
  1135. 'url' => 'http://purl.obolibrary.org/obo/uo',
  1136. 'urlprefix' => 'http://purl.obolibrary.org/obo/TAXRANK_',
  1137. ));
  1138. tripal_insert_cv('uo','Units of Measurement Ontology');
  1139. $term = tripal_insert_cvterm(array(
  1140. 'id' => 'UO:0000000',
  1141. 'name' => 'unit',
  1142. 'cv_name' => 'uo',
  1143. 'description' => 'A unit of measurement is a standardized quantity of a physical quality.'
  1144. ));
  1145. tripal_associate_chado_semweb_term('featuremap', 'unittype_id', $term);
  1146. }
  1147. /**
  1148. * Adds the Taxonomic Rank Ontology database and terms.
  1149. */
  1150. function tripal_chado_populate_vocab_TAXRANK() {
  1151. tripal_insert_db(array(
  1152. 'name' => 'TAXRANK',
  1153. 'description' => 'Taxonomic rank vocabulary.',
  1154. 'url' => 'https://github.com/phenoscape/taxrank',
  1155. 'urlprefix' => 'http://purl.obolibrary.org/obo/TAXRANK_',
  1156. ));
  1157. tripal_insert_cv('taxrank','Taxonomic rank vocabulary. A vocabulary of taxonomic ranks (species, family, phylum, etc).');
  1158. $term = tripal_insert_cvterm(array(
  1159. 'id' => 'TAXRANK:0000005',
  1160. 'name' => 'genus',
  1161. 'cv_name' => 'taxonomic_rank',
  1162. 'description' => 'Taxonomic rank of Genus'
  1163. ));
  1164. tripal_associate_chado_semweb_term('organism', 'genus', $term);
  1165. $term = tripal_insert_cvterm(array(
  1166. 'id' => 'TAXRANK:0000006',
  1167. 'name' => 'species',
  1168. 'cv_name' => 'taxonomic_rank',
  1169. 'description' => 'Taxonomic rank of species.'
  1170. ));
  1171. tripal_associate_chado_semweb_term('organism', 'species', $term);
  1172. $term = tripal_insert_cvterm(array(
  1173. 'id' => 'TAXRANK:0000045',
  1174. 'name' => 'infraspecies',
  1175. 'cv_name' => 'taxonomic_rank',
  1176. 'description' => 'Taxonomic infraspecies name.'
  1177. ));
  1178. tripal_associate_chado_semweb_term('organism', 'infraspecific_name', $term);
  1179. }
  1180. /**
  1181. * Adds the NCBI Taxon vocabulary database and terms.
  1182. */
  1183. function tripal_chado_populate_vocab_NCBITAXON() {
  1184. tripal_insert_db(array(
  1185. 'name' => 'NCBITaxon',
  1186. 'description' => 'NCBI organismal classification.',
  1187. 'url' => 'http://www.berkeleybop.org/ontologies/ncbitaxon/',
  1188. 'urlprefix' => 'http://purl.obolibrary.org/obo/ncbitaxon#',
  1189. ));
  1190. tripal_insert_cv('ncbitaxon','NCBI organismal classification. An ontology representation of the NCBI organismal taxonomy.');
  1191. $term = tripal_insert_cvterm(array(
  1192. 'id' => 'NCBITaxon:common_name',
  1193. 'name' => 'common name',
  1194. 'cv_name' => 'ncbitaxon',
  1195. ));
  1196. tripal_associate_chado_semweb_term('organism', 'common_name', $term);
  1197. }
  1198. /**
  1199. * Adds defaults to the chado_semweb table.
  1200. */
  1201. function tripal_chado_semweb_form($form, &$form_state, $chado_table = NULL) {
  1202. if (array_key_exists('values', $form_state)) {
  1203. $chado_table = $form_state['values']['chado_table'];
  1204. }
  1205. $chado_tables = chado_get_table_names(TRUE);
  1206. $chado_tables = array_merge(array('Select a Chado Table'), $chado_tables);
  1207. // Make sure the table name exists. If not, reset it.
  1208. $chado_table = in_array($chado_table, $chado_tables) ? $chado_table: NULL;
  1209. $form['chado_table'] = array(
  1210. '#type' => 'select',
  1211. '#title' => 'Chado Table',
  1212. '#description' => t('Select a chado table to set web services terms used for its columns.'),
  1213. '#options' => $chado_tables,
  1214. '#default_value' => $chado_table,
  1215. '#ajax' => array(
  1216. 'callback' => "tripal_chado_semweb_form_ajax_callback",
  1217. 'wrapper' => "tripal-chado-semweb-form",
  1218. 'effect' => 'fade',
  1219. 'method' => 'replace'
  1220. ),
  1221. );
  1222. // If the user has selected a chado table, then we need to
  1223. // show the columns for setting terms.
  1224. if ($chado_table) {
  1225. $schema = chado_get_schema($chado_table);
  1226. $pk = $schema['primary key'][0];
  1227. // $cv_default = db_select('tripal_cv_defaults', 'tc')
  1228. // ->fields('tc', array('field_name'))
  1229. // ->condition('table_name', $chado_table)
  1230. // ->execute()
  1231. // ->fetchField();
  1232. $columns = $schema['fields'];
  1233. $headers = array(
  1234. 'Field Name',
  1235. 'Vocabulary',
  1236. array(
  1237. 'data' => 'Name',
  1238. 'nowrap' => TRUE,
  1239. ),
  1240. 'Term',
  1241. 'Term Description',
  1242. 'Action'
  1243. );
  1244. $rows = array();
  1245. foreach ($columns AS $column => $detail) {
  1246. // Do not show column if it's the primary key or default cv
  1247. if ($column != $pk && $column != $cv_default) {
  1248. $cvterm_id =
  1249. db_select('chado_semweb', 'cs')
  1250. ->fields('cs', array('cvterm_id'))
  1251. ->condition('chado_table', $chado_table)
  1252. ->condition('chado_column', $column)
  1253. ->execute()
  1254. ->fetchField();
  1255. $sw_voc = '';
  1256. $sw_term = '';
  1257. $sw_desc = '';
  1258. $sw_accession = '';
  1259. if($cvterm_id) {
  1260. $term = chado_generate_var('cvterm', array('cvterm_id' => $cvterm_id));
  1261. $sw_voc = $term->cv_id->name;
  1262. $sw_term = $term->name;
  1263. $sw_accession = l($term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession,
  1264. 'cv/lookup/' . $term->dbxref_id->db_id->name . '/' . $term->dbxref_id->accession,
  1265. array('attributes' => array('target' => '_blank')));
  1266. $sw_desc = $term->definition;
  1267. }
  1268. $rows[] = array(
  1269. $column,
  1270. $sw_voc,
  1271. $sw_term,
  1272. $sw_accession,
  1273. $sw_desc,
  1274. array(
  1275. 'data' => l('Edit', '/admin/tripal/storage/chado/semweb/edit/' . $chado_table . '/' . $column) . ' | ' .
  1276. l('Reset', '/admin/tripal/storage/chado/semweb/reset/' . $chado_table . '/' . $column),
  1277. 'nowrap' => TRUE,
  1278. ),
  1279. );
  1280. }
  1281. }
  1282. $output = theme('table', array(
  1283. 'header' => $headers,
  1284. 'rows' => $rows,
  1285. ));
  1286. $form['table'] = array(
  1287. '#markup' => $output
  1288. );
  1289. }
  1290. $form['#prefix'] = '<div id="tripal-chado-semweb-form">';
  1291. $form['#suffix'] = '</div>';
  1292. return $form;
  1293. }
  1294. /**
  1295. * Implements hook_form()
  1296. * Edit terms used by the semantic web
  1297. *
  1298. * @param $form
  1299. * @param $form_state
  1300. * @param $table
  1301. * @param $column
  1302. * @return $form
  1303. */
  1304. function tripal_chado_semweb_edit_form($form, &$form_state, $table = NULL, $column = NULL) {
  1305. $term_name = array_key_exists('values', $form_state) ? $form_state['values']['term_name'] : '';
  1306. $form['chado_table'] = array(
  1307. '#markup' => 'Term used for the <strong>' . t($column) . '</strong> column of the chado <strong>' . t($table) . '</strong> table:',
  1308. );
  1309. $form['table_name'] = array(
  1310. '#type' => 'value',
  1311. '#value' => $table
  1312. );
  1313. $form['column'] = array(
  1314. '#type' => 'value',
  1315. '#value' => $column
  1316. );
  1317. // If no term has been selected yet then provide the auto complete field.
  1318. $form['term_name'] = array(
  1319. '#title' => t('Term'),
  1320. '#type' => 'textfield',
  1321. '#description' => t("The content type must be the name of a term in
  1322. a controlled vocabulary and the controlled vocabulary should
  1323. already be loaded into Tripal. For example, to create a content
  1324. type for storing 'genes', use the 'gene' term from the
  1325. Sequence Ontology (SO)."),
  1326. '#required' => TRUE,
  1327. '#default_value' => $term_name,
  1328. '#autocomplete_path' => "admin/tripal/storage/chado/auto_name/cvterm/",
  1329. );
  1330. $form['select_button'] = array(
  1331. '#type' => 'button',
  1332. '#value' => t('Lookup Term'),
  1333. '#name' => 'select_cvterm',
  1334. '#ajax' => array(
  1335. 'callback' => "tripal_chado_semweb_form_ajax_callback",
  1336. 'wrapper' => "tripal-chado-semweb-edit-form",
  1337. 'effect' => 'fade',
  1338. 'method' => 'replace'
  1339. ),
  1340. );
  1341. if ($term_name) {
  1342. $form['terms_list'] = array(
  1343. '#type' => 'fieldset',
  1344. '#title' => t('Matching Terms'),
  1345. '#description' => t('Please select the term the best matches the
  1346. content type you want to create. If the same term exists in
  1347. multiple vocabularies you will see more than one option below.')
  1348. );
  1349. $match = array(
  1350. 'name' => $term_name,
  1351. );
  1352. $terms = chado_generate_var('cvterm', $match, array('return_array' => TRUE));
  1353. $terms = chado_expand_var($terms, 'field', 'cvterm.definition');
  1354. $num_terms = 0;
  1355. foreach ($terms as $term) {
  1356. // Save the user a click by setting the default value as 1 if there's
  1357. // only one matching term.
  1358. $default = FALSE;
  1359. $attrs = array();
  1360. if ($num_terms == 0 and count($terms) == 1) {
  1361. $default = TRUE;
  1362. $attrs = array('checked' => 'checked');
  1363. }
  1364. $form['terms_list']['term-' . $term->cvterm_id] = array(
  1365. '#type' => 'checkbox',
  1366. '#title' => $term->name,
  1367. '#default_value' => $default,
  1368. '#attributes' => $attrs,
  1369. '#description' => '<b>Vocabulary:</b> ' . $term->cv_id->name . ' (' . $term->dbxref_id->db_id->name . ') ' . $term->cv_id->definition .
  1370. '<br><b>Term: </b> ' . $term->dbxref_id->db_id->name . ':' . $term->dbxref_id->accession . '. ' .
  1371. '<br><b>Definition:</b> ' . $term->definition,
  1372. );
  1373. $num_terms++;
  1374. }
  1375. if ($num_terms == 0) {
  1376. $form['terms_list']['none'] = array(
  1377. '#type' => 'item',
  1378. '#markup' => '<i>' . t('There is no term that matches the entered text.') . '</i>'
  1379. );
  1380. }
  1381. // Add in the button for the cases of no terms or too many.
  1382. $form['submit_button'] = array(
  1383. '#type' => 'submit',
  1384. '#value' => t('Use this term'),
  1385. '#name' => 'use_cvterm'
  1386. );
  1387. }
  1388. $form['cancel_button'] = array(
  1389. '#type' => 'button',
  1390. '#value' => t('Cancel'),
  1391. '#name' => 'cancel_button',
  1392. '#limit_validation_errors' => array()
  1393. );
  1394. $form['#prefix'] = '<div id = "tripal-chado-semweb-edit-form">';
  1395. $form['#suffix'] = '</div>';
  1396. return $form;
  1397. }
  1398. /**
  1399. * Implements hook_form_validate()
  1400. *
  1401. * Validate function for editing the semantic web term
  1402. *
  1403. * @param unknown $form
  1404. * @param unknown $form_state
  1405. */
  1406. function tripal_chado_semweb_edit_form_validate($form, &$form_state) {
  1407. if (array_key_exists('clicked_button', $form_state)) {
  1408. if ($form_state['clicked_button']['#name'] =='use_cvterm') {
  1409. $cvterm_id = NULL;
  1410. // Make sure we have a cvterm selected
  1411. $num_selected = 0;
  1412. foreach ($form_state['values'] as $key => $value) {
  1413. $matches = array();
  1414. if (preg_match("/^term-(\d+)$/", $key, $matches) and
  1415. $form_state['values']['term-' . $matches[1]]) {
  1416. $cvterm_id = $matches[1];
  1417. $num_selected++;
  1418. }
  1419. }
  1420. if ($num_selected == 0) {
  1421. form_set_error('', 'Please select at least one term.');
  1422. }
  1423. else if ($num_selected > 1) {
  1424. form_set_error('term-' . $cvterm_id, 'Please select only one term from the list below.');
  1425. }
  1426. else {
  1427. $form_state['values']['#selected_cvterm_id'] = $cvterm_id;
  1428. }
  1429. }
  1430. else if ($form_state['clicked_button']['#name'] =='cancel_button') {
  1431. $table_name = $form_state['values']['table_name'];
  1432. drupal_goto('/admin/tripal/storage/chado/semweb/' . $table_name);
  1433. }
  1434. }
  1435. }
  1436. /**
  1437. * Implements hook_form_submit()
  1438. *
  1439. * Submit function for editing the semantic web term
  1440. *
  1441. * @param unknown $form
  1442. * @param unknown $form_state
  1443. */
  1444. function tripal_chado_semweb_edit_form_submit($form, &$form_state) {
  1445. if (array_key_exists('clicked_button', $form_state) && $form_state['clicked_button']['#name'] =='use_cvterm') {
  1446. $table_name = $form_state['values']['table_name'];
  1447. $column = $form_state['values']['column'];
  1448. $cvterm_id = $form_state['values']['#selected_cvterm_id'];
  1449. // Check if there is already a record
  1450. $record_id =
  1451. db_select('chado_semweb', 'cs')
  1452. ->fields('cs', array('chado_semweb_id'))
  1453. ->condition('chado_table', $table_name)
  1454. ->condition('chado_column', $column)
  1455. ->execute()
  1456. ->fetchField();
  1457. // If the record exists, update it
  1458. if ($record_id) {
  1459. db_update('chado_semweb')
  1460. ->fields(array(
  1461. 'cvterm_id' => $cvterm_id
  1462. ))
  1463. ->condition('chado_semweb_id', $record_id)
  1464. ->execute();
  1465. }
  1466. // Otherwise, insert a new record
  1467. else {
  1468. db_insert('chado_semweb')
  1469. ->fields(array(
  1470. 'chado_table' => $table_name,
  1471. 'chado_column' => $column,
  1472. 'cvterm_id' => $cvterm_id
  1473. ))
  1474. ->execute();
  1475. }
  1476. drupal_set_message('The term settings have been saved.');
  1477. drupal_goto('/admin/tripal/storage/chado/semweb/' . $table_name);
  1478. }
  1479. }
  1480. /**
  1481. * Implements hook_form()
  1482. * Reset term used by semantic web
  1483. *
  1484. * @param $form
  1485. * @param $form_state
  1486. * @param $table
  1487. * @param $column
  1488. * @return $form
  1489. */
  1490. function tripal_chado_semweb_reset_form($form, &$form_state, $table = NULL, $column = NULL) {
  1491. $term_name = array_key_exists('values', $form_state) ? $form_state['values']['term_name'] : '';
  1492. $form['chado_table'] = array(
  1493. '#markup' => 'Are you sure you want to remove the use of this term? ',
  1494. );
  1495. $form['table_name'] = array(
  1496. '#type' => 'value',
  1497. '#value' => $table
  1498. );
  1499. $form['column'] = array(
  1500. '#type' => 'value',
  1501. '#value' => $column
  1502. );
  1503. $form['submit_button'] = array(
  1504. '#type' => 'submit',
  1505. '#value' => t('Reset'),
  1506. '#name' => 'reset_term'
  1507. );
  1508. $form['cancel_button'] = array(
  1509. '#type' => 'button',
  1510. '#value' => t('Cancel'),
  1511. '#name' => 'cancel_button',
  1512. '#limit_validation_errors' => array()
  1513. );
  1514. return $form;
  1515. }
  1516. /**
  1517. * Implements hook_form_validate()
  1518. *
  1519. * Validate function for resetting the semantic web term
  1520. *
  1521. * @param unknown $form
  1522. * @param unknown $form_state
  1523. */
  1524. function tripal_chado_semweb_reset_form_validate($form, &$form_state) {
  1525. if (array_key_exists('clicked_button', $form_state)) {
  1526. if ($form_state['clicked_button']['#name'] =='use_cvterm') {
  1527. $cvterm_id = NULL;
  1528. // Make sure we have a cvterm selected
  1529. $num_selected = 0;
  1530. foreach ($form_state['values'] as $key => $value) {
  1531. $matches = array();
  1532. if (preg_match("/^term-(\d+)$/", $key, $matches) and
  1533. $form_state['values']['term-' . $matches[1]]) {
  1534. $cvterm_id = $matches[1];
  1535. $num_selected++;
  1536. }
  1537. }
  1538. if ($num_selected == 0) {
  1539. form_set_error('', 'Please select at least one term.');
  1540. }
  1541. else if ($num_selected > 1) {
  1542. form_set_error('term-' . $cvterm_id, 'Please select only one term from the list below.');
  1543. }
  1544. else {
  1545. $form_state['values']['#selected_cvterm_id'] = $cvterm_id;
  1546. }
  1547. }
  1548. else if ($form_state['clicked_button']['#name'] =='cancel_button') {
  1549. $table_name = $form_state['values']['table_name'];
  1550. drupal_goto('/admin/tripal/storage/chado/semweb/' . $table_name);
  1551. }
  1552. }
  1553. }
  1554. /**
  1555. * Implements hook_form_submit()
  1556. *
  1557. * Submit function for editing the semantic web term
  1558. *
  1559. * @param unknown $form
  1560. * @param unknown $form_state
  1561. */
  1562. function tripal_chado_semweb_reset_form_submit($form, &$form_state) {
  1563. if (array_key_exists('clicked_button', $form_state) && $form_state['clicked_button']['#name'] =='reset_term') {
  1564. $table_name = $form_state['values']['table_name'];
  1565. $column = $form_state['values']['column'];
  1566. // Check if there is already a record
  1567. $record_id =
  1568. db_select('chado_semweb', 'cs')
  1569. ->fields('cs', array('chado_semweb_id'))
  1570. ->condition('chado_table', $table_name)
  1571. ->condition('chado_column', $column)
  1572. ->execute()
  1573. ->fetchField();
  1574. // If the record exists, reset it
  1575. if ($record_id) {
  1576. db_update('chado_semweb')
  1577. ->fields(array(
  1578. 'cvterm_id' => NULL
  1579. ))
  1580. ->condition('chado_semweb_id', $record_id)
  1581. ->execute();
  1582. }
  1583. drupal_set_message('The term settings have been reset.');
  1584. drupal_goto('/admin/tripal/storage/chado/semweb/' . $table_name);
  1585. }
  1586. }
  1587. /**
  1588. *
  1589. */
  1590. function tripal_chado_semweb_form_ajax_callback($form, $form_state) {
  1591. return $form;
  1592. }