tripal_chado.fields.inc 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  1. <?php
  2. /**
  3. * Implements hook_chado_bundle_create().
  4. *
  5. * This is a Tripal hook. It allows any module to perform tasks after
  6. * a bundle has been created.
  7. *
  8. * @param $bundle
  9. * The TripalBundle object.
  10. */
  11. function tripal_chado_bundle_create($bundle) {
  12. $entity_type = $bundle->type;
  13. // Create/Add the new fields for this bundle.
  14. tripal_chado_bundle_create_fields($entity_type, $bundle);
  15. // Create/Add the new field instances for this bundle.
  16. tripal_chado_bundle_create_instances($entity_type, $bundle);
  17. }
  18. /**
  19. * Implements hook_field_create_info().
  20. *
  21. * This is a Tripal defined hook that supports integration with the
  22. * TripalEntity field.
  23. */
  24. function tripal_chado_bundle_create_fields($entity_type, $bundle) {
  25. // Get the table this bundle is mapped to.
  26. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  27. $vocab = $term->vocab;
  28. $params = array(
  29. 'vocabulary' => $vocab->vocabulary,
  30. 'accession' => $term->accession,
  31. );
  32. $mapped_table = chado_get_cvterm_mapping($params);
  33. // Get the details about the mapping of this bundle to the Chado table:
  34. $details = array(
  35. 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
  36. 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
  37. 'chado_table' => $mapped_table->chado_table,
  38. 'chado_type_table' => $mapped_table->chado_table,
  39. 'chado_type_column' => $mapped_table->chado_field,
  40. );
  41. $info = array();
  42. // Create the fields for each column in the table.
  43. tripal_chado_bundle_create_fields_base($info, $details, $entity_type, $bundle);
  44. // Create custom fields.
  45. tripal_chado_bundle_create_fields_custom($info, $details, $entity_type, $bundle);
  46. // Create fields for linking tables.
  47. tripal_chado_bundle_create_fields_linker($info, $details, $entity_type, $bundle);
  48. foreach ($info as $field_name => $details) {
  49. $field_type = $details['type'];
  50. // If the field already exists then skip it.
  51. $field = field_info_field($details['field_name']);
  52. if ($field) {
  53. continue;
  54. }
  55. // Create the field.
  56. $field = field_create_field($details);
  57. if (!$field) {
  58. tripal_set_message(t("Could not create new field: %field.",
  59. array('%field' => $details['field_name'])), TRIPAL_ERROR);
  60. }
  61. }
  62. }
  63. /**
  64. *
  65. * @param unknown $details
  66. */
  67. function tripal_chado_bundle_create_fields_base(&$info, $details, $entity_type, $bundle) {
  68. $table_name = $details['chado_table'];
  69. $type_table = $details['chado_type_table'];
  70. $type_field = $details['chado_type_column'];
  71. $cv_id = $details['chado_cv_id'];
  72. $cvterm_id = $details['chado_cvterm_id'];
  73. // Iterate through the columns of the table and see if fields have been
  74. // created for each one. If not, then create them.
  75. $schema = chado_get_schema($table_name);
  76. if (!$schema) {
  77. return;
  78. }
  79. // Get the list of columns for this table and create a new field for each one.
  80. $columns = $schema['fields'];
  81. foreach ($columns as $column_name => $details) {
  82. $field_name = $table_name . '__' . $column_name;
  83. // Skip fields with a custom field:
  84. if ($field_name == 'dbxref_id' or $field_name == 'organism_id') {
  85. continue;
  86. }
  87. if ($table_name == 'feature' and ($field_name == 'md5checksum' or
  88. $field_name == 'residues' or $field_name == 'seqlen')) {
  89. continue;
  90. }
  91. if ($table_name == 'organism' and ($field_name == 'type_id')) {
  92. continue;
  93. }
  94. // Skip the primary key field.
  95. if ($column_name == $schema['primary key'][0]) {
  96. continue;
  97. }
  98. // Skip the type field.
  99. if ($table_name == $type_table and $column_name == $type_field) {
  100. continue;
  101. }
  102. // Set some defaults for the field.
  103. $base_info = array(
  104. 'field_name' => $field_name,
  105. 'type' => '',
  106. 'cardinality' => 1,
  107. 'locked' => FALSE,
  108. 'storage' => array(
  109. 'type' => 'field_chado_storage',
  110. ),
  111. 'settings' => array(
  112. 'chado_table' => $table_name,
  113. 'chado_column' => $column_name,
  114. 'semantic_web' => tripal_get_chado_semweb_term($table_name, $column_name),
  115. ),
  116. );
  117. // Alter the field info array depending on the column details.
  118. switch($details['type']) {
  119. case 'char':
  120. $base_info['type'] = 'text';
  121. $base_info['settings']['max_length'] = $details['length'];
  122. break;
  123. case 'varchar':
  124. $base_info['type'] = 'text';
  125. $base_info['settings']['max_length'] = $details['length'];
  126. break;
  127. case 'text':
  128. $base_info['type'] = 'text';
  129. $base_info['settings']['max_length'] = 17179869184;
  130. $base_info['settings']['text_processing'] = 1;
  131. break;
  132. case 'blob':
  133. // not sure how to support a blob field.
  134. continue;
  135. break;
  136. case 'int':
  137. $base_info['type'] = 'number_integer';
  138. break;
  139. case 'float':
  140. $base_info['type'] = 'number_float';
  141. $base_info['settings']['precision'] = 10;
  142. $base_info['settings']['scale'] = 2;
  143. $base_info['settings']['decimal_separator'] = '.';
  144. break;
  145. case 'numeric':
  146. $base_info['type'] = 'number_decimal';
  147. break;
  148. case 'serial':
  149. // Serial fields are most likely not needed as a field.
  150. break;
  151. case 'boolean':
  152. $base_info['type'] = 'list_boolean';
  153. $base_info['settings']['allowed_values'] = array(0 => "No", 1 => "Yes");
  154. break;
  155. case 'datetime':
  156. // Use the Drupal Date and Date API to create the field/widget
  157. $base_info['type'] = 'datetime';
  158. break;
  159. }
  160. // Set some default semantic web information
  161. if ($column_name == 'uniquename') {
  162. $base_info['settings']['text_processing'] = 0;
  163. }
  164. //
  165. // PUB TABLE
  166. //
  167. elseif ($table_name == 'pub' and $column_name == 'uniquename') {
  168. $base_info['type'] = 'text';
  169. $base_info['settings']['text_processing'] = 0;
  170. }
  171. //
  172. // ANALYSIS TABLE
  173. //
  174. elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
  175. $base_info['type'] = 'text';
  176. $base_info['settings']['text_processing'] = 0;
  177. }
  178. $info[$field_name] = $base_info;
  179. }
  180. }
  181. /**
  182. *
  183. * @param unknown $details
  184. */
  185. function tripal_chado_bundle_create_fields_custom(&$info, $details, $entity_type, $bundle) {
  186. $table_name = $details['chado_table'];
  187. $type_table = $details['chado_type_table'];
  188. $type_field = $details['chado_type_column'];
  189. $cv_id = $details['chado_cv_id'];
  190. $cvterm_id = $details['chado_cvterm_id'];
  191. $schema = chado_get_schema($table_name);
  192. // BASE ORGANISM_ID
  193. if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
  194. $field_name = 'obi__organism';
  195. $field_type = 'obi__organism';
  196. $info[$field_name] = array(
  197. 'field_name' => $field_name,
  198. 'type' => $field_type,
  199. 'cardinality' => 1,
  200. 'locked' => FALSE,
  201. 'storage' => array(
  202. 'type' => 'field_chado_storage',
  203. ),
  204. 'settings' => array(
  205. 'chado_table' => $table_name,
  206. 'chado_column' => 'organism_id',
  207. ),
  208. );
  209. }
  210. // BASE DBXREF
  211. if (array_key_exists('dbxref_id', $schema['fields'])) {
  212. $field_name = 'data__accession';
  213. $field_type = 'data__accession';
  214. $info[$field_name] = array(
  215. 'field_name' => $field_name,
  216. 'type' => $field_type,
  217. 'cardinality' => 1,
  218. 'locked' => FALSE,
  219. 'storage' => array(
  220. 'type' => 'field_chado_storage',
  221. ),
  222. 'settings' => array(
  223. 'chado_table' => $table_name,
  224. 'chado_column' => 'dbxref_id',
  225. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'dbxref_id'),
  226. ),
  227. );
  228. }
  229. // FEATURE MD5CHECKSUM
  230. if ($table_name == 'feature') {
  231. $field_name = 'data__sequence_checksum';
  232. $field_type = 'data__sequence_checksum';
  233. $info[$field_name] = array(
  234. 'field_name' => $field_name,
  235. 'type' => $field_type,
  236. 'cardinality' => 1,
  237. 'locked' => FALSE,
  238. 'storage' => array(
  239. 'type' => 'field_chado_storage',
  240. ),
  241. 'settings' => array(
  242. 'chado_table' => $table_name,
  243. 'chado_column' => 'md5checksum',
  244. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'md5checksum'),
  245. ),
  246. );
  247. }
  248. // FEATURE RESIDUES
  249. if ($table_name == 'feature') {
  250. $field_name = 'data__sequence';
  251. $field_type = 'data__sequence';
  252. $info[$field_name] = array(
  253. 'field_name' => $field_name,
  254. 'type' => $field_type,
  255. 'cardinality' => 1,
  256. 'locked' => FALSE,
  257. 'storage' => array(
  258. 'type' => 'field_chado_storage',
  259. ),
  260. 'settings' => array(
  261. 'chado_table' => $table_name,
  262. 'chado_column' => 'residues',
  263. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'residues'),
  264. ),
  265. );
  266. }
  267. // FEATURE SEQLEN
  268. if ($table_name == 'feature') {
  269. $field_name = 'data__sequence_length';
  270. $field_type = 'data__sequence_length';
  271. $info[$field_name] = array(
  272. 'field_name' => $field_name,
  273. 'type' => $field_type,
  274. 'cardinality' => 1,
  275. 'locked' => FALSE,
  276. 'storage' => array(
  277. 'type' => 'field_chado_storage',
  278. ),
  279. 'settings' => array(
  280. 'chado_table' => $table_name,
  281. 'chado_column' => 'seqlen',
  282. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'seqlen'),
  283. ),
  284. );
  285. }
  286. // GENE TRANSCRIPTS
  287. $rel_table = $table_name . '_relationship';
  288. if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  289. $field_name = 'so__transcript';
  290. $field_type = 'so__transcript';
  291. $info[$field_name] = array(
  292. 'field_name' => $field_name,
  293. 'type' => $field_type,
  294. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  295. 'locked' => FALSE,
  296. 'storage' => array(
  297. 'type' => 'field_chado_storage',
  298. ),
  299. 'settings' => array(
  300. 'chado_table' => $rel_table,
  301. 'chado_column' => '',
  302. 'base_table' => $table_name,
  303. 'semantic_web' => 'SO:0000673',
  304. ),
  305. );
  306. }
  307. // ORGANISM TYPE_ID
  308. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  309. $field_name = 'taxarank__infraspecific_taxon';
  310. $field_type = 'taxarank__infraspecific_taxon';
  311. $info[$field_name] = array(
  312. 'field_name' => $field_name,
  313. 'type' => $field_type,
  314. 'cardinality' => 1,
  315. 'locked' => FALSE,
  316. 'storage' => array(
  317. 'type' => 'field_chado_storage',
  318. ),
  319. 'settings' => array(
  320. 'chado_table' => 'organism',
  321. 'chado_column' => 'type_id',
  322. 'semantic_web' => 'TAXRANK:0000046',
  323. ),
  324. );
  325. }
  326. }
  327. /**
  328. *
  329. * @param unknown $details
  330. */
  331. function tripal_chado_bundle_create_fields_linker(&$info, $details, $entity_type, $bundle) {
  332. $table_name = $details['chado_table'];
  333. $type_table = $details['chado_type_table'];
  334. $type_field = $details['chado_type_column'];
  335. $cv_id = $details['chado_cv_id'];
  336. $cvterm_id = $details['chado_cvterm_id'];
  337. // CONTACTS
  338. $contact_table = $table_name . '_contact';
  339. if (chado_table_exists($contact_table)) {
  340. $schema = chado_get_schema($contact_table);
  341. $pkey = $schema['primary key'][0];
  342. $field_name = $table_name . '_contact';
  343. $field_type = 'chado_linker__contact';
  344. $info[$field_name] = array(
  345. 'field_name' => $field_name,
  346. 'type' => $field_type,
  347. 'cardinality' => 1,
  348. 'locked' => FALSE,
  349. 'storage' => array(
  350. 'type' => 'field_chado_storage',
  351. ),
  352. 'settings' => array(
  353. 'chado_table' => $contact_table,
  354. 'base_table' => $table_name,
  355. 'chado_column' => 'contact_id',
  356. 'semantic_web' => tripal_get_chado_semweb_term($table_name, 'contact_id'),
  357. ),
  358. );
  359. }
  360. // CVTERM
  361. $cvterm_table = $table_name . '_cvterm';
  362. if (chado_table_exists($cvterm_table)) {
  363. $field_name = $table_name . '_cvterm';
  364. $field_type = 'chado_linker__cvterm_adder';
  365. $info[$field_name] = array(
  366. 'field_name' => $field_name,
  367. 'type' => $field_type,
  368. 'cardinality' => 1,
  369. 'locked' => FALSE,
  370. 'storage' => array(
  371. 'type' => 'field_chado_storage',
  372. ),
  373. 'settings' => array(
  374. ),
  375. );
  376. }
  377. // DBXREF
  378. $dbxref_table = $table_name . '_dbxref';
  379. if (chado_table_exists($dbxref_table)) {
  380. $dbxref_table = $table_name . '_dbxref';
  381. $schema = chado_get_schema($dbxref_table);
  382. $pkey = $schema['primary key'][0];
  383. $field_name = 'sbo__database_cross_reference';
  384. $field_type = 'sbo__database_cross_reference';
  385. $info[$field_name] = array(
  386. 'field_name' => $field_name,
  387. 'type' => $field_type,
  388. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  389. 'locked' => FALSE,
  390. 'storage' => array(
  391. 'type' => 'field_chado_storage',
  392. ),
  393. 'settings' => array(
  394. 'chado_table' => $dbxref_table,
  395. 'chado_column' => $pkey,
  396. 'base_table' => $table_name,
  397. 'semantic_web' => 'SBO:0000554',
  398. ),
  399. );
  400. }
  401. // EXPRESSION
  402. $expression_table = $table_name . '_expression';
  403. if (chado_table_exists($expression_table)) {
  404. $schema = chado_get_schema($expression_table);
  405. $pkey = $schema['primary key'][0];
  406. $field_name = 'go__gene_expression';
  407. $field_type = 'go__gene_expression';
  408. $info[$field_name] = array(
  409. 'field_name' => $field_name,
  410. 'type' => $field_type,
  411. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  412. 'locked' => FALSE,
  413. 'storage' => array(
  414. 'type' => 'field_chado_storage',
  415. ),
  416. 'settings' => array(
  417. 'chado_table' => $expression_table,
  418. 'chado_column' => $pkey,
  419. 'base_table' => $table_name,
  420. 'semantic_web' => 'GO:0010467',
  421. ),
  422. );
  423. }
  424. // FEATURELOC
  425. if ($table_name == 'feature') {
  426. $schema = chado_get_schema('featureloc');
  427. $pkey = $schema['primary key'][0];
  428. $field_name = 'data__sequence_coordinates';
  429. $field_type = 'data__sequence_coordinates';
  430. $info[$field_name] = array(
  431. 'field_name' => $field_name,
  432. 'type' => $field_type,
  433. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  434. 'locked' => FALSE,
  435. 'storage' => array(
  436. 'type' => 'field_chado_storage',
  437. ),
  438. 'settings' => array(
  439. 'chado_table' => 'featureloc',
  440. 'chado_column' => $pkey,
  441. 'base_table' => 'feature',
  442. 'semantic_web' => 'data:2012',
  443. ),
  444. );
  445. }
  446. // FEATUREPOS
  447. if ($table_name == 'feature') {
  448. $schema = chado_get_schema('featurepos');
  449. $pkey = $schema['primary key'][0];
  450. $field_name = 'ogi__location_on_map';
  451. $field_type = 'ogi__location_on_map';
  452. $info[$field_name] = array(
  453. 'field_name' => $field_name,
  454. 'type' => $field_type,
  455. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  456. 'locked' => FALSE,
  457. 'storage' => array(
  458. 'type' => 'field_chado_storage',
  459. ),
  460. 'settings' => array(
  461. 'chado_table' => 'featurepos',
  462. 'chado_column' => $pkey,
  463. 'base_table' => 'feature',
  464. 'semantic_web' => 'OGI:0000021',
  465. ),
  466. );
  467. }
  468. // GENOTYPE
  469. $genotype_table = $table_name . '_genotype';
  470. if (chado_table_exists($genotype_table)) {
  471. $schema = chado_get_schema($genotype_table);
  472. $pkey = $schema['primary key'][0];
  473. $field_name = 'so__genotype';
  474. $field_type = 'so__genotype';
  475. $info[$field_name] = array(
  476. 'field_name' => $field_name,
  477. 'type' => $field_type,
  478. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  479. 'locked' => FALSE,
  480. 'storage' => array(
  481. 'type' => 'field_chado_storage',
  482. ),
  483. 'settings' => array(
  484. 'chado_table' => $genotype_table,
  485. 'chado_column' => $pkey,
  486. 'semantic_web' => 'SO:0001027',
  487. 'base_table' => $table_name,
  488. ),
  489. );
  490. }
  491. // PHENOTYPE
  492. $phenotype_table = $table_name . '_phenotype';
  493. if (chado_table_exists($phenotype_table)) {
  494. $schema = chado_get_schema($phenotype_table);
  495. $pkey = $schema['primary key'][0];
  496. $field_name = 'sbo__phenotype';
  497. $field_type = 'sbo__phenotype';
  498. $info[$field_name] = array(
  499. 'field_name' => $field_name,
  500. 'type' => $field_type,
  501. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  502. 'locked' => FALSE,
  503. 'storage' => array(
  504. 'type' => 'field_chado_storage',
  505. ),
  506. 'settings' => array(
  507. 'chado_table' => $phenotype_table,
  508. 'chado_column' => $pkey,
  509. 'base_table' => $table_name,
  510. 'semantic_web' => 'SBO:0000358',
  511. ),
  512. );
  513. }
  514. // PROPERTIES
  515. $prop_table = $table_name . 'prop';
  516. if (chado_table_exists($prop_table)) {
  517. $field_name = $table_name . 'prop';
  518. $field_type = 'chado_linker__prop_adder';
  519. $info[$field_name] = array(
  520. 'field_name' => $field_name,
  521. 'type' => $field_type,
  522. 'cardinality' => 1,
  523. 'locked' => FALSE,
  524. 'storage' => array(
  525. 'type' => 'field_chado_storage',
  526. ),
  527. 'settings' => array(
  528. 'base_table' => $table_name
  529. ),
  530. );
  531. }
  532. // PUBLICATIONS
  533. $pub_table = $table_name . '_pub';
  534. if (chado_table_exists($pub_table)) {
  535. $schema = chado_get_schema($pub_table);
  536. $pkey = $schema['primary key'][0];
  537. $field_name = 'schema__publication';
  538. $field_type = 'schema__publication';
  539. $info[$field_name] = array(
  540. 'field_name' => $field_name,
  541. 'type' => $field_type,
  542. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  543. 'locked' => FALSE,
  544. 'storage' => array(
  545. 'type' => 'field_chado_storage',
  546. ),
  547. 'settings' => array(
  548. 'chado_table' => $pub_table,
  549. 'chado_column' => $pkey,
  550. 'base_table' => $table_name,
  551. 'semantic_web' => 'schema:publication',
  552. ),
  553. );
  554. }
  555. // RELATIONSHIPS
  556. // If the linker table does not exists then we don't want to add attach.
  557. $rel_table = $table_name . '_relationship';
  558. if (chado_table_exists($rel_table)) {
  559. $schema = chado_get_schema($rel_table);
  560. $pkey = $schema['primary key'][0];
  561. $field_name = 'sbo__relationship';
  562. $field_type = 'sbo__relationship';
  563. $info[$field_name] = array(
  564. 'field_name' => $field_name,
  565. 'type' => $field_type,
  566. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  567. 'locked' => FALSE,
  568. 'storage' => array(
  569. 'type' => 'field_chado_storage',
  570. ),
  571. 'settings' => array(
  572. 'chado_table' => $rel_table,
  573. 'chado_column' => $pkey,
  574. 'base_table' => $table_name,
  575. 'semantic_web' => 'SBO:0000374',
  576. ),
  577. );
  578. }
  579. // SYNONYMS
  580. $syn_table = $table_name . '_synonym';
  581. if (chado_table_exists($syn_table)) {
  582. $schema = chado_get_schema($syn_table);
  583. $pkey = $schema['primary key'][0];
  584. $field_name = 'schema__alternate_name';
  585. $field_type = 'schema__alternate_name';
  586. $info[$field_name] = array(
  587. 'field_name' => $field_name,
  588. 'type' => $field_type,
  589. 'cardinality' => FIELD_CARDINALITY_UNLIMITED,
  590. 'locked' => FALSE,
  591. 'storage' => array(
  592. 'type' => 'field_chado_storage',
  593. ),
  594. 'settings' => array(
  595. 'chado_table' => $syn_table,
  596. 'chado_column' => $pkey,
  597. 'base_table' => $table_name,
  598. 'semantic_web' => 'schema:alternateName',
  599. ),
  600. );
  601. }
  602. }
  603. /**
  604. * Impelments hook_create_tripalfield_instance().
  605. *
  606. * This is a Tripal defined hook that supports integration with the
  607. * TripalEntity field.
  608. */
  609. function tripal_chado_bundle_create_instances($entity_type, $bundle) {
  610. $term = tripal_load_term_entity(array('term_id' => $bundle->term_id));
  611. $vocab = $term->vocab;
  612. $params = array(
  613. 'vocabulary' => $vocab->vocabulary,
  614. 'accession' => $term->accession,
  615. );
  616. $mapped_table = chado_get_cvterm_mapping($params);
  617. // Get the details about the mapping of this bundle to the Chado table:
  618. $details = array(
  619. 'chado_cv_id' => $mapped_table->cvterm->cv_id->cv_id,
  620. 'chado_cvterm_id' => $mapped_table->cvterm->cvterm_id,
  621. 'chado_table' => $mapped_table->chado_table,
  622. 'chado_type_table' => $mapped_table->chado_table,
  623. 'chado_type_column' => $mapped_table->chado_field,
  624. );
  625. tripal_chado_bundle_create_instances_base($info, $entity_type, $bundle, $details);
  626. tripal_chado_bundle_create_instances_custom($info, $entity_type, $bundle, $details);
  627. tripal_chado_bundle_create_instances_linker($info, $entity_type, $bundle, $details);
  628. foreach ($info as $field_name => $details) {
  629. // If the field is already attached to this bundle then skip it.
  630. $field = field_info_field($details['field_name']);
  631. if ($field and array_key_exists('bundles', $field) and
  632. array_key_exists('TripalEntity', $field['bundles']) and
  633. in_array($bundle_name, $field['bundles']['TripalEntity'])) {
  634. continue;
  635. }
  636. // Create the field instance.
  637. $instance = field_create_instance($details);
  638. }
  639. }
  640. /**
  641. * Helper function for the hook_create_tripalfield_instance().
  642. *
  643. * Add the field instances that corresond to the columns of the base table.
  644. *
  645. * @param $entity_type
  646. * @param $bundle
  647. * @param $details
  648. */
  649. function tripal_chado_bundle_create_instances_base(&$info, $entity_type, $bundle, $details) {
  650. $fields = array();
  651. // Get Chado information
  652. $table_name = $details['chado_table'];
  653. $type_table = $details['chado_type_table'];
  654. $type_field = $details['chado_type_column'];
  655. $cv_id = $details['chado_cv_id'];
  656. $cvterm_id = $details['chado_cvterm_id'];
  657. // Iterate through the columns of the table and see if fields have been
  658. // created for each one. If not, then create them.
  659. $schema = chado_get_schema($table_name);
  660. if (!$schema) {
  661. return;
  662. }
  663. $columns = $schema['fields'];
  664. foreach ($columns as $column_name => $details) {
  665. $field_name = $table_name . '__' . $column_name;
  666. // Skip the primary key field.
  667. if ($column_name == $schema['primary key'][0]) {
  668. continue;
  669. }
  670. // Skip the type field.
  671. if ($table_name == $type_table and $column_name == $type_field) {
  672. continue;
  673. }
  674. $base_info = array(
  675. 'field_name' => $field_name,
  676. 'entity_type' => 'TripalEntity',
  677. 'bundle' => $bundle->name,
  678. 'label' => ucwords(preg_replace('/_/', ' ', $column_name)),
  679. 'description' => '',
  680. 'required' => FALSE,
  681. 'settings' => array(
  682. 'auto_attach' => TRUE,
  683. ),
  684. 'widget' => array(
  685. 'settings' => array(
  686. 'display_label' => 1,
  687. ),
  688. ),
  689. 'display' => array(
  690. 'default' => array(
  691. 'label' => 'inline',
  692. 'settings' => array(),
  693. ),
  694. ),
  695. );
  696. // Determine if the field is required.
  697. if (array_key_exists('not null', $details) and $details['not null'] === TRUE) {
  698. $base_info['required'] = TRUE;
  699. }
  700. // Alter the field info array depending on the column details.
  701. switch($details['type']) {
  702. case 'char':
  703. $base_info['widget']['type'] = 'text_textfield';
  704. break;
  705. case 'varchar':
  706. $base_info['widget']['type'] = 'text_textfield';
  707. break;
  708. case 'text':
  709. $base_info['widget']['type'] = 'text_textarea';
  710. $base_info['widget']['settings']['format'] = filter_default_format();
  711. break;
  712. case 'blob':
  713. // not sure how to support a blob field.
  714. continue;
  715. break;
  716. case 'int':
  717. $base_info['widget']['type'] = 'number';
  718. break;
  719. case 'float':
  720. $base_info['widget']['type'] = 'number';
  721. break;
  722. case 'numeric':
  723. $base_info['widget']['type'] = 'number';
  724. break;
  725. case 'serial':
  726. // Serial fields are most likely not needed as a field.
  727. break;
  728. case 'boolean':
  729. $base_info['widget']['type'] = 'options_onoff';
  730. $base_info['required'] = FALSE;
  731. break;
  732. case 'datetime':
  733. $base_info['widget']['type'] = 'date_select';
  734. $base_info['widget']['settings']['increment'] = 1;
  735. $base_info['widget']['settings']['tz_handling'] = 'none';
  736. $base_info['widget']['settings']['collapsible'] = TRUE;
  737. // TODO: Add settings so that the minutes increment by 1.
  738. // And turn off the timezone, as the Chado field doesn't support it.
  739. break;
  740. }
  741. // Set some default semantic web information
  742. if ($column_name == 'uniquename') {
  743. $base_info['label'] = 'Identifier';
  744. $base_info['widget_type'] = 'text_textfield';
  745. }
  746. elseif ($base_info['label'] == 'Timeaccessioned') {
  747. $base_info['label'] = 'Time Accessioned';
  748. $base_info['description'] = 'Please enter the time that this record was first added to the database.';
  749. }
  750. elseif ($base_info['label'] == 'Timelastmodified') {
  751. $base_info['label'] = 'Time Last Modified';
  752. $base_info['description'] = 'Please enter the time that this record was last modified. The default is the current time.';
  753. }
  754. //
  755. // ORGANISM TABLE
  756. //
  757. elseif ($table_name == 'organism' and $column_name == 'comment') {
  758. $base_info['label'] = 'Description';
  759. }
  760. //
  761. // PUB TABLE
  762. //
  763. elseif ($table_name == 'pub' and $column_name == 'uniquename') {
  764. $base_info['widget_type'] = 'text_textfield';
  765. }
  766. //
  767. // ANALYSIS TABLE
  768. //
  769. elseif ($table_name == 'analysis' and $column_name == 'program') {
  770. $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.';
  771. $base_info['label'] = 'Program, Pipeline, Workflow or Method Name.';
  772. }
  773. elseif ($table_name == 'analysis' and $column_name == 'sourceuri') {
  774. $base_info['widget_type'] = 'text_textfield';
  775. $base_info['label'] = 'Source URL';
  776. $base_info['description'] = 'The URL where the original source data was derived. Ideally, this should link to the page where more information about the source data can be found.';
  777. }
  778. elseif ($table_name == 'analysis' and $column_name == 'sourcename') {
  779. $base_info['label'] = 'Source Name';
  780. $base_info['description'] = 'The name of the source data. This could be a file name, data set or a small description for how the data was collected. For long descriptions use the larger description field.';
  781. }
  782. elseif ($table_name == 'analysis' and $column_name == 'sourceversion') {
  783. $base_info['label'] = 'Source Version';
  784. $base_info['description'] = 'If hte source data set has a version include it here.';
  785. }
  786. elseif ($table_name == 'analysis' and $column_name == 'algorithm') {
  787. $base_info['label'] = 'Source Version';
  788. $base_info['description'] = 'The name of the algorithm used to produce the dataset if different from the program.';
  789. }
  790. elseif ($table_name == 'analysis' and $column_name == 'programversion') {
  791. $base_info['label'] = 'Program Version';
  792. $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.';
  793. }
  794. //
  795. // PROJECT TABLE
  796. //
  797. elseif ($table_name == 'project' and $column_name == 'description') {
  798. $base_info['label'] = 'Short Description';
  799. }
  800. $info[$field_name] = $base_info;
  801. }
  802. }
  803. /**
  804. * Helper function for the hook_create_tripalfield_instance().
  805. *
  806. * Adds custom fields for base fields. These override the settings provided
  807. * in the tripal_chado_create_tripalfield_instance_base() function.
  808. *
  809. * @param $entity_type
  810. * @param $bundle
  811. * @param $details
  812. */
  813. function tripal_chado_bundle_create_instances_custom(&$info, $entity_type, $bundle, $details) {
  814. $table_name = $details['chado_table'];
  815. $type_table = $details['chado_type_table'];
  816. $type_field = $details['chado_type_column'];
  817. $cv_id = $details['chado_cv_id'];
  818. $cvterm_id = $details['chado_cvterm_id'];
  819. $schema = chado_get_schema($table_name);
  820. // BASE ORGANISM_ID
  821. if ($table_name != 'organism' and array_key_exists('organism_id', $schema['fields'])) {
  822. $field_name = 'obi__organism';
  823. $is_required = FALSE;
  824. if (array_key_exists('not null', $schema['fields']['organism_id']) and
  825. $schema['fields']['organism_id']['not null']) {
  826. $is_required = TRUE;
  827. }
  828. $info[$field_name] = array(
  829. 'field_name' => $field_name,
  830. 'entity_type' => $entity_type,
  831. 'bundle' => $bundle->name,
  832. 'label' => 'Organism',
  833. 'description' => 'Select an organism.',
  834. 'required' => $is_required,
  835. 'settings' => array(
  836. 'auto_attach' => TRUE,
  837. ),
  838. 'widget' => array(
  839. 'type' => 'obi__organism_widget',
  840. 'settings' => array(
  841. 'display_label' => 1,
  842. ),
  843. ),
  844. 'display' => array(
  845. 'default' => array(
  846. 'label' => 'inline',
  847. 'type' => 'obi__organism_formatter',
  848. 'settings' => array(),
  849. ),
  850. ),
  851. );
  852. }
  853. // BASE DBXREF
  854. if (array_key_exists('dbxref_id', $schema['fields'])) {
  855. $field_name = 'data__accession';
  856. $info[$field_name] = array(
  857. 'field_name' => $field_name,
  858. 'entity_type' => $entity_type,
  859. 'bundle' => $bundle->name,
  860. 'label' => 'Accession',
  861. 'description' => 'This field specifies the unique stable accession (ID) for
  862. this record. It requires that this site have a database entry.',
  863. 'required' => FALSE,
  864. 'settings' => array(
  865. 'auto_attach' => TRUE,
  866. ),
  867. 'widget' => array(
  868. 'type' => 'data__accession_widget',
  869. 'settings' => array(
  870. 'display_label' => 1,
  871. ),
  872. ),
  873. 'display' => array(
  874. 'default' => array(
  875. 'label' => 'inline',
  876. 'type' => 'data__accession_formatter',
  877. 'settings' => array(),
  878. ),
  879. ),
  880. );
  881. }
  882. // FEATURE MD5CHECKSUM
  883. if ($table_name == 'feature') {
  884. $field_name = 'data__sequence_checksum';
  885. $info[$field_name] = array(
  886. 'field_name' => $field_name,
  887. 'entity_type' => $entity_type,
  888. 'bundle' => $bundle->name,
  889. 'label' => 'Sequence Checksum',
  890. 'description' => 'The MD5 checksum for the sequence. The checksum here
  891. will always be unique for the raw unformatted sequence. To verify that the
  892. sequence has not been corrupted, download the raw sequence and use an MD5 tool
  893. to calculate the value. If the value calculated is identical the one shown
  894. here, then the downloaded sequence is uncorrupted.',
  895. 'required' => FALSE,
  896. 'settings' => array(
  897. 'auto_attach' => TRUE,
  898. ),
  899. 'widget' => array(
  900. 'type' => 'data__sequence_checksum_widget',
  901. 'settings' => array(
  902. 'display_label' => 1,
  903. 'md5_fieldname' => 'feature__md5checksum',
  904. ),
  905. ),
  906. 'display' => array(
  907. 'default' => array(
  908. 'label' => 'inline',
  909. 'type' => 'data__sequence_checksum_formatter',
  910. 'settings' => array(),
  911. ),
  912. ),
  913. );
  914. }
  915. // FEATURE RESIDUES
  916. if ($table_name == 'feature') {
  917. $field_name = 'data__sequence';
  918. $info[$field_name] = array(
  919. 'field_name' => $field_name,
  920. 'entity_type' => $entity_type,
  921. 'bundle' => $bundle->name,
  922. 'label' => 'Sequences',
  923. 'description' => 'All available sequences for this record.',
  924. 'required' => FALSE,
  925. 'settings' => array(
  926. 'auto_attach' => FALSE,
  927. ),
  928. 'widget' => array(
  929. 'type' => 'data__sequence_widget',
  930. 'settings' => array(
  931. 'display_label' => 1,
  932. ),
  933. ),
  934. 'display' => array(
  935. 'default' => array(
  936. 'label' => 'above',
  937. 'type' => 'data__sequence_formatter',
  938. 'settings' => array(),
  939. ),
  940. ),
  941. );
  942. }
  943. // FEATURE SEQLEN
  944. if ($table_name == 'feature') {
  945. $field_name = 'data__sequence_length';
  946. $info[$field_name] = array(
  947. 'field_name' => $field_name,
  948. 'entity_type' => $entity_type,
  949. 'bundle' => $bundle->name,
  950. 'label' => 'Sequence Length',
  951. 'description' => 'The number of residues in the raw sequence. This length
  952. is only for the assigned raw sequence and does not represent the length of any
  953. sequences derived from alignments. If this value is zero but aligned sequences
  954. are present then this record has no official assigned sequence.',
  955. 'required' => FALSE,
  956. 'settings' => array(
  957. 'auto_attach' => TRUE,
  958. ),
  959. 'widget' => array(
  960. 'type' => 'data__sequence_length_widget',
  961. 'settings' => array(
  962. 'display_label' => 1,
  963. ),
  964. ),
  965. 'display' => array(
  966. 'default' => array(
  967. 'label' => 'inline',
  968. 'type' => 'data__sequence_length_formatter',
  969. 'settings' => array(),
  970. ),
  971. ),
  972. );
  973. }
  974. // GENE TRANSCRIPTS
  975. $rel_table = $table_name . '_relationship';
  976. if (chado_table_exists($rel_table) and $bundle->label == 'gene') {
  977. $field_name = 'so__transcript';
  978. $info[$field_name] = array(
  979. 'field_name' => $field_name,
  980. 'entity_type' => $entity_type,
  981. 'bundle' => $bundle->name,
  982. 'label' => 'Transcript',
  983. 'description' => 'These transcripts are associated with this gene.',
  984. 'required' => FALSE,
  985. 'settings' => array(
  986. 'auto_attach' => FALSE,
  987. ),
  988. 'widget' => array(
  989. 'type' => 'so__transcript_widget',
  990. 'settings' => array(
  991. 'display_label' => 1,
  992. ),
  993. ),
  994. 'display' => array(
  995. 'default' => array(
  996. 'label' => 'above',
  997. 'type' => 'so__transcript_formatter',
  998. 'settings' => array(),
  999. ),
  1000. ),
  1001. );
  1002. }
  1003. // ORGANISM TYPE_ID
  1004. if ($table_name == 'organism' and array_key_exists('type_id', $schema['fields'])) {
  1005. $field_name = 'taxarank__infraspecific_taxon';
  1006. $info[$field_name] = array(
  1007. 'field_name' => $field_name,
  1008. 'entity_type' => $entity_type,
  1009. 'bundle' => $bundle->name,
  1010. 'label' => 'Infraspecific Taxon',
  1011. 'description' => 'The Infraspecific Taxon.',
  1012. 'required' => FALSE,
  1013. 'settings' => array(
  1014. 'auto_attach' => TRUE,
  1015. ),
  1016. 'widget' => array(
  1017. 'type' => 'taxarank__infraspecific_taxon_widget',
  1018. 'settings' => array(
  1019. 'display_label' => 1,
  1020. ),
  1021. ),
  1022. 'display' => array(
  1023. 'default' => array(
  1024. 'label' => 'inline',
  1025. 'type' => 'taxarank__infraspecific_taxon_formatter',
  1026. 'settings' => array(),
  1027. ),
  1028. ),
  1029. );
  1030. }
  1031. }
  1032. /**
  1033. *
  1034. * @param unknown $entity_type
  1035. * @param unknown $bundle
  1036. * @param unknown $details
  1037. */
  1038. function tripal_chado_bundle_create_instances_linker(&$info, $entity_type, $bundle, $details) {
  1039. $table_name = $details['chado_table'];
  1040. $type_table = $details['chado_type_table'];
  1041. $type_field = $details['chado_type_column'];
  1042. $cv_id = $details['chado_cv_id'];
  1043. $cvterm_id = $details['chado_cvterm_id'];
  1044. // CONTACTS
  1045. $contact_table = $table_name . '_contact';
  1046. if (chado_table_exists($contact_table)) {
  1047. $field_name = $table_name . '_contact';
  1048. $info[$field_name] = $info[$field_name] = array(
  1049. 'field_name' => $field_name,
  1050. 'entity_type' => $entity_type,
  1051. 'bundle' => $bundle->name,
  1052. 'label' => 'Contact',
  1053. 'description' => 'Associates an indviddual or organization with this record',
  1054. 'required' => FALSE,
  1055. 'settings' => array(
  1056. 'auto_attach' => TRUE,
  1057. ),
  1058. 'widget' => array(
  1059. 'type' => 'local__contact_widget',
  1060. 'settings' => array(
  1061. 'display_label' => 1,
  1062. ),
  1063. ),
  1064. 'display' => array(
  1065. 'default' => array(
  1066. 'label' => 'inline',
  1067. 'type' => 'local__contact_formatter',
  1068. 'settings' => array(),
  1069. ),
  1070. ),
  1071. );
  1072. }
  1073. // CVTERM
  1074. $cvterm_table = $table_name . '_cvterm';
  1075. if (chado_table_exists($cvterm_table)) {
  1076. $field_name = $table_name . '_cvterm';
  1077. $info[$field_name] = array(
  1078. 'field_name' => $field_name,
  1079. 'entity_type' => $entity_type,
  1080. 'bundle' => $bundle->name,
  1081. 'label' => 'Add Annotation Types',
  1082. 'description' => 'Add additional annotations types to this record.',
  1083. 'required' => FALSE,
  1084. 'settings' => array(
  1085. 'auto_attach' => FALSE,
  1086. ),
  1087. 'widget' => array(
  1088. 'type' => 'chado_linker__cvterm_adder_widget',
  1089. 'settings' => array(
  1090. 'display_label' => 1,
  1091. ),
  1092. ),
  1093. 'display' => array(
  1094. 'default' => array(
  1095. 'label' => 'above',
  1096. 'type' => 'chado_linker__cvterm_adder_formatter',
  1097. 'settings' => array(),
  1098. ),
  1099. ),
  1100. );
  1101. }
  1102. // DBXREF
  1103. $dbxref_table = $table_name . '_dbxref';
  1104. if (chado_table_exists($dbxref_table)) {
  1105. $field_name = 'sbo__database_cross_reference';
  1106. $info[$field_name] = array(
  1107. 'field_name' => $field_name,
  1108. 'entity_type' => $entity_type,
  1109. 'bundle' => $bundle->name,
  1110. 'label' => 'Database Cross Reference',
  1111. 'description' => 'The IDs where this record may be available in other external online databases.',
  1112. 'required' => FALSE,
  1113. 'settings' => array(
  1114. 'auto_attach' => FALSE,
  1115. ),
  1116. 'widget' => array(
  1117. 'type' => 'sbo__database_cross_reference_widget',
  1118. 'settings' => array(
  1119. 'display_label' => 1,
  1120. ),
  1121. ),
  1122. 'display' => array(
  1123. 'default' => array(
  1124. 'label' => 'inline',
  1125. 'type' => 'sbo__database_cross_reference_formatter',
  1126. 'settings' => array(),
  1127. ),
  1128. ),
  1129. );
  1130. }
  1131. // EXPRESSION
  1132. $expression_table = $table_name . '_expression';
  1133. if (chado_table_exists($expression_table)) {
  1134. $field_name = 'go__gene_expression';
  1135. $info[$field_name] = array(
  1136. 'field_name' => $field_name,
  1137. 'entity_type' => $entity_type,
  1138. 'bundle' => $bundle->name,
  1139. 'label' => 'Gene expression',
  1140. 'description' => 'Information about the expression of this record.',
  1141. 'required' => FALSE,
  1142. 'settings' => array(
  1143. 'auto_attach' => FALSE,
  1144. ),
  1145. 'widget' => array(
  1146. 'type' => 'go__gene_expression_widget',
  1147. 'settings' => array(
  1148. 'display_label' => 1,
  1149. ),
  1150. ),
  1151. 'display' => array(
  1152. 'default' => array(
  1153. 'label' => 'above',
  1154. 'type' => 'go__gene_expression_formatter',
  1155. 'settings' => array(),
  1156. ),
  1157. ),
  1158. );
  1159. }
  1160. // FEATURELOC
  1161. if ($table_name == 'feature') {
  1162. $field_name = 'data__sequence_coordinates';
  1163. $info[$field_name] = array(
  1164. 'field_name' => $field_name,
  1165. 'entity_type' => $entity_type,
  1166. 'bundle' => $bundle->name,
  1167. 'label' => 'Sequence Coordinates',
  1168. 'description' => 'The locations on other genomic sequences where this
  1169. record has been aligned.',
  1170. 'required' => FALSE,
  1171. 'settings' => array(
  1172. 'auto_attach' => FALSE,
  1173. ),
  1174. 'widget' => array(
  1175. 'type' => 'data__sequence_coordinates_widget',
  1176. 'settings' => array(
  1177. 'display_label' => 1,
  1178. ),
  1179. ),
  1180. 'display' => array(
  1181. 'default' => array(
  1182. 'label' => 'above',
  1183. 'type' => 'data__sequence_coordinates_formatter',
  1184. 'settings' => array(),
  1185. ),
  1186. ),
  1187. );
  1188. }
  1189. // FEATUREPOS
  1190. if ($table_name == 'feature') {
  1191. $field_name = 'ogi__location_on_map';
  1192. $info[$field_name] = array(
  1193. 'field_name' => $field_name,
  1194. 'entity_type' => $entity_type,
  1195. 'bundle' => $bundle->name,
  1196. 'label' => 'Location on Map',
  1197. 'description' => 'The positions on a genetic map.',
  1198. 'required' => FALSE,
  1199. 'settings' => array(
  1200. 'auto_attach' => FALSE,
  1201. ),
  1202. 'widget' => array(
  1203. 'type' => 'ogi__location_on_map_widget',
  1204. 'settings' => array(
  1205. 'display_label' => 1,
  1206. ),
  1207. ),
  1208. 'display' => array(
  1209. 'default' => array(
  1210. 'label' => 'above',
  1211. 'type' => 'ogi__location_on_map_formatter',
  1212. 'settings' => array(),
  1213. ),
  1214. ),
  1215. );
  1216. }
  1217. // GENOTYPE
  1218. $genotype_table = $table_name . '_genotype';
  1219. if (chado_table_exists($genotype_table)) {
  1220. $field_name = 'so__genotype';
  1221. $info[$field_name] = array(
  1222. 'field_name' => $field_name,
  1223. 'entity_type' => $entity_type,
  1224. 'bundle' => $bundle->name,
  1225. 'label' => 'Genotype',
  1226. 'description' => 'The genotypes associated with this record.',
  1227. 'required' => FALSE,
  1228. 'settings' => array(
  1229. 'auto_attach' => FALSE,
  1230. ),
  1231. 'widget' => array(
  1232. 'type' => 'so__genotype_widget',
  1233. 'settings' => array(
  1234. 'display_label' => 1,
  1235. ),
  1236. ),
  1237. 'display' => array(
  1238. 'default' => array(
  1239. 'label' => 'above',
  1240. 'type' => 'so__genotype_formatter',
  1241. 'settings' => array(),
  1242. ),
  1243. ),
  1244. );
  1245. }
  1246. // PHENOTYPE
  1247. $phenotype_table = $table_name . '_phenotype';
  1248. if (chado_table_exists($phenotype_table)) {
  1249. $field_name = 'sbo__phenotype';
  1250. $info[$field_name] = array(
  1251. 'field_name' => $field_name,
  1252. 'entity_type' => $entity_type,
  1253. 'bundle' => $bundle->name,
  1254. 'label' => 'Phenotype',
  1255. 'description' => 'The phenotypes associated with this record.',
  1256. 'required' => FALSE,
  1257. 'settings' => array(
  1258. 'auto_attach' => FALSE,
  1259. ),
  1260. 'widget' => array(
  1261. 'type' => 'sbo__phenotype_widget',
  1262. 'settings' => array(
  1263. 'display_label' => 1,
  1264. ),
  1265. ),
  1266. 'display' => array(
  1267. 'default' => array(
  1268. 'label' => 'above',
  1269. 'type' => 'sbo__phenotype_formatter',
  1270. 'settings' => array(),
  1271. ),
  1272. ),
  1273. );
  1274. }
  1275. // PROPERTIES
  1276. $prop_table = $table_name . 'prop';
  1277. if (chado_table_exists($prop_table)) {
  1278. $field_name = $table_name . 'prop';
  1279. $info[$field_name] = array(
  1280. 'field_name' => $field_name,
  1281. 'entity_type' => $entity_type,
  1282. 'bundle' => $bundle->name,
  1283. 'label' => 'Add Properties',
  1284. 'description' => 'Add additional property types to this record.',
  1285. 'required' => FALSE,
  1286. 'settings' => array(
  1287. 'auto_attach' => FALSE,
  1288. ),
  1289. 'widget' => array(
  1290. 'type' => 'chado_linker__prop_adder_widget',
  1291. 'settings' => array(
  1292. 'display_label' => 1,
  1293. ),
  1294. ),
  1295. 'display' => array(
  1296. 'default' => array(
  1297. 'label' => 'above',
  1298. 'type' => 'chado_linker__prop_adder_formatter',
  1299. 'settings' => array(),
  1300. ),
  1301. ),
  1302. );
  1303. }
  1304. // PUBLICATIONS
  1305. $pub_table = $table_name . '_pub';
  1306. if (chado_table_exists($pub_table)) {
  1307. $field_name = 'schema__publication';
  1308. $info[$field_name] = array(
  1309. 'field_name' => $field_name,
  1310. 'entity_type' => $entity_type,
  1311. 'bundle' => $bundle->name,
  1312. 'label' => 'Publication',
  1313. 'description' => 'This record has been referenced or is sourced from
  1314. these publications.',
  1315. 'required' => FALSE,
  1316. 'settings' => array(
  1317. 'auto_attach' => FALSE,
  1318. ),
  1319. 'widget' => array(
  1320. 'type' => 'schema__publication_widget',
  1321. 'settings' => array(
  1322. 'display_label' => 1,
  1323. ),
  1324. ),
  1325. 'display' => array(
  1326. 'default' => array(
  1327. 'label' => 'above',
  1328. 'type' => 'schema__publication_formatter',
  1329. 'settings' => array(),
  1330. ),
  1331. ),
  1332. );
  1333. }
  1334. // RELATIONSHIPS
  1335. // If the linker table does not exists then we don't want to add attach.
  1336. $rel_table = $table_name . '_relationship';
  1337. if (chado_table_exists($rel_table)) {
  1338. $field_name = 'sbo__relationship';
  1339. $info[$field_name] = array(
  1340. 'field_name' => $field_name,
  1341. 'entity_type' => $entity_type,
  1342. 'bundle' => $bundle->name,
  1343. 'label' => 'Relationship',
  1344. 'description' => 'Other records with relationships to this record.',
  1345. 'required' => FALSE,
  1346. 'settings' => array(
  1347. 'auto_attach' => FALSE,
  1348. ),
  1349. 'widget' => array(
  1350. 'type' => 'sbo__relationship_widget',
  1351. 'settings' => array(
  1352. 'display_label' => 1,
  1353. ),
  1354. ),
  1355. 'display' => array(
  1356. 'default' => array(
  1357. 'label' => 'above',
  1358. 'type' => 'sbo__relationship_formatter',
  1359. 'settings' => array(),
  1360. ),
  1361. ),
  1362. );
  1363. }
  1364. // SYNONYMS
  1365. $syn_table = $table_name . '_synonym';
  1366. if (chado_table_exists($syn_table)) {
  1367. $field_name = 'schema__alternate_name';
  1368. $info[$field_name] = array(
  1369. 'field_name' => $field_name,
  1370. 'entity_type' => $entity_type,
  1371. 'bundle' => $bundle->name,
  1372. 'label' => 'Synonyms',
  1373. 'description' => 'Alternate names, aliases or synonyms for this record.',
  1374. 'required' => FALSE,
  1375. 'settings' => array(
  1376. 'auto_attach' => FALSE,
  1377. ),
  1378. 'widget' => array(
  1379. 'type' => 'schema__alternate_name_widget',
  1380. 'settings' => array(
  1381. 'display_label' => 1,
  1382. ),
  1383. ),
  1384. 'display' => array(
  1385. 'default' => array(
  1386. 'label' => 'inline',
  1387. 'type' => 'schema__alternate_name_formatter',
  1388. 'settings' => array(),
  1389. ),
  1390. ),
  1391. );
  1392. }
  1393. }
  1394. /**
  1395. * Implements hook_form_FORM_ID_alter().
  1396. *
  1397. * The field_ui_field_overview_form is used for ordering and configuring the
  1398. * fields attached to an entity.
  1399. *
  1400. * This function removes the property adder field as that is really not meant
  1401. * for users to show or manage.
  1402. */
  1403. function tripal_chado_form_field_ui_field_overview_form_alter(&$form, &$form_state, $form_id) {
  1404. // Remove the kvproperty_addr field as it isn't ever displayed. It's just used
  1405. // on the add/edit form of an entity for adding new property fields.
  1406. $fields_names = element_children($form['fields']);
  1407. foreach ($fields_names as $field_name) {
  1408. $field_info = field_info_field($field_name);
  1409. if ($field_info['type'] == 'kvproperty_adder') {
  1410. unset($form['fields'][$field_name]);
  1411. }
  1412. if ($field_info['type'] == 'cvterm_class_adder') {
  1413. unset($form['fields'][$field_name]);
  1414. }
  1415. }
  1416. }