Skip to content

Commit 0ad6383

Browse files
author
Ubuntu
committed
added pre batch removal tpms
1 parent 75cd840 commit 0ad6383

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

modules/preprocess/preprocess_cohort.snakefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def preprocess_cohort_targets(wildcards):
2626
ls.append("analysis/batchremoval/%s_%s_tpm.genesymbol.csv" % (design,covariates))
2727
ls.append("analysis/batchremoval/%s_%s_tpm.genesymbol.batchremoved.csv" % (design,covariates))
2828

29-
ls.append("analysis/batchremoval/pca_plot_before.png" )
30-
ls.append("analysis/batchremoval/pca_plot_after.png" )
29+
ls.append("analysis/batchremoval/%s_%s_pca_plot_before.png" % (design,covariates))
30+
ls.append("analysis/batchremoval/%s_%s_pca_plot_after.png" % (design,covariates))
3131
return ls
3232

3333
rule preprocess_cohort_all:
@@ -154,22 +154,23 @@ rule batch_removal:
154154

155155
rule pca_sample_clustering:
156156
input:
157-
before_batch = "analysis/salmon/{design}_{covariates}_tpm.genesymbol.csv",
158-
after_batch = "analysis/batchremoval/{design}_{covariates}_tpm.genesymbol.batchremoved.csv"
157+
before_batch = "analysis/batchremoval/{design}_{covariates}_tpm.genesymbol.batchremoved.csv",
158+
after_batch = "analysis/batchremoval/{design}_{covariates}_tpm.genesymbol.csv"
159159
output:
160-
"analysis/batchremoval/{design}_{covariates}_pca_plot_before.png",
161-
"analysis/batchremoval/{design}_{covariates}_pca_plot_after.png",
160+
before_pca = "analysis/batchremoval/{design}_{covariates}_pca_plot_before.png",
161+
after_pca = "analysis/batchremoval/{design}_{covariates}_pca_plot_after.png",
162162
message:
163163
"Running PCA for sample clustering"
164164
benchmark:
165165
"benchmarks/batchremoval/{design}_{covariates}_pca.benchmark"
166166
params:
167167
meta_info = config["metasheet"],
168-
out_path = "analysis/batchremoval/",
169168
path="set +eu;source activate %s" % config['stat_root'],
170169
covariates = config["batch"],
170+
design = config["design"]
171171
conda: "../envs/stat_perl_r.yml"
172172
shell:
173-
"{params.path}; Rscript src/preprocess/pca.R -b {input.before_batch} -a {input.after_batch} -m {params.meta_info} -o {params.out_path} -c {params.covariates}"
173+
"{params.path}; Rscript src/preprocess/pca.R -b {input.before_batch} -a {input.after_batch} -m {params.meta_info} -c {params.covariates} \
174+
-g {params.design} -i {output.before_pca} -j {output.after_pca}"
174175

175176

src/preprocess/pca.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@ option_list = list(
1212
help="expression matrix after batch removal", metavar="character"),
1313
make_option(c("-m", "--metainfo"), type="character", default=NULL,
1414
help="meta file", metavar="character"),
15-
make_option(c("-o", "--outdir"), type="character", default=NULL,
16-
help="output directory", metavar="character"),
15+
make_option(c("-i", "--out_before"), type="character", default=NULL,
16+
help="PCA plot before batch removal", metavar="character"),
17+
make_option(c("-j", "--out_after"), type="character", default=NULL,
18+
help="PCA plot after batch removal", metavar="character"),
1719
make_option(c("-c", "--column"), type="character", default=NULL,
18-
help="batch column", metavar="character")
20+
help="batch column", metavar="character"),
21+
make_option(c("-g", "--group"), type="character", default=NULL,
22+
help="group column", metavar="character")
1923
);
2024

2125
opt_parser = OptionParser(option_list=option_list);
@@ -24,7 +28,7 @@ opt = parse_args(opt_parser);
2428
expr_before <- read.table(opt$before,sep = ",", row.names = 1, header = TRUE, check.names = FALSE)
2529
expr_after <- read.table(opt$after,sep = ",", row.names = 1, header = TRUE, check.names = FALSE)
2630
annot <- read.table(opt$metainfo,sep = ",",header = TRUE, row.names = 1)
27-
pca_out_dir <- opt$outdir
31+
2832

2933
if (opt$column == "False") {
3034
annot$Batch <- 1
@@ -54,12 +58,12 @@ pca_plot <- function(exprTable, annot,title, Batch) {
5458

5559

5660
###print pca plot
57-
png(file = paste(pca_out_dir,"pca_plot_before.png",sep = ""), res = 300, height = 1200, width = 1500)
61+
png(file = opt$out_before, res = 300, height = 1200, width = 1500)
5862
pca_plot(exprTable = expr_before, annot = annot, title = "PCA plot Before Batch Removal",Batch=Batch)
5963
dev.off()
6064

61-
png(file = paste(pca_out_dir,"pca_plot_after.png",sep = ""), res = 300, height = 1200, width = 1500)
65+
png(file = opt$out_after, res = 300, height = 1200, width = 1500)
6266
pca_plot(exprTable = expr_after, annot = annot, title = "PCA plot After Batch Removal",Batch = Batch)
6367
dev.off()
6468

65-
###
69+
###

0 commit comments

Comments
 (0)