Learn R Programming

pophelper (version 2.0.0)

readQ: Convert run files (q-matrices) to qlist.

Description

Takes one or more STRUCTURE, TESS, numeric delimited run files or CLUMPP format files and converts them to a qlist (list of dataframes).

Usage

readQ(files = NULL, filetype = "auto", indlabfromfile = FALSE)

Arguments

files

A character or character vector of one or more files.

filetype

A character indicating input filetype. Options are 'auto','structure','tess', 'basic' or 'clumpp'. See details.

indlabfromfile

A logical indicating if individual labels must be read from input file and used as row names for resulting dataframe. Spaces in labels may be replaced with _. Currently only applicable to STRUCTURE runs files.

Value

A list of lists with dataframes is returned. List items are named by input filenames. File extensions such as '.txt','.csv','.tsv' and '.meanQ' are removed from filename. In case filenames are missing or not available, lists are named sample1, sample2 etc. For STRUCTURE runs, if individual labels are present in the run file and indlabfromfile=T, they are added to the dataframe as row names. Structure metadata including loci, burnin, reps, elpd, mvll, and vll is added as attributes to each dataframe. For CLUMPP files, multiple runs within one file are suffixed by -1, -2 etc.

Details

STRUCTURE and TESS run files have unique layout and format (See vignette). BASIC files can be Admixture run files, fastStructure meanQ files or any tab-delimited, space-delimited or comma-delimited tabular data without a header. CLUMPP files can be COMBINED, ALIGNED or MERGED files. COMBINED files are generated from clumppExport. ALIGNED and MERGED files are generated by CLUMPP.

See the vignette for more details.

Examples

Run this code
# NOT RUN {
# STRUCTURE files
sfiles <- list.files(path=system.file("files/structure",package="pophelper"),full.names=TRUE)
# create a qlist of all runs
slist <- readQ(sfiles)
slist <- readQ(sfiles,filetype="structure")

# use ind names from file
readQ(sfiles[1],indlabfromfile=T)

# access the first run
readQ(sfiles)[[1]]

# access names of runs
names(slist)

# TESS files
tfiles <- list.files(path=system.file("files/tess",package="pophelper"),full.names=TRUE)
# create a qlist
readQ(tfiles)

# BASIC files
afiles <- list.files(path=system.file("files/admixture",package="pophelper"),full.names=TRUE)
# create a qlist
readQ(afiles)

# CLUMPP files
tabs1 <- system.file("files/STRUCTUREpop_K4-combined.txt",package="pophelper")
tabs2 <- system.file("files/STRUCTUREpop_K4-combined-aligned.txt",package="pophelper")
tabs3 <- system.file("files/STRUCTUREpop_K4-combined-merged.txt",package="pophelper")

# create a qlist
readQ(tabs1)
readQ(tabs2)
readQ(tabs3)

# manually create qlist
df1 <- data.frame(Cluster1=c(0.2,0.4,0.6,0.2),Cluster2=c(0.8,0.6,0.4,0.8))
df2 <- data.frame(Cluster1=c(0.3,0.1,0.5,0.6),Cluster2=c(0.7,0.9,0.5,0.4))

# one-element qlist
q1 <- list("sample1"=df1)
str(q1)

# two-element qlist
q2 <- list("sample1"=df1,"sample2"=df2)
str(q2)

# }

Run the code above in your browser using DataLab