annotate id_converter_UniProt.R @ 0:f2d0b13d9615 draft

planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
author proteore
date Fri, 16 Feb 2018 03:16:29 -0500
parents
children 134949593a3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
1 # Read file and return file content as data.frame
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
2 readfile = function(filename, header) {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
3 if (header == "true") {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
4 # Read only first line of the file as header:
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
5 headers <- read.table(filename, nrows = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
6 #Read the data of the files (skipping the first row)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
7 file <- read.table(filename, skip = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
8 # Remove empty rows
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
9 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
10 #And assign the header to the data
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
11 names(file) <- headers
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
12 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
13 else {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
14 file <- read.table(filename, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
15 # Remove empty rows
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
16 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
17 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
18 return(file)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
19 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
20
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
21 # Mapping IDs using file built from
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
22 # - HUMAN_9606_idmapping_selected.tab
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
23 # Tarball downloaded from ftp://ftp.uniprot.org/pub/databases/uniprot/current_release/knowledgebase/idmapping/by_organism/
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
24 # - nextprot_ac_list_all.txt
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
25 # Downloaded from ftp://ftp.nextprot.org/pub/current_release/ac_lists/
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
26 # Available databases:
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
27 # UNIPROT_AC: Uniprot accession number (e.g. P31946)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
28 # UNIPROT_ID: Uniprot identifiers (e.g 1433B_HUMAN)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
29 # GeneID_EntrezGene: Entrez gene ID (serie of digit) (e.g. 7529)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
30 # RefSeq: RefSeq (NCBI) protein (e.g. NP_003395.1; NP_647539.1; XP_016883528.1)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
31 # GI_number: GI (NCBI GI number) ID (serie of digits) assigned to each sequence record processed by NCBI (e.g; 21328448; 377656701; 67464627; 78101741)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
32 # PDB: Protein DataBank Identifiers (e.g. 2BR9:A; 3UAL:A; 3UBW:A)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
33 # GO_ID: GOterms (Gene Ontology) Identifiers (e.g. GO:0070062; GO:0005925; GO:0042470; GO:0016020; GO:0005739; GO:0005634)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
34 # PIR: Protein Information Resource ID (e.g. S34755)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
35 # OMIM: OMIM (Online Mendelian Inheritance in Man database) ID (serie of digits) (e.g: 601289)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
36 # UniGene: Unigene Identifier (e.g. Hs.643544)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
37 # Ensembl_ENSG: Ensembl gene identifiers (e.g. ENSG00000166913)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
38 # Ensembl_ENST: Ensembl transcript identifiers (e.g. ENST00000353703; ENST00000372839)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
39 # Ensembl_ENSP: Ensembl protein identifiers (e.g. ENSP00000300161; ENSP00000361930)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
40
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
41 mapping = function() {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
42 # Extract arguments
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
43 args = commandArgs(trailingOnly = TRUE)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
44 #print(args)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
45 if (length(args) != 6) {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
46 stop("Not enough/Too many arguments", call. = FALSE)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
47 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
48 else {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
49 input_id_type = args[1]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
50 list_id = args[2]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
51 list_id_input_type = args[3]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
52 options = strsplit(args[4], ",")[[1]]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
53 output = args[5]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
54 human_id_mapping_file = args[6]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
55
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
56 # Extract ID maps
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
57 human_id_map = read.table(human_id_mapping_file, header = TRUE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings = "")
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
58
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
59 # Extract input IDs
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
60 if (list_id_input_type == "list") {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
61 list_id = strsplit(args[2], " ")[[1]]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
62 # Remove isoform accession number (e.g. "-2")
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
63 list_id = gsub("-.+", "", list_id)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
64 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
65 else if (list_id_input_type == "file") {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
66 filename = as.character(strsplit(list_id, ",")[[1]][1])
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
67 column_number = as.numeric(gsub("c", "" ,strsplit(list_id, ",")[[1]][2]))
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
68 header = strsplit(list_id, ",")[[1]][3]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
69 file_all = readfile(filename, header)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
70 print(class(file_all))
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
71 str(file_all)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
72 print(class(file_all[,1]))
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
73 list_id = c()
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
74 list_id = sapply(strsplit(file_all[,column_number], ";"), "[", 1)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
75 # Remove isoform accession number (e.g. "-2")
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
76 list_id = gsub("-.+", "", list_id)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
77 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
78 names = c()
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
79
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
80 # Map IDs
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
81 res = matrix(nrow=length(list_id), ncol=0)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
82
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
83 for (opt in options) {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
84 names = c(names, opt)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
85 mapped = human_id_map[match(list_id, human_id_map[input_id_type][,]),][opt][,]
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
86 res = cbind(res, matrix(mapped))
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
87 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
88
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
89 # Write output
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
90 if (list_id_input_type == "list") {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
91 res = cbind(as.matrix(list_id), res)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
92 names = c(input_id_type, names)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
93 colnames(res) = names
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
94 write.table(res, output, row.names = FALSE, sep = "\t", quote = FALSE)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
95 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
96 else if (list_id_input_type == "file") {
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
97 names(res) = options
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
98 names = c(names(file_all), names)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
99 output_content = cbind(file_all, res)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
100 colnames(output_content) = names
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
101 write.table(output_content, output, row.names = FALSE, sep = "\t", quote = FALSE)
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
102 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
103 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
104 }
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
105
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
106 mapping()
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
107
f2d0b13d9615 planemo upload commit 5774fd6a5a746f36f6bf4671a51a39ea2b978300-dirty
proteore
parents:
diff changeset
108 #Rscript id_converter_UniProt.R "UniProt.AC" "test-data/UnipIDs.txt,c1,false" "file" "Ensembl_PRO,Ensembl,neXtProt_ID" "test-data/output.txt" ../../utils/mapping_file.txt