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