data3.Rmd 17 KB
Newer Older
mariefbourdon's avatar
mariefbourdon committed
1
2
3
---
title: "data3.Rmd"
author: "Marie Bourdon"
mariefbourdon's avatar
mariefbourdon committed
4
date: '2022-06-08'
mariefbourdon's avatar
mariefbourdon committed
5
6
7
8
9
10
11
12
13
14
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(stuart)
library(magrittr)
library(readr)
library(stringr)
library(qtl)
mariefbourdon's avatar
mariefbourdon committed
15
source("../files/QTL_plot.R")
mariefbourdon's avatar
mariefbourdon committed
16
17
18
19
```

## Load
```{r}
mariefbourdon's avatar
mariefbourdon committed
20
genos <- read_csv("genos_data3.csv",show_col_types = FALSE) #genotypes of F2s
mariefbourdon's avatar
mariefbourdon committed
21
annot_mini <- read.csv(url("https://raw.githubusercontent.com/kbroman/MUGAarrays/master/UWisc/mini_uwisc_v2.csv")) #annotation file for miniMUGA
mariefbourdon's avatar
mariefbourdon committed
22
23
phenos <- read_csv("phenos_data3.csv",show_col_types = FALSE) #phenotypes of F2s
parents <- read_csv("parents_data3.csv",show_col_types = FALSE) #genotypes of parental strains (genotyped with F2s)
mariefbourdon's avatar
mariefbourdon committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
strns_ref <- read_csv("ref_geno_data3.csv",show_col_types = FALSE) #reference genotypes of parental strains
```

```{r}
tab <- tab_mark(genos,annot_mini,"cM_cox")
```

## Before: creation of Rqtl csv file 

```{r cross_before}
# filter at minima: remove non polymorphic and NA>0.5 
tab_before <- mark_na(tab)
tab_before <- mark_poly(tab_before)

#join with annotation file from miniMUGA
strns_ref <- strns_ref %>% select(name,StrainA,StrainB) %>% right_join(annot_mini,.,by=c("marker"="name")) %>% select(c(marker,chr,cM_cox,StrainA,StrainB))

# create rqtl csv file
mariefbourdon's avatar
mariefbourdon committed
42
write_rqtl(geno=genos,pheno=phenos,tab=tab_before,ref=strns_ref,par1="StrainA",par2="StrainB",prefix=" ",pos="cM_cox",path="cluster/cross_before.csv")
mariefbourdon's avatar
mariefbourdon committed
43
44
45

# import cross
cross_before <- read.cross(format="csv",file="cluster/cross_before.csv",
mariefbourdon's avatar
mariefbourdon committed
46
                              genotypes=c("0","1","2"),na.strings=c("NA"), convertXdata=TRUE)
mariefbourdon's avatar
mariefbourdon committed
47
48


mariefbourdon's avatar
mariefbourdon committed
49
50
load("cluster/newmap_before.rda")
plotMap(cross_before,newmap_before,shift=TRUE)
mariefbourdon's avatar
mariefbourdon committed
51
52
53

cross_before_data3 <- cross_before
newmap_before_data3 <- newmap_before
mariefbourdon's avatar
mariefbourdon committed
54
plotmap_before_data3 <- ~plotMap(cross_before_data3,newmap_before_data3,shift=TRUE,main="", ylab='')
mariefbourdon's avatar
mariefbourdon committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
```

### Before: plot genome scan

```{r before_scan}
# load rda with perm
load("cluster/before_1000p.rda")
# load("files/before_1000p.rda")


# calculate thresholds
threshold_before <- summary(before_1000p,alpha=c(0.05,0.1,0.63)) #donne lod score pour risque 0.05, 0.1, 0.63

# scanone
cross_before <- calc.genoprob(cross_before, step=2.0, off.end=0.0,
                                 error.prob=1.0E-4, map.function="haldane", stepwidth="fixed")


mariefbourdon's avatar
mariefbourdon committed
73
pheno_before <- scanone(cross=cross_before, chr=c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "X", "Y"), pheno.col="Pheno", model="normal", method="em")
mariefbourdon's avatar
mariefbourdon committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
summary(pheno_before)

# Plot
pheno_before_plot <- qtl_plot(pheno_before,lod=data.frame(group = c("alpha=0.05", "alpha=0.1","alpha=0.63"),
                 lod = threshold_before[1:3]),
         ylab="LOD score",
         title="QTL mapping",
         x.label = element_blank(),
         size=0.6,
         strip.pos="bottom") +
    theme(legend.position = "none") +
    ggtitle("")
