so__cds.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 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 global settings. These can be accessed witihn the
  15. // globalSettingsForm. When the globalSettingsForm is submitted then
  16. // Drupal will automatically change these settings for all fields.
  17. public static $default_settings = array(
  18. 'chado_table' => '',
  19. 'chado_column' => '',
  20. 'base_table' => '',
  21. );
  22. // Provide a list of instance specific settings. These can be access within
  23. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  24. // then Drupal with automatically change these settings for the instnace.
  25. // It is recommended to put settings at the instance level whenever possible.
  26. // If you override this variable in a child class be sure to replicate the
  27. // term_name, term_vocab, term_accession and term_fixed keys as these are
  28. // required for all TripalFields.
  29. public static $default_instance_settings = array(
  30. // The short name for the vocabulary (e.g. shcema, SO, GO, PATO, etc.).
  31. 'term_vocabulary' => 'SO',
  32. // The name of the term.
  33. 'term_name' => 'CDS',
  34. // The unique ID (i.e. accession) of the term.
  35. 'term_accession' => '0000316',
  36. // Set to TRUE if the site admin is allowed to change the term
  37. // type. This will create form elements when editing the field instance
  38. // to allow the site admin to change the term settings above.
  39. 'term_fixed' => TRUE,
  40. );
  41. // Set this to the name of the storage backend that by default will support
  42. // this field.
  43. public static $storage = 'field_chado_storage';
  44. // The default widget for this field.
  45. public static $default_widget = 'so__cds_widget';
  46. // The default formatter for this field.
  47. public static $default_formatter = 'so__cds_formatter';
  48. /**
  49. * @see TripalField::load()
  50. */
  51. public function load($entity, $details = array()) {
  52. $field_name = $this->field['field_name'];
  53. $feature = $details['record'];
  54. $num_seqs = 0;
  55. $feature = chado_expand_var($feature, 'table', 'featureloc', $options);
  56. $featureloc_sequences = chado_get_featureloc_sequences($feature->feature_id, $feature->featureloc->feature_id);
  57. foreach($featureloc_sequences as $src => $attrs){
  58. // Generate a CDS sequence if one exsits for this feature alignment.
  59. $cds_sequence = tripal_get_feature_sequences(
  60. array(
  61. 'feature_id' => $feature->feature_id,
  62. 'parent_id' => $attrs['featureloc']->srcfeature_id->feature_id,
  63. 'name' => $feature->name,
  64. 'featureloc_id' => $attrs['featureloc']->featureloc_id,
  65. ),
  66. array(
  67. // CDS are in parent-child relationships so we want to use the
  68. // sequence from the parent
  69. 'derive_from_parent' => 1,
  70. // we want to combine all CDS for this feature into a single sequence
  71. 'aggregate' => 1,
  72. // we're looking for CDS features
  73. 'sub_feature_types' => array('CDS'),
  74. 'is_html' => 0
  75. )
  76. );
  77. if (count($cds_sequence) > 0) {
  78. $defline = tripal_get_fasta_defline($feature, '', $attrs['featureloc'], 'CDS', strlen($attrs['residues']));
  79. // the tripal_get_feature_sequences() function can return multiple sequences
  80. // if a feature is aligned to multiple places. In the case of CDSs we expect
  81. // that one mRNA is only aligned to a single location on the assembly so we
  82. // can access the CDS sequence with index 0.
  83. if ($cds_sequence[0]['residues']) {
  84. $entity->{$field_name}['und'][$num_seqs++]['value'] = $defline . "\n" . $cds_sequence[0]['residues'];
  85. }
  86. }
  87. }
  88. }
  89. }