tripal_chado.fields.inc 94 KB

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