tripal_chado.setup.inc 63 KB

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