annotate cummeRbund.R @ 2:ac2ebc60ef5d draft

Uploaded corrected dynamic options
author devteam
date Mon, 16 Mar 2015 15:43:02 -0400
parents 587c425b4e76
children 78fcfc04fcfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
1 ## Feature Selection ##
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
2 get_features <- function(myGenes, f="gene") {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
3 if (f == "isoforms")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
4 return(isoforms(myGenes))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
5 else if (f == "tss")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
6 return(TSS(myGenes))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
7 else if (f == "cds")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
8 return(CDS(myGenes))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
9 else
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
10 return(myGenes)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
11 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
12
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
13 ## Main Function ##
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
14
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
15 library(argparse)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
16
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
17 parser <- ArgumentParser(description='Create a plot with cummeRbund')
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
18
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
19 parser$add_argument('--type', dest='plotType', default='Density', required=TRUE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
20 parser$add_argument('--height', dest='height', type='integer', default=960, required=TRUE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
21 parser$add_argument('--width', dest='width', type='integer', default=1280, required=TRUE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
22 parser$add_argument('--outfile', dest='filename', default="plot-unknown-0.png", required=TRUE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
23 parser$add_argument('--input', dest='input_database', default="cuffData.db", required=TRUE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
24 parser$add_argument('--smooth', dest='smooth', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
25 parser$add_argument('--gene_selector', dest='gene_selector', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
26 parser$add_argument('--replicates', dest='replicates', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
27 parser$add_argument('--labcol', dest='labcol', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
28 parser$add_argument('--labrow', dest='labrow', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
29 parser$add_argument('--border', dest='border', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
30 parser$add_argument('--summary', dest='summary', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
31 parser$add_argument('--count', dest='count', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
32 parser$add_argument('--error_bars', dest='error_bars', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
33 parser$add_argument('--log10', dest='log10', action="store_true", default=FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
34 parser$add_argument('--features', dest='features', action="store", default="genes")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
35 parser$add_argument('--clustering', dest='clustering', action="store", default="both")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
36 parser$add_argument('--iter_max', dest='iter_max', action="store")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
37 parser$add_argument('--genes', dest='genes', action="append")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
38 parser$add_argument('--k', dest='k', action="store")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
39 parser$add_argument('--x', dest='x', action="store")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
40 parser$add_argument('--y', dest='y', action="store")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
41
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
42 args <- parser$parse_args()
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
43
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
44 ## Load cummeRbund library
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
45 library("cummeRbund")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
46
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
47 ## Initialize cuff object
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
48 cuff <- readCufflinks(dir = "", dbFile = args$input_database, rebuild = FALSE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
49
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
50 ## Print out info
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
51 print(cuff)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
52 sink("cuffdb_info.txt")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
53 print(cuff)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
54 print("SAMPLES:")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
55 samples(cuff)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
56 print("REPLICATES:")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
57 replicates(cuff)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
58 print("FEATURES:")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
59 print(annotation(genes(cuff)))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
60 cat(annotation(genes(cuff))[[1]],sep=",")
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
61 sink()
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
62
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
63 png(filename = args$filename, width = args$width, height = args$height, type=c('cairo-png'))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
64 tryCatch({
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
65 if (args$plotType == 'density') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
66 csDensity(genes(cuff), replicates=args$replicates, logMode=args$log10)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
67 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
68 else if (args$plotType == 'boxplot') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
69 csBoxplot(genes(cuff), replicates=args$replicates, logMode=args$log10)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
70 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
71 else if (args$plotType == 'mds') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
72 MDSplot(genes(cuff), replicates=args$replicates)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
73 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
74 else if (args$plotType == 'pca') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
75 PCAplot(genes(cuff), "PC1", "PC2", replicates=args$replicates)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
76 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
77 else if (args$plotType == 'dendrogram') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
78 csDendro(genes(cuff), replicates=args$replicates)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
79 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
80 else if (args$plotType == 'scatter') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
81 if (args$gene_selector) {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
82 myGenes <- getGenes(cuff, args$genes)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
83 csScatter(get_features(myGenes, args$features), args$x, args$y, smooth=args$smooth, logMode=args$log10)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
84 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
85 else {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
86 csScatter(genes(cuff), args$x, args$y, smooth=args$smooth, logMode=args$log10)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
87 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
88 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
89 else if (args$plotType == 'volcano') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
90 if (args$gene_selector) {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
91 myGenes <- get_features(getGenes(cuff, args$genes), args$features)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
92 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
93 else {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
94 myGenes <- genes(cuff)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
95 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
96 csVolcano(myGenes, args$x, args$y)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
97 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
98 else if (args$plotType == 'heatmap') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
99 if (args$gene_selector) {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
100 myGenes <- getGenes(cuff, args$genes)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
101 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
102 else {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
103 myGenes <- getGenes(cuff,annotation(genes(cuff))[[1]])
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
104 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
105 csHeatmap(get_features(myGenes, args$features), clustering=args$clustering, labCol=args$labcol, labRow=args$labrow, border=args$border, logMode=args$log10)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
106 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
107 else if (args$plotType == 'cluster') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
108 myGenes <- getGenes(cuff, args$genes)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
109 csCluster(get_features(myGenes, args$features), k=args$k)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
110 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
111 else if (args$plotType == 'dispersion') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
112 dispersionPlot(genes(cuff))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
113 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
114 else if (args$plotType == 'fpkmSCV') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
115 fpkmSCVPlot(genes(cuff))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
116 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
117 else if (args$plotType == 'scatterMatrix') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
118 csScatterMatrix(genes(cuff))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
119 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
120 else if (args$plotType == 'expressionplot') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
121 myGenes <- getGenes(cuff, args$genes)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
122 expressionPlot(get_features(myGenes, args$features), drawSummary=args$summary, showErrorbars=args$error_bars, replicates=args$replicates)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
123 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
124 else if (args$plotType == 'expressionbarplot') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
125 myGeneId <- args$genes
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
126 myGenes <- getGenes(cuff, myGeneId)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
127 expressionBarplot(get_features(myGenes, args$features), showErrorbars=args$error_bars, replicates=args$replicates)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
128 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
129 else if (args$plotType == 'mds') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
130 MDSplot(genes(cuff),replicates=args$replicates)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
131 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
132 else if (args$plotType == 'pca') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
133 PCAplot(genes(cuff),"PC1","PC2", replicates=args$replicates)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
134 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
135 else if (args$plotType == 'maplot') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
136 MAplot(genes(cuff), args$x, args$y, useCount=args$count)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
137 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
138 else if (args$plotType == 'genetrack') {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
139 myGene <- getGene(cuff, args$genes)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
140 plotTracks(makeGeneRegionTrack(myGene))
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
141 }
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
142 },error = function(e) {
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
143 write(paste("Failed:", e, sep=" "), stderr())
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
144 q("no", 1, TRUE)
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
145 })
587c425b4e76 Initial commit with version 1.0.0 of the cummeRbund wrapper.
devteam
parents:
diff changeset
146 devname = dev.off()