Mercurial > repos > proteore > proteore_goprofiles
comparison goprofiles.R @ 4:715002a394ec draft
planemo upload commit b36435833bf54f90f62cc240f2cda1c889161b23-dirty
author | proteore |
---|---|
date | Fri, 23 Mar 2018 10:47:17 -0400 |
parents | 58a8ddd58dde |
children | 781072a65600 |
comparison
equal
deleted
inserted
replaced
3:ed226f0e5625 | 4:715002a394ec |
---|---|
1 # Load necessary libraries | 1 # Load necessary libraries |
2 library(org.Hs.eg.db) | 2 library(org.Hs.eg.db) |
3 library(goProfiles) | 3 library(goProfiles) |
4 | 4 |
5 # Read file and return file content as data.frame? | 5 # Read file and return file content as data.frame |
6 readfile = function(filename, header) { | 6 readfile = function(filename, header) { |
7 if (header == "true") { | 7 if (header == "true") { |
8 # Read only the first line of the files as data (without headers): | 8 # Read only first line of the file as header: |
9 headers <- read.table(filename, nrows = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE) | 9 headers <- read.table(filename, nrows = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "") |
10 #Read the data of the files (skipping the first row): | 10 #Read the data of the files (skipping the first row) |
11 file <- read.table(filename, skip = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE) | 11 file <- read.table(filename, skip = 1, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "") |
12 # Remove empty rows | 12 # Remove empty rows |
13 file <- file[!apply(is.na(file) | file == "", 1, all),] | 13 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE] |
14 #And assign the headers of step two to the data: | 14 #And assign the header to the data |
15 names(file) <- headers | 15 names(file) <- headers |
16 } | 16 } |
17 else { | 17 else { |
18 file <- read.table(filename, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE) | 18 file <- read.table(filename, header = FALSE, sep = "\t", stringsAsFactors = FALSE, fill = TRUE, na.strings=c("", "NA"), blank.lines.skip = TRUE, quote = "") |
19 # Remove empty rows | |
20 file <- file[!apply(is.na(file) | file == "", 1, all), , drop=FALSE] | |
19 } | 21 } |
20 return(file) | 22 return(file) |
21 } | 23 } |
22 | 24 |
23 getprofile = function(ids, id_type, level, duplicate) { | 25 getprofile = function(ids, id_type, level, duplicate) { |
173 args <- as.list(as.character(argsDF$V2)) | 175 args <- as.list(as.character(argsDF$V2)) |
174 names(args) <- argsDF$V1 | 176 names(args) <- argsDF$V1 |
175 | 177 |
176 input_type = args$input_type | 178 input_type = args$input_type |
177 if (input_type == "text") { | 179 if (input_type == "text") { |
178 input = strsplit(args$input, " ")[[1]] | 180 input = strsplit(args$input, "[ \t\n]+")[[1]] |
179 } | 181 } |
180 else if (input_type == "file") { | 182 else if (input_type == "file") { |
181 filename = args$input | 183 filename = args$input |
182 ncol = args$ncol | 184 ncol = args$ncol |
183 # Check ncol | 185 # Check ncol |