Mercurial > repos > proteore > proteore_prot_features_mouse
annotate add_protein_features_mouse.R @ 0:b9f57cba3172 draft
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
| author | proteore |
|---|---|
| date | Tue, 14 May 2019 09:47:13 -0400 |
| parents | |
| children |
| rev | line source |
|---|---|
|
0
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
1 options(warn=-1) #TURN OFF WARNINGS !!!!!! |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
2 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
3 # Read file and return file content as data.frame |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
4 order_columns <- function (df,ncol,file){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
5 if (ncol==1){ #already at the right position |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
6 return (df) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
7 } else { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
8 df = df[,c(2:ncol,1,(ncol+1):dim.data.frame(df)[2])] |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
9 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
10 return (df) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
11 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
12 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
13 get_list_from_cp <-function(list){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
14 list = gsub(";","\t",list) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
15 list = strsplit(list, "[ \t\n]+")[[1]] |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
16 list = gsub("NA","",list) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
17 list = list[list != ""] #remove empty entry |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
18 list = gsub("-.+", "", list) #Remove isoform accession number (e.g. "-2") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
19 return(list) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
20 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
21 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
22 check_ids <- function(vector,type) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
23 uniprot_pattern = "^([OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9]([A-Z][A-Z0-9]{2}[0-9]){1,2})$" |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
24 entrez_id = "^([0-9]+|[A-Z]{1,2}_[0-9]+|[A-Z]{1,2}_[A-Z]{1,4}[0-9]+)$" |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
25 if (type == "entrez") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
26 return(grepl(entrez_id,vector)) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
27 else if (type == "uniprot") { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
28 return(grepl(uniprot_pattern,vector)) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
29 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
30 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
31 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
32 get_args <- function(){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
33 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
34 ## Collect arguments |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
35 args <- commandArgs(TRUE) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
36 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
37 ## Default setting when no arguments passed |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
38 if(length(args) < 1) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
39 args <- c("--help") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
40 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
41 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
42 ## Help section |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
43 if("--help" %in% args) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
44 cat("Selection and Annotation HPA |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
45 Arguments: |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
46 --inputtype: type of input (list of id or filename) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
47 --input: input |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
48 --uniprot_file: path to uniprot reference file |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
49 --column: the column number which you would like to apply... |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
50 --header: true/false if your file contains a header |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
51 --pc_features: IsoPoint,SeqLength,MW |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
52 --output: text output filename \n") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
53 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
54 q(save="no") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
55 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
56 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
57 parseArgs <- function(x) strsplit(sub("^--", "", x), "=") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
58 argsDF <- as.data.frame(do.call("rbind", parseArgs(args))) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
59 args <- as.list(as.character(argsDF$V2)) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
60 names(args) <- argsDF$V1 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
61 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
62 return(args) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
63 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
64 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
65 str2bool <- function(x){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
66 if (any(is.element(c("t","true"),tolower(x)))){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
67 return (TRUE) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
68 }else if (any(is.element(c("f","false"),tolower(x)))){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
69 return (FALSE) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
70 }else{ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
71 return(NULL) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
72 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
73 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
74 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
75 #take data frame, return data frame |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
76 split_ids_per_line <- function(line,ncol){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
77 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
78 #print (line) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
79 header = colnames(line) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
80 line[ncol] = gsub("[[:blank:]]|\u00A0","",line[ncol]) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
81 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
82 if (length(unlist(strsplit(as.character(line[ncol]),";")))>1) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
83 if (length(line)==1 ) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
84 lines = as.data.frame(unlist(strsplit(as.character(line[ncol]),";")),stringsAsFactors = F) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
85 } else { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
86 if (ncol==1) { #first column |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
87 lines = suppressWarnings(cbind(unlist(strsplit(as.character(line[ncol]),";")), line[2:length(line)])) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
88 } else if (ncol==length(line)) { #last column |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
89 lines = suppressWarnings(cbind(line[1:ncol-1],unlist(strsplit(as.character(line[ncol]),";")))) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
90 } else { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
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)])) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
92 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
93 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
94 colnames(lines)=header |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
95 return(lines) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
96 } else { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
97 return(line) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
98 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
99 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
100 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
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 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
102 one_id_one_line <-function(tab,ncol){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
103 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
104 if (ncol(tab)>1){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
105 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
106 tab[,ncol] = sapply(tab[,ncol],function(x) gsub("[[:blank:]]","",x)) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
107 header=colnames(tab) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
108 res=as.data.frame(matrix(ncol=ncol(tab),nrow=0)) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
109 for (i in 1:nrow(tab) ) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
110 lines = split_ids_per_line(tab[i,],ncol) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
111 res = rbind(res,lines) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
112 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
113 }else { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
114 res = unlist(sapply(tab[,1],function(x) strsplit(x,";")),use.names = F) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
115 res = data.frame(res[which(!is.na(res[res!=""]))],stringsAsFactors = F) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
116 colnames(res)=colnames(tab) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
117 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
118 return(res) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
119 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
120 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
121 # Get information from neXtProt |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
122 get_uniprot_info <- function(ids,pc_features,uniprot_file){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
123 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
124 cols = c("Entry",pc_features) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
125 cols=cols[cols!="None"] |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
126 info = uniprot_file[match(ids,uniprot_file$Entry),cols] |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
127 colnames(info)[1]="UniProt-AC" |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
128 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
129 return(info) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
130 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
131 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
132 main <- function() { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
133 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
134 args <- get_args() |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
135 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
136 #save(args,file="/home/dchristiany/proteore_project/ProteoRE/tools/add_protein_features_mouse/args.rda") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
137 #load("/home/dchristiany/proteore_project/ProteoRE/tools/add_protein_features_mouse/args.rda") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
138 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
139 #setting variables |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
140 inputtype = args$inputtype |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
141 if (inputtype == "copy_paste") { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
142 ids = get_list_from_cp(args$input) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
143 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
144 #Check for UniProt-AC ids |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
145 if (all(!check_ids(ids,'uniprot'))){ |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
146 stop ("No UniProt-AC found in ids.") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
147 } else if (any(!check_ids(ids,'uniprot'))) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
148 print ('Some ids in ids are not uniprot-AC:') |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
149 print (ids[which(!check_ids(ids,'uniprot'))]) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
150 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
151 file = data.frame(ids,stringsAsFactors = F) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
152 ncol=1 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
153 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
154 } else if (inputtype == "file") { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
155 filename = args$input |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
156 ncol = args$column |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
157 # Check ncol |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
158 if (! as.numeric(gsub("c", "", ncol)) %% 1 == 0) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
159 stop("Please enter an integer for level") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
160 } else { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
161 ncol = as.numeric(gsub("c", "", ncol)) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
162 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
163 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
164 header = str2bool(args$header) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
165 file = read.table(filename, header = header , sep = "\t", fill = TRUE, stringsAsFactors = FALSE, quote="", check.names = F, comment.char = "") # Get file content |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
166 if (any(grep(";",file[,ncol]))) {file = one_id_one_line(file,ncol)} |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
167 ids=file[,ncol] |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
168 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
169 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
170 # Read reference file |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
171 uniprot_file <- read.table(args$uniprot_file, header = TRUE , sep = "\t", fill = TRUE,stringsAsFactors = FALSE, quote="", check.names = F, comment.char = "") |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
172 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
173 # Parse arguments |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
174 pc_features = gsub("__ob__","[",gsub("__cb__","]",strsplit(args$pc_features, ",")[[1]])) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
175 output = args$output |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
176 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
177 #output file |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
178 res <- get_uniprot_info(ids,pc_features,uniprot_file) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
179 res = res[!duplicated(res$`UniProt-AC`),] |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
180 output_content = merge(file, res,by.x=ncol,by.y="UniProt-AC",incomparables = NA,all.x=T) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
181 output_content = order_columns(output_content,ncol,file) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
182 output_content <- as.data.frame(apply(output_content, c(1,2), function(x) gsub("^$|^ $", NA, x))) #convert "" et " " to NA |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
183 write.table(output_content, output, row.names = FALSE, sep = "\t", quote = FALSE) |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
184 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
185 } |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
186 |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
187 if(!interactive()) { |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
188 main() |
|
b9f57cba3172
planemo upload commit e507ac5916a604c5fd7fd2af8074cc2fbb6707fe-dirty
proteore
parents:
diff
changeset
|
189 } |
