tripal_chado.fields.inc 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049
  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. );
  21. $info = array();
  22. // Create the fields for each column in the table.
  23. tripal_chado_bundle_fields_info_base($info, $details, $entity_type, $bundle);
  24. // Create custom fields.
  25. tripal_chado_bundle_fields_info_custom($info, $details, $entity_type, $bundle);
  26. // Create fields for linking tables.
  27. tripal_chado_bundle_fields_info_linker($info, $details, $entity_type, $bundle);
  28. return $info;
  29. }
  30. /**
  31. *
  32. * @param unknown $details
  33. */
  34. function tripal_chado_bundle_fields_info_base(&$info, $details, $entity_type, $bundle) {
  35. $table_name = $details['chado_table'];
  36. $type_table = $details['chado_type_table'];
  37. $type_field = $details['chado_type_column'];
  38. $cvterm_id = $details['chado_cvterm_id'];
  39. // Iterate through the columns of the table and see if fields have been
  40. // created for each one. If not, then create them.
  41. $schema = chado_get_schema($table_name);
  42. if (!$schema) {
  43. return;
  44. }
  45. $pkey = $schema['primary key'][0];
  46. // Get the list of columns for this table and create a new field for each one.
  47. $columns = $schema['fields'];
  48. foreach ($columns as $column_name => $details) {
  49. // Skip the source columns in the analysis table. We have a custom
  50. // field for those columns
  51. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  52. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  53. continue;
  54. }
  55. // Skip the cvterm.is_relationshptype.
  56. if ($table_name == 'cvterm' and $column_name == 'is_relationshiptype') {
  57. continue;
  58. }
  59. // Don't create base fields for the primary key and the type_id field.
  60. if ($column_name == $pkey or $column_name == $type_field) {
  61. continue;
  62. }
  63. $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  64. if (!$cvterm) {
  65. tripal_report_error('tripal', TRIPAL_ERROR,
  66. 'Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  67. array('%table_name' => $table_name, '%column_name' => $column_name));
  68. drupal_set_message(t('Cannot create field for "%table_name.%column_name". Missing an appropriate vocabulary term',
  69. array('%table_name' => $table_name, '%column_name' => $column_name)), 'error');
  70. continue;
  71. }
  72. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/ /', '_', $cvterm->name));
  73. $field_name = substr($field_name, 0, 32);
  74. // Skip the primary key field.
  75. if ($column_name == $schema['primary key'][0]) {
  76. continue;
  77. }
  78. // Skip the type field that will always be custom
  79. if (($table_name == $type_table and $column_name == $type_field) or
  80. $column_name == 'type_id') {
  81. continue;
  82. }
  83. // Set some defaults for the field.
  84. $base_info = array(
  85. 'field_name' => $field_name,
  86. 'type' => '',
  87. 'cardinality' => 1,
  88. 'locked' => FALSE,
  89. 'storage' => array(
  90. 'type' => 'field_chado_storage',
  91. 'sql' => array(),
  92. ),
  93. );
  94. // Alter the field info array depending on the column details.
  95. switch($details['type']) {
  96. case 'char':
  97. $base_info['type'] = 'text';
  98. $base_info['settings']['max_length'] = $details['length'];
  99. break;
  100. case 'varchar':
  101. $base_info['type'] = 'text';
  102. $base_info['settings']['max_length'] = $details['length'];
  103. break;
  104. case 'text':
  105. $base_info['type'] = 'text';
  106. $base_info['settings']['max_length'] = 17179869184;
  107. $base_info['settings']['text_processing'] = 1;
  108. break;
  109. case 'blob':
  110. // not sure how to support a blob field.
  111. continue;
  112. break;
  113. case 'int':
  114. $base_info['type'] = 'number_integer';
  115. break;
  116. case 'float':
  117. $base_info['type'] = 'number_float';
  118. $base_info['settings']['precision'] = 10;
  119. $base_info['settings']['scale'] = 2;
  120. $base_info['settings']['decimal_separator'] = '.';
  121. break;
  122. case 'numeric':
  123. $base_info['type'] = 'number_decimal';
  124. break;
  125. case 'serial':
  126. // Serial fields are most likely not needed as a field.
  127. break;
  128. case 'boolean':
  129. $base_info['type'] = 'list_boolean';
  130. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  131. break;
  132. case 'datetime':
  133. // Use the Drupal Date and Date API to create the field/widget
  134. $base_info['type'] = 'datetime';
  135. break;
  136. }
  137. // Set some default semantic web information
  138. if ($column_name == 'uniquename') {
  139. $base_info['settings']['text_processing'] = 0;
  140. }
  141. //
  142. // PUB TABLE
  143. //
  144. elseif ($table_name == 'pub' and $column_name == 'uniquename') {
  145. $base_info['type'] = 'text';
  146. $base_info['settings']['text_processing'] = 0;
  147. }
  148. $info[$field_name] = $base_info;
  149. }
  150. }
  151. /**
  152. *
  153. * @param unknown $details
  154. */
  155. function tripal_chado_bundle_fields_info_custom(&$info, $details, $entity_type, $bundle) {
  156. $table_name = $details['chado_table'];
  157. $type_table = $details['chado_type_table'];
  158. $type_field = $details['chado_type_column'];
  159. $cvterm_id = $details['chado_cvterm_id'];
  160. $schema = chado_get_schema($table_name);
  161. // BASE TYPE_ID
  162. // Exclude the type_id field on base tables where content types are mapped
  163. // by the type_id field or on the organism table where the type_id is mean
  164. // as an infraspecific name type.
  165. if (array_key_exists('type_id', $schema['fields']) and
  166. $table_name != 'organism' and $type_field != 'type_id') {
  167. $field_name = 'schema__additional_type';
  168. $field_type = 'schema__additional_type';
  169. $info[$field_name] = array(
  170. 'field_name' => $field_name,
  171. 'type' => $field_type,
  172. 'cardinality' => 1,
  173. 'locked' => FALSE,
  174. 'storage' => array(
  175. 'type' => 'field_chado_storage',
  176. ),
  177. );
  178. }
  179. // BASE ORGANISM_ID
  180. if ($table_name != 'organism' and
  181. array_key_exists('organism_id', $schema['fields'])) {
  182. $field_name = 'obi__organism';
  183. $field_type = 'obi__organism';
  184. $info[$field_name] = array(
  185. 'field_name' => $field_name,
  186. 'type' => $field_type,
  187. 'cardinality' => 1,
  188. 'locked' => FALSE,
  189. 'storage' => array(
  190. 'type' => 'field_chado_storage',
  191. ),
  192. );
  193. }
  194. // BASE ORGANISM_ID
  195. if ($table_name == 'cvterm') {
  196. $field_name = 'sio__vocabulary';
  197. $field_type = 'sio__vocabulary';
  198. $info[$field_name] = array(
  199. 'field_name' => $field_name,
  200. 'type' => $field_type,
  201. 'cardinality' => 1,
  202. 'locked' => FALSE,
  203. 'storage' => array(
  204. 'type' => 'field_chado_storage',
  205. ),
  206. );
  207. }
  208. // BASE DBXREF
  209. if (array_key_exists('dbxref_id', $schema['fields'])) {
  210. $field_name = 'data__accession';
  211. $field_type = 'data__accession';
  212. $info[$field_name] = array(
  213. 'field_name' => $field_name,
  214. 'type' => $field_type,
  215. 'cardinality' => 1,
  216. 'locked' => FALSE,
  217. 'storage' => array(
  218. 'type' => 'field_chado_storage',
  219. ),
  220. );
  221. }
  222. // FEATURE MD5CHECKSUM
  223. if ($table_name == 'feature') {
  224. $field_name = 'data__sequence_checksum';
  225. $field_type = 'data__sequence_checksum';
  226. $info[$field_name] = array(
  227. 'field_name' => $field_name,
  228. 'type' => $field_type,
  229. 'cardinality' => 1,
  230. 'locked' => FALSE,
  231. 'storage' => array(
  232. 'type' => 'field_chado_storage',
  233. ),
  234. );
  235. }
  236. // FEATURE RESIDUES
  237. if ($table_name == 'feature') {
  238. $field_name = 'data__sequence';
  239. $field_type = 'data__sequence';
  240. $info[$field_name] = array(
  241. 'field_name' => $field_name,
  242. 'type' => $field_type,
  243. 'cardinality' => 1,
  244. 'locked' => FALSE,
  245. 'storage' => array(
  246. 'type' => 'field_chado_storage',
  247. ),
  248. );
  249. }
  250. // FEATURE SEQLEN
  251. if ($table_name == 'feature') {
  252. $field_name = 'data__sequence_length';
  253. $field_type = 'data__sequence_length';
  254. $info[$field_name] = array(
  255. 'field_name' => $field_name,
  256. 'type' => $field_type,
  257. 'cardinality' => 1,
  258. 'locked' => FALSE,
  259. 'storage' => array(
  260. 'type' => 'field_chado_storage',
  261. ),
  262. );
  263. }
  264. // GENE TRANSCRIPTS
  265. $rel_table = $table_name . '_relationship';
  266. if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  267. $field_name = 'so__transcript';
  268. $field_type = 'so__transcript';
  269. $info[$field_name] = array(
  270. 'field_name' => $field_name,
  271. 'type' => $field_type,
  272. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  273. 'locked' => FALSE,
  274. 'storage' => array(
  275. 'type' => 'field_chado_storage',
  276. ),
  277. );
  278. }
  279. // ORGANISM TYPE_ID
  280. // if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  281. // $field_name = 'taxarank__infraspecific_taxon';
  282. // $field_type = 'taxarank__infraspecific_taxon';
  283. // $info[$field_name] = array(
  284. // 'field_name' => $field_name,
  285. // 'type' => $field_type,
  286. // 'cardinality' => 1,
  287. // 'locked' => FALSE,
  288. // 'storage' => array(
  289. // 'type' => 'field_chado_storage',
  290. // ),
  291. // 'settings' => array(
  292. // ),
  293. // );
  294. // }
  295. // FEATUREMAP UNITTYPE_ID
  296. if ($table_name == 'featuremap') {
  297. $field_name = 'uo__unit';
  298. $field_type = 'uo__unit';
  299. $info[$field_name] = array(
  300. 'field_name' => $field_name,
  301. 'type' => $field_type,
  302. 'cardinality' => 1,
  303. 'locked' => FALSE,
  304. 'storage' => array(
  305. 'type' => 'field_chado_storage',
  306. ),
  307. );
  308. }
  309. // Analysis source
  310. if ($table_name == 'analysis') {
  311. $field_name = 'local__source_data';
  312. $field_type = 'local__source_data';
  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. }
  323. // Add an image field to the Organism type. This is a Drupal field and
  324. // not stored in Chado, but is used for backwards compatibility.
  325. if ($table_name == 'organism') {
  326. $field_name = 'data__image';
  327. $info[$field_name] = array(
  328. 'field_name' => $field_name,
  329. 'type' => 'image',
  330. 'cardinality' => 1,
  331. 'locked' => FALSE,
  332. 'storage' => array(
  333. 'type' => 'field_sql_storage',
  334. ),
  335. );
  336. }
  337. }
  338. /**
  339. *
  340. * @param unknown $details
  341. */
  342. function tripal_chado_bundle_fields_info_linker(&$info, $details, $entity_type, $bundle) {
  343. $table_name = $details['chado_table'];
  344. $type_table = $details['chado_type_table'];
  345. $type_field = $details['chado_type_column'];
  346. $cvterm_id = $details['chado_cvterm_id'];
  347. // CONTACTS
  348. $contact_table = $table_name . '_contact';
  349. if (chado_table_exists($contact_table)) {
  350. $schema = chado_get_schema($contact_table);
  351. $pkey = $schema['primary key'][0];
  352. $field_name = $table_name . '_contact';
  353. $field_type = 'chado_linker__contact';
  354. $info[$field_name] = array(
  355. 'field_name' => $field_name,
  356. 'type' => $field_type,
  357. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  358. 'locked' => FALSE,
  359. 'storage' => array(
  360. 'type' => 'field_chado_storage',
  361. ),
  362. );
  363. }
  364. // DBXREF
  365. $dbxref_table = $table_name . '_dbxref';
  366. if (chado_table_exists($dbxref_table)) {
  367. $field_name = 'sbo__database_cross_reference';
  368. $field_type = 'sbo__database_cross_reference';
  369. $info[$field_name] = array(
  370. 'field_name' => $field_name,
  371. 'type' => $field_type,
  372. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  373. 'locked' => FALSE,
  374. 'storage' => array(
  375. 'type' => 'field_chado_storage',
  376. ),
  377. );
  378. }
  379. // EXPRESSION
  380. // TODO: this should only show up on gene or mRNA bunldes, not every feature.
  381. // $expression_table = $table_name . '_expression';
  382. // if (chado_table_exists($expression_table)) {
  383. // $field_name = 'go__gene_expression';
  384. // $field_type = 'go__gene_expression';
  385. // $info[$field_name] = array(
  386. // 'field_name' => $field_name,
  387. // 'type' => $field_type,
  388. // 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  389. // 'locked' => FALSE,
  390. // 'storage' => array(
  391. // 'type' => 'field_chado_storage',
  392. // ),
  393. // );
  394. // }
  395. // FEATURELOC
  396. if ($table_name == 'feature') {
  397. $field_name = 'data__sequence_coordinates';
  398. $field_type = 'data__sequence_coordinates';
  399. $info[$field_name] = array(
  400. 'field_name' => $field_name,
  401. 'type' => $field_type,
  402. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  403. 'locked' => FALSE,
  404. 'storage' => array(
  405. 'type' => 'field_chado_storage',
  406. ),
  407. );
  408. }
  409. // FEATUREPOS
  410. if ($table_name == 'feature') {
  411. $field_name = 'ogi__location_on_map';
  412. $field_type = 'ogi__location_on_map';
  413. $info[$field_name] = array(
  414. 'field_name' => $field_name,
  415. 'type' => $field_type,
  416. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  417. 'locked' => FALSE,
  418. 'storage' => array(
  419. 'type' => 'field_chado_storage',
  420. ),
  421. );
  422. }
  423. // GENOTYPE
  424. $genotype_table = $table_name . '_genotype';
  425. if (chado_table_exists($genotype_table)) {
  426. $field_name = 'so__genotype';
  427. $field_type = 'so__genotype';
  428. $info[$field_name] = array(
  429. 'field_name' => $field_name,
  430. 'type' => $field_type,
  431. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  432. 'locked' => FALSE,
  433. 'storage' => array(
  434. 'type' => 'field_chado_storage',
  435. ),
  436. );
  437. }
  438. // PHENOTYPE
  439. $phenotype_table = $table_name . '_phenotype';
  440. if (chado_table_exists($phenotype_table)) {
  441. $field_name = 'sbo__phenotype';
  442. $field_type = 'sbo__phenotype';
  443. $info[$field_name] = array(
  444. 'field_name' => $field_name,
  445. 'type' => $field_type,
  446. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  447. 'locked' => FALSE,
  448. 'storage' => array(
  449. 'type' => 'field_chado_storage',
  450. ),
  451. );
  452. }
  453. // PROPERTIES
  454. $prop_table = $table_name . 'prop';
  455. if (chado_table_exists($prop_table)) {
  456. // Get the list of existing property types for this table.
  457. $sql = 'SELECT DISTINCT type_id FROM {' . $prop_table . '}';
  458. $props = chado_query($sql);
  459. while ($prop = $props->fetchObject()) {
  460. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  461. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  462. // tripal_analysis_interpro modules store results in the analysisprop
  463. // table which is probably not the best place, but we don't want to
  464. // create a ton of fields for this.
  465. if ($prop_table == 'analysisprop' and
  466. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  467. $term->dbxref_id->db_id->name == 'tripal')) {
  468. continue;
  469. }
  470. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  471. $field_name = substr($field_name, 0, 32);
  472. $field_type = 'chado_linker__prop';
  473. $info[$field_name] = array(
  474. 'field_name' => $field_name,
  475. 'type' => $field_type,
  476. 'cardinality' => 1,
  477. 'locked' => FALSE,
  478. 'storage' => array(
  479. 'type' => 'field_chado_storage',
  480. ),
  481. );
  482. }
  483. }
  484. // PUBLICATIONS
  485. $pub_table = $table_name . '_pub';
  486. if (chado_table_exists($pub_table)) {
  487. $field_name = 'schema__publication';
  488. $field_type = 'schema__publication';
  489. $info[$field_name] = array(
  490. 'field_name' => $field_name,
  491. 'type' => $field_type,
  492. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  493. 'locked' => FALSE,
  494. 'storage' => array(
  495. 'type' => 'field_chado_storage',
  496. ),
  497. );
  498. }
  499. // PUBLICATIONS (in reverse)
  500. // We want to be able to show all of the content that a publication links
  501. // to. The sio__references field does that.
  502. if ($table_name == 'pub') {
  503. $field_name = 'sio__references';
  504. $field_type = 'sio__references';
  505. $info[$field_name] = array(
  506. 'field_name' => $field_name,
  507. 'type' => $field_type,
  508. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  509. 'locked' => FALSE,
  510. 'storage' => array(
  511. 'type' => 'field_chado_storage',
  512. ),
  513. );
  514. }
  515. // RELATIONSHIPS
  516. // If the linker table does not exists then we don't want to add attach.
  517. $rel_table = $table_name . '_relationship';
  518. if (chado_table_exists($rel_table)) {
  519. $field_name = 'sbo__relationship';
  520. $field_type = 'sbo__relationship';
  521. $info[$field_name] = array(
  522. 'field_name' => $field_name,
  523. 'type' => $field_type,
  524. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  525. 'locked' => FALSE,
  526. 'storage' => array(
  527. 'type' => 'field_chado_storage',
  528. ),
  529. );
  530. }
  531. // SYNONYMS
  532. $syn_table = $table_name . '_synonym';
  533. if (chado_table_exists($syn_table)) {
  534. $field_name = 'schema__alternate_name';
  535. $field_type = 'schema__alternate_name';
  536. $info[$field_name] = array(
  537. 'field_name' => $field_name,
  538. 'type' => $field_type,
  539. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  540. 'locked' => FALSE,
  541. 'storage' => array(
  542. 'type' => 'field_chado_storage',
  543. ),
  544. 'settings' => array(
  545. ),
  546. );
  547. }
  548. }
  549. /**
  550. * Impelments hook_create_tripalfield_instance().
  551. *
  552. * This is a Tripal defined hook that supports integration with the
  553. * TripalEntity field.
  554. */
  555. function tripal_chado_bundle_instances_info($entity_type, $bundle) {
  556. $chado_bundle = db_select('chado_bundle', 'cb')
  557. ->fields('cb')
  558. ->condition('bundle_id', $bundle->id)
  559. ->execute()
  560. ->fetchObject();
  561. $details = array(
  562. 'chado_cvterm_id' => $chado_bundle->type_id,
  563. 'chado_table' => $chado_bundle->data_table,
  564. 'chado_type_table' => $chado_bundle->type_linker_table,
  565. 'chado_type_column' => $chado_bundle->type_column,
  566. );
  567. $info = array();
  568. tripal_chado_bundle_instances_info_base($info, $entity_type, $bundle, $details);
  569. tripal_chado_bundle_instances_info_custom($info, $entity_type, $bundle, $details);
  570. tripal_chado_bundle_instances_info_linker($info, $entity_type, $bundle, $details);
  571. return $info;
  572. }
  573. /**
  574. * Helper function for the hook_create_tripalfield_instance().
  575. *
  576. * Add the field instances that corresond to the columns of the base table.
  577. *
  578. * @param $entity_type
  579. * @param $bundle
  580. * @param $details
  581. */
  582. function tripal_chado_bundle_instances_info_base(&$info, $entity_type, $bundle, $details) {
  583. $fields = array();
  584. // Get Chado information
  585. $table_name = $details['chado_table'];
  586. $type_table = $details['chado_type_table'];
  587. $type_field = $details['chado_type_column'];
  588. $cvterm_id = $details['chado_cvterm_id'];
  589. // Iterate through the columns of the table and see if fields have been
  590. // created for each one. If not, then create them.
  591. $schema = chado_get_schema($table_name);
  592. if (!$schema) {
  593. return;
  594. }
  595. $pkey = $schema['primary key'][0];
  596. $columns = $schema['fields'];
  597. foreach ($columns as $column_name => $details) {
  598. // Skip the source columns in the analysis table. We have a custom
  599. // field for those columns
  600. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  601. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  602. continue;
  603. }
  604. // Don't create base fields for the primary key and the type_id field.
  605. if ($column_name == $pkey or $column_name == $type_field) {
  606. continue;
  607. }
  608. // Skip the type field that will always be custom
  609. if (($table_name == $type_table and $column_name == $type_field) or
  610. $column_name == 'type_id') {
  611. continue;
  612. }
  613. $cvterm = tripal_get_chado_semweb_term($table_name, $column_name, array('return_object' => TRUE));
  614. if (!$cvterm) {
  615. // We already provided an error when creating the base field. So
  616. // don't create another one here.
  617. continue;
  618. }
  619. $field_name = strtolower($cvterm->dbxref_id->db_id->name . '__' . preg_replace('/ /', '_', $cvterm->name));
  620. $field_name = substr($field_name, 0, 32);
  621. // Skip the primary key field.
  622. if ($column_name == $schema['primary key'][0]) {
  623. continue;
  624. }
  625. // Skip the type field.
  626. if ($table_name == $type_table and $column_name == $type_field) {
  627. continue;
  628. }
  629. $base_info = array(
  630. 'field_name' => $field_name,
  631. 'entity_type' => 'TripalEntity',
  632. 'bundle' => $bundle->name,
  633. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  634. 'description' => '',
  635. 'required' => FALSE,
  636. 'settings' => array(
  637. 'auto_attach' => TRUE,
  638. 'term_vocabulary' => $cvterm->dbxref_id->db_id->name,
  639. 'term_name' => $cvterm->name,
  640. 'term_accession' => $cvterm->dbxref_id->accession,
  641. 'chado_table' => $table_name,
  642. 'chado_column' => $column_name,
  643. 'base_table' => $table_name,
  644. ),
  645. 'widget' => array(
  646. 'settings' => array(
  647. 'display_label' => 1,
  648. ),
  649. ),
  650. 'display' => array(
  651. 'default' => array(
  652. 'label' => 'inline',
  653. 'region' =>'Left',
  654. 'settings' => array(),
  655. ),
  656. ),
  657. );
  658. // Determine if the field is required.
  659. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  660. $base_info['required'] = TRUE;
  661. }
  662. // Alter the field info array depending on the column details.
  663. switch($details['type']) {
  664. case 'char':
  665. $base_info['widget']['type'] = 'text_textfield';
  666. break;
  667. case 'varchar':
  668. $base_info['widget']['type'] = 'text_textfield';
  669. break;
  670. case 'text':
  671. $base_info['display']['default']['label'] = 'above';
  672. $base_info['widget']['type'] = 'text_textarea';
  673. $base_info['settings']['text_processing'] = '1';
  674. $base_info['settings']['format'] = 'full_html';
  675. break;
  676. case 'blob':
  677. // not sure how to support a blob field.
  678. continue;
  679. break;
  680. case 'int':
  681. $base_info['widget']['type'] = 'number';
  682. break;
  683. case 'float':
  684. $base_info['widget']['type'] = 'number';
  685. break;
  686. case 'numeric':
  687. $base_info['widget']['type'] = 'number';
  688. break;
  689. case 'serial':
  690. // Serial fields are most likely not needed as a field.
  691. break;
  692. case 'boolean':
  693. $base_info['widget']['type'] = 'options_onoff';
  694. $base_info['required'] = FALSE;
  695. break;
  696. case 'datetime':
  697. $base_info['widget']['type'] = 'date_select';
  698. $base_info['widget']['settings']['increment'] = 1;
  699. $base_info['widget']['settings']['tz_handling'] = 'none';
  700. $base_info['widget']['settings']['collapsible'] = TRUE;
  701. // TODO: Add settings so that the minutes increment by 1.
  702. // And turn off the timezone, as the Chado field doesn't support it.
  703. break;
  704. }
  705. // Set some default semantic web information
  706. if ($column_name == 'uniquename') {
  707. $base_info['label'] = 'Identifier';
  708. $base_info['widget_type'] = 'text_textfield';
  709. }
  710. elseif ($base_info['label'] == 'Timeaccessioned') {
  711. $base_info['label'] = 'Time Accessioned';
  712. $base_info['description'] = 'Please enter the time that this record was first added to the database.';
  713. }
  714. elseif ($base_info['label'] == 'Timelastmodified') {
  715. $base_info['label'] = 'Time Last Modified';
  716. $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  717. }
  718. //
  719. // ORGANISM TABLE
  720. //
  721. elseif ($table_name == 'organism' and $column_name == 'comment') {
  722. $base_info['label'] = 'Description';
  723. }
  724. //
  725. // PUB TABLE
  726. //
  727. elseif ($table_name == 'pub' and $column_name == 'uniquename') {
  728. $base_info['widget_type'] = 'text_textfield';
  729. }
  730. //
  731. // ANALYSIS TABLE
  732. //
  733. elseif ($table_name == 'analysis' and $column_name == 'program') {
  734. $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.';
  735. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name';
  736. }
  737. elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
  738. $base_info['label'] = 'Source Version';
  739. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  740. }
  741. elseif ($table_name == 'analysis' and $column_name == 'programversion') {
  742. $base_info['label'] = 'Program Version';
  743. $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.';
  744. }
  745. if ($table_name == 'analysis' and ($column_name == 'sourceuri' or
  746. $column_name == 'sourceversion' or $column_name == 'sourcename')) {
  747. // Skip the source columns in the analysis table. We have a custom
  748. // field for those columns
  749. continue;
  750. }
  751. //
  752. // PROJECT TABLE
  753. //
  754. elseif ($table_name == 'project' and $column_name == 'description') {
  755. $base_info['label'] = 'Short Description';
  756. }
  757. $info[$field_name] = $base_info;
  758. }
  759. }
  760. /**
  761. * Helper function for the hook_create_tripalfield_instance().
  762. *
  763. * Adds custom fields for base fields. These override the settings provided
  764. * in the tripal_chado_create_tripalfield_instance_base() function.
  765. *
  766. * @param $entity_type
  767. * @param $bundle
  768. * @param $details
  769. */
  770. function tripal_chado_bundle_instances_info_custom(&$info, $entity_type, $bundle, $details) {
  771. $table_name = $details['chado_table'];
  772. $type_table = $details['chado_type_table'];
  773. $type_field = $details['chado_type_column'];
  774. $cvterm_id = $details['chado_cvterm_id'];
  775. $schema = chado_get_schema($table_name);
  776. // BASE TYPE_ID
  777. // Exclude the type_id field on base tables where content types are mapped
  778. // by the type_id field or on the organism table where the type_id is mean
  779. // as an infraspecific name type.
  780. if (array_key_exists('type_id', $schema['fields']) and
  781. $table_name != 'organism' and $type_field != 'type_id') {
  782. $field_name = 'schema__additional_type';
  783. $is_required = FALSE;
  784. if (array_key_exists('not null', $schema['fields']['type_id']) and
  785. $schema['fields']['type_id']['not null']) {
  786. $is_required = TRUE;
  787. }
  788. $info[$field_name] = array(
  789. 'field_name' => $field_name,
  790. 'entity_type' => $entity_type,
  791. 'bundle' => $bundle->name,
  792. 'label' => 'Type',
  793. 'description' => 'Select a type for this record.',
  794. 'required' => $is_required,
  795. 'settings' => array(
  796. 'auto_attach' => TRUE,
  797. 'chado_table' => $table_name,
  798. 'chado_column' => 'type_id',
  799. 'base_table' => $table_name,
  800. ),
  801. 'widget' => array(
  802. 'type' => 'schema__additional_type_widget',
  803. 'settings' => array(
  804. 'display_label' => 1,
  805. ),
  806. ),
  807. 'display' => array(
  808. 'default' => array(
  809. 'label' => 'inline',
  810. 'type' => 'schema__additional_type_formatter',
  811. 'settings' => array(),
  812. ),
  813. ),
  814. );
  815. }
  816. // BASE ORGANISM_ID
  817. if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
  818. $field_name = 'obi__organism';
  819. $is_required = FALSE;
  820. if (array_key_exists('not null', $schema['fields']['organism_id']) and
  821. $schema['fields']['organism_id']['not null']) {
  822. $is_required = TRUE;
  823. }
  824. $info[$field_name] = array(
  825. 'field_name' => $field_name,
  826. 'entity_type' => $entity_type,
  827. 'bundle' => $bundle->name,
  828. 'label' => 'Organism',
  829. 'description' => 'Select an organism.',
  830. 'required' => $is_required,
  831. 'settings' => array(
  832. 'auto_attach' => TRUE,
  833. 'chado_table' => $table_name,
  834. 'chado_column' => 'organism_id',
  835. 'base_table' => $table_name,
  836. ),
  837. 'widget' => array(
  838. 'type' => 'obi__organism_widget',
  839. 'settings' => array(
  840. 'display_label' => 1,
  841. ),
  842. ),
  843. 'display' => array(
  844. 'default' => array(
  845. 'label' => 'inline',
  846. 'type' => 'obi__organism_formatter',
  847. 'settings' => array(),
  848. ),
  849. ),
  850. );
  851. }
  852. // BASE ORGANISM_ID
  853. if ($table_name == 'cvterm') {
  854. $field_name = 'sio__vocabulary';
  855. $is_required = TRUE;
  856. $info[$field_name] = array(
  857. 'field_name' => $field_name,
  858. 'entity_type' => $entity_type,
  859. 'bundle' => $bundle->name,
  860. 'label' => 'Vocabulary',
  861. 'description' => 'Select a vocabulary.',
  862. 'required' => $is_required,
  863. 'settings' => array(
  864. 'auto_attach' => TRUE,
  865. 'chado_table' => $table_name,
  866. 'chado_column' => 'cv_id',
  867. 'base_table' => $table_name,
  868. ),
  869. 'widget' => array(
  870. 'type' => 'sio__vocabulary_widget',
  871. 'settings' => array(
  872. 'display_label' => 1,
  873. ),
  874. ),
  875. 'display' => array(
  876. 'default' => array(
  877. 'label' => 'inline',
  878. 'type' => 'sio__vocabulary_formatter',
  879. 'settings' => array(),
  880. ),
  881. ),
  882. );
  883. }
  884. // BASE DBXREF
  885. if (array_key_exists('dbxref_id', $schema['fields'])) {
  886. $field_name = 'data__accession';
  887. $info[$field_name] = array(
  888. 'field_name' => $field_name,
  889. 'entity_type' => $entity_type,
  890. 'bundle' => $bundle->name,
  891. 'label' => 'Accession',
  892. 'description' => 'This field specifies the unique stable accession (ID) for
  893. this record. It requires that this site have a database entry.',
  894. 'required' => FALSE,
  895. 'settings' => array(
  896. 'auto_attach' => TRUE,
  897. 'chado_table' => $table_name,
  898. 'chado_column' => 'dbxref_id',
  899. 'base_table' => $table_name,
  900. ),
  901. 'widget' => array(
  902. 'type' => 'data__accession_widget',
  903. 'settings' => array(
  904. 'display_label' => 1,
  905. ),
  906. ),
  907. 'display' => array(
  908. 'default' => array(
  909. 'label' => 'inline',
  910. 'type' => 'data__accession_formatter',
  911. 'settings' => array(),
  912. ),
  913. ),
  914. );
  915. }
  916. // FEATURE MD5CHECKSUM
  917. if ($table_name == 'feature') {
  918. $field_name = 'data__sequence_checksum';
  919. $info[$field_name] = array(
  920. 'field_name' => $field_name,
  921. 'entity_type' => $entity_type,
  922. 'bundle' => $bundle->name,
  923. 'label' => 'Sequence Checksum',
  924. 'description' => 'The MD5 checksum for the sequence. The checksum here
  925. will always be unique for the raw unformatted sequence. To verify that the
  926. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  927. to calculate the value. If the value calculated is identical the one shown
  928. here, then the downloaded sequence is uncorrupted.',
  929. 'required' => FALSE,
  930. 'settings' => array(
  931. 'auto_attach' => TRUE,
  932. 'chado_table' => $table_name,
  933. 'chado_column' => 'md5checksum',
  934. 'base_table' => $table_name,
  935. ),
  936. 'widget' => array(
  937. 'type' => 'data__sequence_checksum_widget',
  938. 'settings' => array(
  939. 'display_label' => 1,
  940. 'md5_fieldname' => 'feature__md5checksum',
  941. ),
  942. ),
  943. 'display' => array(
  944. 'default' => array(
  945. 'label' => 'inline',
  946. 'type' => 'data__sequence_checksum_formatter',
  947. 'settings' => array(),
  948. ),
  949. ),
  950. );
  951. }
  952. // FEATURE RESIDUES
  953. if ($table_name == 'feature') {
  954. $field_name = 'data__sequence';
  955. $info[$field_name] = array(
  956. 'field_name' => $field_name,
  957. 'entity_type' => $entity_type,
  958. 'bundle' => $bundle->name,
  959. 'label' => 'Sequence',
  960. 'description' => 'All available sequences for this record.',
  961. 'required' => FALSE,
  962. 'settings' => array(
  963. 'auto_attach' => FALSE,
  964. 'chado_table' => $table_name,
  965. 'chado_column' => 'residues',
  966. 'base_table' => $table_name,
  967. ),
  968. 'widget' => array(
  969. 'type' => 'data__sequence_widget',
  970. 'settings' => array(
  971. 'display_label' => 1,
  972. ),
  973. ),
  974. 'display' => array(
  975. 'default' => array(
  976. 'label' => 'above',
  977. 'type' => 'data__sequence_formatter',
  978. 'settings' => array(),
  979. ),
  980. ),
  981. );
  982. }
  983. // FEATURE SEQLEN
  984. if ($table_name == 'feature') {
  985. $field_name = 'data__sequence_length';
  986. $info[$field_name] = array(
  987. 'field_name' => $field_name,
  988. 'entity_type' => $entity_type,
  989. 'bundle' => $bundle->name,
  990. 'label' => 'Sequence Length',
  991. 'description' => 'The number of residues in the raw sequence. This length
  992. is only for the assigned raw sequence and does not represent the length of any
  993. sequences derived from alignments. If this value is zero but aligned sequences
  994. are present then this record has no official assigned sequence.',
  995. 'required' => FALSE,
  996. 'settings' => array(
  997. 'auto_attach' => TRUE,
  998. 'chado_table' => $table_name,
  999. 'chado_column' => 'seqlen',
  1000. 'base_table' => $table_name,
  1001. ),
  1002. 'widget' => array(
  1003. 'type' => 'data__sequence_length_widget',
  1004. 'settings' => array(
  1005. 'display_label' => 1,
  1006. ),
  1007. ),
  1008. 'display' => array(
  1009. 'default' => array(
  1010. 'label' => 'inline',
  1011. 'type' => 'data__sequence_length_formatter',
  1012. 'settings' => array(),
  1013. ),
  1014. ),
  1015. );
  1016. }
  1017. // GENE TRANSCRIPTS
  1018. $rel_table = $table_name . '_relationship';
  1019. if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  1020. $field_name = 'so__transcript';
  1021. $info[$field_name] = array(
  1022. 'field_name' => $field_name,
  1023. 'entity_type' => $entity_type,
  1024. 'bundle' => $bundle->name,
  1025. 'label' => 'Transcripts',
  1026. 'description' => 'Transcripts that are part of this gene.',
  1027. 'required' => FALSE,
  1028. 'settings' => array(
  1029. 'auto_attach' => FALSE,
  1030. 'chado_table' => $rel_table,
  1031. 'chado_column' => '',
  1032. 'base_table' => $table_name,
  1033. ),
  1034. 'widget' => array(
  1035. 'type' => 'so__transcript_widget',
  1036. 'settings' => array(
  1037. 'display_label' => 1,
  1038. ),
  1039. ),
  1040. 'display' => array(
  1041. 'default' => array(
  1042. 'label' => 'above',
  1043. 'type' => 'so__transcript_formatter',
  1044. 'settings' => array(),
  1045. ),
  1046. ),
  1047. );
  1048. }
  1049. // ORGANISM TYPE_ID
  1050. // if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1051. // $field_name = 'taxarank__infraspecific_taxon';
  1052. // $info[$field_name] = array(
  1053. // 'field_name' => $field_name,
  1054. // 'entity_type' => $entity_type,
  1055. // 'bundle' => $bundle->name,
  1056. // 'label' => 'Infraspecific Taxon',
  1057. // 'description' => 'The Infraspecific Taxon.',
  1058. // 'required' => FALSE,
  1059. // 'settings' => array(
  1060. // 'auto_attach' => TRUE,
  1061. // 'chado_table' => 'organism',
  1062. // 'chado_column' => 'type_id',
  1063. // 'base_table' => 'organism',
  1064. // ),
  1065. // 'widget' => array(
  1066. // 'type' => 'taxarank__infraspecific_taxon_widget',
  1067. // 'settings' => array(
  1068. // 'display_label' => 1,
  1069. // ),
  1070. // ),
  1071. // 'display' => array(
  1072. // 'default' => array(
  1073. // 'label' => 'inline',
  1074. // 'type' => 'taxarank__infraspecific_taxon_formatter',
  1075. // 'settings' => array(),
  1076. // ),
  1077. // ),
  1078. // );
  1079. // }
  1080. // FEATURE SEQLEN
  1081. if ($table_name == 'featuremap') {
  1082. $field_name = 'uo__unit';
  1083. $info[$field_name] = array(
  1084. 'field_name' => $field_name,
  1085. 'entity_type' => $entity_type,
  1086. 'bundle' => $bundle->name,
  1087. 'label' => 'Units',
  1088. 'description' => 'The map\'s unit type.',
  1089. 'required' => TRUE,
  1090. 'settings' => array(
  1091. 'auto_attach' => TRUE,
  1092. 'chado_table' => $table_name,
  1093. 'chado_column' => 'unittype_id',
  1094. 'base_table' => $table_name,
  1095. ),
  1096. 'widget' => array(
  1097. 'type' => 'uo__unit_widget',
  1098. 'settings' => array(
  1099. 'display_label' => 1,
  1100. ),
  1101. ),
  1102. 'display' => array(
  1103. 'default' => array(
  1104. 'label' => 'inline',
  1105. 'type' => 'uo__unit_formatter',
  1106. 'settings' => array(),
  1107. ),
  1108. ),
  1109. );
  1110. }
  1111. // the analysis source.
  1112. if ($table_name == 'analysis') {
  1113. $field_name = 'local__source_data';
  1114. $info[$field_name] = array(
  1115. 'field_name' => $field_name,
  1116. 'entity_type' => $entity_type,
  1117. 'bundle' => $bundle->name,
  1118. 'label' => 'Data Source',
  1119. 'description' => 'The source where data was obtained for this analysis.',
  1120. 'required' => FALSE,
  1121. 'settings' => array(
  1122. 'auto_attach' => TRUE,
  1123. 'chado_table' => $table_name,
  1124. 'chado_column' => 'analysis_id',
  1125. 'base_table' => $table_name,
  1126. ),
  1127. 'widget' => array(
  1128. 'type' => 'local__source_data_widget',
  1129. 'settings' => array(
  1130. 'display_label' => 1,
  1131. ),
  1132. ),
  1133. 'display' => array(
  1134. 'default' => array(
  1135. 'label' => 'inline',
  1136. 'type' => 'local__source_data_formatter',
  1137. 'settings' => array(),
  1138. ),
  1139. ),
  1140. );
  1141. }
  1142. // Add an image field to the Organism type. This is a Drupal field and
  1143. // not stored in Chado, but is used for backwards compatibility.
  1144. if ($table_name == 'organism') {
  1145. $field_name = 'data__image';
  1146. $info[$field_name] = array(
  1147. 'field_name' => $field_name,
  1148. 'entity_type' => $entity_type,
  1149. 'bundle' => $bundle->name,
  1150. 'label' => 'Organism Image',
  1151. 'description' => 'An image for the organism',
  1152. 'required' => FALSE,
  1153. 'settings' => array(
  1154. 'term_vocabulary' => 'data',
  1155. 'term_name' => 'Image',
  1156. 'term_accession' => '2968',
  1157. ),
  1158. 'display' => array(
  1159. 'default' => array(
  1160. 'label' => 'hidden',
  1161. ),
  1162. ),
  1163. );
  1164. }
  1165. }
  1166. /**
  1167. *
  1168. * @param unknown $entity_type
  1169. * @param unknown $bundle
  1170. * @param unknown $details
  1171. */
  1172. function tripal_chado_bundle_instances_info_linker(&$info, $entity_type, $bundle, $details) {
  1173. $table_name = $details['chado_table'];
  1174. $type_table = $details['chado_type_table'];
  1175. $type_field = $details['chado_type_column'];
  1176. $cvterm_id = $details['chado_cvterm_id'];
  1177. // CONTACTS
  1178. $contact_table = $table_name . '_contact';
  1179. if (chado_table_exists($contact_table)) {
  1180. $field_name = $table_name . '_contact';
  1181. $info[$field_name] = $info[$field_name] = array(
  1182. 'field_name' => $field_name,
  1183. 'entity_type' => $entity_type,
  1184. 'bundle' => $bundle->name,
  1185. 'label' => 'Contact',
  1186. 'description' => 'Associates an indviddual or organization with this record',
  1187. 'required' => FALSE,
  1188. 'settings' => array(
  1189. 'auto_attach' => FALSE,
  1190. 'chado_table' => $contact_table,
  1191. 'base_table' => $table_name,
  1192. 'chado_column' => 'contact_id',
  1193. ),
  1194. 'widget' => array(
  1195. 'type' => 'local__contact_widget',
  1196. 'settings' => array(
  1197. 'display_label' => 1,
  1198. ),
  1199. ),
  1200. 'display' => array(
  1201. 'default' => array(
  1202. 'label' => 'above',
  1203. 'type' => 'local__contact_formatter',
  1204. 'settings' => array(),
  1205. ),
  1206. ),
  1207. );
  1208. }
  1209. // DBXREF
  1210. $dbxref_table = $table_name . '_dbxref';
  1211. if (chado_table_exists($dbxref_table)) {
  1212. $field_name = 'sbo__database_cross_reference';
  1213. $schema = chado_get_schema($dbxref_table);
  1214. $pkey = $schema['primary key'][0];
  1215. $info[$field_name] = array(
  1216. 'field_name' => $field_name,
  1217. 'entity_type' => $entity_type,
  1218. 'bundle' => $bundle->name,
  1219. 'label' => 'Cross Reference',
  1220. 'description' => 'The IDs where this record may be available in other external online databases.',
  1221. 'required' => FALSE,
  1222. 'settings' => array(
  1223. 'auto_attach' => FALSE,
  1224. 'chado_table' => $dbxref_table,
  1225. 'chado_column' => $pkey,
  1226. 'base_table' => $table_name,
  1227. ),
  1228. 'widget' => array(
  1229. 'type' => 'sbo__database_cross_reference_widget',
  1230. 'settings' => array(
  1231. 'display_label' => 1,
  1232. ),
  1233. ),
  1234. 'display' => array(
  1235. 'default' => array(
  1236. 'label' => 'inline',
  1237. 'type' => 'sbo__database_cross_reference_formatter',
  1238. 'settings' => array(),
  1239. ),
  1240. ),
  1241. );
  1242. }
  1243. // EXPRESSION
  1244. // TODO: this should only show up on gene or mRNA and the GO must be
  1245. // laoded or this field will crash things.
  1246. // $expression_table = $table_name . '_expression';
  1247. // if (chado_table_exists($expression_table)) {
  1248. // $field_name = 'go__gene_expression';
  1249. // $schema = chado_get_schema($expression_table);
  1250. // $pkey = $schema['primary key'][0];
  1251. // $info[$field_name] = array(
  1252. // 'field_name' => $field_name,
  1253. // 'entity_type' => $entity_type,
  1254. // 'bundle' => $bundle->name,
  1255. // 'label' => 'Gene expression',
  1256. // 'description' => 'Information about the expression of this record.',
  1257. // 'required' => FALSE,
  1258. // 'settings' => array(
  1259. // 'auto_attach' => FALSE,
  1260. // 'chado_table' => $expression_table,
  1261. // 'chado_column' => $pkey,
  1262. // 'base_table' => $table_name,
  1263. // ),
  1264. // 'widget' => array(
  1265. // 'type' => 'go__gene_expression_widget',
  1266. // 'settings' => array(
  1267. // 'display_label' => 1,
  1268. // ),
  1269. // ),
  1270. // 'display' => array(
  1271. // 'default' => array(
  1272. // 'label' => 'above',
  1273. // 'type' => 'go__gene_expression_formatter',
  1274. // 'settings' => array(),
  1275. // ),
  1276. // ),
  1277. // );
  1278. // }
  1279. // FEATURELOC
  1280. if ($table_name == 'feature') {
  1281. $field_name = 'data__sequence_coordinates';
  1282. $schema = chado_get_schema('featureloc');
  1283. $pkey = $schema['primary key'][0];
  1284. $info[$field_name] = array(
  1285. 'field_name' => $field_name,
  1286. 'entity_type' => $entity_type,
  1287. 'bundle' => $bundle->name,
  1288. 'label' => 'Sequence Coordinates',
  1289. 'description' => 'The locations on other genomic sequences where this
  1290. record has been aligned.',
  1291. 'required' => FALSE,
  1292. 'settings' => array(
  1293. 'auto_attach' => FALSE,
  1294. 'chado_table' => 'featureloc',
  1295. 'chado_column' => $pkey,
  1296. 'base_table' => 'feature',
  1297. ),
  1298. 'widget' => array(
  1299. 'type' => 'data__sequence_coordinates_widget',
  1300. 'settings' => array(
  1301. 'display_label' => 1,
  1302. ),
  1303. ),
  1304. 'display' => array(
  1305. 'default' => array(
  1306. 'label' => 'above',
  1307. 'type' => 'data__sequence_coordinates_formatter',
  1308. 'settings' => array(),
  1309. ),
  1310. ),
  1311. );
  1312. }
  1313. // FEATUREPOS
  1314. if ($table_name == 'feature') {
  1315. $field_name = 'ogi__location_on_map';
  1316. $schema = chado_get_schema('featurepos');
  1317. $pkey = $schema['primary key'][0];
  1318. $info[$field_name] = array(
  1319. 'field_name' => $field_name,
  1320. 'entity_type' => $entity_type,
  1321. 'bundle' => $bundle->name,
  1322. 'label' => 'Location on Map',
  1323. 'description' => 'The positions on a genetic map.',
  1324. 'required' => FALSE,
  1325. 'settings' => array(
  1326. 'auto_attach' => FALSE,
  1327. 'chado_table' => 'featurepos',
  1328. 'chado_column' => $pkey,
  1329. 'base_table' => 'feature',
  1330. ),
  1331. 'widget' => array(
  1332. 'type' => 'ogi__location_on_map_widget',
  1333. 'settings' => array(
  1334. 'display_label' => 1,
  1335. ),
  1336. ),
  1337. 'display' => array(
  1338. 'default' => array(
  1339. 'label' => 'above',
  1340. 'type' => 'ogi__location_on_map_formatter',
  1341. 'settings' => array(),
  1342. ),
  1343. ),
  1344. );
  1345. }
  1346. // GENOTYPE
  1347. $genotype_table = $table_name . '_genotype';
  1348. if (chado_table_exists($genotype_table)) {
  1349. $field_name = 'so__genotype';
  1350. $schema = chado_get_schema($genotype_table);
  1351. $pkey = $schema['primary key'][0];
  1352. $info[$field_name] = array(
  1353. 'field_name' => $field_name,
  1354. 'entity_type' => $entity_type,
  1355. 'bundle' => $bundle->name,
  1356. 'label' => 'Genotype',
  1357. 'description' => 'The genotypes associated with this record.',
  1358. 'required' => FALSE,
  1359. 'settings' => array(
  1360. 'auto_attach' => FALSE,
  1361. 'chado_table' => $genotype_table,
  1362. 'chado_column' => $pkey,
  1363. 'base_table' => $table_name,
  1364. ),
  1365. 'widget' => array(
  1366. 'type' => 'so__genotype_widget',
  1367. 'settings' => array(
  1368. 'display_label' => 1,
  1369. ),
  1370. ),
  1371. 'display' => array(
  1372. 'default' => array(
  1373. 'label' => 'above',
  1374. 'type' => 'so__genotype_formatter',
  1375. 'settings' => array(),
  1376. ),
  1377. ),
  1378. );
  1379. }
  1380. // PHENOTYPE
  1381. $phenotype_table = $table_name . '_phenotype';
  1382. if (chado_table_exists($phenotype_table)) {
  1383. $field_name = 'sbo__phenotype';
  1384. $schema = chado_get_schema($phenotype_table);
  1385. $pkey = $schema['primary key'][0];
  1386. $info[$field_name] = array(
  1387. 'field_name' => $field_name,
  1388. 'entity_type' => $entity_type,
  1389. 'bundle' => $bundle->name,
  1390. 'label' => 'Phenotype',
  1391. 'description' => 'The phenotypes associated with this record.',
  1392. 'required' => FALSE,
  1393. 'settings' => array(
  1394. 'auto_attach' => FALSE,
  1395. 'chado_table' => $phenotype_table,
  1396. 'chado_column' => $pkey,
  1397. 'base_table' => $table_name,
  1398. ),
  1399. 'widget' => array(
  1400. 'type' => 'sbo__phenotype_widget',
  1401. 'settings' => array(
  1402. 'display_label' => 1,
  1403. ),
  1404. ),
  1405. 'display' => array(
  1406. 'default' => array(
  1407. 'label' => 'above',
  1408. 'type' => 'sbo__phenotype_formatter',
  1409. 'settings' => array(),
  1410. ),
  1411. ),
  1412. );
  1413. }
  1414. // PROPERTIES
  1415. $prop_table = $table_name . 'prop';
  1416. if (chado_table_exists($prop_table)) {
  1417. $tschema = chado_get_schema($table_name);
  1418. $schema = chado_get_schema($prop_table);
  1419. $tpkey = $tschema['primary key'][0];
  1420. $pkey = $schema['primary key'][0];
  1421. // Get the list of existing property types for this table.
  1422. $args = array();
  1423. $sql = "
  1424. SELECT DISTINCT P.type_id
  1425. FROM {" . $prop_table . "} P
  1426. ";
  1427. if (array_key_exists('type_id', $tschema['fields'])) {
  1428. $sql .= "
  1429. INNER JOIN {" . $table_name . "} T on T.$tpkey = P.$tpkey
  1430. WHERE T.type_id = :cvterm_id
  1431. ";
  1432. $args[':cvterm_id'] = $cvterm_id;
  1433. }
  1434. $props = chado_query($sql, $args);
  1435. while ($prop = $props->fetchObject()) {
  1436. $term = chado_generate_var('cvterm', array('cvterm_id' => $prop->type_id));
  1437. // The tripal_analysis_KEGG, tripal_analysis_blast, and
  1438. // tripal_analysis_interpro modules store results in the analysisprop
  1439. // table which is probably not the best place, but we don't want to
  1440. // create a ton of fields for this.
  1441. if ($prop_table == 'analysisprop' and
  1442. ($term->dbxref_id->db_id->name == 'KEGG_BRITE' or
  1443. $term->dbxref_id->db_id->name == 'tripal')) {
  1444. continue;
  1445. }
  1446. $field_name = strtolower(preg_replace('/[^\w]/','_', $term->dbxref_id->db_id->name . '__' . $term->name));
  1447. $field_name = substr($field_name, 0, 32);
  1448. $info[$field_name] = array(
  1449. 'field_name' => $field_name,
  1450. 'entity_type' => $entity_type,
  1451. 'bundle' => $bundle->name,
  1452. 'label' => ucwords(preg_replace('/_/', ' ', $term->name)),
  1453. 'description' => $term->definition,
  1454. 'required' => FALSE,
  1455. 'settings' => array(
  1456. 'auto_attach' => TRUE,
  1457. 'term_vocabulary' => $term->dbxref_id->db_id->name,
  1458. 'term_accession' => $term->dbxref_id->accession,
  1459. 'term_name' => $term->name,
  1460. 'base_table' => $table_name,
  1461. 'chado_table' => $prop_table,
  1462. 'chado_column' => $pkey,
  1463. ),
  1464. 'widget' => array(
  1465. 'type' => 'chado_linker__prop_widget',
  1466. 'settings' => array(
  1467. 'display_label' => 1,
  1468. ),
  1469. ),
  1470. 'display' => array(
  1471. 'default' => array(
  1472. 'label' => 'inline',
  1473. 'type' => 'chado_linker__prop_formatter',
  1474. 'settings' => array(),
  1475. ),
  1476. ),
  1477. );
  1478. }
  1479. }
  1480. // PUBLICATIONS
  1481. $pub_table = $table_name . '_pub';
  1482. if (chado_table_exists($pub_table)) {
  1483. $field_name = 'schema__publication';
  1484. $schema = chado_get_schema($pub_table);
  1485. $pkey = $schema['primary key'][0];
  1486. $info[$field_name] = array(
  1487. 'field_name' => $field_name,
  1488. 'entity_type' => $entity_type,
  1489. 'bundle' => $bundle->name,
  1490. 'label' => 'Publication',
  1491. 'description' => 'This record has been referenced or is sourced from these publications.',
  1492. 'required' => FALSE,
  1493. 'settings' => array(
  1494. 'auto_attach' => FALSE,
  1495. 'chado_table' => $pub_table,
  1496. 'chado_column' => $pkey,
  1497. 'base_table' => $table_name,
  1498. ),
  1499. 'widget' => array(
  1500. 'type' => 'schema__publication_widget',
  1501. 'settings' => array(
  1502. 'display_label' => 1,
  1503. ),
  1504. ),
  1505. 'display' => array(
  1506. 'default' => array(
  1507. 'label' => 'above',
  1508. 'type' => 'schema__publication_formatter',
  1509. 'settings' => array(),
  1510. ),
  1511. ),
  1512. );
  1513. }
  1514. // PUBLICATIONS (in reverse)
  1515. // We want to be able to show all of the content that a publication links
  1516. // to. The sio__references field does that.
  1517. if ($table_name == 'pub') {
  1518. $field_name = 'sio__references';
  1519. $schema = chado_get_schema($table_name);
  1520. $pkey = $schema['primary key'][0];
  1521. $info[$field_name] = array(
  1522. 'field_name' => $field_name,
  1523. 'entity_type' => $entity_type,
  1524. 'bundle' => $bundle->name,
  1525. 'label' => 'References',
  1526. 'description' => 'Records that are referred to by the publication.',
  1527. 'required' => FALSE,
  1528. 'settings' => array(
  1529. 'auto_attach' => FALSE,
  1530. 'chado_table' => $table_name,
  1531. 'chado_column' => $pkey,
  1532. 'base_table' => $table_name,
  1533. ),
  1534. 'widget' => array(
  1535. 'type' => 'sio__references_widget',
  1536. 'settings' => array(
  1537. 'display_label' => 1,
  1538. ),
  1539. ),
  1540. 'display' => array(
  1541. 'default' => array(
  1542. 'label' => 'above',
  1543. 'type' => 'sio__references_formatter',
  1544. 'settings' => array(),
  1545. ),
  1546. ),
  1547. );
  1548. }
  1549. // RELATIONSHIPS
  1550. // If the linker table does not exists then we don't want to add attach.
  1551. $rel_table = $table_name . '_relationship';
  1552. if (chado_table_exists($rel_table)) {
  1553. $field_name = 'sbo__relationship';
  1554. $schema = chado_get_schema($rel_table);
  1555. $pkey = $schema['primary key'][0];
  1556. $info[$field_name] = array(
  1557. 'field_name' => $field_name,
  1558. 'entity_type' => $entity_type,
  1559. 'bundle' => $bundle->name,
  1560. 'label' => 'Relationship',
  1561. 'description' => 'Other records with relationships to this record.',
  1562. 'required' => FALSE,
  1563. 'settings' => array(
  1564. 'auto_attach' => FALSE,
  1565. 'chado_table' => $rel_table,
  1566. 'chado_column' => $pkey,
  1567. 'base_table' => $table_name,
  1568. ),
  1569. 'widget' => array(
  1570. 'type' => 'sbo__relationship_widget',
  1571. 'settings' => array(
  1572. 'display_label' => 1,
  1573. ),
  1574. ),
  1575. 'display' => array(
  1576. 'default' => array(
  1577. 'label' => 'above',
  1578. 'type' => 'sbo__relationship_formatter',
  1579. 'settings' => array(),
  1580. ),
  1581. ),
  1582. );
  1583. }
  1584. // SYNONYMS
  1585. $syn_table = $table_name . '_synonym';
  1586. if (chado_table_exists($syn_table)) {
  1587. $field_name = 'schema__alternate_name';
  1588. $schema = chado_get_schema($syn_table);
  1589. $pkey = $schema['primary key'][0];
  1590. $info[$field_name] = array(
  1591. 'field_name' => $field_name,
  1592. 'entity_type' => $entity_type,
  1593. 'bundle' => $bundle->name,
  1594. 'label' => 'Synonyms',
  1595. 'description' => 'Alternate names, aliases or synonyms for this record.',
  1596. 'required' => FALSE,
  1597. 'settings' => array(
  1598. 'auto_attach' => FALSE,
  1599. 'chado_table' => $syn_table,
  1600. 'chado_column' => $pkey,
  1601. 'base_table' => $table_name,
  1602. ),
  1603. 'widget' => array(
  1604. 'type' => 'schema__alternate_name_widget',
  1605. 'settings' => array(
  1606. 'display_label' => 1,
  1607. ),
  1608. ),
  1609. 'display' => array(
  1610. 'default' => array(
  1611. 'label' => 'inline',
  1612. 'type' => 'schema__alternate_name_formatter',
  1613. 'settings' => array(),
  1614. ),
  1615. ),
  1616. );
  1617. }
  1618. }
  1619. /**
  1620. * Implements hook_bundle_create_user_field().
  1621. *
  1622. * A priviledged user has the ability to add new fields to the bundle. The
  1623. * chado_linker__prop and chado_linker__cvterm fields are allowed to be
  1624. * added dynamically by the user. But, Drupal doesn't know how to deal with
  1625. * it, so this function is called for any field attached to a TripalEntity
  1626. * bundle type. Any fields whose TripalField::$module argument is set to
  1627. * 'tripal_chado' and that can be added dynamically will result in a call
  1628. * to this function.
  1629. */
  1630. function tripal_chado_bundle_create_user_field($new_field, $bundle) {
  1631. // Get the table this bundle is mapped to.
  1632. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  1633. $vocab = $term->vocab;
  1634. $params = array(
  1635. 'vocabulary' => $vocab->vocabulary,
  1636. 'accession' => $term->accession,
  1637. );
  1638. $chado_table = $bundle->data_table;
  1639. $chado_type_table = $bundle->type_linker_table;
  1640. $chado_type_column = $bundle->type_column;
  1641. $chado_type_id = $bundle->type_id;
  1642. $chado_type_value = $bundle->type_value;
  1643. // We allow site admins to add new chado_linker__prop fields to an entity.
  1644. // This function will allow us to properly add them. But at this point we
  1645. // don't know the controlled vocabulary term. We'll have to use the
  1646. // defaults and let the user set it using the interface.
  1647. if ($new_field['type'] == 'chado_linker__prop') {
  1648. $table_name = $chado_table . 'prop';
  1649. if (chado_table_exists($table_name)) {
  1650. $schema = chado_get_schema($table_name);
  1651. $pkey = $schema['primary key'][0];
  1652. $field_name = $new_field['field_name'];
  1653. $field_type = 'chado_linker__prop';
  1654. // First add the field.
  1655. field_create_field(array(
  1656. 'field_name' => $field_name,
  1657. 'type' => $field_type,
  1658. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1659. 'locked' => FALSE,
  1660. 'storage' => array(
  1661. 'type' => 'field_chado_storage',
  1662. ),
  1663. ));
  1664. // Now add the instance
  1665. field_create_instance(array(
  1666. 'field_name' => $field_name,
  1667. 'entity_type' => 'TripalEntity',
  1668. 'bundle' => $bundle->name,
  1669. 'label' => $new_field['label'],
  1670. 'description' => '',
  1671. 'required' => FALSE,
  1672. 'settings' => array(
  1673. 'auto_attach' => TRUE,
  1674. 'base_table' => $chado_table,
  1675. 'chado_table' => $table_name,
  1676. 'chado_column' => $pkey,
  1677. 'term_vocabulary' => '',
  1678. 'term_accession' => '',
  1679. 'term_name' => ''
  1680. ),
  1681. 'widget' => array(
  1682. 'type' => 'chado_linker__prop_widget',
  1683. 'settings' => array(
  1684. 'display_label' => 1,
  1685. ),
  1686. ),
  1687. 'display' => array(
  1688. 'default' => array(
  1689. 'label' => 'inline',
  1690. 'type' => 'chado_linker__prop_formatter',
  1691. 'settings' => array(),
  1692. ),
  1693. ),
  1694. ));
  1695. }
  1696. else {
  1697. drupal_set_message('Cannot add a property field to this entity. Chado does not support properties for this data type.', 'error');
  1698. }
  1699. }
  1700. // We allow site admins to add new chado_linker__cvterm fields to an entity.
  1701. // This function will allow us to properly add them. But at this point we
  1702. // don't know the controlled vocabulary term. We'll have to use the
  1703. // defaults and let the user set it using the interface.
  1704. if ($new_field['type'] == 'chado_linker__cvterm') {
  1705. $table_name = $chado_table . '_cvterm';
  1706. if (chado_table_exists($table_name)) {
  1707. $schema = chado_get_schema($table_name);
  1708. $pkey = $schema['primary key'][0];
  1709. $field_name = $new_field['field_name'];
  1710. $field_type = 'chado_linker__cvterm';
  1711. // First add the field.
  1712. field_create_field(array(
  1713. 'field_name' => $field_name,
  1714. 'type' => $field_type,
  1715. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  1716. 'locked' => FALSE,
  1717. 'storage' => array(
  1718. 'type' => 'field_chado_storage',
  1719. ),
  1720. 'settings' => array(
  1721. 'base_table' => $chado_table,
  1722. 'chado_table' => $table_name,
  1723. 'chado_column' => $pkey,
  1724. ),
  1725. ));
  1726. // Now add the instance
  1727. field_create_instance(array(
  1728. 'field_name' => $field_name,
  1729. 'entity_type' => 'TripalEntity',
  1730. 'bundle' => $bundle->name,
  1731. 'label' => $new_field['label'],
  1732. 'description' => '',
  1733. 'required' => FALSE,
  1734. 'settings' => array(
  1735. 'auto_attach' => TRUE,
  1736. ),
  1737. 'widget' => array(
  1738. 'type' => 'chado_linker__cvterm_widget',
  1739. 'settings' => array(
  1740. 'display_label' => 1,
  1741. ),
  1742. ),
  1743. 'display' => array(
  1744. 'default' => array(
  1745. 'label' => 'above',
  1746. 'type' => 'chado_linker__cvterm_formatter',
  1747. 'settings' => array(),
  1748. ),
  1749. ),
  1750. ));
  1751. }
  1752. else {
  1753. drupal_set_message('Cannot add a property field to this entity. Chado does not support annotations for this data type.', 'error');
  1754. }
  1755. }
  1756. }
  1757. /**
  1758. * Allows for altering of a field's instance setting form.
  1759. *
  1760. * This appears to be a Drupal hook but is actually a custom function created
  1761. * by this module. It is called by the tripal_form_alter() function of this
  1762. * module.
  1763. *
  1764. * Here we put additional form elements for any field, regardless if it is
  1765. * a tripalField or not.
  1766. *
  1767. * @param $form
  1768. * The form array. Alterations to the form can be made within this array.
  1769. * @param $form_state
  1770. * The form state array.
  1771. */
  1772. function tripal_chado_field_instance_settings_form_alter(&$form, $form_state) {
  1773. global $language;
  1774. $field = $form['#field'];
  1775. $instance = $form['#instance'];
  1776. $base_table = array_key_exists('base_table', $instance['settings']) ? $instance['settings']['base_table'] : '';
  1777. $chado_table = array_key_exists('chado_table', $instance['settings']) ? $instance['settings']['chado_table'] : '';
  1778. $chado_column = array_key_exists('chado_column', $instance['settings']) ? $instance['settings']['chado_column'] : '';
  1779. if ($chado_table) {
  1780. // Construct a table for the vocabulary information.
  1781. $headers = array();
  1782. $rows = array();
  1783. $rows[] = array(
  1784. array(
  1785. 'data' => 'Base Table',
  1786. 'header' => TRUE,
  1787. 'width' => '20%',
  1788. ),
  1789. $base_table
  1790. );
  1791. $rows[] = array(
  1792. array(
  1793. 'data' => 'Record Table',
  1794. 'header' => TRUE,
  1795. 'width' => '20%',
  1796. ),
  1797. $chado_table
  1798. );
  1799. $rows[] = array(
  1800. array(
  1801. 'data' => 'ID Column',
  1802. 'header' => TRUE,
  1803. 'width' => '20%',
  1804. ),
  1805. $chado_column
  1806. );
  1807. $table = array(
  1808. 'header' => $headers,
  1809. 'rows' => $rows,
  1810. 'attributes' => array(
  1811. ),
  1812. 'sticky' => FALSE,
  1813. 'caption' => '',
  1814. 'colgroups' => array(),
  1815. 'empty' => '',
  1816. );
  1817. $form['chado_mapping'] = array(
  1818. '#type' => 'fieldset',
  1819. '#title' => 'Chado Mapping',
  1820. '#description' => t('This field maps to data in Chado to the following table:'),
  1821. );
  1822. $form['chado_mapping']['details'] = array(
  1823. '#type' => 'item',
  1824. '#markup' => theme_table($table),
  1825. );
  1826. }
  1827. }
  1828. /**
  1829. * Implements hook_form_FROM_ID_alter()
  1830. */
  1831. function tripal_chado_form_tripalbundle_form_alter(&$form, $form_state) {
  1832. global $language;
  1833. $bundle = $form['#bundle'];
  1834. $term = entity_load('TripalTerm', array('id' => $bundle->term_id));
  1835. $term = reset($term);
  1836. $vocab = $term->vocab;
  1837. $params = array(
  1838. 'vocabulary' => $vocab->vocabulary,
  1839. 'accession' => $term->accession,
  1840. );
  1841. $chado_table = $bundle->data_table;
  1842. $chado_column = $bundle->type_column;
  1843. $chado_type_table = $bundle->type_linker_table;
  1844. $chado_type_id = $bundle->type_id;
  1845. $chado_type_value = $bundle->type_value;
  1846. // Construct a table for the vocabulary information.
  1847. $headers = array();
  1848. $rows = array();
  1849. $rows[] = array(
  1850. array(
  1851. 'data' => 'Chado Table',
  1852. 'header' => TRUE,
  1853. 'width' => '20%',
  1854. ),
  1855. $chado_table
  1856. );
  1857. if ($chado_column) {
  1858. $rows[] = array(
  1859. array(
  1860. 'data' => 'Type Column',
  1861. 'header' => TRUE,
  1862. 'width' => '20%',
  1863. ),
  1864. $chado_column
  1865. );
  1866. }
  1867. if ($chado_type_table) {
  1868. $rows[] = array(
  1869. array(
  1870. 'data' => 'Association Table',
  1871. 'header' => TRUE,
  1872. 'width' => '20%',
  1873. ),
  1874. $chado_type_table
  1875. );
  1876. }
  1877. if ($chado_type_table and $chado_type_id) {
  1878. $rows[] = array(
  1879. array(
  1880. 'data' => 'CVTerm Table ID',
  1881. 'header' => TRUE,
  1882. 'width' => '20%',
  1883. ),
  1884. $chado_type_id
  1885. );
  1886. }
  1887. if ($chado_type_value) {
  1888. $rows[] = array(
  1889. array(
  1890. 'data' => 'Property Value',
  1891. 'header' => TRUE,
  1892. 'width' => '20%',
  1893. ),
  1894. $chado_type_value
  1895. );
  1896. }
  1897. $table = array(
  1898. 'header' => $headers,
  1899. 'rows' => $rows,
  1900. 'attributes' => array(
  1901. ),
  1902. 'sticky' => FALSE,
  1903. 'caption' => '',
  1904. 'colgroups' => array(),
  1905. 'empty' => '',
  1906. );
  1907. $form['chado_mapping'] = array(
  1908. '#type' => 'item',
  1909. '#title' => 'Chado Mapping',
  1910. '#markup' => theme_table($table),
  1911. '#description' => t('This content type maps to the table in Chado
  1912. listed above. Chado allows multiple data types to be housed
  1913. in a single table. Therefore, the column that is used to
  1914. differentiate between data types is also listed above.'),
  1915. '#weight' => 0,
  1916. );
  1917. }