<p>For semantic purposes, it's better to use the reference sequence as the pattern. Note that only the pattern argument can be used as a multi-element vector, i.e. you can match multiple patterns against a single subject with this function, but not a single pattern against multiple subjects. Knowing that might alter what is defined as a "pattern" or a "subject".</p>

<p>The scores are associated with the alignment method that is used. Alignment scores are higher for more similar matches and lower for poor matches, but the weightings associated with matches and mismatches dictate what that actually means. It might be that a score of -2 happens to be the optimal alignment score, because all other possible alignments are more negative.</p>

<p>It's possible to use <code>pairwiseAlignment</code> to generate the levenshtein distance (most commonly-used edit distance) between two sequences by setting the match score to 0, the mismatch score to -1, gap opening penalty to 0, gap extension penalty to 1, and then negating the resultant <code>pairwiseAlignment</code> score.</p>

CC BY-SA 3.0
2018-04-05T23:18:50.167Z
2018-04-05T23:18:50.167Z
gringer
<p>According to the <a href="https://www.rdocumentation.org/packages/Biostrings/versions/2.40.2/topics/pairwiseAlignment" rel="nofollow noreferrer">help page</a>, it seems more logic to put the reference sequence in <code>subject</code>, and your query sequence in <code>pattern</code>, but it won't really matter for the outcome (except that the pattern sequence will be on top of the alignment).</p>

<p>For your second question: </p>

<blockquote>
  <p>the scores for the optimal pairwise alignments is returned</p>
</blockquote>

CC BY-SA 3.0
2018-04-05T07:53:20.900Z
2018-04-05T07:53:20.900Z
benn
<p>I'm a bit confused and would appreciate your assistance, please.</p>

<p>I'm trying to use the <code>pairwiseAlignment</code> function from the <code>Biostrings</code> package to align two protein sequences.</p>

<p>I'm not quite sure where to put my reference sequence, the sequence I want to compare to. Is it under "subject" or "pattern"?</p>

<p>Also, is the score I get the edit distance? Is it the alignment score? Or is it the the alignment length? When I use local alignment, will the score be higher the more the sequences resemble each other? And when I use global alignment, will the score be lower the more the sequences resemble each other?</p>

<r><phylogenetics>
Question regarding the function pairwiseAlignment in R
# Question regarding the function pairwiseAlignment in R

(Asked by: username_0 on 2018-04-05)

I'm a bit confused and would appreciate your assistance, please.

I'm trying to use the `pairwiseAlignment` function from the `Biostrings` package to align two protein sequences.

I'm not quite sure where to put my reference sequence, the sequence I want to compare to. Is it under "subject" or "pattern"?

Also, is the score I get the edit distance? Is it the alignment score? Or is it the the alignment length? When I use local alignment, will the score be higher the more the sequences resemble each other? And when I use global alignment, will the score be lower the more the sequences resemble each other?

**Tags:** r, phylogenetics

---

## 2 answers

### Answer by username_1 on 2018-04-05. Score: 2 | Accepted answer

For semantic purposes, it's better to use the reference sequence as the pattern. Note that only the pattern argument can be used as a multi-element vector, i.e. you can match multiple patterns against a single subject with this function, but not a single pattern against multiple subjects. Knowing that might alter what is defined as a "pattern" or a "subject".

The scores are associated with the alignment method that is used. Alignment scores are higher for more similar matches and lower for poor matches, but the weightings associated with matches and mismatches dictate what that actually means. It might be that a score of -2 happens to be the optimal alignment score, because all other possible alignments are more negative.

It's possible to use `pairwiseAlignment` to generate the levenshtein distance (most commonly-used edit distance) between two sequences by setting the match score to 0, the mismatch score to -1, gap opening penalty to 0, gap extension penalty to 1, and then negating the resultant `pairwiseAlignment` score.


---

### Answer by username_2 on 2018-04-05. Score: 2

According to the [help page](https://www.rdocumentation.org/packages/Biostrings/versions/2.40.2/topics/pairwiseAlignment), it seems more logic to put the reference sequence in `subject`, and your query sequence in `pattern`, but it won't really matter for the outcome (except that the pattern sequence will be on top of the alignment).

For your second question:

> the scores for the optimal pairwise alignments is returned


---

