annotate GSVA.R @ 1:b83133fd91d5 draft default tip

Uploaded
author mora-lab
date Thu, 20 May 2021 08:30:52 +0000
parents f94ef9b31552
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
1 ###############################################################################
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
2 # title: Gene set variation analysis
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
3 # author: Xiaowei
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
4 # time: Mar.31 2021
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
5 ###############################################################################
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
6 #=================================================================
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
7 #how to pass parameters
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
8 #=================================================================
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
9 spec <- matrix(c("expr", 'E', 1, 'character', 'Gene expression data which is an CSV file of expression values where rows correspond to genes and columns correspond to samples.',
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
10 "geneSet", 'G', 1, 'character', 'Gene set',
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
11 'gene_Identifier_class','C', 1, 'character', 'Gene Identifier class of GeneSet',
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
12 'method', "M", 1,'character', 'One of gsva, ssgsea, zscore, plage',
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
13 'img_file', 'I', 1,'character', 'img_file',
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
14 'img_type', 'T', 1,'character', 'PDF, PNG, JPEG',
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
15 'img_width', 'W', 1, 'integer', 'the img file width',
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
16 'img_height', 'H', 1, 'integer', 'the img file height',
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
17 'GSVA_result', 'R', 1, 'character', 'Result of GSVA, an CSV file.'
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
18
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
19 ),
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
20 byrow = TRUE, ncol = 5)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
21
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
22
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
23 if (!requireNamespace("getopt", quietly = TRUE))
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
24 install.packages("getopt")
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
25
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
26 opt <- getopt::getopt(spec)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
27
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
28 #----------------
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
29 #整理参数
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
30 #----------------
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
31
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
32 if(is.null(opt$gene_Identifier_class)){gene_Identifier_class = 'Symbol'}else{gene_Identifier_class = opt$gene_Identifier_class }
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
33 if(is.null(opt$method)){opt$method = 'gsva'}
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
34 if(is.null(opt$img_type)){opt$img_type = 'PNG'}
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
35 if(is.null(opt$img_width)){img_width = 900}else{img_width = opt$img_width}
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
36 if(is.null(opt$img_height)){img_height = 900}else{img_height = opt$img_height}
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
37
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
38 #================================================================
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
39 #run codes
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
40 #================================================================
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
41 gsva_input_data <- read.csv(opt$expr, row.names = 1)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
42
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
43 # if (gene_Identifier_class == 'Symbol'){
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
44 # geneset <- GSEABase::getGmt(opt$geneSet,
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
45 # geneIdType = GSEABase::SymbolIdentifier())
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
46 # }else{
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
47 # geneset <- GSEABase::getGmt(opt$geneSet,
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
48 # geneIdType = GSEABase::EntrezIdentifier())
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
49 # }
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
50
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
51 load(opt$geneSet)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
52
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
53 result <- GSVA::gsva(as.matrix(gsva_input_data), geneSet, mx.diff=FALSE,
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
54 verbose=FALSE, parallel.sz=2, method = opt$method)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
55 #================================================================
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
56 #output
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
57 #================================================================
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
58
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
59 write.csv(result, file = opt$GSVA_result)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
60
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
61 if (opt$img_type == 'PNG'){
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
62 png(filename = opt$img_file, width = img_width, height = img_height)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
63 }else if(opt$img_type == 'JPG'){
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
64 jpeg(filename = opt$img_file, width = img_width, height = img_height)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
65 }else{
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
66 pdf(file = opt$img_file, width = img_width, height = img_height)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
67 }
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
68
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
69 pheatmap::pheatmap(result, scale = "row", main = "heatmap", show_colnames=T)
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
70 dev.off()
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
71
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
72
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
73
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
74
f94ef9b31552 Uploaded
mora-lab
parents:
diff changeset
75