so__transcript.inc 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. *
  49. * @see TripalField::load()
  50. */
  51. public function load($entity, $details = array()) {
  52. $record = $details['record'];
  53. $field_name = $this->field['field_name'];
  54. $field_type = $this->field['type'];
  55. $field_table = $this->instance['settings']['chado_table'];
  56. $field_column = $this->instance['settings']['chado_column'];
  57. // Set some defaults for the empty record.
  58. $entity->{$field_name}['und'][0] = array(
  59. 'value' => array(
  60. 'rdfs:type' => '',
  61. 'schema:name' => '',
  62. // Identifier
  63. 'data:0842' => '',
  64. // sequence location
  65. 'SO:0000735' => '',
  66. ),
  67. );
  68. // Get the mRNA features for this gene.
  69. $sql = "
  70. SELECT FS.name, FS.uniquename, FS.feature_id, FCVT.name as type
  71. FROM {feature_relationship} FR
  72. INNER JOIN {feature} FS on FS.feature_id = FR.subject_id
  73. INNER JOIN {cvterm} FCVT on FCVT.cvterm_id = FS.type_id
  74. INNER JOIN {cv} CV on CV.cv_id = FCVT.cv_id
  75. WHERE
  76. FR.object_id = :feature_id and
  77. FCVT.name = 'mRNA' and
  78. CV.name = 'sequence'
  79. ";
  80. $results = chado_query($sql, array(':feature_id' => $record->feature_id));
  81. $i = 0;
  82. while ($transcript = $results->fetchObject()) {
  83. // Get the location of this mRNA.
  84. $sql = "
  85. SELECT FL.*, F.name as srcfeature_name
  86. FROM {featureloc} FL
  87. INNER JOIN {feature} F on F.feature_id = FL.srcfeature_id
  88. WHERE FL.feature_id = :object_id
  89. ";
  90. $floc_results = chado_query($sql, array(':object_id' => $transcript->feature_id));
  91. $loc = "";
  92. while ($location = $floc_results->fetchObject()) {
  93. $loc .= $location->srcfeature_name . ":" . $location->fmin . ".." . $location->fmax;
  94. }
  95. $entity->{$field_name}['und'][$i]['value'] = array(
  96. 'rdfs:type' => $transcript->type,
  97. 'schema:name' => $transcript->name,
  98. 'data:0842' => $transcript->uniquename,
  99. 'SO:0000735' => $loc,
  100. );
  101. $entity_id = tripal_get_chado_entity_id($field_table, $record->feature_id);
  102. if ($entity_id) {
  103. $entity->{$field_name}['und'][$i]['value']['entity'] = 'TripalEntity:' . $entity_id;
  104. }
  105. $i++;
  106. }
  107. }
  108. }