data__protein_sequence.inc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. class data__protein_sequence extends ChadoField {
  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 instance specific settings. These can be access within
  15. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  16. // then Drupal with automatically change these settings for the instnace.
  17. // It is recommended to put settings at the instance level whenever possible.
  18. // If you override this variable in a child class be sure to replicate the
  19. // term_name, term_vocab, term_accession and term_fixed keys as these are
  20. // required for all TripalFields.
  21. public static $default_instance_settings = array(
  22. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  23. 'term_vocabulary' => 'data',
  24. // The name of the term.
  25. 'term_name' => 'protein_sequence',
  26. // The unique ID (i.e. accession) of the term.
  27. 'term_accession' => '2976',
  28. // Set to TRUE if the site admin is allowed to change the term
  29. // type. This will create form elements when editing the field instance
  30. // to allow the site admin to change the term settings above.
  31. 'term_fixed' => FALSE,
  32. );
  33. // The default widget for this field.
  34. public static $default_widget = 'data__protein_sequence_widget';
  35. // The default formatter for this field.
  36. public static $default_formatter = 'data__protein_sequence_formatter';
  37. /**
  38. * @see TripalField::load()
  39. */
  40. public function load($entity, $details = array()) {
  41. $field_name = $this->field['field_name'];
  42. $feature = $details['record'];
  43. $num_seqs = 0;
  44. // Look for Protein sequences
  45. $sql = "
  46. SELECT F.*
  47. FROM {feature_relationship} FR
  48. INNER JOIN {feature} F on FR.subject_id = F.feature_id
  49. INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
  50. INNER JOIN {cvterm} RCVT on RCVT.cvterm_id = FR.type_id
  51. WHERE
  52. FR.object_id = :feature_id and
  53. CVT.name = 'polypeptide' and
  54. RCVT.name = 'derives_from'
  55. ORDER BY FR.rank ASC
  56. ";
  57. $results = chado_query($sql, array(':feature_id' => $feature->feature_id));
  58. while ($protein = $results->fetchObject()) {
  59. if ($protein->residues) {
  60. $entity->{$field_name}['und'][$num_seqs++]['value'] = $protein->residues;
  61. }
  62. }
  63. }
  64. }