annotate add_protein_features.R @ 10:4de4f6359820 draft

planemo upload commit 9af2cf12c26c94e7206751ccf101a3368f92d0ba
author proteore
date Tue, 18 Dec 2018 09:13:47 -0500
parents 0b46a7aead62
children 8df559ad14a7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
1 # Read file and return file content as data.frame
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
2 read_file <- function(path,header){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
3 file <- try(read.table(path,header=header, sep="\t",stringsAsFactors = FALSE, quote="", check.names = F),silent=TRUE)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
4 if (inherits(file,"try-error")){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
5 stop("File not found !")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
6 }else{
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
7 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
8 return(file)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
9 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
10 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
11
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
12 order_columns <- function (df,ncol,id_type,file){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
13 if (id_type=="Uniprot_AC"){ncol=ncol(file)}
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
14 if (ncol==1){ #already at the right position
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
15 return (df)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
16 } else {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
17 df = df[,c(2:ncol,1,(ncol+1):dim.data.frame(df)[2])]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
18 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
19 return (df)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
20 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
21
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
22 get_list_from_cp <-function(list){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
23 list = strsplit(list, "[ \t\n]+")[[1]]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
24 list = gsub("NA","",list)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
25 list = list[list != ""] #remove empty entry
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
26 list = gsub("-.+", "", list) #Remove isoform accession number (e.g. "-2")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
27 return(list)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
28 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
29
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
30 get_args <- function(){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
31
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
32 ## Collect arguments
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
33 args <- commandArgs(TRUE)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
34
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
35 ## Default setting when no arguments passed
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
36 if(length(args) < 1) {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
37 args <- c("--help")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
38 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
39
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
40 ## Help section
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
41 if("--help" %in% args) {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
42 cat("Selection and Annotation HPA
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
43 Arguments:
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
44 --inputtype: type of input (list of id or filename)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
45 --input: input
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
46 --nextprot: path to nextprot information file
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
47 --column: the column number which you would like to apply...
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
48 --header: true/false if your file contains a header
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
49 --type: the type of input IDs (Uniprot_AC/EntrezID)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
50 --pc_features: IsoPoint,SeqLength,MW
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
51 --localization: Chr,SubcellLocations
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
52 --diseases_info: Diseases
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
53 --output: text output filename \n")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
54
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
55 q(save="no")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
56 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
57
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
58 parseArgs <- function(x) strsplit(sub("^--", "", x), "=")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
59 argsDF <- as.data.frame(do.call("rbind", parseArgs(args)))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
60 args <- as.list(as.character(argsDF$V2))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
61 names(args) <- argsDF$V1
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
62
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
63 return(args)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
64 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
65
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
66 str2bool <- function(x){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
67 if (any(is.element(c("t","true"),tolower(x)))){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
68 return (TRUE)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
69 }else if (any(is.element(c("f","false"),tolower(x)))){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
70 return (FALSE)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
71 }else{
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
72 return(NULL)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
73 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
74 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
75
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
76 #take data frame, return data frame
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
77 split_ids_per_line <- function(line,ncol){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
78
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
79 #print (line)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
80 header = colnames(line)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
81 line[ncol] = gsub("[[:blank:]]|\u00A0","",line[ncol])
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
82
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
83 if (length(unlist(strsplit(as.character(line[ncol]),";")))>1) {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
84 if (length(line)==1 ) {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
85 lines = as.data.frame(unlist(strsplit(as.character(line[ncol]),";")),stringsAsFactors = F)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
86 } else {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
87 if (ncol==1) { #first column
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
88 lines = suppressWarnings(cbind(unlist(strsplit(as.character(line[ncol]),";")), line[2:length(line)]))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
89 } else if (ncol==length(line)) { #last column
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
90 lines = suppressWarnings(cbind(line[1:ncol-1],unlist(strsplit(as.character(line[ncol]),";"))))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
91 } else {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
92 lines = suppressWarnings(cbind(line[1:ncol-1], unlist(strsplit(as.character(line[ncol]),";"),use.names = F), line[(ncol+1):length(line)]))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
93 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
94 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
95 colnames(lines)=header
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
96 return(lines)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
97 } else {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
98 return(line)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
99 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
100 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
101
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
102 #create new lines if there's more than one id per cell in the columns in order to have only one id per line
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
103 one_id_one_line <-function(tab,ncol){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
104
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
105 if (ncol(tab)>1){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
106
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
107 tab[,ncol] = sapply(tab[,ncol],function(x) gsub("[[:blank:]]","",x))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
108 header=colnames(tab)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
109 res=as.data.frame(matrix(ncol=ncol(tab),nrow=0))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
110 for (i in 1:nrow(tab) ) {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
111 lines = split_ids_per_line(tab[i,],ncol)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
112 res = rbind(res,lines)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
113 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
114 }else {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
115 res = unlist(sapply(tab[,1],function(x) strsplit(x,";")),use.names = F)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
116 res = data.frame(res[which(!is.na(res[res!=""]))],stringsAsFactors = F)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
117 colnames(res)=colnames(tab)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
118 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
119 return(res)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
120 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
121
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
122 # Get information from neXtProt
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
123 get_nextprot_info <- function(nextprot,input,pc_features,localization,diseases_info){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
124 if(diseases_info){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
125 cols = c("NextprotID",pc_features,localization,"Diseases")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
126 } else {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
127 cols = c("NextprotID",pc_features,localization)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
128 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
129
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
130 cols=cols[cols!="None"]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
131 info = nextprot[match(input,nextprot$NextprotID),cols]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
132 return(info)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
133 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
134
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
135 protein_features = function() {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
136
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
137 args <- get_args()
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
138
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
139 #save(args,file="/home/dchristiany/proteore_project/ProteoRE/tools/add_human_protein_features/args.rda")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
140 #load("/home/dchristiany/proteore_project/ProteoRE/tools/add_human_protein_features/args.rda")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
141
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
142 #setting variables
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
143 inputtype = args$inputtype
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
144 if (inputtype == "copy_paste") {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
145 input = get_list_from_cp(args$input)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
146 file = data.frame(input,stringsAsFactors = F)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
147 ncol=1
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
148 } else if (inputtype == "file") {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
149 filename = args$input
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
150 ncol = args$column
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
151 # Check ncol
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
152 if (! as.numeric(gsub("c", "", ncol)) %% 1 == 0) {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
153 stop("Please enter an integer for level")
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
154 } else {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
155 ncol = as.numeric(gsub("c", "", ncol))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
156 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
157
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
158 header = str2bool(args$header)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
159 file = read_file(filename, header) # Get file content
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
160 if (any(grep(";",file[,ncol]))) {file = one_id_one_line(file,ncol)}
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
161 if (args$type == "NextprotID" && ! "NextprotID" %in% colnames(file)) { colnames(file)[ncol] <- "NextprotID"
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
162 } else if (args$type == "NextprotID" && "NextprotID" %in% colnames(file) && match("NextprotID",colnames(file))!=ncol ) {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
163 colnames(file)[match("NextprotID",colnames(file))] <- "old_NextprotID"
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
164 colnames(file)[ncol] = "NextprotID"
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
165 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
166 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
167
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
168 # Read reference file
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
169 nextprot = read_file(args$nextprot,T)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
170
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
171 # Parse arguments
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
172 id_type = args$type
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
173 pc_features = strsplit(args$pc_features, ",")[[1]]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
174 localization = strsplit(args$localization, ",")[[1]]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
175 diseases_info = str2bool(args$diseases_info)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
176 output = args$output
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
177
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
178 # Change the sample ids if they are Uniprot_AC ids to be able to match them with
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
179 # Nextprot data
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
180 if (id_type=="Uniprot_AC"){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
181 NextprotID = gsub("^NX_$","",gsub("^","NX_",file[,ncol]))
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
182 file = cbind(file,NextprotID)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
183 if (inputtype=="copy_paste") {colnames(file)[1]="Uniprot-AC"}
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
184 ncol=ncol(file)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
185 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
186 NextprotID = file[,ncol]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
187
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
188 #Select user input protein ids in nextprot
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
189 #NextprotID = unique(NextprotID[which(!is.na(NextprotID[NextprotID!=""]))])
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
190 if (all(!NextprotID %in% nextprot[,1])){
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
191 write.table("None of the input ids can be found in Nextprot",file=output,sep="\t",quote=FALSE,col.names=TRUE,row.names=FALSE)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
192 } else {
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
193 res <- get_nextprot_info(nextprot,NextprotID,pc_features,localization,diseases_info)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
194 res = res[!duplicated(res$NextprotID),]
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
195 output_content = merge(file, res,by.x=ncol,by.y="NextprotID",incomparables = NA,all.x=T)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
196 output_content = order_columns(output_content,ncol,id_type,file)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
197 output_content <- as.data.frame(apply(output_content, c(1,2), function(x) gsub("^$|^ $", NA, x))) #convert "" et " " to NA
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
198 write.table(output_content, output, row.names = FALSE, sep = "\t", quote = FALSE)
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
199 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
200
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
201 }
0b46a7aead62 planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff changeset
202 protein_features()