Mercurial > repos > proteore > proteore_topgo
comparison enrichment_v3.R @ 8:ddaa0c318d65 draft
planemo upload commit d23909db127a655212b79d6826033889812f59b5-dirty
author | proteore |
---|---|
date | Fri, 23 Mar 2018 10:43:32 -0400 |
parents | 829cbdb71efa |
children | 70c0c8757f5f |
comparison
equal
deleted
inserted
replaced
7:1b2b81169c66 | 8:ddaa0c318d65 |
---|---|
30 # results file, barplot.png for the barplot image file and dotplot.png for the | 30 # results file, barplot.png for the barplot image file and dotplot.png for the |
31 # dotplot image file | 31 # dotplot image file |
32 | 32 |
33 | 33 |
34 # loading topGO library | 34 # loading topGO library |
35 library(topGO) | 35 library(topGO) |
36 | |
37 # Read file and return file content as data.frame | |
38 readfile = function(filename, header) { | |
39 if (header == "true") { | |
40 # Read only first line of the file as header: | |
41 headers <- read.table(filename, nrows = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "") | |
42 #Read the data of the files (skipping the first row) | |
43 file <- read.table(filename, skip = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "") | |
44 # Remove empty rows | |
45 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE] | |
46 #And assign the header to the data | |
47 names(file) <- headers | |
48 } | |
49 else { | |
50 file <- read.table(filename, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "") | |
51 # Remove empty rows | |
52 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE] | |
53 } | |
54 return(file) | |
55 } | |
36 | 56 |
37 '%!in%' <- function(x,y)!('%in%'(x,y)) | 57 '%!in%' <- function(x,y)!('%in%'(x,y)) |
38 | 58 |
39 | 59 |
40 # Parse command line arguments | 60 # Parse command line arguments |
48 listoptions <- unlist(strsplit(hh,'--'))[-1] | 68 listoptions <- unlist(strsplit(hh,'--'))[-1] |
49 | 69 |
50 # for each input, split the arguments with blank space as separator, unlist, | 70 # for each input, split the arguments with blank space as separator, unlist, |
51 # and delete the first element which is the input name (e.g --inputtype) | 71 # and delete the first element which is the input name (e.g --inputtype) |
52 options.args <- sapply(listoptions,function(x){ | 72 options.args <- sapply(listoptions,function(x){ |
53 unlist(strsplit(x, ' '))[-1] | 73 unlist(strsplit(x, '[ \t\n]+'))[-1] |
54 }) | 74 }) |
55 # same as the step above, except that only the names are kept | 75 # same as the step above, except that only the names are kept |
56 options.names <- sapply(listoptions,function(x){ | 76 options.names <- sapply(listoptions,function(x){ |
57 option <- unlist(strsplit(x, ' '))[1] | 77 option <- unlist(strsplit(x, '[ \t\n]+'))[1] |
58 }) | 78 }) |
59 names(options.args) <- unlist(options.names) | 79 names(options.args) <- unlist(options.names) |
60 | 80 |
61 | 81 |
62 if (length(options.args) != 12) { | 82 if (length(options.args) != 12) { |
81 sample = sample[,column] | 101 sample = sample[,column] |
82 } | 102 } |
83 if (typeinput=="tabfile"){ | 103 if (typeinput=="tabfile"){ |
84 | 104 |
85 if (header=="TRUE"){ | 105 if (header=="TRUE"){ |
86 sample = read.table(listfile,header=TRUE,sep="\t",na.strings="NA",fill=TRUE) | 106 sample = readfile(listfile, "true") |
87 }else{ | 107 }else{ |
88 sample = read.table(listfile,header=FALSE,sep="\t",na.strings="NA",fill=TRUE) | 108 sample = readfile(listfile, "false") |
89 } | 109 } |
90 sample = sample[,column] | 110 sample = sample[,column] |
91 | 111 |
92 } | 112 } |
93 # Launch enrichment analysis and return result data from the analysis or the null | 113 # Launch enrichment analysis and return result data from the analysis or the null |