data__protein_sequence.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 = [
  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. // Indicates the download formats for this field. The list must be the
  34. // name of a child class of the TripalFieldDownloader.
  35. public static $download_formatters = [
  36. 'TripalTabDownloader',
  37. 'TripalCSVDownloader',
  38. 'TripalProteinFASTADownloader',
  39. ];
  40. // The default widget for this field.
  41. public static $default_widget = 'data__protein_sequence_widget';
  42. // The default formatter for this field.
  43. public static $default_formatter = 'data__protein_sequence_formatter';
  44. /**
  45. * @see TripalField::elementInfo()
  46. */
  47. public function elementInfo() {
  48. $field_term = $this->getFieldTermID();
  49. $info = [
  50. $field_term => [
  51. 'label' => 'Protein sequence',
  52. 'help' => 'The polypeptide sequence derived from mRNA',
  53. 'sortable' => FALSE,
  54. 'searchable' => FALSE,
  55. 'type' => 'xs:string',
  56. 'readonly' => FALSE,
  57. ],
  58. ];
  59. return $info;
  60. }
  61. /**
  62. * @see TripalField::load()
  63. */
  64. public function load($entity) {
  65. $field_name = $this->field['field_name'];
  66. $feature = $entity->chado_record;
  67. $num_seqs = 0;
  68. // Set some defauls for the empty record
  69. $entity->{$field_name}['und'][0] = [
  70. 'value' => '',
  71. ];
  72. // Look for protein sequences based on the relationship of this field.
  73. $sql = "
  74. SELECT F.*
  75. FROM {feature_relationship} FR
  76. INNER JOIN {feature} F on FR.subject_id = F.feature_id
  77. INNER JOIN {cvterm} CVT on CVT.cvterm_id = F.type_id
  78. INNER JOIN {cvterm} RCVT on RCVT.cvterm_id = FR.type_id
  79. WHERE
  80. FR.object_id = :feature_id and
  81. CVT.name = 'polypeptide' and
  82. RCVT.name = 'derives_from'
  83. ORDER BY FR.rank ASC
  84. ";
  85. $proteins = chado_query($sql, [':feature_id' => $feature->feature_id]);
  86. while ($protein = $proteins->fetchObject()) {
  87. $entity->{$field_name}['und'][$num_seqs]['value'] = $protein->residues;
  88. // Because we'll be saving a feature we need to maintain all of it's
  89. // columns in the feature table. The following will add them all.
  90. $columns = get_object_vars($protein);
  91. foreach ($columns as $colname => $value) {
  92. $entity->{$field_name}['und'][$num_seqs]['chado-feature__' . $colname] = $value;
  93. }
  94. $num_seqs++;
  95. }
  96. }
  97. }