-
Notifications
You must be signed in to change notification settings - Fork 0
/
.Rhistory
512 lines (512 loc) · 20.8 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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
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
274
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
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
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
382
383
384
385
386
387
388
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
438
439
440
441
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
505
506
507
508
509
510
511
512
tmp$X1 <- gsub(":.*","", tmp$X1)
tmp$X2 <- gsub(":.*","", tmp$X2)
idx <- rep(1:nrow(tmp), rowSums(tmp[,c(1,2)]!=""))
tmp2 <- tmp[idx,]
tmp2[duplicated(tmp2$bed.ID_caller),]$X1 <- tmp2[duplicated(tmp2$bed.ID_caller),]$X2
tmp3 <- tmp2[,-2]
tmp3 <- cbind(tmp3, stringr::str_split_fixed(tmp3$X1,"",2))
colnames(tmp3) <- c("strands","ID_caller","strand1","strand2")
strand1 <- tmp3$strand1
strand2 <- tmp3$strand2
#bed <- bed[match(tmp3$ID_caller, bed$ID),]
#bed$strand1 <- tmp3$strand1
#bed$strand2 <- tmp3$strand2
}
if(sum(!is.na(bed$INFO_CT)) != 0){
strand1 <- rep(NA, nrow(bed)); strand2 <- rep(NA, nrow(bed))
strand1[bed$INFO_CT=="3to5"] <- "+"; strand2[bed$INFO_CT=="3to5"] <- "-"
strand1[bed$INFO_CT=="5to3"] <- "-"; strand2[bed$INFO_CT=="5to3"] <- "+"
strand1[bed$INFO_CT=="3to3"] <- "+"; strand2[bed$INFO_CT=="3to3"] <- "+"
strand1[bed$INFO_CT=="5to5"] <- "-"; strand2[bed$INFO_CT=="5to5"] <- "-"
strand1[bed$INFO_CT=="NtoN"] <- NA; strand2[bed$INFO_CT=="NtoN"] <- NA
}
if(sum(!is.na(bed$INFO_INV5)) !=0){
strand1 <- rep(NA, nrow(bed)); strand2 <- rep(NA, nrow(bed))
strand1[bed$INFO_INV5] <- "-";strand2[bed$INFO_INV5] <- "-"
strand1[bed$INFO_INV3] <- "+";strand2[bed$INFO_INV3] <- "+"
}
ALT <- bed$ALT
tmp <- gsub("\\:.*",'', ALT[grepl('\\[',ALT) | grepl('\\]',ALT)])
tmp1 <- gsub(".*\\[",'', tmp)
tmp2 <- gsub(".*\\]",'', tmp1)
chrom1 = as.character(bed$CHROM)
chrom2 <- chrom1
chrom2[grepl('\\[',ALT) | grepl('\\]',ALT)] <- tmp2
tmp <- gsub(".*\\:",'', ALT[grepl('\\[',ALT) | grepl('\\]',ALT)])
tmp1 <- gsub("\\[.*",'', tmp)
tmp2 <- gsub("\\].*",'', tmp1)
pos2 <- bed$INFO_END
pos2[grepl('\\[',ALT) | grepl('\\]',ALT)] <- tmp2
pos2[is.na(pos2)] <- bed$POS[is.na(pos2)] ###if no POS2 then use #CHROM in VCF
bedpe <- data.frame(chrom1=bed$CHROM,
pos1=bed$POS,
chrom2=paste0(tolower(substring(chrom2,1,3)), substring(chrom2,4,nchar(chrom2))),
pos2=pos2,
ALT=ALT,
stringsAsFactors = FALSE)
bedpe <- data.frame(bedpe, bed[,!(colnames(bed) %in% c("CHROM","POS","INFO_END","ALT"))])
colnames(bedpe) <- c("chrom1", "pos1","chrom2","pos2","ALT", colnames(bed)[!(colnames(bed) %in% c("CHROM","POS","INFO_END","ALT"))])
return(bedpe)
}
vcf_file <- system.file("extdata", "lumpy_SVEngine_TumorSV2.60x_NormalSV1.60x_0.5.vcf", package = "ShinySoSV2")
bed <- vcf_to_bed(vcf_file)
head(bed)
tail(bed)
bedpe <- bed_to_bedpe(bed)
head(bedpe)
tail(bedpe)
vcf_file <- system.file("extdata",
"GRIDSS_SVEngine_TumorSV2.60x_NormalSV1.60x_0.5_somatic_PASS_annotated.vcf",
package = "ShinySoSV2")
bed <- vcf_to_bed(vcf_file)
bed_test <- data.frame(CHROM = bed$CHROM,
POS = bed$POS,
ALT = bed$ALT)
usethis::use_data(bed_test,overwrite = TRUE)
vcf_file <- system.file("extdata",
"lumpy_SVEngine_TumorSV2.60x_NormalSV1.60x_0.5_TumorminSU4.vcf",
package = "ShinySoSV2")
CallerA_bed <- simple_SVTYPE_classification(bed = vcf_to_bed(vcf_file), "CallerA")
#' Convert strands into standard form
#'
#' This function read bed format
#'
#' @param bed dataframe
#' @return data frame
#' @export
strands_standardisation <- function(bed){
if(length(bed$ID_caller) == 0){bed$ID_caller = c(1:nrow(bed))}
strand1 <- rep(NA, nrow(bed)); strand2 <- rep(NA, nrow(bed))
if(sum(!is.na(bed$INFO_STRANDS))!=0){
tmp <- data.frame(stringr::str_split_fixed(bed$INFO_STRANDS,",",2), bed$ID_caller)
tmp$X1 <- gsub(":.*","", tmp$X1)
tmp$X2 <- gsub(":.*","", tmp$X2)
idx <- rep(1:nrow(tmp), rowSums(tmp[,c(1,2)]!=""))
tmp2 <- tmp[idx,]
tmp2[duplicated(tmp2$bed.ID_caller),]$X1 <- tmp2[duplicated(tmp2$bed.ID_caller),]$X2
tmp3 <- tmp2[,-2]
tmp3 <- cbind(tmp3, stringr::str_split_fixed(tmp3$X1,"",2))
colnames(tmp3) <- c("strands","ID_caller","strand1","strand2")
}else if(sum(!is.na(bed$INFO_CT)) != 0){
tmp <- data.frame(bed$INFO_CT, ID_caller = bed$ID_caller)
strand1[tmp$INFO_CT=="3to5"] <- "+"; strand2[tmp$INFO_CT=="3to5"] <- "-"
strand1[tmp$INFO_CT=="5to3"] <- "-"; strand2[tmp$INFO_CT=="5to3"] <- "+"
strand1[tmp$INFO_CT=="3to3"] <- "+"; strand2[tmp$INFO_CT=="3to3"] <- "+"
strand1[tmp$INFO_CT=="5to5"] <- "-"; strand2[tmp$INFO_CT=="5to5"] <- "-"
strand1[tmp$INFO_CT=="NtoN"] <- NA; strand2[tmp$INFO_CT=="NtoN"] <- NA
tmp3 <- cbind(tmp, strand1, strand2)
}else if(sum(!is.na(bed$INFO_INV5)) !=0){
tmp <- data.frame(bed$INFO_INV5, bed$INFO_INV3, ID_caller = bed$ID_caller)
strand1[bed$INFO_INV5] <- "-";strand2[bed$INFO_INV5] <- "-"
strand1[bed$INFO_INV3] <- "+";strand2[bed$INFO_INV3] <- "+"
tmp3 <- cbind(tmp, strand1, strand2)
}else{
tmp3 <- cbind(bed, strand1, strand2)
}
bed2 <- bed[match(tmp3$ID_caller, bed$ID_caller),]
bed2$strand1 <- tmp3$strand1
bed2$strand2 <- tmp3$strand2
if((sum(bed2$INFO_SVTYPE %in% c("DEL","DUP")) != 0) & sum(is.na(bed2$strand1))!=0){
bed2[is.na(bed2$strand1) & bed2$INFO_SVTYPE == "DEL",]$strand1 <- "+"
bed2[is.na(bed2$strand2) & bed2$INFO_SVTYPE == "DEL",]$strand2 <- "-"
bed2[is.na(bed2$strand1) & bed2$INFO_SVTYPE == "DUP",]$strand1 <- "-"
bed2[is.na(bed2$strand2) & bed2$INFO_SVTYPE == "DUP",]$strand2 <- "+"
}
return(bed2)
}
#' Convert bed format to bedpe format
#'
#' This function read bed format
#'
#' @param bed data frame
#' @return data frame
#' @export
bed_to_bedpe <- function(bed){
bed <- strands_standardisation(bed)
ALT <- bed$ALT
tmp <- gsub("\\:.*",'', ALT[grepl('\\[',ALT) | grepl('\\]',ALT)])
tmp1 <- gsub(".*\\[",'', tmp)
tmp2 <- gsub(".*\\]",'', tmp1)
chrom1 = as.character(bed$CHROM)
chrom2 <- chrom1
chrom2[grepl('\\[',ALT) | grepl('\\]',ALT)] <- tmp2
tmp <- gsub(".*\\:",'', ALT[grepl('\\[',ALT) | grepl('\\]',ALT)])
tmp1 <- gsub("\\[.*",'', tmp)
tmp2 <- gsub("\\].*",'', tmp1)
pos2 <- bed$INFO_END
pos2[grepl('\\[',ALT) | grepl('\\]',ALT)] <- tmp2
pos2[is.na(pos2)] <- bed$POS[is.na(pos2)] ###if no POS2 then use #CHROM in VCF
strand1 <- bed$strand1; strand2 <- bed$strand2
###[p[t
strand1[grepl('\\[', bed$ALT) & substr(bed$ALT,1,1) == "["] <- "-"
strand2[grepl('\\[', bed$ALT) & substr(bed$ALT,1,1) == "["] <- "-"
###t[p[
strand1[grepl('\\[', bed$ALT) & substr(bed$ALT,1,1) != "["] <- "+"
strand2[grepl('\\[', bed$ALT) & substr(bed$ALT,1,1) != "["] <- "-"
###t]p]
strand1[grepl(']', bed$ALT) & substr(bed$ALT,1,1) != "]"] <- "+"
strand2[grepl(']', bed$ALT) & substr(bed$ALT,1,1) != "]"] <- "+"
###]p]t
strand1[grepl(']', bed$ALT) & substr(bed$ALT,1,1) == "]"] <- "-"
strand2[grepl(']', bed$ALT) & substr(bed$ALT,1,1) == "]"] <- "+"
bedpe <- data.frame(chrom1=bed$CHROM,
pos1=bed$POS,
chrom2=paste0(tolower(substring(chrom2,1,3)), substring(chrom2,4,nchar(chrom2))),
pos2=pos2,
strand1 = strand1,
strand2 = strand2,
ALT=ALT,
stringsAsFactors = FALSE)
bedpe <- data.frame(bedpe, bed[,!(colnames(bed) %in% c("CHROM","POS","INFO_END","ALT","strand1","strand2"))])
colnames(bedpe) <- c("chrom1", "pos1","chrom2","pos2","strand1","strand2","ALT",
colnames(bed)[!(colnames(bed) %in% c("CHROM","POS","INFO_END","ALT","strand1","strand2"))])
return(bedpe)
}
vcf_file <- system.file("extdata",
"lumpy_SVEngine_TumorSV2.60x_NormalSV1.60x_0.5_TumorminSU4.vcf",
package = "ShinySoSV2")
CallerA_bed <- simple_SVTYPE_classification(bed = vcf_to_bed(vcf_file), "CallerA")
#' Classify SV types based on VCF
#'
#' This function read bed format
#'
#' @param bed datafame of bed format
#' @param caller_name name of caller to be used in ID
#' @return data frame
#' @export
simple_SVTYPE_classification <- function(bed, caller_name){
bedpe <- bed_to_bedpe(bed)
if(length(bedpe$ID_caller)!=0){
bedpe <- bedpe[is.na(match(bedpe$ID_caller, bedpe$INFO_MATEID_caller)) | ### either don't have mate (i.e. not BND)
(c(1:nrow(bedpe)) < match(bedpe$ID_caller, bedpe$INFO_MATEID_caller)),] ### or present first as BND
}
SV_index <- c(1:nrow(bedpe))
event_index <- SV_index
SVTYPE <- bedpe$INFO_SVTYPE
SVTYPE[(bedpe$strand1 == "+") & (bedpe$strand2 == "-") & (bedpe$chrom1 == bedpe$chrom2)] <- "DEL"
SVTYPE[(bedpe$strand1 == "-") & (bedpe$strand2 == "+") & (bedpe$chrom1 == bedpe$chrom2)] <- "DUP"
SVTYPE[(bedpe$strand1 == bedpe$strand2) & (bedpe$chrom1 == bedpe$chrom2)] <- "INV"
SVTYPE[(bedpe$chrom1 != bedpe$chrom2)] <- "TRA"
SVTYPE[is.na(bedpe$strand1)] <- "INS"
standard_bedpe <- data.frame(chrom1 = as.character(bedpe$chrom1),
pos1 = as.integer(bedpe$pos1),
chrom2 = as.character(bedpe$chrom2),
pos2 = as.integer(bedpe$pos2),
SVTYPE = SVTYPE,
strand1 = bedpe$strand1,
strand2 = bedpe$strand2,
ID = paste0(caller_name,"_",SV_index,"_1_",event_index),
ID_mate = paste0(caller_name,"_",SV_index,"_2_",event_index),
#ALT = bedpe$ALT,
stringsAsFactors = FALSE)
bedpe_SVTYPE_classified <- data.frame(standard_bedpe, bedpe[,!(colnames(bedpe) %in% c("chrom1","chrom2","pos1","pos2","strand1","strand2"))])
colnames(bedpe_SVTYPE_classified) <- c("chrom1", "pos1","chrom2","pos2","SVTYPE",
"strand1","strand2",
"ID","ID_mate",
colnames(bedpe)[!(colnames(bedpe) %in% c("chrom1","chrom2","pos1","pos2","strand1","strand2"))])
return(bedpe_SVTYPE_classified)
}
#' Convert VCF format to bed format
#'
#' This function read vcf file and convert it to bed format
#'
#' @param vcf_file names of vcf file
#' @return data frame
#' @export
vcf_to_bed <- function(vcf_file){
vcf <- VariantAnnotation::readVcf(vcf_file)
fixed_df <- vcf@fixed
gr <- vcf@rowRanges
info <- vcf@info
for(field in c("SVLEN","END", "STRANDS","CT","INV5","INV3","MATEID")){
tmp <- eval(parse(text=paste0("info$", field)))
if (length(tmp) == 0){
assign(paste0("INFO_", field), NA)
}else{
idx <- !(sapply(tmp, length))
tmp[idx] <- NA
if(field == "STRANDS"){
assign(paste0("INFO_", field), sapply(tmp, paste, collapse = ","))
}else{
assign(paste0("INFO_", field), unlist(tmp))
}
}
}
bed <- data.frame(CHROM = gr@seqnames,
POS = gr@ranges@start,
ID_caller = gr@ranges@NAMES,
REF = as.character(fixed_df$REF),
ALT = data.frame(fixed_df$ALT)$value,
QUAL = fixed_df$QUAL,
FILTER = fixed_df$FILTER,
INFO_END,
INFO_SVTYPE = info$SVTYPE,
INFO_SVLEN,
INFO_STRANDS,
INFO_CT = INFO_CT,
INFO_INV5 = INFO_INV5,
INFO_INV3 = INFO_INV3,
INFO_MATEID_caller = INFO_MATEID,
stringsAsFactors = FALSE
)
return(bed)
}
#' Classify SV types based on VCF
#'
#' This function read bed format
#'
#' @param bed datafame of bed format
#' @param caller_name name of caller to be used in ID
#' @return data frame
#' @export
simple_SVTYPE_classification <- function(bed, caller_name){
bedpe <- bed_to_bedpe(bed)
if(length(bedpe$ID_caller)!=0){
bedpe <- bedpe[is.na(match(bedpe$ID_caller, bedpe$INFO_MATEID_caller)) | ### either don't have mate (i.e. not BND)
(c(1:nrow(bedpe)) < match(bedpe$ID_caller, bedpe$INFO_MATEID_caller)),] ### or present first as BND
}
SV_index <- c(1:nrow(bedpe))
event_index <- SV_index
SVTYPE <- bedpe$INFO_SVTYPE
SVTYPE[(bedpe$strand1 == "+") & (bedpe$strand2 == "-") & (bedpe$chrom1 == bedpe$chrom2)] <- "DEL"
SVTYPE[(bedpe$strand1 == "-") & (bedpe$strand2 == "+") & (bedpe$chrom1 == bedpe$chrom2)] <- "DUP"
SVTYPE[(bedpe$strand1 == bedpe$strand2) & (bedpe$chrom1 == bedpe$chrom2)] <- "INV"
SVTYPE[(bedpe$chrom1 != bedpe$chrom2)] <- "TRA"
SVTYPE[is.na(bedpe$strand1)] <- "INS"
standard_bedpe <- data.frame(chrom1 = as.character(bedpe$chrom1),
pos1 = as.integer(bedpe$pos1),
chrom2 = as.character(bedpe$chrom2),
pos2 = as.integer(bedpe$pos2),
SVTYPE = SVTYPE,
strand1 = bedpe$strand1,
strand2 = bedpe$strand2,
ID = paste0(caller_name,"_",SV_index,"_1_",event_index),
ID_mate = paste0(caller_name,"_",SV_index,"_2_",event_index),
#ALT = bedpe$ALT,
stringsAsFactors = FALSE)
bedpe_SVTYPE_classified <- data.frame(standard_bedpe, bedpe[,!(colnames(bedpe) %in% c("chrom1","chrom2","pos1","pos2","strand1","strand2"))])
colnames(bedpe_SVTYPE_classified) <- c("chrom1", "pos1","chrom2","pos2","SVTYPE",
"strand1","strand2",
"ID","ID_mate",
colnames(bedpe)[!(colnames(bedpe) %in% c("chrom1","chrom2","pos1","pos2","strand1","strand2"))])
return(bedpe_SVTYPE_classified)
}
#' Convert strands into standard form
#'
#' This function read bed format
#'
#' @param bed dataframe
#' @return data frame
#' @export
strands_standardisation <- function(bed){
if(length(bed$ID_caller) == 0){bed$ID_caller = c(1:nrow(bed))}
strand1 <- rep(NA, nrow(bed)); strand2 <- rep(NA, nrow(bed))
if(sum(!is.na(bed$INFO_STRANDS))!=0){
tmp <- data.frame(stringr::str_split_fixed(bed$INFO_STRANDS,",",2), bed$ID_caller)
tmp$X1 <- gsub(":.*","", tmp$X1)
tmp$X2 <- gsub(":.*","", tmp$X2)
idx <- rep(1:nrow(tmp), rowSums(tmp[,c(1,2)]!=""))
tmp2 <- tmp[idx,]
tmp2[duplicated(tmp2$bed.ID_caller),]$X1 <- tmp2[duplicated(tmp2$bed.ID_caller),]$X2
tmp3 <- tmp2[,-2]
tmp3 <- cbind(tmp3, stringr::str_split_fixed(tmp3$X1,"",2))
colnames(tmp3) <- c("strands","ID_caller","strand1","strand2")
}else if(sum(!is.na(bed$INFO_CT)) != 0){
tmp <- data.frame(bed$INFO_CT, ID_caller = bed$ID_caller)
strand1[tmp$INFO_CT=="3to5"] <- "+"; strand2[tmp$INFO_CT=="3to5"] <- "-"
strand1[tmp$INFO_CT=="5to3"] <- "-"; strand2[tmp$INFO_CT=="5to3"] <- "+"
strand1[tmp$INFO_CT=="3to3"] <- "+"; strand2[tmp$INFO_CT=="3to3"] <- "+"
strand1[tmp$INFO_CT=="5to5"] <- "-"; strand2[tmp$INFO_CT=="5to5"] <- "-"
strand1[tmp$INFO_CT=="NtoN"] <- NA; strand2[tmp$INFO_CT=="NtoN"] <- NA
tmp3 <- cbind(tmp, strand1, strand2)
}else if(sum(!is.na(bed$INFO_INV5)) !=0){
tmp <- data.frame(bed$INFO_INV5, bed$INFO_INV3, ID_caller = bed$ID_caller)
strand1[bed$INFO_INV5] <- "-";strand2[bed$INFO_INV5] <- "-"
strand1[bed$INFO_INV3] <- "+";strand2[bed$INFO_INV3] <- "+"
tmp3 <- cbind(tmp, strand1, strand2)
}else{
tmp3 <- cbind(bed, strand1, strand2)
}
bed2 <- bed[match(tmp3$ID_caller, bed$ID_caller),]
bed2$strand1 <- tmp3$strand1
bed2$strand2 <- tmp3$strand2
if((sum(bed2$INFO_SVTYPE %in% c("DEL","DUP")) != 0) & sum(is.na(bed2$strand1))!=0){
bed2[is.na(bed2$strand1) & bed2$INFO_SVTYPE == "DEL",]$strand1 <- "+"
bed2[is.na(bed2$strand2) & bed2$INFO_SVTYPE == "DEL",]$strand2 <- "-"
bed2[is.na(bed2$strand1) & bed2$INFO_SVTYPE == "DUP",]$strand1 <- "-"
bed2[is.na(bed2$strand2) & bed2$INFO_SVTYPE == "DUP",]$strand2 <- "+"
}
return(bed2)
}
#' Convert bed format to bedpe format
#'
#' This function read bed format
#'
#' @param bed data frame
#' @return data frame
#' @export
bed_to_bedpe <- function(bed){
bed <- strands_standardisation(bed)
ALT <- bed$ALT
tmp <- gsub("\\:.*",'', ALT[grepl('\\[',ALT) | grepl('\\]',ALT)])
tmp1 <- gsub(".*\\[",'', tmp)
tmp2 <- gsub(".*\\]",'', tmp1)
chrom1 = as.character(bed$CHROM)
chrom2 <- chrom1
chrom2[grepl('\\[',ALT) | grepl('\\]',ALT)] <- tmp2
tmp <- gsub(".*\\:",'', ALT[grepl('\\[',ALT) | grepl('\\]',ALT)])
tmp1 <- gsub("\\[.*",'', tmp)
tmp2 <- gsub("\\].*",'', tmp1)
pos2 <- bed$INFO_END
pos2[grepl('\\[',ALT) | grepl('\\]',ALT)] <- tmp2
pos2[is.na(pos2)] <- bed$POS[is.na(pos2)] ###if no POS2 then use #CHROM in VCF
strand1 <- bed$strand1; strand2 <- bed$strand2
###[p[t
strand1[grepl('\\[', bed$ALT) & substr(bed$ALT,1,1) == "["] <- "-"
strand2[grepl('\\[', bed$ALT) & substr(bed$ALT,1,1) == "["] <- "-"
###t[p[
strand1[grepl('\\[', bed$ALT) & substr(bed$ALT,1,1) != "["] <- "+"
strand2[grepl('\\[', bed$ALT) & substr(bed$ALT,1,1) != "["] <- "-"
###t]p]
strand1[grepl(']', bed$ALT) & substr(bed$ALT,1,1) != "]"] <- "+"
strand2[grepl(']', bed$ALT) & substr(bed$ALT,1,1) != "]"] <- "+"
###]p]t
strand1[grepl(']', bed$ALT) & substr(bed$ALT,1,1) == "]"] <- "-"
strand2[grepl(']', bed$ALT) & substr(bed$ALT,1,1) == "]"] <- "+"
bedpe <- data.frame(chrom1=bed$CHROM,
pos1=bed$POS,
chrom2=paste0(tolower(substring(chrom2,1,3)), substring(chrom2,4,nchar(chrom2))),
pos2=pos2,
strand1 = strand1,
strand2 = strand2,
ALT=ALT,
stringsAsFactors = FALSE)
bedpe <- data.frame(bedpe, bed[,!(colnames(bed) %in% c("CHROM","POS","INFO_END","ALT","strand1","strand2"))])
colnames(bedpe) <- c("chrom1", "pos1","chrom2","pos2","strand1","strand2","ALT",
colnames(bed)[!(colnames(bed) %in% c("CHROM","POS","INFO_END","ALT","strand1","strand2"))])
return(bedpe)
}
usethis::use_data(CallerA_bed,overwrite = TRUE)
CallerA_bed <- simple_SVTYPE_classification(bed = vcf_to_bed(vcf_file), "CallerA")
usethis::use_data(CallerA_bed,overwrite = TRUE)
vcf_file <- system.file("extdata",
"manta_SVEngine_TumorSV2.60x_NormalSV1.60x_0.5.T.PASS.recode.vcf",
package = "ShinySoSV2")
CallerB_bed <- simple_SVTYPE_classification(bed = vcf_to_bed(vcf_file), "CallerB")
usethis::use_data(CallerB_bed,overwrite = TRUE)
vcf_file <- system.file("extdata",
"GRIDSS_SVEngine_TumorSV2.60x_NormalSV1.60x_0.5_somatic_PASS_annotated.vcf",
package = "ShinySoSV2")
CallerC_bed <- simple_SVTYPE_classification(bed = vcf_to_bed(vcf_file), "CallerC")
usethis::use_data(CallerC_bed,overwrite = TRUE)
devtools::document()
?use_data
devtools::document()
set.seed(1)
input_SV_count <- data.frame(sampleID = paste0("sample_",c(1:100)),
DEL = sample.int(300, 100, replace = TRUE),
DUP = sample.int(300, 100, replace = TRUE),
INS = sample.int(100, 100, replace = TRUE),
INV = sample.int(300, 100, replace = TRUE),
TRA = sample.int(300, 100, replace = TRUE))
usethis::use_data(input_SV_count, overwrite = TRUE)
devtools::document()
devtools::install_github("tgong1/ShinySoSV2")
library(ShinySoSV2)
setwd("~/Desktop/work_at_home/HRPCa_SV_method_paper/TEST_R_script2")
install.packages("devtools")
install.packages("devtools")
install.packages("remotes")
devtools::install_github("tgong1/ShinySoSV2")
library(ShinySoSV2)
setwd("~/Desktop/work_at_home/HRPCa_SV_method_paper/TEST_R_script2")
remove.packages("curl")
remove.packages("httr")
install.packages("curl")
install.packages("curl")
install.packages("httr")
devtools::install_github("tgong1/ShinySoSV2")
options(download.file.method = "libcurl")
devtools::install_github("tgong1/ShinySoSV2")
options(download.file.method = "wininet")
devtools::install_github("tgong1/ShinySoSV2")
?options
options(download.file.method = "curl")
devtools::install_github("tgong1/ShinySoSV2")
set.seed(1)
input_SV_count <- data.frame(sampleID = paste0("sample_",c(1:100)),
DEL = sample.int(300, 100, replace = TRUE),
DUP = sample.int(300, 100, replace = TRUE),
INS = sample.int(100, 100, replace = TRUE),
INV = sample.int(300, 100, replace = TRUE),
TRA = sample.int(300, 100, replace = TRUE))
usethis::use_data(input_SV_count, overwrite = TRUE)
devtools::document()
###Test data for CNV integration, currently use sample UP2003 in HRPCa project
SCNV <- read.table(system.file("extdata",
"UP2003-T.final.call.threshold.cns",
package = "ShinySoSV2"), header = TRUE)
CNV_bed <- SCNV[,c(1,2,3,6)]
View(CNV_bed)
usethis::use_data(CNV_bed, overwrite = TRUE)
SCNV <- read.table(system.file("extdata",
"UP2003_Manta_GRIDSS_intersect_both_high_confidence.bedpe",
package = "ShinySoSV2"), header = TRUE)
SV_bed <- bedpe[,c(1:10)]
bedpe <- read.table(system.file("extdata",
"UP2003_Manta_GRIDSS_intersect_both_high_confidence.bedpe",
package = "ShinySoSV2"), header = TRUE)
View(bedpe)
SV_bed <- bedpe[,c(1:10)]
usethis::use_data(SV_bed, overwrite = TRUE)
devtools::install_github("tgong1/ShinySoSV2")
library(ShinySoSV2)
ShinySoSV2::Spectrum_SV_type()
load("/Users/tingtinggong/Desktop/work_at_home/HRPCa_SV_method_paper/ShinySoSV2/data/input_SV_bed.rds")
All_sampleID <- paste0("sample_",c(1:100))
All_input_df_name <- paste0(All_sampleID, "_df")
input_SV_count <- Summary_SV_type(All_sampleID, All_input_df_name)
head(input_SV_count)
data("input_SV_count")
hyper_SV <- Spectrum_SV_type(input_SV_count,threshold_total = 500, threshold_relative_freq = 0.5)
data()
data(SV_bed)
SV_bed
head(SV_bed)
data(CNV_bed)
head(CNV_bed)
data(CallerA_bed)
gene_bed <- load(system.file("extdata", "gene_bed.Rdata", package = "ShinySoSV2"))
system.file("extdata",
"GRIDSS_SVEngine_TumorSV2.60x_NormalSV1.60x_0.5_somatic_PASS_annotated.vcf",
package = "ShinySoSV2")
library(ShinySoSV2)
system.file("extdata",
"GRIDSS_SVEngine_TumorSV2.60x_NormalSV1.60x_0.5_somatic_PASS_annotated.vcf",
package = "ShinySoSV2")
gene_bed <- load(system.file("extdata", "gene_bed.Rdata", package = "ShinySoSV2"))
system.file("extdata", "gene_bed.Rdata", package = "ShinySoSV2")
gene_bed <- load("/Users/tingtinggong/Desktop/work_at_home/HRPCa_SV_method_paper/ShinySoSV2/gene_bed.Rdata")
gene_bed <- load("/Users/tingtinggong/Desktop/work_at_home/HRPCa_SV_method_paper/ShinySoSV2/inst/extdata/gene_bed.Rdata")
usethis::use_data(gene_bed, overwrite = TRUE)
gene_bed
gene_bed <- load("/Users/tingtinggong/Desktop/work_at_home/HRPCa_SV_method_paper/ShinySoSV2/inst/extdata/gene_bed.Rdata")
?load
load("/Users/tingtinggong/Desktop/work_at_home/HRPCa_SV_method_paper/ShinySoSV2/inst/extdata/gene_bed.Rdata")
devtools::document()
devtools::document()
data(CallerA_bed)
load(system.file("extdata", "gene_bed.Rdata", package = "ShinySoSV2"))
bedtools_dir = "/opt/homebrew/bin/bedtools"
CallerA_bed_GeneAnnotated <- SV_bedpe_gene_annotation(input_df_name = "CallerA_bed", gene_bed, bedtools_dir)
usethis::use_data(CallerA_bed_GeneAnnotated, overwrite = TRUE)
df_All_gene_fusions_ensembl <- read.csv("/Users/tingtinggong/Desktop/work_at_home/HYPER-DUP/SomaticSV_MantaGRIDSS/All_gene_fusions.csv")
usethis::use_data(df_All_gene_fusions_ensembl, overwrite = TRUE)
df_All_gene_fusions <- read.csv("/Users/tingtinggong/Desktop/work_at_home/HYPER-DUP/SomaticSV_MantaGRIDSS/All_gene_fusions.csv")
df_All_gene_fusions <- df_All_gene_fusions[!(df_All_gene_fusions$sampleID %in% c("16599-1159140", "10651-1042378","UP2063","UP2037","UP2041")),]
df_All_gene_fusions$sampleID<- gsub('-.*','',as.character(df_All_gene_fusions$sampleID))
df_All_gene_fusions$SVTYPE[df_All_gene_fusions$SVTYPE=="TRA_INV"] <- "TRA"
ProstateCancer_SV_bed_GeneAnnotated <- df_All_gene_fusions[,c(1:11,18,19)]
View(ProstateCancer_SV_bed_GeneAnnotated)
usethis::use_data(ProstateCancer_SV_bed_GeneAnnotated, overwrite = TRUE)
devtools::document()