data2.Rmd 16.4 KB
Newer Older
mariefbourdon's avatar
mariefbourdon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
---
title: "data2.Rmd"
author: "Marie Bourdon"
date: "01/06/2022"
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
16
library(ggplot2)
source("../files/QTL_plot.R")
mariefbourdon's avatar
mariefbourdon committed
17
18
19
20
21
22
23
24
25
26
27
```

## Load
```{r}
genos <- read_csv("geno_data2.csv",show_col_types = FALSE) #genotypes of F2s
annot_mini <- read.csv(url("https://raw.githubusercontent.com/kbroman/MUGAarrays/master/UWisc/mini_uwisc_v2.csv")) #annotation file for miniMUGA
phenos <- read_csv("pheno_data2.csv",show_col_types = FALSE) #phenotypes of F2s
parents <- read_csv("parents_data2.csv",show_col_types = FALSE) #genotypes of parental strains (genotyped with F2s)
strns_ref <- read_csv("ref_geno_data2.csv",show_col_types = FALSE) #reference genotypes of parental strains
```

mariefbourdon's avatar
data3-4    
mariefbourdon committed
28
```{r,cache=TRUE}
mariefbourdon's avatar
mariefbourdon committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
cross_before <- write_rqtl(geno=genos,pheno=phenos,tab=tab_before,ref=strns_ref,par1="StrainA",par2="StrainB",prefix="F2-",pos="cM_cox",path="cluster/cross_before.csv")

# import cross
cross_before <- read.cross(format="csv",file="cluster/cross_before.csv",
                              genotypes=c("0","1","2"),na.strings=c("NA"), convertXdata=TRUE)


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

cross_before_data2 <- cross_before
newmap_before_data2 <- newmap_before
mariefbourdon's avatar
mariefbourdon committed
55
plotmap_before_data2 <- ~plotMap(cross_before_data2,newmap_before_data2,shift=TRUE,main='',ylab='')
mariefbourdon's avatar
mariefbourdon committed
56
57
58
59
60
61
62
63
64
65
66
67
```

### 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
mariefbourdon's avatar
mariefbourdon committed
68

mariefbourdon's avatar
mariefbourdon committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# scanone
cross_before <- calc.genoprob(cross_before, step=2.0, off.end=0.0, 
                                 error.prob=1.0E-4, map.function="haldane", stepwidth="fixed")


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")
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
88
89
```

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

rec_ratios_before_data2

mariefbourdon's avatar
mariefbourdon committed
162
163
164
165
166
#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
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

mariefbourdon's avatar
mariefbourdon committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
## create file for parental strains genotyped

```{r}
#our genotypes

#create tibble with individivual names
parental_strains <- tibble::tibble(StrainA = c("StrainsA_1","StrainsA_2"),
                                   StrainB = c("StrainsB_1","StrainsB_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}
mariefbourdon's avatar
mariefbourdon committed
193
tab2 <- mark_match(tab,ref=strains)
mariefbourdon's avatar
mariefbourdon committed
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
tab2 <- mark_poly(tab2)
tab2 <- mark_na(tab2)
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")
```



### estmap

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

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


load("cluster/newmap_after.rda")
plotMap(cross_after,newmap_after,shift=TRUE)

mariefbourdon's avatar
mariefbourdon committed
216
217
cross_after_data2 <- cross_after
newmap_after_data2 <- newmap_after
mariefbourdon's avatar
mariefbourdon committed
218
plotmap_after_data2 <- ~plotMap(cross_after_data2,newmap_after_data2,shift=TRUE,main="")
mariefbourdon's avatar
mariefbourdon committed
219
220


mariefbourdon's avatar
data3-4    
mariefbourdon committed
221
tab2 <- mark_estmap(tab=tab2,map=newmap_after,annot=annot_mini) #0 marker removed
mariefbourdon's avatar
mariefbourdon committed
222
223
224
```


mariefbourdon's avatar
mariefbourdon committed
225
226
```{r after_scan}
# load rda with perm
mariefbourdon's avatar
mariefbourdon committed
227
load("cluster/after_1000p.rda")
mariefbourdon's avatar
mariefbourdon committed
228
229

# calculate thresholds
mariefbourdon's avatar
mariefbourdon committed
230
threshold_after <- summary(after_1000p,alpha=c(0.05,0.1,0.63)) #donne lod score pour risque 0.05, 0.1, 0.63
mariefbourdon's avatar
mariefbourdon committed
231
232

