tripal_chado.fields.inc 45 KB

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