so__cds.inc 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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::load()
  39. */
  40. public function load($entity) {
  41. $field_name = $this->field['field_name'];
  42. $feature = $entity->chado_record;
  43. $num_seqs = 0;
  44. // Set some defauls for the empty record
  45. $entity->{$field_name}['und'][0] = array(
  46. 'value' => '',
  47. );
  48. $options = array(
  49. 'return_array' => TRUE,
  50. 'order_by' => array('rank' => 'ASC'),
  51. );
  52. $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
  53. $featurelocs = $feature->featureloc->feature_id;
  54. foreach($featurelocs as $featureloc){
  55. // Generate a CDS sequence if one exsits for this feature alignment.
  56. $cds_sequence = tripal_get_feature_sequences(
  57. array(
  58. 'feature_id' => $feature->feature_id,
  59. 'parent_id' => $featureloc->srcfeature_id->feature_id,
  60. 'name' => $feature->name,
  61. 'featureloc_id' => $featureloc->featureloc_id,
  62. ),
  63. array(
  64. // CDS are in parent-child relationships so we want to use the
  65. // sequence from the parent
  66. 'derive_from_parent' => 1,
  67. // we want to combine all CDS for this feature into a single sequence
  68. 'aggregate' => 1,
  69. // we're looking for CDS features
  70. 'sub_feature_types' => array('CDS'),
  71. 'is_html' => 0
  72. )
  73. );
  74. if (count($cds_sequence) > 0) {
  75. // the tripal_get_feature_sequences() function can return multiple sequences
  76. // if a feature is aligned to multiple places. In the case of CDSs we expect
  77. // that one mRNA is only aligned to a single location on the assembly so we
  78. // can access the CDS sequence with index 0.
  79. if ($cds_sequence[0]['residues']) {
  80. $entity->{$field_name}['und'][$num_seqs++]['value'] = $cds_sequence[0]['residues'];
  81. }
  82. }
  83. }
  84. }
  85. }