-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_bias.R
86 lines (80 loc) · 4.59 KB
/
draw_bias.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
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
required.pack = c("getopt","optparse")
for(p in required.pack){
sig=suppressMessages(require(p,character.only = TRUE,quietly = T))
if(!sig){stop(paste("package",p,"needed!"))}
}
opt.p=OptionParser(description="Draw bias plot from matrix and average signal file. Output as 'pptx' or 'pdf'")
opt.p=add_option(opt.p,c("--signal","-s"),type="character",
help="Average signal file (.txt) generated by 'cal_bias.R' or 'normalize_bias.R'. (Required)
\t\tFiles can be joined by ','.")
opt.p=add_option(opt.p,c("--output","-o"),type="character",default="my_profile.pptx",
help="Output plot file. It can be 'pptx' or 'pdf' based on file suffix. (Optional, default='my_profile.pptx')")
opt.p=add_option(opt.p,c("--page","-p"),type="character",
help="Page label for samples. Samples with same page label will be plotted in one page. (Optional)
\t\tPage label should be joined by ','. Length of page label should be same as signal files.
\t\tIf not provided, each sample will be plotted in a page.")
opt.p=add_option(opt.p,c("--group","-g"),type="character",
help="Group label for samples. Sample with same group label will be plotted in average. (Optional)
\t\tGroup label should be joined by ','. Length of group label should be same as signal files.
\t\tIf not provide, each sample will be plotted.")
opt.p=add_option(opt.p,c("--interval"),type="logical", default=F,
help="When group label is specified, this flag is used to decide whether to plot the confidence interval for each group. (Optional,default=F)")
opt.p=add_option(opt.p,c("--legendNcol"),type="numeric",default=1,
help="Number of columns for legend showing. (Optional, default=1)")
opt.p=add_option(opt.p,c("--xlab"),type="character",default="replication origin",
help="X-axis labels. (Optional)")
opt.p=add_option(opt.p,c("--ylab"),type="character",default="Bias",
help="Y-axis labels. (Optional)")
opt.p=add_option(opt.p,c("--width"),type="numeric",default=5,
help="Width for the plot. (Optional, default=5)")
opt.p=add_option(opt.p,c("--height"),type="numeric",default=4,
help="Height for the plot. (Optional, default=4)")
opt.p=add_option(opt.p,c("--ymin"),type="numeric",default=NA,
help="Y-axis minimum value. (Optional, default=NA)")
opt.p=add_option(opt.p,c("--ymax"),type="numeric",default=NA,
help="Y-axis maximum value. (Optional, default=NA)")
opt.p=add_option(opt.p,c("--ybreaks"),type="numeric",default=NA,
help="Y-axis breaks value. (Optional, default=NA)")
opt.p=add_option(opt.p,c("--xmin"),type="numeric",default=NA,
help="X-axis minimum value. (Optional, default=NA)")
opt.p=add_option(opt.p,c("--xmax"),type="numeric",default=NA,
help="X-axis maximum value. (Optional, default=NA)")
opt.p=add_option(opt.p,c("--xbreaks"),type="numeric",default=NA,
help="X-axis breaks value. (Optional, default=NA)")
opt=parse_args(opt.p)
if(is.null(opt$signal)){print_help(opt.p);stop()}
print(opt)
where=function(){
spath <-parent.frame(2)$ofile
if (is.null(spath)) {
args <- commandArgs()
filearg <- args[grep("^--file=", args)]
fname <- strsplit(filearg, "=")[[1]][2]
} else {
fname <- spath
}
dirname(normalizePath(fname))
}
source(file.path(where(),"source/draw_bias_function.R"))
##initialize value
sig.file=unlist(strsplit(opt$signal,","));sig.file=trimws(sig.file)
graph.file=opt$output
if(is.null(opt$page)){page=NULL}else{page=unlist(strsplit(opt$page,","))}
if(is.null(opt$group)){group=NULL}else{group=unlist(strsplit(opt$group,","))}
cat("Draw bias in smooth line...\n")
sig.file=sub("\\..*$","\\.txt",sig.file)
draw_profiles(sig.file=sig.file, graph.file=graph.file,
sig.class=page,
group=group,
interval = opt$interval,
legend.ncol = opt$legendNcol,
xlab= opt$xlab, ylab= opt$ylab,
width=opt$width, height=opt$height,
yMin=opt$ymin,yMax=opt$ymax,y.breaks=opt$ybreaks,
xMin=opt$xmin,xMax=opt$xmax,x.breaks=opt$xbreaks)
cat("Draw heatmap...\n")
mat.file=sub("\\.txt$","\\.mat",sig.file)
heatmap.file=sub("\\..+$","_heatmap.pdf",graph.file)
draw_heatmap(mat.file=mat.file,graph.file= heatmap.file,
zMin=-1, zMax=1,smooth=NA,fill=NA, my.color=c("blue","white","red"), ncolor=100,
sort=FALSE,show_rownum=100,show_colnum=20,width=6,height=8,cluster_rows=F,cluster_cols=F)