@@ -20,6 +20,7 @@ Segment.ASCAT <- function(data = NULL, mingap = 5E+06, smooth.k = NULL, BAF.filt
20
20
# source("~/git_gustaveroussy/EaCoN/R/mini_functions.R")
21
21
# source("~/git_gustaveroussy/EaCoN/R/plot_functions.R")
22
22
23
+ `%do%` <- foreach :: " %do%"
23
24
24
25
calling.method <- tolower(calling.method )
25
26
@@ -93,11 +94,13 @@ Segment.ASCAT <- function(data = NULL, mingap = 5E+06, smooth.k = NULL, BAF.filt
93
94
94
95
# # Winsorization
95
96
if (! is.null(smooth.k )) {
96
- tmsg(" Smoothing L2R outliers ..." )
97
+ tmsg(" Smoothing L2R outliers ..." )
97
98
cndf <- data.frame (Chr = rep(unlist(cs $ chrom2chr [data $ data $ chrs ]), vapply(data $ data $ ch , length , 1L )), Position = unlist(data $ data $ ch ), MySample = data $ data $ Tumor_LogR [[1 ]], stringsAsFactors = FALSE )
99
+ l2r.nona <- ! is.na(data $ data $ Tumor_LogR [[1 ]])
100
+ cndf <- cndf [l2r.nona ,]
98
101
cndf.wins <- copynumber :: winsorize(data = cndf , pos.unit = " bp" , method = " mad" , k = smooth.k , tau = 1 , verbose = FALSE )
99
- data $ data $ Tumor_LogR [,1 ] <- cndf.wins [, 3 , drop = FALSE ]
100
- rm(list = c(" cndf" , " cndf.wins" ))
102
+ data $ data $ Tumor_LogR [l2r.nona ,1 ] <- cndf.wins [, 3 , drop = FALSE ]
103
+ rm(list = c(" cndf" , " cndf.wins" , " l2r.nona " ))
101
104
}
102
105
103
106
# # BAF filtering
@@ -130,7 +133,8 @@ Segment.ASCAT <- function(data = NULL, mingap = 5E+06, smooth.k = NULL, BAF.filt
130
133
131
134
# # Computing gaps
132
135
if (! is.null(mingap )) {
133
- data $ data $ chr <- foreach(k = data $ data $ ch , .combine = " c" ) %do % {
136
+ # `%do%` <- foreach::"%do%"
137
+ data $ data $ chr <- foreach :: foreach(k = data $ data $ ch , .combine = " c" ) %do % {
134
138
gapz <- which(diff(data $ data $ SNPpos $ pos [k ]) > = mingap )
135
139
return (unname(split(k , findInterval(k , k [gapz + 1 ]))))
136
140
}
@@ -202,11 +206,13 @@ Segment.ASCAT <- function(data = NULL, mingap = 5E+06, smooth.k = NULL, BAF.filt
202
206
# # Winsorization (for aesthetics)
203
207
tmsg(" Smoothing L2R (for plots)..." )
204
208
cndf <- data.frame (Chr = rep(unlist(cs $ chrom2chr [data $ data $ chrs ]), vapply(data $ data $ ch , length , 1L )), Position = unlist(data $ data $ ch ), MySample = data $ data $ Tumor_LogR [[1 ]], stringsAsFactors = FALSE )
209
+ l2r.nona <- ! is.na(data $ data $ Tumor_LogR [[1 ]])
210
+ cndf <- cndf [l2r.nona ,]
205
211
cndf.wins <- copynumber :: winsorize(data = cndf , pos.unit = " bp" , method = " mad" , k = 5 , tau = 1 , verbose = FALSE )
206
- data $ data $ Tumor_LogR_wins <- cndf.wins [, 3 , drop = FALSE ]
212
+ data $ data $ Tumor_LogR_wins <- data $ data $ Tumor_LogR
213
+ data $ data $ Tumor_LogR_wins [l2r.nona ,] <- cndf.wins [, 3 , drop = FALSE ]
207
214
colnames(data $ data $ Tumor_LogR_wins ) <- samplename
208
- rm(list = c(" cndf" , " cndf.wins" ))
209
-
215
+ rm(list = c(" cndf" , " cndf.wins" , " l2r.nona" ))
210
216
211
217
# # PELT rescue
212
218
if (! is.null(SER.pen )) {
@@ -239,7 +245,7 @@ Segment.ASCAT <- function(data = NULL, mingap = 5E+06, smooth.k = NULL, BAF.filt
239
245
tmsg(paste0(" Found " , length(rescued ), " ." ))
240
246
if (length(rescued ) > seg.maxn ) tmsg(" WARNING : Many small events found, profile may be noisy ! Consider using 'smooth.k', or for WES data, strengthen low depth filtering !" )
241
247
data $ meta $ eacon [[" PELT-nseg" ]] <- length(rescued )
242
- `%do%` <- foreach :: " %do%"
248
+ # `%do%` <- foreach::"%do%"
243
249
foreach :: foreach(re = rescued , .combine = " c" ) %do % {
244
250
interv <- mydf $ idx.ori [seg.start [re ]]: mydf $ idx.ori [seg.end [re ]]
245
251
data $ data $ Tumor_LogR_segmented [interv ] <- median(data $ data $ Tumor_LogR [interv , 1 ], na.rm = TRUE )
@@ -354,6 +360,7 @@ Segment.ASCAT <- function(data = NULL, mingap = 5E+06, smooth.k = NULL, BAF.filt
354
360
Start = as.integer(data $ data $ SNPpos $ pos ),
355
361
End = as.integer(data $ data $ SNPpos $ pos ),
356
362
Value = data $ data $ Tumor_LogR_wins [,1 ],
363
+ # Value = data$data$Tumor_LogR[,1],
357
364
stringsAsFactors = FALSE )
358
365
baf.value <- data.frame (Chr = l2r.chr ,
359
366
Start = as.integer(data $ data $ SNPpos $ pos ),
@@ -475,12 +482,14 @@ Segment.FACETS <- function(data = NULL, smooth.k = NULL, BAF.filter = .75, homoC
475
482
))
476
483
477
484
# # Winsorization
478
- if (! is.null(smooth.k )) {
485
+ if (! is.null(smooth.k )) {
479
486
tmsg(" Smoothing L2R outliers ..." )
480
487
cndf <- data.frame (Chr = rep(unlist(cs $ chrom2chr [data $ data $ chrs ]), vapply(data $ data $ ch , length , 1L )), Position = unlist(data $ data $ ch ), MySample = data $ data $ Tumor_LogR [[1 ]], stringsAsFactors = FALSE )
488
+ l2r.nona <- ! is.na(data $ data $ Tumor_LogR [[1 ]])
489
+ cndf <- cndf [l2r.nona ,]
481
490
cndf.wins <- copynumber :: winsorize(data = cndf , pos.unit = " bp" , method = " mad" , k = smooth.k , tau = 1 , verbose = FALSE )
482
- data $ data $ Tumor_LogR [,1 ] <- cndf.wins [, 3 , drop = FALSE ]
483
- rm(list = c(" cndf" , " cndf.wins" ))
491
+ data $ data $ Tumor_LogR [l2r.nona ,1 ] <- cndf.wins [, 3 , drop = FALSE ]
492
+ rm(list = c(" cndf" , " cndf.wins" , " l2r.nona " ))
484
493
}
485
494
486
495
# # BAF filtering
@@ -624,13 +633,16 @@ Segment.FACETS <- function(data = NULL, smooth.k = NULL, BAF.filter = .75, homoC
624
633
tmsg(" No recentering." )
625
634
} else stop(tmsg(" Invalid recentering method called !" ), call. = FALSE )
626
635
627
- # # Winsorization
636
+ # # Winsorization (for aesthetics)
628
637
tmsg(" Smoothing L2R (for plots)..." )
629
638
cndf <- data.frame (Chr = rep(unlist(cs $ chrom2chr [data $ data $ chrs ]), vapply(data $ data $ ch , length , 1L )), Position = unlist(data $ data $ ch ), MySample = data $ data $ Tumor_LogR [[1 ]], stringsAsFactors = FALSE )
639
+ l2r.nona <- ! is.na(data $ data $ Tumor_LogR [[1 ]])
640
+ cndf <- cndf [l2r.nona ,]
630
641
cndf.wins <- copynumber :: winsorize(data = cndf , pos.unit = " bp" , method = " mad" , k = 5 , tau = 1 , verbose = FALSE )
631
- data $ data $ Tumor_LogR_wins <- cndf.wins [, 3 , drop = FALSE ]
642
+ data $ data $ Tumor_LogR_wins <- data $ data $ Tumor_LogR
643
+ data $ data $ Tumor_LogR_wins [l2r.nona ,] <- cndf.wins [, 3 , drop = FALSE ]
632
644
colnames(data $ data $ Tumor_LogR_wins ) <- samplename
633
- rm(list = c(" cndf" , " cndf.wins" ))
645
+ rm(list = c(" cndf" , " cndf.wins" , " l2r.nona " ))
634
646
635
647
636
648
# # PELT rescue
@@ -782,6 +794,7 @@ Segment.FACETS <- function(data = NULL, smooth.k = NULL, BAF.filter = .75, homoC
782
794
Start = data $ data $ SNPpos $ pos ,
783
795
End = data $ data $ SNPpos $ pos ,
784
796
Value = data $ data $ Tumor_LogR_wins [,1 ],
797
+ # Value = data$data$Tumor_LogR[,1],
785
798
stringsAsFactors = FALSE )
786
799
# baf.chr <- if(length(grep(pattern = "chr", x = names(cs$chrom2chr), ignore.case = TRUE)) > 0) unlist(cs$chrom2chr[paste0("chr", as.character(data$data$SNPpos$chrs))]) else unlist(cs$chrom2chr[as.character(data$data$SNPpos$chrs)])
787
800
baf.value <- data.frame (Chr = l2r.chr ,
@@ -844,6 +857,8 @@ Segment.SEQUENZA <- function(data = NULL, smooth.k = NULL, BAF.filter = .75, hom
844
857
845
858
calling.method <- tolower(calling.method )
846
859
860
+ `%do%` <- foreach :: " %do%"
861
+
847
862
if (! is.list(data )) stop(tmsg(" data should be a list !" ), call. = FALSE )
848
863
if (! dir.exists(out.dir )) stop(tmsg(paste0(" Output directory [" , out.dir , " ] does not exist !" )), call. = FALSE )
849
864
if (! (calling.method %in% c(" mad" , " density" ))) stop(tmsg(" calling.method should be 'MAD' or 'density' !" ), call. = FALSE )
@@ -900,9 +915,11 @@ Segment.SEQUENZA <- function(data = NULL, smooth.k = NULL, BAF.filter = .75, hom
900
915
if (! is.null(smooth.k )) {
901
916
tmsg(" Smoothing L2R outliers ..." )
902
917
cndf <- data.frame (Chr = rep(unlist(cs $ chrom2chr [data $ data $ chrs ]), vapply(data $ data $ ch , length , 1L )), Position = unlist(data $ data $ ch ), MySample = data $ data $ Tumor_LogR [[1 ]], stringsAsFactors = FALSE )
918
+ l2r.nona <- ! is.na(data $ data $ Tumor_LogR [[1 ]])
919
+ cndf <- cndf [l2r.nona ,]
903
920
cndf.wins <- copynumber :: winsorize(data = cndf , pos.unit = " bp" , method = " mad" , k = smooth.k , tau = 1 , verbose = FALSE )
904
- data $ data $ Tumor_LogR [,1 ] <- cndf.wins [, 3 , drop = FALSE ]
905
- rm(list = c(" cndf" , " cndf.wins" ))
921
+ data $ data $ Tumor_LogR [l2r.nona ,1 ] <- cndf.wins [, 3 , drop = FALSE ]
922
+ rm(list = c(" cndf" , " cndf.wins" , " l2r.nona " ))
906
923
}
907
924
908
925
# # BAF filtering
@@ -1059,14 +1076,16 @@ Segment.SEQUENZA <- function(data = NULL, smooth.k = NULL, BAF.filter = .75, hom
1059
1076
tmsg(" No recentering." )
1060
1077
} else stop(tmsg(" Invalid recentering method called !" ), call. = FALSE )
1061
1078
1062
- # # Winsorization
1079
+ # # Winsorization (for aesthetics)
1063
1080
tmsg(" Smoothing L2R (for plots)..." )
1064
1081
cndf <- data.frame (Chr = rep(unlist(cs $ chrom2chr [data $ data $ chrs ]), vapply(data $ data $ ch , length , 1L )), Position = unlist(data $ data $ ch ), MySample = data $ data $ Tumor_LogR [[1 ]], stringsAsFactors = FALSE )
1082
+ l2r.nona <- ! is.na(data $ data $ Tumor_LogR [[1 ]])
1083
+ cndf <- cndf [l2r.nona ,]
1065
1084
cndf.wins <- copynumber :: winsorize(data = cndf , pos.unit = " bp" , method = " mad" , k = 5 , tau = 1 , verbose = FALSE )
1066
- data $ data $ Tumor_LogR_wins <- cndf.wins [, 3 , drop = FALSE ]
1085
+ data $ data $ Tumor_LogR_wins <- data $ data $ Tumor_LogR
1086
+ data $ data $ Tumor_LogR_wins [l2r.nona ,] <- cndf.wins [, 3 , drop = FALSE ]
1067
1087
colnames(data $ data $ Tumor_LogR_wins ) <- samplename
1068
- rm(list = c(" cndf" , " cndf.wins" ))
1069
-
1088
+ rm(list = c(" cndf" , " cndf.wins" , " l2r.nona" ))
1070
1089
1071
1090
# # PELT rescue
1072
1091
if (! is.null(SER.pen )) {
@@ -1099,7 +1118,6 @@ Segment.SEQUENZA <- function(data = NULL, smooth.k = NULL, BAF.filter = .75, hom
1099
1118
tmsg(paste0(" Found " , length(rescued ), " ." ))
1100
1119
if (length(rescued ) > seg.maxn ) tmsg(" WARNING : Many small events found, profile may be noisy ! Consider using 'smooth.k', or for WES data, strengthen low depth filtering !" )
1101
1120
data $ meta $ eacon [[" PELT-nseg" ]] <- length(rescued )
1102
- `%do%` <- foreach :: " %do%"
1103
1121
foreach :: foreach(re = rescued , .combine = " c" ) %do % {
1104
1122
interv <- mydf $ idx.ori [seg.start [re ]]: mydf $ idx.ori [seg.end [re ]]
1105
1123
data $ data $ Tumor_LogR_segmented [interv ] <- median(data $ data $ Tumor_LogR [interv , 1 ], na.rm = TRUE )
@@ -1217,6 +1235,7 @@ Segment.SEQUENZA <- function(data = NULL, smooth.k = NULL, BAF.filter = .75, hom
1217
1235
Start = data $ data $ SNPpos $ pos ,
1218
1236
End = data $ data $ SNPpos $ pos ,
1219
1237
Value = data $ data $ Tumor_LogR_wins [,1 ],
1238
+ # Value = data$data$Tumor_LogR[,1],
1220
1239
stringsAsFactors = FALSE )
1221
1240
# baf.chr <- if(length(grep(pattern = "chr", x = names(cs$chrom2chr), ignore.case = TRUE)) > 0) unlist(cs$chrom2chr[paste0("chr", as.character(data$data$SNPpos$chrs))]) else unlist(cs$chrom2chr[as.character(data$data$SNPpos$chrs)])
1222
1241
baf.value <- data.frame (Chr = l2r.chr ,
@@ -1334,6 +1353,7 @@ ASCN.ASCAT <- function(data = NULL, gammaRange = c(.35,.95), nsubthread = 1, clu
1334
1353
cls <- parallel :: makeCluster(spec = nsubthread , type = cluster.type , outfile = " " )
1335
1354
doParallel :: registerDoParallel(cls )
1336
1355
gamma <- 0
1356
+ `%dopar%` <- foreach :: " %dopar%"
1337
1357
fit.val <- as.data.frame(foreach :: foreach(gamma = gammavec , .combine = " rbind" , .inorder = TRUE ) %dopar % {
1338
1358
tmsg(paste0(" gamma = " , gamma ))
1339
1359
odirg <- paste0(odir , " /gamma" , sprintf(" %.2f" , gamma ))
@@ -2015,6 +2035,8 @@ Annotate <- function(data = NULL, refGene.table = NULL, targets.table = NULL, re
2015
2035
2016
2036
oridir <- getwd()
2017
2037
2038
+ `%do%` <- foreach :: " %do%"
2039
+
2018
2040
if (! is.list(data )) stop(tmsg(" data should be a list !" ), call. = FALSE )
2019
2041
2020
2042
valid.genomes <- get.valid.genomes()
0 commit comments