Running a multi-level AMOVA from a genind object and defining/splitting strata

638 views
Skip to first unread message

Emily Helliwell

unread,
Mar 28, 2018, 6:25:56 PM3/28/18
to poppr


Hello Zhian,

I am trying to run a multi-level AMOVA with a SNP dataset (diploid organism, 9,568 loci), and I am having a little bit of trouble.  Here is my workflow:

1) Convert dataframe to genind object

2) Define and split strata

3) Run AMOVA


The conversion to genind object works, but I am unable to define the columns that list the individuals and their population (individuals are the first column, Population is the second column): This is the script I am using:

Mpol_genind <- df2genind(Mpol_wout_USDA, sep = NULL, ncode = 1, ind.names = NA,
                         loc.names = NULL, pop = NA, NA.char = "99", ploidy = 2,
                         type = c("codom", "PA"), strata = NULL, hierarchy = NA)

I have tried listing the column names to ind.names and pop, but they cannot be found.  This is probably something very obvious that I am missing (not great with R).

So, I imagine this is why when I try to go on and define the strata that I get an error message stating that the strata is Empty.  Eventually I would like to split the strata into Populations within a Range, but I would like to solve this problem first.

Here is my attempt at running an AMOVA, although it did not really have a chance at working since there was no defined strata:

Mpol_genid_amova <- poppr.amova(Mpol_genind, hier = "Range_Population", clonecorrect = FALSE, within = TRUE,
                                dist = NULL, squared = TRUE, correction = "quasieuclid",
                                sep = "", filter = FALSE, threshold = 0,
                                algorithm = "farthest_neighbor", missing = "loci", cutoff = 0.05,
                                quiet = FALSE, method = c("ade4", "pegas"), nperm = 0)

Any obvious fixes to this?  

Thank you so much,
-Emily

Zhian Kamvar

unread,
Mar 29, 2018, 11:31:24 AM3/29/18
to Emily Helliwell, poppr
Hello,

The conversion to genind object works, but I am unable to define the columns that list the individuals and their population (individuals are the first column, Population is the second column): This is the script I am using:

Mpol_genind <- df2genind(Mpol_wout_USDA, sep = NULL, ncode = 1, ind.names = NA,
                         loc.names = NULL, pop = NA, NA.char = "99", ploidy = 2,
                         type = c("codom", "PA"), strata = NULL, hierarchy = NA)

I have tried listing the column names to ind.names and pop, but they cannot be found.  This is probably something very obvious that I am missing (not great with R).

Side note: since all of the function calls have a lot of default arguments, I am trimming them to highlight where I made changes. Though it IS a good idea to inspect the defaults and make sure they make sense for your situation. 

What you should do is use subsetting to provide the individual names and population names like so:

Mpol_genind <- df2genind(
    Mpol_wout_USDA[, -(1:2)],        # remove first two columns
    ncode = 1,
    ind.names = Mpol_wout_USDA[[1]], # pull out the vector of individuals
    pop = Mpol_wout_USDA[[2]],       # pull out the population vector
    NA.char = "99",
    ploidy = 2,
    type = "codom"                   # SNP data are codominant
  )

From here, you can define strata with:

splitStrata(Mpol_genind) <- ~Range/Population/ETC # you should make sure that these are in the right order

From there, any argument in a function asking for strata or hierarchy will take the same form as above, so your AMOVA could look like this.

Mpol_genid_amova <-poppr.amova(
    Mpol_genind,
    hier = ~Range/Population  # This is how you access the strata
  )

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




--
You received this message because you are subscribed to the Google Groups "poppr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to poppr+un...@googlegroups.com.
To post to this group, send email to po...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/poppr/03d5f40c-652b-4268-ab5d-936037cb056e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc

Zhian Kamvar

unread,
Mar 29, 2018, 4:22:23 PM3/29/18
to Emily Helliwell, poppr
Hi Emily,

I realized that I included a slight error in my initial reply. I forgot to include the strata (this is done automagically in read.genalex):

Mpol_genind <- df2genind(
    Mpol_wout_USDA[, -(1:2)],        # remove first two columns
    ncode = 1,
    ind.names = Mpol_wout_USDA[[1]], # pull out the vector of individuals
    pop = Mpol_wout_USDA[[2]],       # pull out the population vector
    strata = Mpol_wout_USDA[2],      # Set the strata from the second column
    NA.char = "99",
    ploidy = 2,
    type = "codom"                   # SNP data are codominant
  )

-----
Zhian N. Kamvar, Ph. D.
Postdoctoral Researcher (Everhart Lab)
Department of Plant Pathology
University of Nebraska-Lincoln
ORCID: 0000-0003-1458-7108



On Mar 29, 2018, at 15:18 , Emily Helliwell <emily.h...@gmail.com> wrote:

Hello Zhian,

Thanks for the quick reply.  I ran the df2genind code that you specified above, and it worked to correctly identify the individual and population columns.  However, the splitStrata line did not seem to work.  This is the output:

> splitStrata(Mpol_genind) <- ~Range/Population
Warning message:
Cannot split empty strata 

I went ahead and tried to run an amova at the population level, specifying this code:

> Mpol_genid_amova <-poppr.amova(
+   Mpol_genind,
+   hier = ~Range/Population  # This is how you access the strata
+ )

Error in `row.names<-.data.frame`(`*tmp*`, value = value) : 
  invalid 'row.names' length
In addition: Warning messages:
1: Cannot set the population from an empty strata 
2: In df2genind(separate_haplotypes(x), ploidy = 1, strata = df) :
  entirely non-type individual(s) deleted

I know that I probably am lacking a few function calls, but maybe I also need a line defining the strata before it can be split?
Is there anything obvious that I am missing?
Thanks again for your help!
-Emily
 

To unsubscribe from this group and stop receiving emails from it, send an email to poppr+unsubscribe@googlegroups.com.
signature.asc
Reply all
Reply to author
Forward
0 new messages