pheno_before_plot
```

mariefbourdon's avatar
mariefbourdon committed
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
### Distribution of calculated distance between markers

```{r}
## BEFORE
#initialize variables
mark <- c()
chr <- c()
pos <- c()
place <- c()
previous <- c()
follow <- c()
kn_previous <- c()
kn_follow <- c()

#get information in newmap
for(i in names(newmap_before)){
  mark <- c(mark,names(newmap_before[[i]]))
  chr <- c(chr,rep(i,times=length(newmap_before[[i]])))
  pos <- c(pos,unname(newmap_before[[i]]))
  place <- c(place,"first",rep("middle",times=(length(newmap_before[[i]])-2)),"last")
  prev <- c(NA,unname(newmap_before[[i]])[1:length(newmap_before[[i]])-1])
  previous <- c(previous,prev)
  fol <- c(unname(newmap_before[[i]])[2:length(newmap_before[[i]])],NA)
  follow <- c(follow,fol)
}

annot <- annot_mini %>% filter(marker %in% mark)
kn_pos <- annot$cM_cox
kn_prev <- c(NA, annot[1:(nrow(annot) - 1), "cM_cox"])
kn_previous <- c(kn_previous, kn_prev)
kn_fol <- c(annot[2:nrow(annot), "cM_cox"], NA)
kn_follow <- c(kn_follow, kn_fol)

#create tab with positions
rec_ratios <- tibble(marker = mark,
                  chr = chr,
                  place = place,
                  pos = pos,
                  previous = previous,
                  prev_dif = pos-previous,
                  kn_pos = kn_pos,
                  kn_previous = kn_previous,
                  kn_prev_dif = kn_pos - kn_previous)

rec_ratios <- rec_ratios %>% mutate(kn_prev_dif = case_when(is.na(previous) == TRUE ~ NA_real_, T ~ kn_prev_dif))


rec_ratios <- rec_ratios %>% mutate(rat_prev = prev_dif/kn_prev_dif)


#remove if dist < 1cM
rec_ratios %<>% filter(!prev_dif<1 & !kn_prev_dif<1) 

#mean sd
rec_ratios %>% summarise(mean=mean(rat_prev,na.rm=TRUE),
                       sd=sd(rat_prev,na.rm=TRUE),
                       max=max(rat_prev,na.rm=TRUE)) 


rec_ratios_before_data3 <- rec_ratios %>% ggplot(aes(x=rat_prev)) +
  geom_histogram(binwidth = .1,alpha=0.4, position="identity",fill="#990000") +
mariefbourdon's avatar
mariefbourdon committed
150
  scale_x_log10(limits=c(0.2,1000)) +
mariefbourdon's avatar
mariefbourdon committed
151
  labs(x="Ratio between the calculated and the known distance with the previous marker",
mariefbourdon's avatar
mariefbourdon committed
152
       y="Count",
mariefbourdon's avatar
mariefbourdon committed
153
       fill="",
mariefbourdon's avatar
mariefbourdon committed
154
       title="Distance between adjacent markers") +
mariefbourdon's avatar
mariefbourdon committed
155
  geom_vline(xintercept = 5,linetype="dashed") +
mariefbourdon's avatar
mariefbourdon committed
156
157
  ggpubr::theme_classic2() +
  theme(plot.title = element_text(hjust=0.5,size=14)) 
mariefbourdon's avatar
mariefbourdon committed
158
159
160

rec_ratios_before_data3

mariefbourdon's avatar
mariefbourdon committed
161
162
163
164
165
#percentage of markers in each group
rec_ratios %>% mutate(group_rat=case_when(rat_prev<5 ~ 0,
                                          rat_prev >=5 ~ 1)) %>%
  group_by(group_rat) %>% summarise(n=n(),p=n()/nrow(rec_ratios))

mariefbourdon's avatar
mariefbourdon committed
166
167
168
rm(mark,chr,pos,place,previous,follow,kn_previous,kn_follow,fol,kn_fol,kn_pos,kn_prev,i,prev)
```

mariefbourdon's avatar
mariefbourdon committed
169
170
171
172
173

```{r}
#our genotypes

#create tibble with individivual names
mariefbourdon's avatar
mariefbourdon committed
174
parental_strains <- tibble::tibble(StrainA = "StrainA",
mariefbourdon's avatar
mariefbourdon committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
                                   StrainB = c("StrainB_1","StrainB_2"))


