Population names - how to completely change

263 views
Skip to first unread message

Berry, Olly (NCMI, IOMRC Crawley)

unread,
Nov 19, 2019, 8:33:36 PM11/19/19
to da...@googlegroups.com

Hi dartR community,

 

This is a rookie question that I thought I could easily solve, but haven’t been able to. I hope somebody has a quick fix.

 

I am working with a genlight file, and for historical reasons my pop slot is filled with labels for high-level geographic regions, whereas what I would like to have in that slot is finer scale sampling sites.  Typically there may be several sites within the regions.

 

The gl.recode.pop function doesn’t seem appropriate because it designed for one for one population name changes, or combining pops.

 

If I import a text file vector of pop names (i.e. the vector is as long as the number of individuals) and try to place it in the pop slot by e.g.

Site_names <- read.table(file = "Site_names.txt", header = FALSE)

my.gl$pop <- Site_names

 

I get an error like:

Error in checkSlotAssignment(object, name, value) :

  assignment of an object of class “data.frame” is not valid for slot ‘pop’ in an object of class “genlight”; is(value, "factorOrNULL") is not TRUE

 

I don’t have that problem if I import data into $other slots.

No doubt a basic error, but I am hoping an R guru can set me straight.

 

Cheers,

 

Olly

 

 

Arthur Georges

unread,
Nov 19, 2019, 8:38:05 PM11/19/19
to da...@googlegroups.com
Hi Olly,

The solution is to have your new finer scale sampling sites as a variable in your individual metrics (added when you read the data in), then use gl.reassign.pop() to assign that metric to the pop slot.

A

--
You received this message because you are subscribed to the Google Groups "dartR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dartr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/ME2PR01MB238824B855E5091C882C3091FF4F0%40ME2PR01MB2388.ausprd01.prod.outlook.com.

Berry, Olly (NCMI, IOMRC Crawley)

unread,
Nov 19, 2019, 9:03:40 PM11/19/19
to da...@googlegroups.com

Thanks Arthur,

 

In this case I am already past the QC stage etc and don’t have the sites included in my individual metrics (in hindsight an error!).

 

Cheers,

 

Olly

Arthur Georges

unread,
Nov 19, 2019, 11:00:10 PM11/19/19
to da...@googlegroups.com
Just add them. gl@other$ind.metrics$newsites <- [vector with the new site allocations in order]
Then gl <- gl.reassign.pop(gl,as.pop=newsites)

A


Berry, Olly (NCMI, IOMRC Crawley)

unread,
Nov 20, 2019, 2:51:34 AM11/20/19
to da...@googlegroups.com

Thanks Arthur.

 

With some minor tweaking it worked!

 

Cheers,

 

Olly

 

--

For the record….

 

 

#Switching the "pop" name to Region - which is more appropriate

test.gl$other$Region <-test.gl$pop

 

#Now bring in the actual site names to the pop slot#

Site_names <- read.csv(file = "Site_names.csv", header = TRUE) #import the vector

 

test.gl@other$ind.metrics <- Site_names #The variable is labelled Site in the input file (header), this will be the label for the vector within ind.metrics

 

test.gl <- gl.reassign.pop(test.gl,as.pop="Site") #The function looks in ind.metrics for a vector called Site

test.gl #have a look

levels(test.gl$pop)

levels(test.gl$other$Region)

renee....@gmail.com

unread,
Apr 1, 2021, 4:52:00 AM4/1/21
to dartR
Hi All,

I had a bit of trouble with this, assigning populations to an exon capture dataset read in as a fasta.

What worked was:
gl <- fasta2genlight("snp_align_one_snp_gene_r_0.fasta")
#read in csv file with population names
pops <- read.csv("pop_reassign.csv")
pops$pop <- as.factor(pops$pop)
#assign populations
gl@other$ind.metrics$sites <- pops$pop
gl@pop <- gl@other$ind.metrics$sites

The key thing was getting the pops file perfectly formatted. I compared it to an existing dataset with automated assignments.

Renee
Reply all
Reply to author
Forward
0 new messages