data1.Rmd 18.2 KB
Newer Older
mariefbourdon's avatar
mariefbourdon committed
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
---
title: "data1.Rmd"
author: "Marie Bourdon"
date: '2022-06-24'
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(stuart)
library(magrittr)
library(readr)
library(stringr)
library(qtl)
library(ggplot2)
source("../files/QTL_plot.R")
```

## Load

```{r laod}
data(genos)
summary(genos)
data(phenos)
summary(phenos)
annot_mini <- read.csv(url("https://raw.githubusercontent.com/kbroman/MUGAarrays/master/UWisc/mini_uwisc_v2.csv"))
```

## Parental genotypes

```{r}
#our genotypes

#create tibble with individivual names
parental_strains <- tibble::tibble(parent1 = c("StrainsA_1","StrainsA_2"),
                                   parent2 = c("StrainsB_1","StrainsB_2"))


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

#remove genotypes of parental strains from genos data frame
genos %<>% filter(!Sample.ID %in% c("StrainsA_1","StrainsA_2","StrainsB_1","StrainsB_2"))

#summary
summary(strains)


#reference genotypes
#load parental strains genotype data from Neogen
strns_ref <- read.csv("files/ref_genotypes.csv")

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

#summary
summary(strns_ref)
```

## Before after

### Before: creation of Rqtl csv file 

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

# create rqtl csv file
write_rqtl(geno=genos,pheno=phenos,tab=tab_before,ref=strns_ref,par1="parent1",par2="parent2",prefix="ind_",pos="cM_cox",path="files/cluster/cross_before.csv")
```

### Before: newmap and permutation

These objects were produced on our cluster with the following script: /files/cluster/before_after.R

### Before: plot estimated map

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

# load rda with newmap
load("files/cluster/newmap_before.rda")

# plot
plotMap(cross_before,newmap_before,shift=TRUE)
mariefbourdon's avatar
mariefbourdon committed
91
plotmap_before <- ~plotMap(cross_before,newmap_before,shift=TRUE,main="", ylab='')
mariefbourdon's avatar
mariefbourdon committed
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
```

## Before: plot genome scan

```{r before_scan}
# load rda with perm
load("files/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")


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") +
mariefbourdon's avatar
mariefbourdon committed
122
123
    ggtitle("Genome scan") +
    theme(plot.title = element_text(face="plain",size=14)) 
mariefbourdon's avatar
mariefbourdon committed
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
pheno_before_plot

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(NA,NA,NA,NA,15,NA,NA,NA,NA,NA,NA,NA,18.3,NA,NA,NA,NA,NA,NA,NA),
    label=c(NA,NA,NA,NA,"p1",NA,NA,NA,NA,NA,NA,NA,"p2",NA,NA,NA,NA,NA,NA,NA),
    x=c(NA,NA,NA,NA,27,NA,NA,NA,NA,NA,NA,NA,33,NA,NA,NA,NA,NA,NA,NA)
)

pheno_before_annot <- 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")
)
pheno_before_annot

rm(ann_dat_text)
rm(chrs)
```

```{r before_plot}
pheno_before_zoom <- 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",
         chrs = "13",
         size=0.6,
         rug = TRUE) +
    theme(legend.position = "none",
          strip.background = element_blank(),
          strip.text.x = element_blank()) +
mariefbourdon's avatar
mariefbourdon committed
159
160
161
    xlab("Position on chromosome 13 (cM)") +
    ggtitle("Peak p2") +
    theme(plot.title = element_text(face="plain",size=14)) 
mariefbourdon's avatar
mariefbourdon committed
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
pheno_before_zoom
```

### 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 <- rec_ratios %>% ggplot(aes(x=rat_prev)) +
  geom_histogram(binwidth = .1,alpha=0.4, position="identity",fill="#990000") +
mariefbourdon's avatar
mariefbourdon committed
226
  scale_x_log10(limits=c(0.2,1000)) +
mariefbourdon's avatar
mariefbourdon committed
227
  labs(x="Ratio between the calculated and the known distance with the previous marker",
mariefbourdon's avatar
mariefbourdon committed
228
       y="Count",
mariefbourdon's avatar
mariefbourdon committed
229
       fill="",
mariefbourdon's avatar
mariefbourdon committed
230
       title="Distance between adjacent markers") +
mariefbourdon's avatar
mariefbourdon committed
231
  geom_vline(xintercept = 5,linetype="dashed") +
mariefbourdon's avatar
mariefbourdon committed
232
233
  ggpubr::theme_classic2() +
  theme(plot.title = element_text(face="plain",size=14,hjust=0.5)) 
mariefbourdon's avatar
mariefbourdon committed
234
235
236

rec_ratios_before

mariefbourdon's avatar
mariefbourdon committed
237
238
239
240
241
#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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
rm(mark,chr,pos,place,previous,follow,kn_previous,kn_follow,fol,kn_fol,kn_pos,kn_prev,i,prev)
```


