data__protein_sequence.inc 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. class data__protein_sequence extends TripalField {
  3. // --------------------------------------------------------------------------
  4. // EDITABLE STATIC CONSTANTS
  5. //
  6. // The following constants SHOULD be set for each descendent class. They are
  7. // used by the static functions to provide information to Drupal about
  8. // the field and it's default widget and formatter.
  9. // --------------------------------------------------------------------------
  10. // The default lable for this field.
  11. public static $default_label = 'Protein Sequence';
  12. // The default description for this field.
  13. public static $description = 'polypeptide sequences.';
  14. // Provide a list of global settings. These can be accessed witihn the
  15. // globalSettingsForm. When the globalSettingsForm is submitted then
  16. // Drupal will automatically change these settings for all fields.
  17. public static $default_settings = array(
  18. 'chado_table' => '',
  19. 'chado_column' => '',
  20. 'base_table' => '',
  21. );
  22. // Provide a list of instance specific settings. These can be access within
  23. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  24. // then Drupal with automatically change these settings for the instnace.
  25. // It is recommended to put settings at the instance level whenever possible.
  26. // If you override this variable in a child class be sure to replicate the
  27. // term_name, term_vocab, term_accession and term_fixed keys as these are
  28. // required for all TripalFields.
  29. public static $default_instance_settings = array(
  30. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  31. 'term_vocabulary' => 'data',
  32. // The name of the term.
  33. 'term_name' => 'protein_sequence',
  34. // The unique ID (i.e. accession) of the term.
  35. 'term_accession' => '2976',
  36. // Set to TRUE if the site admin is allowed to change the term
  37. // type. This will create form elements when editing the field instance
  38. // to allow the site admin to change the term settings above.
  39. 'term_fixed' => TRUE,
  40. );
  41. // Set this to the name of the storage backend that by default will support
  42. // this field.
  43. public static $storage = 'field_chado_storage';
  44. // The default widget for this field.
  45. public static $default_widget = 'data__protein_sequence_widget';
  46. // The default formatter for this field.
  47. public static $default_formatter = 'data__protein_sequence_formatter';
  48. /**
  49. * @see TripalField::load()
  50. */
  51. public function load($entity, $details = array()) {
  52. $field_name = $this->field['field_name'];
  53. $feature = $details['record'];
  54. $num_seqs = 0;
  55. // Look for Protein sequences
  56. $sql = "
  57. SELECT F.*
  58. FROM {feature_relationship} FR
  59. INNER JOIN {feature} F on FR.subject_id = F.feature_id
  60. INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
  61. INNER JOIN {cvterm} RCVT on RCVT.cvterm_id = FR.type_id
  62. WHERE
  63. FR.object_id = :feature_id and
  64. CVT.name = 'polypeptide' and
  65. RCVT.name = 'derives_from'
  66. ORDER BY FR.rank ASC
  67. ";
  68. $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
  69. while ($protein = $results->fetchObject()) {
  70. if ($protein->residues) {
  71. $entity->{$field_name}['und'][$num_seqs++]['value'] = $protein->residues;
  72. }
  73. }
  74. }
  75. }