<p>I’d like to perform the following, but I am having difficulty.</p>
<p>I want to convert amino acid sequences in multifasta files into matrices (or vectors) with Euclidean distance and Pearson correlation coefficient.</p>
<p>If you know a solution, please let me know. Thanking you in advance.</p>
<h3>File1</h3>
<pre><code>&gt;BDP27474.1 |surface glycoprotein [Severe acute respiratory syndrome coronavirus 2]
MFVFLVLLPL
&gt;BDP27485.1 |surface glycoprotein [Severe acute respiratory syndrome coronavirus 2]
MFVFLVLLPL
</code></pre>
<h3>File2</h3>
<pre><code>&gt;BDD77411.1 |surface glycoprotein [Severe acute respiratory syndrome coronavirus 2]
MFVFLVLLPL
&gt;BDD77515.1 |surface glycoprotein [Severe acute respiratory syndrome coronavirus 2]
MFVFFVLLPL
</code></pre>
<h3>Code</h3>
<pre><code>library(tidyverse)
library(ape)
library(Biostrings)

naseq1 &lt;- readAAStringSet(&quot;File1.fasta&quot;)
naseq2 &lt;- readAAStringSet(&quot;File2.fasta&quot;)

dist.aa(naseq1)
dist.aa(naseq2)

##Error in numeric(n * (n - 1)/2) : invalid 'length' argument
</code></pre>
<h3>Add info.</h3>
<p>iOS 10.15, Rstudio cloud</p>

CC BY-SA 4.0
2022-07-26T15:19:27.083Z
There's no matrix for file1 because MFVFLVLLPL and MFVFLVLLPL are identical
M__
CC BY-SA 4.0
2022-07-27T08:13:10.030Z
You are probably looking for Biostrings::stringDist to compare both strings
llrs
<fasta><r>
How to calculate distance matrix from fasta?
# How to calculate distance matrix from fasta?

(Asked by: username_0 on 2022-07-25)

I’d like to perform the following, but I am having difficulty.
I want to convert amino acid sequences in multifasta files into matrices (or vectors) with Euclidean distance and Pearson correlation coefficient.
If you know a solution, please let me know. Thanking you in advance.
File1
>BDP27474.1 |surface glycoprotein [Severe acute respiratory syndrome coronavirus 2]
MFVFLVLLPL
>BDP27485.1 |surface glycoprotein [Severe acute respiratory syndrome coronavirus 2]
MFVFLVLLPL

File2
>BDD77411.1 |surface glycoprotein [Severe acute respiratory syndrome coronavirus 2]
MFVFLVLLPL
>BDD77515.1 |surface glycoprotein [Severe acute respiratory syndrome coronavirus 2]
MFVFFVLLPL

Code
library(tidyverse)
library(ape)
library(Biostrings)

naseq1 <- readAAStringSet("File1.fasta")
naseq2 <- readAAStringSet("File2.fasta")

dist.aa(naseq1)
dist.aa(naseq2)

##Error in numeric(n * (n - 1)/2) : invalid 'length' argument

Add info.
iOS 10.15, Rstudio cloud

**Tags:** fasta, r
> **Comments:**
> **username_1**: There's no matrix for file1 because MFVFLVLLPL and MFVFLVLLPL are identical  
> **username_2**: You are probably looking for Biostrings::stringDist to compare both strings  

---

## 0 answers

