so__transcript.inc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 lable 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 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' => '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 array(
  53. $field_term => array(
  54. 'operations' => array(),
  55. 'sortable' => FALSE,
  56. 'searchable' => FALSE,
  57. 'elements' => array(
  58. 'rdfs:type' => array(
  59. 'name' => 'transcript_type',
  60. 'label' => 'Transcript Type',
  61. 'help' => 'The type of a transcript.',
  62. 'searchable' => FALSE,
  63. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  64. 'sortable' => FALSE,
  65. ),
  66. 'schema:name' => array(
  67. 'name' => 'transcript_name',
  68. 'label' => 'Transcript Name',
  69. 'help' => 'The name of a transcript.',
  70. 'searchable' => FALSE,
  71. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  72. 'sortable' => FALSE,
  73. ),
  74. 'data:0842' => array(
  75. 'name' => 'transcript_uniquename',
  76. 'label' => 'Transcript Identifier',
  77. 'help' => 'The unique identifier of a transcript.',
  78. 'searchable' => FALSE,
  79. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  80. 'sortable' => FALSE,
  81. ),
  82. 'SO:0000735' => array(
  83. 'name' => 'loc',
  84. 'label' => 'Transcript Location',
  85. 'help' => 'The location of the transcript on a reference feature.',
  86. 'searchable' => FALSE,
  87. 'operations' => array('eq', 'ne', 'contains', 'starts'),
  88. 'sortable' => FALSE,
  89. ),
  90. 'entity' => array(
  91. 'searchable' => FALSE,
  92. 'sortable' => FALSE,
  93. ),
  94. ),
  95. ),
  96. );
  97. }
  98. /**
  99. *
  100. * @see TripalField::load()
  101. */
  102. public function load($entity) {
  103. $record = $entity->chado_record;
  104. $field_name = $this->field['field_name'];
  105. $field_type = $this->field['type'];
  106. $field_table = $this->instance['settings']['chado_table'];
  107. $field_column = $this->instance['settings']['chado_column'];
  108. // Set some defaults for the empty record.
  109. $entity->{$field_name}['und'][0] = array(
  110. 'value' => array(
  111. 'rdfs:type' => '',
  112. 'schema:name' => '',
  113. // Identifier
  114. 'data:0842' => '',
  115. // sequence location
  116. 'SO:0000735' => '',
  117. ),
  118. );
  119. // Get the mRNA features for this gene.
  120. $sql = "
  121. SELECT FS.name, FS.uniquename, FS.feature_id, FCVT.name as type
  122. FROM {feature_relationship} FR
  123. INNER JOIN {feature} FS on FS.feature_id = FR.subject_id
  124. INNER JOIN {cvterm} FCVT on FCVT.cvterm_id = FS.type_id
  125. INNER JOIN {cv} CV on CV.cv_id = FCVT.cv_id
  126. WHERE
  127. FR.object_id = :feature_id and
  128. FCVT.name = 'mRNA' and
  129. CV.name = 'sequence'
  130. ";
  131. $results = chado_query($sql, array(':feature_id' => $record->feature_id));
  132. $i = 0;
  133. while ($transcript = $results->fetchObject()) {
  134. // Get the location of this mRNA.
  135. $sql = "
  136. SELECT FL.*, F.name as srcfeature_name
  137. FROM {featureloc} FL
  138. INNER JOIN {feature} F on F.feature_id = FL.srcfeature_id
  139. WHERE FL.feature_id = :object_id
  140. ";
  141. $floc_results = chado_query($sql, array(':object_id' => $transcript->feature_id));
  142. $loc = "";
  143. while ($location = $floc_results->fetchObject()) {
  144. $loc .= $location->srcfeature_name . ":" . $location->fmin . ".." . $location->fmax;
  145. }
  146. $entity->{$field_name}['und'][$i]['value'] = array(
  147. 'rdfs:type' => $transcript->type,
  148. 'schema:name' => $transcript->name,
  149. 'data:0842' => $transcript->uniquename,
  150. 'SO:0000735' => $loc,
  151. );
  152. $entity_id = chado_get_record_entity_by_bundle($entity->bundle, $record_id);
  153. if ($entity_id) {
  154. $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $entity_id;
  155. }
  156. $i++;
  157. }
  158. }
  159. }