tripal_chado.fields.inc 101 KB

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