annotate goprofiles.R @ 15:601027649251 draft default tip

"planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
author proteore
date Tue, 06 Apr 2021 16:59:30 +0000
parents 3ddc1f78773d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
1 options(warn = -1) #TURN OFF WARNINGS !!!!!!
6
6afe8166a9a4 planemo upload commit 4e898239997b7ef266b1d0ce0a4c7cdec31b4ecd-dirty
proteore
parents: 5
diff changeset
2
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
3 # Load necessary libraries
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
4 suppressMessages(library(goProfiles, quietly = TRUE))
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
5
4
715002a394ec planemo upload commit b36435833bf54f90f62cc240f2cda1c889161b23-dirty
proteore
parents: 2
diff changeset
6 # Read file and return file content as data.frame
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
7 read_file <- function(path, header) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
8 file <- try(read.csv(path, header = header,
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
9 sep = "\t", stringsAsFactors = FALSE,
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
10 quote = "\"", check.names = F), silent = TRUE)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
11 if (inherits(file, "try-error")) {
8
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
12 stop("File not found !")
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
13 }else{
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
14 return(file)
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
15 }
8
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
16 }
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
17
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
18 #convert a string to boolean
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
19 str2bool <- function(x) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
20 if (any(is.element(c("t", "true"), tolower(x)))) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
21 return(TRUE)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
22 }else if (any(is.element(c("f", "false"), tolower(x)))) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
23 return(FALSE)
8
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
24 }else{
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
25 return(NULL)
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
26 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
27 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
28
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
29 check_ids <- function(vector, type) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
30 # nolint start
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
31 uniprot_pattern <-
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
32 "^([OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})$"
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
33 entrez_id <- "^([0-9]+|[A-Z]{1,2}_[0-9]+|[A-Z]{1,2}_[A-Z]{1,4}[0-9]+)$"
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
34 # nolint end
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
35 if (type == "Entrez") {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
36 return(grepl(entrez_id, vector))
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
37 } else if (type == "UniProt") {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
38 return(grepl(uniprot_pattern, vector))
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
39 }
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
40 }
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
41
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
42 getprofile <- function(ids, id_type, level, duplicate, species) {
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
43 ####################################################################
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
44 # Arguments
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
45 # - ids: list of input IDs
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
46 # - id_type: type of input IDs (UniProt/ENTREZID)
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
47 # - level
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
48 # - duplicate: if the duplicated IDs should be removed or not (TRUE/FALSE)
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
49 # - species
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
50 ####################################################################
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
51
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
52 library(species, character.only = TRUE, quietly = TRUE)
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
53
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
54 if (species == "org.Hs.eg.db") {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
55 package <- org.Hs.eg.db #nolint
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
56 } else if (species == "org.Mm.eg.db") {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
57 package <- org.Mm.eg.db #nolint
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
58 } else if (species == "org.Rn.eg.db") {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
59 package <- org.Rn.eg.db #nolint
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
60 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
61
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
62 # Check if level is number
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
63 if (! as.numeric(level) %% 1 == 0) {
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
64 stop("Please enter an integer for level")
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
65 } else {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
66 level <- as.numeric(level)
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
67 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
68
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
69
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
70 # Extract Gene Entrez ID
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
71 if (id_type == "Entrez") {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
72 id <- select(package, ids, "ENTREZID", multiVals = "first") #nolint
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
73 } else {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
74 id <- select(package, ids, "ENTREZID", "UNIPROT", multiVals = "first") #nolint
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
75 }
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
76 if (duplicate) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
77 id <- unique(id)
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
78 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
79 genes_ids <- id$ENTREZID[which(!is.na(id$ENTREZID))]
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
80 nas <- id$UNIPROT[which(is.na(id$ENTREZID))] # IDs that have NA ENTREZID #nolint
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
81
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
82 # Create basic profiles
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
83 profile.CC <-
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
84 basicProfile(genes_ids, onto = "CC", level = level,
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
85 orgPackage = species, empty.cats = F, ord = T, na.rm = T)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
86 profile.BP <-
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
87 basicProfile(genes_ids, onto = "BP", level = level,
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
88 orgPackage = species, empty.cats = F, ord = T, na.rm = T)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
89 profile.MF <-
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
90 basicProfile(genes_ids, onto = "MF", level = level,
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
91 orgPackage = species, empty.cats = F, ord = T, na.rm = T)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
92 profile.ALL <-
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
93 basicProfile(genes_ids, onto = "ANY", level = level,
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
94 orgPackage = species, empty.cats = F, ord = T, na.rm = T)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
95
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
96 return(c(profile.CC, profile.MF, profile.BP, profile.ALL))
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
97 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
98
9
948fecb6a40b planemo upload commit 973d782455fd6a7df7ba9bce0a7878de53bc1e68-dirty
proteore
parents: 8
diff changeset
99 #return height and width of plot in inches from profile
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
100 plot_size_from_nb_onto <- function(profile) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
101 width <- 10
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
102 range <- seq(25, 2000, by = 25)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
103 names(range) <- seq(5, 242, by = 3)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
104 nb_onto <- round(nrow(profile[[1]]) / 25) * 25
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
105 if (nb_onto < 25) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
106 nb_onto <- 25
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
107 }
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
108 if (nb_onto <= 2000) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
109 height <- as.integer(names(which(range == nb_onto)))
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
110 } else {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
111 height <- 250
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
112 }
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
113 return(c(width, height))
9
948fecb6a40b planemo upload commit 973d782455fd6a7df7ba9bce0a7878de53bc1e68-dirty
proteore
parents: 8
diff changeset
114 }
948fecb6a40b planemo upload commit 973d782455fd6a7df7ba9bce0a7878de53bc1e68-dirty
proteore
parents: 8
diff changeset
115
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
116 make_plot <- function(profile, percent, title, onto, plot_opt) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
117
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
118 tmp <- plot_size_from_nb_onto(profile)
9
948fecb6a40b planemo upload commit 973d782455fd6a7df7ba9bce0a7878de53bc1e68-dirty
proteore
parents: 8
diff changeset
119 width <- tmp[1]
948fecb6a40b planemo upload commit 973d782455fd6a7df7ba9bce0a7878de53bc1e68-dirty
proteore
parents: 8
diff changeset
120 height <- tmp[2]
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
121
8
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
122 if (plot_opt == "PDF") {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
123 file_name <- paste("profile_", onto, ".pdf", collapse = "", sep = "")
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
124 pdf(file_name, width = width, height = height)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
125 } else if (plot_opt == "JPEG") {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
126 file_name <- paste("profile_", onto, ".jpeg", collapse = "", sep = "")
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
127 jpeg(file_name, width = width, height = height, units = "in", res = 100)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
128 } else if (plot_opt == "PNG") {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
129 file_name <- paste("profile_", onto, ".png", collapse = "", sep = "")
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
130 png(file_name, width = width, height = height, units = "in", res = 100)
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
131 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
132 plotProfiles(profile, percentage = percent,
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
133 multiplePlots = FALSE, aTitle = title)
8
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
134 dev.off()
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
135 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
136
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
137 goprofiles <- function() {
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
138 args <- commandArgs(TRUE)
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
139 if (length(args) < 1) {
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
140 args <- c("--help")
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
141 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
142
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
143 # Help section
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
144 if ("--help" %in% args) {
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
145 cat("Selection and Annotation HPA
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
146 Arguments:
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
147 --input_type: type of input (list of id or filename)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
148 --input: input
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
149 --ncol: the column number which you would like to apply...
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
150 --header: true/false if your file contains a header
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
151 --id_type: the type of input IDs (UniProt/EntrezID)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
152 --onto_opt: ontology options
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
153 --plot_opt: plot extension options (PDF/JPEG/PNG)
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
154 --level: 1-3
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
155 --per
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
156 --title: title of the plot
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
157 --duplicate: remove dupliate input IDs (true/false)
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
158 --text_output: text output filename \n
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
159 --species")
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
160 q(save = "no")
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
161 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
162
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
163 # Parse arguments
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
164 parse_args <- function(x) strsplit(sub("^--", "", x), "=")
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
165 args_df <- as.data.frame(do.call("rbind", parse_args(args)))
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
166 args <- as.list(as.character(args_df$V2))
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
167 names(args) <- args_df$V1
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
168
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
169
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
170 id_type <- args$id_type
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
171 input_type <- args$input_type
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
172 if (input_type == "text") {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
173 input <- unlist(strsplit(strsplit(args$input, "[ \t\n]+")[[1]], ";"))
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
174 } else if (input_type == "file") {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
175 filename <- args$input
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
176 ncol <- args$ncol
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
177 # Check ncol
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
178 if (! as.numeric(gsub("c", "", ncol)) %% 1 == 0) {
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
179 stop("Please enter an integer for level")
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
180 } else {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
181 ncol <- as.numeric(gsub("c", "", ncol))
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
182 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
183 header <- str2bool(args$header)
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
184 # Get file content
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
185 file <- read_file(filename, header)
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
186 # Extract Protein IDs list
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
187 input <- unlist(strsplit(as.character(file[, ncol]), ";"))
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
188 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
189 input <- input [which(!is.na(gsub("NA", NA, input)))]
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
190
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
191 if (! any(check_ids(input, id_type))) {
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
192 stop(paste(id_type,
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
193 "not found in your ids list, please check your IDs in input
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
194 or the selected column of your input file"))
5
781072a65600 planemo upload commit 0ce4c81e6d2f7af8c9b52f6c07e83b0319c2adb1-dirty
proteore
parents: 4
diff changeset
195 }
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
196
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
197 ontoopt <- strsplit(args$onto_opt, ",")[[1]]
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
198 onto_pos <- as.integer(gsub("BP", 3, gsub("MF", 2, gsub("CC", 1, ontoopt))))
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
199 plotopt <- args$plot_opt
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
200 level <- args$level
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
201 per <- as.logical(args$per)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
202 title <- args$title
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
203 duplicate <- str2bool(args$duplicate)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
204 text_output <- args$text_output
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
205 species <- args$species
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
206
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
207 profiles <- getprofile(input, id_type, level, duplicate, species)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
208
8
386145573c19 planemo upload commit bdd7e8a1f08c11db2a9f1b6db5535c6d32153b2b
proteore
parents: 7
diff changeset
209 for (index in onto_pos) {
15
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
210 onto <- names(profiles[index])
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
211 profile <- profiles[index]
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
212 make_plot(profile, per, title, onto, plotopt)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
213 text_output <- paste("goProfiles_", onto, "_",
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
214 title, ".tsv", sep = "", collapse = "")
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
215 profile <- as.data.frame(profile)
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
216 profile <- as.data.frame(apply(profile, c(1, 2),
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
217 function(x) gsub("^$|^ $", NA, x))) #convert "" and " " to NA
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
218 write.table(profile, text_output, sep = "\t",
601027649251 "planemo upload commit 6bc2c32177acd823d5025bc90a562e6e6b2a233a"
proteore
parents: 11
diff changeset
219 row.names = FALSE, quote = FALSE, col.names = T)
1
1236ee08ccb8 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents: 0
diff changeset
220 }
0
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
221 }
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
222
d89c09253c8d planemo upload commit abb24d36c776520e73220d11386252d848173697-dirty
proteore
parents:
diff changeset
223 goprofiles()