tripal_chado.fields.inc 45 KB

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