#create data frame with geno_strains
strains <- geno_strains(annot=annot_mini,geno=parents,
                        strn=parental_strains,cols=c("chr","cM_cox"))
rm(parental_strains)

#summary
summary(strains)
```

## Use of stuart's functions

```{r}
tab2 <- mark_match(tab,ref=strains)
tab2 <- mark_poly(tab2)
tab2 <- mark_na(tab2)
mariefbourdon's avatar
mariefbourdon committed
193
194
tab2 <- mark_prop(tab2,cross="F2",homo=0.1,hetero=0.1,homo1X=c(0.1,1),homo2X=c(0.1,1),heteroX=c(0.1,1))
tab2 <- mark_allele(tab2,ref=strains,cross="F2",par1="StrainA",par2="StrainB")
mariefbourdon's avatar
mariefbourdon committed
195
196
197
198
199
200
201
202
203
204
```

### estmap

```{r}
# create rqtl csv file
write_rqtl(geno=genos,pheno=phenos,tab=tab2,ref=strains,par1="StrainA",par2="StrainB",prefix=" ",pos="cM_cox",path="cluster/cross_after.csv")

# import cross
cross_after <- read.cross(format="csv",file="cluster/cross_after.csv",
mariefbourdon's avatar
mariefbourdon committed
205
                              genotypes=c("0","1","2"),na.strings=c("NA"), convertXdata=TRUE)
mariefbourdon's avatar
mariefbourdon committed
206

mariefbourdon's avatar
mariefbourdon committed
207

mariefbourdon's avatar
mariefbourdon committed
208
load("cluster/newmap_after.rda")
mariefbourdon's avatar
mariefbourdon committed
209
210
211
212
213
214
215
plotMap(cross_after,newmap_after,shift=TRUE)

tab2 <- mark_estmap(tab=tab2,map=newmap_after,annot=annot_mini)

# create new rqtl csv file
write_rqtl(geno=genos,pheno=phenos,tab=tab2,ref=strains,par1="StrainA",par2="StrainB",prefix="F2-",pos="cM_cox",path="cluster2/cross_after2.csv")
```
mariefbourdon's avatar
mariefbourdon committed
216
217


mariefbourdon's avatar
mariefbourdon committed
218
219
220
221
### After: plot estimated map 2

```{r after_map2}
# import cross
mariefbourdon's avatar
data3-4    
mariefbourdon committed
222
cross_after2 <- read.cross(format="csv",file="cluster2/cross_after2.csv",
mariefbourdon's avatar
mariefbourdon committed
223
                              genotypes=c("0","1","2"),na.strings=c("NA"), convertXdata=TRUE)
mariefbourdon's avatar
mariefbourdon committed
224

mariefbourdon's avatar
mariefbourdon committed
225
226
227
228
cross_after2 <- calc.genoprob(cross_after2, step=2.0, off.end=0.0, 
                             error.prob=1.0E-4, map.function="haldane", stepwidth="fixed")

newmap_after2 <- est.map(cross=cross_after2,error.prob=0.01)
mariefbourdon's avatar
mariefbourdon committed
229
230
231

# plot
plotMap(cross_after2,newmap_after2,shift=TRUE)
mariefbourdon's avatar
mariefbourdon committed
232
233
234
235


cross_after_data3 <- cross_after2
newmap_after_data3 <- newmap_after2
mariefbourdon's avatar
mariefbourdon committed
236
plotmap_after_data3 <- ~plotMap(cross_after_data3,newmap_after_data3,shift=TRUE,main="")
mariefbourdon's avatar
mariefbourdon committed
237
238
239
240
```

```{r after_scan}
# load rda with perm
mariefbourdon's avatar
mariefbourdon committed
241
242
243
after_1000p2 <- scanone(cross=cross_after2, 
                        chr=c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "X"), 
                        pheno.col="Pheno", model="normal", method="em", n.perm=1000, perm.Xsp=FALSE, verbose=FALSE) 
mariefbourdon's avatar
mariefbourdon committed
244
245
246
247
248
249
250
251
252

# calculate thresholds
threshold_after <- summary(after_1000p2,alpha=c(0.05,0.1,0.63)) #donne lod score pour risque 0.05, 0.1, 0.63

# scanone
cross_after <- calc.genoprob(cross_after2, step=2.0, off.end=0.0, 
                                 error.prob=1.0E-4, map.function="haldane", stepwidth="fixed")