## Use of stuart's functions

```{r}
data(stuart_tab)
summary(stuart_tab)

tab2 <- mark_match(stuart_tab,ref=strns_ref)
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=strns_ref,cross="F2",par1="parent1",par2="parent2")

data(stuart_newmap)
tab2 <- mark_estmap(tab=tab2,map=stuart_newmap,annot=annot_mini)
```

### After: plot estimated map 2

```{r after_map2}
# import cross
cross_after2 <- read.cross(format="csv",file="files/cluster2/cross_after2.csv",
                              genotypes=c("0","1","2"),na.strings=c("NA"), convertXdata=TRUE)

# load rda with newmap
load("files/cluster2/newmap_after2.rda")

# plot
plotMap(cross_after2,newmap_after2,shift=TRUE)
mariefbourdon's avatar
mariefbourdon committed
274
plotmap_after <- ~plotMap(cross_after2,newmap_after2,shift=TRUE,main="")
mariefbourdon's avatar
mariefbourdon committed
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
```

### After: plot genome scan

```{r after_scan}
# load rda with perm
load("files/cluster2/after_1000p2.rda")

# 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")


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")
summary(pheno_after)

# Plot
pheno_after_plot <- qtl_plot(pheno_after,lod=data.frame(group = c("alpha=0.05", "alpha=0.1","alpha=0.63"),
                 lod = threshold_after[1:3]),
         ylab="LOD score",
         title="QTL mapping",
         x.label = element_blank(),
         size=0.6,
         strip.pos="bottom") +
    theme(legend.position = "none") +
mariefbourdon's avatar
mariefbourdon committed
303
304
305
    ggtitle("Genome scan") +
    theme(plot.title = element_text(face="plain",size=14)) 
pheno_after_plot 
mariefbourdon's avatar
mariefbourdon committed
306
307
308
309
310
311
312
313
314
315
316
317
318

pheno_after_zoom <- qtl_plot(pheno_after,lod=data.frame(group = c("alpha=0.05", "alpha=0.1","alpha=0.63"),
                 lod = threshold_after[1:3]),
         ylab="LOD score",
         title="",
         x.label = element_blank(),
         size=0.6,
         rug = TRUE,
         chr="12") +
    theme(legend.position = "none",
          strip.background = element_blank(),
          strip.text.x = element_blank()) +
    xlab("Position (cM)") +
mariefbourdon's avatar
mariefbourdon committed
319
320
    ggtitle("QTL") +
    theme(plot.title = element_text(face="plain",size=14)) 
mariefbourdon's avatar
mariefbourdon committed
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
pheno_after_zoom
```

### 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 <- rec_ratios %>% ggplot(aes(x=rat_prev)) +
  geom_histogram(binwidth = .1,alpha=0.4, position="identity",fill="#2171b5") +
mariefbourdon's avatar
mariefbourdon committed
382
  scale_x_log10(limits=c(0.2,1000)) +
