[adegenet-forum] distribution
Jombart, Thibaut
t.jombart at imperial.ac.uk
Fri Apr 23 16:40:16 CEST 2010
That's off-topic but... actually for exporting triangular matrices, no need to use cat:
toto=dist(1:5)
M <- as.matrix(toto)
M[upper.tri(M)] <- ""
write.table(M, file="M.txt")
There may be a need for adding an extra space at the begining of the file for some software.
Cheers
Thibaut.
________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] On Behalf Of Jombart, Thibaut [t.jombart at imperial.ac.uk]
Sent: 23 April 2010 15:27
To: Consuelo Hermosilla; adegenet-forum at lists.r-forge.r-project.org
Subject: Re: [adegenet-forum] distribution
Hello,
there is no automated way for using several input matrices in monmonier. You'll have to run several algorithms, one per matrix, or merge all your matrices into one e.g. by averaging your matrices possibly with after a standardization. It really depends on the question you ask to your data.
You can export triangular matrices in R (using cat and a bit of coding - that would be a question for R-help), but if you don't especially need triangular matrices for another software, then it's much simpler to export a square matrix.
Cheers
Thibaut.
________________________________________
From: Consuelo Hermosilla [cheluna at gmail.com]
Sent: 21 April 2010 14:03
To: Jombart, Thibaut; adegenet-forum at lists.r-forge.r-project.org
Subject: Re: [adegenet-forum] distribution
Thanks for your quick reply. :)
I'm still a little lost. I have used the Monmonier function with 1 dist matrix. But my I'm not sure if I can use a file with several matrices, instead of one single matrix (they are bootstraps). Is it possible?
And if I understand you well, then I cannot export the matrices in triangular format, can I?
Thanks!!
Consuelo
-------------
Consuelo Hermosilla
PhD student
Departamento de Ecología y Biología Animal
Departamento de Bioquímica, Genética e Inmunología, Área de Genética
Facultad de Ciencias del Mar
Campus de As Lagoas-Marcosende
Universidad de Vigo
36310 Vigo
SPAIN
Mobile: +34 692 633 298
oooO
( ) Oooo
( ( )
_) ) /
(_/
Stop Gaza Massacre
On Wed, Apr 21, 2010 at 1:45 PM, Jombart, Thibaut <t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk>> wrote:
Hello,
you can read your square matrices using read.table with adequate arguments. Use lapply to read all your matrices at once. You may also use 'dir', which will be useful to retrieve all the names of your files if they're stored in a single directory.
To export the matrices, make them square (as.matrix) and then used write.table. If you import a distance matrix in R, then you can convert it to a dist (as.dist) and use it in Monmonier.
Best
Thibaut
________________________________________
From: Consuelo Hermosilla [cheluna at gmail.com<mailto:cheluna at gmail.com>]
Sent: 21 April 2010 12:36
To: Jombart, Thibaut; adegenet-forum at lists.r-forge.r-project.org<mailto:adegenet-forum at lists.r-forge.r-project.org>
Subject: Re: [adegenet-forum] distribution
Hi Thibaut!
I'm remembering what you say "you can read anything into R, with more or less pain"... I'm experiencing some pain with dists again... Here is the thing. I have a bootstraped file with 1000 dist matrices from AFLPsurv... but they are square matrices... grrr.... I cannot use the as.dist function directly to transform them to triangular matrices. How can I do it? Do I need a loop? And then, if I manage it, how can I export them? I tried to export a single triangle matrix (using write.table) and it says "cannot coerce class "dist" into a data.frame"... Tricky...
My last question (hopefully) is related to this an to my previous monmonier question. Can I use this bootstraped file (if I manage to convert it) as the dist object for the monmonier function?
Thank you very much!!!
Consuelo
-------------
Consuelo Hermosilla
PhD student
Departamento de Ecología y Biología Animal
Departamento de Bioquímica, Genética e Inmunología, Área de Genética
Facultad de Ciencias del Mar
Campus de As Lagoas-Marcosende
Universidad de Vigo
36310 Vigo
SPAIN
Mobile: +34 692 633 298
oooO
( ) Oooo
( ( )
_) ) /
(_/
Stop Gaza Massacre
On Thu, Apr 15, 2010 at 5:21 PM, Jombart, Thibaut <t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk><mailto:t.jombart at imperial.ac.uk<mailto:t.jombart at imperial.ac.uk>>> wrote:
Dear Consuelo,
good question about searching in the archives... I don't know (shame on me). My best guess for now is googling a question preceeded by 'adegenet-forum'. For instance, if you google:
"adegenet-forum seppop"
then you find an appropriate discussion in the archives as first answer. Lucky enough, 'adegenet-forum horse riding' does not point to anything in the archives...
Thanks for pointing this out, I will mention that on the website.
As for your other question: you could read a triangular matrix into R (you can read anything into R, with more or less pain), but a more straightforward way is using 'as.dist' on your rectangular matrix.
M <- matrix(1:9, ncol=3)
M <- M + t(M)
diag(M) <- 0
M # M is a symmetric matrix
[,1] [,2] [,3]
[1,] 0 6 10
[2,] 6 0 14
[3,] 10 14 0
foo=as.dist(M)
foo # lower triangular matrix
1 2
2 6
3 10 14
Best regards
Thibaut
________________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org<mailto:adegenet-forum-bounces at lists.r-forge.r-project.org><mailto:adegenet-forum-bounces at lists.r-forge.r-project.org<mailto:adegenet-forum-bounces at lists.r-forge.r-project.org>> [adegenet-forum-bounces at lists.r-forge.r-project.org<mailto:adegenet-forum-bounces at lists.r-forge.r-project.org><mailto:adegenet-forum-bounces at lists.r-forge.r-project.org<mailto:adegenet-forum-bounces at lists.r-forge.r-project.org>>] On Behalf Of Consuelo Hermosilla [cheluna at gmail.com<mailto:cheluna at gmail.com><mailto:cheluna at gmail.com<mailto:cheluna at gmail.com>>]
Sent: 15 April 2010 14:48
To: adegenet-forum at lists.r-forge.r-project.org<mailto:adegenet-forum at lists.r-forge.r-project.org><mailto:adegenet-forum at lists.r-forge.r-project.org<mailto:adegenet-forum at lists.r-forge.r-project.org>>
Subject: [adegenet-forum] distribution
Hello Thibaut,
I'd like to know, how can I import a triangular matrix into R? For example, for amova analysis in pegas, the input distance matrix must be triangular. The thing is I have calculated the Fsts in Structure and I wanted to import them to run the Amova in pegas. But I don't know how to convert my square Fst matrix into a triangular one. I could save it as a triangular matrix, but R does not read triangular matrix, does it? Do you know how can I do it?
The other thing, is there a way to search in the past threads of the forum? I mean, instead of search in each month manually?
Thanks!!
Consuelo
-------------
Consuelo Hermosilla
PhD student
Departamento de Ecología y Biología Animal
Departamento de Bioquímica, Genética e Inmunología, Área de Genética
Facultad de Ciencias del Mar
Campus de As Lagoas-Marcosende
Universidad de Vigo
36310 Vigo
SPAIN
Mobile: +34 692 633 298
oooO
( ) Oooo
( ( )
_) ) /
(_/
Stop Gaza Massacre
_______________________________________________
adegenet-forum mailing list
adegenet-forum at lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum
More information about the adegenet-forum
mailing list