-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
205 lines (205 loc) · 4.7 KB
/
.Rhistory
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
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
199
200
201
202
203
204
205
hello <- function() {
print("Hello, world!")
}
devtools::load_all(".")
library(TEST)
library(TEST)
TEST::compare_vcfs_GT()
??TEST::compare_vcfs_GT()
library(devtools)
check()
library(roxygen2)
compare_vcfs_GT()
library(TEST)
document()
library(TEST)
compare_vcfs_GT()
??compare_vcfs_GT()
??compare_vcfs_GT()
??compare_vcfs_GT()
library(TEST)
devtools::load_all(".")
??compare_vcfs_GT()
??compare_vcfs_GT()
library(TEST)
library(TEST)
??compare_vcfs_GT()
library(TEST)
??compare_vcfs_GT()
install_github("shankarkshakya/mypackage")
library(mypackage)
install_github("shankarkshakya/mypackage")
require::vcfR
library(vcfR)
vcf <- read.vcfR("vcf")
vcfR_to_012 <- function(vcf){
require::vcfR
vcf <- read.vcfR("vcf")
gt <- extract.gt(vcf, "GT")
gt2a <- apply(gt,2, function(x) gsub("1[/|]1","1",x))
gt2b <- gsub("0[/|]0","0",gt2a)
gt2c <- gsub("[10][/|][10]","0.5",gt2b)
gt <- gt2c
vcf@gt <- gt
return(vcf)
}
library(roxygen2)
devtools::document()
library(TEST)
roxygen2::roxygenise()
roxygenise("TEST")
roxygenise()
library(TEST)
??TEST::vcfR_to_012()
library(TEST)
??vcfR_to_012
#' Convert vcfR to 012 format
#'
#' @param vcf vcf file
#'
#' @return vcf file with new GT format
#' @export
#'
#' @examples
vcfR_to_012 <- function(vcf){
require::vcfR
vcf <- read.vcfR("vcf")
gt <- extract.gt(vcf, "GT")
gt2a <- apply(gt,2, function(x) gsub("1[/|]1","2",x))
gt2b <- gsub("0[/|]0","0",gt2a)
gt2c <- gsub("[10][/|][10]","1",gt2b)
gt <- gt2c
vcf@gt <- gt
return(vcf)
}
library(TEST)
vcfR_to_012("vcf1.test.gz")
#' Convert vcfR to 012 format
#'
#' @param vcf vcf file
#'
#' @return vcf file with new GT format
#' @export
#'
#' @examples
vcfR_to_012 <- function(vcf){
library(vcfR)
vcf <- read.vcfR("vcf")
gt <- extract.gt(vcf, "GT")
gt2a <- apply(gt,2, function(x) gsub("1[/|]1","2",x))
gt2b <- gsub("0[/|]0","0",gt2a)
gt2c <- gsub("[10][/|][10]","1",gt2b)
gt <- gt2c
vcf@gt <- gt
return(vcf)
}
vcfR_to_012("vcf1.test.gz")
#' Convert vcfR to 012 format
#'
#' @param vcf vcf file
#'
#' @return vcf file with new GT format
#' @export
#'
#' @examples
vcfR_to_012 <- function(vcf){
library(vcfR)
vcf <- read.vcfR(vcf)
gt <- extract.gt(vcf, "GT")
gt2a <- apply(gt,2, function(x) gsub("1[/|]1","2",x))
gt2b <- gsub("0[/|]0","0",gt2a)
gt2c <- gsub("[10][/|][10]","1",gt2b)
gt <- gt2c
vcf@gt <- gt
return(vcf)
}
vcfR_to_012("vcf1.test.gz")
vcf@gt
p <- vcfR_to_012("vcf1.test.gz")
p
p@gt
find_unique_GT_per_sample("vcf1.test.gz")
library(vcfR)
read.vcfR("vcf1.test.gz")
p <- read.vcfR("vcf1.test.gz")
colnames(p)
colnames(p@gt)
colnames(p@gt)[2:11]
colnames(p@gt)[2:11] <- paste0("Sample_", 1:10)
p
write.vcf(p, "Mytest.vcf.gz")
vcf <- read.vcfR("Mytest.vcf.gz")
gt <- extract.gt(vcf, "GT", return.alleles = TRUE)
vcf <- vcf[which(!duplicated(gt)), ]
gt <- extract.gt(vcf, "GT")
gt2a <- apply(gt,2, function(x) gsub("1[/|]1","1",x))
gt2b <- gsub("0[/|]0","0",gt2a)
gt2c <- gsub("[10][/|][10]","0.5",gt2b)
gt <- gt2c
count_list <- apply(gt, 1, table)
my_min_list <- vector("list", length = length(count_list))
for(i in 1:length(count_list)) {
ith_item <- count_list[[i]]
my_min_list[[i]] <- min(ith_item)
}
q <- gt[which(unlist(lapply(my_min_list, function(x) x == 1))), ]
q <- data.frame(q, stringsAsFactors = FALSE)
test <- q
my_unique <- vector("list", length = nrow(test))
names(my_unique) <- rownames(test)
# Extract unique SNPs per sample
for (i in 1:nrow(test)){
p <- data.frame(apply(test[i,], 1, table))
index <- which(p[,1] == 1)
my_unique[[i]] <- colnames(test[which(test[i,] == rownames(p)[index])])
}
test
vcf
gt <- extract.gt(vcf, "GT")
gt2a <- apply(gt,2, function(x) gsub("1[/|]1","1",x))
gt2b <- gsub("0[/|]0","0",gt2a)
gt2c <- gsub("[10][/|][10]","0.5",gt2b)
gt <- gt2c
gt
count_list <- apply(gt, 1, table)
my_min_list <- vector("list", length = length(count_list))
i <- 1
ith_item <- count_list[[i]]
my_min_list[[i]] <- min(ith_item)
my_min_list
ith_item
for(i in 1:length(count_list)) {
ith_item <- count_list[[i]]
my_min_list[[i]] <- min(ith_item)
}
my_min_list
vcf <- read.vcfR("vcf1.test.gz")
gt <- extract.gt(vcf, "GT", return.alleles = TRUE)
vcf <- vcf[which(!duplicated(gt)), ]
gt <- extract.gt(vcf, "GT")
gt2a <- apply(gt,2, function(x) gsub("1[/|]1","1",x))
gt2b <- gsub("0[/|]0","0",gt2a)
gt2c <- gsub("[10][/|][10]","0.5",gt2b)
gt <- gt2c
count_list <- apply(gt, 1, table)
my_min_list <- vector("list", length = length(count_list))
for(i in 1:length(count_list)) {
ith_item <- count_list[[i]]
my_min_list[[i]] <- min(ith_item)
}
q <- gt[which(unlist(lapply(my_min_list, function(x) x == 1))), ]
q <- data.frame(q, stringsAsFactors = FALSE)
q
vcf
gt
count_list <- apply(gt, 1, table)
my_min_list <- vector("list", length = length(count_list))
my_min_list
for(i in 1:length(count_list)) {
ith_item <- count_list[[i]]
my_min_list[[i]] <- min(ith_item)
}
my_min_list
i <- 1
ith_item <- count_list[[i]]
ith_item