Mercurial > repos > proteore > proteore_prot_features
annotate add_protein_features.R @ 18:0a9ae3d7dbf2 draft default tip
"planemo upload commit 7afd4b3ee25f024257ccbac6e51076d25b2a04e7"
author | proteore |
---|---|
date | Thu, 20 Aug 2020 03:09:52 -0400 |
parents | 7caa90759aba |
children |
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){ |
12
1a4cfa7a3a27
planemo upload commit 77279e994f5751c6cd9aa165aa0604db3d241271-dirty
proteore
parents:
11
diff
changeset
|
3 file <- try(read.csv(path,header=header, sep="\t",stringsAsFactors = FALSE, quote="", check.names = F),silent=TRUE) |
9
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){ |
16
7caa90759aba
planemo upload commit 4ba1ebe7b3f5e3fabf78b5fed7ed0b92e2cbf9e5-dirty
proteore
parents:
13
diff
changeset
|
23 list = gsub(";","\t",list) |
9
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
24 list = strsplit(list, "[ \t\n]+")[[1]] |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
25 list = gsub("NA","",list) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
26 list = list[list != ""] #remove empty entry |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
27 list = gsub("-.+", "", list) #Remove isoform accession number (e.g. "-2") |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
28 return(list) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
29 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
30 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
31 get_args <- function(){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
32 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
33 ## Collect arguments |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
34 args <- commandArgs(TRUE) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
35 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
36 ## Default setting when no arguments passed |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
37 if(length(args) < 1) { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
38 args <- c("--help") |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
39 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
40 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
41 ## Help section |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
42 if("--help" %in% args) { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
43 cat("Selection and Annotation HPA |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
44 Arguments: |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
45 --inputtype: type of input (list of id or filename) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
46 --input: input |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
47 --nextprot: path to nextprot information file |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
48 --column: the column number which you would like to apply... |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
49 --header: true/false if your file contains a header |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
50 --type: the type of input IDs (Uniprot_AC/EntrezID) |
18
0a9ae3d7dbf2
"planemo upload commit 7afd4b3ee25f024257ccbac6e51076d25b2a04e7"
proteore
parents:
16
diff
changeset
|
51 --pc_features: IsoPoint,SeqLength,MW,Chr,SubcellLocations,Diseases,protein_name,function,post_trans_mod,protein_family,pathway |
9
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
52 --output: text output filename \n") |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
53 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
54 q(save="no") |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
55 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
56 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
57 parseArgs <- function(x) strsplit(sub("^--", "", x), "=") |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
58 argsDF <- as.data.frame(do.call("rbind", parseArgs(args))) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
59 args <- as.list(as.character(argsDF$V2)) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
60 names(args) <- argsDF$V1 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
61 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
62 return(args) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
63 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
64 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
65 str2bool <- function(x){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
66 if (any(is.element(c("t","true"),tolower(x)))){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
67 return (TRUE) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
68 }else if (any(is.element(c("f","false"),tolower(x)))){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
69 return (FALSE) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
70 }else{ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
71 return(NULL) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
72 } |
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 #take data frame, return data frame |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
76 split_ids_per_line <- function(line,ncol){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
77 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
78 #print (line) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
79 header = colnames(line) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
80 line[ncol] = gsub("[[:blank:]]|\u00A0","",line[ncol]) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
81 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
82 if (length(unlist(strsplit(as.character(line[ncol]),";")))>1) { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
83 if (length(line)==1 ) { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
84 lines = as.data.frame(unlist(strsplit(as.character(line[ncol]),";")),stringsAsFactors = F) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
85 } else { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
86 if (ncol==1) { #first column |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
87 lines = suppressWarnings(cbind(unlist(strsplit(as.character(line[ncol]),";")), line[2:length(line)])) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
88 } else if (ncol==length(line)) { #last column |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
89 lines = suppressWarnings(cbind(line[1:ncol-1],unlist(strsplit(as.character(line[ncol]),";")))) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
90 } else { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
91 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
|
92 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
93 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
94 colnames(lines)=header |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
95 return(lines) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
96 } else { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
97 return(line) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
98 } |
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 #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
|
102 one_id_one_line <-function(tab,ncol){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
103 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
104 if (ncol(tab)>1){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
105 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
106 tab[,ncol] = sapply(tab[,ncol],function(x) gsub("[[:blank:]]","",x)) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
107 header=colnames(tab) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
108 res=as.data.frame(matrix(ncol=ncol(tab),nrow=0)) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
109 for (i in 1:nrow(tab) ) { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
110 lines = split_ids_per_line(tab[i,],ncol) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
111 res = rbind(res,lines) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
112 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
113 }else { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
114 res = unlist(sapply(tab[,1],function(x) strsplit(x,";")),use.names = F) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
115 res = data.frame(res[which(!is.na(res[res!=""]))],stringsAsFactors = F) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
116 colnames(res)=colnames(tab) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
117 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
118 return(res) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
119 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
120 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
121 # Get information from neXtProt |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
122 get_nextprot_info <- function(nextprot,input,pc_features,localization,diseases_info){ |
18
0a9ae3d7dbf2
"planemo upload commit 7afd4b3ee25f024257ccbac6e51076d25b2a04e7"
proteore
parents:
16
diff
changeset
|
123 cols = c("NextprotID",pc_features) |
9
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
124 cols=cols[cols!="None"] |
18
0a9ae3d7dbf2
"planemo upload commit 7afd4b3ee25f024257ccbac6e51076d25b2a04e7"
proteore
parents:
16
diff
changeset
|
125 info = nextprot[match(input,nextprot$NextprotID),intersect(colnames(nextprot),cols)] |
9
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
126 return(info) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
127 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
128 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
129 protein_features = function() { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
130 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
131 args <- get_args() |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
132 |
11
8df559ad14a7
planemo upload commit 27f7b6a4a0139ca47ae874fe2fe6de4bd40ffbcf-dirty
proteore
parents:
9
diff
changeset
|
133 #save(args,file="/home/dchristiany/proteore_project/ProteoRE/tools/add_protein_features/args.rda") |
8df559ad14a7
planemo upload commit 27f7b6a4a0139ca47ae874fe2fe6de4bd40ffbcf-dirty
proteore
parents:
9
diff
changeset
|
134 #load("/home/dchristiany/proteore_project/ProteoRE/tools/add_protein_features/args.rda") |
9
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
135 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
136 #setting variables |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
137 inputtype = args$inputtype |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
138 if (inputtype == "copy_paste") { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
139 input = get_list_from_cp(args$input) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
140 file = data.frame(input,stringsAsFactors = F) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
141 ncol=1 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
142 } else if (inputtype == "file") { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
143 filename = args$input |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
144 ncol = args$column |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
145 # Check ncol |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
146 if (! as.numeric(gsub("c", "", ncol)) %% 1 == 0) { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
147 stop("Please enter an integer for level") |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
148 } else { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
149 ncol = as.numeric(gsub("c", "", ncol)) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
150 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
151 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
152 header = str2bool(args$header) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
153 file = read_file(filename, header) # Get file content |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
154 if (any(grep(";",file[,ncol]))) {file = one_id_one_line(file,ncol)} |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
155 if (args$type == "NextprotID" && ! "NextprotID" %in% colnames(file)) { colnames(file)[ncol] <- "NextprotID" |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
156 } else if (args$type == "NextprotID" && "NextprotID" %in% colnames(file) && match("NextprotID",colnames(file))!=ncol ) { |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
157 colnames(file)[match("NextprotID",colnames(file))] <- "old_NextprotID" |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
158 colnames(file)[ncol] = "NextprotID" |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
159 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
160 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
161 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
162 # Read reference file |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
163 nextprot = read_file(args$nextprot,T) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
164 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
165 # Parse arguments |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
166 id_type = args$type |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
167 pc_features = strsplit(args$pc_features, ",")[[1]] |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
168 output = args$output |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
169 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
170 # 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
|
171 # Nextprot data |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
172 if (id_type=="Uniprot_AC"){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
173 NextprotID = gsub("^NX_$","",gsub("^","NX_",file[,ncol])) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
174 file = cbind(file,NextprotID) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
175 if (inputtype=="copy_paste") {colnames(file)[1]="Uniprot-AC"} |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
176 ncol=ncol(file) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
177 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
178 NextprotID = file[,ncol] |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
179 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
180 #Select user input protein ids in nextprot |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
181 #NextprotID = unique(NextprotID[which(!is.na(NextprotID[NextprotID!=""]))]) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
182 if (all(!NextprotID %in% nextprot[,1])){ |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
183 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
|
184 } else { |
18
0a9ae3d7dbf2
"planemo upload commit 7afd4b3ee25f024257ccbac6e51076d25b2a04e7"
proteore
parents:
16
diff
changeset
|
185 res <- get_nextprot_info(nextprot,NextprotID,pc_features) |
9
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
186 res = res[!duplicated(res$NextprotID),] |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
187 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
|
188 output_content = order_columns(output_content,ncol,id_type,file) |
13
0116d444d21f
planemo upload commit a957a9b76923f071837aa5d86c1ee2271ebd34fd-dirty
proteore
parents:
12
diff
changeset
|
189 if (id_type=="Uniprot_AC"){output_content = output_content[,-which(colnames(output_content)=="NextprotID")]} #remove nextprotID column |
9
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
190 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
|
191 write.table(output_content, output, row.names = FALSE, sep = "\t", quote = FALSE) |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
192 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
193 |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
194 } |
0b46a7aead62
planemo upload commit eb7450f36863f02f036cbc52bf5525d68f22bd9e
proteore
parents:
diff
changeset
|
195 protein_features() |