# scanone
mariefbourdon's avatar
mariefbourdon committed
233
cross_after <- calc.genoprob(cross_after, step=2.0, off.end=0.0, 
mariefbourdon's avatar
mariefbourdon committed
234
235
236
                                 error.prob=1.0E-4, map.function="haldane", stepwidth="fixed")


mariefbourdon's avatar
mariefbourdon committed
237
pheno_after <- scanone(cross=cross_after, 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
238
239
240
summary(pheno_after)

# Plot
mariefbourdon's avatar
mariefbourdon committed
241
pheno_after_plot_data2 <- qtl_plot(pheno_after,lod=data.frame(group = c("alpha=0.05", "alpha=0.1","alpha=0.63"),
mariefbourdon's avatar
mariefbourdon committed
242
243
244
245
246
247
                 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
248
249
    ggtitle("Dataset 2: genome scan") +
  theme(plot.title = element_text(face="plain",size=14,hjust=0.5)) 
mariefbourdon's avatar
mariefbourdon committed
250
pheno_after_plot_data2
mariefbourdon's avatar
mariefbourdon committed
251
```
mariefbourdon's avatar
mariefbourdon committed
252
253
254
255

## Number of markers kept after each function

```{r barplot}
mariefbourdon's avatar
mariefbourdon committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
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))

functions_plot
rm(none,allele,match,poly,prop,functions_df)
mariefbourdon's avatar
mariefbourdon committed
280
281
```

mariefbourdon's avatar
mariefbourdon committed
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
327
328
329
330
331
332
333
334
335
336
337
338
339
### 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_after)){
  mark <- c(mark,names(newmap_after[[i]]))
  chr <- c(chr,rep(i,times=length(newmap_after[[i]])))
  pos <- c(pos,unname(newmap_after[[i]]))
  place <- c(place,"first",rep("middle",times=(length(newmap_after[[i]])-2)),"last")
  prev <- c(NA,unname(newmap_after[[i]])[1:length(newmap_after[[i]])-1])
  previous <- c(previous,prev)
  fol <- c(unname(newmap_after[[i]])[2:length(newmap_after[[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_data2 <- rec_ratios %>% ggplot(aes(x=rat_prev)) +
  geom_histogram(binwidth = .1,alpha=0.4, position="identity",fill="#2171b5") +
mariefbourdon's avatar
mariefbourdon committed
340
  scale_x_log10(limits=c(0.2,1000)) +
mariefbourdon's avatar
mariefbourdon committed
341
  labs(x="Ratio between the calculated and the known distance with the previous marker",
mariefbourdon's avatar
mariefbourdon committed
342
       y="Count",
mariefbourdon's avatar
mariefbourdon committed
343
       fill="",
mariefbourdon's avatar
mariefbourdon committed
344
345
346
       title="Distance between adjacent markers") +
  ggpubr::theme_classic2() +
  theme(plot.title = element_text(face="plain",size=14,hjust=0.5)) 
mariefbourdon's avatar
mariefbourdon committed
347
348
349
350
351
352

rec_ratios_after_data2

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
353
354
355
356
## Narrow peaks

Investigation of high lod score peaks 

mariefbourdon's avatar
mariefbourdon committed
357
358
359
360
361
362
363

```{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),
    lod=c(rep(NA,10),8,rep(NA,9)),
mariefbourdon's avatar
mariefbourdon committed
364
    label=c(rep(NA,10),"p3",rep(NA,9)),
mariefbourdon's avatar
mariefbourdon committed
365
366
367
368
369
370
371
372
373
374
    x=c(rep(NA,10),22,rep(NA,9))
)

pheno_before_annot_data2 <- 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
375
  ) +
mariefbourdon's avatar
mariefbourdon committed
376
377
  ggtitle("Dataset 2: genome scan") +
  theme(plot.title = element_text(face="plain",size=14,hjust=0.5)) 
mariefbourdon's avatar
mariefbourdon committed
378
379
380
381
382
383
384
pheno_before_annot_data2

rm(ann_dat_text)
rm(chrs)
```


mariefbourdon's avatar
mariefbourdon committed
385
### Peak 3
mariefbourdon's avatar
mariefbourdon committed
386

mariefbourdon's avatar
mariefbourdon committed
387
388
```{r peak3_zoom}
peak3 <- qtl_plot(pheno_before,lod=data.frame(group = c("alpha=0.05", "alpha=0.1","alpha=0.63"),
mariefbourdon's avatar
mariefbourdon committed
389
390
391
392
393
394
395
396
397
398
                 lod = threshold_before[1:3]),
         ylab="LOD score",
         title="QTL mapping",
         size=0.6,
         strip.pos="bottom",
         chr="11",
         rug=TRUE) +
    theme(legend.position = "none",
          strip.background = element_blank(),
          strip.text.x = element_blank()) +
