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