Mercurial > repos > proteore > proteore_expression_rnaseq_abbased
comparison add_expression_HPA.R @ 12:f8d3a8a2f2e5 draft
"planemo upload commit 58e072579a4be282c00b54ebb88fbc59e189a7ed-dirty"
| author | proteore |
|---|---|
| date | Thu, 23 Jan 2020 10:44:39 +0000 |
| parents | 07858c6dbbff |
| children | 8ee4cfdc1a92 |
comparison
equal
deleted
inserted
replaced
| 11:4c27466a4e15 | 12:f8d3a8a2f2e5 |
|---|---|
| 1 # Read file and return file content as data.frame | 1 # Read file and return file content as data.frame |
| 2 read_file <- function(path,header){ | 2 read_file <- function(path,header){ |
| 3 file <- read.csv(path,header=header, sep="\t",stringsAsFactors = FALSE, quote="\"", check.names = F) | 3 file <- try(read.csv(path,header=header, sep="\t",stringsAsFactors = FALSE, quote="\"", check.names = F),silent=TRUE) |
| 4 return(file) | 4 if (inherits(file,"try-error")){ |
| 5 stop("File not found !") | |
| 6 }else{ | |
| 7 return(file) | |
| 8 } | |
| 5 } | 9 } |
| 6 | 10 |
| 7 #convert a string to boolean | 11 #convert a string to boolean |
| 8 str2bool <- function(x){ | 12 str2bool <- function(x){ |
| 9 if (any(is.element(c("t","true"),tolower(x)))){ | 13 if (any(is.element(c("t","true"),tolower(x)))){ |
| 140 cat(paste(sep = "", collapse = " ", c("Column",ncol,"not found in file") )) | 144 cat(paste(sep = "", collapse = " ", c("Column",ncol,"not found in file") )) |
| 141 stopQuietly() | 145 stopQuietly() |
| 142 } | 146 } |
| 143 } | 147 } |
| 144 | 148 |
| 149 convert_to_previous_header <- function(options){ | |
| 150 header = c('Gene','description','Evidence','Antibody','RNA tissue specificity','Reliability (IH)','Reliability (IF)','Subcellular location','RNA tissue specific NX') | |
| 151 names(header) = c('Gene','description','Evidence','Antibody','RNA tissue category','Reliability (IH)','Reliability (IF)','Subcellular location','RNA TS TPM') | |
| 152 options = names(header[which(header %in% options)]) | |
| 153 return(options) | |
| 154 } | |
| 155 | |
| 145 main = function() { | 156 main = function() { |
| 146 | 157 |
| 147 args = get_args() | 158 args = get_args() |
| 148 | 159 |
| 149 #save(args,file="/home/dchristiany/proteore_project/ProteoRE/tools/add_expression_data_HPA/args.rda") | 160 #save(args,file="/home/dchristiany/proteore_project/ProteoRE/tools/add_expression_data_HPA/args.rda") |
| 174 protein_atlas = read_file(args$atlas, T) | 185 protein_atlas = read_file(args$atlas, T) |
| 175 | 186 |
| 176 # Add expression | 187 # Add expression |
| 177 output = args$output | 188 output = args$output |
| 178 options = strsplit(args$select, ",")[[1]] | 189 options = strsplit(args$select, ",")[[1]] |
| 190 if (tail(unlist(strsplit(args$atlas,"/")),1) == "HPA_full_atlas_23-10-2018.tsv"){ options = convert_to_previous_header(options)} | |
| 179 res = add_expression(ids, protein_atlas, options) | 191 res = add_expression(ids, protein_atlas, options) |
| 180 | 192 |
| 181 # Write output | 193 # Write output |
| 182 if (is.null(res)) { | 194 if (is.null(res)) { |
| 183 write.table("None of the ENSG ids entered can be found in HPA data file",file=output,sep="\t",quote=FALSE,col.names=TRUE,row.names=FALSE) | 195 write.table("None of the ENSG ids entered can be found in HPA data file",file=output,sep="\t",quote=FALSE,col.names=TRUE,row.names=FALSE) |
