so__transcript.inc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. class so__transcript 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 label for this field.
  11. public static $default_label = 'Transcripts';
  12. // The default description for this field.
  13. public static $description = 'An RNA synthesized on a DNA or RNA template by an RNA polymerase.';
  14. // Provide a list of instance specific settings. These can be accessed within
  15. // the instanceSettingsForm. When the instanceSettingsForm is submitted
  16. // then Drupal will automatically change these settings for the instance.
  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 = [
  22. // The short name for the vocabulary (e.g. schema, SO, GO, PATO, etc.).
  23. 'term_vocabulary' => 'SO',
  24. // The name of the term.
  25. 'term_name' => 'transcript',
  26. // The unique ID (i.e. accession) of the term.
  27. 'term_accession' => '0000673',
  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__transcript_widget';
  35. // The default formatter for this field.
  36. public static $default_formatter = 'so__transcript_formatter';
  37. // --------------------------------------------------------------------------
  38. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  39. // --------------------------------------------------------------------------
  40. // An array containing details about the field. The format of this array
  41. // is the same as that returned by field_info_fields()
  42. protected $field;
  43. // An array containing details about an instance of the field. A field does
  44. // not have to have an instance. But if dealing with an instance (such as
  45. // when using the widgetForm, formatterSettingsForm, etc.) it should be set.
  46. protected $instance;
  47. /**
  48. * @see TripalField::elementInfo()
  49. */
  50. public function elementInfo() {
  51. $field_term = $this->getFieldTermID();
  52. return [
  53. $field_term => [
  54. 'operations' => [],
  55. 'sortable' => FALSE,
  56. 'searchable' => FALSE,
  57. 'type' => 'xs:complexType',
  58. 'readonly' => TRUE,
  59. 'elements' => [
  60. 'rdfs:type' => [
  61. 'name' => 'transcript_type',
  62. 'label' => 'Transcript Type',
  63. 'help' => 'The type of a transcript.',
  64. 'searchable' => FALSE,
  65. 'operations' => ['eq', 'ne', 'contains', 'starts'],
  66. 'sortable' => FALSE,
  67. 'type' => 'xs:string',
  68. 'readonly' => TRUE,
  69. 'required' => FALSE,
  70. ],
  71. 'schema:name' => [
  72. 'name' => 'transcript_name',
  73. 'label' => 'Transcript Name',
  74. 'help' => 'The name of a transcript.',
  75. 'searchable' => FALSE,
  76. 'operations' => ['eq', 'ne', 'contains', 'starts'],
  77. 'sortable' => FALSE,
  78. 'type' => 'xs:string',
  79. 'readonly' => TRUE,
  80. 'required' => FALSE,
  81. ],
  82. 'data:0842' => [
  83. 'name' => 'transcript_uniquename',
  84. 'label' => 'Transcript Identifier',
  85. 'help' => 'The unique identifier of a transcript.',
  86. 'searchable' => FALSE,
  87. 'operations' => ['eq', 'ne', 'contains', 'starts'],
  88. 'sortable' => FALSE,
  89. 'type' => 'xs:string',
  90. 'readonly' => TRUE,
  91. 'required' => FALSE,
  92. ],
  93. 'SO:0000735' => [
  94. 'name' => 'loc',
  95. 'label' => 'Transcript Location',
  96. 'help' => 'The location of the transcript on a reference feature.',
  97. 'searchable' => FALSE,
  98. 'operations' => ['eq', 'ne', 'contains', 'starts'],
  99. 'sortable' => FALSE,
  100. 'type' => 'xs:string',
  101. 'readonly' => TRUE,
  102. 'required' => FALSE,
  103. ],
  104. 'entity' => [
  105. 'searchable' => FALSE,
  106. 'sortable' => FALSE,
  107. ],
  108. ],
  109. ],
  110. ];
  111. }
  112. /**
  113. *
  114. * @see TripalField::load()
  115. */
  116. public function load($entity) {
  117. $record = $entity->chado_record;
  118. $field_name = $this->field['field_name'];
  119. $field_type = $this->field['type'];
  120. $field_table = $this->instance['settings']['chado_table'];
  121. $field_column = $this->instance['settings']['chado_column'];
  122. // Set some defaults for the empty record.
  123. $entity->{$field_name}['und'][0] = [
  124. 'value' => '',
  125. ];
  126. if (!$record) {
  127. return;
  128. }
  129. // Get the mRNA features for this gene.
  130. $sql = "
  131. SELECT FS.name, FS.uniquename, FS.feature_id, FCVT.name as type
  132. FROM {feature_relationship} FR
  133. INNER JOIN {feature} FS on FS.feature_id = FR.subject_id
  134. INNER JOIN {cvterm} FCVT on FCVT.cvterm_id = FS.type_id
  135. INNER JOIN {cv} CV on CV.cv_id = FCVT.cv_id
  136. WHERE
  137. FR.object_id = :feature_id and
  138. FCVT.name = 'mRNA' and
  139. CV.name = 'sequence'
  140. ";
  141. $results = chado_query($sql, [':feature_id' => $record->feature_id]);
  142. $i = 0;
  143. while ($transcript = $results->fetchObject()) {
  144. // Get the location of this mRNA.
  145. $sql = "
  146. SELECT FL.*, F.name as srcfeature_name
  147. FROM {featureloc} FL
  148. INNER JOIN {feature} F on F.feature_id = FL.srcfeature_id
  149. WHERE FL.feature_id = :object_id
  150. ";
  151. $floc_results = chado_query($sql, [':object_id' => $transcript->feature_id]);
  152. $loc = "";
  153. while ($location = $floc_results->fetchObject()) {
  154. $loc .= $location->srcfeature_name . ":" . $location->fmin . ".." . $location->fmax;
  155. }
  156. $entity->{$field_name}['und'][$i]['value'] = [
  157. 'rdfs:type' => $transcript->type,
  158. 'schema:name' => $transcript->name,
  159. 'data:0842' => $transcript->uniquename,
  160. 'SO:0000735' => $loc,
  161. ];
  162. $feature = chado_generate_var('feature', ['feature_id' => $transcript->feature_id]);
  163. if (property_exists($feature, 'entity_id')) {
  164. $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $feature->entity_id;
  165. }
  166. $i++;
  167. }
  168. }
  169. }