tripal_chado.fields.inc 83 KB

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