# HG changeset patch # User proteore # Date 1545139428 18000 # Node ID 5c260bd3552e3c6c19feb5cf52949345717451f8 # Parent 2df5166efebb16d7cfc61e1976e2f561db86db33 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e diff -r 2df5166efebb -r 5c260bd3552e README.rst --- a/README.rst Fri Mar 23 10:31:59 2018 -0400 +++ b/README.rst Tue Dec 18 08:23:48 2018 -0500 @@ -2,7 +2,7 @@ ========================================================= **Authors** -Lisa Peru, T.P. Lien Nguyen, Florence Combes, Yves Vandenbrouck CEA, INSERM, CNRS, Grenoble-Alpes University, BIG Institute, FR +Lisa Perus, T.P. Lien Nguyen, Florence Combes, Yves Vandenbrouck CEA, INSERM, CNRS, Grenoble-Alpes University, BIG Institute, FR Sandra Dérozier, Olivier Rué, Christophe Caron, Valentin Loux INRA, Paris-Saclay University, MAIAGE Unit, Migale Bioinformatics platform @@ -20,7 +20,7 @@ **Databases** -HPA source file (Human Protein Atlas version 18): http://www.proteinatlas.org/download/proteinatlas.tab.gz +HPA source file: http://www.proteinatlas.org/download/proteinatlas.tab.gz **Annotation** @@ -46,4 +46,4 @@ **Outputs** -The output is a tabular file. The initial columns are kept and new columns are added according to what type of annotation data you chose. +The output is a tabular file. The initial columns are kept and new columns are added according to what type of annotation data you chose. diff -r 2df5166efebb -r 5c260bd3552e add_expression_HPA.R --- a/add_expression_HPA.R Fri Mar 23 10:31:59 2018 -0400 +++ b/add_expression_HPA.R Tue Dec 18 08:23:48 2018 -0500 @@ -1,40 +1,94 @@ # Read file and return file content as data.frame -readfile = function(filename, header) { - if (header == "true") { - # Read only first line of the file as header: - headers <- read.table(filename, nrows = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "", comment.char = "") - #Read the data of the files (skipping the first row) - file <- read.table(filename, skip = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "", comment.char = "") - # Remove empty rows - file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE] - #And assign the header to the data - names(file) <- headers +read_file <- function(path,header){ + file <- try(read.csv(path,header=header, sep="\t",stringsAsFactors = FALSE, quote="\"", check.names = F),silent=TRUE) + if (inherits(file,"try-error")){ + stop("File not found !") + }else{ + return(file) } - else { - file <- read.table(filename, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "", comment.char = "") - # Remove empty rows - file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE] +} + +#convert a string to boolean +str2bool <- function(x){ + if (any(is.element(c("t","true"),tolower(x)))){ + return (TRUE) + }else if (any(is.element(c("f","false"),tolower(x)))){ + return (FALSE) + }else{ + return(NULL) } - return(file) } add_expression = function(input, atlas, options) { + input <- unique(input[!is.na(input)]) + input <- gsub("[[:blank:]]|\u00A0","",input) if (all(!input %in% atlas$Ensembl)) { return(NULL) - } - else { - res = matrix(nrow=length(input), ncol=0) - names = c() - for (opt in options) { - names = c(names, opt) - info = atlas[match(input, atlas$Ensembl,incomparable="NA"),][opt][,] - res = cbind(res, info) - } - colnames(res) = names + } else { + res = atlas[match(input,atlas$Ensembl),c("Ensembl",options)] + res = res[which(!is.na(res[,1])),] + row.names(res)=res[,1] + res=res[2:ncol(res)] + res <- as.data.frame(apply(res, c(1,2), function(x) gsub("^$|^ $", NA, x))) #convert "" et " " to NA return(res) } } +order_columns <- function (df,ncol){ + if (ncol==1){ #already at the right position + return (df) + } else { + df = df[,c(2:ncol,1,(ncol+1):dim.data.frame(df)[2])] + } + return (df) +} + +#take data frame, return data frame +split_ids_per_line <- function(line,ncol){ + + #print (line) + header = colnames(line) + line[ncol] = gsub("[[:blank:]]","",line[ncol]) + + if (length(unlist(strsplit(as.character(line[ncol]),";")))>1) { + if (length(line)==1 ) { + lines = as.data.frame(unlist(strsplit(as.character(line[ncol]),";")),stringsAsFactors = F) + } else { + if (ncol==1) { #first column + lines = suppressWarnings(cbind(unlist(strsplit(as.character(line[ncol]),";")), line[2:length(line)])) + } else if (ncol==length(line)) { #last column + lines = suppressWarnings(cbind(line[1:ncol-1],unlist(strsplit(as.character(line[ncol]),";")))) + } else { + lines = suppressWarnings(cbind(line[1:ncol-1], unlist(strsplit(as.character(line[ncol]),";"),use.names = F), line[(ncol+1):length(line)])) + } + } + colnames(lines)=header + return(lines) + } else { + return(line) + } +} + +#create new lines if there's more than one id per cell in the columns in order to have only one id per line +one_id_one_line <-function(tab,ncol){ + + if (ncol(tab)>1){ + + tab[,ncol] = sapply(tab[,ncol],function(x) gsub("[[:blank:]]","",x)) + header=colnames(tab) + res=as.data.frame(matrix(ncol=ncol(tab),nrow=0)) + for (i in 1:nrow(tab) ) { + lines = split_ids_per_line(tab[i,],ncol) + res = rbind(res,lines) + } + }else { + res = unlist(sapply(tab[,1],function(x) strsplit(x,";")),use.names = F) + res = data.frame(res[which(!is.na(res[res!=""]))],stringsAsFactors = F) + colnames(res)=colnames(tab) + } + return(res) +} + main = function() { args <- commandArgs(TRUE) if(length(args)<1) { @@ -63,59 +117,52 @@ args <- as.list(as.character(argsDF$V2)) names(args) <- argsDF$V1 + #save(args,file="/home/dchristiany/proteore_project/ProteoRE/tools/add_expression_data_HPA/args.rda") + #load("/home/dchristiany/proteore_project/ProteoRE/tools/add_expression_data_HPA/args.rda") + inputtype = args$inputtype if (inputtype == "copypaste") { input = strsplit(args$input, "[ \t\n]+")[[1]] - } - else if (inputtype == "tabfile") { + } else if (inputtype == "tabfile") { filename = args$input ncol = args$column # Check ncol if (! as.numeric(gsub("c", "", ncol)) %% 1 == 0) { stop("Please enter an integer for level") - } - else { + } else { ncol = as.numeric(gsub("c", "", ncol)) } - header = args$header - # Get file content - file = readfile(filename, header) - # Extract Protein IDs list - input = c() - for (row in as.character(file[,ncol])) { - input = c(input, strsplit(row, ";")[[1]][1]) - } + header = str2bool(args$header) + file = read_file(filename, header) + file = one_id_one_line(file,ncol) + input = unlist(sapply(as.character(file[,ncol]),function(x) rapply(strsplit(x,";"),c),USE.NAMES = FALSE)) + input = input[which(!is.na(input))] } # Read protein atlas protein_atlas = args$atlas - protein_atlas = readfile(protein_atlas, "true") + protein_atlas = read_file(protein_atlas, T) # Add expression output = args$output - names = c() options = strsplit(args$select, ",")[[1]] res = add_expression(input, protein_atlas, options) - + # Write output if (is.null(res)) { 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) - } - else { + } else { if (inputtype == "copypaste") { - names = c("Ensembl", colnames(res)) - res = cbind(as.matrix(input), res) - colnames(res) = names - write.table(res, output, row.names = FALSE, sep = "\t", quote = FALSE) + input <- data.frame(input) + output_content = merge(input,res,by.x=1,by.y="row.names",incomparables = NA, all.x=T) + colnames(output_content)[1] = "Ensembl" + } else if (inputtype == "tabfile") { + output_content = merge(file, res, by.x=ncol, by.y="row.names", incomparables = NA, all.x=T) + output_content = order_columns(output_content,ncol) } - else if (inputtype == "tabfile") { - names = c(names(file), colnames(res)) - output_content = cbind(file, res) - colnames(output_content) = names - write.table(output_content, output, row.names = FALSE, sep = "\t", quote = FALSE) - } + output_content <- as.data.frame(apply(output_content, c(1,2), function(x) gsub("^$|^ $", NA, x))) + write.table(output_content, output, row.names = FALSE, sep = "\t", quote = FALSE) } - } main() diff -r 2df5166efebb -r 5c260bd3552e add_expression_data.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/add_expression_data.xml Tue Dec 18 08:23:48 2018 -0500 @@ -0,0 +1,157 @@ + + (RNAseq or Immuno-assays)[Human Protein Atlas] + + + R + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + +
+ +
+ +
+
+ + + + + + +
diff -r 2df5166efebb -r 5c260bd3552e expression_rnaseq_abbased.xml --- a/expression_rnaseq_abbased.xml Fri Mar 23 10:31:59 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ - - -mRNA and protein level data from Human Protein Atlas - - - R - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- -
- - - - - - - - - - - - - - -
- -
- -
-
- - - - - - -