mariefbourdon's avatar
mariefbourdon committed
253
pheno_after <- scanone(cross=cross_after2, chr=c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "X", "Y"), pheno.col="Pheno", model="normal", method="em")
mariefbourdon's avatar
mariefbourdon committed
254
255
256
summary(pheno_after)

# Plot
mariefbourdon's avatar
mariefbourdon committed
257
pheno_after_plot_data3 <- qtl_plot(pheno_after,lod=data.frame(group = c("alpha=0.05", "alpha=0.1","alpha=0.63"),
mariefbourdon's avatar
mariefbourdon committed
258
259
260
261
262
263
                 lod = threshold_after[1:3]),
         ylab="LOD score",
         title="QTL mapping",
         x.label = element_blank(),
         size=0.6) +
    theme(legend.position = "none") +
mariefbourdon's avatar
mariefbourdon committed
264
265
    ggtitle("Dataset 3: genome scan") +
   theme(plot.title = element_text(face="plain",size=14,hjust=0.5)) 
mariefbourdon's avatar
mariefbourdon committed
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
pheno_after_plot_data3
```

### Distribution of calculated distance between markers

```{r}
## AFTER
#initialize variables
mark <- c()
chr <- c()
pos <- c()
place <- c()
previous <- c()
follow <- c()
kn_previous <- c()
kn_follow <- c()

#get information in newmap
for(i in names(newmap_after2)){
  mark <- c(mark,names(newmap_after2[[i]]))
  chr <- c(chr,rep(i,times=length(newmap_after2[[i]])))
  pos <- c(pos,unname(newmap_after2[[i]]))
  place <- c(place,"first",rep("middle",times=(length(newmap_after2[[i]])-2)),"last")
  prev <- c(NA,unname(newmap_after2[[i]])[1:length(newmap_after2[[i]])-1])
  previous <- c(previous,prev)
  fol <- c(unname(newmap_after2[[i]])[2:length(newmap_after2[[i]])],NA)
  follow <- c(follow,fol)
}

annot <- annot_mini %>% filter(marker %in% mark)
kn_pos <- annot$cM_cox
kn_prev <- c(NA, annot[1:(nrow(annot) - 1), "cM_cox"])
kn_previous <- c(kn_previous, kn_prev)
kn_fol <- c(annot[2:nrow(annot), "cM_cox"], NA)
kn_follow <- c(kn_follow, kn_fol)

#create tab with positions
rec_ratios <- tibble(marker = mark,
                  chr = chr,
                  place = place,
                  pos = pos,
                  previous = previous,
                  prev_dif = pos-previous,
                  kn_pos = kn_pos,
                  kn_previous = kn_previous,
                  kn_prev_dif = kn_pos - kn_previous)

rec_ratios <- rec_ratios %>% mutate(kn_prev_dif = case_when(is.na(previous) == TRUE ~ NA_real_, T ~ kn_prev_dif))

rec_ratios <- rec_ratios %>% mutate(rat_prev = prev_dif/kn_prev_dif)

#remove if dist < 1cM
rec_ratios %<>% filter(!prev_dif<1 & !kn_prev_dif<1) 

#mean sd
rec_ratios %>% summarise(mean=mean(rat_prev,na.rm=TRUE),
                       sd=sd(rat_prev,na.rm=TRUE)) 


rec_ratios_after_data3 <- rec_ratios %>% ggplot(aes(x=rat_prev)) +
  geom_histogram(binwidth = .1,alpha=0.4, position="identity",fill="#2171b5") +
mariefbourdon's avatar
mariefbourdon committed
327
  scale_x_log10(limits=c(0.2,1000)) +
mariefbourdon's avatar
mariefbourdon committed
328
  labs(x="Ratio between the calculated and the known distance with the previous marker",
mariefbourdon's avatar
mariefbourdon committed
329
       y="Count",
mariefbourdon's avatar
mariefbourdon committed
330
       fill="",
mariefbourdon's avatar
mariefbourdon committed
331
332
333
       title="Distance between adjacent markers") +
  ggpubr::theme_classic2() +
  theme(plot.title = element_text(hjust=0.5,size=14)) 
mariefbourdon's avatar
mariefbourdon committed
334
335
336
337

rec_ratios_after_data3

