tripal_chado.fields.inc 91 KB

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