seq_extract.inc 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /*
  3. *
  4. */
  5. function tripal_feature_seq_extract_page() {
  6. // generate the search form
  7. $form = drupal_get_form('tripal_feature_seq_extract_form');
  8. $output .= $form;
  9. return $output;
  10. }
  11. /*
  12. *
  13. */
  14. function theme_tripal_feature_seq_extract_form($form) {
  15. $rows = array();
  16. $rows[] = array(
  17. drupal_render($form['genus']),
  18. drupal_render($form['species']) ,
  19. drupal_render($form['ftypes']) ,
  20. );
  21. $rows[] = array(
  22. drupal_render($form['analysis']) ,
  23. drupal_render($form['upstream']) ,
  24. drupal_render($form['downstream']) ,
  25. );
  26. $rows[] = array(
  27. drupal_render($form['format']),
  28. array(
  29. 'data' => drupal_render($form['fname']),
  30. 'colspan' => 2,
  31. ),
  32. );
  33. $rows[] = array(
  34. array(
  35. 'data' => drupal_render($form['advanced']),
  36. 'colspan' => 3,
  37. ),
  38. );
  39. $rows[] = array(
  40. array(
  41. 'data' => drupal_render($form['retrieve_btn']),
  42. 'colspan' => 3,
  43. ),
  44. );
  45. $headers = array();
  46. $table = theme('table', $headers, $rows, array('id' => 'tripal-feature-seq-extract-form-table', 'border' => '0'));
  47. $markup = $table;
  48. $form['criteria'] = array(
  49. '#type' => 'markup',
  50. '#value' => $markup,
  51. '#weight' => -10,
  52. );
  53. return drupal_render($form);
  54. }
  55. /**
  56. *
  57. */
  58. function tripal_feature_seq_extract_form(&$form_state = NULL) {
  59. tripal_core_ahah_init_form();
  60. // get defaults
  61. $dgenus = $form_state['values']['genus'];
  62. $dspecies = $form_state['values']['species'];
  63. $danalysis = $form_state['values']['analysis'];
  64. $dftypes = $form_state['values']['ftypes'];
  65. $dfname = $form_state['values']['fname'];
  66. $dupstream = $form_state['values']['upstream'];
  67. $ddownstream = $form_state['values']['downstream'];
  68. $dformat = $form_state['values']['format'] ? $form_state['values']['format'] : 'fasta_txt';
  69. $duse_parent = $form_state['values']['use_parent'];
  70. $aggregate = $form_state['values']['aggregate'];
  71. $dagg_types = $form_state['values']['agg_types'];
  72. $sql = "
  73. SELECT DISTINCT genus
  74. FROM {organism}
  75. ORDER BY genus
  76. ";
  77. $results = chado_query($sql);
  78. $genus = array();
  79. $genus[] = '';
  80. while ($organism = db_fetch_object($results)) {
  81. $genus[$organism->genus] = $organism->genus;
  82. }
  83. $form['genus'] = array(
  84. '#title' => t('Genus'),
  85. '#type' => 'select',
  86. '#options' => $genus,
  87. '#default_value' => $dgenus,
  88. '#multiple' => FALSE,
  89. '#description' => t('The organism\'s genus. If specified, features for all organism with this genus will be retrieved.'),
  90. '#ahah' => array(
  91. 'path' => 'seq_extract/set_genus',
  92. 'wrapper' => 'tripal-feature-seq-extract-form-table',
  93. 'event' => 'change',
  94. 'method' => 'replace',
  95. ),
  96. );
  97. $species = array();
  98. if ($dgenus) {
  99. $sql = "
  100. SELECT DISTINCT species
  101. FROM {organism}
  102. WHERE genus = '%s'
  103. ORDER BY species
  104. ";
  105. $results = chado_query($sql, $dgenus);
  106. $species[] = '';
  107. while ($organism = db_fetch_object($results)) {
  108. $species[$organism->species] = $organism->species;
  109. }
  110. }
  111. $form['species'] = array(
  112. '#title' => t('Species'),
  113. '#type' => 'select',
  114. '#options' => $species,
  115. '#default_value' => $dspecies,
  116. '#multiple' => FALSE,
  117. '#description' => t('The organism\'s species name. If specified, features for all organisms with this species will be retrieved. Please first select a genus'),
  118. '#ahah' => array(
  119. 'path' => 'seq_extract/set_species',
  120. 'wrapper' => 'tripal-feature-seq-extract-form-table',
  121. 'event' => 'change',
  122. 'method' => 'replace',
  123. ),
  124. );
  125. $analyses = array();
  126. $args = array();
  127. $sql = "
  128. SELECT DISTINCT A.analysis_id, A.name
  129. FROM {analysis} A
  130. INNER JOIN {analysisfeature} AF ON A.analysis_id = AF.analysis_id
  131. ";
  132. if ($dgenus) {
  133. $sql .= "
  134. INNER JOIN {feature} F on F.feature_id = AF.feature_id
  135. INNER JOIN {organism} O on O.organism_id = F.organism_id
  136. WHERE O.genus = '%s'
  137. ";
  138. $args[] = $dgenus;
  139. }
  140. if ($dgenus and $dspecies) {
  141. $sql .= " AND O.species = '%s' ";
  142. $args[] = $dspecies;
  143. }
  144. $results = chado_query($sql, $args);
  145. $analyses[] = '';
  146. while ($analysis = db_fetch_object($results)) {
  147. $analyses[$analysis->analysis_id] = $analysis->name;
  148. }
  149. $form['analysis'] = array(
  150. '#title' => t('Source'),
  151. '#type' => 'select',
  152. '#options' => $analyses,
  153. '#default_value' => $danalysis,
  154. '#multiple' => FALSE,
  155. '#description' => t('The feature source. If specified, only features derived or part of the selected source will be retrieved.'),
  156. '#ahah' => array(
  157. 'path' => 'seq_extract/set_source',
  158. 'wrapper' => 'tripal-feature-seq-extract-form-table',
  159. 'event' => 'change',
  160. 'method' => 'replace',
  161. ),
  162. );
  163. $ftypes = array();
  164. if ($dgenus) {
  165. $sql = "
  166. SELECT DISTINCT CVT.cvterm_id, CVT.name
  167. FROM {cvterm} CVT
  168. INNER JOIN {feature} F on CVT.cvterm_id = F.type_id
  169. INNER JOIN {organism} O on O.organism_id = F.organism_id
  170. WHERE O.genus = '%s'
  171. ";
  172. $args = array();
  173. $args[] = $dgenus;
  174. if ($dspecies) {
  175. $sql .= " AND O.species = '%s'";
  176. $args[] = $dspecies;
  177. }
  178. $results = chado_query($sql, $args);
  179. $ftypes[] = '';
  180. while ($type = db_fetch_object($results)) {
  181. $ftypes[$type->cvterm_id] = $type->name;
  182. }
  183. }
  184. $form['ftypes'] = array(
  185. '#title' => t('Feature Types'),
  186. '#type' => 'select',
  187. '#options' => $ftypes,
  188. '#multiple' => FALSE,
  189. '#default_value' => $dftypes,
  190. '#description' => t('The type of feature to retrieve (e.g. mRNA). All features that match this type will be retrieved.'),
  191. );
  192. $form['fname'] = array(
  193. '#title' => t('Feature Name'),
  194. '#type' => 'textarea',
  195. '#default_value' => $dfname,
  196. '#description' => t('The names of the features to retrieve. Separate each with a space. Leave blank to retrieve all features matching other criteria.'),
  197. );
  198. $form['upstream'] = array(
  199. '#title' => t('Upstream Bases'),
  200. '#type' => 'textfield',
  201. '#description' => t('An numeric value specifying the number of upstream bases to include.'),
  202. '#default_value' => $dupstream,
  203. '#size' => 5,
  204. );
  205. $form['downstream'] = array(
  206. '#title' => t('Downstream Bases'),
  207. '#type' => 'textfield',
  208. '#description' => t('An numeric value specifying the number of downstream bases to incldue.'),
  209. '#default_value' => $ddownstream,
  210. '#size' => 5,
  211. );
  212. $form['format'] = array(
  213. '#title' => t('Output Format'),
  214. '#type' => 'select',
  215. '#default_value' => $dformat,
  216. '#options' => array(
  217. 'fasta_html' => 'FASTA (in browser)',
  218. 'fasta_txt' => 'FASTA (download)',
  219. ),
  220. );
  221. $form['advanced'] = array(
  222. '#type' => 'fieldset',
  223. '#title' => 'Advanced',
  224. '#collapsible' => TRUE,
  225. '#collapsed' => TRUE
  226. );
  227. $form['advanced']['use_parent'] = array(
  228. '#title' => t('Use Parent'),
  229. '#type' => 'checkbox',
  230. '#default_value' => $duse_parent,
  231. '#description' => t('Check this box to retrieve the sequence from the parent in an alignment rather than the feature itself. This is useful if the same feature is aligned to multiple parents and you would like to retrieve the underlying sequence from each parent.'),
  232. );
  233. $form['advanced']['aggregate'] = array(
  234. '#title' => t('Aggregate'),
  235. '#type' => 'checkbox',
  236. '#default_value' => $daggregate,
  237. '#description' => t('Check this box to aggregate sub features into a single sequence. This is useful, for example, for obtaining CDS sequence from an mRNA. Rather than retrieve the mRNA sequence, the sub features of the mRNA will be aggregated and that will be returned.')
  238. );
  239. $form['advanced']['agg_types'] = array(
  240. '#title' => t('Types to aggregate'),
  241. '#type' => 'textarea',
  242. '#default_value' => $dagg_types,
  243. '#description' => t('Set this argument to the type of children to aggregate. This is useful in the case where a gene has exons, CDSs and UTRs. In this case, you may only want to aggregate CDSs and exclude exons. If you want to aggregate both CDSs and UTRs you could specify both.')
  244. );
  245. $form['retrieve_btn'] = array(
  246. '#type' => 'submit',
  247. '#value' => 'Retrieve'
  248. );
  249. return $form;
  250. }
  251. /**
  252. *
  253. */
  254. function tripal_feature_seq_extract_set_genus() {
  255. $status = TRUE;
  256. // prepare and render the form
  257. $form = tripal_core_ahah_prepare_form();
  258. $data = theme('tripal_feature_seq_extract_form', $form);
  259. // bind javascript events to the new objects that will be returned
  260. // so that AHAH enabled elements will work.
  261. $settings = tripal_core_ahah_bind_events();
  262. // return the updated JSON
  263. drupal_json(
  264. array(
  265. 'status' => $status,
  266. 'data' => $data,
  267. 'settings' => $settings,
  268. )
  269. );
  270. }
  271. /**
  272. *
  273. */
  274. function tripal_feature_seq_extract_set_species() {
  275. $status = TRUE;
  276. // prepare and render the form
  277. $form = tripal_core_ahah_prepare_form();
  278. $data = theme('tripal_feature_seq_extract_form', $form);
  279. // bind javascript events to the new objects that will be returned
  280. // so that AHAH enabled elements will work.
  281. $settings = tripal_core_ahah_bind_events();
  282. // return the updated JSON
  283. drupal_json(
  284. array(
  285. 'status' => $status,
  286. 'data' => $data,
  287. 'settings' => $settings,
  288. )
  289. );
  290. }
  291. /**
  292. *
  293. */
  294. function tripal_feature_seq_extract_set_source() {
  295. $status = TRUE;
  296. // prepare and render the form
  297. $form = tripal_core_ahah_prepare_form();
  298. $data = theme('tripal_feature_seq_extract_form', $form);
  299. // bind javascript events to the new objects that will be returned
  300. // so that AHAH enabled elements will work.
  301. $settings = tripal_core_ahah_bind_events();
  302. // return the updated JSON
  303. drupal_json(
  304. array(
  305. 'status' => $status,
  306. 'data' => $data,
  307. 'settings' => $settings,
  308. )
  309. );
  310. }