rm(mark,chr,pos,place,previous,follow,kn_previous,kn_follow,fol,kn_fol,kn_pos,kn_prev,i,prev)
mariefbourdon's avatar
mariefbourdon committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
```

## Number of markers kept after each function

```{r barplot}
none <- tab2 %>% nrow()
match <- tab2 %>% filter(exclude_match==0) %>% nrow()
allele <- tab2 %>% filter(exclude_match==0&exclude_allele==0) %>% nrow()
naf <- tab2 %>% filter(exclude_match==0&exclude_allele==0&exclude_na==0) %>% nrow()
poly <- tab2 %>% filter(exclude_match==0&exclude_allele==0&exclude_na==0&exclude_poly==0) %>% nrow()
prop <- tab2 %>% filter(exclude_match==0&exclude_allele==0&exclude_na==0&exclude_poly==0&exclude_prop==0) %>% nrow()
estmap <- tab2 %>% filter(exclude_match==0&exclude_allele==0&exclude_na==0&exclude_poly==0&exclude_prop==0&exclude_estmap==0) %>% nrow()

functions_df <- tibble(fct=c("none","match","allele","na","poly","prop","estmap"),
                       markers=c(none,match,allele,naf,poly,prop,estmap))

functions_plot <- functions_df %>% ggplot(aes(x=markers,y=fct)) +
  geom_bar(stat="identity",width=0.6) +
  geom_text(aes(label=markers), hjust=1.3, color="white", size=3.5) +
  scale_y_discrete(limits=c("estmap","prop","poly", "na", "allele","match","none")) +
  theme(aspect.ratio=0.7) +
  labs(title="Number of markers kept after each step",
       x="Number of markers",
       y="Function used") +
  theme_classic() +
  theme(plot.title = element_text(hjust = 0.4,face="bold",size=14))
mariefbourdon's avatar
mariefbourdon committed
364

mariefbourdon's avatar
mariefbourdon committed
365
functions_plot
mariefbourdon's avatar
mariefbourdon committed
366
rm(none,allele,match,poly,prop)
mariefbourdon's avatar
mariefbourdon committed
367
368
369
```


mariefbourdon's avatar
mariefbourdon committed
370
371
372
373
374
375
376
## Narrow peaks

```{r before_ann}
chrs <- c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "X")
ann_dat_text<-data.frame(
    chr=factor(chrs,
               levels=chrs),
mariefbourdon's avatar
mariefbourdon committed
377
378
379
    lod=c(NA,NA,NA,NA,11,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA),
    label=c(NA,NA,NA,NA,"p4",NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA),
    x=c(NA,NA,NA,NA,20,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA,NA)
mariefbourdon's avatar
mariefbourdon committed
380
381
382
383
384
385
386
387
388
)

pheno_before_annot_data3 <- pheno_before_plot +  geom_text(
    # the new dataframe for annotating text
    data = ann_dat_text,
    mapping = aes(x = x,
                  y = lod,
                  label = label,
                  color="blue")
mariefbourdon's avatar
mariefbourdon committed
389
  ) +
mariefbourdon's avatar
mariefbourdon committed
390
391
  ggtitle("Dataset 3: genome scan") +
  theme(plot.title = element_text(face="plain",size=14,hjust=0.5)) 
mariefbourdon's avatar
mariefbourdon committed
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
pheno_before_annot_data3
```

### Peak 4

```{r peak4_zoom}
peak4 <- qtl_plot(pheno_before,lod=data.frame(group = c("alpha=0.05", "alpha=0.1","alpha=0.63"),
                 lod = threshold_before[1:3]),
         ylab="LOD score",
         title="QTL mapping",
         x.label = element_blank(),
         size=0.6,
         strip.pos="bottom",
         chr="5",
         rug=TRUE) +
    theme(legend.position = "none",
          strip.background = element_blank(),
          strip.text.x = element_blank()) +
    xlab("Position (cM)") +
    xlim(c(12,32)) +
    ggtitle("")
peak4
```

1 peak on chromosome 5 on 3 pseudomarkers : c5.loc16, c5.loc18, c5.loc20 in a region with very few markers, postionned between S6J050685107 and mUNC050096588.

Here are the infos on genotype counts for these markers:

```{r summary_geno_peak4}
tab_before %>% filter(marker %in% c("S6J050685107","mUNC050096588")) %>% select(marker:n_NA)
```


For mUNC050096588, all individuals heterozygous so this marker should be removed. The proportions for S6J050685107 seem correct.

Graph:

```{r geno_plot_peak4}
phenotypes <- cross_before[["pheno"]]
map <- cross_before[["geno"]][["5"]][["map"]] 
map <- tibble(marker=names(map),pos=map)
genotypes <- cross_before[["geno"]][["5"]][["data"]]
genotypes <- as_tibble(genotypes)
phenogeno <- cbind(phenotypes,genotypes)
phenogeno %<>% pivot_longer(mUNC050013072:gUNC10448854,names_to="marker",values_to="genotype")
pgmap <- full_join(phenogeno,map,by="marker")

