so__transcript.inc 5.2 KB

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