seq_extract.inc 10 KB

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