### Example of analyses using lfmm ###
data("tutorial")
# creation of the genotype file, genotypes.lfmm.
# It contains 400 SNPs for 50 individuals.
write.lfmm(tutorial.R, "genotypes.lfmm")
# creation of the environment file, gradient.env.
# It contains 1 environmental variable for 40 individuals.
write.env(tutorial.C, "gradients.env")
################
# runs of lfmm #
################
# main options, K: (the number of latent factors),
# CPU: the number of CPUs.
# Runs with K = 9 and 5 repetitions.
# The runs are composed of 6000 iterations including 3000 iterations
# for burnin.
# around 30 seconds per run.
project = NULL
project = lfmm("genotypes.lfmm", "gradients.env", K = 6, repetitions = 5,
project = "new")
# get the adjusted p-values using the genomic control method
res = adjusted.pvalues(project, K = 6)
for (alpha in c(.05,.1,.15,.2)) {
# expected FDR
print(paste("expected FDR:", alpha))
L = length(res$p.values)
# return a list of candidates with an expected FDR of alpha.
w = which(sort(res$p.values) < alpha * (1:L) / L)
candidates = order(res$p.values)[w]
# estimated FDR and True Positif
estimated.FDR = length(which(candidates <= 350))/length(candidates)
estimated.TP = length(which(candidates > 350))/50
print(paste("FDR:", estimated.FDR, "True Positive:", estimated.TP))
}
###################
# Post-treatments #
###################
# show the project
show(project)
# summary of the project
summary(project)
# get the z-scores for the 2nd run for K = 6
z = z.scores(project, K = 6, run = 2)
# get the p-values for the 2nd run for K = 6
p = p.values(project, K = 6, run = 2)
# get the adjusted p-values for for K = 6
res = adjusted.pvalues(project, K = 6)
# get the -log10(p-values) for the 2nd run for K = 6
mp = mlog10p.values(project, K = 6, run = 2)
##########################
# Manage an lfmm project #
##########################
# All the runs of lfmm for a given file are
# automatically saved into a lfmm project directory and a file.
# The name of the lfmmProject file is a combination of
# the name of the input file and the environment file
# with a .lfmmProject extension ("genotypes_gradient.lfmmProject").
# The name of the lfmmProject directory is the same name as
# the lfmmProject file with a .lfmm extension ("genotypes_gradient.lfmm/")
# There is only one lfmm Project for each input file including all the runs.
# An lfmmProject can be load in a different session.
project = load.lfmmProject("genotypes_gradients.lfmmProject")
# An lfmmProject can be exported to be imported in another directory
# or in another computer
export.lfmmProject("genotypes_gradients.lfmmProject")
windows
dir.create("test", showWarnings = TRUE)
#import
newProject = import.lfmmProject("genotypes_gradients_lfmmProject.zip", "test")
# combine projects
combinedProject = combine.lfmmProject("genotypes_gradients.lfmmProject", "test/genotypes_gradients.lfmmProject")
# remove
remove.lfmmProject("test/genotypes_gradients.lfmmProject")
windows
# remove
remove.lfmmProject("genotypes_gradients.lfmmProject")
#import
newProject = import.lfmmProject("genotypes_gradients_lfmmProject.zip")
# An lfmmProject can be erased.
# Caution: All the files associated with the project will be removed.
remove.lfmmProject("genotypes_gradients.lfmmProject")
Run the code above in your browser using DataLab