tripal_chado.fields.inc 101 KB

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