annotate goprofiles.R @ 3:ed226f0e5625 draft

planemo upload commit 08f1831e097df5d74bf60ff5955e7e9c8e524cc8-dirty
author proteore
date Wed, 14 Mar 2018 12:51:53 -0400
parents 58a8ddd58dde
children 715002a394ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
1 # Load necessary libraries
2
58a8ddd58dde planemo upload commit f338a1cf9a782938c228f9bd0ea19ef22eec35d8-dirty
proteore
parents: 1
diff changeset
2 library(org.Hs.eg.db)
58a8ddd58dde planemo upload commit f338a1cf9a782938c228f9bd0ea19ef22eec35d8-dirty
proteore
parents: 1
diff changeset
3 library(goProfiles)
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
4
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
5 # Read file and return file content as data.frame?
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
6 readfile = function(filename, header) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
7 if (header == "true") {
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
8 # Read only the first line of the files as data (without headers):
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
9 headers <- read.table(filename, nrows = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE)
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
10 #Read the data of the files (skipping the first row):
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
11 file <- read.table(filename, skip = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE)
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
12 # Remove empty rows
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
13 file <- file[!apply(is.na(file) | file == "", 1, all),]
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
14 #And assign the headers of step two to the data:
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
15 names(file) <- headers
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
16 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
17 else {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
18 file <- read.table(filename, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
19 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
20 return(file)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
21 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
22
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
23 getprofile = function(ids, id_type, level, duplicate) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
24 ####################################################################
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
25 # Arguments
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
26 # - ids: list of input IDs
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
27 # - id_type: type of input IDs (UniProt/ENTREZID)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
28 # - level
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
29 # - duplicate: if the duplicated IDs should be removed or not (TRUE/FALSE)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
30 ####################################################################
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
31
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
32 # Check if level is number
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
33 if (! as.numeric(level) %% 1 == 0) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
34 stop("Please enter an integer for level")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
35 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
36 else {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
37 level = as.numeric(level)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
38 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
39 #genes = as.vector(file[,ncol])
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
40
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
41 # Extract Gene Entrez ID
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
42 if (id_type == "Entrez") {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
43 id = select(org.Hs.eg.db, ids, "ENTREZID", multiVals = "first")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
44 genes_ids = id$ENTREZID[which( ! is.na(id$ENTREZID))]
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
45 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
46 else {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
47 genes_ids = c()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
48 id = select(org.Hs.eg.db, ids, "ENTREZID", "UNIPROT", multiVals = "first")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
49 if (duplicate == "TRUE") {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
50 id = unique(id)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
51 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
52 print(id[[1]])
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
53 genes_ids = id$ENTREZID[which( ! is.na(id$ENTREZID))]
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
54 # IDs that have NA ENTREZID
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
55 NAs = id$UNIPROT[which(is.na(id$ENTREZID))]
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
56 print("IDs unable to convert to ENTREZID: ")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
57 print(NAs)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
58 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
59
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
60 # Create basic profiles
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
61 profile.CC = basicProfile(genes_ids, onto='CC', level=level, orgPackage="org.Hs.eg.db", empty.cats=F, ord=T, na.rm=T)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
62 profile.BP = basicProfile(genes_ids, onto='BP', level=level, orgPackage="org.Hs.eg.db", empty.cats=F, ord=T, na.rm=T)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
63 profile.MF = basicProfile(genes_ids, onto='MF', level=level, orgPackage="org.Hs.eg.db", empty.cats=F, ord=T, na.rm=T)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
64 profile.ALL = basicProfile(genes_ids, onto='ANY', level=level, orgPackage="org.Hs.eg.db", empty.cats=F, ord=T, na.rm=T)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
65
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
66 # Print profile
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
67 # printProfiles(profile)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
68
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
69 return(c(profile.CC, profile.MF, profile.BP, profile.ALL))
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
70 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
71
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
72 # Plot profiles to PNG
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
73 plotPNG = function(profile.CC = NULL, profile.BP = NULL, profile.MF = NULL, profile.ALL = NULL, per = TRUE, title = TRUE) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
74 if (!is.null(profile.CC)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
75 png("profile.CC.png")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
76 plotProfiles(profile.CC, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
77 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
78 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
79 if (!is.null(profile.BP)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
80 png("profile.BP.png")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
81 plotProfiles(profile.BP, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
82 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
83 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
84 if (!is.null(profile.MF)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
85 png("profile.MF.png")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
86 plotProfiles(profile.MF, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
87 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
88 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
89 if (!is.null(profile.ALL)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
90 png("profile.ALL.png")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
91 plotProfiles(profile.ALL, percentage=per, multiplePlots=T, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
92 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
93 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
94 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
95
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
96 # Plot profiles to JPEG
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
97 plotJPEG = function(profile.CC = NULL, profile.BP = NULL, profile.MF = NULL, profile.ALL = NULL, per = TRUE, title = TRUE) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
98 if (!is.null(profile.CC)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
99 jpeg("profile.CC.jpeg")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
100 plotProfiles(profile.CC, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
101 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
102 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
103 if (!is.null(profile.BP)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
104 jpeg("profile.BP.jpeg")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
105 plotProfiles(profile.BP, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
106 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
107 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
108 if (!is.null(profile.MF)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
109 jpeg("profile.MF.jpeg")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
110 plotProfiles(profile.MF, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
111 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
112 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
113 if (!is.null(profile.ALL)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
114 jpeg("profile.ALL.jpeg")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
115 plotProfiles(profile.ALL, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
116 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
117 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
118 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
119
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
120 # Plot profiles to PDF
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
121 plotPDF = function(profile.CC = NULL, profile.BP = NULL, profile.MF = NULL, profile.ALL = NULL, per = TRUE, title = TRUE) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
122 if (!is.null(profile.CC)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
123 pdf("profile.CC.pdf")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
124 plotProfiles(profile.CC, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
125 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
126 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
127 if (!is.null(profile.BP)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
128 pdf("profile.BP.pdf")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
129 plotProfiles(profile.BP, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
130 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
131 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
132 if (!is.null(profile.MF)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
133 pdf("profile.MF.pdf")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
134 plotProfiles(profile.MF, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
135 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
136 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
137 if (!is.null(profile.ALL)) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
138 #print("all")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
139 pdf("profile.ALL.pdf")
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
140 plotProfiles(profile.ALL, percentage=per, multiplePlots=FALSE, aTitle=title)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
141 dev.off()
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
142 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
143 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
144
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
145 goprofiles = function() {
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
146 args <- commandArgs(TRUE)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
147 if(length(args)<1) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
148 args <- c("--help")
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
149 }
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
150
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
151 # Help section
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
152 if("--help" %in% args) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
153 cat("Selection and Annotation HPA
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
154 Arguments:
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
155 --input_type: type of input (list of id or filename)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
156 --input: input
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
157 --ncol: the column number which you would like to apply...
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
158 --header: true/false if your file contains a header
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
159 --id_type: the type of input IDs (UniProt/EntrezID)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
160 --onto_opt: ontology options
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
161 --plot_opt: plot extension options (PDF/JPEG/PNG)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
162 --level: 1-3
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
163 --per
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
164 --title: title of the plot
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
165 --duplicate: remove dupliate input IDs (true/false)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
166 --text_output: text output filename \n")
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
167 q(save="no")
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
168 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
169
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
170 # Parse arguments
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
171 parseArgs <- function(x) strsplit(sub("^--", "", x), "=")
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
172 argsDF <- as.data.frame(do.call("rbind", parseArgs(args)))
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
173 args <- as.list(as.character(argsDF$V2))
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
174 names(args) <- argsDF$V1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
175
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
176 input_type = args$input_type
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
177 if (input_type == "text") {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
178 input = strsplit(args$input, " ")[[1]]
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
179 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
180 else if (input_type == "file") {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
181 filename = args$input
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
182 ncol = args$ncol
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
183 # Check ncol
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
184 if (! as.numeric(gsub("c", "", ncol)) %% 1 == 0) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
185 stop("Please enter an integer for level")
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
186 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
187 else {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
188 ncol = as.numeric(gsub("c", "", ncol))
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
189 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
190 header = args$header
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
191 # Get file content
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
192 file = readfile(filename, header)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
193 # Extract Protein IDs list
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
194 input = c()
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
195 for (row in as.character(file[,ncol])) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
196 input = c(input, strsplit(row, ";")[[1]][1])
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
197 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
198 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
199 id_type = args$id_type
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
200 ontoopt = strsplit(args$onto_opt, ",")[[1]]
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
201 #print(ontoopt)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
202 #plotopt = strsplit(args[3], ",")
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
203 plotopt = args$plot_opt
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
204 level = args$level
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
205 per = as.logical(args$per)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
206 title = args$title
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
207 duplicate = args$duplicate
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
208 text_output = args$text_output
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
209
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
210 profiles = getprofile(input, id_type, level, duplicate)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
211 profile.CC = profiles[1]
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
212 #print(profile.CC)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
213 profile.MF = profiles[2]
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
214 #print(profile.MF)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
215 profile.BP = profiles[3]
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
216 #print(profile.BP)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
217 profile.ALL = profiles[-3:-1]
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
218 #print(profile.ALL)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
219 #c(profile.ALL, profile.CC, profile.MF, profile.BP)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
220
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
221 if ("CC" %in% ontoopt) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
222 write.table(profile.CC, text_output, append = TRUE, sep="\t", row.names = FALSE, quote=FALSE)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
223 if (grepl("PNG", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
224 plotPNG(profile.CC=profile.CC, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
225 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
226 if (grepl("JPEG", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
227 plotJPEG(profile.CC = profile.CC, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
228 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
229 if (grepl("PDF", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
230 plotPDF(profile.CC = profile.CC, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
231 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
232 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
233 if ("MF" %in% ontoopt) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
234 write.table(profile.MF, text_output, append = TRUE, sep="\t", row.names = FALSE, quote=FALSE)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
235 if (grepl("PNG", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
236 plotPNG(profile.MF = profile.MF, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
237 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
238 if (grepl("JPEG", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
239 plotJPEG(profile.MF = profile.MF, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
240 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
241 if (grepl("PDF", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
242 plotPDF(profile.MF = profile.MF, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
243 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
244 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
245 if ("BP" %in% ontoopt) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
246 write.table(profile.BP, text_output, append = TRUE, sep="\t", row.names = FALSE, quote=FALSE)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
247 if (grepl("PNG", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
248 plotPNG(profile.BP = profile.BP, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
249 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
250 if (grepl("JPEG", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
251 plotJPEG(profile.BP = profile.BP, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
252 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
253 if (grepl("PDF", plotopt)) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
254 plotPDF(profile.BP = profile.BP, per=per, title=title)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
255 }
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
256 }
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
257 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
258
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
259 goprofiles()