Subsetting snpclone object based on strata

29 views
Skip to first unread message

Victoria Glynn

unread,
Apr 28, 2022, 2:23:39 PM4/28/22
to poppr
Dear poppr community, 

I hope this finds you well. 

I would like to subset my snpclone object on the basis of another column in the data, which is stored under "strata." I could not find any documentation online that details how to do this, so any guidance would be much appreciated. 

Thank you in advance.

Best regards,

Victoria

Zhian Kamvar

unread,
Apr 28, 2022, 3:01:15 PM4/28/22
to Victoria Glynn, poppr
You can assign the strata column to the population slot by using `setPop()` (https://rdrr.io/cran/adegenet/man/population-methods.html) and then subset by population. For example if you have snpclone "x" with a strata that has the column "site" and you wanted to pull sites "A" and "B" from your data, you would use:

setPop(x) <- ~site
ab <- x[pop = c("A", "B")]

HTH,
Zhian

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/poppr/b3600712-cd80-412e-8101-74b0ce270f7en%40googlegroups.com.

Victoria Glynn

unread,
Apr 28, 2022, 4:00:17 PM4/28/22
to Zhian Kamvar, poppr
Hello Zhian,

Thank you for your prompt reply.

I have already defined populations as my different sampled sites, but I wish to provide a higher order classification. In my case, it seems to be we have two lineages in my data, which are defined in the strata column, and these are distributed across my various sites.

I would like to subset my data by lineage but keep the site information, to determine the MLGs called per site, for my two lineages independently. 

Would I need to re-define the lineages as my populations, and then set the sites (which are currently set as my populations) as my sub populations?

Thank you in advance for all your guidance. Please let me know if you have any questions or if I can provide you with any further information.

Best regards,

Victoria
--
Victoria Marie Glynn
B.S. Environmental Sciences | Honors Program
University of California, Berkeley | Class of 2019 
Phi Beta Kappa 
Ronald E. McNair Post-Baccalaureate Achievement Program

Zhian Kamvar

unread,
Apr 28, 2022, 7:11:36 PM4/28/22
to Victoria Glynn, poppr
Meant to send this to the list:

I would like to subset my data by lineage but keep the site information, to determine the MLGs called per site, for my two lineages independently. 

Would I need to re-define the lineages as my populations, and then set the sites (which are currently set as my populations) as my sub populations?

The strata information will stay with the object after you subset, so you could set the population by lineage and split by lineage using sepop() (https://rdrr.io/cran/adegenet/man/seppop.html), then set each population to site like so:

lineage_list <- seppop(x, ~lineage)
lineage_list <- lapply(lineage_list, function(i) setPop(i, ~site))
lineage_list$A # lineage A
lineage_list$B # lineage B

Victoria Glynn

unread,
Apr 28, 2022, 11:16:46 PM4/28/22
to Zhian Kamvar, poppr
Hello Zhian, 

Thank you for your reply. 

It seems I was able to split my populations by lineage using sepop, as you delineated above. Briefly, below are my commands: 

lineage_list <- seppop(gl, ~lineage)

lineage_list <- lapply(lineage_list, function(i) setPop(i, ~site))

#lineage 1 
mt1 <- lineage_list$"1"
mt1
as.snpclone(mt1)

#lineage 3
mt3 <- lineage_list$"3"
mt3
as.snpclone(mt3)

I am now trying to find the MLGs per lineage, using filter_stats to gain insights on the genetic distance cut-off. However, I am receiving an error, which was not there before when I ran this same command earlier on the un-subsetted dataset: 

mt3_filt <- filter_stats(mt3, distance = bitwise.dist, plot = TRUE)

Multilocus genotypes do not match the number of observations
Error in validObject(x) : invalid class “snpclone” object: FALSE

Any further insights would be much appreciated. Thank you again Zhian for all your help thus far!

Best regards,

Victoria

Zhian Kamvar

unread,
Apr 28, 2022, 11:50:34 PM4/28/22
to Victoria Glynn, poppr
would recommend converting your initial genlight object to snpclone. 

Either that or you need to set an output variable for as.snpclone():

mt1 <- as.snpclone(mt1)

(Forgot to reply to the group again)

Victoria Glynn

unread,
Apr 29, 2022, 10:27:59 PM4/29/22
to Zhian Kamvar, poppr
Hello Zhian, 

Thank you for your reply. 

This worked perfectly, many thanks again for all your help! 

Best regards,

Victoria
Reply all
Reply to author
Forward
0 new messages