blast_ui.blastn.inc_COPY 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. function blast_nucleotide_form($form, &$form_state) {
  3. //Nucleotide BLAST
  4. $form['nBLAST'] = array(
  5. '#type' => 'fieldset',
  6. '#title' => t('Standard Nucleotide BLAST'),
  7. '#collapsible' => TRUE,
  8. '#collapsed' => FALSE,
  9. );
  10. $form['nBLAST']['FASTA'] = array(
  11. '#type' => 'textarea',
  12. '#title' => t('Enter FASTA sequence(s)'),
  13. '#description'=>t('Enter query sequence(s) in the text area.'),
  14. );
  15. // Upload a file as an alternative to enter a query sequence
  16. $form['#attributes']['enctype'] = 'multipart/form-data';
  17. $form['nBLAST']['UPLOAD'] = array(
  18. '#prefix' => 'Or upload your query files: ',
  19. '#type' => 'file',
  20. '#description' => t('Please give a text a FASTA file, not a MS-Word or other document, you can upload up to 10 Mb.'),
  21. );
  22. //DATABASE//
  23. $form['DB'] = array(
  24. '#type' => 'fieldset',
  25. '#title' => t('BLAST Assembled KnowPulse Genomes'),
  26. '#collapsible' => TRUE,
  27. '#collapsed' => FALSE,
  28. );
  29. // //$options = _DB_options();
  30. // $form['DB']['SELECT_DB'] = array(
  31. // '#type' => 'select',
  32. // '#title' => t('KnowPulse Databases:'),
  33. // '#options' => $options,
  34. // '#default_value' => NULL,
  35. // );
  36. // Upload a file as an alternative to enter a query sequence
  37. $form['#attributes']['enctype'] = 'multipart/form-data';
  38. $form['DB']['DBUPLOAD'] = array(
  39. '#prefix' => 'Or upload your own dataset: ',
  40. '#type' => 'file',
  41. '#description' => t('Please give a text or a FASTA file, not a MS-Word or other document, you can upload up to 10 Mb.'),
  42. );
  43. //Algorithm parameters
  44. $form['ALG'] = array(
  45. '#type' => 'fieldset',
  46. '#title' => t('Algorithm parameters'),
  47. '#collapsible' => TRUE,
  48. '#collapsed' => TRUE,
  49. );
  50. //General parameters
  51. $form['ALG']['GParam'] = array(
  52. '#type' => 'fieldset',
  53. '#title' => t('General parameters'),
  54. '#collapsible' => FALSE,
  55. );
  56. $form['ALG']['GParam']['maxTarget'] = array(
  57. '#type' => 'select',
  58. '#title' => t('Max target sequences:'),
  59. '#options' => array(
  60. 0 => t('10'),
  61. 1 => t('50'),
  62. 2 => t('100'),
  63. 3 => t('250'),
  64. 4 => t('500'),
  65. 5 => t('1000'),
  66. 6 => t('5000'),
  67. 7 => t('10000'),
  68. 8 => t('20000'),
  69. ),
  70. '#default_value' => 2,
  71. '#description' => t('Select the maximum number of aligned sequences to display'),
  72. );
  73. $form['ALG']['GParam']['shortQueries'] = array(
  74. '#type' => 'checkbox',
  75. '#title' => t('Automatically adjust parameters for short input sequences'),
  76. '#default_value' => TRUE,
  77. );
  78. $form['ALG']['GParam']['eVal'] = array(
  79. '#type' => 'textfield',
  80. '#title' => t('Expect threshold'),
  81. '#default_value' => 10,
  82. '#size' => 12,
  83. '#maxlength' => 20,
  84. '#description' => t('Expected number of chance matches in a random model.'),
  85. );
  86. $form['ALG']['GParam']['wordSize'] = array(
  87. '#type' => 'select',
  88. '#title' => t('Word size:'),
  89. '#options' => array(
  90. 0 => t('16'),
  91. 1 => t('20'),
  92. 2 => t('24'),
  93. 3 => t('28'),
  94. 4 => t('32'),
  95. 5 => t('48'),
  96. 6 => t('64'),
  97. 7 => t('128'),
  98. 8 => t('256'),
  99. ),
  100. '#default_value' => 3,
  101. '#description' => t('The length of the seed that initiates an alignment'),
  102. );
  103. $form['ALG']['GParam']['qRange'] = array(
  104. '#type' => 'textfield',
  105. '#title' => t('Max matches in a query range'),
  106. '#default_value' => 0,
  107. '#size' => 12,
  108. '#maxlength' => 20,
  109. '#description' => t('Limit the number of matches to a query range. This option is useful if many strong matches to one part of a query may prevent BLAST from presenting weaker matches to another part of the query.'),
  110. );
  111. // Scoring parameters
  112. $form['ALG']['SParam'] = array(
  113. '#type' => 'fieldset',
  114. '#title' => t('Scoring parameters'),
  115. '#collapsible' => FALSE,
  116. );
  117. $form['ALG']['SParam']['M&MScores'] = array(
  118. '#type' => 'select',
  119. '#title' => t('Match/Mismatch Scores:'),
  120. '#options' => array(
  121. 0 => t('1,-2'),
  122. 1 => t('1,-3'),
  123. 2 => t('1,-4'),
  124. 3 => t('2,-3'),
  125. 4 => t('4,-5'),
  126. 5 => t('1,-1'),
  127. ),
  128. '#default_value' => 0,
  129. '#description' => t('Reward and penalty for matching and mismatching bases.'),
  130. );
  131. $form['ALG']['SParam']['gapCost'] = array(
  132. '#type' => 'select',
  133. '#title' => t('Gap Costs:'),
  134. '#options' => array(
  135. 0 => t('Linear'),
  136. 1 => t('Extension: 5 Extension: 2'),
  137. 2 => t('Extension: 2 Extension: 2'),
  138. 3 => t('Extension: 1 Extension: 2'),
  139. 4 => t('Extension: 0 Extension: 2'),
  140. 5 => t('Extension: 3 Extension: 1'),
  141. 6 => t('Extension: 2 Extension: 1'),
  142. 7 => t('Extension: 1 Extension: 1'),
  143. ),
  144. '#default_value' => 0,
  145. '#description' => t('Cost to create and extend a gap in an alignment. Linear costs are available only with megablast and are determined by the match/mismatch scores.'),
  146. );
  147. //Submit
  148. $form['submit'] = array(
  149. '#type' => 'submit',
  150. '#default_value' => ' BLAST ',
  151. );
  152. return $form;
  153. }
  154. function blast_nucleotide_form_validate($form, &$form_state) {
  155. $fastaSeq = $form_state['input']['FASTA'];
  156. dpm($form_state, $name = NULL);
  157. if (isset($fastaSeq)) {
  158. if(_validateFasta($fastaSeq)){
  159. form_set_error('nBLAST', t('Error: Failed to read the Blast query: Wrong format provided for FASTA nucleotide sequence'));
  160. } else {
  161. //
  162. }
  163. }
  164. $upQuery = file_save_upload('UPLOAD', array('file_validate_extensions' => array('txt fasta fa fna')), FILE_EXISTS_RENAME);
  165. if ($upQuery) {
  166. $upQuery_uri = $upQuery->uri;
  167. $upQuery_path = drupal_realpath($upQuery_uri);
  168. $upQuery_content = file_get_contents($upQuery_path);
  169. if(_validateFasta($upQuery_content)){
  170. form_set_error('nBLAST', t('Error: Failed to upload the Blast query: Wrong format provided for FASTA nucleotide sequence'));
  171. } else {
  172. //
  173. }
  174. }
  175. $upDB = file_save_upload('DBUPLOAD', array('file_validate_extensions' => array('txt fasta fa fna')), FILE_EXISTS_RENAME);
  176. if ($upDB) {
  177. $upDB_uri = $upDB->uri;
  178. $upDB_path = drupal_realpath($upDB_uri);
  179. $upDB_content = file_get_contents($upDB_path);
  180. if(_validateFasta($upDB_content)){
  181. form_set_error('DB', t('Error: Failed to upload the Blast reference file: Wrong format provided for FASTA nucleotide sequence'));
  182. } else {
  183. //Build a Blast DB?
  184. }
  185. }
  186. }
  187. function blast_nucleotide_form_submit($form, &$form_state) {
  188. //dpm($form_state['values'], $name = NULL);
  189. //$output = shell_exec("water -asequence $aSeq -bsequence $selectedDB -gapopen 10 -gapextend 2 -outfile /tmp/$jobID.water ");
  190. }
  191. function _validateFasta($sequence) {
  192. $fastaIdRegEx = '/^>.*(\\n|\\r)/';
  193. $fastaSeqRegEx = '/[^acgntuACGNTU\n\r]/';
  194. if ( preg_match($fastaSeqRegEx,$sequence) && !(preg_match($fastaIdRegEx,$sequence)) ) {
  195. $flag = 1;
  196. } else {
  197. $flag = 0;
  198. }
  199. return $flag;
  200. }
  201. function _DB_options() {
  202. $type = 'BLASTDB';
  203. $nodes = node_load_multiple(array(), array('type' => $type));
  204. return $nodes;
  205. }