blast_ui.form_advanced_options.inc 36 KB

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