data3.Rmd 6.91 KB
Newer Older
mariefbourdon's avatar
mariefbourdon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
---
title: "data3.Rmd"
author: "Marie Bourdon"
date: "02/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
source("../files/QTL_plot.R")
mariefbourdon's avatar
mariefbourdon committed
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
```

## Load
```{r}
genos <- read_csv("geno_data3.csv",show_col_types = FALSE) #genotypes of N2s
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_data3.csv",show_col_types = FALSE) #phenotypes of N2s
parents <- read_csv("parents_data3.csv",show_col_types = FALSE) #genotypes of parental strains (genotyped with N2s)
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
46
47
48

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


mariefbourdon's avatar
mariefbourdon committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
load("cluster/newmap_before.rda")
plotMap(cross_before,newmap_before,shift=TRUE)
```

### 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
69
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="binary", method="em")
mariefbourdon's avatar
mariefbourdon committed
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
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
```

## create file for parental strains genotyped

```{r}
#our genotypes

#create tibble with individivual names
parental_strains <- tibble::tibble(StrainA = c("StrainA_1","StrainA_2"),
                                   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
110
111
tab2 <- mark_prop(tab2,cross="N2",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="N2",par1="StrainA",par2="StrainB")
mariefbourdon's avatar
mariefbourdon committed
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
```

### 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",
                              genotypes=c("0","1"),na.strings=c("NA"), convertXdata=TRUE)


load("cluster/newmap_after.rda")
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")
```
### After: plot estimated map 2

```{r after_map2}
# import cross
mariefbourdon's avatar
data3-4    
mariefbourdon committed
137
cross_after2 <- read.cross(format="csv",file="cluster2/cross_after2.csv",
mariefbourdon's avatar
mariefbourdon committed
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
                              genotypes=c("0","1"),na.strings=c("NA"), convertXdata=TRUE)

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

# plot
plotMap(cross_after2,newmap_after2,shift=TRUE)
plotmap_after <- ~plotMap(cross_after2,newmap_after2,shift=TRUE,main="After stuart")
```

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


mariefbourdon's avatar
mariefbourdon committed
160
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="binary", method="em")
mariefbourdon's avatar
mariefbourdon committed
161
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
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) +
    theme(legend.position = "none") +
    ggtitle("")
pheno_after_plot
```

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

mariefbourdon's avatar
mariefbourdon committed
200
functions_plot
mariefbourdon's avatar
mariefbourdon committed
201
rm(none,allele,match,poly,prop)
mariefbourdon's avatar
mariefbourdon committed
202
203
204
205
206
207
208
```


```{r}
pheno_before_data3 <- pheno_before_plot
save(pheno_before_data3,file="data3_peaks.rda")
```