tripal_chado.fields.inc 95 KB

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