11library(rhdf5 )
2+
23# Load Python and R functions for basic Wilcoxon Tests, DESeq2, and CocoA-Diff
34# and causarray, cinemaot
45require(reticulate )
@@ -16,8 +17,9 @@ p <- 2000
1617c = 0.1
1718alpha = 0.1
1819
19- ind <- ' _d_0_r_4_noise_1.0 '
20+ ind <- ' _d_2_r_1_noise_0.5 '
2021num_r <- 1
22+ noise <- 1 .
2123
2224args = commandArgs(trailingOnly = TRUE )
2325if (length(args )== 0 ){
@@ -35,13 +37,12 @@ if((ind != '') && grepl( 'r', ind, fixed = TRUE)){
3537
3638if ((ind != ' ' ) && grepl( ' noise' , ind , fixed = TRUE )){
3739 library(stringr )
38- noise <- as.double(str_extract(ind , " (?<=noise_)[0-9]* " ))
40+ noise <- as.double(str_extract(ind , " (?<=noise_)[0-9]+( \\ .[0-9]+)? " ))
3941}else {
40- noise <- 1 .
42+ noise <- 1
4143}
4244
43-
44- for (n in c(100 ,500 ,1000 ,5000 )){
45+ for (n in c(100 , 500 , 1000 , 5000 )){
4546
4647 path_result <- sprintf(paste0(path_base ,' results/simu_%d%s/' ), n , ind )
4748 dir.create(path_result , recursive = TRUE , showWarnings = FALSE )
@@ -75,7 +76,7 @@ for(n in c(100,500,1000,5000)){
7576 possibleError <- tryCatch(
7677 {
7778 # Wilcoxon Tests ----
78- res.wilc <- run_wilcoxon(Y , metadata = scaleW , raw = T )
79+ res.wilc <- run_wilcoxon(Y , metadata = scaleW )
7980
8081 # # DESeq ----
8182 res.DESeq <- run_DESeq(Y , metadata = scaleW , return_ds = TRUE )
@@ -87,7 +88,6 @@ for(n in c(100,500,1000,5000)){
8788 cocoa <- run_cocoa(sc = Y_sc , indvs = metadata [,2 ], metadata = scaleW , cocoAWriteName = sprintf(' %stmp_cocoa/tmp_%d' , path_result , seed ))
8889 res.cocoa <- cocoa [[1 ]]
8990 cf.cocoa <- t(cocoa [[2 ]]$ cf.ln.mu )
90-
9191
9292 # CINEMA-OT ---- run_cinemaot returns list(df, CF, TE)
9393 res.cinemaot <- run_cinemaot(Y , A , raw = TRUE )
@@ -100,8 +100,6 @@ for(n in c(100,500,1000,5000)){
100100 W.cinemaotw <- res.cinemaotw [[2 ]]$ W
101101 res.cinemaotw <- res.cinemaotw [[1 ]]
102102
103-
104-
105103 # Save confounder estimation results
106104 write.csv(cf.cocoa , sprintf(' %scocoa_cf_%d.csv' , path_result , seed ))
107105 write.csv(cf.cinemaot , sprintf(' %scinemaot_cf_%d.csv' , path_result , seed ))
@@ -116,7 +114,15 @@ for(n in c(100,500,1000,5000)){
116114 write.csv(res.cinemaot , sprintf(' %scinemaot_%d.csv' , path_result , seed ))
117115 write.csv(res.cinemaotw , sprintf(' %scinemaotw_%d.csv' , path_result , seed ))
118116
117+ res.mixscape <- run_mixscape(Y , A , raw = TRUE )
118+ cf.mixscape <- res.mixscape [[2 ]]$ Y_hat_0
119+ W.mixscape <- res.mixscape [[2 ]]$ W
120+ res.mixscape <- res.mixscape [[1 ]]
119121
122+ write.csv(cf.mixscape , sprintf(' %smixscape_cf_%d.csv' , path_result , seed ))
123+ write.csv(W.mixscape , sprintf(' %smixscape_W_%d.csv' , path_result , seed ))
124+ write.csv(res.mixscape , sprintf(' %smixscape_%d.csv' , path_result , seed ))
125+
120126 for (r_hat in c(2 ,4 ,6 )){
121127 # RUV
122128 ruv <- run_ruv(Y , metadata = scaleW , r_hat )
@@ -136,39 +142,40 @@ for(n in c(100,500,1000,5000)){
136142 write.csv(cf.ruv3nb , sprintf(' %sruv3nb_r_%d_cf_%d.csv' , path_result , r_hat , seed ))
137143 write.csv(W.ruv3nb , sprintf(' %sruv3nb_r_%d_W_%d.csv' , path_result , r_hat , seed ))
138144 write.csv(res.ruv3nb , sprintf(' %sruv3nb_r_%d_%d.csv' , path_result , r_hat , seed ))
139- }
145+ }
140146
141- # causarray
147+ # # causarray
142148 # res.causarray.r <- estimate_r_causarray(Y, scaleW[,-ncol(scaleW)], A, 5)
143149 # r_hat <- res.causarray.r[which.min(res.causarray.r$JIC), 'r']
144150 # cat('r_hat:', r_hat, '\n')
145151 # r_hat <- num_r
146152 # res.causarray <- run_causarray(Y, scaleW[,-ncol(scaleW)], A,
147- # alpha=alpha, c=c, r=r_hat, #B=2000,
148- # # Y_hat_0=res[[1]], Y_hat_1=res[[2]],
149- # # ps_model='logistic', penalty=NULL,
150- # # max_depth=as.integer(5), func='LFC'
153+ # alpha=alpha, c=c, r=r_hat
151154 # )[[1]]
152155
153156 res.causarray <- run_causarray(Y , scaleW [,- ncol(scaleW )], A ,
154- fdx = T , r = r_hat , glm_alpha = .5 , shrinkage = T , usevar = ' unequal' )
155- cf.causarray <- log1p(res.causarray [[2 ]]$ Y_hat_0 )
157+ fdx = T , r = r_hat , glm_alpha = 0.5 , shrinkage = T , usevar = ' unequal'
158+ )
159+
160+ cf.causarray <- log1p(res.causarray [[2 ]]$ Y_hat [,,1 ,1 ])
156161 W.causarray <- res.causarray [[2 ]]$ W
157162 res.causarray <- res.causarray [[1 ]]
158-
163+ cat(sum(res.causarray $ padj < 0.1 ))
164+
159165 # Save confounder estimation results
160166 write.csv(cf.ruv , sprintf(' %sruv_r_%d_cf_%d.csv' , path_result , r_hat , seed ))
161167 write.csv(W.ruv , sprintf(' %sruv_r_%d_W_%d.csv' , path_result , r_hat , seed ))
162-
168+ write.csv(res.ruv , sprintf(' %sruv_r_%d_%d.csv' , path_result , r_hat , seed ))
169+
163170 write.csv(cf.causarray , sprintf(' %scausarray_r_%d_cf_%d.csv' , path_result , r_hat , seed ))
164171 write.csv(W.causarray , sprintf(' %scausarray_r_%d_W_%d.csv' , path_result , r_hat , seed ))
165-
166- write.csv(res.ruv , sprintf(' %sruv_r_%d_%d.csv' , path_result , r_hat , seed ))
167172 write.csv(res.causarray , sprintf(' %scausarray_r_%d_%d.csv' , path_result , r_hat , seed ))
168173 }
169174
170175 },
171176 error = function (e ) e
172177 )
173178 }
174- }
179+ }
180+
181+ print(' Done' )
0 commit comments