so__transcript.inc 6.0 KB

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