mariefbourdon's avatar
mariefbourdon committed
399
    xlab("Position on chromosome 11 (cM)") +
mariefbourdon's avatar
mariefbourdon committed
400
    xlim(c(11,31)) +
mariefbourdon's avatar
mariefbourdon committed
401
402
    ggtitle("Peak p3") +
    theme(plot.title = element_text(face="plain",size=14,hjust=0.5)) 
mariefbourdon's avatar
mariefbourdon committed
403
peak3
mariefbourdon's avatar
mariefbourdon committed
404
405
406
```

1 peak on chromosome 11 on 1 pseudomarker : c11.loc18, postionned between SNT111392585 and mJAX00308021.
mariefbourdon's avatar
mariefbourdon committed
407
408
409

Here are the infos on genotype counts for these markers:

mariefbourdon's avatar
mariefbourdon committed
410
411
412
```{r summary_geno_peak3}
peak3_tab <- tab_before %>% filter(marker %in% c("SNT111392585","mJAX00308021")) %>% select(marker:n_NA)
peak3_tab 
mariefbourdon's avatar
mariefbourdon committed
413
414
415
416
417
418
```

For SNT111392585, all individuals except 1 are homozygous so this marker should be removed. The proportions for mJAX00308021 seem correct.

Graph:

mariefbourdon's avatar
mariefbourdon committed
419
```{r geno_plot_peak7}
mariefbourdon's avatar
mariefbourdon committed
420
421
422
423
424
425
426
427
428
phenotypes <- cross_before[["pheno"]]
map <- cross_before[["geno"]][["11"]][["map"]] 
map <- tibble(marker=names(map),pos=map)
genotypes <- cross_before[["geno"]][["11"]][["data"]]
genotypes <- as_tibble(genotypes)
phenogeno <- cbind(phenotypes,genotypes)
phenogeno %<>% pivot_longer(mbackupUNC110000218:gUNC20538837,names_to="marker",values_to="genotype")
pgmap <- full_join(phenogeno,map,by="marker")

mariefbourdon's avatar
mariefbourdon committed
429
geno_plot3 <- pgmap %>% filter(pos > 15 & pos < 25) %>%
mariefbourdon's avatar
mariefbourdon committed
430
431
432
433
434
435
436
437
438
439
440
441
  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 > 15 & pos < 25) %>% pull(pos),
           label = map %>% filter(pos > 15 & pos < 25) %>% 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)))
mariefbourdon's avatar
mariefbourdon committed
442
geno_plot3
mariefbourdon's avatar
mariefbourdon committed
443
444
445
446
447
448

rm(pgmap,phenotypes,map,genotypes,phenogeno)
```

The two markers before the pseudomarker have an excess of homozygous.

mariefbourdon's avatar
mariefbourdon committed
449
450
451
452
453
454
455
456


## Phenotype distributions

```{r pheno_distrib}
pheno_data2 <- phenos %>% ggplot(aes(x=Pheno)) +
  geom_histogram(binwidth=0.1) +
  ggpubr::theme_classic2() +
mariefbourdon's avatar
mariefbourdon committed
457
458
  labs(y="Count", x="Quantitative phenotype",title="Dataset 2") +
  theme(plot.title = element_text(hjust=0.5,size=14)) 
mariefbourdon's avatar
mariefbourdon committed
459
460
461
pheno_data2
```

mariefbourdon's avatar
mariefbourdon committed
462
463
464
465
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
## 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
502
```{r save_narrow}
mariefbourdon's avatar
mariefbourdon committed
503
tab2_data2 <- tab2
mariefbourdon's avatar
mariefbourdon committed
504
505
506
507
508
509
save(pheno_before_annot_data2,pheno_data2,peak3,peak3_tab,tab2_data2,
     plotmap_before_data2,plotmap_after_data2,
     rec_ratios_before_data2,rec_ratios_after_data2,
     cross_before_data2,newmap_before_data2,cross_after_data2,newmap_after_data2,
     pheno_after_plot_data2,
     file="data2.rda")
mariefbourdon's avatar
mariefbourdon committed
510
rm(tab2_data2)
mariefbourdon's avatar
mariefbourdon committed
511
512
```