[adegenet-forum] newbie help: formatting xy data stored in genind object for use in a sPCA
Zhian Kamvar
zkamvar at gmail.com
Mon Nov 6 17:11:03 CET 2017
Hi Caroline,
To format your spatial data:
By default, spca will look in the "other" slot to find a data frame or matrix called "xy" that has numeric coordinates.
You have a matrix called "X" in your other slot, which contains character data. To convert the last two columns to xy coordinates, there are three steps: 1) subset X to the last two columns, 2) save these as a matrix in the "other" slot called "xy", 3) convert xy to numeric:
other(mydata)$xy <- other(mydata)$X[, 5:6]
mode(other(mydata)$xy) <- "numeric"
colnames(other(mydata)$xy) <- c("x", "y")
To format your trait data:
If you will be using any of the categorical traits to separate your data, you can add them as strata:
strata(mydata) <- as.data.frame(other(mydata)$X[, 1:3]) # you can rename them with nameStrata()
Otherwise, you can add the traits one by one to your "other" slot like so:
other(mydata)$sex <- other(mydata)$X[, 1, drop = TRUE]
...
I hope that helps,
Zhian
-----
Zhian N. Kamvar, Ph. D.
Postdoctoral Researcher (Everhart Lab)
Department of Plant Pathology
University of Nebraska-Lincoln
ORCID: 0000-0003-1458-7108
> Date: Fri, 3 Nov 2017 21:04:35 +0000
> From: "Judy (Duffie), Caroline" <JudyC at si.edu>
> To: "adegenet-forum at lists.r-forge.r-project.org"
> <adegenet-forum at lists.r-forge.r-project.org>
> Subject: [adegenet-forum] newbie help: formatting xy data stored in
> genind object for use in a sPCA
> Message-ID: <66466C5A-F609-46E1-9DCD-3DE3387BA55C at si.edu>
> Content-Type: text/plain; charset="utf-8"
>
> Dear Adegenet forum,
>
> I created a genind object using the ?read.structure? command. As you see in the code below - I specified the columns [,3:8] as ?other?. These original data contain four traits, and xy coordinates [,7:8]. After conversion to a genind object, the resulting structure of @other is a list with one object, $X, which is a 158 x 6 matrix. The columns represent the four traits and the x,y data stored in separate columns.
>
> How can I reformat $X to contain five objects: the four traits (each as a separate object), and an xy matrix as a single matrix with dimensions 158 x 2 for use in a downstream sPCA?
>
> Many thanks in advance for help.
> Caroline
>
> ------------------------------------------------------
>
>> mydata <- read.structure("~/Documents/Trochilus/second_chapter/Analysis/structure/input/GBS_all_pop_pheno.stru",
> + n.ind=158,
> + n.loc=6451,
> + onerowperin=TRUE,
> + col.lab=1,
> + col.pop=2,
> + col.others=3:8,
> + row.marknames=0,
> + ask=FALSE,
> + )
>
> Converting data from a STRUCTURE .stru file to a genind object...
>
>> mydata at other
> $X
> [,1] [,2] [,3] [,4] [,5] [,6]
> 1 "female" "black" "1" "3.72" "18.02911667" "-76.3886"
> 2 "female" "black" "1" "3.55" "18.02911667" "-76.3886"
> 3 "male" "black" "1" "3.97" "18.02953333" "-76.38783333"
> 4 "male" "black" "1" "3.55" "18.0337" "-76.38993333"
> 5 "female" "black" "1" "3.735" "18.0337" "-76.38993333"
> 6 "male" "black" "1" "3.95" "18.0295" "-76.38831667"
> 7 "male" "black" "1" "3.99" "18.02953333" "-76.38783333"
>
> Caroline D. Judy
> PhD Candidate (LSU)
> Peter Buck Predoctoral Fellow (NMNH)
> email: judyc at si.edu<mailto:judyc at si.edu>
>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20171103/ae25fd0e/attachment-0001.html>
>
> ------------------------------
>
> _______________________________________________
> 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
>
> End of adegenet-forum Digest, Vol 111, Issue 3
> **********************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20171106/3e62cad7/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20171106/3e62cad7/attachment-0001.sig>
More information about the adegenet-forum
mailing list