annotate get_expression_profiles.R @ 7:6a9db2cc54de draft default tip

planemo upload commit fb27a6b5de5cd7b269a41be3c85c593b77aa1b18-dirty
author proteore
date Thu, 27 Jun 2019 04:14:10 -0400
parents 5cd79aa7aac9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
1 # Read file and return file content as data.frame
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
2 read_file <- function(path,header){
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
3 file <- try(read.csv(path,header=header, sep="\t",stringsAsFactors = FALSE, quote="\"", check.names = F),silent=TRUE)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
4 if (inherits(file,"try-error")){
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
5 stop("File not found !")
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
6 }else{
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
7 return(file)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
8 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
9 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
10
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
11 str2bool <- function(x){
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
12 if (any(is.element(c("t","true"),tolower(x)))){
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
13 return (TRUE)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
14 }else if (any(is.element(c("f","false"),tolower(x)))){
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
15 return (FALSE)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
16 }else{
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
17 return(NULL)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
18 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
19 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
20
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
21 # input has to be a list of IDs in ENSG format
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
22 # tissue is one of unique(HPA.normal.tissue$Tissue)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
23 # level is one, or several, or 0 (=ALL) of "Not detected", "Medium", "High", "Low"
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
24 # reliability is one, or several, or 0 (=ALL) of "Approved", "Supported", "Uncertain"
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
25 annot.HPAnorm<-function(input, HPA_normal_tissue, tissue, level, reliability, not_mapped_option) {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
26 dat <- subset(HPA_normal_tissue, Gene %in% input)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
27 res.Tissue<-subset(dat, Tissue %in% tissue)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
28 res.Level<-subset(res.Tissue, Level %in% level)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
29 res.Rel<-subset(res.Level, Reliability %in% reliability)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
30
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
31 if (not_mapped_option) {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
32 if (length(setdiff(intersect(input, unique(dat$Gene)), unique(res.Rel$Gene)))>0) {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
33 not_match_IDs <- matrix(setdiff(intersect(input, unique(dat$Gene)), unique(res.Rel$Gene)), ncol = 1, nrow = length(setdiff(intersect(input, unique(dat$Gene)), unique(res.Rel$Gene))))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
34 not.match <- matrix("no match", ncol = ncol(HPA_normal_tissue) - 1, nrow = length(not_match_IDs))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
35 not.match <- cbind(not_match_IDs, unname(not.match))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
36 colnames(not.match) <- colnames(HPA_normal_tissue)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
37 res <- rbind(res.Rel, not.match)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
38 } else {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
39 res <- res.Rel
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
40 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
41
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
42 if (length(setdiff(input, unique(dat$Gene)))>0) {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
43 not.mapped <- matrix(ncol = ncol(HPA_normal_tissue) - 1, nrow = length(setdiff(input, unique(dat$Gene))))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
44 not.mapped <- cbind(matrix(setdiff(input, unique(dat$Gene)), ncol = 1, nrow = length(setdiff(input, unique(dat$Gene)))), unname(not.mapped))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
45 colnames(not.mapped) <- colnames(HPA_normal_tissue)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
46 res <- rbind(res, not.mapped)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
47 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
48
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
49 } else {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
50 res <- res.Rel
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
51 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
52
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
53 return(res)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
54
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
55 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
56
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
57 annot.HPAcancer<-function(input, HPA_cancer_tissue, cancer, not_mapped_option) {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
58 dat <- subset(HPA_cancer_tissue, Gene %in% input)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
59 res.Cancer<-subset(dat, Cancer %in% cancer)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
60
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
61 if (not_mapped_option) {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
62 not.mapped <- matrix(ncol=ncol(HPA_cancer_tissue)-1, nrow=length(setdiff(input, unique(dat$Gene))))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
63 not.mapped <- cbind(matrix(setdiff(input, unique(dat$Gene)), ncol = 1, nrow = length(setdiff(input, unique(dat$Gene)))), unname(not.mapped))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
64 colnames(not.mapped) <- colnames(HPA_cancer_tissue)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
65 res <- rbind(res.Cancer, not.mapped)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
66 } else {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
67 res <- res.Cancer
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
68 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
69 return(res)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
70 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
71
4
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
72 clean_ids <- function(ids){
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
73
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
74 ids = gsub(" ","",ids)
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
75 ids = ids[which(ids!="")]
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
76 ids = ids[which(ids!="NA")]
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
77 ids = ids[!is.na(ids)]
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
78
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
79 return(ids)
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
80 }
3
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
81
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
82 main <- function() {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
83 args <- commandArgs(TRUE)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
84 if(length(args)<1) {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
85 args <- c("--help")
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
86 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
87
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
88 # Help section
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
89 if("--help" %in% args) {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
90 cat("Selection and Annotation HPA
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
91 Arguments:
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
92 --ref_file: HPA normal/cancer tissue file path
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
93 --input_type: type of input (list of id or filename)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
94 --input: list of IDs in ENSG format
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
95 --column_number: the column number which you would like to apply...
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
96 --header: true/false if your file contains a header
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
97 --atlas: normal/cancer
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
98 if normal:
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
99 --tissue: list of tissues
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
100 --level: Not detected, Low, Medium, High
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
101 --reliability: Supportive, Uncertain
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
102 if cancer:
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
103 --cancer: Cancer tissues
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
104 --not_mapped: true/false if your output file should contain not-mapped and not-match IDs
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
105 --output: output filename \n")
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
106 q(save="no")
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
107 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
108
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
109 # Parse arguments
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
110 parseArgs <- function(x) strsplit(sub("^--", "", x), "=")
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
111 argsDF <- as.data.frame(do.call("rbind", parseArgs(args)))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
112 args <- as.list(as.character(argsDF$V2))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
113 names(args) <- argsDF$V1
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
114
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
115 #save(args,file = "/home/dchristiany/proteore_project/ProteoRE/tools/Get_expression_profiles/args.rda")
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
116 #load("/home/dchristiany/proteore_project/ProteoRE/tools/Get_expression_profiles/args.rda")
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
117
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
118 # Extract input
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
119 input_type = args$input_type
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
120 if (input_type == "list") {
4
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
121 ids = unlist(strsplit(strsplit(args$input, "[ \t\n]+")[[1]],";"))
3
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
122 } else if (input_type == "file") {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
123 filename = args$input
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
124 column_number = as.numeric(gsub("c", "" ,args$column_number))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
125 header = str2bool(args$header)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
126 file = read_file(filename, header)
4
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
127 ids = unlist(strsplit(file[,column_number], ";"))
3
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
128 }
4
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
129 #filter ids
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
130 ids = clean_ids(ids)
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
131
3
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
132 # Read reference file
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
133 reference_file = read_file(args$ref_file, TRUE)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
134
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
135 # Extract other options
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
136 atlas = args$atlas
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
137 not_mapped_option = str2bool(args$not_mapped)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
138 if (atlas=="normal") {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
139 tissue = strsplit(args$tissue, ",")[[1]]
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
140 level = strsplit(args$level, ",")[[1]]
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
141 reliability = strsplit(args$reliability, ",")[[1]]
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
142 # Calculation
4
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
143 res = annot.HPAnorm(ids, reference_file, tissue, level, reliability, not_mapped_option)
3
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
144 } else if (atlas=="cancer") {
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
145 cancer = strsplit(args$cancer, ",")[[1]]
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
146 # Calculation
4
5cd79aa7aac9 planemo upload commit ed42daf54e6d0fa2a693b501c7ebca4efe4d95e3-dirty
proteore
parents: 3
diff changeset
147 res = annot.HPAcancer(ids, reference_file, cancer, not_mapped_option)
3
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
148 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
149
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
150 # Write output
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
151 output = args$output
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
152 res <- apply(res, c(1,2), function(x) gsub("^$|^ $", NA, x))
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
153 write.table(res, output, sep = "\t", quote = FALSE, row.names = FALSE)
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
154 }
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
155
3bedd074c485 planemo upload commit c6e1fd1f68e81ce9eea6ad66adee21070f2893ef-dirty
proteore
parents:
diff changeset
156 main()