Skip to content

Commit 184f1cc

Browse files
authored
Merge pull request #8 from omixer/7-missing-file
7 missing file
2 parents 4ae24fe + 02f54ac commit 184f1cc

File tree

4 files changed

+101
-91
lines changed

4 files changed

+101
-91
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.bash_history
2+
.idea
13
.project
24
.settings
35
.RData

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Package: omixerRpm
22
Type: Package
33
Title: Metabolic module profiling of microbiome samples
4-
Version: 0.3.2
5-
Date: 2018-11-13
4+
Version: 0.3.3
5+
Date: 2022-12-16
66
Author: Youssef Darzi
7-
Maintainer: Youssef Darzi<youssef.darzi@gmail.com>
7+
Maintainer: Youssef Darzi<youssef.darzi@omixer.io>
88
Description: An R interface to the omixer-rpm for metabolic module profiling of microbiome samples
99
License: GNU General Public License v3.0. The bundled omixer-rpm.jar is licensed under an Academic Non-commercial Software License Agreement, https://github.com/raeslab/omixer-rpm/blob/master/LICENSE

R/rpm.R

Lines changed: 90 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,95 @@
11
# x is a dataframe or a valid file path
22
# Add the Description of modules as a data object
3-
rpm <- function(x, minimum.coverage=-1, score.estimator="median", annotation = 1, module.db = NULL, threads = 1,
4-
normalize.by.length = FALSE, distribute = FALSE, java.mem=NULL) {
5-
# link to the GMMs executable and DB
6-
rpm.exec <- system.file("java", "omixer-rpm.jar", package = "omixerRpm")
7-
if(is.null(module.db)) {
8-
module.db <- loadDefaultDB()
9-
}
10-
11-
# Prepare output directories
12-
out.dir <- tempfile()
13-
dir.create(out.dir)
14-
15-
# Is x a file or a data.frame
16-
if(!is.character(x)) {
17-
# write samples for processing with the GMMs
18-
in.dir <- tempfile()
19-
dir.create(in.dir)
20-
input <- file.path(in.dir, "input.tsv")
21-
write.table(x, input, col.names=T, row.names=F, quote=F, sep="\t")
22-
} else {
23-
input <- x
24-
}
3+
rpm <- function(x, minimum.coverage = -1, score.estimator = "median", annotation = 1, module.db = NULL, threads = 1,
4+
normalize.by.length = FALSE, distribute = FALSE, java.mem = NULL) {
5+
# link to the GMMs executable and DB
6+
rpm.exec <- system.file("java", "omixer-rpm.jar", package = "omixerRpm")
7+
if (is.null(module.db)) {
8+
module.db <- loadDefaultDB()
9+
}
2510

26-
# Compiling the command
27-
command <- "java -server"
28-
29-
if(!is.null(java.mem)){
30-
command <- paste(command, paste0("-Xmx", java.mem, "G"))
31-
}
32-
33-
command <- paste(command , "-jar", rpm.exec,
34-
"-c" , minimum.coverage,
35-
"-s", score.estimator,
36-
"-d", file.path(module.db@directory, module.db@modules),
37-
"-i", input,
38-
"-o", out.dir,
39-
"-a", annotation,
40-
"-t", threads,
41-
"-e", 2)
42-
if( normalize.by.length == TRUE) {
43-
command <-paste(command, "-n")
44-
}
45-
46-
if( distribute == TRUE) {
47-
command <-paste(command, "--Xdistribute")
48-
}
49-
50-
# Run the module mapping
51-
tryCatch({
52-
system(command)
53-
},
54-
warning = function (e) {
55-
print(e)
56-
if(e$message == "error in running command"){
57-
stop(e)
58-
}
59-
},
60-
error = function (e) {
61-
print(geterrmessage())
62-
stop(e)
63-
}
64-
)
11+
# Prepare output directories
12+
out.dir <- tempfile()
13+
dir.create(out.dir)
6514

66-
abundance <- read.table(file.path(out.dir, "modules.tsv"), sep="\t", header=TRUE)
67-
coverage <- read.table(file.path(out.dir, "modules-coverage.tsv"), sep="\t", header=TRUE)
68-
69-
annotation.df <- NULL
70-
71-
if (annotation == 1){
72-
# ortohology only
73-
abundance.colnames <- colnames(abundance)
74-
annotation.df <- as.data.frame(abundance[, 1])
75-
abundance <- as.data.frame(abundance[, -c(1)])
76-
coverage <- as.data.frame(coverage[, -c(1)])
77-
colnames(annotation.df) <- abundance.colnames[1]
78-
colnames(abundance) <- abundance.colnames[2:length(abundance.colnames)]
79-
colnames(coverage) <- abundance.colnames[2:length(abundance.colnames)]
80-
} else if (annotation == 2) {
81-
# orthology and taxonomy
82-
abundance.colnames <- colnames(abundance)
83-
annotation.df <- as.data.frame(abundance[, c(1, 2)])
84-
abundance <- as.data.frame(abundance[, -c(1, 2)])
85-
coverage <- as.data.frame(coverage[, -c(1, 2)])
86-
colnames(annotation.df) <- abundance.colnames[1:2]
87-
colnames(abundance) <- abundance.colnames[3:length(abundance.colnames)]
88-
colnames(coverage) <- abundance.colnames[3:length(abundance.colnames)]
89-
}
90-
91-
Modules(abundance=abundance, coverage=coverage, annotation=annotation.df, db=module.db)
15+
# Is x a file or a data.frame
16+
if (!is.character(x)) {
17+
# write samples for processing with the GMMs
18+
in.dir <- tempfile()
19+
dir.create(in.dir)
20+
input <- file.path(in.dir, "input.tsv")
21+
write.table(x, input, col.names = T, row.names = F, quote = F, sep = "\t")
22+
} else {
23+
input <- x
24+
}
25+
26+
# Compiling the command
27+
command <- "java -server"
28+
29+
if (!is.null(java.mem)) {
30+
command <- paste(command, paste0("-Xmx", java.mem, "G"))
31+
}
32+
33+
command <- paste(command, "-jar", rpm.exec,
34+
"-c", minimum.coverage,
35+
"-s", score.estimator,
36+
"-d", file.path(module.db@directory, module.db@modules),
37+
"-i", input,
38+
"-o", out.dir,
39+
"-a", annotation,
40+
"-t", threads,
41+
"-e", 2)
42+
if (normalize.by.length == TRUE) {
43+
command <- paste(command, "-n")
44+
}
45+
46+
if (distribute == TRUE) {
47+
command <- paste(command, "--Xdistribute")
48+
}
49+
50+
# Run the module mapping
51+
tryCatch({
52+
status <- system(command)
53+
if (status != 0) {
54+
stop("The execution of Omixer-RPM returned a non-zero exit status. Refer to the exception output for details.")
55+
}
56+
},
57+
warning = function(e) {
58+
print(e)
59+
if (e$message == "error in running command") {
60+
stop(e)
61+
}
62+
},
63+
error = function(e) {
64+
print(geterrmessage())
65+
stop(e)
66+
}
67+
)
68+
69+
abundance <- read.table(file.path(out.dir, "modules.tsv"), sep = "\t", header = TRUE)
70+
coverage <- read.table(file.path(out.dir, "modules-coverage.tsv"), sep = "\t", header = TRUE)
71+
72+
annotation.df <- NULL
73+
74+
if (annotation == 1) {
75+
# ortohology only
76+
abundance.colnames <- colnames(abundance)
77+
annotation.df <- as.data.frame(abundance[, 1])
78+
abundance <- as.data.frame(abundance[, -c(1)])
79+
coverage <- as.data.frame(coverage[, -c(1)])
80+
colnames(annotation.df) <- abundance.colnames[1]
81+
colnames(abundance) <- abundance.colnames[2:length(abundance.colnames)]
82+
colnames(coverage) <- abundance.colnames[2:length(abundance.colnames)]
83+
} else if (annotation == 2) {
84+
# orthology and taxonomy
85+
abundance.colnames <- colnames(abundance)
86+
annotation.df <- as.data.frame(abundance[, c(1, 2)])
87+
abundance <- as.data.frame(abundance[, -c(1, 2)])
88+
coverage <- as.data.frame(coverage[, -c(1, 2)])
89+
colnames(annotation.df) <- abundance.colnames[1:2]
90+
colnames(abundance) <- abundance.colnames[3:length(abundance.colnames)]
91+
colnames(coverage) <- abundance.colnames[3:length(abundance.colnames)]
92+
}
93+
94+
Modules(abundance = abundance, coverage = coverage, annotation = annotation.df, db = module.db)
9295
}

test/runitModules.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ test.moduleDbLoad <- function() {
6767
db <- loadDB("GMMs.v1.07")
6868
# check getNames returns the correct annotation
6969
checkEquals(getNames(db, "MF0010"), "sucrose degradation I")
70-
}
70+
}
71+
72+
test.handleMalformedInput <- function() {
73+
# expect a NumberFormat exception for the wrong annotation value
74+
checkException(rpm("test/species_matrix.tsv", annotation = 1, minimum.coverage = 0.3))
75+
}

0 commit comments

Comments
 (0)