annotate add_expression_HPA.R @ 11:e109cacd75b2 draft

planemo upload commit f91a292f92a3e75996e6f4502fa090961727c235-dirty
author proteore
date Wed, 02 Jan 2019 04:40:04 -0500
parents 5c260bd3552e
children dbeabf9bf091
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
1 # Read file and return file content as data.frame
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
2 read_file <- function(path,header){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
3 file <- try(read.csv(path,header=header, sep="\t",stringsAsFactors = FALSE, quote="\"", check.names = F),silent=TRUE)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
4 if (inherits(file,"try-error")){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
5 stop("File not found !")
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
6 }else{
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
7 return(file)
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
8 }
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
9 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
10
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
11 #convert a string to boolean
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
12 str2bool <- function(x){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
13 if (any(is.element(c("t","true"),tolower(x)))){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
14 return (TRUE)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
15 }else if (any(is.element(c("f","false"),tolower(x)))){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
16 return (FALSE)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
17 }else{
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
18 return(NULL)
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
19 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
20 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
21
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
22 add_expression = function(input, atlas, options) {
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
23 input <- unique(input[!is.na(input)])
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
24 input <- gsub("[[:blank:]]|\u00A0","",input)
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
25 if (all(!input %in% atlas$Ensembl)) {
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
26 return(NULL)
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
27 } else {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
28 res = atlas[match(input,atlas$Ensembl),c("Ensembl",options)]
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
29 res = res[which(!is.na(res[,1])),]
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
30 row.names(res)=res[,1]
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
31 res=res[2:ncol(res)]
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
32 res <- as.data.frame(apply(res, c(1,2), function(x) gsub("^$|^ $", NA, x))) #convert "" et " " to NA
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
33 return(res)
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
34 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
35 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
36
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
37 order_columns <- function (df,ncol){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
38 if (ncol==1){ #already at the right position
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
39 return (df)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
40 } else {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
41 df = df[,c(2:ncol,1,(ncol+1):dim.data.frame(df)[2])]
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
42 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
43 return (df)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
44 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
45
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
46 #take data frame, return data frame
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
47 split_ids_per_line <- function(line,ncol){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
48
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
49 #print (line)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
50 header = colnames(line)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
51 line[ncol] = gsub("[[:blank:]]","",line[ncol])
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
52
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
53 if (length(unlist(strsplit(as.character(line[ncol]),";")))>1) {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
54 if (length(line)==1 ) {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
55 lines = as.data.frame(unlist(strsplit(as.character(line[ncol]),";")),stringsAsFactors = F)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
56 } else {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
57 if (ncol==1) { #first column
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
58 lines = suppressWarnings(cbind(unlist(strsplit(as.character(line[ncol]),";")), line[2:length(line)]))
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
59 } else if (ncol==length(line)) { #last column
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
60 lines = suppressWarnings(cbind(line[1:ncol-1],unlist(strsplit(as.character(line[ncol]),";"))))
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
61 } else {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
62 lines = suppressWarnings(cbind(line[1:ncol-1], unlist(strsplit(as.character(line[ncol]),";"),use.names = F), line[(ncol+1):length(line)]))
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
63 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
64 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
65 colnames(lines)=header
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
66 return(lines)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
67 } else {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
68 return(line)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
69 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
70 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
71
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
72 #create new lines if there's more than one id per cell in the columns in order to have only one id per line
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
73 one_id_one_line <-function(tab,ncol){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
74
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
75 if (ncol(tab)>1){
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
76
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
77 tab[,ncol] = sapply(tab[,ncol],function(x) gsub("[[:blank:]]","",x))
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
78 header=colnames(tab)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
79 res=as.data.frame(matrix(ncol=ncol(tab),nrow=0))
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
80 for (i in 1:nrow(tab) ) {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
81 lines = split_ids_per_line(tab[i,],ncol)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
82 res = rbind(res,lines)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
83 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
84 }else {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
85 res = unlist(sapply(tab[,1],function(x) strsplit(x,";")),use.names = F)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
86 res = data.frame(res[which(!is.na(res[res!=""]))],stringsAsFactors = F)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
87 colnames(res)=colnames(tab)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
88 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
89 return(res)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
90 }
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
91
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
92 main = function() {
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
93 args <- commandArgs(TRUE)
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
94 if(length(args)<1) {
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
95 args <- c("--help")
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
96 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
97
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
98 # Help section
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
99 if("--help" %in% args) {
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
100 cat("Selection and Annotation HPA
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
101 Arguments:
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
102 --inputtype: type of input (list of id or filename)
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
103 --input: either a file name (e.g : input.txt) or a list of blank-separated
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
104 ENSG identifiers (e.g : ENSG00000283071 ENSG00000283072)
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
105 --atlas: path to protein atlas file
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
106 --column: the column number which you would like to apply...
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
107 --header: true/false if your file contains a header
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
108 --select: information from HPA to select, maybe:
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
109 RNA.tissue.category,Reliability..IH.,Reliability..IF. (comma-separated)
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
110 --output: text output filename \n")
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
111 q(save="no")
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
112 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
113
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
114 # Parse arguments
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
115 parseArgs <- function(x) strsplit(sub("^--", "", x), "=")
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
116 argsDF <- as.data.frame(do.call("rbind", parseArgs(args)))
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
117 args <- as.list(as.character(argsDF$V2))
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
118 names(args) <- argsDF$V1
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
119
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
120 #save(args,file="/home/dchristiany/proteore_project/ProteoRE/tools/add_expression_data_HPA/args.rda")
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
121 #load("/home/dchristiany/proteore_project/ProteoRE/tools/add_expression_data_HPA/args.rda")
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
122
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
123 inputtype = args$inputtype
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
124 if (inputtype == "copypaste") {
7
c9943f867413 planemo upload commit 6b011549498a096af60a494bc39c1a2078580a5a-dirty
proteore
parents: 6
diff changeset
125 input = strsplit(args$input, "[ \t\n]+")[[1]]
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
126 } else if (inputtype == "tabfile") {
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
127 filename = args$input
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
128 ncol = args$column
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
129 # Check ncol
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
130 if (! as.numeric(gsub("c", "", ncol)) %% 1 == 0) {
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
131 stop("Please enter an integer for level")
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
132 } else {
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
133 ncol = as.numeric(gsub("c", "", ncol))
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
134 }
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
135 header = str2bool(args$header)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
136 file = read_file(filename, header)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
137 file = one_id_one_line(file,ncol)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
138 input = unlist(sapply(as.character(file[,ncol]),function(x) rapply(strsplit(x,";"),c),USE.NAMES = FALSE))
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
139 input = input[which(!is.na(input))]
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
140 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
141
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
142 # Read protein atlas
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
143 protein_atlas = args$atlas
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
144 protein_atlas = read_file(protein_atlas, T)
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
145
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
146 # Add expression
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
147 output = args$output
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
148 options = strsplit(args$select, ",")[[1]]
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
149 res = add_expression(input, protein_atlas, options)
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
150
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
151 # Write output
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
152 if (is.null(res)) {
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
153 write.table("None of the input ENSG ids are can be found in HPA data file",file=output,sep="\t",quote=FALSE,col.names=TRUE,row.names=FALSE)
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
154 } else {
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
155 if (inputtype == "copypaste") {
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
156 input <- data.frame(input)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
157 output_content = merge(input,res,by.x=1,by.y="row.names",incomparables = NA, all.x=T)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
158 colnames(output_content)[1] = "Ensembl"
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
159 } else if (inputtype == "tabfile") {
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
160 output_content = merge(file, res, by.x=ncol, by.y="row.names", incomparables = NA, all.x=T)
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
161 output_content = order_columns(output_content,ncol)
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
162 }
9
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
163 output_content <- as.data.frame(apply(output_content, c(1,2), function(x) gsub("^$|^ $", NA, x)))
5c260bd3552e planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents: 7
diff changeset
164 write.table(output_content, output, row.names = FALSE, sep = "\t", quote = FALSE)
6
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
165 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
166 }
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
167
71214d6034e7 planemo upload commit 4af7ac25de19ca10b1654820e909c647a2d337b2-dirty
proteore
parents:
diff changeset
168 main()