mariefbourdon's avatar
mariefbourdon committed
383
  labs(x="Ratio between the calculated and the known distance with the previous marker",
mariefbourdon's avatar
mariefbourdon committed
384
       y="Count",
mariefbourdon's avatar
mariefbourdon committed
385
       fill="",
mariefbourdon's avatar
mariefbourdon committed
386
387
388
       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
389
390
391
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

rec_ratios_after

rm(mark,chr,pos,place,previous,follow,kn_previous,kn_follow,fol,kn_fol,kn_pos,kn_prev,i,prev)
```

## 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))

functions_plot
rm(none,allele,match,poly,prop,estmap,naf,functions_df)
```

### Peak 1

```{r peak7_zoom}
peak1 <- 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",
         size=0.6,
         strip.pos="bottom",
         chr="5",
         rug=TRUE) +
    theme(legend.position = "none",
          strip.background = element_blank(),
          strip.text.x = element_blank()) +
mariefbourdon's avatar
mariefbourdon committed
438
    xlab("Position on chromosome 5 (cM)") +
mariefbourdon's avatar
mariefbourdon committed
439
    xlim(c(15,35)) +
mariefbourdon's avatar
mariefbourdon committed
440
441
    ggtitle("Peak p1") +
    theme(plot.title = element_text(face="plain",size=14)) 
mariefbourdon's avatar
mariefbourdon committed
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
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
502
503
504
peak1
```

1 peak on chromosome 2 on 1 marker : mUNC050096588

Here are the infos on genotype counts for these markers:

```{r summary_geno_chr5}
peak1_tab <- tab_before %>% filter(marker %in% c("mUNC050096588")) %>% select(marker:n_NA)
peak1_tab
```

All individuals heterozygous so this marker should be removed.

```{r}
newmap_before[["5"]][18:23]
```

This leads to enormous calculated distance with adjacent markers: 1186.0871-184.5811 = 2187.5930-1186.0871=1001.506 cM with the previous and the following marker.

Graph:

```{r geno_plot_chr5}
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(gUNCHS013469:SAC056009450,names_to="marker",values_to="genotype")
pgmap <- full_join(phenogeno,map,by="marker")

test_plot <- pgmap %>% filter(pos > 20 & 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 > 20 & pos < 30) %>% pull(pos),
           label = map %>% filter(pos > 20 & 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)))
test_plot 
rm(pgmap,phenotypes,map,genotypes,phenogeno)
```

### Peak 2

```{r peak2_zoom}
peak2 <- qtl_plot(pheno_before,
         ylab="LOD score",
         title="QTL mapping",
         x.label = element_blank(),
         size=0.6,
         strip.pos="bottom",
         chr="13",
         rug=TRUE) +
    theme(legend.position = "none",
          strip.background = element_blank(),
          strip.text.x = element_blank()) +
mariefbourdon's avatar
mariefbourdon committed
505
    xlab("Position on chromosome 13 (cM)") +
mariefbourdon's avatar
mariefbourdon committed
506
    xlim(c(23,43)) +
mariefbourdon's avatar
mariefbourdon committed
507
508
    ggtitle("Peak p2") +
    theme(plot.title = element_text(face="plain")) 
mariefbourdon's avatar
mariefbourdon committed
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
peak2
```

1 peak on chromosome 13 on 1 marker : SAC132487883

Here are the infos on genotype counts for this marker:

```{r summary_geno_chr13}
peak2_tab <- tab_before %>% filter(marker %in% c("SAC132487883")) %>% select(marker:n_NA)
peak2_tab
```

All individuals are heterozygous at this loci so this marker should be removed.

```{r}
newmap_before[["13"]][48:50]
```

This leads to enormous calculated distance with adjacent markers: 9521.842-8520.336 = 8520.336-7518.830 = 1001.506 cM with the previous and the following marker.


Graph:

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

test_plot <- pgmap %>% filter(pos > 25 & pos < 35) %>% 
  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.7,size=3,
           x = map %>% filter(pos > 25 & pos < 35) %>% pull(pos),
           label = map %>% filter(pos > 25 & pos < 35) %>% 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 = 55)))
test_plot 
```

## Phenotype distributions

```{r pheno_distrib}
pheno_data1 <- phenos %>% ggplot(aes(x=Pheno)) +
  geom_histogram(binwidth=0.1) +
  ggpubr::theme_classic2() +
mariefbourdon's avatar
mariefbourdon committed
564
565
  labs(y="Count", x="Quantitative phenotype",title="Dataset 1") +
  theme(plot.title = element_text(hjust=0.5,size=14)) 
mariefbourdon's avatar
mariefbourdon committed
566
567
568
569
570
571
572
573
574
575
576
pheno_data1
```


```{r}
save(tab2,strains,strns_ref,phenos,cross_before,cross_after2,newmap_before,newmap_after2,
     plotmap_before,pheno_before_annot,pheno_before_zoom,plotmap_after,pheno_after_plot,pheno_after_zoom,
     peak1,peak1_tab,peak2,peak2_tab,pheno_data1,
     rec_ratios_before,rec_ratios_after,
     file="data1.rda")
```