tripal_chado.fields.inc 59 KB

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