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