comparison cummeRbund.R @ 2:4bbfacecedd3 draft default tip

"planemo upload for repository https://github.com/galaxyproject/tools-devteam/tree/master/tools/cummerbund commit f929353ffb0623f2218d7dec459c7da62f3b0d24"
author devteam
date Mon, 06 Jul 2020 18:11:20 +0000
parents aefbcaf15a94
children
comparison
equal deleted inserted replaced
1:aefbcaf15a94 2:4bbfacecedd3
1 ## Feature Selection ## 1 ## Feature Selection ##
2 options(echo=TRUE) 2 options(echo = TRUE)
3 get_features <- function(myGenes, f="gene") { 3 get_features <- function(my_genes, f = "gene") {
4 if (f == "isoforms") 4 if (f == "isoforms")
5 return(isoforms(myGenes)) 5 return(isoforms(my_genes))
6 else if (f == "tss") 6 else if (f == "tss")
7 return(TSS(myGenes)) 7 return(TSS(my_genes))
8 else if (f == "cds") 8 else if (f == "cds")
9 return(CDS(myGenes)) 9 return(CDS(my_genes))
10 else 10 else
11 return(myGenes) 11 return(my_genes)
12 } 12 }
13 13
14 ## Main Function ## 14 ## Main Function ##
15 15
16 library(argparse) 16 library(argparse)
17 17
18 parser <- ArgumentParser(description='Create a plot with cummeRbund') 18 parser <- ArgumentParser(description = "Create a plot with cummeRbund")
19 19
20 parser$add_argument('--type', dest='plotType', default='Density', required=TRUE) 20 parser$add_argument("--type", dest = "plotType", default = "Density", required = TRUE)
21 parser$add_argument('--height', dest='height', type='integer', default=960, required=TRUE) 21 parser$add_argument("--height", dest = "height", type = "integer", default = 960, required = TRUE)
22 parser$add_argument('--width', dest='width', type='integer', default=1280, required=TRUE) 22 parser$add_argument("--width", dest = "width", type = "integer", default = 1280, required = TRUE)
23 parser$add_argument('--outfile', dest='filename', default="plot-unknown-0.png", required=TRUE) 23 parser$add_argument("--outfile", dest = "filename", default = "plot-unknown-0.png", required = TRUE)
24 parser$add_argument('--input', dest='input_database', default="cuffData.db", required=TRUE) 24 parser$add_argument("--input", dest = "input_database", default = "cuffData.db", required = TRUE)
25 parser$add_argument('--smooth', dest='smooth', action="store_true", default=FALSE) 25 parser$add_argument("--smooth", dest = "smooth", action = "store_true", default = FALSE)
26 parser$add_argument('--gene_selector', dest='gene_selector', action="store_true", default=FALSE) 26 parser$add_argument("--gene_selector", dest = "gene_selector", action = "store_true", default = FALSE)
27 parser$add_argument('--replicates', dest='replicates', action="store_true", default=FALSE) 27 parser$add_argument("--replicates", dest = "replicates", action = "store_true", default = FALSE)
28 parser$add_argument('--labcol', dest='labcol', action="store_true", default=FALSE) 28 parser$add_argument("--labcol", dest = "labcol", action = "store_true", default = FALSE)
29 parser$add_argument('--labrow', dest='labrow', action="store_true", default=FALSE) 29 parser$add_argument("--labrow", dest = "labrow", action = "store_true", default = FALSE)
30 parser$add_argument('--border', dest='border', action="store_true", default=FALSE) 30 parser$add_argument("--border", dest = "border", action = "store_true", default = FALSE)
31 parser$add_argument('--summary', dest='summary', action="store_true", default=FALSE) 31 parser$add_argument("--summary", dest = "summary", action = "store_true", default = FALSE)
32 parser$add_argument('--count', dest='count', action="store_true", default=FALSE) 32 parser$add_argument("--count", dest = "count", action = "store_true", default = FALSE)
33 parser$add_argument('--error_bars', dest='error_bars', action="store_true", default=FALSE) 33 parser$add_argument("--error_bars", dest = "error_bars", action = "store_true", default = FALSE)
34 parser$add_argument('--log10', dest='log10', action="store_true", default=FALSE) 34 parser$add_argument("--log10", dest = "log10", action = "store_true", default = FALSE)
35 parser$add_argument('--features', dest='features', action="store", default="genes") 35 parser$add_argument("--features", dest = "features", action = "store", default = "genes")
36 parser$add_argument('--clustering', dest='clustering', action="store", default="both") 36 parser$add_argument("--clustering", dest = "clustering", action = "store", default = "both")
37 parser$add_argument('--iter_max', dest='iter_max', action="store") 37 parser$add_argument("--iter_max", dest = "iter_max", action = "store")
38 parser$add_argument('--genes', dest='genes', action="append") 38 parser$add_argument("--genes", dest = "genes", action = "append")
39 parser$add_argument('--k', dest='k', action="store") 39 parser$add_argument("--k", dest = "k", action = "store")
40 parser$add_argument('--x', dest='x', action="store") 40 parser$add_argument("--x", dest = "x", action = "store")
41 parser$add_argument('--y', dest='y', action="store") 41 parser$add_argument("--y", dest = "y", action = "store")
42 42
43 args <- parser$parse_args() 43 args <- parser$parse_args()
44 44
45 ## Load cummeRbund library 45 ## Load cummeRbund library
46 library("cummeRbund") 46 library("cummeRbund")
56 samples(cuff) 56 samples(cuff)
57 print("REPLICATES:") 57 print("REPLICATES:")
58 replicates(cuff) 58 replicates(cuff)
59 print("FEATURES:") 59 print("FEATURES:")
60 print(annotation(genes(cuff))) 60 print(annotation(genes(cuff)))
61 cat(annotation(genes(cuff))[[1]],sep=",") 61 cat(annotation(genes(cuff))[[1]], sep = ",")
62 sink() 62 sink()
63 63
64 png(filename = args$filename, width = args$width, height = args$height, type=c('cairo-png')) 64 png(filename = args$filename, width = args$width, height = args$height)
65 tryCatch({ 65 tryCatch({
66 if (args$plotType == 'density') { 66 if (args$plotType == "density") {
67 csDensity(genes(cuff), replicates=args$replicates, logMode=args$log10) 67 csDensity(genes(cuff), replicates = args$replicates, logMode = args$log10)
68 } else if (args$plotType == "boxplot") {
69 csBoxplot(genes(cuff), replicates = args$replicates, logMode = args$log10)
70 } else if (args$plotType == "mds") {
71 MDSplot(genes(cuff), replicates = args$replicates)
72 } else if (args$plotType == "pca") {
73 PCAplot(genes(cuff), "PC1", "PC2", replicates = args$replicates)
74 } else if (args$plotType == "dendrogram") {
75 csDendro(genes(cuff), replicates = args$replicates)
76 } else if (args$plotType == "scatter") {
77 if (args$gene_selector) {
78 my_genes <- get_features(getGenes(cuff, args$genes), args$features)
79 } else {
80 my_genes <- genes(cuff)
81 }
82 csScatter(my_genes, args$x, args$y, smooth = args$smooth, logMode = args$log10)
83 } else if (args$plotType == "volcano") {
84 if (args$gene_selector) {
85 my_genes <- get_features(getGenes(cuff, args$genes), args$features)
86 } else {
87 my_genes <- genes(cuff)
88 }
89 csVolcano(my_genes, args$x, args$y)
90 } else if (args$plotType == "heatmap") {
91 if (args$gene_selector) {
92 my_genes <- getGenes(cuff, args$genes)
93 } else {
94 my_genes <- getGenes(cuff, annotation(genes(cuff))[[1]])
95 }
96 csHeatmap(get_features(my_genes, args$features), clustering = args$clustering, labCol = args$labcol, labRow = args$labrow, border = args$border, logMode = args$log10)
97 } else if (args$plotType == "cluster") {
98 my_genes <- getGenes(cuff, args$genes)
99 csCluster(get_features(my_genes, args$features), k = args$k)
100 } else if (args$plotType == "dispersion") {
101 dispersionPlot(genes(cuff))
102 } else if (args$plotType == "fpkmSCV") {
103 fpkmSCVPlot(genes(cuff))
104 } else if (args$plotType == "scatterMatrix") {
105 csScatterMatrix(genes(cuff))
106 } else if (args$plotType == "expressionplot") {
107 my_genes <- getGenes(cuff, args$genes)
108 expressionPlot(get_features(my_genes, args$features), drawSummary = args$summary, showErrorbars = args$error_bars, replicates = args$replicates)
109 } else if (args$plotType == "expressionbarplot") {
110 my_gene_id <- args$genes
111 my_genes <- getGenes(cuff, my_gene_id)
112 expressionBarplot(get_features(my_genes, args$features), showErrorbars = args$error_bars, replicates = args$replicates)
113 } else if (args$plotType == "mds") {
114 MDSplot(genes(cuff), replicates = args$replicates)
115 } else if (args$plotType == "pca") {
116 PCAplot(genes(cuff), "PC1", "PC2", replicates = args$replicates)
117 } else if (args$plotType == "maplot") {
118 MAplot(genes(cuff), args$x, args$y, useCount = args$count)
119 } else if (args$plotType == "genetrack") {
120 my_gene <- getGene(cuff, args$genes)
121 plotTracks(makeGeneRegionTrack(my_gene))
68 } 122 }
69 else if (args$plotType == 'boxplot') { 123 }, error = function(e) {
70 csBoxplot(genes(cuff), replicates=args$replicates, logMode=args$log10) 124 write(paste("Failed:", e, sep = " "), stderr())
71 }
72 else if (args$plotType == 'mds') {
73 MDSplot(genes(cuff), replicates=args$replicates)
74 }
75 else if (args$plotType == 'pca') {
76 PCAplot(genes(cuff), "PC1", "PC2", replicates=args$replicates)
77 }
78 else if (args$plotType == 'dendrogram') {
79 csDendro(genes(cuff), replicates=args$replicates)
80 }
81 else if (args$plotType == 'scatter') {
82 if (args$gene_selector) {
83 myGenes <- getGenes(cuff, args$genes)
84 csScatter(get_features(myGenes, args$features), args$x, args$y, smooth=args$smooth, logMode=args$log10)
85 }
86 else {
87 csScatter(genes(cuff), args$x, args$y, smooth=args$smooth, logMode=args$log10)
88 }
89 }
90 else if (args$plotType == 'volcano') {
91 if (args$gene_selector) {
92 myGenes <- get_features(getGenes(cuff, args$genes), args$features)
93 }
94 else {
95 myGenes <- genes(cuff)
96 }
97 csVolcano(myGenes, args$x, args$y)
98 }
99 else if (args$plotType == 'heatmap') {
100 if (args$gene_selector) {
101 myGenes <- getGenes(cuff, args$genes)
102 }
103 else {
104 myGenes <- getGenes(cuff,annotation(genes(cuff))[[1]])
105 }
106 csHeatmap(get_features(myGenes, args$features), clustering=args$clustering, labCol=args$labcol, labRow=args$labrow, border=args$border, logMode=args$log10)
107 }
108 else if (args$plotType == 'cluster') {
109 myGenes <- getGenes(cuff, args$genes)
110 csCluster(get_features(myGenes, args$features), k=args$k)
111 }
112 else if (args$plotType == 'dispersion') {
113 dispersionPlot(genes(cuff))
114 }
115 else if (args$plotType == 'fpkmSCV') {
116 fpkmSCVPlot(genes(cuff))
117 }
118 else if (args$plotType == 'scatterMatrix') {
119 csScatterMatrix(genes(cuff))
120 }
121 else if (args$plotType == 'expressionplot') {
122 myGenes <- getGenes(cuff, args$genes)
123 expressionPlot(get_features(myGenes, args$features), drawSummary=args$summary, showErrorbars=args$error_bars, replicates=args$replicates)
124 }
125 else if (args$plotType == 'expressionbarplot') {
126 myGeneId <- args$genes
127 myGenes <- getGenes(cuff, myGeneId)
128 expressionBarplot(get_features(myGenes, args$features), showErrorbars=args$error_bars, replicates=args$replicates)
129 }
130 else if (args$plotType == 'mds') {
131 MDSplot(genes(cuff),replicates=args$replicates)
132 }
133 else if (args$plotType == 'pca') {
134 PCAplot(genes(cuff),"PC1","PC2", replicates=args$replicates)
135 }
136 else if (args$plotType == 'maplot') {
137 MAplot(genes(cuff), args$x, args$y, useCount=args$count)
138 }
139 else if (args$plotType == 'genetrack') {
140 myGene <- getGene(cuff, args$genes)
141 plotTracks(makeGeneRegionTrack(myGene))
142 }
143 },error = function(e) {
144 write(paste("Failed:", e, sep=" "), stderr())
145 q("no", 1, TRUE) 125 q("no", 1, TRUE)
146 }) 126 })
147 devname = dev.off() 127 devname <- dev.off()
128 print("cummeRbund finished")