so__cds.inc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. class so__cds 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 term that this field maps to. The format for the term should be:
  11. // [vocab]:[accession] where [vocab] is the short name of the vocabulary
  12. // and [acession] is the unique accession number for the term. This term
  13. // must already exist in the vocabulary storage backend. This
  14. // value should never be changed once fields exist for this type.
  15. public static $term = 'SO:0000316';
  16. // The default lable for this field.
  17. public static $label = 'Coding Sequence';
  18. // The default description for this field.
  19. public static $description = 'A contiguous sequence which begins with, and includes, a start codon and ends with, and includes, a stop codon.';
  20. // Provide a list of global settings. These can be accessed witihn the
  21. // globalSettingsForm. When the globalSettingsForm is submitted then
  22. // Drupal will automatically change these settings for all fields.
  23. public static $settings = array(
  24. 'chado_table' => '',
  25. 'chado_column' => '',
  26. 'base_table' => '',
  27. );
  28. // Provide a list of instance specific settings. These can be access within
  29. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  30. // then Drupal with automatically change these settings for the instnace.
  31. // It is recommended to put settings at the instance level whenever possible.
  32. public static $instance_settings = array();
  33. // Set this to the name of the storage backend that by default will support
  34. // this field.
  35. public static $storage = 'tripal_no_storage';
  36. // The default widget for this field.
  37. public static $default_widget = 'so__cds_widget';
  38. // The default formatter for this field.
  39. public static $default_formatter = 'so__cds_formatter';
  40. /**
  41. * @see TripalField::load()
  42. */
  43. public function load($entity, $details = array()) {
  44. $field_name = $this->field['field_name'];
  45. $feature = $details['record'];
  46. $num_seqs = 0;
  47. $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
  48. $featureloc_sequences = chado_get_featureloc_sequences($feature->feature_id, $feature->featureloc->feature_id);
  49. foreach($featureloc_sequences as $src => $attrs){
  50. // Generate a CDS sequence if one exsits for this feature alignment.
  51. $cds_sequence = tripal_get_feature_sequences(
  52. array(
  53. 'feature_id' => $feature->feature_id,
  54. 'parent_id' => $attrs['featureloc']->srcfeature_id->feature_id,
  55. 'name' => $feature->name,
  56. 'featureloc_id' => $attrs['featureloc']->featureloc_id,
  57. ),
  58. array(
  59. // CDS are in parent-child relationships so we want to use the
  60. // sequence from the parent
  61. 'derive_from_parent' => 1,
  62. // we want to combine all CDS for this feature into a single sequence
  63. 'aggregate' => 1,
  64. // we're looking for CDS features
  65. 'sub_feature_types' => array('CDS'),
  66. 'is_html' => 0
  67. )
  68. );
  69. if (count($cds_sequence) > 0) {
  70. $defline = tripal_get_fasta_defline($feature, '', $attrs['featureloc'], 'CDS', strlen($attrs['residues']));
  71. // the tripal_get_feature_sequences() function can return multiple sequences
  72. // if a feature is aligned to multiple places. In the case of CDSs we expect
  73. // that one mRNA is only aligned to a single location on the assembly so we
  74. // can access the CDS sequence with index 0.
  75. if ($cds_sequence[0]['residues']) {
  76. $entity->{$field_name}['und'][$num_seqs++]['value'] = $defline . "\n" . $cds_sequence[0]['residues'];
  77. }
  78. }
  79. }
  80. }
  81. }