tripal_chado.fields.inc 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004
  1. <?php
  2. /**
  3. * Implements hook_bundle_fields_info().
  4. *
  5. * This is a Tripal defined hook that supports integration with the
  6. * TripalEntity field.
  7. */
  8. function tripal_chado_bundle_fields_info($entity_type, $bundle) {
  9. $chado_bundle = db_select('chado_bundle', 'cb')
  10. ->fields('cb')
  11. ->condition('bundle_id', $bundle->id)
  12. ->execute()
  13. ->fetchObject();
  14. // Get the details about the mapping of this bundle to the Chado table:
  15. $details = array(
  16. 'chado_cvterm_id' => $chado_bundle->type_id,
  17. 'chado_table' => $chado_bundle->data_table,
  18. 'chado_type_table' => $chado_bundle->type_linker_table,
  19. 'chado_type_column' => $chado_bundle->type_column,
  20. 'chado_type_value' => $chado_bundle->type_value,
  21. );
  22. $info = array();
  23. // Create the fields for each column in the table.
  24. tripal_chado_bundle_fields_info_base($info, $details, $entity_type, $bundle);
  25. // Create custom fields.
  26. tripal_chado_bundle_fields_info_custom($info, $details, $entity_type, $bundle);
  27. // Create fields for linking tables.
  28. tripal_chado_bundle_fields_info_linker($info, $details, $entity_type, $bundle);
  29. return $info;
  30. }
  31. /**
  32. *
  33. * @param unknown $details
  34. */
  35. function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle) {
  36. $table_name = $details['chado_table'];
  37. $type_table = $details['chado_type_table'];
  38. $type_column = $details['chado_type_column'];
  39. $cvterm_id = $details['chado_cvterm_id'];
  40. $type_value = $details['chado_type_value'];
  41. // Iterate through the columns of the table and see if fields have been
  42. // created for each one. If not, then create them.
  43. $schema = chado_get_schema($table_name);
  44. if (!$schema) {
  45. return;
  46. }
  47. $pkey = $schema['primary key'][0];
  48. // Get the list of columns for this table and create a new field for each one.
  49. $columns = $schema['fields'];
  50. foreach ($columns as $column_name => $details) {
  51. // Skip the source columns in the analysis table. We have a custom
  52. // field for those columns
  53. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  54. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  55. continue;
  56. }
  57. // Skip the infraspecific type_id and name from the organism table as we
  58. // have a special field for those.
  59. if ($table_name == 'organism' and ($column_name == 'type_id' or
  60. $column_name == 'infraspecific_name')) {
  61. continue;
  62. }
  63. // Skip the cvterm.is_relationshptype.
  64. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  65. continue;
  66. }
  67. // The biosourceprovider_id and taxon_id are handled by custom fields.
  68. if ($table_name == 'biomaterial' and (
  69. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  70. continue;
  71. }
  72. // Don't create base fields for the primary key and the type_id field.
  73. if ($column_name == $pkey or $column_name == $type_column) {
  74. continue;
  75. }
  76. $cvterm = chado_get_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  77. if (!$cvterm) {
  78. tripal_report_error('tripal', TRIPAL_ERROR,
  79. 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  80. array('%table_name' => $table_name, '%column_name' => $column_name));
  81. drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  82. array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
  83. continue;
  84. }
  85. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  86. $field_name = substr($field_name, 0, 32);
  87. // Skip the primary key field.
  88. if ($column_name == $schema['primary key'][0]) {
  89. continue;
  90. }
  91. // If the type_id defines the content type and it's part of the
  92. // base table and this column is the type_id then skip it.
  93. if (!$type_table and $type_column and $column_name == $type_column) {
  94. continue;
  95. }
  96. // Skip the type ID as it will be handled by a custom field.
  97. if ($column_name == 'type_id') {
  98. continue;
  99. }
  100. // Set some defaults for the field.
  101. $base_info = array(
  102. 'field_name' => $field_name,
  103. 'type' => '',
  104. 'cardinality' => 1,
  105. 'locked' => FALSE,
  106. 'storage' => array(
  107. 'type' => 'field_chado_storage',
  108. 'sql' => array(),
  109. ),
  110. );
  111. // Alter the field info array depending on the column details.
  112. switch($details['type']) {
  113. case 'char':
  114. $base_info['type'] = 'text';
  115. $base_info['settings']['max_length'] = $details['length'];
  116. break;
  117. case 'varchar':
  118. $base_info['type'] = 'text';
  119. $base_info['settings']['max_length'] = $details['length'];
  120. break;
  121. case 'text':
  122. $base_info['type'] = 'text';
  123. $base_info['settings']['max_length'] = 17179869184;
  124. $base_info['settings']['text_processing'] = 1;
  125. break;
  126. case 'blob':
  127. // not sure how to support a blob field.
  128. continue;
  129. break;
  130. case 'int':
  131. $base_info['type'] = 'number_integer';
  132. break;
  133. case 'float':
  134. $base_info['type'] = 'number_float';
  135. $base_info['settings']['precision'] = 10;
  136. $base_info['settings']['scale'] = 2;
  137. $base_info['settings']['decimal_separator'] = '.';
  138. break;
  139. case 'numeric':
  140. $base_info['type'] = 'number_decimal';
  141. break;
  142. case 'serial':
  143. // Serial fields are most likely not needed as a field.
  144. break;
  145. case 'boolean':
  146. $base_info['type'] = 'list_boolean';
  147. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  148. break;
  149. case 'datetime':
  150. // Use the Drupal Date and Date API to create the field/widget
  151. $base_info['type'] = 'datetime';
  152. break;
  153. }
  154. // Set some defaults for biomaterial table
  155. if ($table_name == 'biomaterial' and $column_name == 'name') {
  156. $base_info['type'] = 'text';
  157. $base_info['settings']['max_length'] = '2048';
  158. $base_info['settings']['text_processing'] = 0;
  159. }
  160. // Set some default semantic web information
  161. if ($column_name == 'uniquename') {
  162. $base_info['settings']['text_processing'] = 0;
  163. }
  164. // Sometimes the boolean fields are listed as integer. We need to
  165. // correct for that.
  166. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  167. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  168. $column_name == 'is_view' or $column_name == 'is_updateable') {
  169. $base_info['type'] = 'list_boolean';
  170. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  171. }
  172. //
  173. // PUB TABLE
  174. //
  175. if ($table_name == 'pub' and (
  176. $column_name == 'uniquename' or $column_name == 'title' or
  177. $column_name == 'volumetitle')) {
  178. $base_info['type'] = 'text';
  179. $base_info['settings']['text_processing'] = 0;
  180. }
  181. $info[$field_name] = $base_info;
  182. }
  183. }
  184. /**
  185. *
  186. * @param unknown $details
  187. */
  188. function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type, $bundle) {
  189. $table_name = $details['chado_table'];
  190. $type_table = $details['chado_type_table'];
  191. $type_column = $details['chado_type_column'];
  192. $cvterm_id = $details['chado_cvterm_id'];
  193. $type_value = $details['chado_type_value'];
  194. $schema = chado_get_schema($table_name);
  195. // Handle type_id fields that are not the type_column.
  196. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
  197. $field_name = 'schema__additional_type';
  198. $field_type = 'schema__additional_type';
  199. $info[$field_name] = array(
  200. 'field_name' => $field_name,
  201. 'type' => $field_type,
  202. 'cardinality' => 1,
  203. 'locked' => FALSE,
  204. 'storage' => array(
  205. 'type' => 'field_chado_storage',
  206. ),
  207. );
  208. }
  209. // BASE ARRAYDESIGN TABLE
  210. if ($table_name == 'arraydesign') {
  211. $field_name = 'ncit__technology_platform';
  212. $field_type = 'schema__additional_type';
  213. $info[$field_name] = array(
  214. 'field_name' => $field_name,
  215. 'type' => $field_type,
  216. 'cardinality' => 1,
  217. 'locked' => FALSE,
  218. 'storage' => array(
  219. 'type' => 'field_chado_storage',
  220. ),
  221. );
  222. $field_name = 'efo__substrate_type';
  223. $field_type = 'schema__additional_type';
  224. $info[$field_name] = array(
  225. 'field_name' => $field_name,
  226. 'type' => $field_type,
  227. 'cardinality' => 1,
  228. 'locked' => FALSE,
  229. 'storage' => array(
  230. 'type' => 'field_chado_storage',
  231. ),
  232. );
  233. }
  234. // BASE ORGANISM_ID
  235. if ($table_name != 'organism' and
  236. (array_key_exists('organism_id', $schema['fields']) or
  237. array_key_exists('taxon_id', $schema['fields']))) {
  238. $field_name = 'obi__organism';
  239. $field_type = 'obi__organism';
  240. $info[$field_name] = array(
  241. 'field_name' => $field_name,
  242. 'type' => $field_type,
  243. 'cardinality' => 1,
  244. 'locked' => FALSE,
  245. 'storage' => array(
  246. 'type' => 'field_chado_storage',
  247. ),
  248. );
  249. }
  250. if ($table_name == 'biomaterial') {
  251. $field_name = 'biomaterial__provider_id';
  252. $field_type = 'local__contact';
  253. $info[$field_name] = array(
  254. 'field_name' => $field_name,
  255. 'type' => $field_type,
  256. 'cardinality' => 1,
  257. 'locked' => FALSE,
  258. 'storage' => array(
  259. 'type' => 'field_chado_storage',
  260. ),
  261. );
  262. }
  263. if ($table_name == 'arraydesign') {
  264. $field_name = 'efo__array_manufacturer';
  265. $field_type = 'local__contact';
  266. $info[$field_name] = array(
  267. 'field_name' => $field_name,
  268. 'type' => $field_type,
  269. 'cardinality' => 1,
  270. 'locked' => FALSE,
  271. 'storage' => array(
  272. 'type' => 'field_chado_storage',
  273. ),
  274. );
  275. }
  276. // BASE ORGANISM_ID
  277. if ($table_name == 'cvterm') {
  278. $field_name = 'sio__vocabulary';
  279. $field_type = 'sio__vocabulary';
  280. $info[$field_name] = array(
  281. 'field_name' => $field_name,
  282. 'type' => $field_type,
  283. 'cardinality' => 1,
  284. 'locked' => FALSE,
  285. 'storage' => array(
  286. 'type' => 'field_chado_storage',
  287. ),
  288. );
  289. }
  290. // BASE DBXREF
  291. if (array_key_exists('dbxref_id', $schema['fields'])) {
  292. $field_name = 'data__accession';
  293. $field_type = 'data__accession';
  294. $info[$field_name] = array(
  295. 'field_name' => $field_name,
  296. 'type' => $field_type,
  297. 'cardinality' => 1,
  298. 'locked' => FALSE,
  299. 'storage' => array(
  300. 'type' => 'field_chado_storage',
  301. ),
  302. );
  303. }
  304. // FEATURE MD5CHECKSUM
  305. if ($table_name == 'feature') {
  306. $field_name = 'data__sequence_checksum';
  307. $field_type = 'data__sequence_checksum';
  308. $info[$field_name] = array(
  309. 'field_name' => $field_name,
  310. 'type' => $field_type,
  311. 'cardinality' => 1,
  312. 'locked' => FALSE,
  313. 'storage' => array(
  314. 'type' => 'field_chado_storage',
  315. ),
  316. );
  317. }
  318. // FEATURE RESIDUES
  319. if ($table_name == 'feature') {
  320. $field_name = 'data__sequence';
  321. $field_type = 'data__sequence';
  322. $info[$field_name] = array(
  323. 'field_name' => $field_name,
  324. 'type' => $field_type,
  325. 'cardinality' => 1,
  326. 'locked' => FALSE,
  327. 'storage' => array(
  328. 'type' => 'field_chado_storage',
  329. ),
  330. );
  331. }
  332. // FEATURE SEQLEN
  333. if ($table_name == 'feature') {
  334. $field_name = 'data__sequence_length';
  335. $field_type = 'data__sequence_length';
  336. $info[$field_name] = array(
  337. 'field_name' => $field_name,
  338. 'type' => $field_type,
  339. 'cardinality' => 1,
  340. 'locked' => FALSE,
  341. 'storage' => array(
  342. 'type' => 'field_chado_storage',
  343. ),
  344. );
  345. }
  346. // PROTEIN & CDS
  347. if ($table_name == 'feature' and
  348. ($bundle->label == 'mRNA' or $bundle->label == 'transcript' or $bundle->label == 'Transcript')) {
  349. $field_name = 'data__protein_sequence';
  350. $field_type = 'data__protein_sequence';
  351. $info[$field_name] = array(
  352. 'field_name' => $field_name,
  353. 'type' => $field_type,
  354. 'cardinality' => 1,
  355. 'locked' => FALSE,
  356. 'storage' => array(
  357. 'type' => 'field_chado_storage',
  358. ),
  359. );
  360. $field_name = 'so__cds';
  361. $field_type = 'so__cds';
  362. $info[$field_name] = array(
  363. 'field_name' => $field_name,
  364. 'type' => $field_type,
  365. 'cardinality' => 1,
  366. 'locked' => FALSE,
  367. 'storage' => array(
  368. 'type' => 'field_chado_storage',
  369. ),
  370. );
  371. }
  372. if ($table_name == 'feature') {
  373. $field_name = 'local__gbrowse_image';
  374. $field_type = 'local__gbrowse_image';
  375. $info[$field_name] = array(
  376. 'field_name' => $field_name,
  377. 'type' => $field_type,
  378. 'cardinality' => 1,
  379. 'locked' => FALSE,
  380. 'storage' => array(
  381. 'type' => 'field_chado_storage',
  382. ),
  383. );
  384. }
  385. // GENE TRANSCRIPTS
  386. $rel_table = $table_name . '_relationship';
  387. if (chado_table_exists($rel_table) and ($bundle->label == 'gene' or $bundle->label == 'Gene')) {
  388. $field_name = 'so__transcript';
  389. $field_type = 'so__transcript';
  390. $info[$field_name] = array(
  391. 'field_name' => $field_name,
  392. 'type' => $field_type,
  393. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  394. 'locked' => FALSE,
  395. 'storage' => array(
  396. 'type' => 'field_chado_storage',
  397. ),
  398. );
  399. }
  400. // ORGANISM TYPE_ID
  401. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  402. $field_name = 'taxrank__infraspecific_taxon';
  403. $field_type = 'taxrank__infraspecific_taxon';
  404. $info[$field_name] = array(
  405. 'field_name' => $field_name,
  406. 'type' => $field_type,
  407. 'cardinality' => 1,
  408. 'locked' => FALSE,
  409. 'storage' => array(
  410. 'type' => 'field_chado_storage',
  411. ),
  412. );
  413. }
  414. // FEATUREMAP UNITTYPE_ID
  415. if ($table_name == 'featuremap') {
  416. $field_name = 'uo__unit';
  417. $field_type = 'uo__unit';
  418. $info[$field_name] = array(
  419. 'field_name' => $field_name,
  420. 'type' => $field_type,
  421. 'cardinality' => 1,
  422. 'locked' => FALSE,
  423. 'storage' => array(
  424. 'type' => 'field_chado_storage',
  425. ),
  426. );
  427. }
  428. // Analysis source
  429. if ($table_name == 'analysis') {
  430. $field_name = 'local__source_data';
  431. $field_type = 'local__source_data';
  432. $info[$field_name] = array(
  433. 'field_name' => $field_name,
  434. 'type' => $field_type,
  435. 'cardinality' => 1,
  436. 'locked' => FALSE,
  437. 'storage' => array(
  438. 'type' => 'field_chado_storage',
  439. ),
  440. );
  441. }
  442. // Add an image field to the Organism type. This is a Drupal field and
  443. // not stored in Chado, but is used for backwards compatibility.
  444. if ($table_name == 'organism') {
  445. $field_name = 'data__image';
  446. $info[$field_name] = array(
  447. 'field_name' => $field_name,
  448. 'type' => 'image',
  449. 'cardinality' => 1,
  450. 'locked' => FALSE,
  451. 'storage' => array(
  452. 'type' => 'field_sql_storage',
  453. ),
  454. );
  455. }
  456. // Add field for viewing the phylogenetic tree.
  457. if ($table_name == 'phylotree') {
  458. $field_name = 'operation__phylotree_vis';
  459. $field_type = 'operation__phylotree_vis';
  460. $info[$field_name] = array(
  461. 'field_name' => $field_name,
  462. 'type' => $field_type,
  463. 'cardinality' => 1,
  464. 'locked' => FALSE,
  465. 'storage' => array(
  466. 'type' => 'field_chado_storage',
  467. ),
  468. );
  469. }
  470. // Protocol.
  471. if ($table_name != 'protocol' and
  472. array_key_exists('protocol_id', $schema['fields'])) {
  473. $field_name = 'sep__protocol';
  474. $field_type = 'sep__protocol';
  475. $info[$field_name] = array(
  476. 'field_name' => $field_name,
  477. 'type' => $field_type,
  478. 'cardinality' => 1,
  479. 'locked' => FALSE,
  480. 'storage' => array(
  481. 'type' => 'field_chado_storage',
  482. ),
  483. );
  484. }
  485. // Assay operator.
  486. if ($table_name == 'assay') {
  487. $field_name = 'assay__operator_id';
  488. $field_type = 'local__contact';
  489. $info[$field_name] = array(
  490. 'field_name' => $field_name,
  491. 'type' => $field_type,
  492. 'cardinality' => 1,
  493. 'locked' => FALSE,
  494. 'storage' => array(
  495. 'type' => 'field_chado_storage',
  496. ),
  497. );
  498. }
  499. // For the pub_id field in the base table.
  500. $schema = chado_get_schema($table_name);
  501. if (array_key_exists('pub_id', $schema['fields'])) {
  502. // Remove the schema__publication added by the
  503. // tripal_chado_bunde_instnaces_info_base function.
  504. unset($info['schema__publication']);
  505. $field_name = 'schema__publication_single';
  506. $field_type = 'schema__publication';
  507. $info[$field_name] = array(
  508. 'field_name' => $field_name,
  509. 'type' => $field_type,
  510. 'cardinality' => 1,
  511. 'locked' => FALSE,
  512. 'storage' => array(
  513. 'type' => 'field_chado_storage',
  514. ),
  515. );
  516. }
  517. }
  518. /**
  519. *
  520. * @param $details
  521. */
  522. function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
  523. $table_name = $details['chado_table'];
  524. $type_table = $details['chado_type_table'];
  525. $type_column = $details['chado_type_column'];
  526. $cvterm_id = $details['chado_cvterm_id'];
  527. $type_value = $details['chado_type_value'];
  528. // CONTACTS
  529. $contact_table = $table_name . '_contact';
  530. if (chado_table_exists($contact_table)) {
  531. $schema = chado_get_schema($contact_table);
  532. $pkey = $schema['primary key'][0];
  533. $field_name = $table_name . '_contact';
  534. $field_type = 'chado_linker__contact';
  535. $info[$field_name] = array(
  536. 'field_name' => $field_name,
  537. 'type' => $field_type,
  538. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  539. 'locked' => FALSE,
  540. 'storage' => array(
  541. 'type' => 'field_chado_storage',
  542. ),
  543. );
  544. }
  545. // DBXREF
  546. $dbxref_table = $table_name . '_dbxref';
  547. if (chado_table_exists($dbxref_table)) {
  548. $field_name = 'sbo__database_cross_reference';
  549. $field_type = 'sbo__database_cross_reference';
  550. $info[$field_name] = array(
  551. 'field_name' => $field_name,
  552. 'type' => $field_type,
  553. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  554. 'locked' => FALSE,
  555. 'storage' => array(
  556. 'type' => 'field_chado_storage',
  557. ),
  558. );
  559. }
  560. // EXPRESSION
  561. // TODO: this should only show up on gene or mRNA bunldes, not every feature.
  562. // $expression_table = $table_name . '_expression';
  563. // if (chado_table_exists($expression_table)) {
  564. // $field_name = 'go__gene_expression';
  565. // $field_type = 'go__gene_expression';
  566. // $info[$field_name] = array(
  567. // 'field_name' => $field_name,
  568. // 'type' => $field_type,
  569. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  570. // 'locked' => FALSE,
  571. // 'storage' => array(
  572. // 'type' => 'field_chado_storage',
  573. // ),
  574. // );
  575. // }
  576. // FEATURELOC
  577. if ($table_name == 'feature') {
  578. $field_name = 'data__sequence_coordinates';
  579. $field_type = 'data__sequence_coordinates';
  580. $info[$field_name] = array(
  581. 'field_name' => $field_name,
  582. 'type' => $field_type,
  583. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  584. 'locked' => FALSE,
  585. 'storage' => array(
  586. 'type' => 'field_chado_storage',
  587. ),
  588. );
  589. }
  590. // FEATUREPOS
  591. if ($table_name == 'feature') {
  592. $field_name = 'ogi__location_on_map';
  593. $field_type = 'ogi__location_on_map';
  594. $info[$field_name] = array(
  595. 'field_name' => $field_name,
  596. 'type' => $field_type,
  597. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  598. 'locked' => FALSE,
  599. 'storage' => array(
  600. 'type' => 'field_chado_storage',
  601. ),
  602. );
  603. }
  604. // // GENOTYPE
  605. // $genotype_table = $table_name . '_genotype';
  606. // if (chado_table_exists($genotype_table)) {
  607. // $field_name = 'so__genotype';
  608. // $field_type = 'so__genotype';
  609. // $info[$field_name] = array(
  610. // 'field_name' => $field_name,
  611. // 'type' => $field_type,
  612. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  613. // 'locked' => FALSE,
  614. // 'storage' => array(
  615. // 'type' => 'field_chado_storage',
  616. // ),
  617. // );
  618. // }
  619. // // PHENOTYPE
  620. // $phenotype_table = $table_name . '_phenotype';
  621. // if (chado_table_exists($phenotype_table)) {
  622. // $field_name = 'sbo__phenotype';
  623. // $field_type = 'sbo__phenotype';
  624. // $info[$field_name] = array(
  625. // 'field_name' => $field_name,
  626. // 'type' => $field_type,
  627. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  628. // 'locked' => FALSE,
  629. // 'storage' => array(
  630. // 'type' => 'field_chado_storage',
  631. // ),
  632. // );
  633. // }
  634. // PROPERTIES
  635. $prop_table = $table_name . 'prop';
  636. if (chado_table_exists($prop_table)) {
  637. // Get the list of existing property types for this table.
  638. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  639. $props = chado_query($sql);
  640. while ($prop = $props->fetchObject()) {
  641. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  642. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  643. // tripal_analysis_interpro modules store results in the analysisprop
  644. // table which is probably not the best place, but we don't want to
  645. // create a ton of fields for this, so skip them.
  646. if ($prop_table == 'analysisprop' and
  647. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  648. $term->dbxref_id->db_id->name == 'tripal')) {
  649. continue;
  650. }
  651. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  652. $field_name = substr($field_name, 0, 32);
  653. $field_type = 'chado_linker__prop';
  654. $info[$field_name] = array(
  655. 'field_name' => $field_name,
  656. 'type' => $field_type,
  657. 'cardinality' => 1,
  658. 'locked' => FALSE,
  659. 'storage' => array(
  660. 'type' => 'field_chado_storage',
  661. ),
  662. );
  663. }
  664. }
  665. // CVTERMS
  666. $term_table = $table_name . '_cvterm';
  667. if (chado_table_exists($term_table)) {
  668. $schema = chado_get_schema($term_table);
  669. $pkey = $schema['primary key'][0];
  670. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  671. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  672. $field_name = 'sio__annotation';
  673. $field_type = 'sio__annotation';
  674. $info[$field_name] = array(
  675. 'field_name' => $field_name,
  676. 'type' => $field_type,
  677. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  678. 'locked' => FALSE,
  679. 'storage' => array(
  680. 'type' => 'field_chado_storage',
  681. ),
  682. );
  683. }
  684. // PUBLICATIONS
  685. $pub_table = $table_name . '_pub';
  686. if (chado_table_exists($pub_table)) {
  687. $field_name = 'schema__publication';
  688. $field_type = 'schema__publication';
  689. $info[$field_name] = array(
  690. 'field_name' => $field_name,
  691. 'type' => $field_type,
  692. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  693. 'locked' => FALSE,
  694. 'storage' => array(
  695. 'type' => 'field_chado_storage',
  696. ),
  697. );
  698. }
  699. // PUBLICATIONS (in reverse)
  700. // We want to be able to show all of the content that a publication links
  701. // to. The sio__references field does that.
  702. if ($table_name == 'pub') {
  703. $field_name = 'sio__references';
  704. $field_type = 'sio__references';
  705. $info[$field_name] = array(
  706. 'field_name' => $field_name,
  707. 'type' => $field_type,
  708. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  709. 'locked' => FALSE,
  710. 'storage' => array(
  711. 'type' => 'field_chado_storage',
  712. ),
  713. );
  714. }
  715. // RELATIONSHIPS
  716. // If the linker table does not exists then we don't want to add attach.
  717. $rel_table = $table_name . '_relationship';
  718. if (chado_table_exists($rel_table)) {
  719. $field_name = 'sbo__relationship';
  720. $field_type = 'sbo__relationship';
  721. $info[$field_name] = array(
  722. 'field_name' => $field_name,
  723. 'type' => $field_type,
  724. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  725. 'locked' => FALSE,
  726. 'storage' => array(
  727. 'type' => 'field_chado_storage',
  728. ),
  729. );
  730. }
  731. // SYNONYMS
  732. $syn_table = $table_name . '_synonym';
  733. if (chado_table_exists($syn_table)) {
  734. $field_name = 'schema__alternate_name';
  735. $field_type = 'schema__alternate_name';
  736. $info[$field_name] = array(
  737. 'field_name' => $field_name,
  738. 'type' => $field_type,
  739. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  740. 'locked' => FALSE,
  741. 'storage' => array(
  742. 'type' => 'field_chado_storage',
  743. ),
  744. 'settings' => array(
  745. ),
  746. );
  747. }
  748. }
  749. /**
  750. * Impelments hook_create_tripalfield_instance().
  751. *
  752. * This is a Tripal defined hook that supports integration with the
  753. * TripalEntity field.
  754. */
  755. function tripal_chado_bundle_instances_info($entity_type, $bundle) {
  756. $chado_bundle = db_select('chado_bundle', 'cb')
  757. ->fields('cb')
  758. ->condition('bundle_id', $bundle->id)
  759. ->execute()
  760. ->fetchObject();
  761. $details = array(
  762. 'chado_cvterm_id' => $chado_bundle->type_id,
  763. 'chado_table' => $chado_bundle->data_table,
  764. 'chado_type_table' => $chado_bundle->type_linker_table,
  765. 'chado_type_column' => $chado_bundle->type_column,
  766. 'chado_type_value' => $chado_bundle->type_value,
  767. );
  768. $info = array();
  769. tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
  770. tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
  771. tripal_chado_bundle_instances_info_linker($info, $entity_type, $bundle, $details);
  772. return $info;
  773. }
  774. /**
  775. * Helper function for the hook_create_tripalfield_instance().
  776. *
  777. * Add the field instances that corresond to the columns of the base table.
  778. *
  779. * @param $entity_type
  780. * @param $bundle
  781. * @param $details
  782. */
  783. function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle, $details) {
  784. $fields = array();
  785. // Get Chado information
  786. $table_name = $details['chado_table'];
  787. $type_table = $details['chado_type_table'];
  788. $type_column = $details['chado_type_column'];
  789. $cvterm_id = $details['chado_cvterm_id'];
  790. $type_value = $details['chado_type_value'];
  791. // Iterate through the columns of the table and see if fields have been
  792. // created for each one. If not, then create them.
  793. $schema = chado_get_schema($table_name);
  794. if (!$schema) {
  795. return;
  796. }
  797. $pkey = $schema['primary key'][0];
  798. $columns = $schema['fields'];
  799. foreach ($columns as $column_name => $details) {
  800. // Skip the source columns in the analysis table. We have a custom
  801. // field for those columns
  802. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  803. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  804. continue;
  805. }
  806. // Skip the infraspecific type_id and name from the organism table as we
  807. // have a special field for those.
  808. if ($table_name == 'organism' and ($column_name == 'type_id' or
  809. $column_name == 'infraspecific_name')) {
  810. continue;
  811. }
  812. // Skip the cvterm.is_relationshptype.
  813. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  814. continue;
  815. }
  816. // The biosourceprovider_id and taxon_id are handled by custom fields.
  817. if ($table_name == 'biomaterial' and (
  818. $column_name == 'biosourceprovider_id' or $column_name == 'taxon_id')) {
  819. continue;
  820. }
  821. // Don't create base fields for the primary key and the type_id field.
  822. if ($column_name == $pkey or $column_name == $type_column) {
  823. continue;
  824. }
  825. $cvterm = chado_get_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  826. if (!$cvterm) {
  827. // We already provided an error when creating the base field. So
  828. // don't create another one here.
  829. continue;
  830. }
  831. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/[^\w]/', '_', $cvterm->name));
  832. $field_name = substr($field_name, 0, 32);
  833. // Skip the primary key field.
  834. if ($column_name == $schema['primary key'][0]) {
  835. continue;
  836. }
  837. // If the type_id defines the content type and it's part of the
  838. // base table and this column is the type_id then skip it.
  839. if (!$type_table and $type_column and $column_name == $type_column) {
  840. continue;
  841. }
  842. // Skip the type ID as it will be handled by a custom field.
  843. if ($column_name == 'type_id') {
  844. continue;
  845. }
  846. $base_info = array(
  847. 'field_name' => $field_name,
  848. 'entity_type' => 'TripalEntity',
  849. 'bundle' => $bundle->name,
  850. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  851. 'description' => '',
  852. 'required' => FALSE,
  853. 'settings' => array(
  854. 'auto_attach' => TRUE,
  855. 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
  856. 'term_name' => $cvterm->name,
  857. 'term_accession' => $cvterm->dbxref_id->accession,
  858. 'chado_table' => $table_name,
  859. 'chado_column' => $column_name,
  860. 'base_table' => $table_name,
  861. ),
  862. 'widget' => array(
  863. 'settings' => array(
  864. 'display_label' => 1,
  865. ),
  866. ),
  867. 'display' => array(
  868. 'default' => array(
  869. 'label' => 'inline',
  870. 'region' =>'Left',
  871. 'settings' => array(),
  872. ),
  873. ),
  874. );
  875. // Determine if the field is required.
  876. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  877. $base_info['required'] = TRUE;
  878. }
  879. // Alter the field info array depending on the column details.
  880. switch($details['type']) {
  881. case 'char':
  882. $base_info['widget']['type'] = 'text_textfield';
  883. break;
  884. case 'varchar':
  885. $base_info['widget']['type'] = 'text_textfield';
  886. break;
  887. case 'text':
  888. $base_info['display']['default']['label'] = 'above';
  889. $base_info['widget']['type'] = 'text_textarea';
  890. $base_info['settings']['text_processing'] = '1';
  891. $base_info['settings']['format'] = 'full_html';
  892. break;
  893. case 'blob':
  894. // not sure how to support a blob field.
  895. continue;
  896. break;
  897. case 'int':
  898. $base_info['widget']['type'] = 'number';
  899. break;
  900. case 'float':
  901. $base_info['widget']['type'] = 'number';
  902. break;
  903. case 'numeric':
  904. $base_info['widget']['type'] = 'number';
  905. break;
  906. case 'serial':
  907. // Serial fields are most likely not needed as a field.
  908. break;
  909. case 'boolean':
  910. $base_info['widget']['type'] = 'options_onoff';
  911. $base_info['required'] = FALSE;
  912. break;
  913. case 'datetime':
  914. $base_info['widget']['type'] = 'date_select';
  915. $base_info['widget']['settings']['increment'] = 1;
  916. $base_info['widget']['settings']['tz_handling'] = 'none';
  917. $base_info['widget']['settings']['collapsible'] = TRUE;
  918. // TODO: Add settings so that the minutes increment by 1.
  919. // And turn off the timezone, as the Chado field doesn't support it.
  920. break;
  921. }
  922. // Set some default semantic web information
  923. if ($column_name == 'uniquename') {
  924. $base_info['label'] = 'Identifier';
  925. $base_info['widget']['type'] = 'text_textfield';
  926. if ($details['type'] == 'text') {
  927. unset($base_info['display']['default']['label']);
  928. unset($base_info['settings']['text_processing']);
  929. unset($base_info['settings']['format']);
  930. }
  931. }
  932. if ($base_info['label'] == 'Timeaccessioned') {
  933. $base_info['label'] = 'Time Accessioned';
  934. $base_info['description'] = 'Please enter the time that this record was first added to the database.';
  935. }
  936. if ($base_info['label'] == 'Timelastmodified') {
  937. $base_info['label'] = 'Time Last Modified';
  938. $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  939. }
  940. // Sometimes the boolean fields are listed as integer. We need to
  941. // correct for that.
  942. if ($column_name == 'is_obsolete' or $column_name == 'is_analysis' or
  943. $column_name == 'is_relationshiptype' or $column_name == 'is_for_definition' or
  944. $column_name == 'is_view' or $column_name == 'is_updateable') {
  945. $base_info['widget']['type'] = 'options_onoff';
  946. $base_info['required'] = FALSE;
  947. }
  948. //
  949. // ORGANISM TABLE
  950. //
  951. if ($table_name == 'organism' and $column_name == 'comment') {
  952. $base_info['label'] = 'Description';
  953. }
  954. //
  955. // BIOMATERIAL TABLE
  956. //
  957. if ($table_name == 'biomaterial' and $column_name == 'name') {
  958. $base_info['widget'] = array();
  959. $base_info['widget']['type'] = 'text_textfield';
  960. unset($base_info['display']['default']['label']);
  961. unset($base_info['settings']['text_processing']);
  962. unset($base_info['settings']['format']);
  963. }
  964. //
  965. // FEATUREMAP TABLE
  966. //
  967. if ($table_name == 'featuremap' and $column_name == 'name') {
  968. $base_info['required'] = TRUE;
  969. }
  970. //
  971. // PUB TABLE
  972. //
  973. if ($table_name == 'pub') {
  974. if ($column_name == 'title' or $column_name == 'type_id') {
  975. $base_info['required'] = TRUE;
  976. }
  977. if($column_name == 'uniquename' or $column_name == 'title' or $column_name == 'volumetitle') {
  978. $base_info['widget']['type'] = 'text_textfield';
  979. $base_info['settings']['text_processing'] = '0';
  980. }
  981. if($column_name == 'uniquename') {
  982. $base_info['label'] = 'Unique Local Identifier';
  983. $base_info['required'] = TRUE;
  984. $base_info['description'] = 'This publication is housed in Chado whic requires a unique identifer (or name) be provided for every publication. This identifier need not be shown to end-users but it is required. Each site must decide on a format for this unique name.';
  985. }
  986. if($column_name == 'title') {
  987. $base_info['description'] = 'The title of the published work.';
  988. }
  989. if($column_name == 'series_name') {
  990. $base_info['description'] = 'The name media that produces a series of publications (e.g. journal, conference proceedings, etc.).';
  991. }
  992. if($column_name == 'issue') {
  993. $base_info['description'] = 'The issue of the series (e.g. journal) where the publication was printed.';
  994. }
  995. if($column_name == 'volume') {
  996. $base_info['description'] = 'The volume of the series (e.g. journal) where the publication was printed.';
  997. }
  998. if($column_name == 'pyear') {
  999. $base_info['label'] = 'Publication Year';
  1000. $base_info['required'] = TRUE;
  1001. }
  1002. if($column_name == 'pages') {
  1003. $base_info['label'] = 'Page Numbers';
  1004. }
  1005. if($column_name == 'pubplace') {
  1006. $base_info['label'] = 'Publication Location';
  1007. }
  1008. if($column_name == 'volumetitle') {
  1009. $base_info['label'] = 'Volumn Title';
  1010. $base_info['label'] = 'The title of the volume (if applicable).';
  1011. }
  1012. if($column_name == 'miniref') {
  1013. $base_info['label'] = 'Mini Local identifier';
  1014. $base_info['description'] = 'Some sites use small identifiers for each publication. if your site uses this please provide the proper miniref for this publication.';
  1015. }
  1016. }
  1017. //
  1018. // ANALYSIS TABLE
  1019. //
  1020. if ($table_name == 'analysis' and $column_name == 'name') {
  1021. $base_info['required'] = TRUE;
  1022. }
  1023. if ($table_name == 'analysis' and $column_name == 'program') {
  1024. $base_info['description'] = 'The program name (e.g. blastx, blastp, sim4, genscan. If the analysis was not derived from a software package then provide a very brief description of the pipeline, workflow or method.';
  1025. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
  1026. }
  1027. if ($table_name == 'analysis' and $column_name == 'algorithm') {
  1028. $base_info['label'] = 'Algorithm';
  1029. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  1030. }
  1031. if ($table_name == 'analysis' and $column_name == 'programversion') {
  1032. $base_info['label'] = 'Program Version';
  1033. $base_info['description'] = 'The version of the program used to perform this analysis. (e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]. Enter "n/a" if no version is available or applicable.';
  1034. }
  1035. if ($table_name == 'analysis' and $column_name == 'timeexecuted') {
  1036. $base_info['label'] = 'Date Performed';
  1037. $base_info['description'] = 'The date and time when the analysis was performed.';
  1038. }
  1039. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  1040. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  1041. // Skip the source columns in the analysis table. We have a custom
  1042. // field for those columns
  1043. continue;
  1044. }
  1045. //
  1046. // PROJECT TABLE
  1047. //
  1048. if ($table_name == 'project' and $column_name == 'description') {
  1049. $base_info['label'] = 'Short Description';
  1050. }
  1051. //
  1052. // CONTACT TABLE
  1053. //
  1054. if ($table_name == 'contact' and $column_name == 'description') {
  1055. $base_info['label'] = 'Short Description';
  1056. }
  1057. //
  1058. // PROTOCOL TABLE
  1059. //
  1060. if ($table_name == 'protocol') {
  1061. if ($column_name == 'protocoldescription') {
  1062. $base_info['label'] = 'Protocol Description';
  1063. }
  1064. if ($column_name == 'uri') {
  1065. $base_info['label'] = 'URI';
  1066. $base_info['widget']['type'] = 'text_textfield';
  1067. $base_info['settings']['text_processing'] = '0';
  1068. }
  1069. if ($column_name == 'name') {
  1070. $base_info['widget']['type'] = 'text_textfield';
  1071. $base_info['settings']['text_processing'] = '0';
  1072. }
  1073. if ($column_name == 'hardwaredescription') {
  1074. $base_info['label'] = 'Instrument Description';
  1075. $base_info['description'] = 'The description of instruments used for this protocol';
  1076. }
  1077. if ($column_name == 'softwaredescription') {
  1078. $base_info['label'] = 'Software Description';
  1079. $base_info['description'] = 'The description of software used for this protocol';
  1080. }
  1081. if ($column_name == 'pub_id') {
  1082. $base_info['label'] = 'Publication';
  1083. }
  1084. }
  1085. //
  1086. // ASSAY TABLE
  1087. //
  1088. if ($table_name == 'assay') {
  1089. if ($column_name == 'name') {
  1090. $base_info['widget']['type'] = 'text_textfield';
  1091. $base_info['settings']['text_processing'] = '0';
  1092. }
  1093. if ($column_name == 'protcol_id') {
  1094. $base_info['label'] = 'Protocol';
  1095. }
  1096. if ($column_name == 'arraybatchidentifier') {
  1097. $base_info['label'] = 'Array Batch Identifier';
  1098. $base_info['widget']['type'] = 'text_textfield';
  1099. $base_info['settings']['text_processing'] = '0';
  1100. }
  1101. if ($column_name == 'operator_id') {
  1102. $base_info['label'] = 'Operator';
  1103. }
  1104. if ($column_name == 'arrayidentifier') {
  1105. $base_info['label'] = 'Array Identifier';
  1106. $base_info['widget']['type'] = 'text_textfield';
  1107. $base_info['settings']['text_processing'] = '0';
  1108. }
  1109. if ($column_name == 'arraydesign_id') {
  1110. $base_info['label'] = 'Array Design';
  1111. }
  1112. if ($column_name == 'assaydate') {
  1113. $base_info['label'] = 'Assay Date';
  1114. }
  1115. }
  1116. //
  1117. // ARRAYDESIGN TABLE
  1118. //
  1119. if ($table_name == 'arraydesign') {
  1120. if ($column_name == 'name' or $column_name == 'version' or
  1121. $column_name == 'array_dimensions' or $column_name == 'element_dimensions') {
  1122. $base_info['widget']['type'] = 'text_textfield';
  1123. $base_info['settings']['text_processing'] = '0';
  1124. }
  1125. if ($column_name == 'platformtype_id') {
  1126. $base_info['label'] = 'Platform type';
  1127. }
  1128. if ($column_name == 'substratetype_id') {
  1129. $base_info['label'] = 'Substrate Type';
  1130. }
  1131. if ($column_name == 'manufacturer_id') {
  1132. $base_info['label'] = 'Manufacturer';
  1133. }
  1134. }
  1135. $info[$field_name] = $base_info;
  1136. }
  1137. }
  1138. /**
  1139. * Helper function for the hook_create_tripalfield_instance().
  1140. *
  1141. * Adds custom fields for base fields. These override the settings provided
  1142. * in the tripal_chado_create_tripalfield_instance_base() function.
  1143. *
  1144. * @param $entity_type
  1145. * @param $bundle
  1146. * @param $details
  1147. */
  1148. function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
  1149. $table_name = $details['chado_table'];
  1150. $type_table = $details['chado_type_table'];
  1151. $type_column = $details['chado_type_column'];
  1152. $cvterm_id = $details['chado_cvterm_id'];
  1153. $type_value = $details['chado_type_value'];
  1154. $schema = chado_get_schema($table_name);
  1155. // An additional type for publications
  1156. if (array_key_exists('type_id', $schema['fields']) and 'type_id' != $type_column) {
  1157. $field_name = 'schema__additional_type';
  1158. $is_required = FALSE;
  1159. if (array_key_exists('not null', $schema['fields']['type_id']) and
  1160. $schema['fields']['type_id']['not null']) {
  1161. $is_required = TRUE;
  1162. }
  1163. $label = ucwords(preg_replace('/_/', ' ', $table_name)) . ' Type';
  1164. $default_vocab = '';
  1165. $parent_term = '';
  1166. switch($table_name) {
  1167. case 'pub':
  1168. $default_vocab = 'tripal_pub';
  1169. $label = 'Publication Type';
  1170. $parent_term = 'TPUB:0000015';
  1171. $description = 'Select the type.';
  1172. break;
  1173. case 'contact':
  1174. $default_vocab = 'tripal_contact';
  1175. $parent_term = 'TContact:0000001';
  1176. $description = 'Select the type.';
  1177. break;
  1178. default:
  1179. $description = t('Enter the name of the term that specifies the type. ' .
  1180. 'The type must be the name of a term in a controlled vocabulary and ' .
  1181. 'the controlled vocabulary should already be loaded into this site.');
  1182. }
  1183. $info[$field_name] = array(
  1184. 'field_name' => $field_name,
  1185. 'entity_type' => $entity_type,
  1186. 'bundle' => $bundle->name,
  1187. 'label' => $label,
  1188. 'description' => $description,
  1189. 'required' => $is_required,
  1190. 'settings' => array(
  1191. 'auto_attach' => TRUE,
  1192. 'chado_table' => $table_name,
  1193. 'chado_column' => 'type_id',
  1194. 'base_table' => $table_name,
  1195. 'vocabulary' => $default_vocab,
  1196. 'parent_term' => $parent_term,
  1197. ),
  1198. 'widget' => array(
  1199. 'type' => 'schema__additional_type_widget',
  1200. 'settings' => array(
  1201. 'display_label' => 1,
  1202. ),
  1203. ),
  1204. 'display' => array(
  1205. 'default' => array(
  1206. 'label' => 'inline',
  1207. 'type' => 'schema__additional_type_formatter',
  1208. 'settings' => array(),
  1209. ),
  1210. ),
  1211. );
  1212. }
  1213. if ($table_name == 'arraydesign') {
  1214. $field_name = 'ncit__technology_platform';
  1215. $default_vocab = '';
  1216. $parent_term = '';
  1217. $description = 'Select the platform type.';
  1218. $info[$field_name] = array(
  1219. 'field_name' => $field_name,
  1220. 'entity_type' => $entity_type,
  1221. 'bundle' => $bundle->name,
  1222. 'label' => 'Platform Type',
  1223. 'description' => $description,
  1224. 'required' => TRUE,
  1225. 'settings' => array(
  1226. 'auto_attach' => TRUE,
  1227. 'chado_table' => $table_name,
  1228. 'chado_column' => 'platformtype_id',
  1229. 'base_table' => $table_name,
  1230. 'vocabulary' => $default_vocab,
  1231. 'parent_term' => $parent_term,
  1232. 'term_vocabulary' => 'NCIT',
  1233. 'term_name' => 'Technology Platform',
  1234. 'term_accession' => 'C45378',
  1235. ),
  1236. 'widget' => array(
  1237. 'type' => 'schema__additional_type_widget',
  1238. 'settings' => array(
  1239. 'display_label' => 1,
  1240. ),
  1241. ),
  1242. 'display' => array(
  1243. 'default' => array(
  1244. 'label' => 'inline',
  1245. 'type' => 'schema__additional_type_formatter',
  1246. 'settings' => array(),
  1247. ),
  1248. ),
  1249. );
  1250. $field_name = 'efo__substrate_type';
  1251. $default_vocab = '';
  1252. $parent_term = '';
  1253. $description = 'Select the substrate type.';
  1254. $info[$field_name] = array(
  1255. 'field_name' => $field_name,
  1256. 'entity_type' => $entity_type,
  1257. 'bundle' => $bundle->name,
  1258. 'label' => 'Substrate Type',
  1259. 'description' => $description,
  1260. 'required' => FALSE,
  1261. 'settings' => array(
  1262. 'auto_attach' => TRUE,
  1263. 'chado_table' => $table_name,
  1264. 'chado_column' => 'substratetype_id',
  1265. 'base_table' => $table_name,
  1266. 'vocabulary' => $default_vocab,
  1267. 'parent_term' => $parent_term,
  1268. 'term_vocabulary' => 'EFO',
  1269. 'term_name' => 'substrate type',
  1270. 'term_accession' => '0005522',
  1271. ),
  1272. 'widget' => array(
  1273. 'type' => 'schema__additional_type_widget',
  1274. 'settings' => array(
  1275. 'display_label' => 1,
  1276. ),
  1277. ),
  1278. 'display' => array(
  1279. 'default' => array(
  1280. 'label' => 'inline',
  1281. 'type' => 'schema__additional_type_formatter',
  1282. 'settings' => array(),
  1283. ),
  1284. ),
  1285. );
  1286. }
  1287. // BASE ORGANISM_ID
  1288. if ($table_name != 'organism' and
  1289. (array_key_exists('organism_id', $schema['fields']) or
  1290. array_key_exists('taxon_id', $schema['fields']))) {
  1291. $field_name = 'obi__organism';
  1292. $is_required = FALSE;
  1293. $table_column = 'organism_id';
  1294. if ($table_name == 'biomaterial') {
  1295. $is_required = FALSE;
  1296. $table_column = 'taxon_id';
  1297. }
  1298. elseif (array_key_exists('not null', $schema['fields']['organism_id']) and
  1299. $schema['fields']['organism_id']['not null']) {
  1300. $is_required = TRUE;
  1301. }
  1302. $info[$field_name] = array(
  1303. 'field_name' => $field_name,
  1304. 'entity_type' => $entity_type,
  1305. 'bundle' => $bundle->name,
  1306. 'label' => 'Organism',
  1307. 'description' => 'The full scientific name for a species..',
  1308. 'required' => $is_required,
  1309. 'settings' => array(
  1310. 'auto_attach' => TRUE,
  1311. 'chado_table' => $table_name,
  1312. 'chado_column' => $table_column,
  1313. 'base_table' => $table_name,
  1314. ),
  1315. 'widget' => array(
  1316. 'type' => 'obi__organism_widget',
  1317. 'settings' => array(
  1318. 'display_label' => 1,
  1319. ),
  1320. ),
  1321. 'display' => array(
  1322. 'default' => array(
  1323. 'label' => 'inline',
  1324. 'type' => 'obi__organism_formatter',
  1325. 'settings' => array(),
  1326. ),
  1327. ),
  1328. );
  1329. }
  1330. if ($table_name == 'biomaterial') {
  1331. $field_name = 'biomaterial__provider_id';
  1332. $field_type = 'local__contact';
  1333. $info[$field_name] = array(
  1334. 'field_name' => $field_name,
  1335. 'entity_type' => $entity_type,
  1336. 'bundle' => $bundle->name,
  1337. 'label' => 'Contact',
  1338. 'description' => 'An indvidual or organization that serves as a contact for this record.',
  1339. 'required' => FALSE,
  1340. 'settings' => array(
  1341. 'auto_attach' => FALSE,
  1342. 'chado_table' => 'biomaterial',
  1343. 'chado_column' => 'biosourceprovider_id',
  1344. 'base_table' => 'biomaterial',
  1345. ),
  1346. 'widget' => array(
  1347. 'type' => 'local__contact_widget',
  1348. 'settings' => array(
  1349. 'display_label' => 1,
  1350. ),
  1351. ),
  1352. 'display' => array(
  1353. 'default' => array(
  1354. 'label' => 'inline',
  1355. 'type' => 'local__contact_formatter',
  1356. 'settings' => array(),
  1357. ),
  1358. ),
  1359. );
  1360. }
  1361. if ($table_name == 'arraydesign') {
  1362. $field_name = 'efo__array_manufacturer';
  1363. $field_type = 'local__contact';
  1364. $info[$field_name] = array(
  1365. 'field_name' => $field_name,
  1366. 'entity_type' => $entity_type,
  1367. 'bundle' => $bundle->name,
  1368. 'label' => 'Manufacturer',
  1369. 'description' => 'A manufacturer\'s contact details',
  1370. 'required' => TRUE,
  1371. 'settings' => array(
  1372. 'auto_attach' => FALSE,
  1373. 'chado_table' => 'arraydesign',
  1374. 'chado_column' => 'manufacturer_id',
  1375. 'base_table' => 'arraydesign',
  1376. 'term_vocabulary' => 'EFO',
  1377. 'term_name' => 'aarray manufacturer',
  1378. 'term_accession' => '0001728',
  1379. ),
  1380. 'widget' => array(
  1381. 'type' => 'local__contact_widget',
  1382. 'settings' => array(
  1383. 'display_label' => 1,
  1384. ),
  1385. ),
  1386. 'display' => array(
  1387. 'default' => array(
  1388. 'label' => 'inline',
  1389. 'type' => 'local__contact_formatter',
  1390. 'settings' => array(),
  1391. ),
  1392. ),
  1393. );
  1394. }
  1395. // BASE CVTERM
  1396. if ($table_name == 'cvterm') {
  1397. $field_name = 'sio__vocabulary';
  1398. $is_required = TRUE;
  1399. $info[$field_name] = array(
  1400. 'field_name' => $field_name,
  1401. 'entity_type' => $entity_type,
  1402. 'bundle' => $bundle->name,
  1403. 'label' => 'Vocabulary',
  1404. 'description' => 'A controlled vocabulary.',
  1405. 'required' => $is_required,
  1406. 'settings' => array(
  1407. 'auto_attach' => TRUE,
  1408. 'chado_table' => $table_name,
  1409. 'chado_column' => 'cv_id',
  1410. 'base_table' => $table_name,
  1411. ),
  1412. 'widget' => array(
  1413. 'type' => 'sio__vocabulary_widget',
  1414. 'settings' => array(
  1415. 'display_label' => 1,
  1416. ),
  1417. ),
  1418. 'display' => array(
  1419. 'default' => array(
  1420. 'label' => 'inline',
  1421. 'type' => 'sio__vocabulary_formatter',
  1422. 'settings' => array(),
  1423. ),
  1424. ),
  1425. );
  1426. }
  1427. // BASE DBXREF
  1428. if (array_key_exists('dbxref_id', $schema['fields'])) {
  1429. $field_name = 'data__accession';
  1430. $info[$field_name] = array(
  1431. 'field_name' => $field_name,
  1432. 'entity_type' => $entity_type,
  1433. 'bundle' => $bundle->name,
  1434. 'label' => 'Accession',
  1435. 'description' => 'This field specifies the unique stable accession (ID) for
  1436. this record. It requires that this site have a database entry.',
  1437. 'required' => FALSE,
  1438. 'settings' => array(
  1439. 'auto_attach' => TRUE,
  1440. 'chado_table' => $table_name,
  1441. 'chado_column' => 'dbxref_id',
  1442. 'base_table' => $table_name,
  1443. ),
  1444. 'widget' => array(
  1445. 'type' => 'data__accession_widget',
  1446. 'settings' => array(
  1447. 'display_label' => 1,
  1448. ),
  1449. ),
  1450. 'display' => array(
  1451. 'default' => array(
  1452. 'label' => 'inline',
  1453. 'type' => 'data__accession_formatter',
  1454. 'settings' => array(),
  1455. ),
  1456. ),
  1457. );
  1458. }
  1459. // FEATURE MD5CHECKSUM
  1460. if ($table_name == 'feature') {
  1461. $field_name = 'data__sequence_checksum';
  1462. $info[$field_name] = array(
  1463. 'field_name' => $field_name,
  1464. 'entity_type' => $entity_type,
  1465. 'bundle' => $bundle->name,
  1466. 'label' => 'Sequence Checksum',
  1467. 'description' => 'The MD5 checksum for the sequence. The checksum here
  1468. will always be unique for the raw unformatted sequence. To verify that the
  1469. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  1470. to calculate the value. If the value calculated is identical the one shown
  1471. here, then the downloaded sequence is uncorrupted.',
  1472. 'required' => FALSE,
  1473. 'settings' => array(
  1474. 'auto_attach' => TRUE,
  1475. 'chado_table' => $table_name,
  1476. 'chado_column' => 'md5checksum',
  1477. 'base_table' => $table_name,
  1478. ),
  1479. 'widget' => array(
  1480. 'type' => 'data__sequence_checksum_widget',
  1481. 'settings' => array(
  1482. 'display_label' => 1,
  1483. 'md5_fieldname' => 'feature__md5checksum',
  1484. ),
  1485. ),
  1486. 'display' => array(
  1487. 'default' => array(
  1488. 'label' => 'inline',
  1489. 'type' => 'data__sequence_checksum_formatter',
  1490. 'settings' => array(),
  1491. ),
  1492. ),
  1493. );
  1494. }
  1495. // FEATURE RESIDUES
  1496. if ($table_name == 'feature') {
  1497. $field_name = 'data__sequence';
  1498. $info[$field_name] = array(
  1499. 'field_name' => $field_name,
  1500. 'entity_type' => $entity_type,
  1501. 'bundle' => $bundle->name,
  1502. 'label' => 'Sequence',
  1503. 'description' => 'One or more molecular sequences, possibly with associated annotation.',
  1504. 'required' => FALSE,
  1505. 'settings' => array(
  1506. 'auto_attach' => FALSE,
  1507. 'chado_table' => $table_name,
  1508. 'chado_column' => 'residues',
  1509. 'base_table' => $table_name,
  1510. ),
  1511. 'widget' => array(
  1512. 'type' => 'data__sequence_widget',
  1513. 'settings' => array(
  1514. 'display_label' => 1,
  1515. ),
  1516. ),
  1517. 'display' => array(
  1518. 'default' => array(
  1519. 'label' => 'above',
  1520. 'type' => 'data__sequence_formatter',
  1521. 'settings' => array(),
  1522. ),
  1523. ),
  1524. );
  1525. }
  1526. // FEATURE SEQLEN
  1527. if ($table_name == 'feature') {
  1528. $field_name = 'data__sequence_length';
  1529. $info[$field_name] = array(
  1530. 'field_name' => $field_name,
  1531. 'entity_type' => $entity_type,
  1532. 'bundle' => $bundle->name,
  1533. 'label' => 'Sequence Length',
  1534. 'description' => 'The number of residues in the raw sequence. This length
  1535. is only for the assigned raw sequence and does not represent the length of any
  1536. sequences derived from alignments. If this value is zero but aligned sequences
  1537. are present then this record has no official assigned sequence.',
  1538. 'required' => FALSE,
  1539. 'settings' => array(
  1540. 'auto_attach' => TRUE,
  1541. 'chado_table' => $table_name,
  1542. 'chado_column' => 'seqlen',
  1543. 'base_table' => $table_name,
  1544. ),
  1545. 'widget' => array(
  1546. 'type' => 'data__sequence_length_widget',
  1547. 'settings' => array(
  1548. 'display_label' => 1,
  1549. ),
  1550. ),
  1551. 'display' => array(
  1552. 'default' => array(
  1553. 'label' => 'inline',
  1554. 'type' => 'data__sequence_length_formatter',
  1555. 'settings' => array(),
  1556. ),
  1557. ),
  1558. );
  1559. }
  1560. // PROTEIN & CDS SEQUENCES.
  1561. if ($table_name == 'feature' and
  1562. ($bundle->label == 'mRNA' or $bundle->label == 'transcript' or $bundle->label == 'Transcript')) {
  1563. $field_name = 'data__protein_sequence';
  1564. $info[$field_name] = array(
  1565. 'field_name' => $field_name,
  1566. 'entity_type' => $entity_type,
  1567. 'bundle' => $bundle->name,
  1568. 'label' => 'Protein Sequence',
  1569. 'description' => 'Protein sequences.',
  1570. 'required' => FALSE,
  1571. 'settings' => array(
  1572. 'auto_attach' => FALSE,
  1573. 'chado_table' => 'feature',
  1574. 'chado_column' => 'residues',
  1575. 'base_table' => 'feature',
  1576. ),
  1577. 'widget' => array(
  1578. 'type' => 'data__protein_sequence_widget',
  1579. 'settings' => array(
  1580. 'display_label' => 1,
  1581. ),
  1582. ),
  1583. 'display' => array(
  1584. 'default' => array(
  1585. 'label' => 'above',
  1586. 'type' => 'data__protein_sequence_formatter',
  1587. 'settings' => array(),
  1588. ),
  1589. ),
  1590. );
  1591. $field_name = 'so__cds';
  1592. $info[$field_name] = array(
  1593. 'field_name' => $field_name,
  1594. 'entity_type' => $entity_type,
  1595. 'bundle' => $bundle->name,
  1596. 'label' => 'Coding Sequence (CDS)',
  1597. 'description' => 'Coding sequences.',
  1598. 'required' => FALSE,
  1599. 'settings' => array(
  1600. 'auto_attach' => FALSE,
  1601. 'chado_table' => 'featureprop',
  1602. 'chado_column' => 'value',
  1603. 'base_table' => 'feature',
  1604. 'term_vocabulary' => 'SO',
  1605. 'term_name' => 'CDS',
  1606. 'term_accession' => '0000316',
  1607. ),
  1608. 'widget' => array(
  1609. 'type' => 'so__cds_widget',
  1610. 'settings' => array(
  1611. 'display_label' => 1,
  1612. ),
  1613. ),
  1614. 'display' => array(
  1615. 'default' => array(
  1616. 'label' => 'above',
  1617. 'type' => 'so__cds_formatter',
  1618. 'settings' => array(),
  1619. ),
  1620. ),
  1621. );
  1622. }
  1623. if ($table_name == 'feature') {
  1624. $field_name = 'local__gbrowse_image';
  1625. $info[$field_name] = array(
  1626. 'field_name' => $field_name,
  1627. 'entity_type' => $entity_type,
  1628. 'bundle' => $bundle->name,
  1629. 'label' => 'GBrowse image',
  1630. 'description' => 'A GBrowse image of a feature alignment.',
  1631. 'required' => FALSE,
  1632. 'settings' => array(
  1633. 'auto_attach' => FALSE,
  1634. 'chado_table' => '',
  1635. 'chado_column' => '',
  1636. 'base_table' => 'feature',
  1637. 'term_vocabulary' => 'local',
  1638. 'term_name' => 'Gbrowse Image',
  1639. 'term_accession' => 'gbrowse_image',
  1640. 'gbrowse_url' => '',
  1641. ),
  1642. 'widget' => array(
  1643. 'type' => 'local__gbrowse_image_widget',
  1644. 'settings' => array(
  1645. 'display_label' => 1,
  1646. ),
  1647. ),
  1648. 'display' => array(
  1649. 'default' => array(
  1650. 'label' => 'above',
  1651. 'type' => 'local__gbrowse_image_formatter',
  1652. 'settings' => array(),
  1653. ),
  1654. ),
  1655. );
  1656. }
  1657. // GENE TRANSCRIPTS
  1658. $rel_table = $table_name . '_relationship';
  1659. if (chado_table_exists($rel_table) and ($bundle->label == 'gene' or $bundle->label == 'Gene')) {
  1660. $field_name = 'so__transcript';
  1661. $info[$field_name] = array(
  1662. 'field_name' => $field_name,
  1663. 'entity_type' => $entity_type,
  1664. 'bundle' => $bundle->name,
  1665. 'label' => 'Transcripts',
  1666. 'description' => 'Transcripts that are part of this gene.',
  1667. 'required' => FALSE,
  1668. 'settings' => array(
  1669. 'auto_attach' => FALSE,
  1670. 'chado_table' => $rel_table,
  1671. 'chado_column' => '',
  1672. 'base_table' => $table_name,
  1673. 'term_vocabulary' => 'SO',
  1674. 'term_name' => 'transcript',
  1675. 'term_accession' => '0000673',
  1676. ),
  1677. 'widget' => array(
  1678. 'type' => 'so__transcript_widget',
  1679. 'settings' => array(
  1680. 'display_label' => 1,
  1681. ),
  1682. ),
  1683. 'display' => array(
  1684. 'default' => array(
  1685. 'label' => 'above',
  1686. 'type' => 'so__transcript_formatter',
  1687. 'settings' => array(),
  1688. ),
  1689. ),
  1690. );
  1691. }
  1692. // ORGANISM TYPE_ID
  1693. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1694. $field_name = 'taxrank__infraspecific_taxon';
  1695. $info[$field_name] = array(
  1696. 'field_name' => $field_name,
  1697. 'entity_type' => $entity_type,
  1698. 'bundle' => $bundle->name,
  1699. 'label' => 'Infraspecific Taxon',
  1700. 'description' => 'The Infraspecific Taxon.',
  1701. 'required' => FALSE,
  1702. 'settings' => array(
  1703. 'auto_attach' => TRUE,
  1704. 'chado_table' => 'organism',
  1705. 'chado_column' => 'type_id',
  1706. 'base_table' => 'organism',
  1707. ),
  1708. 'widget' => array(
  1709. 'type' => 'taxrank__infraspecific_taxon_widget',
  1710. 'settings' => array(
  1711. 'display_label' => 1,
  1712. ),
  1713. ),
  1714. 'display' => array(
  1715. 'default' => array(
  1716. 'label' => 'inline',
  1717. 'type' => 'taxrank__infraspecific_taxon_formatter',
  1718. 'settings' => array(),
  1719. ),
  1720. ),
  1721. );
  1722. }
  1723. // FEATURE MAP UNITS
  1724. if ($table_name == 'featuremap') {
  1725. $field_name = 'uo__unit';
  1726. $info[$field_name] = array(
  1727. 'field_name' => $field_name,
  1728. 'entity_type' => $entity_type,
  1729. 'bundle' => $bundle->name,
  1730. 'label' => 'Units',
  1731. 'description' => 'The map\'s unit type.',
  1732. 'required' => TRUE,
  1733. 'settings' => array(
  1734. 'auto_attach' => TRUE,
  1735. 'chado_table' => $table_name,
  1736. 'chado_column' => 'unittype_id',
  1737. 'base_table' => $table_name,
  1738. ),
  1739. 'widget' => array(
  1740. 'type' => 'uo__unit_widget',
  1741. 'settings' => array(
  1742. 'display_label' => 1,
  1743. ),
  1744. ),
  1745. 'display' => array(
  1746. 'default' => array(
  1747. 'label' => 'inline',
  1748. 'type' => 'uo__unit_formatter',
  1749. 'settings' => array(),
  1750. ),
  1751. ),
  1752. );
  1753. }
  1754. // the analysis source.
  1755. if ($table_name == 'analysis') {
  1756. $field_name = 'local__source_data';
  1757. $info[$field_name] = array(
  1758. 'field_name' => $field_name,
  1759. 'entity_type' => $entity_type,
  1760. 'bundle' => $bundle->name,
  1761. 'label' => 'Data Source',
  1762. 'description' => 'The source where data was obtained for this analysis.',
  1763. 'required' => FALSE,
  1764. 'settings' => array(
  1765. 'auto_attach' => TRUE,
  1766. 'chado_table' => $table_name,
  1767. 'chado_column' => 'analysis_id',
  1768. 'base_table' => $table_name,
  1769. ),
  1770. 'widget' => array(
  1771. 'type' => 'local__source_data_widget',
  1772. 'settings' => array(
  1773. 'display_label' => 1,
  1774. ),
  1775. ),
  1776. 'display' => array(
  1777. 'default' => array(
  1778. 'label' => 'inline',
  1779. 'type' => 'local__source_data_formatter',
  1780. 'settings' => array(),
  1781. ),
  1782. ),
  1783. );
  1784. }
  1785. // Add an image field to the Organism type. This is a Drupal field and
  1786. // not stored in Chado, but is used for backwards compatibility.
  1787. if ($table_name == 'organism') {
  1788. $field_name = 'data__image';
  1789. $info[$field_name] = array(
  1790. 'field_name' => $field_name,
  1791. 'entity_type' => $entity_type,
  1792. 'bundle' => $bundle->name,
  1793. 'label' => 'Organism Image',
  1794. 'description' => 'An image for the organism',
  1795. 'required' => FALSE,
  1796. 'settings' => array(
  1797. 'term_vocabulary' => 'data',
  1798. 'term_name' => 'Image',
  1799. 'term_accession' => '2968',
  1800. ),
  1801. 'display' => array(
  1802. 'default' => array(
  1803. 'label' => 'hidden',
  1804. ),
  1805. ),
  1806. );
  1807. }
  1808. // Phylotree Viewer
  1809. if ($table_name == 'phylotree') {
  1810. $field_name = 'operation__phylotree_vis';
  1811. $schema = chado_get_schema('phylotree');
  1812. $pkey = $schema['primary key'][0];
  1813. $info[$field_name] = array(
  1814. 'field_name' => $field_name,
  1815. 'entity_type' => $entity_type,
  1816. 'bundle' => $bundle->name,
  1817. 'label' => 'Tree View',
  1818. 'description' => 'Rendering of a phylogenetic tree.',
  1819. 'required' => FALSE,
  1820. 'settings' => array(
  1821. 'auto_attach' => FALSE,
  1822. 'chado_table' => 'phylotree',
  1823. 'chado_column' => 'type_id',
  1824. 'base_table' => 'phylotree',
  1825. ),
  1826. 'widget' => array(
  1827. 'type' => 'operation__phylotree_vis_widget',
  1828. 'settings' => array(
  1829. 'display_label' => 0,
  1830. ),
  1831. ),
  1832. 'display' => array(
  1833. 'default' => array(
  1834. 'label' => 'hidden',
  1835. 'type' => 'operation__phylotree_vis_formatter',
  1836. 'settings' => array(),
  1837. ),
  1838. ),
  1839. );
  1840. }
  1841. // PROTOCOL FIELD
  1842. if ($table_name != 'protocol' and
  1843. (array_key_exists('protocol_id', $schema['fields']))) {
  1844. $field_name = 'sep__protocol';
  1845. $is_required = FALSE;
  1846. $table_column = 'protocol_id';
  1847. if (array_key_exists('not null', $schema['fields']['protocol_id']) and
  1848. $schema['fields']['protocol_id']['not null']) {
  1849. $is_required = TRUE;
  1850. }
  1851. $info[$field_name] = array(
  1852. 'field_name' => $field_name,
  1853. 'entity_type' => $entity_type,
  1854. 'bundle' => $bundle->name,
  1855. 'label' => 'Protocol',
  1856. 'description' => 'The parameterizable description of a process',
  1857. 'required' => $is_required,
  1858. 'settings' => array(
  1859. 'auto_attach' => TRUE,
  1860. 'chado_table' => $table_name,
  1861. 'chado_column' => $table_column,
  1862. 'base_table' => $table_name,
  1863. ),
  1864. 'widget' => array(
  1865. 'type' => 'sep__protocol_widget',
  1866. 'settings' => array(
  1867. 'display_label' => 1,
  1868. ),
  1869. ),
  1870. 'display' => array(
  1871. 'default' => array(
  1872. 'label' => 'inline',
  1873. 'type' => 'sep__protocol_formatter',
  1874. 'settings' => array(),
  1875. ),
  1876. ),
  1877. );
  1878. }
  1879. // pub_id field in table.
  1880. $schema = chado_get_schema($table_name);
  1881. if (array_key_exists('pub_id', $schema['fields'])) {
  1882. // Remove the schema__publication added by the
  1883. // tripal_chado_bunde_instnaces_info_base function.
  1884. unset($info['schema__publication']);
  1885. $field_name = 'schema__publication_single';
  1886. $info[$field_name] = array(
  1887. 'field_name' => $field_name,
  1888. 'entity_type' => $entity_type,
  1889. 'bundle' => $bundle->name,
  1890. 'label' => 'Publication',
  1891. 'description' => 'This record has been referenced or is sourced from these publications.',
  1892. 'required' => FALSE,
  1893. 'settings' => array(
  1894. 'auto_attach' => TRUE,
  1895. 'chado_table' => $table_name,
  1896. 'chado_column' => 'pub_id',
  1897. 'base_table' => $table_name,
  1898. ),
  1899. 'widget' => array(
  1900. 'type' => 'schema__publication_widget',
  1901. 'settings' => array(
  1902. 'display_label' => 1,
  1903. ),
  1904. ),
  1905. 'display' => array(
  1906. 'default' => array(
  1907. 'label' => 'hidden',
  1908. 'type' => 'schema__publication_formatter',
  1909. 'settings' => array(),
  1910. ),
  1911. ),
  1912. );
  1913. }
  1914. if ($table_name == 'assay') {
  1915. // Remove the ncit__operator added by the
  1916. // tripal_chado_bunde_instnaces_info_base function.
  1917. unset($info['ncit__operator']);
  1918. $field_name = 'assay__operator_id';
  1919. $info[$field_name] = array(
  1920. 'field_name' => $field_name,
  1921. 'entity_type' => $entity_type,
  1922. 'bundle' => $bundle->name,
  1923. 'label' => 'Operator',
  1924. 'description' => 'The individual responsible for performing the assay.',
  1925. 'required' => TRUE,
  1926. 'settings' => array(
  1927. 'auto_attach' => TRUE,
  1928. 'chado_table' => 'assay',
  1929. 'chado_column' => 'operator_id',
  1930. 'base_table' => 'assay',
  1931. 'term_vocabulary' => 'NCIT',
  1932. 'term_name' => 'Operator',
  1933. 'term_accession' => 'C48036',
  1934. ),
  1935. 'widget' => array(
  1936. 'type' => 'local__contact_widget',
  1937. 'settings' => array(
  1938. 'display_label' => 1,
  1939. ),
  1940. ),
  1941. 'display' => array(
  1942. 'default' => array(
  1943. 'label' => 'inline',
  1944. 'type' => 'local__contact_formatter',
  1945. 'settings' => array(),
  1946. ),
  1947. ),
  1948. );
  1949. }
  1950. }
  1951. /**
  1952. *
  1953. * @param unknown $entity_type
  1954. * @param unknown $bundle
  1955. * @param unknown $details
  1956. */
  1957. function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
  1958. $table_name = $details['chado_table'];
  1959. $type_table = $details['chado_type_table'];
  1960. $type_column = $details['chado_type_column'];
  1961. $cvterm_id = $details['chado_cvterm_id'];
  1962. $type_value = $details['chado_type_value'];
  1963. // CONTACTS
  1964. $contact_table = $table_name . '_contact';
  1965. if (chado_table_exists($contact_table)) {
  1966. $field_name = $table_name . '_contact';
  1967. $info[$field_name] = $info[$field_name] = array(
  1968. 'field_name' => $field_name,
  1969. 'entity_type' => $entity_type,
  1970. 'bundle' => $bundle->name,
  1971. 'label' => 'Contact',
  1972. 'description' => 'Associates an indviddual or organization with this record',
  1973. 'required' => FALSE,
  1974. 'settings' => array(
  1975. 'auto_attach' => FALSE,
  1976. 'chado_table' => $contact_table,
  1977. 'base_table' => $table_name,
  1978. 'chado_column' => 'contact_id',
  1979. ),
  1980. 'widget' => array(
  1981. 'type' => 'local__contact_widget',
  1982. 'settings' => array(
  1983. 'display_label' => 1,
  1984. ),
  1985. ),
  1986. 'display' => array(
  1987. 'default' => array(
  1988. 'label' => 'hidden',
  1989. 'type' => 'local__contact_formatter',
  1990. 'settings' => array(),
  1991. ),
  1992. ),
  1993. );
  1994. }
  1995. // DBXREF
  1996. $dbxref_table = $table_name . '_dbxref';
  1997. if (chado_table_exists($dbxref_table)) {
  1998. $field_name = 'sbo__database_cross_reference';
  1999. $schema = chado_get_schema($dbxref_table);
  2000. $pkey = $schema['primary key'][0];
  2001. $info[$field_name] = array(
  2002. 'field_name' => $field_name,
  2003. 'entity_type' => $entity_type,
  2004. 'bundle' => $bundle->name,
  2005. 'label' => 'Cross Reference',
  2006. 'description' => 'The IDs where this record may be available in other external online databases.',
  2007. 'required' => FALSE,
  2008. 'settings' => array(
  2009. 'auto_attach' => FALSE,
  2010. 'chado_table' => $dbxref_table,
  2011. 'chado_column' => $pkey,
  2012. 'base_table' => $table_name,
  2013. ),
  2014. 'widget' => array(
  2015. 'type' => 'sbo__database_cross_reference_widget',
  2016. 'settings' => array(
  2017. 'display_label' => 1,
  2018. ),
  2019. ),
  2020. 'display' => array(
  2021. 'default' => array(
  2022. 'label' => 'hidden',
  2023. 'type' => 'sbo__database_cross_reference_formatter',
  2024. 'settings' => array(),
  2025. ),
  2026. ),
  2027. );
  2028. }
  2029. // EXPRESSION
  2030. // TODO: this should only show up on gene or mRNA and the GO must be
  2031. // laoded or this field will crash things.
  2032. // $expression_table = $table_name . '_expression';
  2033. // if (chado_table_exists($expression_table)) {
  2034. // $field_name = 'go__gene_expression';
  2035. // $schema = chado_get_schema($expression_table);
  2036. // $pkey = $schema['primary key'][0];
  2037. // $info[$field_name] = array(
  2038. // 'field_name' => $field_name,
  2039. // 'entity_type' => $entity_type,
  2040. // 'bundle' => $bundle->name,
  2041. // 'label' => 'Gene expression',
  2042. // 'description' => 'Information about the expression of this record.',
  2043. // 'required' => FALSE,
  2044. // 'settings' => array(
  2045. // 'auto_attach' => FALSE,
  2046. // 'chado_table' => $expression_table,
  2047. // 'chado_column' => $pkey,
  2048. // 'base_table' => $table_name,
  2049. // ),
  2050. // 'widget' => array(
  2051. // 'type' => 'go__gene_expression_widget',
  2052. // 'settings' => array(
  2053. // 'display_label' => 1,
  2054. // ),
  2055. // ),
  2056. // 'display' => array(
  2057. // 'default' => array(
  2058. // 'label' => 'above',
  2059. // 'type' => 'go__gene_expression_formatter',
  2060. // 'settings' => array(),
  2061. // ),
  2062. // ),
  2063. // );
  2064. // }
  2065. // FEATURELOC
  2066. if ($table_name == 'feature') {
  2067. $field_name = 'data__sequence_coordinates';
  2068. $schema = chado_get_schema('featureloc');
  2069. $pkey = $schema['primary key'][0];
  2070. $info[$field_name] = array(
  2071. 'field_name' => $field_name,
  2072. 'entity_type' => $entity_type,
  2073. 'bundle' => $bundle->name,
  2074. 'label' => 'Sequence Coordinates',
  2075. 'description' => 'The locations on other genomic sequences where this
  2076. record has been aligned.',
  2077. 'required' => FALSE,
  2078. 'settings' => array(
  2079. 'auto_attach' => FALSE,
  2080. 'chado_table' => 'featureloc',
  2081. 'chado_column' => $pkey,
  2082. 'base_table' => 'feature',
  2083. ),
  2084. 'widget' => array(
  2085. 'type' => 'data__sequence_coordinates_widget',
  2086. 'settings' => array(
  2087. 'display_label' => 1,
  2088. ),
  2089. ),
  2090. 'display' => array(
  2091. 'default' => array(
  2092. 'label' => 'hidden',
  2093. 'type' => 'data__sequence_coordinates_formatter',
  2094. 'settings' => array(),
  2095. ),
  2096. ),
  2097. );
  2098. }
  2099. // FEATUREPOS
  2100. if ($table_name == 'feature') {
  2101. $field_name = 'ogi__location_on_map';
  2102. $schema = chado_get_schema('featurepos');
  2103. $pkey = $schema['primary key'][0];
  2104. $info[$field_name] = array(
  2105. 'field_name' => $field_name,
  2106. 'entity_type' => $entity_type,
  2107. 'bundle' => $bundle->name,
  2108. 'label' => 'Location on Map',
  2109. 'description' => 'The positions on a genetic map.',
  2110. 'required' => FALSE,
  2111. 'settings' => array(
  2112. 'auto_attach' => FALSE,
  2113. 'chado_table' => 'featurepos',
  2114. 'chado_column' => $pkey,
  2115. 'base_table' => 'feature',
  2116. ),
  2117. 'widget' => array(
  2118. 'type' => 'ogi__location_on_map_widget',
  2119. 'settings' => array(
  2120. 'display_label' => 1,
  2121. ),
  2122. ),
  2123. 'display' => array(
  2124. 'default' => array(
  2125. 'label' => 'hidden',
  2126. 'type' => 'ogi__location_on_map_formatter',
  2127. 'settings' => array(),
  2128. ),
  2129. ),
  2130. );
  2131. }
  2132. // // GENOTYPE
  2133. // $genotype_table = $table_name . '_genotype';
  2134. // if (chado_table_exists($genotype_table)) {
  2135. // $field_name = 'so__genotype';
  2136. // $schema = chado_get_schema($genotype_table);
  2137. // $pkey = $schema['primary key'][0];
  2138. // $info[$field_name] = array(
  2139. // 'field_name' => $field_name,
  2140. // 'entity_type' => $entity_type,
  2141. // 'bundle' => $bundle->name,
  2142. // 'label' => 'Genotype',
  2143. // 'description' => 'The genotypes associated with this record.',
  2144. // 'required' => FALSE,
  2145. // 'settings' => array(
  2146. // 'auto_attach' => FALSE,
  2147. // 'chado_table' => $genotype_table,
  2148. // 'chado_column' => $pkey,
  2149. // 'base_table' => $table_name,
  2150. // ),
  2151. // 'widget' => array(
  2152. // 'type' => 'so__genotype_widget',
  2153. // 'settings' => array(
  2154. // 'display_label' => 1,
  2155. // ),
  2156. // ),
  2157. // 'display' => array(
  2158. // 'default' => array(
  2159. // 'label' => 'hidden',
  2160. // 'type' => 'so__genotype_formatter',
  2161. // 'settings' => array(),
  2162. // ),
  2163. // ),
  2164. // );
  2165. // }
  2166. // // PHENOTYPE
  2167. // $phenotype_table = $table_name . '_phenotype';
  2168. // if (chado_table_exists($phenotype_table)) {
  2169. // $field_name = 'sbo__phenotype';
  2170. // $schema = chado_get_schema($phenotype_table);
  2171. // $pkey = $schema['primary key'][0];
  2172. // $info[$field_name] = array(
  2173. // 'field_name' => $field_name,
  2174. // 'entity_type' => $entity_type,
  2175. // 'bundle' => $bundle->name,
  2176. // 'label' => 'Phenotype',
  2177. // 'description' => 'The phenotypes associated with this record.',
  2178. // 'required' => FALSE,
  2179. // 'settings' => array(
  2180. // 'auto_attach' => FALSE,
  2181. // 'chado_table' => $phenotype_table,
  2182. // 'chado_column' => $pkey,
  2183. // 'base_table' => $table_name,
  2184. // ),
  2185. // 'widget' => array(
  2186. // 'type' => 'sbo__phenotype_widget',
  2187. // 'settings' => array(
  2188. // 'display_label' => 1,
  2189. // ),
  2190. // ),
  2191. // 'display' => array(
  2192. // 'default' => array(
  2193. // 'label' => 'hidden',
  2194. // 'type' => 'sbo__phenotype_formatter',
  2195. // 'settings' => array(),
  2196. // ),
  2197. // ),
  2198. // );
  2199. // }
  2200. // PROPERTIES
  2201. $prop_table = $table_name . 'prop';
  2202. if (chado_table_exists($prop_table)) {
  2203. $tschema = chado_get_schema($table_name);
  2204. $schema = chado_get_schema($prop_table);
  2205. $tpkey = $tschema['primary key'][0];
  2206. $pkey = $schema['primary key'][0];
  2207. // Property tables can be a bit tricky because not all property types
  2208. // in the prop table are appropriate for each type of data. Also som
  2209. // bundle types are resolved via a property. So, we have to distinguish
  2210. // between these two cases.
  2211. $sql = '';
  2212. $args = array();
  2213. // First, is this the case where all of the records in the table are
  2214. // of this type? If so, then all properties apply
  2215. if (!$type_column) {
  2216. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  2217. $props = chado_query($sql, $args);
  2218. }
  2219. // Second, if this is the case where a content type is uniquely identified
  2220. // by a type_id value in the base table, then only properties associated
  2221. // with that type ID should be used.
  2222. else if ($type_column and !$type_table) {
  2223. $sql = "
  2224. SELECT DISTINCT P.type_id
  2225. FROM {" . $prop_table . "} P
  2226. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  2227. WHERE T.$type_column = :cvterm_id
  2228. ";
  2229. $args[':cvterm_id'] = $cvterm_id;
  2230. $props = chado_query($sql, $args);
  2231. }
  2232. // Third, if this is the case where a content type is uniquely identified
  2233. // via a term/value pair in the prop table.
  2234. else if ($type_column and $type_table == $prop_table and !empty($type_value)) {
  2235. $sql = "
  2236. SELECT DISTINCT P2.type_id
  2237. FROM {" . $prop_table . "} P1
  2238. INNER JOIN {" . $table_name . "} T on T.$tpkey = P1.$tpkey
  2239. INNER JOIN {" . $prop_table . "} P2 on T.$tpkey = P2.$tpkey
  2240. WHERE P1.$type_column = :cvterm_id AND P1.value = :prop_value AND
  2241. P2.type_id != P1.type_id
  2242. ";
  2243. $args[':cvterm_id'] = $cvterm_id;
  2244. $args[':prop_value'] = $type_value;
  2245. $props = chado_query($sql, $args);
  2246. }
  2247. // Fourth, if this is the case where the content type is uinquely identifed
  2248. // via another table (e.g. cvterm linking table) and not this prop table.
  2249. else if ($type_column and $type_table != $prop_table and empty($type_value)) {
  2250. $sql = "
  2251. SELECT DISTINCT P.type_id
  2252. FROM {" . $prop_table . "} P
  2253. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  2254. INNER JOIN {" . $type_table . "} TT on TT.$tpkey = T.$tpkey
  2255. WHERE TT.$type_column = :cvterm_id
  2256. ";
  2257. $args[':cvterm_id'] = $cvterm_id;
  2258. $props = chado_query($sql, $args);
  2259. }
  2260. else {
  2261. // Do nothing;
  2262. }
  2263. if ($props) {
  2264. while ($prop = $props->fetchObject()) {
  2265. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  2266. $term = chado_expand_var($term, 'field', 'cvterm.definition');
  2267. // Skip the Publiation Type property for pubs as this is
  2268. // already handled by the pub.type_id field.
  2269. if ($term->name == 'Publication Type' and $term->cv_id->name == 'tripal_pub') {
  2270. continue;
  2271. }
  2272. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  2273. // tripal_analysis_interpro modules store results in the analysisprop
  2274. // table which is probably not the best place, but we don't want to
  2275. // create a ton of fields for this.
  2276. if ($prop_table == 'analysisprop' and
  2277. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  2278. $term->dbxref_id->db_id->name == 'tripal')) {
  2279. continue;
  2280. }
  2281. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  2282. $field_name = substr($field_name, 0, 32);
  2283. $info[$field_name] = array(
  2284. 'field_name' => $field_name,
  2285. 'entity_type' => $entity_type,
  2286. 'bundle' => $bundle->name,
  2287. 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
  2288. 'description' => $term->definition,
  2289. 'required' => FALSE,
  2290. 'settings' => array(
  2291. 'auto_attach' => TRUE,
  2292. 'term_vocabulary' => $term->dbxref_id->db_id->name,
  2293. 'term_accession' => $term->dbxref_id->accession,
  2294. 'term_name' => $term->name,
  2295. 'base_table' => $table_name,
  2296. 'chado_table' => $prop_table,
  2297. 'chado_column' => $pkey,
  2298. ),
  2299. 'widget' => array(
  2300. 'type' => 'chado_linker__prop_widget',
  2301. 'settings' => array(
  2302. 'display_label' => 1,
  2303. ),
  2304. ),
  2305. 'display' => array(
  2306. 'default' => array(
  2307. 'label' => 'hidden',
  2308. 'type' => 'chado_linker__prop_formatter',
  2309. 'settings' => array(),
  2310. ),
  2311. ),
  2312. );
  2313. // Make some customizations to some fields
  2314. if ($term->name == 'Citation' and $term->cv_id->name == 'tripal_pub') {
  2315. $info[$field_name]['required'] = TRUE;
  2316. $info[$field_name]['description'] = t('All publications must have a unique citation.
  2317. Please enter the full citation for this publication. For PubMed style citations list
  2318. the last name of the author followed by initials. Each author should be separated by a comma. Next comes
  2319. the title, followed by the series title (e.g. journal name), publication date (4 digit year, 3 character Month, day), volume, issue and page numbers. You may also use HTML to provide a link in the citation.
  2320. Below is an example: <pre>Medeiros PM, Ladio AH, Santos AM, Albuquerque UP. <a href="http://www.ncbi.nlm.nih.gov/pubmed/23462414" target="_blank">Does the selection of medicinal plants by Brazilian local populations
  2321. suffer taxonomic influence?</a> J Ethnopharmacol. 2013 Apr 19; 146(3):842-52.</pre>');
  2322. $info[$field_name]['settings']['rows'] = 3;
  2323. }
  2324. if ($term->name == 'Abstract' and $term->cv_id->name == 'tripal_pub') {
  2325. $info[$field_name]['settings']['rows'] = 5;
  2326. }
  2327. }
  2328. }
  2329. }
  2330. // CVTERMS
  2331. $term_table = $table_name . '_cvterm';
  2332. if (chado_table_exists($term_table)) {
  2333. $schema = chado_get_schema($term_table);
  2334. $pkey = $schema['primary key'][0];
  2335. $lkey = key($schema['foreign keys'][$table_name]['columns']);
  2336. $rkey = $schema['foreign keys'][$table_name]['columns'][$lkey];
  2337. $field_name = 'sio__annotation';
  2338. $info[$field_name] = array(
  2339. 'field_name' => $field_name,
  2340. 'entity_type' => $entity_type,
  2341. 'bundle' => $bundle->name,
  2342. 'label' => 'Annotations',
  2343. 'description' => 'Annotations that are associated with this record.',
  2344. 'required' => FALSE,
  2345. 'settings' => array(
  2346. 'auto_attach' => FALSE,
  2347. 'chado_table' => $term_table,
  2348. 'chado_column' => $pkey,
  2349. 'base_table' => $table_name,
  2350. ),
  2351. 'widget' => array(
  2352. 'type' => 'sio__annotation_widget',
  2353. 'settings' => array(
  2354. 'display_label' => 1,
  2355. ),
  2356. ),
  2357. 'display' => array(
  2358. 'default' => array(
  2359. 'label' => 'hidden',
  2360. 'type' => 'sio__annotation_formatter',
  2361. 'settings' => array(),
  2362. ),
  2363. ),
  2364. );
  2365. }
  2366. // PUBLICATIONS
  2367. $pub_table = $table_name . '_pub';
  2368. if (chado_table_exists($pub_table)) {
  2369. $field_name = 'schema__publication';
  2370. $schema = chado_get_schema($pub_table);
  2371. $pkey = $schema['primary key'][0];
  2372. $info[$field_name] = array(
  2373. 'field_name' => $field_name,
  2374. 'entity_type' => $entity_type,
  2375. 'bundle' => $bundle->name,
  2376. 'label' => 'Publication',
  2377. 'description' => 'This record has been referenced or is sourced from these publications.',
  2378. 'required' => FALSE,
  2379. 'settings' => array(
  2380. 'auto_attach' => FALSE,
  2381. 'chado_table' => $pub_table,
  2382. 'chado_column' => $pkey,
  2383. 'base_table' => $table_name,
  2384. ),
  2385. 'widget' => array(
  2386. 'type' => 'schema__publication_widget',
  2387. 'settings' => array(
  2388. 'display_label' => 1,
  2389. ),
  2390. ),
  2391. 'display' => array(
  2392. 'default' => array(
  2393. 'label' => 'hidden',
  2394. 'type' => 'schema__publication_formatter',
  2395. 'settings' => array(),
  2396. ),
  2397. ),
  2398. );
  2399. }
  2400. // PUBLICATIONS (in reverse)
  2401. // We want to be able to show all of the content that a publication links
  2402. // to. The sio__references field does that.
  2403. if ($table_name == 'pub') {
  2404. $field_name = 'sio__references';
  2405. $schema = chado_get_schema($table_name);
  2406. $pkey = $schema['primary key'][0];
  2407. $info[$field_name] = array(
  2408. 'field_name' => $field_name,
  2409. 'entity_type' => $entity_type,
  2410. 'bundle' => $bundle->name,
  2411. 'label' => 'References',
  2412. 'description' => 'Records that are referred to by the publication.',
  2413. 'required' => FALSE,
  2414. 'settings' => array(
  2415. 'auto_attach' => FALSE,
  2416. 'chado_table' => $table_name,
  2417. 'chado_column' => $pkey,
  2418. 'base_table' => $table_name,
  2419. ),
  2420. 'widget' => array(
  2421. 'type' => 'sio__references_widget',
  2422. 'settings' => array(
  2423. 'display_label' => 1,
  2424. ),
  2425. ),
  2426. 'display' => array(
  2427. 'default' => array(
  2428. 'label' => 'hidden',
  2429. 'type' => 'sio__references_formatter',
  2430. 'settings' => array(),
  2431. ),
  2432. ),
  2433. );
  2434. }
  2435. // RELATIONSHIPS
  2436. // If the linker table does not exists then we don't want to add attach.
  2437. $rel_table = $table_name . '_relationship';
  2438. if (chado_table_exists($rel_table)) {
  2439. $field_name = 'sbo__relationship';
  2440. $schema = chado_get_schema($rel_table);
  2441. $pkey = $schema['primary key'][0];
  2442. $info[$field_name] = array(
  2443. 'field_name' => $field_name,
  2444. 'entity_type' => $entity_type,
  2445. 'bundle' => $bundle->name,
  2446. 'label' => 'Relationship',
  2447. 'description' => 'Other records with relationships to this record.',
  2448. 'required' => FALSE,
  2449. 'settings' => array(
  2450. 'auto_attach' => FALSE,
  2451. 'chado_table' => $rel_table,
  2452. 'chado_column' => $pkey,
  2453. 'base_table' => $table_name,
  2454. ),
  2455. 'widget' => array(
  2456. 'type' => 'sbo__relationship_widget',
  2457. 'settings' => array(
  2458. 'display_label' => 1,
  2459. ),
  2460. ),
  2461. 'display' => array(
  2462. 'default' => array(
  2463. 'label' => 'hidden',
  2464. 'type' => 'sbo__relationship_formatter',
  2465. 'settings' => array(),
  2466. ),
  2467. ),
  2468. );
  2469. }
  2470. // SYNONYMS
  2471. $syn_table = $table_name . '_synonym';
  2472. if (chado_table_exists($syn_table)) {
  2473. $field_name = 'schema__alternate_name';
  2474. $schema = chado_get_schema($syn_table);
  2475. $pkey = $schema['primary key'][0];
  2476. $info[$field_name] = array(
  2477. 'field_name' => $field_name,
  2478. 'entity_type' => $entity_type,
  2479. 'bundle' => $bundle->name,
  2480. 'label' => 'Synonyms',
  2481. 'description' => 'Alternate names, aliases or synonyms for this record.',
  2482. 'required' => FALSE,
  2483. 'settings' => array(
  2484. 'auto_attach' => FALSE,
  2485. 'chado_table' => $syn_table,
  2486. 'chado_column' => $pkey,
  2487. 'base_table' => $table_name,
  2488. ),
  2489. 'widget' => array(
  2490. 'type' => 'schema__alternate_name_widget',
  2491. 'settings' => array(
  2492. 'display_label' => 1,
  2493. ),
  2494. ),
  2495. 'display' => array(
  2496. 'default' => array(
  2497. 'label' => 'hidden',
  2498. 'type' => 'schema__alternate_name_formatter',
  2499. 'settings' => array(),
  2500. ),
  2501. ),
  2502. );
  2503. }
  2504. }
  2505. /**
  2506. * Implements hook_bundle_create_user_field().
  2507. *
  2508. * A priviledged user has the ability to add new fields to the bundle. The
  2509. * chado_linker__prop and chado_linker__cvterm fields are allowed to be
  2510. * added dynamically by the user. But, Drupal doesn't know how to deal with
  2511. * it, so this function is called for any field attached to a TripalEntity
  2512. * bundle type. Any fields whose TripalField::$module argument is set to
  2513. * 'tripal_chado' and that can be added dynamically will result in a call
  2514. * to this function.
  2515. */
  2516. function tripal_chado_bundle_create_user_field($new_field, $bundle) {
  2517. // Get the table this bundle is mapped to.
  2518. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  2519. $vocab = $term->vocab;
  2520. $params = array(
  2521. 'vocabulary' => $vocab->vocabulary,
  2522. 'accession' => $term->accession,
  2523. );
  2524. $chado_table = $bundle->data_table;
  2525. $chado_type_table = $bundle->type_linker_table;
  2526. $chado_type_column = $bundle->type_column;
  2527. $chado_type_id = $bundle->type_id;
  2528. $chado_type_value = $bundle->type_value;
  2529. // We allow site admins to add new chado_linker__prop fields to an entity.
  2530. // This function will allow us to properly add them. But at this point we
  2531. // don't know the controlled vocabulary term. We'll have to use the
  2532. // defaults and let the user set it using the interface.
  2533. if ($new_field['type'] == 'chado_linker__prop') {
  2534. $table_name = $chado_table . 'prop';
  2535. if (chado_table_exists($table_name)) {
  2536. $schema = chado_get_schema($table_name);
  2537. $pkey = $schema['primary key'][0];
  2538. $field_name = $new_field['field_name'];
  2539. $field_type = 'chado_linker__prop';
  2540. // First add the field.
  2541. field_create_field(array(
  2542. 'field_name' => $field_name,
  2543. 'type' => $field_type,
  2544. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2545. 'locked' => FALSE,
  2546. 'storage' => array(
  2547. 'type' => 'field_chado_storage',
  2548. ),
  2549. ));
  2550. // Now add the instance
  2551. field_create_instance(array(
  2552. 'field_name' => $field_name,
  2553. 'entity_type' => 'TripalEntity',
  2554. 'bundle' => $bundle->name,
  2555. 'label' => $new_field['label'],
  2556. 'description' => '',
  2557. 'required' => FALSE,
  2558. 'settings' => array(
  2559. 'auto_attach' => TRUE,
  2560. 'base_table' => $chado_table,
  2561. 'chado_table' => $table_name,
  2562. 'chado_column' => $pkey,
  2563. 'term_vocabulary' => '',
  2564. 'term_accession' => '',
  2565. 'term_name' => ''
  2566. ),
  2567. 'widget' => array(
  2568. 'type' => 'chado_linker__prop_widget',
  2569. 'settings' => array(
  2570. 'display_label' => 1,
  2571. ),
  2572. ),
  2573. 'display' => array(
  2574. 'default' => array(
  2575. 'label' => 'inline',
  2576. 'type' => 'chado_linker__prop_formatter',
  2577. 'settings' => array(),
  2578. ),
  2579. ),
  2580. ));
  2581. }
  2582. else {
  2583. drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
  2584. }
  2585. }
  2586. // We allow site admins to add new chado_linker__cvterm fields to an entity.
  2587. // This function will allow us to properly add them. But at this point we
  2588. // don't know the controlled vocabulary term. We'll have to use the
  2589. // defaults and let the user set it using the interface.
  2590. if ($new_field['type'] == 'chado_linker__cvterm') {
  2591. $table_name = $chado_table . '_cvterm';
  2592. if (chado_table_exists($table_name)) {
  2593. $schema = chado_get_schema($table_name);
  2594. $pkey = $schema['primary key'][0];
  2595. $field_name = $new_field['field_name'];
  2596. $field_type = 'chado_linker__cvterm';
  2597. // First add the field.
  2598. field_create_field(array(
  2599. 'field_name' => $field_name,
  2600. 'type' => $field_type,
  2601. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  2602. 'locked' => FALSE,
  2603. 'storage' => array(
  2604. 'type' => 'field_chado_storage',
  2605. ),
  2606. 'settings' => array(
  2607. 'base_table' => $chado_table,
  2608. 'chado_table' => $table_name,
  2609. 'chado_column' => $pkey,
  2610. ),
  2611. ));
  2612. // Now add the instance
  2613. field_create_instance(array(
  2614. 'field_name' => $field_name,
  2615. 'entity_type' => 'TripalEntity',
  2616. 'bundle' => $bundle->name,
  2617. 'label' => $new_field['label'],
  2618. 'description' => '',
  2619. 'required' => FALSE,
  2620. 'settings' => array(
  2621. 'auto_attach' => TRUE,
  2622. ),
  2623. 'widget' => array(
  2624. 'type' => 'chado_linker__cvterm_widget',
  2625. 'settings' => array(
  2626. 'display_label' => 1,
  2627. ),
  2628. ),
  2629. 'display' => array(
  2630. 'default' => array(
  2631. 'label' => 'above',
  2632. 'type' => 'chado_linker__cvterm_formatter',
  2633. 'settings' => array(),
  2634. ),
  2635. ),
  2636. ));
  2637. }
  2638. else {
  2639. drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
  2640. }
  2641. }
  2642. }
  2643. /**
  2644. * Allows for altering of a field's instance setting form.
  2645. *
  2646. * This appears to be a Drupal hook but is actually a custom function created
  2647. * by this module. It is called by the tripal_form_alter() function of this
  2648. * module.
  2649. *
  2650. * Here we put additional form elements for any field, regardless if it is
  2651. * a tripalField or not.
  2652. *
  2653. * @param $form
  2654. * The form array. Alterations to the form can be made within this array.
  2655. * @param $form_state
  2656. * The form state array.
  2657. */
  2658. function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
  2659. global $language;
  2660. $field = $form['#field'];
  2661. $instance = $form['#instance'];
  2662. $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
  2663. $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
  2664. $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
  2665. if ($chado_table) {
  2666. // Construct a table for the vocabulary information.
  2667. $headers = array();
  2668. $rows = array();
  2669. $rows[] = array(
  2670. array(
  2671. 'data' => 'Base Table',
  2672. 'header' => TRUE,
  2673. 'width' => '20%',
  2674. ),
  2675. $base_table
  2676. );
  2677. $rows[] = array(
  2678. array(
  2679. 'data' => 'Record Table',
  2680. 'header' => TRUE,
  2681. 'width' => '20%',
  2682. ),
  2683. $chado_table
  2684. );
  2685. $rows[] = array(
  2686. array(
  2687. 'data' => 'ID Column',
  2688. 'header' => TRUE,
  2689. 'width' => '20%',
  2690. ),
  2691. $chado_column
  2692. );
  2693. $table = array(
  2694. 'header' => $headers,
  2695. 'rows' => $rows,
  2696. 'attributes' => array(
  2697. ),
  2698. 'sticky' => FALSE,
  2699. 'caption' => '',
  2700. 'colgroups' => array(),
  2701. 'empty' => '',
  2702. );
  2703. $form['chado_mapping'] = array(
  2704. '#type' => 'fieldset',
  2705. '#title' => 'Chado Mapping',
  2706. '#description' => t('This field maps to data in Chado to the following table:'),
  2707. );
  2708. $form['chado_mapping']['details'] = array(
  2709. '#type' => 'item',
  2710. '#markup' => theme_table($table),
  2711. );
  2712. }
  2713. }
  2714. /**
  2715. * Implements hook_form_FROM_ID_alter()
  2716. */
  2717. function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
  2718. global $language;
  2719. $bundle = $form['#bundle'];
  2720. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  2721. $term = reset($term);
  2722. $vocab = $term->vocab;
  2723. $params = array(
  2724. 'vocabulary' => $vocab->vocabulary,
  2725. 'accession' => $term->accession,
  2726. );
  2727. $chado_table = $bundle->data_table;
  2728. $chado_column = $bundle->type_column;
  2729. $chado_type_table = $bundle->type_linker_table;
  2730. $chado_type_id = $bundle->type_id;
  2731. $chado_type_value = $bundle->type_value;
  2732. // Construct a table for the vocabulary information.
  2733. $headers = array();
  2734. $rows = array();
  2735. $rows[] = array(
  2736. array(
  2737. 'data' => 'Chado Table',
  2738. 'header' => TRUE,
  2739. 'width' => '20%',
  2740. ),
  2741. $chado_table
  2742. );
  2743. if ($chado_column) {
  2744. $rows[] = array(
  2745. array(
  2746. 'data' => 'Type Column',
  2747. 'header' => TRUE,
  2748. 'width' => '20%',
  2749. ),
  2750. $chado_column
  2751. );
  2752. }
  2753. if ($chado_type_table) {
  2754. $rows[] = array(
  2755. array(
  2756. 'data' => 'Association Table',
  2757. 'header' => TRUE,
  2758. 'width' => '20%',
  2759. ),
  2760. $chado_type_table
  2761. );
  2762. }
  2763. if ($chado_type_table and $chado_type_id) {
  2764. $rows[] = array(
  2765. array(
  2766. 'data' => 'CVTerm Table ID',
  2767. 'header' => TRUE,
  2768. 'width' => '20%',
  2769. ),
  2770. $chado_type_id
  2771. );
  2772. }
  2773. if ($chado_type_value) {
  2774. $rows[] = array(
  2775. array(
  2776. 'data' => 'Property Value',
  2777. 'header' => TRUE,
  2778. 'width' => '20%',
  2779. ),
  2780. $chado_type_value
  2781. );
  2782. }
  2783. $table = array(
  2784. 'header' => $headers,
  2785. 'rows' => $rows,
  2786. 'attributes' => array(
  2787. ),
  2788. 'sticky' => FALSE,
  2789. 'caption' => '',
  2790. 'colgroups' => array(),
  2791. 'empty' => '',
  2792. );
  2793. $form['chado_mapping'] = array(
  2794. '#type' => 'item',
  2795. '#title' => 'Chado Mapping',
  2796. '#markup' => theme_table($table),
  2797. '#description' => t('This content type maps to the table in Chado
  2798. listed above. Chado allows multiple data types to be housed
  2799. in a single table. Therefore, the column that is used to
  2800. differentiate between data types is also listed above.'),
  2801. '#weight' => 0,
  2802. );
  2803. }
  2804. /**
  2805. * Implements hook_field_views_data_alter();
  2806. */
  2807. function tripal_chado_field_views_data_alter(&$result, $field, $module) {
  2808. // This module creates the data__image field for managing images on
  2809. // bio_data content types. But we want it to render correctly
  2810. // so we need to set some handlers.
  2811. if ($field['field_name'] == 'data__image') {
  2812. foreach ($result as $key => $fields) {
  2813. // It's not clear how to identify our bundle types, but they do have
  2814. // a double underscore in their name to separate the vocabulary from
  2815. // the accession, so we'll use that to find them.
  2816. if (preg_match('/__/', $key)) {
  2817. $result[$key]['data__image']['field']['handler'] = 'tripal_views_handler_field_image';
  2818. }
  2819. }
  2820. }
  2821. }