PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/sites/all/modules/custom/i5k_features/theme/templates/tripal_feature_sequence.tpl.php

https://gitlab.com/vijaya.tsavatapalli/drupal7
PHP | 194 lines | 115 code | 30 blank | 49 comment | 6 complexity | 62a4530ccb3ca21ab4cd8aa4296e2740 MD5 | raw file
  1. <?php
  2. /*
  3. * There are several ways that sequences can be displayed. They can come from the
  4. * feature.residues column, they can come from an alignment with another feature,
  5. * they can come from a protein sequence that has relationship with this sequence,
  6. * or they can come from sub children (e.g. CDS coding sequences).
  7. *
  8. * This template will show all types depending on the data available.
  9. *
  10. */
  11. $feature = $variables['node']->feature;
  12. $gene_var = array('gene', 'pseudogene');
  13. if(in_array($node->feature->feature_relationship->object_id[0]->object_id->type_id->name, $gene_var)) {
  14. $all_relationships = $feature->all_relationships;
  15. $object_rels = $all_relationships['object'];
  16. $subject_rels = $all_relationships['subject'];
  17. //VIJAYA - generating sequence as per new ppt
  18. if (count($object_rels) > 0 or count($subject_rels) > 0) { ?>
  19. <div class="tripal_feature-data-block-desc tripal-data-block-desc"></div> <?php
  20. // first add in the subject relationships.
  21. foreach ($subject_rels as $rel_type => $rels){
  22. foreach ($rels as $obj_type => $objects){
  23. // the $headers array is an array of fields to use as the colum headers.
  24. // additional documentation can be found here
  25. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  26. $headers = array('Name', 'Genome', 'Transcript', 'CDS', 'Protein');
  27. // the $rows array contains an array of rows where each row is an array
  28. // of values for each column of the table in that row. Additional documentation
  29. // can be found here:
  30. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  31. $rows = array();
  32. foreach ($objects as $object){
  33. // Below tripal function is used to get seqlen from featureloc relationship
  34. $obj_feature = chado_expand_var($object, 'table', 'featureloc');
  35. // Genomic sequence - nothing but co-ordinates sequence
  36. $genomic_link = "<a href='#' onclick=\"popup_message_display_popup(".$object->record->object_id->feature_id.", '".$object->record->object_id->type_id->name."', 680, 300);\">Genomic Fasta</a>";
  37. // cDNA sequence
  38. $type_id_cdna = CDNA_TYPE_ID; //'585';
  39. $cdna_args = array(':feature_id' => $object->record->subject_id->feature_id);
  40. $cdna_sql = "select * from chado.feature where uniquename=(select uniquename from chado.feature where feature_id=:feature_id) and type_id=".$type_id_cdna;
  41. $cdna_sequence = chado_query($cdna_sql, $cdna_args)->fetchObject();
  42. $cDNA_link = "-";
  43. if(!empty($cdna_sequence->residues))
  44. $cDNA_link = "<a href='#' onclick=\"popup_message_display_popup(".$object->record->subject_id->feature_id.", '".$object->record->subject_id->type_id->name."', 680, 300);\">cDNA Fasta</a>";
  45. // CDS sequence
  46. $type_id_cds = CDS_TYPE_ID; //'325';
  47. $cds_args = array(':feature_id' => $object->record->subject_id->feature_id, ':type_id_cds' => $type_id_cds);
  48. $cds_sql = "select f.feature_id, c.name, f.residues from chado.feature f, chado.cvterm c where f.uniquename=(select uniquename from chado.feature where feature_id=:feature_id) and f.type_id=c.cvterm_id and f.type_id=:type_id_cds";
  49. $cds_sequence = chado_query($cds_sql, $cds_args)->fetchObject();
  50. $cds_link = '-';
  51. if(!empty($cds_sequence->residues))
  52. $cds_link = "<a href='#' onclick=\"popup_message_display_popup(".$cds_sequence->subject_id.", '".$cds_sequence->name."', 680, 300);\">CDS Fasta</a>";
  53. // Polypeptide sequence
  54. $fid = $object->record->subject_id->feature_id;
  55. $pep_link = '-';
  56. $type_id_pep = PEP_TYPE_ID; //324;
  57. $query = db_query("select fr.subject_id, fr.object_id, fr.type_id, c.name as typename from chado.feature_relationship fr, chado.feature f, chado.featureloc fc, chado.cvterm c where f.feature_id=fr.subject_id and fc.feature_id=f.feature_id and f.type_id=c.cvterm_id and fr.object_id=:fid and c.cvterm_id=".$type_id_pep."", array(':fid' => $fid));
  58. foreach($query as $result) {
  59. $pep_link = "<a href='#' onclick=\"popup_message_display_popup(".$result->subject_id.", '".$result->typename."', 680, 300);\">Peptide Fasta</a>";
  60. }
  61. $rows[] = array(
  62. array('data' =>$object->record->subject_id->uniquename, 'width' => '30%'),
  63. $genomic_link,
  64. $cDNA_link,
  65. $cds_link,
  66. $pep_link
  67. );
  68. }
  69. // the $table array contains the headers and rows array as well as other
  70. // options for controlling the display of the table. Additional
  71. // documentation can be found here:
  72. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  73. $table = array(
  74. 'header' => $headers,
  75. 'rows' => $rows,
  76. 'attributes' => array(
  77. 'id' => 'tripal_feature-table-sequence-object',
  78. 'class' => 'tripal-data-table'
  79. ),
  80. 'sticky' => FALSE,
  81. 'caption' => '',
  82. 'colgroups' => array(),
  83. 'empty' => '',
  84. );
  85. // once we have our table array structure defined, we call Drupal's theme_table()
  86. // function to generate the table.
  87. print theme_table($table); ?>
  88. </p>
  89. <br><?php
  90. }
  91. }
  92. // second add in the object relationships.
  93. foreach ($object_rels as $rel_type => $rels){
  94. foreach ($rels as $subject_type => $subjects){
  95. // the $headers array is an array of fields to use as the colum headers.
  96. // additional documentation can be found here
  97. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  98. $headers = array('Name', 'Genome', 'Transcript', 'CDS', 'Protein');
  99. // the $rows array contains an array of rows where each row is an array
  100. // of values for each column of the table in that row. Additional documentation
  101. // can be found here:
  102. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  103. $rows = array();
  104. foreach ($subjects as $subject){
  105. // Below tripal function is used to get seqlen from featureloc relationship
  106. $obj_feature = chado_expand_var($subject, 'table', 'featureloc');
  107. //echo "<pre>"; print_r($subject);echo "</pre>";
  108. // Genomic sequence - nothing but co-ordinates sequence
  109. $genomic_link = "<a href='#' onclick=\"popup_message_display_popup(".$subject->record->object_id->feature_id.", '".$subject->record->object_id->type_id->name."', 680, 300, '0', '".$subject->record->object_id->featureloc->feature_id->strand."');\">Genomic Fasta</a>";
  110. // cDNA sequence
  111. $type_id_cdna = CDNA_TYPE_ID; //'585';
  112. $cdna_args = array(':feature_id' => $subject->record->subject_id->feature_id);
  113. $cdna_sql = "select * from chado.feature where uniquename=(select uniquename from chado.feature where feature_id=:feature_id) and type_id=".$type_id_cdna;
  114. $cdna_sequence = chado_query($cdna_sql, $cdna_args)->fetchObject();
  115. $cDNA_link = "-";
  116. if(!empty($cdna_sequence->residues))
  117. $cDNA_link = "<a href='#' onclick=\"popup_message_display_popup(".$subject->record->subject_id->feature_id.", '".$subject->record->subject_id->type_id->name."', 680, 300, '0', '".$subject->record->subject_id->featureloc->feature_id->strand."');\">cDNA Fasta</a>";
  118. // CDS sequence
  119. $type_id_cds = CDS_TYPE_ID; //'325';
  120. $cds_args = array(':feature_id' => $subject->record->subject_id->feature_id, ':type_id_cds' => $type_id_cds);
  121. $cds_sql = "select distinct fr.subject_id, c.name, f.feature_id, fc.strand, f.residues from chado.feature_relationship fr, chado.feature f, chado.featureloc fc, chado.cvterm c where f.feature_id=fr.subject_id and fc.feature_id=f.feature_id and f.type_id=c.cvterm_id and fr.object_id=:feature_id and cvterm_id=:type_id_cds";
  122. $cds_sequence = chado_query($cds_sql, $cds_args)->fetchObject();
  123. $cds_link = '-';
  124. if(!empty($cds_sequence->residues))
  125. $cds_link = "<a href='#' onclick=\"popup_message_display_popup(".$cds_sequence->feature_id.", '".$cds_sequence->name."', 680, 300, '1', '".$cds_sequence->strand."');\">CDS Fasta</a>";
  126. // Polypeptide sequence
  127. $fid = $subject->record->subject_id->feature_id;
  128. $pep_link = '-';
  129. $type_id_pep = PEP_TYPE_ID; //'324';
  130. $query = db_query("select fr.subject_id, fr.object_id, fr.type_id, c.name as typename, fc.strand from chado.feature_relationship fr, chado.feature f, chado.featureloc fc, chado.cvterm c where f.feature_id=fr.subject_id and fc.feature_id=f.feature_id and f.type_id=c.cvterm_id and fr.object_id=:fid and c.cvterm_id=".$type_id_pep." order by c.name", array(':fid' => $fid));
  131. foreach($query as $result) {
  132. $pep_link = "<a href='#' onclick=\"popup_message_display_popup(".$result->subject_id.", '".$result->typename."', 680, 300, '0', '".$result->strand."');\">Peptide Fasta</a>"; }
  133. $rows[] = array(
  134. array('data' =>$subject->record->subject_id->uniquename, 'width' => '30%'), $genomic_link,
  135. $cDNA_link,
  136. $cds_link,
  137. $pep_link
  138. );
  139. }
  140. // the $table array contains the headers and rows array as well as other
  141. // options for controlling the display of the table. Additional
  142. // documentation can be found here:
  143. // https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_table/7
  144. $table = array(
  145. 'header' => $headers,
  146. 'rows' => $rows,
  147. 'attributes' => array(
  148. 'id' => 'tripal_feature-table-sequence-subject',
  149. 'class' => 'tripal-data-table'
  150. ),
  151. 'sticky' => FALSE,
  152. 'caption' => '',
  153. 'colgroups' => array(),
  154. 'empty' => '',
  155. );
  156. // once we have our table array structure defined, we call Drupal's theme_table()
  157. // function to generate the table.
  158. print theme_table($table); ?>
  159. </p>
  160. <br><?php
  161. }
  162. }
  163. }
  164. } // if condition close - checkong the if condition for gene and pseudogene