tripal_chado.fields.inc 105 KB

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