blast_ui.form_advanced_options.inc 36 KB

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