so__transcript.inc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. class so__transcript 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:0000673';
  16. // The default lable for this field.
  17. public static $label = 'Transcripts';
  18. // The default description for this field.
  19. public static $description = 'An RNA synthesized on a DNA or RNA template by an RNA polymerase.';
  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__transcript_widget';
  38. // The default formatter for this field.
  39. public static $default_formatter = 'so__transcript_formatter';
  40. // --------------------------------------------------------------------------
  41. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  42. // --------------------------------------------------------------------------
  43. // An array containing details about the field. The format of this array
  44. // is the same as that returned by field_info_fields()
  45. protected $field;
  46. // An array containing details about an instance of the field. A field does
  47. // not have to have an instance. But if dealing with an instance (such as
  48. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  49. protected $instance;
  50. /**
  51. *
  52. * @see TripalField::validate()
  53. */
  54. public function validate($entity_type, $entity, $field, $items, &$errors) {
  55. }
  56. /**
  57. *
  58. * @see TripalField::load()
  59. */
  60. public function load($entity, $details = array()) {
  61. $record = $details['record'];
  62. $field_name = $this->field['field_name'];
  63. $field_type = $this->field['type'];
  64. $field_table = $this->field['settings']['chado_table'];
  65. $field_column = $this->field['settings']['chado_column'];
  66. // Set some defaults for the empty record.
  67. $entity->{$field_name}['und'][0] = array(
  68. 'value' => array(
  69. 'type' => '',
  70. 'name' => '',
  71. 'identifier' => '',
  72. 'location' => '',
  73. ),
  74. );
  75. // Get the mRNA features for this gene.
  76. $sql = "
  77. SELECT FS.name, FS.uniquename, FS.feature_id, FCVT.name as type
  78. FROM {feature_relationship} FR
  79. INNER JOIN {feature} FS on FS.feature_id = FR.subject_id
  80. INNER JOIN {cvterm} FCVT on FCVT.cvterm_id = FS.type_id
  81. INNER JOIN {cv} CV on CV.cv_id = FCVT.cv_id
  82. WHERE
  83. FR.object_id = :feature_id and
  84. FCVT.name = 'mRNA' and
  85. CV.name = 'sequence'
  86. ";
  87. $results = chado_query($sql, array(':feature_id' => $record->feature_id));
  88. $i = 0;
  89. while ($transcript = $results->fetchObject()) {
  90. // Get the location of this mRNA.
  91. $sql = "
  92. SELECT FL.*, F.name as srcfeature_name
  93. FROM {featureloc} FL
  94. INNER JOIN {feature} F on F.feature_id = FL.srcfeature_id
  95. WHERE FL.feature_id = :object_id
  96. ";
  97. $floc_results = chado_query($sql, array(':object_id' => $transcript->feature_id));
  98. $loc = "";
  99. while ($location = $floc_results->fetchObject()) {
  100. $loc .= $location->srcfeature_name . ":" . $location->fmin . ".." . $location->fmax;
  101. }
  102. $entity->{$field_name}['und'][$i]['value'] = array(
  103. 'type' => $transcript->type,
  104. 'name' => $transcript->name,
  105. 'identifier' => $transcript->uniquename,
  106. 'location' => $loc,
  107. );
  108. $entity_id = tripal_get_chado_entity_id($field_table, $record->feature_id);
  109. if ($entity_id) {
  110. $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $entity_id;
  111. }
  112. $i++;
  113. }
  114. }
  115. }