geno_plot4 <- pgmap %>% filter(pos > 1 & pos < 30) %>%
  filter(id %in% sample(phenotypes$id,10)) %>%
  ggplot(aes(x=pos,y=as.factor(id))) +
  geom_point(aes(color=as.factor(genotype))) +
  coord_cartesian(ylim = c(1, 10), expand = TRUE, clip = "off") +
  annotate(geom="text",y=-1,size=3,
           x = map %>% filter(pos > 1 & pos < 30) %>% pull(pos),
           label = map %>% filter(pos > 1 & pos < 30) %>% pull(marker),
           angle=90) +
  labs(x="Position (cM)",y="Individual",color="Genotype") +
  theme_bw() +
  theme(plot.margin = unit(c(1, 1, 1, 1), "lines"),
        axis.title.x = element_text(margin = margin(t = 50)))
geno_plot4
```

## Phenotype distributions

```{r pheno_distrib}
pheno_data3 <- phenos %>% ggplot(aes(x=Pheno)) +
  geom_histogram(binwidth=0.2) +
  ggpubr::theme_classic2() +
mariefbourdon's avatar
mariefbourdon committed
461
462
  labs(y="Count", x="Quantitative phenotype",title="Dataset 3") +
  theme(plot.title = element_text(hjust=0.5,size=14)) 
mariefbourdon's avatar
mariefbourdon committed
463
464
465
pheno_data3
```

mariefbourdon's avatar
mariefbourdon committed
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
## Missing genotypes

```{r}
na_plot <- tab2 %>% mutate(prop_NA=n_NA/176) %>% ggplot(aes(x=prop_NA)) +
  geom_histogram() +
  scale_y_log10() +
  theme_classic() +
  labs(title="Proportion of missing genotyped",
       x="Proportion of NA",y="Number of markers") +
  theme(
    aspect.ratio=0.8,
    plot.title = element_text(hjust = 0.4,face="bold",size=14))

na_plot
```

## Genotype proportions

```{r}
prop_plot <- tab2 %>% filter(n_NA<88) %>% filter(!chr %in% c("M","X","Y")) %>%
  ggplot(aes(x=n_HM1/(n_HM1+n_HM2+n_HT),y=n_HM2/(n_HM1+n_HM2+n_HT),color=as.factor(exclude_prop))) +
  geom_point() +
  scale_color_manual(values=c("#66bd63","#b2182b"),labels = c("Retained", "Excluded")) +
  geom_hline(yintercept = 0.1,linetype="dashed",size=.3) +
  geom_vline(xintercept = 0.1,linetype="dashed",size=.3) +
  geom_abline(intercept = 0.9, slope=-1,linetype="dashed",size=.3) +
  labs(title="Exclusion of markers with mark_prop()",
       x="Proportion of homozygous individuals AA",
       y="Proportion of homozygous individuals BB",
       color="Exclusion") +
  theme_classic() +
  theme(aspect.ratio=0.8,
        legend.position=c(0.8,0.8),
        legend.title = element_blank()) +
  theme(plot.title = element_text(hjust = 0.4,face="bold",size=14))

prop_plot
```
mariefbourdon's avatar
mariefbourdon committed
504

mariefbourdon's avatar
mariefbourdon committed
505
```{r}
mariefbourdon's avatar
mariefbourdon committed
506
tab2_data3 <- tab2
mariefbourdon's avatar
mariefbourdon committed
507
save(pheno_before_annot_data3,pheno_data3,tab2_data3,
mariefbourdon's avatar
mariefbourdon committed
508
509
510
511
512
     rec_ratios_before_data3,rec_ratios_after_data3,
     plotmap_before_data3,plotmap_after_data3,
     cross_before_data3,newmap_before_data3,cross_after_data3,newmap_after_data3,
     pheno_after_plot_data3,
     file="data3.rda")
mariefbourdon's avatar
mariefbourdon committed
513
rm(tab2_data3)
mariefbourdon's avatar
mariefbourdon committed
514
```
mariefbourdon's avatar
mariefbourdon committed
515