tripal_chado.fields.inc 46 KB

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