blast_ui.form_advanced_options.inc 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  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. $all_job_data = variable_get('job_data', '');
  24. if (isset($_GET['jid']) && isset($all_job_data)) {
  25. $jid = base64_decode($_GET['jid']);
  26. $job_data = $all_job_data[$jid];
  27. }
  28. else {
  29. $job_data = array();
  30. $jid = 0;
  31. }
  32. $defaults = _get_default_values($job_data, 'blastn');
  33. // General parameters
  34. //.........................
  35. $form['ALG']['GParam'] = array(
  36. '#type' => 'fieldset',
  37. '#title' => t('General parameters'),
  38. '#collapsible' => FALSE,
  39. );
  40. $form['ALG']['GParam']['maxTarget'] = array(
  41. '#type' => 'select',
  42. '#title' => t('Max target sequences:'),
  43. '#options' => _get_max_target('blastn'),
  44. '#default_value' => $defaults['max_target_seqs'],
  45. '#description' => t('Select the maximum number of aligned sequences to display'),
  46. );
  47. /*eksc- remove until we learn how this is implemented by NCBI
  48. $form['ALG']['GParam']['shortQueries'] = array(
  49. '#type' => 'checkbox',
  50. '#title' => t('Automatically adjust parameters for short input sequences'),
  51. '#default_value' => $short_queries,
  52. );
  53. */
  54. $form['ALG']['GParam']['eVal'] = array(
  55. '#type' => 'textfield',
  56. '#title' => t('e-Value (Expected Threshold)'),
  57. '#default_value' => $defaults['evalue'],
  58. '#size' => 12,
  59. '#maxlength' => 20,
  60. '#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format. <a href="http://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>'),
  61. );
  62. $form['ALG']['GParam']['wordSize'] = array(
  63. '#type' => 'select',
  64. '#title' => t('Word size:'),
  65. '#options' => _get_word_size('blastn'),
  66. '#default_value' => $defaults['word_size'],
  67. '#description' => t('The length of the seed that initiates an alignment'),
  68. );
  69. $form['ALG']['GParam']['qRange'] = array(
  70. '#type' => 'textfield',
  71. '#title' => t('Max matches in a query range'),
  72. '#default_value' => $defaults['qRange'],
  73. '#size' => 12,
  74. '#maxlength' => 20,
  75. '#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.'),
  76. );
  77. // Scoring parameters
  78. //.........................
  79. $form['ALG']['SParam'] = array(
  80. '#type' => 'fieldset',
  81. '#title' => t('Scoring parameters'),
  82. '#collapsible' => FALSE,
  83. );
  84. $form['ALG']['SParam']['M&MScores'] = array(
  85. '#type' => 'select',
  86. '#title' => t('Match/Mismatch Scores:'),
  87. '#options' => _get_match_mismatch('blastn'),
  88. '#default_value' => $defaults['matchmiss'],
  89. '#description' => t('Reward and penalty for matching and mismatching bases.'),
  90. );
  91. $form['ALG']['SParam']['gapCost'] = array(
  92. '#type' => 'select',
  93. '#title' => t('Gap Costs:'),
  94. '#options' => _get_gap('blastn'),
  95. '#default_value' => $defaults['gap'],
  96. '#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.'),
  97. );
  98. }
  99. /**
  100. * Validate the advanced options provided by the BLASTn form above.
  101. *
  102. * @see blast_ui_blastn_advanced_options_form().
  103. */
  104. function blast_ui_blastn_advanced_options_form_validate($form, $form_state) { }
  105. /**
  106. * Processed the advanced options provided by the BLASTn form above.
  107. *
  108. * @see blast_ui_blastn_advanced_options_form().
  109. */
  110. function blast_ui_blastn_advanced_options_form_submit($form, $form_state) {
  111. $eVal = $form_state['values']['eVal'];
  112. $trgtKey = $form_state['values']['maxTarget'];
  113. $numAlign = $form['ALG']['GParam']['maxTarget']['#options'][$trgtKey];
  114. $wsKey = $form_state['values']['wordSize'];
  115. $wordSize = $form['ALG']['GParam']['wordSize']['#options'][$wsKey];
  116. // Expand Gap Cost key into open and extend penalties
  117. $gap = _set_gap($form_state['values']['gapCost']);
  118. // Expand Match/Mismatch option into penalty/reward values
  119. $m_m = _set_match_mismatch($form_state['values']['M&MScores']);
  120. // Limit number of query hits
  121. $qRange = $form_state['values']['qRange'];
  122. return array(
  123. 'max_target_seqs' => $numAlign,
  124. 'evalue' => $eVal,
  125. 'word_size' => $wordSize,
  126. 'gapopen' => $gap['gapOpen'],
  127. 'gapextend' => $gap['gapExtend'],
  128. 'penalty' => $m_m['penalty'],
  129. 'reward' => $m_m['reward'],
  130. 'culling_limit' => $qRange,
  131. );
  132. }//blast_ui_blastn_advanced_options_form_submit
  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. $all_job_data = variable_get('job_data', '');
  151. if (isset($_GET['jid']) && isset($all_job_data)) {
  152. $jid = base64_decode($_GET['jid']);
  153. $job_data = $all_job_data[$jid];
  154. }
  155. else {
  156. $job_data = array();
  157. $jid = 0;
  158. }
  159. $defaults = _get_default_values($job_data, 'blastx');
  160. $form['ALG']['GParam'] = array(
  161. '#type' => 'fieldset',
  162. '#title' => t('General parameters'),
  163. '#collapsible' => FALSE,
  164. );
  165. $form['ALG']['GParam']['maxTarget'] = array(
  166. '#type' => 'select',
  167. '#title' => t('Max target sequences:'),
  168. '#options' => _get_max_target('blastx'),
  169. '#default_value' => $defaults['max_target_seqs'],
  170. '#description' => t('Select the maximum number of aligned sequences to display'),
  171. );
  172. $form['ALG']['GParam']['eVal'] = array(
  173. '#type' => 'textfield',
  174. '#title' => t('e-Value (Expected Threshold)'),
  175. '#default_value' => $defaults['evalue'],
  176. '#size' => 12,
  177. '#maxlength' => 20,
  178. '#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format. <a href="http://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>'),
  179. );
  180. /*eksc- need to learn how this is implemented for blastx
  181. $form['ALG']['GParam']['shortQueries'] = array(
  182. '#type' => 'checkbox',
  183. '#title' => t('Automatically adjust parameters for short input sequences'),
  184. '#default_value' => TRUE,
  185. );
  186. */
  187. $form['ALG']['GParam']['wordSize'] = array(
  188. '#type' => 'select',
  189. '#title' => t('Word size:'),
  190. '#options' => _get_word_size('blastx'),
  191. '#default_value' => $defaults['word_size'],
  192. '#description' => t('The length of the seed that initiates an alignment'),
  193. );
  194. // Scoring parameters
  195. //.........................
  196. $form['ALG']['SParam'] = array(
  197. '#type' => 'fieldset',
  198. '#title' => t('Scoring parameters'),
  199. '#collapsible' => FALSE,
  200. );
  201. $matrix_options = _get_matrix_options();
  202. $form['ALG']['SParam']['Matrix'] = array(
  203. '#type' => 'select',
  204. '#title' => 'Matrix',
  205. '#options' => $matrix_options,
  206. '#default_value' => $default['matrix'],
  207. '#description' => t('Assigns a score for aligning pairs of residues, and determines overall alignment score..'),
  208. '#ajax' => array(
  209. 'callback' => 'ajax_dependent_dropdown_callback',
  210. 'wrapper' => 'dropdown-second-replace',
  211. ),
  212. );
  213. $form['ALG']['GParam']['qRange'] = array(
  214. '#type' => 'textfield',
  215. '#title' => t('Max matches in a query range'),
  216. '#default_value' => $defaults['qRange'],
  217. '#size' => 12,
  218. '#maxlength' => 20,
  219. '#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.'),
  220. );
  221. /*eksc- NOT match/mismatch but instead computational adjustments;
  222. need to learn how there are implemented for blastx
  223. $form['ALG']['SParam']['M&MScores'] = array(
  224. '#type' => 'select',
  225. '#title' => t('Match/Mismatch Scores:'),
  226. '#options' => array(
  227. 0 => t('No adjustment'),
  228. 1 => t('Composition-based statistics'),
  229. 2 => t('Conditional compositional score matrix adjustment'),
  230. 3 => t('Universal composition score matrix adjustment '),
  231. ),
  232. '#default_value' => 2,
  233. '#description' => t('Matrix adjustment method to compensate for amino acid composition of sequences'),
  234. );
  235. */
  236. }
  237. /**
  238. * Validate the advanced options provided by the BLASTn form above.
  239. *
  240. * @see blast_ui_blastx_advanced_options_form().
  241. */
  242. function blast_ui_blastx_advanced_options_form_validate($form, $form_state) { }
  243. /**
  244. * Processed the advanced options provided by the BLASTx form above.
  245. *
  246. * @see blast_ui_blastx_advanced_options_form().
  247. */
  248. function blast_ui_blastx_advanced_options_form_submit($form, $form_state) {
  249. // Same as blastp form submit
  250. return blast_ui_blastp_advanced_options_form_submit($form, $form_state);
  251. }
  252. /**
  253. * @section
  254. * BLASTp: Search protein database using a protein query.
  255. * ----------------------------------------------------------------------------
  256. */
  257. /**
  258. * Adds the BLASTp Advanced Options to the passed in form.
  259. *
  260. * This form function is meant to be called within another form definition.
  261. *
  262. * @param $form
  263. * The form the advanced options should be added to. This form already
  264. * contains a $form['ALG'] fieldset meant to contain the advanced options.
  265. * @param $formstate
  266. * The current state fo the form passed in as $form.
  267. */
  268. function blast_ui_blastp_advanced_options_form(&$form, $form_state) {
  269. $all_job_data = variable_get('job_data', '');
  270. if (isset($_GET['jid']) && isset($all_job_data)) {
  271. $jid = base64_decode($_GET['jid']);
  272. $job_data = $all_job_data[$jid];
  273. }
  274. else {
  275. $job_data = array();
  276. $jid = 0;
  277. }
  278. $defaults = _get_default_values($job_data, 'blastp');
  279. //General parameters
  280. $form['ALG']['GParam'] = array(
  281. '#type' => 'fieldset',
  282. '#title' => t('General parameters'),
  283. '#collapsible' => FALSE,
  284. );
  285. $form['ALG']['GParam']['maxTarget'] = array(
  286. '#type' => 'select',
  287. '#title' => t('Max target sequences:'),
  288. '#options' => _get_max_target('blastp'),
  289. '#default_value' => $defaults['max_target_seqs'],
  290. '#description' => t('Select the maximum number of aligned sequences to display'),
  291. );
  292. /*eksc- remove until we learn how this is implemented
  293. $form['ALG']['GParam']['shortQueries'] = array(
  294. '#type' => 'checkbox',
  295. '#title' => t('Automatically adjust parameters for short input sequences'),
  296. '#default_value' => TRUE,
  297. );
  298. */
  299. $form['ALG']['GParam']['eVal'] = array(
  300. '#type' => 'textfield',
  301. '#title' => t('e-value(Expect threshold)'),
  302. '#default_value' => $defaults['evalue'],
  303. '#size' => 12,
  304. '#maxlength' => 20,
  305. '#description' => t('Expected number of chance matches in a random model.'),
  306. );
  307. $form['ALG']['GParam']['wordSize'] = array(
  308. '#type' => 'select',
  309. '#title' => t('Word size:'),
  310. '#options' => _get_word_size('blastp'),
  311. '#default_value' => $defaults['word_size'],
  312. '#description' => t('The length of the seed that initiates an alignment'),
  313. );
  314. $form['ALG']['GParam']['qRange'] = array(
  315. '#type' => 'textfield',
  316. '#title' => t('Max matches in a query range'),
  317. '#default_value' => $defaults['qRange'],
  318. '#size' => 12,
  319. '#maxlength' => 20,
  320. '#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.'),
  321. );
  322. // Scoring parameters
  323. $form['ALG']['SParam'] = array(
  324. '#type' => 'fieldset',
  325. '#title' => t('Scoring parameters'),
  326. '#collapsible' => FALSE,
  327. );
  328. $matrix_options = _get_matrix_options();
  329. $form['ALG']['SParam']['Matrix'] = array(
  330. '#type' => 'select',
  331. '#title' => 'Matrix',
  332. '#options' => $matrix_options,
  333. '#default_value' => $defaults['matrix'],
  334. '#description' => t('Assigns a score for aligning pairs of residues, and determines overall alignment score..'),
  335. '#ajax' => array(
  336. 'callback' => 'ajax_dependent_dropdown_callback',
  337. 'wrapper' => 'dropdown-second-replace',
  338. ),
  339. );
  340. /*eksc- probably not used for blastp
  341. $form['ALG']['SParam']['gapCost'] = array(
  342. '#type' => 'select',
  343. '#title' => t('Gap Costs:'),
  344. '#prefix' => '<div id="dropdown-second-replace">',
  345. '#suffix' => '</div>',
  346. '#options' => _get_gap_for_matrix($selected),
  347. '#default_value' => 2,
  348. '#description' => t('Cost to create and extend a gap in an alignment.'),
  349. );
  350. */
  351. /*eksc- NOT match/mismatch but instead computational adjustments;
  352. need to learn how there are implemented for blastp
  353. $form['ALG']['SParam']['M&MScores'] = array(
  354. '#type' => 'select',
  355. '#title' => t('Match/Mismatch Scores:'),
  356. '#options' => array(
  357. 0 => t('No adjustment'),
  358. 1 => t('Composition-based statistics'),
  359. 2 => t('Conditional compositional score matrix adjustment'),
  360. 3 => t('Universal composition score matrix adjustment '),
  361. ),
  362. '#default_value' => 2,
  363. '#description' => t('Matrix adjustment method to compensate for amino acid composition of sequences'),
  364. );
  365. */
  366. }//blast_ui_blastp_advanced_options_form
  367. /**
  368. * Validate the advanced options provided by the BLASTp form above.
  369. *
  370. * @see blast_ui_blastp_advanced_options_form().
  371. */
  372. function blast_ui_blastp_advanced_options_form_validate($form, $form_state) { }
  373. /**
  374. * Processed the advanced options provided by the BLASTp form above.
  375. *
  376. * @see blast_ui_blastp_advanced_options_form().
  377. */
  378. function blast_ui_blastp_advanced_options_form_submit($form, $form_state) {
  379. $eVal = $form_state['values']['eVal'];
  380. $trgtKey = $form_state['values']['maxTarget'];
  381. $numAlign = $form['ALG']['GParam']['maxTarget']['#options'][$trgtKey];
  382. $wsKey = $form_state['values']['wordSize'];
  383. $wordSize = $form['ALG']['GParam']['wordSize']['#options'][$wsKey];
  384. $qRange = $form_state['values']['qRange'];
  385. // Expand Gap Cost key into open and extend penalties
  386. $matrix = $form_state['values']['Matrix'];
  387. switch ($matrix) {
  388. case 'PAM30':
  389. $gapKey = $form_state['values']['gapCost'];
  390. switch ($gapKey) {
  391. case 0:
  392. $gapOpen = 7;
  393. $gapExtend = 2;
  394. break;
  395. case 1:
  396. $gapOpen = 6;
  397. $gapExtend = 2;
  398. break;
  399. case 2:
  400. $gapOpen = 5;
  401. $gapExtend = 2;
  402. break;
  403. case 3:
  404. $gapOpen = 10;
  405. $gapExtend = 1;
  406. break;
  407. case 4:
  408. $gapOpen = 9;
  409. $gapExtend = 1;
  410. break;
  411. case 5:
  412. $gapOpen = 8;
  413. $gapExtend = 1;
  414. break;
  415. }
  416. break;
  417. case 'PAM70':
  418. $gapKey = $form_state['values']['gapCost'];
  419. switch ($gapKey) {
  420. case 0:
  421. $gapOpen = 8;
  422. $gapExtend = 2;
  423. break;
  424. case 1:
  425. $gapOpen = 7;
  426. $gapExtend = 2;
  427. break;
  428. case 2:
  429. $gapOpen = 6;
  430. $gapExtend = 2;
  431. break;
  432. case 3:
  433. $gapOpen = 11;
  434. $gapExtend = 1;
  435. break;
  436. case 4:
  437. $gapOpen = 10;
  438. $gapExtend = 1;
  439. break;
  440. case 5:
  441. $gapOpen = 9;
  442. $gapExtend = 1;
  443. break;
  444. }
  445. break;
  446. case 'PAM250':
  447. $gapKey = $form_state['values']['gapCost'];
  448. switch ($gapKey) {
  449. case 0:
  450. $gapOpen = 15;
  451. $gapExtend = 3;
  452. break;
  453. case 1:
  454. $gapOpen = 14;
  455. $gapExtend = 3;
  456. break;
  457. case 2:
  458. $gapOpen = 13;
  459. $gapExtend = 3;
  460. break;
  461. case 3:
  462. $gapOpen = 12;
  463. $gapExtend = 3;
  464. break;
  465. case 4:
  466. $gapOpen = 11;
  467. $gapExtend = 3;
  468. break;
  469. case 5:
  470. $gapOpen = 17;
  471. $gapExtend = 2;
  472. break;
  473. case 6:
  474. $gapOpen = 16;
  475. $gapExtend = 2;
  476. break;
  477. case 7:
  478. $gapOpen = 15;
  479. $gapExtend = 2;
  480. break;
  481. case 8:
  482. $gapOpen = 14;
  483. $gapExtend = 2;
  484. break;
  485. case 9:
  486. $gapOpen = 13;
  487. $gapExtend = 2;
  488. break;
  489. case 10:
  490. $gapOpen = 21;
  491. $gapExtend = 1;
  492. break;
  493. case 11:
  494. $gapOpen = 20;
  495. $gapExtend = 1;
  496. break;
  497. case 12:
  498. $gapOpen = 19;
  499. $gapExtend = 1;
  500. break;
  501. case 13:
  502. $gapOpen = 18;
  503. $gapExtend = 1;
  504. break;
  505. case 14:
  506. $gapOpen = 17;
  507. $gapExtend = 1;
  508. break;
  509. }
  510. break;
  511. case 'BLOSUM80':
  512. $gapKey = $form_state['values']['gapCost'];
  513. switch ($gapKey) {
  514. case 0:
  515. $gapOpen = 8;
  516. $gapExtend = 2;
  517. break;
  518. case 1:
  519. $gapOpen = 7;
  520. $gapExtend = 2;
  521. break;
  522. case 2:
  523. $gapOpen = 6;
  524. $gapExtend = 2;
  525. break;
  526. case 3:
  527. $gapOpen = 11;
  528. $gapExtend = 1;
  529. break;
  530. case 4:
  531. $gapOpen = 10;
  532. $gapExtend = 1;
  533. break;
  534. case 5:
  535. $gapOpen = 9;
  536. $gapExtend = 1;
  537. break;
  538. }
  539. break;
  540. case 'BLOSUM62':
  541. $gapKey = $form_state['values']['gapCost'];
  542. switch ($gapKey) {
  543. case 0:
  544. $gapOpen = 11;
  545. $gapExtend = 2;
  546. break;
  547. case 1:
  548. $gapOpen = 10;
  549. $gapExtend = 2;
  550. break;
  551. case 2:
  552. $gapOpen = 9;
  553. $gapExtend = 2;
  554. break;
  555. case 3:
  556. $gapOpen = 8;
  557. $gapExtend = 2;
  558. break;
  559. case 4:
  560. $gapOpen = 7;
  561. $gapExtend = 2;
  562. break;
  563. case 5:
  564. $gapOpen = 6;
  565. $gapExtend = 2;
  566. break;
  567. case 6:
  568. $gapOpen = 13;
  569. $gapExtend = 1;
  570. break;
  571. case 7:
  572. $gapOpen = 12;
  573. $gapExtend = 1;
  574. break;
  575. case 8:
  576. $gapOpen = 11;
  577. $gapExtend = 1;
  578. break;
  579. case 9:
  580. $gapOpen = 10;
  581. $gapExtend = 1;
  582. break;
  583. case 10:
  584. $gapOpen = 9;
  585. $gapExtend = 1;
  586. break;
  587. }
  588. break;
  589. case 'BLOSUM45':
  590. $gapKey = $form_state['values']['gapCost'];
  591. switch ($gapKey) {
  592. case 0:
  593. $gapOpen = 13;
  594. $gapExtend = 3;
  595. break;
  596. case 1:
  597. $gapOpen = 12;
  598. $gapExtend = 3;
  599. break;
  600. case 2:
  601. $gapOpen = 11;
  602. $gapExtend = 3;
  603. break;
  604. case 3:
  605. $gapOpen = 10;
  606. $gapExtend = 3;
  607. break;
  608. case 4:
  609. $gapOpen = 15;
  610. $gapExtend = 2;
  611. break;
  612. case 5:
  613. $gapOpen = 14;
  614. $gapExtend = 2;
  615. break;
  616. case 6:
  617. $gapOpen = 13;
  618. $gapExtend = 2;
  619. break;
  620. case 7:
  621. $gapOpen = 12;
  622. $gapExtend = 2;
  623. break;
  624. case 8:
  625. $gapOpen = 19;
  626. $gapExtend = 1;
  627. break;
  628. case 9:
  629. $gapOpen = 18;
  630. $gapExtend = 1;
  631. break;
  632. case 10:
  633. $gapOpen = 17;
  634. $gapExtend = 1;
  635. break;
  636. case 11:
  637. $gapOpen = 16;
  638. $gapExtend = 1;
  639. break;
  640. }
  641. break;
  642. case 'BLOSUM50':
  643. $gapKey = $form_state['values']['gapCost'];
  644. switch ($gapKey) {
  645. case 0:
  646. $gapOpen = 13;
  647. $gapExtend = 3;
  648. break;
  649. case 1:
  650. $gapOpen = 12;
  651. $gapExtend = 3;
  652. break;
  653. case 2:
  654. $gapOpen = 11;
  655. $gapExtend = 3;
  656. break;
  657. case 3:
  658. $gapOpen = 10;
  659. $gapExtend = 3;
  660. break;
  661. case 4:
  662. $gapOpen = 9;
  663. $gapExtend = 3;
  664. break;
  665. case 5:
  666. $gapOpen = 16;
  667. $gapExtend = 2;
  668. break;
  669. case 6:
  670. $gapOpen = 15;
  671. $gapExtend = 2;
  672. break;
  673. case 7:
  674. $gapOpen = 14;
  675. $gapExtend = 2;
  676. break;
  677. case 8:
  678. $gapOpen = 13;
  679. $gapExtend = 2;
  680. break;
  681. case 9:
  682. $gapOpen = 12;
  683. $gapExtend = 2;
  684. break;
  685. case 10:
  686. $gapOpen = 19;
  687. $gapExtend = 1;
  688. break;
  689. case 11:
  690. $gapOpen = 18;
  691. $gapExtend = 1;
  692. break;
  693. case 12:
  694. $gapOpen = 17;
  695. $gapExtend = 1;
  696. break;
  697. case 13:
  698. $gapOpen = 16;
  699. $gapExtend = 1;
  700. break;
  701. case 14:
  702. $gapOpen = 15;
  703. $gapExtend = 1;
  704. break;
  705. }
  706. break;
  707. case 'BLOSUM90':
  708. $gapKey = $form_state['values']['gapCost'];
  709. switch ($gapKey) {
  710. case 0:
  711. $gapOpen = 9;
  712. $gapExtend = 2;
  713. break;
  714. case 1:
  715. $gapOpen = 8;
  716. $gapExtend = 2;
  717. break;
  718. case 2:
  719. $gapOpen = 7;
  720. $gapExtend = 2;
  721. break;
  722. case 3:
  723. $gapOpen = 6;
  724. $gapExtend = 2;
  725. break;
  726. case 4:
  727. $gapOpen = 11;
  728. $gapExtend = 1;
  729. break;
  730. case 5:
  731. $gapOpen = 10;
  732. $gapExtend = 1;
  733. break;
  734. case 6:
  735. $gapOpen = 9;
  736. $gapExtend = 1;
  737. break;
  738. }
  739. break;
  740. }
  741. //eksc- need to implement query range limit
  742. // q_range
  743. return array(
  744. 'max_target_seqs' => $numAlign,
  745. 'evalue' => $eVal,
  746. 'word_size' => $wordSize,
  747. 'gapopen' => $gapOpen,
  748. 'gapextend' => $gapExtend,
  749. 'culling_limit' => $qRange,
  750. 'matrix' => $matrix,
  751. );
  752. }//blast_ui_blastp_advanced_options_form_submit
  753. /**
  754. * Fill the matrix dropdown list with appropriate options
  755. *
  756. * @return
  757. * An array consisting of matrices name for the first dropdown list
  758. */
  759. function _get_matrix_options() {
  760. return drupal_map_assoc(array(
  761. t('PAM30'),
  762. t('PAM70'),
  763. t('PAM250'),
  764. t('BLOSUM80'),
  765. t('BLOSUM62'),
  766. t('BLOSUM45'),
  767. t('BLOSUM50'),
  768. t('BLOSUM90'),
  769. ));
  770. }
  771. /**
  772. * Fill the gap penalty dropdown list with appropriate options given selected matrix
  773. *
  774. * @return
  775. * An array containing open and extension gap values for the chosen matrix (to fill the second dropdown list)
  776. */
  777. function _get_gap_for_matrix($key = '') {
  778. $options = array(
  779. t('PAM30') => drupal_map_assoc(array(
  780. t('Existence: 7 Extension: 2'),
  781. t('Existence: 6 Extension: 2'),
  782. t('Existence: 5 Extension: 2'),
  783. t('Existence: 10 Extension: 1'),
  784. t('Existence: 9 Extension: 1'),
  785. t('Existence: 8 Extension: 1'),
  786. )),
  787. t('PAM70') => drupal_map_assoc(array(
  788. t('Existence: 8 Extension: 2'),
  789. t('Existence: 7 Extension: 2'),
  790. t('Existence: 6 Extension: 2'),
  791. t('Existence: 11 Extension: 1'),
  792. t('Existence: 10 Extension: 1'),
  793. t('Existence: 9 Extension: 1'),
  794. )),
  795. t('PAM250') => drupal_map_assoc(array(
  796. t('Existence: 15 Extension: 3'),
  797. t('Existence: 14 Extension: 3'),
  798. t('Existence: 13 Extension: 3'),
  799. t('Existence: 12 Extension: 3'),
  800. t('Existence: 11 Extension: 3'),
  801. t('Existence: 17 Extension: 2'),
  802. t('Existence: 16 Extension: 2'),
  803. t('Existence: 15 Extension: 2'),
  804. t('Existence: 14 Extension: 2'),
  805. t('Existence: 13 Extension: 2'),
  806. t('Existence: 21 Extension: 1'),
  807. t('Existence: 20 Extension: 1'),
  808. t('Existence: 19 Extension: 1'),
  809. t('Existence: 18 Extension: 1'),
  810. t('Existence: 17 Extension: 1'),
  811. )),
  812. t('BLOSUM80') => drupal_map_assoc(array(
  813. t('Existence: 8 Extension: 2'),
  814. t('Existence: 7 Extension: 2'),
  815. t('Existence: 6 Extension: 2'),
  816. t('Existence: 11 Extension: 1'),
  817. t('Existence: 10 Extension: 1'),
  818. t('Existence: 9 Extension: 1'),
  819. )),
  820. t('BLOSUM62') => drupal_map_assoc(array(
  821. t('Existence: 11 Extension: 2'),
  822. t('Existence: 10 Extension: 2'),
  823. t('Existence: 9 Extension: 2'),
  824. t('Existence: 8 Extension: 2'),
  825. t('Existence: 7 Extension: 2'),
  826. t('Existence: 6 Extension: 2'),
  827. t('Existence: 13 Extension: 1'),
  828. t('Existence: 12 Extension: 1'),
  829. t('Existence: 11 Extension: 1'),
  830. t('Existence: 10 Extension: 1'),
  831. t('Existence: 9 Extension: 1'),
  832. )),
  833. t('BLOSUM45') => drupal_map_assoc(array(
  834. t('Existence: 13 Extension: 3'),
  835. t('Existence: 12 Extension: 3'),
  836. t('Existence: 11 Extension: 3'),
  837. t('Existence: 10 Extension: 3'),
  838. t('Existence: 15 Extension: 2'),
  839. t('Existence: 14 Extension: 2'),
  840. t('Existence: 13 Extension: 2'),
  841. t('Existence: 12 Extension: 2'),
  842. t('Existence: 19 Extension: 1'),
  843. t('Existence: 18 Extension: 1'),
  844. t('Existence: 17 Extension: 1'),
  845. t('Existence: 16 Extension: 1'),
  846. )),
  847. t('BLOSUM50') => drupal_map_assoc(array(
  848. t('Existence: 13 Extension: 3'),
  849. t('Existence: 12 Extension: 3'),
  850. t('Existence: 11 Extension: 3'),
  851. t('Existence: 10 Extension: 3'),
  852. t('Existence: 9 Extension: 3'),
  853. t('Existence: 16 Extension: 2'),
  854. t('Existence: 15 Extension: 2'),
  855. t('Existence: 14 Extension: 2'),
  856. t('Existence: 13 Extension: 2'),
  857. t('Existence: 12 Extension: 2'),
  858. t('Existence: 19 Extension: 1'),
  859. t('Existence: 18 Extension: 1'),
  860. t('Existence: 17 Extension: 1'),
  861. t('Existence: 16 Extension: 1'),
  862. t('Existence: 15 Extension: 1'),
  863. )),
  864. t('BLOSUM90') => drupal_map_assoc(array(
  865. t('Existence: 9 Extension: 2'),
  866. t('Existence: 8 Extension: 2'),
  867. t('Existence: 7 Extension: 2'),
  868. t('Existence: 6 Extension: 2'),
  869. t('Existence: 11 Extension: 1'),
  870. t('Existence: 10 Extension: 1'),
  871. t('Existence: 9 Extension: 1'),
  872. )),
  873. );
  874. if (isset($options[$key])) {
  875. return $options[$key];
  876. }
  877. else {
  878. return array();
  879. }
  880. }//_get_gap_for_matrix
  881. /**
  882. * Respond to Ajax dropdown call
  883. */
  884. function ajax_dependent_dropdown_callback($form, $form_state) {
  885. return $form['ALG']['SParam']['gapCost'];
  886. }
  887. /**
  888. * @section
  889. * tBLASTn: Search translated nucleotide database using a protein query.
  890. * ----------------------------------------------------------------------------
  891. */
  892. /**
  893. * Adds the tBLASTn Advanced Options to the passed in form.
  894. *
  895. * This form function is meant to be called within another form definition.
  896. *
  897. * @param $form
  898. * The form the advanced options should be added to. This form already
  899. * contains a $form['ALG'] fieldset meant to contain the advanced options.
  900. * @param $formstate
  901. * The current state fo the form passed in as $form.
  902. */
  903. function blast_ui_tblastn_advanced_options_form(&$form, $form_state) {
  904. $all_job_data = variable_get('job_data', '');
  905. if (isset($_GET['jid']) && isset($all_job_data)) {
  906. $jid = base64_decode($_GET['jid']);
  907. $job_data = $all_job_data[$jid];
  908. }
  909. else {
  910. $job_data = array();
  911. $jid = 0;
  912. }
  913. $defaults = _get_default_values($job_data, 'tblastn');
  914. $form['ALG']['GParam'] = array(
  915. '#type' => 'fieldset',
  916. '#title' => t('General parameters'),
  917. '#collapsible' => FALSE,
  918. );
  919. $form['ALG']['GParam']['maxTarget'] = array(
  920. '#type' => 'select',
  921. '#title' => t('Max target sequences:'),
  922. '#options' => _get_max_target('tblastn'),
  923. '#default_value' => $defaults['max_target_seqs'],
  924. '#description' => t('Select the maximum number of aligned sequences to display'),
  925. );
  926. $form['ALG']['GParam']['eVal'] = array(
  927. '#type' => 'textfield',
  928. '#title' => t('e-Value (Expected Threshold)'),
  929. '#default_value' => $defaults['evalue'],
  930. '#size' => 12,
  931. '#maxlength' => 20,
  932. '#description' => t('Expected number of chance matches in a random model. This number should be give in a decimal format. <a href="http://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>'),
  933. );
  934. /*eksc- need to learn how this is implemented for tblastn
  935. $form['ALG']['GParam']['shortQueries'] = array(
  936. '#type' => 'checkbox',
  937. '#title' => t('Automatically adjust parameters for short input sequences'),
  938. '#default_value' => TRUE,
  939. );
  940. */
  941. $form['ALG']['GParam']['wordSize'] = array(
  942. '#type' => 'select',
  943. '#title' => t('Word size:'),
  944. '#options' => _get_word_size('tblastn'),
  945. '#default_value' => $defaults['word_size'],
  946. '#description' => t('The length of the seed that initiates an alignment'),
  947. );
  948. // Scoring parameters
  949. //.........................
  950. $form['ALG']['SParam'] = array(
  951. '#type' => 'fieldset',
  952. '#title' => t('Scoring parameters'),
  953. '#collapsible' => FALSE,
  954. );
  955. $matrix_options = _get_matrix_options();
  956. $form['ALG']['SParam']['Matrix'] = array(
  957. '#type' => 'select',
  958. '#title' => 'Matrix',
  959. '#options' => $matrix_options,
  960. '#default_value' => $defaults['matrix'],
  961. '#description' => t('Assigns a score for aligning pairs of residues, and determines overall alignment score..'),
  962. '#ajax' => array(
  963. 'callback' => 'ajax_dependent_dropdown_callback',
  964. 'wrapper' => 'dropdown-second-replace',
  965. ),
  966. );
  967. $form['ALG']['SParam']['gapCost'] = array(
  968. '#type' => 'select',
  969. '#title' => t('Gap Costs:'),
  970. '#prefix' => '<div id="dropdown-second-replace">',
  971. '#suffix' => '</div>',
  972. '#options' => _get_gap_for_matrix($$default['matrix']),
  973. '#default_value' => 2,
  974. '#description' => t('Cost to create and extend a gap in an alignment.'),
  975. );
  976. $form['ALG']['GParam']['qRange'] = array(
  977. '#type' => 'textfield',
  978. '#title' => t('Max matches in a query range'),
  979. '#default_value' => $defaults['qRange'],
  980. '#size' => 12,
  981. '#maxlength' => 20,
  982. '#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.'),
  983. );
  984. }//blast_ui_tblastn_advanced_options_form
  985. /**
  986. * Validate the advanced options provided by the tBLASTn form above.
  987. *
  988. * @see blast_ui_tblastn_advanced_options_form().
  989. */
  990. function blast_ui_tblastn_advanced_options_form_validate($form, $form_state) { }
  991. /**
  992. * Processed the advanced options provided by the tBLASTn form above.
  993. *
  994. * @see blast_ui_tblastn_advanced_options_form().
  995. */
  996. function blast_ui_tblastn_advanced_options_form_submit($form, $form_state) {
  997. return blast_ui_blastp_advanced_options_form_submit($form, $form_state);
  998. }
  999. /*
  1000. * Get default form values; may come from saved job data if user is re-running
  1001. * a previous job.
  1002. */
  1003. function _get_default_values($job_data) {
  1004. // restore previous values or set to default
  1005. $max_target = (isset($job_data['options']['max_target_seqs']))
  1006. ? $job_data['options']['max_target_seqs'] : 10;
  1007. $short_queries = (isset($job_data['options']['shortQueries']))
  1008. ? $job_data['options']['shortQueries'] : true;
  1009. $evalue = (isset($job_data['options']['evalue']))
  1010. ? $job_data['options']['evalue'] : .001;
  1011. $word_size = (isset($job_data['options']['word_size']))
  1012. ? $job_data['options']['word_size'] : 11;
  1013. $qRange = (isset($job_data['options']['culling_limit']))
  1014. ? $job_data['options']['culling_limit'] : 0;
  1015. $matchmiss = 0;
  1016. $reward = (isset($job_data['options']['reward']))
  1017. ? $job_data['options']['reward'] : 1;
  1018. $penalty = (isset($job_data['options']['penalty']))
  1019. ? $job_data['options']['penalty'] : -2;
  1020. if ($reward == 1) {
  1021. switch ($penalty) {
  1022. case -1: $matchmiss = 5; break;
  1023. case -2: $matchmiss = 0; break;
  1024. case -3: $matchmiss = 1; break;
  1025. case -4: $matchmiss = 2; break;
  1026. }
  1027. }
  1028. else if ($reward == 2) {
  1029. $matchmiss = 3;
  1030. }
  1031. else if ($reward == 3) {
  1032. $matchmis = 4;
  1033. }
  1034. else if ($eward == 4) {
  1035. $matchmiss = 5;
  1036. }
  1037. $gap = 0;
  1038. $gapopen = (isset($job_data['options']['gapopen']))
  1039. ? $job_data['options']['gapopen'] : 5;
  1040. $gapextend = (isset($job_data['options']['gapextend']))
  1041. ? $job_data['options']['gapextend'] : 2;
  1042. if ($gapextend == 2) {
  1043. switch ($gapopen) {
  1044. case 5: $gap = 0; break;
  1045. case 2: $gap = 1; break;
  1046. case 1: $gap = 2; break;
  1047. case 0: $gap = 3; break;
  1048. }
  1049. }
  1050. else if ($gapextend == 1) {
  1051. switch ($gapopen) {
  1052. case 3: $gap = 4;
  1053. case 2: $gap = 5;
  1054. case 1: $gap = 6;
  1055. }
  1056. }
  1057. // eksc- need to implement query range limit
  1058. // $q_range = 0;
  1059. $matrix = (isset($job_data['options']['matrix']))
  1060. ? $job_data['options']['matrix'] : 'PAM30';
  1061. return array(
  1062. 'max_target_seqs' => $max_target,
  1063. 'short_queries' => $short_queries,
  1064. 'word_size' => $word_size,
  1065. 'evalue' => $evalue,
  1066. 'matchmiss' => $matchmiss,
  1067. 'gap' => $gap,
  1068. 'qRange' => $qRange,
  1069. 'matrix' => $matrix,
  1070. );
  1071. }//_get_default_values
  1072. function _get_max_target($which) {
  1073. switch ($which) {
  1074. case 'blastn':
  1075. case 'blastx':
  1076. case 'blastp':
  1077. case 'tblastn':
  1078. return array(
  1079. 10 => t('10'),
  1080. 50 => t('50'),
  1081. 100 => t('100'),
  1082. 250 => t('250'),
  1083. 500 => t('500'),
  1084. 1000 => t('1000'),
  1085. 5000 => t('5000'),
  1086. 10000 => t('10000'),
  1087. 20000 => t('20000'),
  1088. );
  1089. }//switch
  1090. }
  1091. function _get_word_size($which) {
  1092. switch ($which) {
  1093. case 'blastn':
  1094. return array(
  1095. 7 => t('7'),
  1096. 11 => t('11'),
  1097. 15 => t('15'),
  1098. 16 => t('16'),
  1099. 20 => t('20'),
  1100. 24 => t('24'),
  1101. 28 => t('28'),
  1102. 32 => t('32'),
  1103. 48 => t('48'),
  1104. 64 => t('64'),
  1105. 128 => t('128'),
  1106. 256 => t('256'),
  1107. );
  1108. case 'blastx':
  1109. case 'blastp':
  1110. case 'tblastn':
  1111. return array(
  1112. 2 => t('2'),
  1113. 3 => t('3'),
  1114. 6 => t('6'),
  1115. );
  1116. }//switch
  1117. }
  1118. function _get_match_mismatch($which) {
  1119. switch ($which) {
  1120. case 'blastn':
  1121. return array(
  1122. 0 => t('1,-2'),
  1123. 1 => t('1,-3'),
  1124. 2 => t('1,-4'),
  1125. 3 => t('2,-3'),
  1126. 4 => t('4,-5'),
  1127. 5 => t('1,-1'),
  1128. );
  1129. }//switch
  1130. }
  1131. function _get_gap($which) {
  1132. switch ($which) {
  1133. case 'blastn':
  1134. return array(
  1135. 0 => t('Existence: 5 Extension: 2'),
  1136. 1 => t('Existence: 2 Extension: 2'),
  1137. 2 => t('Existence: 1 Extension: 2'),
  1138. 3 => t('Existence: 0 Extension: 2'),
  1139. 4 => t('Existence: 3 Extension: 1'),
  1140. 5 => t('Existence: 2 Extension: 1'),
  1141. 6 => t('Existence: 1 Extension: 1'),
  1142. );
  1143. }//switch
  1144. }
  1145. function _set_gap($gap_key) {
  1146. switch ($gap_key) {
  1147. case 0:
  1148. $gapOpen = 5;
  1149. $gapExtend = 2;
  1150. break;
  1151. case 1:
  1152. $gapOpen = 2;
  1153. $gapExtend = 2;
  1154. break;
  1155. case 2:
  1156. $gapOpen = 1;
  1157. $gapExtend = 2;
  1158. break;
  1159. case 3:
  1160. $gapOpen = 0;
  1161. $gapExtend = 2;
  1162. break;
  1163. case 4:
  1164. $gapOpen = 3;
  1165. $gapExtend = 1;
  1166. break;
  1167. case 5:
  1168. $gapOpen = 2;
  1169. $gapExtend = 1;
  1170. break;
  1171. case 6:
  1172. $gapOpen = 1;
  1173. $gapExtend = 1;
  1174. break;
  1175. }//switch
  1176. return array('gapOpen' => $gapOpen, 'gapExtend' => $gapExtend);
  1177. }
  1178. function _set_match_mismatch($m_m) {
  1179. switch ($m_m) {
  1180. case 0:
  1181. $penalty = -2;
  1182. $reward = 1;
  1183. break;
  1184. case 1:
  1185. $penalty = -3;
  1186. $reward = 1;
  1187. break;
  1188. case 2:
  1189. $penalty = -4;
  1190. $reward = 1;
  1191. break;
  1192. case 3:
  1193. $penalty = -3;
  1194. $reward = 2;
  1195. break;
  1196. case 4:
  1197. $penalty = -5;
  1198. $reward = 4;
  1199. break;
  1200. case 5:
  1201. $penalty = -1;
  1202. $reward = 1;
  1203. break;
  1204. }//switch
  1205. return array('penalty' => $penalty, 'reward' => $reward);
  1206. }