blast_ui.form_advanced_options.inc 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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 vedio 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. );
  1115. }//switch
  1116. }
  1117. function _get_match_mismatch($which) {
  1118. switch ($which) {
  1119. case 'blastn':
  1120. return array(
  1121. 0 => t('1,-2'),
  1122. 1 => t('1,-3'),
  1123. 2 => t('1,-4'),
  1124. 3 => t('2,-3'),
  1125. 4 => t('4,-5'),
  1126. 5 => t('1,-1'),
  1127. );
  1128. }//switch
  1129. }
  1130. function _get_gap($which) {
  1131. switch ($which) {
  1132. case 'blastn':
  1133. return array(
  1134. 0 => t('Existence: 5 Extension: 2'),
  1135. 1 => t('Existence: 2 Extension: 2'),
  1136. 2 => t('Existence: 1 Extension: 2'),
  1137. 3 => t('Existence: 0 Extension: 2'),
  1138. 4 => t('Existence: 3 Extension: 1'),
  1139. 5 => t('Existence: 2 Extension: 1'),
  1140. 6 => t('Existence: 1 Extension: 1'),
  1141. );
  1142. }//switch
  1143. }
  1144. function _set_gap($gap_key) {
  1145. switch ($gap_key) {
  1146. case 0:
  1147. $gapOpen = 5;
  1148. $gapExtend = 2;
  1149. break;
  1150. case 1:
  1151. $gapOpen = 2;
  1152. $gapExtend = 2;
  1153. break;
  1154. case 2:
  1155. $gapOpen = 1;
  1156. $gapExtend = 2;
  1157. break;
  1158. case 3:
  1159. $gapOpen = 0;
  1160. $gapExtend = 2;
  1161. break;
  1162. case 4:
  1163. $gapOpen = 3;
  1164. $gapExtend = 1;
  1165. break;
  1166. case 5:
  1167. $gapOpen = 2;
  1168. $gapExtend = 1;
  1169. break;
  1170. case 6:
  1171. $gapOpen = 1;
  1172. $gapExtend = 1;
  1173. break;
  1174. }//switch
  1175. return array('gapOpen' => $gapOpen, 'gapExtend' => $gapExtend);
  1176. }
  1177. function _set_match_mismatch($m_m) {
  1178. switch ($m_m) {
  1179. case 0:
  1180. $penalty = -2;
  1181. $reward = 1;
  1182. break;
  1183. case 1:
  1184. $penalty = -3;
  1185. $reward = 1;
  1186. break;
  1187. case 2:
  1188. $penalty = -4;
  1189. $reward = 1;
  1190. break;
  1191. case 3:
  1192. $penalty = -3;
  1193. $reward = 2;
  1194. break;
  1195. case 4:
  1196. $penalty = -5;
  1197. $reward = 4;
  1198. break;
  1199. case 5:
  1200. $penalty = -1;
  1201. $reward = 1;
  1202. break;
  1203. }//switch
  1204. return array('penalty' => $penalty, 'reward' => $reward);
  1205. }