blast_ui.form_advanced_options.inc 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. <?php
  2. /**
  3. * @file
  4. * Contains helper functions related to program-specific advanced options.
  5. */
  6. /**
  7. * @section
  8. * BLASTn: Search a nucleotide database using a nucleotide query.
  9. * ----------------------------------------------------------------------------
  10. */
  11. /**
  12. * Adds the BLASTn Advanced Options to the passed in form.
  13. *
  14. * This form function is meant to be called within another form definition.
  15. *
  16. * @param $form
  17. * The form the advanced options should be added to. This form already
  18. * contains a $form['ALG'] fieldset meant to contain the advanced options.
  19. * @param $formstate
  20. * The current state fo the form passed in as $form.
  21. */
  22. function blast_ui_blastn_advanced_options_form(&$form, $form_state) {
  23. // Edit and Resubmit functionality.
  24. // We want to pull up the details from a previous blast and fill them in as defaults
  25. // for this blast.
  26. if (isset($form_state['prev_blast'])) {
  27. $defaults = _get_default_values($form_state['prev_blast']->options, 'blastn');
  28. }
  29. else {
  30. $defaults = _get_default_values(array(), 'blastn');
  31. }
  32. // General parameters
  33. //.........................
  34. $form['ALG']['GParam'] = array(
  35. '#type' => 'fieldset',
  36. '#title' => t('General parameters'),
  37. '#collapsible' => FALSE,
  38. );
  39. $form['ALG']['GParam']['maxTarget'] = array(
  40. '#type' => 'select',
  41. '#title' => t('Max target sequences:'),
  42. '#options' => _get_max_target('blastn'),
  43. '#default_value' => $defaults['max_target_seqs'],
  44. '#description' => t('Select the maximum number of unique target sequences per query sequence to show results for. Results returned may not be the highest scoring hits. <a href="https://academic.oup.com/bioinformatics/article/35/9/1613/5106166" target="_blank">More Information</a>'),
  45. );
  46. $form['ALG']['GParam']['eVal'] = array(
  47. '#type' => 'textfield',
  48. '#title' => t('e-Value (Expected Threshold)'),
  49. '#default_value' => $defaults['evalue'],
  50. '#size' => 12,
  51. '#maxlength' => 20,
  52. '#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format. <a href="https://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml#expect" target="_blank">More Information</a> | <a href="https://www.youtube.com/watch?v=nO0wJgZRZJs" target="_blank">Expect value video tutorial</a>'),
  53. );
  54. $form['ALG']['GParam']['wordSize'] = array(
  55. '#type' => 'select',
  56. '#title' => t('Word size:'),
  57. '#options' => _get_word_size('blastn'),
  58. '#default_value' => $defaults['word_size'],
  59. '#description' => t('The length of the seed that initiates an alignment'),
  60. );
  61. // Scoring parameters
  62. //.........................
  63. $form['ALG']['SParam'] = array(
  64. '#type' => 'fieldset',
  65. '#title' => t('Scoring parameters'),
  66. '#collapsible' => FALSE,
  67. );
  68. $form['ALG']['SParam']['M&MScores'] = array(
  69. '#type' => 'select',
  70. '#title' => t('Match/Mismatch Scores:'),
  71. '#options' => _get_match_mismatch('blastn'),
  72. '#default_value' => $defaults['matchmiss'],
  73. '#description' => t('Reward and penalty for matching and mismatching bases.'),
  74. '#ajax' => array(
  75. 'callback' => 'gap_cost_callback',
  76. 'wrapper' => 'gap_cost_wrapper',
  77. ),
  78. );
  79. $m_m_set = $defaults['matchmiss'];
  80. if (isset($form_state['values']) && isset($form_state['values']['M&MScores'])) {
  81. $m_m_set = $form_state['values']['M&MScores'];
  82. }
  83. $form['ALG']['SParam']['gapCost'] = array(
  84. '#type' => 'select',
  85. '#title' => t('Gap Costs:'),
  86. '#options' => _get_gap_options('blastn', $m_m_set),
  87. '#default_value' => $defaults['gap'],
  88. '#description' => t('Cost to create and extend a gap in an alignment.'),
  89. '#prefix' => '<div id="gap_cost_wrapper">',
  90. '#suffix' => '</div>',
  91. );
  92. }
  93. /**
  94. * Validate the advanced options provided by the BLASTn form above.
  95. *
  96. * @see blast_ui_blastn_advanced_options_form().
  97. */
  98. function blast_ui_blastn_advanced_options_form_validate($form, $form_state) {
  99. // Ensure that our textfields are what we expect them to be since we will
  100. // use them to generate the BLAST command.
  101. // First up, e-value. We expect the evalue to be a very small yet still
  102. // positive number. It may be given in scientific notation which is
  103. // luckily supported by is_numeric().
  104. if (!is_numeric($form_state['values']['eVal'])) {
  105. form_set_error('eVal', 'The e-value should be a very small number (scientific notation is supported). For example, <em>0.001</em> or, even better, <em>1e-10</em>.');
  106. }
  107. }
  108. /**
  109. * Processed the advanced options provided by the BLASTn form above.
  110. *
  111. * @see blast_ui_blastn_advanced_options_form().
  112. */
  113. function blast_ui_blastn_advanced_options_form_submit($form, $form_state) {
  114. $eVal = $form_state['values']['eVal'];
  115. $trgtKey = $form_state['values']['maxTarget'];
  116. $numAlign = $form['ALG']['GParam']['maxTarget']['#options'][$trgtKey];
  117. $wsKey = $form_state['values']['wordSize'];
  118. $wordSize = $form['ALG']['GParam']['wordSize']['#options'][$wsKey];
  119. // Expand Gap Cost key into open and extend penalties
  120. $gap = _set_gap($form_state['values']['gapCost']);
  121. // Expand Match/Mismatch option into penalty/reward values
  122. $m_m = _set_match_mismatch($form_state['values']['M&MScores']);
  123. return array(
  124. 'max_target_seqs' => $numAlign,
  125. 'evalue' => $eVal,
  126. 'word_size' => $wordSize,
  127. 'gapopen' => $gap['gapOpen'],
  128. 'gapextend' => $gap['gapExtend'],
  129. 'penalty' => $m_m['penalty'],
  130. 'reward' => $m_m['reward'],
  131. );
  132. }
  133. /**
  134. * @section
  135. * BLASTx: Search protein database using a translated nucleotide query.
  136. * ----------------------------------------------------------------------------
  137. */
  138. /**
  139. * Adds the BLASTx Advanced Options to the passed in form.
  140. *
  141. * This form function is meant to be called within another form definition.
  142. *
  143. * @param $form
  144. * The form the advanced options should be added to. This form already
  145. * contains a $form['ALG'] fieldset meant to contain the advanced options.
  146. * @param $formstate
  147. * The current state fo the form passed in as $form.
  148. */
  149. function blast_ui_blastx_advanced_options_form(&$form, $form_state) {
  150. // Edit and Resubmit functionality.
  151. // We want to pull up the details from a previous blast and fill them in as defaults
  152. // for this blast.
  153. if (isset($form_state['prev_blast'])) {
  154. $defaults = _get_default_values($form_state['prev_blast']->options, 'blastx');
  155. }
  156. else {
  157. $defaults = _get_default_values(array(), 'blastx');
  158. }
  159. $form['ALG']['GParam'] = array(
  160. '#type' => 'fieldset',
  161. '#title' => t('General parameters'),
  162. '#collapsible' => FALSE,
  163. );
  164. $form['ALG']['GParam']['maxTarget'] = array(
  165. '#type' => 'select',
  166. '#title' => t('Max target sequences:'),
  167. '#options' => _get_max_target('blastx'),
  168. '#default_value' => $defaults['max_target_seqs'],
  169. '#description' => t('Select the maximum number of aligned sequences to display'),
  170. );
  171. $form['ALG']['GParam']['eVal'] = array(
  172. '#type' => 'textfield',
  173. '#title' => t('e-Value (Expected Threshold)'),
  174. '#default_value' => $defaults['evalue'],
  175. '#size' => 12,
  176. '#maxlength' => 20,
  177. '#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format. <a href="https://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml#expect" target="_blank">More Information</a> | <a href="https://www.youtube.com/watch?v=nO0wJgZRZJs" target="_blank">Expect value vedio tutorial</a>'),
  178. );
  179. $form['ALG']['GParam']['wordSize'] = array(
  180. '#type' => 'select',
  181. '#title' => t('Word size:'),
  182. '#options' => _get_word_size('blastx'),
  183. '#default_value' => $defaults['word_size'],
  184. '#description' => t('The length of the seed that initiates an alignment'),
  185. );
  186. // Scoring parameters
  187. //.........................
  188. $form['ALG']['SParam'] = array(
  189. '#type' => 'fieldset',
  190. '#title' => t('Scoring parameters'),
  191. '#collapsible' => FALSE,
  192. );
  193. $matrix_options = _get_matrix_options();
  194. $form['ALG']['SParam']['Matrix'] = array(
  195. '#type' => 'select',
  196. '#title' => 'Matrix',
  197. '#options' => $matrix_options,
  198. '#default_value' => $defaults['matrix'],
  199. '#description' => t('Assigns a score for aligning pairs of residues, and determines overall alignment score..'),
  200. '#ajax' => array(
  201. 'callback' => 'matrix_gap_cost_callback',
  202. 'wrapper' => 'gap_cost_wrapper',
  203. ),
  204. );
  205. $matrix_set = $defaults['matrix'];
  206. if (isset($form_state['values']) && isset($form_state['values']['Matrix'])) {
  207. $matrix_set = $form_state['values']['Matrix'];
  208. }
  209. $form['ALG']['SParam']['gapCost'] = array(
  210. '#type' => 'select',
  211. '#title' => t('Gap Costs:'),
  212. '#prefix' => '<div id="gap_cost_wrapper">',
  213. '#suffix' => '</div>',
  214. '#options' => _get_gap_for_matrix($matrix_set),
  215. '#default_value' => $defaults['gap'],
  216. '#description' => t('Cost to create and extend a gap in an alignment.'),
  217. );
  218. }
  219. /**
  220. * Validate the advanced options provided by the BLASTn form above.
  221. *
  222. * @see blast_ui_blastx_advanced_options_form().
  223. */
  224. function blast_ui_blastx_advanced_options_form_validate($form, $form_state) {
  225. // Ensure that our textfields are what we expect them to be since we will
  226. // use them to generate the BLAST command.
  227. // First up, e-value. We expect the evalue to be a very small yet still
  228. // positive number. It may be given in scientific notation which is
  229. // luckily supported by is_numeric().
  230. if (!is_numeric($form_state['values']['eVal'])) {
  231. form_set_error('eVal', 'The e-value should be a very small number (scientific notation is supported). For example, <em>0.001</em> or, even better, <em>1e-10</em>.');
  232. }
  233. }
  234. /**
  235. * Processed the advanced options provided by the BLASTx form above.
  236. *
  237. * @see blast_ui_blastx_advanced_options_form().
  238. */
  239. function blast_ui_blastx_advanced_options_form_submit($form, $form_state) {
  240. // Same as blastp form submit
  241. return blast_ui_blastp_advanced_options_form_submit($form, $form_state);
  242. }
  243. /**
  244. * @section
  245. * BLASTp: Search protein database using a protein query.
  246. * ----------------------------------------------------------------------------
  247. */
  248. /**
  249. * Adds the BLASTp Advanced Options to the passed in form.
  250. *
  251. * This form function is meant to be called within another form definition.
  252. *
  253. * @param $form
  254. * The form the advanced options should be added to. This form already
  255. * contains a $form['ALG'] fieldset meant to contain the advanced options.
  256. * @param $formstate
  257. * The current state fo the form passed in as $form.
  258. */
  259. function blast_ui_blastp_advanced_options_form(&$form, $form_state) {
  260. // Edit and Resubmit functionality.
  261. // We want to pull up the details from a previous blast and fill them in as defaults
  262. // for this blast.
  263. if (isset($form_state['prev_blast'])) {
  264. $defaults = _get_default_values($form_state['prev_blast']->options, 'blastp');
  265. }
  266. else {
  267. $defaults = _get_default_values(array(), 'blastp');
  268. }
  269. //General parameters
  270. $form['ALG']['GParam'] = array(
  271. '#type' => 'fieldset',
  272. '#title' => t('General parameters'),
  273. '#collapsible' => FALSE,
  274. );
  275. $form['ALG']['GParam']['maxTarget'] = array(
  276. '#type' => 'select',
  277. '#title' => t('Max target sequences:'),
  278. '#options' => _get_max_target('blastp'),
  279. '#default_value' => $defaults['max_target_seqs'],
  280. '#description' => t('Select the maximum number of aligned sequences to display'),
  281. );
  282. $form['ALG']['GParam']['eVal'] = array(
  283. '#type' => 'textfield',
  284. '#title' => t('e-value(Expect threshold)'),
  285. '#default_value' => $defaults['evalue'],
  286. '#size' => 12,
  287. '#maxlength' => 20,
  288. '#description' => t('Expected number of chance matches in a random model.'),
  289. );
  290. $form['ALG']['GParam']['wordSize'] = array(
  291. '#type' => 'select',
  292. '#title' => t('Word size:'),
  293. '#options' => _get_word_size('blastp'),
  294. '#default_value' => $defaults['word_size'],
  295. '#description' => t('The length of the seed that initiates an alignment'),
  296. );
  297. // Scoring parameters
  298. $form['ALG']['SParam'] = array(
  299. '#type' => 'fieldset',
  300. '#title' => t('Scoring parameters'),
  301. '#collapsible' => FALSE,
  302. );
  303. $matrix_options = _get_matrix_options();
  304. $form['ALG']['SParam']['Matrix'] = array(
  305. '#type' => 'select',
  306. '#title' => 'Matrix',
  307. '#options' => $matrix_options,
  308. '#default_value' => $defaults['matrix'],
  309. '#description' => t('Assigns a score for aligning pairs of residues, and determines overall alignment score..'),
  310. '#ajax' => array(
  311. 'callback' => 'matrix_gap_cost_callback',
  312. 'wrapper' => 'gap_cost_wrapper',
  313. ),
  314. );
  315. $matrix_set = $defaults['matrix'];
  316. if (isset($form_state['values']) && isset($form_state['values']['Matrix'])) {
  317. $matrix_set = $form_state['values']['Matrix'];
  318. }
  319. $form['ALG']['SParam']['gapCost'] = array(
  320. '#type' => 'select',
  321. '#title' => t('Gap Costs:'),
  322. '#prefix' => '<div id="gap_cost_wrapper">',
  323. '#suffix' => '</div>',
  324. '#options' => _get_gap_for_matrix($matrix_set),
  325. '#default_value' => $defaults['gap'],
  326. '#description' => t('Cost to create and extend a gap in an alignment.'),
  327. );
  328. }
  329. /**
  330. * Validate the advanced options provided by the BLASTp form above.
  331. *
  332. * @see blast_ui_blastp_advanced_options_form().
  333. */
  334. function blast_ui_blastp_advanced_options_form_validate($form, $form_state) {
  335. // Ensure that our textfields are what we expect them to be since we will
  336. // use them to generate the BLAST command.
  337. // First up, e-value. We expect the evalue to be a very small yet still
  338. // positive number. It may be given in scientific notation which is
  339. // luckily supported by is_numeric().
  340. if (!is_numeric($form_state['values']['eVal'])) {
  341. form_set_error('eVal', 'The e-value should be a very small number (scientific notation is supported). For example, <em>0.001</em> or, even better, <em>1e-10</em>.');
  342. }
  343. }
  344. /**
  345. * Processed the advanced options provided by the BLASTp form above.
  346. *
  347. * @see blast_ui_blastp_advanced_options_form().
  348. */
  349. function blast_ui_blastp_advanced_options_form_submit($form, $form_state) {
  350. $eVal = $form_state['values']['eVal'];
  351. $trgtKey = $form_state['values']['maxTarget'];
  352. $numAlign = $form['ALG']['GParam']['maxTarget']['#options'][$trgtKey];
  353. $wsKey = $form_state['values']['wordSize'];
  354. $wordSize = $form['ALG']['GParam']['wordSize']['#options'][$wsKey];
  355. //$qRange = $form_state['values']['qRange'];
  356. // Expand Gap Cost key into open and extend penalties
  357. $matrix = $form_state['values']['Matrix'];
  358. $gapKey = $form_state['values']['gapCost'];
  359. $gap = _set_gap($gapKey);
  360. $gapOpen = $gap['gapOpen'];
  361. $gapExtend = $gap['gapExtend'];
  362. return array(
  363. 'max_target_seqs' => $numAlign,
  364. 'evalue' => $eVal,
  365. 'word_size' => $wordSize,
  366. 'gapopen' => $gapOpen,
  367. 'gapextend' => $gapExtend,
  368. //'culling_limit' => $qRange,
  369. 'matrix' => $matrix,
  370. );
  371. }//blast_ui_blastp_advanced_options_form_submit
  372. /**
  373. * @section
  374. * tBLASTn: Search translated nucleotide database using a protein query.
  375. * ----------------------------------------------------------------------------
  376. */
  377. /**
  378. * Adds the tBLASTn Advanced Options to the passed in form.
  379. *
  380. * This form function is meant to be called within another form definition.
  381. *
  382. * @param $form
  383. * The form the advanced options should be added to. This form already
  384. * contains a $form['ALG'] fieldset meant to contain the advanced options.
  385. * @param $formstate
  386. * The current state fo the form passed in as $form.
  387. */
  388. function blast_ui_tblastn_advanced_options_form(&$form, $form_state) {
  389. // Edit and Resubmit functionality.
  390. // We want to pull up the details from a previous blast and fill them in as defaults
  391. // for this blast.
  392. if (isset($form_state['prev_blast'])) {
  393. $defaults = _get_default_values($form_state['prev_blast']->options, 'tblastn');
  394. }
  395. else {
  396. $defaults = _get_default_values(array(), 'tblastn');
  397. }
  398. $form['ALG']['GParam'] = array(
  399. '#type' => 'fieldset',
  400. '#title' => t('General parameters'),
  401. '#collapsible' => FALSE,
  402. );
  403. $form['ALG']['GParam']['maxTarget'] = array(
  404. '#type' => 'select',
  405. '#title' => t('Max target sequences:'),
  406. '#options' => _get_max_target('tblastn'),
  407. '#default_value' => $defaults['max_target_seqs'],
  408. '#description' => t('Select the maximum number of aligned sequences to display'),
  409. );
  410. $form['ALG']['GParam']['eVal'] = array(
  411. '#type' => 'textfield',
  412. '#title' => t('e-Value (Expected Threshold)'),
  413. '#default_value' => $defaults['evalue'],
  414. '#size' => 12,
  415. '#maxlength' => 20,
  416. '#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format. <a href="https://www.ncbi.nlm.nih.gov/BLAST/blastcgihelp.shtml#expect" target="_blank">More Information</a> | <a href="https://www.youtube.com/watch?v=nO0wJgZRZJs" target="_blank">Expect value vedio tutorial</a>'),
  417. );
  418. $form['ALG']['GParam']['wordSize'] = array(
  419. '#type' => 'select',
  420. '#title' => t('Word size:'),
  421. '#options' => _get_word_size('tblastn'),
  422. '#default_value' => $defaults['word_size'],
  423. '#description' => t('The length of the seed that initiates an alignment'),
  424. );
  425. // Scoring parameters
  426. //.........................
  427. $form['ALG']['SParam'] = array(
  428. '#type' => 'fieldset',
  429. '#title' => t('Scoring parameters'),
  430. '#collapsible' => FALSE,
  431. );
  432. $matrix_options = _get_matrix_options();
  433. $form['ALG']['SParam']['Matrix'] = array(
  434. '#type' => 'select',
  435. '#title' => 'Matrix',
  436. '#options' => $matrix_options,
  437. '#default_value' => $defaults['matrix'],
  438. '#description' => t('Assigns a score for aligning pairs of residues, and determines overall alignment score.'),
  439. '#ajax' => array(
  440. 'callback' => 'matrix_gap_cost_callback',
  441. 'wrapper' => 'gap_cost_wrapper',
  442. ),
  443. );
  444. $matrix_set = $defaults['matrix'];
  445. if (isset($form_state['values']) && isset($form_state['values']['Matrix'])) {
  446. $matrix_set = $form_state['values']['Matrix'];
  447. }
  448. $form['ALG']['SParam']['gapCost'] = array(
  449. '#type' => 'select',
  450. '#title' => t('Gap Costs:'),
  451. '#prefix' => '<div id="gap_cost_wrapper">',
  452. '#suffix' => '</div>',
  453. '#options' => _get_gap_for_matrix($matrix_set),
  454. '#default_value' => $defaults['gap'],
  455. '#description' => t('Cost to create and extend a gap in an alignment.'),
  456. );
  457. }
  458. /**
  459. * Validate the advanced options provided by the tBLASTn form above.
  460. *
  461. * @see blast_ui_tblastn_advanced_options_form().
  462. */
  463. function blast_ui_tblastn_advanced_options_form_validate($form, $form_state) {
  464. // Ensure that our textfields are what we expect them to be since we will
  465. // use them to generate the BLAST command.
  466. // First up, e-value. We expect the evalue to be a very small yet still
  467. // positive number. It may be given in scientific notation which is
  468. // luckily supported by is_numeric().
  469. if (!is_numeric($form_state['values']['eVal'])) {
  470. form_set_error('eVal', 'The e-value should be a very small number (scientific notation is supported). For example, <em>0.001</em> or, even better, <em>1e-10</em>.');
  471. }
  472. }
  473. /**
  474. * Processed the advanced options provided by the tBLASTn form above.
  475. *
  476. * @see blast_ui_tblastn_advanced_options_form().
  477. */
  478. function blast_ui_tblastn_advanced_options_form_submit($form, $form_state) {
  479. return blast_ui_blastp_advanced_options_form_submit($form, $form_state);
  480. }
  481. /**
  482. * Fill the matrix dropdown list with appropriate options
  483. *
  484. * @return
  485. * An array consisting of matrices name for the first dropdown list
  486. */
  487. function _get_matrix_options() {
  488. return drupal_map_assoc(array(
  489. t('PAM30'),
  490. t('PAM70'),
  491. t('PAM250'),
  492. t('BLOSUM80'),
  493. t('BLOSUM62'),
  494. t('BLOSUM45'),
  495. t('BLOSUM50'),
  496. t('BLOSUM90'),
  497. ));
  498. }
  499. /**
  500. * Fill the gap penalty dropdown list with appropriate options given selected
  501. * matrix
  502. *
  503. * @return
  504. * An array containing open and extension gap values for the chosen matrix (to
  505. * fill the second dropdown list)
  506. */
  507. function _get_gap_for_matrix($key = '') {
  508. switch ($key) {
  509. case 'PAM30':
  510. return _make_gaps(array('7_2', '6_2', '5_2', '10_1', '8_1', '13_3', '15_3', '14_1',
  511. '14_2')
  512. );
  513. case 'PAM70':
  514. return _make_gaps(array('8_2', '7_2', '6_2', '11_1', '10_1', '9_1', '12_3', '11_2'));
  515. case 'PAM250':
  516. return _make_gaps(array('15_3', '14_3', '13_3', '12_3', '11_3', '17_2', '16_2',
  517. '15_2', '14_2', '13_2', '21_1', '20_1', '19_1', '18_1',
  518. '17_1')
  519. );
  520. case 'BLOSUM80':
  521. return _make_gaps(array('8_2', '7_2', '6_2', '11_1', '10_1', '9_1'));
  522. case 'BLOSUM62':
  523. return _make_gaps(array('11_2', '10_2', '9_2', '8_2', '7_2', '6_2', '13_1',
  524. '12_1', '11_1', '10_1', '9_1')
  525. );
  526. case 'BLOSUM45':
  527. return _make_gaps(array('13_3', '12_3', '11_3', '10_3', '15_2', '14_2', '13_2',
  528. '12_2', '19_1', '18_1', '17_1', '16_1')
  529. );
  530. case 'BLOSUM50':
  531. return _make_gaps(array('13_3', '12_3', '11_3', '10_3', '9_3', '16_2', '15_2',
  532. '14_2', '13_2', '12_2', '19_1', '18_1', '17_1', '16_1',
  533. '15_1')
  534. );
  535. case 'BLOSUM90':
  536. return _make_gaps(array('9_2', '8_2', '7_2', '6_2', '11_1', '10_1', '9_1'));
  537. }
  538. }//_get_gap_for_matrix
  539. /**
  540. * Respond to Ajax dropdown call
  541. */
  542. function matrix_gap_cost_callback($form, &$form_state) {
  543. return $form['B']['ALG']['SParam']['gapCost'];
  544. }
  545. /**
  546. * Get default form values; may come from saved job data if user is re-running
  547. * a previous job.
  548. */
  549. function _get_default_values($options, $program) {
  550. // restore previous values or set to default
  551. $max_target = (isset($options['max_target_seqs']))
  552. ? $options['max_target_seqs'] : 500;
  553. $short_queries = (isset($options['shortQueries']))
  554. ? $options['shortQueries'] : TRUE;
  555. $evalue = (isset($options['evalue']))
  556. ? $options['evalue'] : variable_get('eVal', 0.001);
  557. $word_size = (isset($options['word_size']))
  558. ? $options['word_size'] : 11;
  559. // match/mismatch
  560. $matchmiss = 0;
  561. $reward = (isset($options['reward']))
  562. ? $options['reward'] : 1;
  563. $penalty = (isset($options['penalty']))
  564. ? $options['penalty'] : -2;
  565. if ($reward == 1) {
  566. switch ($penalty) {
  567. case -1:
  568. $matchmiss = 5;
  569. break;
  570. case -2:
  571. $matchmiss = 0;
  572. break;
  573. case -3:
  574. $matchmiss = 1;
  575. break;
  576. case -4:
  577. $matchmiss = 2;
  578. break;
  579. }
  580. }
  581. else {
  582. if ($reward == 2) {
  583. $matchmiss = 3;
  584. }
  585. else {
  586. if ($reward == 3) {
  587. $matchmiss = 4;
  588. }
  589. else {
  590. if ($reward == 4) {
  591. $matchmiss = 5;
  592. }
  593. }
  594. }
  595. }
  596. // gap
  597. if (isset($options['gapopen']) && isset($options['gapextend'])) {
  598. $gapopen = $options['gapopen'];
  599. $gapextend = $options['gapextend'];
  600. }
  601. else {
  602. switch ($program) {
  603. case 'blastn':
  604. $gapopen = 5;
  605. $gapextend = 2;
  606. break;
  607. case 'blastp':
  608. case 'blastx':
  609. case 'tblastn':
  610. $gapopen = 11;
  611. $gapextend = 1;
  612. break;
  613. }
  614. }
  615. $gap = $gapopen.'_'.$gapextend;
  616. // matrix
  617. $matrix = (isset($options['matrix']))
  618. ? $options['matrix'] : 'BLOSUM62';
  619. // all done
  620. return array(
  621. 'max_target_seqs' => $max_target,
  622. 'short_queries' => $short_queries,
  623. 'word_size' => $word_size,
  624. 'evalue' => $evalue,
  625. 'matchmiss' => $matchmiss,
  626. 'gap' => $gap,
  627. 'matrix' => $matrix,
  628. );
  629. }//_get_default_values
  630. /**
  631. * Get a list of options for the max_target_seq blast option.
  632. *
  633. * The options are the same for all programs
  634. * and describe the maximum number of aligned sequences to keep.
  635. */
  636. function _get_max_target($which) {
  637. switch ($which) {
  638. case 'blastn':
  639. case 'blastx':
  640. case 'blastp':
  641. case 'tblastn':
  642. return array(
  643. 0 => t(' '),
  644. 10 => t('10'),
  645. 50 => t('50'),
  646. 100 => t('100'),
  647. 250 => t('250'),
  648. 500 => t('500'),
  649. 1000 => t('1000'),
  650. 5000 => t('5000'),
  651. 10000 => t('10000'),
  652. 20000 => t('20000'),
  653. );
  654. }//switch
  655. }
  656. /**
  657. * Get a list of options for work size.
  658. */
  659. function _get_word_size($which) {
  660. switch ($which) {
  661. case 'blastn':
  662. return array(
  663. 7 => t('7'),
  664. 11 => t('11'),
  665. 15 => t('15'),
  666. 16 => t('16'),
  667. 20 => t('20'),
  668. 24 => t('24'),
  669. 28 => t('28'),
  670. 32 => t('32'),
  671. 48 => t('48'),
  672. 64 => t('64'),
  673. 128 => t('128'),
  674. 256 => t('256'),
  675. );
  676. case 'blastx':
  677. case 'blastp':
  678. case 'tblastn':
  679. return array(
  680. // 2 => t('2'),
  681. 3 => t('3'),
  682. 6 => t('6'),
  683. );
  684. }//switch
  685. }
  686. /**
  687. * Get a list of options for match/mismatch ratio.
  688. */
  689. function _get_match_mismatch($which) {
  690. switch ($which) {
  691. case 'blastn':
  692. return array(
  693. 0 => t('1,-2'),
  694. 1 => t('1,-3'),
  695. 2 => t('1,-4'),
  696. 3 => t('2,-3'),
  697. 4 => t('4,-5'),
  698. 5 => t('1,-1'),
  699. );
  700. }//switch
  701. }
  702. /**
  703. * @param $which - the blast program being run
  704. * @param $m_m - the match mismatch scores.
  705. *
  706. * @return array
  707. */
  708. function _get_gap_options($which, $m_m) {
  709. switch ($which) {
  710. case 'blastn':
  711. switch ($m_m) {
  712. case 0: //1, -2
  713. return _make_gaps(array('5_2', '2_2', '1_2', '0_2', '3_1', '2_1', '1_1'));
  714. case 1: //1, -3
  715. return _make_gaps(array('5_2', '2_2', '1_2', '1_2', '0_2', '2_1', '1_1'));
  716. case 2: // 1, -4
  717. return _make_gaps(array('5_2', '1_2', '0_2', '2_1', '1_1'));
  718. case 3: //2, -3
  719. return _make_gaps(array('4_4', '2_4', '0_4', '3_3', '6_2', '5_2', '4_2', '2_2'));
  720. case 4: //4, -5
  721. return _make_gaps(array('12_8', '6_5', '5_5', '4_5', '3_5'));
  722. case 5: //1, -1
  723. return _make_gaps(array('5_2', '3_2', '2_2', '1_2', '0_2', '4_1', '3_1', '2_1'));
  724. }
  725. }
  726. }
  727. /**
  728. * @param $gap_array - array of gap abbreviations
  729. *
  730. * @return array
  731. */
  732. function _make_gaps($gap_array) {
  733. $a = array();
  734. foreach ($gap_array as $g) {
  735. $parts = explode('_', $g);
  736. $a[$g] = t("Existence: $parts[0] Extension: $parts[1]");
  737. }
  738. return $a;
  739. }
  740. /**
  741. * Translate gap abbreviation into blast gap open and extend costs.
  742. * @param $gap_key - a gap open/extend abbreviation
  743. */
  744. function _set_gap($gap_key) {
  745. $parts = explode('_', $gap_key);
  746. return array('gapOpen' => $parts[0], 'gapExtend' => $parts[1]);
  747. }
  748. /**
  749. * Translate mismatch/match ratio option into blast penalty/reward options.
  750. */
  751. function _set_match_mismatch($m_m) {
  752. switch ($m_m) {
  753. case 0:
  754. $penalty = -2;
  755. $reward = 1;
  756. break;
  757. case 1:
  758. $penalty = -3;
  759. $reward = 1;
  760. break;
  761. case 2:
  762. $penalty = -4;
  763. $reward = 1;
  764. break;
  765. case 3:
  766. $penalty = -3;
  767. $reward = 2;
  768. break;
  769. case 4:
  770. $penalty = -5;
  771. $reward = 4;
  772. break;
  773. case 5:
  774. $penalty = -1;
  775. $reward = 1;
  776. break;
  777. }//switch
  778. return array('penalty' => $penalty, 'reward' => $reward);
  779. }
  780. /**
  781. * AJAX callback for match and gap cost.
  782. * @param $form
  783. * @param $form_state
  784. *
  785. * @return mixed
  786. */
  787. function gap_cost_callback($form, &$form_state) {
  788. return $form['B']['ALG']['SParam']['gapCost'];
  789. }