-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_facets.R
61 lines (49 loc) · 2.06 KB
/
run_facets.R
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
#load the libraries
library(facets)
library(data.table)
#argument should be the snppileup produced in the previous step and the desired output folder
set.seed(1234)
#critical value to call a change
CVAL = 150
#number of hetrozygous snps required to call minor copy number
NHET = snakemake@params[[2]]
#the gzfile produced by snppileup
inputFilename = snakemake@input[[1]]
#the place where things should be written
outputFilename = snakemake@output[[1]]
#the directory where you want to write things
outputDir = snakemake@params[[1]]
#make sure the directory exists already, this will throw a warning if the output folder exists already
dir.create(outputDir)
print(inputFilename)
print(paste0("Reading file: ", inputFilename))
#read the Snp matrix, feed a file path of the snp pileup
rcmat = readSnpMatrix(inputFilename)
#perform the preprocessing
print(paste("preprocessing file",inputFilename))
xx = preProcSample(rcmat)
#process the sample
print(paste("Processing file",inputFilename))
oo = procSample(xx,cval=CVAL)
print(oo$flags)
#we're using the emcncf2 function to allow the data to provide subclonal copy number calls as well
print(paste("Running fit",inputFilename))
fit = emcncf(oo, min.nhet = NHET)
#the data is store in cnfc
fit_table = as.data.table(fit$cncf)
fit_table[,"Purity" := fit$purity]
fit_table[,"Ploidy" := fit$ploidy]
fwrite(fit_table, outputFilename)
print(paste(inputFilename, "written"))
print("Drawing diagnostic plots")
png(paste0(outputFilename,CVAL, NHET, "_fitted.png"), width = 3.25, height = 3.25, units = "in", res=1200, pointsize = 4)
par(mar = c(5, 5, 2, 2), xaxs = "i", yaxs = "i",cex.axis = 2,cex.lab = 2)
print("Plotting Sample")
plotSample(x=oo,emfit=fit)
while(!is.null(dev.list())){dev.off()}
print("Ploting Spider")
png(paste0(outputFilename, CVAL, NHET, "_diagnostic.png"), width = 3.25, height = 3.25, units = "in", res=1200, pointsize = 4)
par(mar = c(5, 5, 2, 2), xaxs = "i", yaxs = "i",cex.axis = 2,cex.lab = 2)
logRlogORspider(oo$out,oo$dipLogR)
while(!is.null(dev.list())){dev.off()}
print(paste("All done with sample:",inputFilename))