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