blast_ui.form_advanced_options.inc 42 KB

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