-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWeek1_vignette.R
173 lines (108 loc) · 7.04 KB
/
Week1_vignette.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
## ----message=FALSE, warning=TRUE--------------------------------------------------------------------
if(!require("adegenet")) install.packages("adegenet")
if(!requireNamespace("popgraph", quietly = TRUE))
{
install.packages(c("RgoogleMaps", "geosphere", "proto", "sampling",
"seqinr", "spacetime", "spdep"), dependencies=TRUE)
remotes::install_github("dyerlab/popgraph")
}
if(!requireNamespace("gstudio", quietly = TRUE)) remotes::install_github("dyerlab/gstudio")
## ----message=FALSE, warning=TRUE--------------------------------------------------------------------
library(adegenet)
library(gstudio)
library(LandGenCourse)
library(tibble)
library(here)
library(vcfR)
library(pinfsc50)
library(utils)
## ---------------------------------------------------------------------------------------------------
data(ralu.loci)
## ---------------------------------------------------------------------------------------------------
if(!dir.exists(paste0(here(),"/downloads"))) dir.create(paste0(here(),"/downloads"))
file.copy(system.file("extdata", "ralu.loci.csv", package = "LandGenCourse"),
paste0(here(), "/downloads/ralu.loci.csv"), overwrite=FALSE)
## ----message=FALSE, include=FALSE, out.width=5------------------------------------------------------
invisible(file.copy(from=system.file("extdata", "ExcelTable.png",
package = "LandGenCourse"),
to=paste0(here::here(), "/downloads/ExcelTable.png")))
#knitr::include_graphics(paste0(here::here(), "/downloads/ExcelTable.png"))
## ----results = 'asis'-------------------------------------------------------------------------------
paste0("![Excel table.](", here::here(), "/downloads/ExcelTable.png)")
## ---------------------------------------------------------------------------------------------------
Frogs <- read.csv(paste0(here(), "/downloads/ralu.loci.csv"), header=TRUE)
as_tibble(Frogs)
## ---------------------------------------------------------------------------------------------------
Frogs <- data.frame(FrogID = paste(substr(Frogs$Pop, 1, 3), row.names(Frogs), sep="."), Frogs)
as_tibble(Frogs)
## ---------------------------------------------------------------------------------------------------
here()
paste0(here(),"/output")
## ---------------------------------------------------------------------------------------------------
if(!dir.exists(paste0(here(),"/output"))) dir.create(paste0(here(),"/output"))
## ---------------------------------------------------------------------------------------------------
write.csv(ralu.loci, paste0(here(),"/output/ralu.loci.csv"),
quote=FALSE, row.names=FALSE)
## ---------------------------------------------------------------------------------------------------
ralu.loci.2 <- read.csv(paste0(here(),"/output/ralu.loci.csv"), header=TRUE)
## ---------------------------------------------------------------------------------------------------
?df2genind
## ---------------------------------------------------------------------------------------------------
Frogs.genind <- df2genind(X=Frogs[,c(4:11)], sep=":", ncode=NULL, ind.names= Frogs$FrogID, loc.names=NULL, pop=Frogs$Pop, NA.char="NA", ploidy=2, type="codom", strata=NULL, hierarchy=NULL)
## ---------------------------------------------------------------------------------------------------
Frogs.genind
## ---------------------------------------------------------------------------------------------------
summary(Frogs.genind)
## ---------------------------------------------------------------------------------------------------
as_tibble(Frogs.genind@tab)
## ---------------------------------------------------------------------------------------------------
Frogs.genind@loc.n.all
## ---------------------------------------------------------------------------------------------------
Frogs.genind@loc.fac
## ---------------------------------------------------------------------------------------------------
Frogs.genind@all.names
## ---------------------------------------------------------------------------------------------------
?read_population
## ---------------------------------------------------------------------------------------------------
Frogs.gstudio <- read_population(path=system.file("extdata", "ralu.loci.csv",
package = "LandGenCourse"),
type="separated", locus.columns=c(3:10),
phased=FALSE, sep=",", header=TRUE)
## ---------------------------------------------------------------------------------------------------
str(Frogs.gstudio)
## ---------------------------------------------------------------------------------------------------
Frogs.gstudio <- data.frame(FrogID=Frogs$FrogID, Frogs.gstudio)
head(Frogs.gstudio)
## ---------------------------------------------------------------------------------------------------
Frogs.genind2 <- adegenet::df2genind(X=Frogs.gstudio[,c(4:11)], sep=":", ncode=NULL,
ind.names=Frogs.gstudio$FrogID, loc.names=NULL,
pop=Frogs.gstudio$Pop, NA.char="", ploidy=2,
type="codom", strata=NULL, hierarchy=NULL)
Frogs.genind2
## ---------------------------------------------------------------------------------------------------
infile <- system.file("extdata", "WWP_SNP_genotypes.txt", package = "LandGenCourse")
Trees <- read.table(infile, header = TRUE, sep = "\t")
Trees[1:6, 1:6]
## ---------------------------------------------------------------------------------------------------
names(Trees) <- unlist(lapply(names(Trees), function(x) strsplit(x, "[.]")[[1]][1]))
## ---------------------------------------------------------------------------------------------------
Trees.genind <- adegenet::df2genind(X=Trees[,-c(1:2)], sep="", ncode=1,
ind.names=Trees$family, loc.names=NULL,
pop=Trees$population, NA.char="NA", ploidy=2,
type="codom", strata=NULL, hierarchy=NULL)
Trees.genind
## ---------------------------------------------------------------------------------------------------
vcf_file <- system.file("extdata", "pinf_sc50.vcf.gz", package = "pinfsc50")
vcf <- read.vcfR( vcf_file, verbose = FALSE )
## ---------------------------------------------------------------------------------------------------
SNP_genind <- vcfR2genind(vcf)
SNP_genind
## ---------------------------------------------------------------------------------------------------
SNP_genlight <- vcfR2genlight(vcf)
SNP_genlight
## ---------------------------------------------------------------------------------------------------
file.copy(system.file("extdata", "pulsatilla_genotypes.csv", package = "LandGenCourse"),
paste0(here(), "/downloads/pulsatilla_genotypes.csv"), overwrite=FALSE)
## ----message=FALSE, warning=TRUE, include=FALSE-----------------------------------------------------
# Note: this line of code detaches all packages that were loaded. This is necessary only for technical reasons of building the R package.
LandGenCourse::detachAllPackages()