-
Notifications
You must be signed in to change notification settings - Fork 0
/
binary.Rmd
141 lines (116 loc) · 2.94 KB
/
binary.Rmd
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
---
title: "Binary"
author: "Brian S. Yandell"
date: "5/15/2017"
params:
datapath: "~/Documents/Research/attie_alan/DO/data/DerivedData"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
Goal: Fit binary OTU data (0 vs >0).
Challenge: R/qtl2 has partially implemented this. There is a `model` option for "normal" or "binary", but the "binary" only works if `kinship` is `NULL`. Here we look at it both ways:
- analyze as binary without `kinship`
- analyze as normal with `kinship`
Bottom line: not there yet.
## Setup
```{r}
suppressPackageStartupMessages({
library(qtl2geno)
library(qtl2scan)
library(qtl2ggplot)
library(qtl2pattern)
library(qtl2feather)
library(dplyr)
library(ggplot2)
library(stringr)
library(readr)
})
```
```{r}
datapath <- as.character(params$datapath)
```
```{r}
finegrain <- function(Order,Family,Genus,Species) {
ifelse(is.na(Species),
ifelse(is.na(Genus),
ifelse(is.na(Family),
Order,
ifelse(str_detect(Family, "[0-9]"),
paste(Order, Family),
Family)),
ifelse(str_detect(Genus, "[0-9]"),
paste(Family, Genus),
Genus)),
paste(Genus, Species))
}
```
```{r}
peaks_zero <- read_tsv(file.path(datapath, "otu",
"20170501_peaks_cr97_w0_ra_wTaxonomy.tsv")) %>%
mutate(chr = factor(chr, c(1:19,"X"))) %>%
select(-lodindex) %>%
rename(pheno = lodcolumn) %>%
mutate(longname = paste0(pheno, " (", finegrain(Order,Family,Genus,Species), ")"),
pheno = paste0("z", pheno),
output = pheno,
pheno_group = "OTU_Closed_Ref",
pheno_type = "OTU_Zero")
```
```{r}
peaks_zero %>%
count(pheno) %>%
count(n)
```
```{r}
peaks_zero %>%
select(Phylum:Species) %>%
group_by(Phylum) %>%
summarize_all(n_distinct)
```
```{r}
peaks_zero %>%
count(Order,Family,Genus,Species)
```
```{r}
peaks_zero %>%
select(Phylum:Species) %>%
group_by(Phylum) %>%
summarize_all(funs(sum(is.na(.))))
```
```{r}
table(peaks_zero$chr)
```
## (Re)analysis of normal approach
```{r}
covar <- readRDS(file.path(datapath, "covar.rds"))
covar <- covar[, c("sex", paste0("DOwave", 2:4))]
```
```{r}
botu <- readRDS(file.path(datapath, "otu",
"phe_otu_cr97_filter1010.rds"))
colnames(botu) <- paste0("b", colnames(botu))
botu[botu > 0] <- 1
ncol(botu)
```
```{r}
aprobs <- DOread::read_probs(datapath = file.path(datapath))
```
```{r}
kinship <- readRDS(file.path(datapath, "kinship.rds"))
```
```{r}
scans <- scan1(aprobs$probs, botu[,1:50], kinship, addcovar = covar,
model = "normal")
```
```{r}
saveRDS(scans, file = "botu_normal_1_50.rds")
```
```{r}
scans <- scan1(aprobs$probs, botu[,1:50], NULL, addcovar = covar,
model = "binary")
```
```{r}
saveRDS(scans, file = "botu_binary_1_50.rds")
```