Answers.Body: <p>Here's my working solution,</p>
  <p>So I found a choice of parameters that resolves this, <code>-reward 3 -gapopen 5 -gapextend 5</code>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-10-08T17:17:27.337Z
Answers.LastActivityDate: 2021-10-08T17:17:27.337Z
Answers.UserDisplayName: Set
Body: <p>In my work I've found that in circumstances where there is a mismatch near the edges of the query sequence, blastn prefers to return a shorter contiguous alignment, rather than allowing for a mismatch near the 5' or 3' end of the query sequence.</p>
  <p>For example, consider the subject sequence (bold indicates alignment with mismatch in brackets):</p>
  <p>GACCAACCTG<strong>CTGGATCTGCTGATCGGCG[G]T</strong>TTGCGAAATA</p>
  <p>and query sequence:</p>
  <p>CTGGATCTGCTGATCGGCG[A]T</p>
  <p>Blasting this will return the 19bp contiguous alignment upstream of the mismatch, rather than returning a 21bp alignment with a single mismatch at the G/A base at position 20 in the query.</p>
  <p>I'm using the command line version of blastn, and I've tried messing with the penalties as well as setting <code>-task blastn-short</code>, but nothing seems to fix this issue.</p>
  <p>I speculate that the various gap and mismatch penalties are working out such that a shorter contiguous alignment is preferred over a slightly longer alignment with a mismatch, but I haven't been able to figure out how to modify the penalties in such a way as to change this preference.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-08T09:20:52.357Z
Comments.Text: Nope, altering the weights is the solution as you said. So please do answer your own question —this a totally encouraged behaviour.
Comments.UserDisplayName: Matteo Ferla
Tags: <phylogenetics><blast><blastn>
Title: blastn returning an inferior alignment
ThreadText: # blastn returning an inferior alignment
  
  (Asked by: username_0 on 2021-10-07)
  
  In my work I've found that in circumstances where there is a mismatch near the edges of the query sequence, blastn prefers to return a shorter contiguous alignment, rather than allowing for a mismatch near the 5' or 3' end of the query sequence.
  
  For example, consider the subject sequence (bold indicates alignment with mismatch in brackets):
  
  GACCAACCTG**CTGGATCTGCTGATCGGCG[G]T**TTGCGAAATA
  
  and query sequence:
  
  CTGGATCTGCTGATCGGCG[A]T
  
  Blasting this will return the 19bp contiguous alignment upstream of the mismatch, rather than returning a 21bp alignment with a single mismatch at the G/A base at position 20 in the query.
  
  I'm using the command line version of blastn, and I've tried messing with the penalties as well as setting `-task blastn-short`, but nothing seems to fix this issue.
  
  I speculate that the various gap and mismatch penalties are working out such that a shorter contiguous alignment is preferred over a slightly longer alignment with a mismatch, but I haven't been able to figure out how to modify the penalties in such a way as to change this preference.
  
  **Tags:** phylogenetics, blast, blastn
  
  > **Comments:**
  > **username_1**: Nope, altering the weights is the solution as you said. So please do answer your own question —this a totally encouraged behaviour.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-10-08. Score: 0 | Accepted answer
  
  Here's my working solution,
  
  So I found a choice of parameters that resolves this, `-reward 3 -gapopen 5 -gapextend 5`.
  
  
  ---
  
  