so__cds.inc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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, $details = array()) {
  41. $field_name = $this->field['field_name'];
  42. $feature = $details['record'];
  43. $num_seqs = 0;
  44. $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
  45. $featureloc_sequences = chado_get_featureloc_sequences($feature->feature_id, $feature->featureloc->feature_id);
  46. foreach($featureloc_sequences as $src => $attrs){
  47. // Generate a CDS sequence if one exsits for this feature alignment.
  48. $cds_sequence = tripal_get_feature_sequences(
  49. array(
  50. 'feature_id' => $feature->feature_id,
  51. 'parent_id' => $attrs['featureloc']->srcfeature_id->feature_id,
  52. 'name' => $feature->name,
  53. 'featureloc_id' => $attrs['featureloc']->featureloc_id,
  54. ),
  55. array(
  56. // CDS are in parent-child relationships so we want to use the
  57. // sequence from the parent
  58. 'derive_from_parent' => 1,
  59. // we want to combine all CDS for this feature into a single sequence
  60. 'aggregate' => 1,
  61. // we're looking for CDS features
  62. 'sub_feature_types' => array('CDS'),
  63. 'is_html' => 0
  64. )
  65. );
  66. if (count($cds_sequence) > 0) {
  67. $defline = tripal_get_fasta_defline($feature, '', $attrs['featureloc'], 'CDS', strlen($attrs['residues']));
  68. // the tripal_get_feature_sequences() function can return multiple sequences
  69. // if a feature is aligned to multiple places. In the case of CDSs we expect
  70. // that one mRNA is only aligned to a single location on the assembly so we
  71. // can access the CDS sequence with index 0.
  72. if ($cds_sequence[0]['residues']) {
  73. $entity->{$field_name}['und'][$num_seqs++]['value'] = $defline . "\n" . $cds_sequence[0]['residues'];
  74. }
  75. }
  76. }
  77. }
  78. }