<p>Disclaimer: I don't have adagenet and hierfstat installed, I just looked at the source code. It seems like pairwise.fst (the deprecated code from the adagenet package, which you seem to be using) already returns a matrix. Set res.type="matrix" and try calling <code>rownames(f)</code> and <code>colnames(f)</code> afterwards.</p>

CC BY-SA 3.0
2017-06-29T03:31:07.683Z
Worked a treat, thanks! I'm using pairwise.fst because it is the method mentioned in this tutorial from 2015 http://adegenet.r-forge.r-project.org/files/tutorial-basics.pdf. Where did you read that it is deprecated?
flashton
CC BY-SA 3.0
2017-06-29T11:10:25.377Z
I was searching for the source code. There are pairwise.fst functions in adagenet and in hierfstat. If you look at the function in the [adagenet repo](https://github.com/cran/adegenet), you will see that it is commented out (R/fstat.R). It is, to my (limited) understanding, one of the functions that have been outsourced/exported to the `hierfstat` package.
galicae
CC BY-SA 3.0
2017-06-28T08:23:44.230Z
2017-06-28T08:23:44.230Z
galicae
<p>I have a distance matrix generated by hierfstat, thusly, with a link to the fasta file <a href="https://www.dropbox.com/s/z9n89y080hvl3s2/2017.06.13.strucutre_test.masked.snp_sites.v2_3_2.subsample.fa?dl=0" rel="noreferrer">here</a>:</p>

<pre><code>library(adegenet)
library(hierfstat)
snps &lt;- fasta2DNAbin('test.fa', chunkSize = 50)
gi &lt;- DNAbin2genind(snps)
# manually define the populations for passing to pairwise.fst
p &lt;- c('Botswana', 'Botswana', 'Botswana', 'Botswana', 'France', 'France', 'Vietnam', 'Vietnam', 'Uganda', 'Uganda', 'Uganda', 'Uganda', 'Vietnam', 'Vietnam', 'Laos', 'Laos', 'Laos', 'Vietnam', 'Vietnam', 'Vietnam', 'Vietnam', 'Vietnam')
f &lt;- pairwise.fst(gi, p, res.type = c('dist', 'matrix'))
as.matrix(f)
</code></pre>

<p>which produces</p>

<pre><code>    1   2   3   4   5
1   0   0.2189008   0.225567409 0.1821518   0.259409722
2   0.2189008   0   0.130736953 0.1648034   0.191050772
3   0.2255674   0.130737    0   0.1669077   0.006396789
4   0.1821518   0.1648034   0.166907683 0   0.203931457
5   0.2594097   0.1910508   0.006396789 0.2039315   0
</code></pre>

<p>Is it safe to assume that 1 = Botswana, 2 = France, 3 = Vietnam, 4 = Uganda and 5 = Laos? i.e. that the distance matrix rows/columns follow the order that each population first appeared in <code>p</code>?</p>

<p>Is there a way to determine for certain, which row/column in the distance matrix corresponds to which population?</p>

CC BY-SA 3.0
2017-06-28T07:10:43.873Z
Welcome to Bioinformatics! You can change the order of your columns in the input and see how is the output, if the columns in the output follow the columns in the input, then  it would be safer. But this is from adegenet package, isn't it? Could you provide some test data to try myself? Otherwise you could check the source code of pairwise.fst
llrs
CC BY-SA 3.0
2017-06-28T08:08:23.520Z
added a test file and the libraries I was using :-) i guess i _could_ go into the source code or permute the samples to check, but seems sensible that there would be a option just to print them somehow...
flashton
<r>
What are the labels in my rstats distance matrix?
# What are the labels in my rstats distance matrix?

(Asked by: username_0 on 2017-06-28)

I have a distance matrix generated by hierfstat, thusly, with a link to the fasta file here:
library(adegenet)
library(hierfstat)
snps <- fasta2DNAbin('test.fa', chunkSize = 50)
gi <- DNAbin2genind(snps)
# manually define the populations for passing to pairwise.fst
p <- c('Botswana', 'Botswana', 'Botswana', 'Botswana', 'France', 'France', 'Vietnam', 'Vietnam', 'Uganda', 'Uganda', 'Uganda', 'Uganda', 'Vietnam', 'Vietnam', 'Laos', 'Laos', 'Laos', 'Vietnam', 'Vietnam', 'Vietnam', 'Vietnam', 'Vietnam')
f <- pairwise.fst(gi, p, res.type = c('dist', 'matrix'))
as.matrix(f)

which produces
    1   2   3   4   5
1   0   0.2189008   0.225567409 0.1821518   0.259409722
2   0.2189008   0   0.130736953 0.1648034   0.191050772
3   0.2255674   0.130737    0   0.1669077   0.006396789
4   0.1821518   0.1648034   0.166907683 0   0.203931457
5   0.2594097   0.1910508   0.006396789 0.2039315   0

Is it safe to assume that 1 = Botswana, 2 = France, 3 = Vietnam, 4 = Uganda and 5 = Laos? i.e. that the distance matrix rows/columns follow the order that each population first appeared in p?
Is there a way to determine for certain, which row/column in the distance matrix corresponds to which population?

**Tags:** r
> **Comments:**
> **username_1**: Welcome to Bioinformatics! You can change the order of your columns in the input and see how is the output, if the columns in the output follow the columns in the input, then  it would be safer. But this is from adegenet package, isn't it? Could you provide some test data to try myself? Otherwise you could check the source code of pairwise.fst  
> **username_0**: added a test file and the libraries I was using :-) i guess i _could_ go into the source code or permute the samples to check, but seems sensible that there would be a option just to print them somehow...  

---

## 1 answers

### Answer by username_2 on 2017-06-28. Score: 2 | Accepted answer

Disclaimer: I don't have adagenet and hierfstat installed, I just looked at the source code. It seems like pairwise.fst (the deprecated code from the adagenet package, which you seem to be using) already returns a matrix. Set res.type="matrix" and try calling `rownames(f)` and `colnames(f)` afterwards.

> **Comments:**
> **username_0**: Worked a treat, thanks! I'm using pairwise.fst because it is the method mentioned in this tutorial from 2015 http://adegenet.r-forge.r-project.org/files/tutorial-basics.pdf. Where did you read that it is deprecated?  
> **username_2**: I was searching for the source code. There are pairwise.fst functions in adagenet and in hierfstat. If you look at the function in the [adagenet repo](https://github.com/cran/adegenet), you will see that it is commented out (R/fstat.R). It is, to my (limited) understanding, one of the functions that have been outsourced/exported to the `hierfstat` package.  

---

