so__cds.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. class so__cds 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 = 'Coding Sequence';
  12. // The default description for this field.
  13. public static $description = 'A contiguous sequence which begins with, and includes, a start codon and ends with, and includes, a stop codon.';
  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' => 'SO',
  24. // The name of the term.
  25. 'term_name' => 'CDS',
  26. // The unique ID (i.e. accession) of the term.
  27. 'term_accession' => '0000316',
  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 = 'so__cds_widget';
  35. // The default formatter for this field.
  36. public static $default_formatter = 'so__cds_formatter';
  37. /**
  38. * @see TripalField::elementInfo()
  39. */
  40. public function elementInfo() {
  41. $field_term = $this->getFieldTermID();
  42. return array(
  43. $field_term => array(
  44. 'sortable' => FALSE,
  45. 'searchable' => FALSE,
  46. 'type' => 'xs:string',
  47. 'readonly' => TRUE,
  48. ),
  49. );
  50. }
  51. /**
  52. * @see TripalField::load()
  53. */
  54. public function load($entity) {
  55. $field_name = $this->field['field_name'];
  56. $feature = $entity->chado_record;
  57. $num_seqs = 0;
  58. // Set some defauls for the empty record
  59. $entity->{$field_name}['und'][0] = array(
  60. 'value' => '',
  61. );
  62. $options = array(
  63. 'return_array' => TRUE,
  64. 'order_by' => array('rank' => 'ASC'),
  65. );
  66. $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
  67. $featurelocs = $feature->featureloc->feature_id;
  68. // Verify that we have featurelocs before entering the loop
  69. if(!is_array($featurelocs)) {
  70. return;
  71. }
  72. foreach($featurelocs as $featureloc){
  73. // Generate a CDS sequence if one exsits for this feature alignment.
  74. $cds_sequence = chado_get_feature_sequences(
  75. array(
  76. 'feature_id' => $feature->feature_id,
  77. 'parent_id' => $featureloc->srcfeature_id->feature_id,
  78. 'name' => $feature->name,
  79. 'featureloc_id' => $featureloc->featureloc_id,
  80. ),
  81. array(
  82. // CDS are in parent-child relationships so we want to use the
  83. // sequence from the parent
  84. 'derive_from_parent' => 1,
  85. // we want to combine all CDS for this feature into a single sequence
  86. 'aggregate' => 1,
  87. // we're looking for CDS features
  88. 'sub_feature_types' => array('CDS'),
  89. 'is_html' => 0
  90. )
  91. );
  92. if (count($cds_sequence) > 0) {
  93. // the chado_get_feature_sequences() function can return multiple sequences
  94. // if a feature is aligned to multiple places. In the case of CDSs we expect
  95. // that one mRNA is only aligned to a single location on the assembly so we
  96. // can access the CDS sequence with index 0.
  97. if ($cds_sequence[0]['residues']) {
  98. $entity->{$field_name}['und'][$num_seqs++]['value'] = $cds_sequence[0]['residues'];
  99. }
  100. }
  101. }
  102. }
  103. }