1
1
# x is a dataframe or a valid file path
2
2
# 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
+ }
25
10
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 )
65
14
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 )
92
95
}
0 commit comments