tripal_chado.fields.inc 99 KB

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