tripal_chado.fields.inc 59 KB

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