tripal_chado.fields.inc 83 KB

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