blast_ui.form_advanced_options.inc 42 KB

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