miga-base 0.4.3.0 → 0.5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/miga/cli.rb +43 -223
  4. data/lib/miga/cli/action/add.rb +91 -62
  5. data/lib/miga/cli/action/classify_wf.rb +97 -0
  6. data/lib/miga/cli/action/daemon.rb +14 -10
  7. data/lib/miga/cli/action/derep_wf.rb +95 -0
  8. data/lib/miga/cli/action/doctor.rb +83 -55
  9. data/lib/miga/cli/action/get.rb +68 -52
  10. data/lib/miga/cli/action/get_db.rb +206 -0
  11. data/lib/miga/cli/action/index_wf.rb +31 -0
  12. data/lib/miga/cli/action/init.rb +115 -190
  13. data/lib/miga/cli/action/init/daemon_helper.rb +124 -0
  14. data/lib/miga/cli/action/ls.rb +20 -11
  15. data/lib/miga/cli/action/ncbi_get.rb +199 -157
  16. data/lib/miga/cli/action/preproc_wf.rb +46 -0
  17. data/lib/miga/cli/action/quality_wf.rb +45 -0
  18. data/lib/miga/cli/action/stats.rb +147 -99
  19. data/lib/miga/cli/action/summary.rb +10 -4
  20. data/lib/miga/cli/action/tax_dist.rb +61 -46
  21. data/lib/miga/cli/action/tax_test.rb +46 -39
  22. data/lib/miga/cli/action/wf.rb +178 -0
  23. data/lib/miga/cli/base.rb +11 -0
  24. data/lib/miga/cli/objects_helper.rb +88 -0
  25. data/lib/miga/cli/opt_helper.rb +160 -0
  26. data/lib/miga/daemon.rb +7 -4
  27. data/lib/miga/dataset/base.rb +5 -5
  28. data/lib/miga/project/base.rb +4 -4
  29. data/lib/miga/project/result.rb +2 -1
  30. data/lib/miga/remote_dataset/base.rb +5 -5
  31. data/lib/miga/remote_dataset/download.rb +1 -1
  32. data/lib/miga/version.rb +3 -3
  33. data/scripts/cds.bash +3 -1
  34. data/scripts/essential_genes.bash +1 -0
  35. data/scripts/stats.bash +1 -1
  36. data/scripts/trimmed_fasta.bash +5 -3
  37. data/utils/distance/runner.rb +3 -0
  38. data/utils/distance/temporal.rb +10 -1
  39. data/utils/enveomics/Manifest/Tasks/fasta.json +5 -0
  40. data/utils/enveomics/Manifest/Tasks/sequence-identity.json +7 -0
  41. data/utils/enveomics/Scripts/BlastTab.addlen.rb +33 -31
  42. data/utils/enveomics/Scripts/FastA.tag.rb +42 -41
  43. data/utils/enveomics/Scripts/HMM.essential.rb +85 -55
  44. data/utils/enveomics/Scripts/HMM.haai.rb +29 -20
  45. data/utils/enveomics/Scripts/SRA.download.bash +1 -1
  46. data/utils/enveomics/Scripts/aai.rb +163 -128
  47. data/utils/enveomics/build_enveomics_r.bash +11 -10
  48. data/utils/enveomics/enveomics.R/DESCRIPTION +3 -2
  49. data/utils/enveomics/enveomics.R/R/autoprune.R +141 -107
  50. data/utils/enveomics/enveomics.R/R/barplot.R +105 -86
  51. data/utils/enveomics/enveomics.R/R/cliopts.R +131 -115
  52. data/utils/enveomics/enveomics.R/R/df2dist.R +144 -106
  53. data/utils/enveomics/enveomics.R/R/growthcurve.R +201 -133
  54. data/utils/enveomics/enveomics.R/R/recplot.R +350 -315
  55. data/utils/enveomics/enveomics.R/R/recplot2.R +1334 -914
  56. data/utils/enveomics/enveomics.R/R/tribs.R +521 -361
  57. data/utils/enveomics/enveomics.R/R/utils.R +31 -15
  58. data/utils/enveomics/enveomics.R/README.md +7 -0
  59. data/utils/enveomics/enveomics.R/man/cash-enve.GrowthCurve-method.Rd +17 -0
  60. data/utils/enveomics/enveomics.R/man/cash-enve.RecPlot2-method.Rd +17 -0
  61. data/utils/enveomics/enveomics.R/man/cash-enve.RecPlot2.Peak-method.Rd +17 -0
  62. data/utils/enveomics/enveomics.R/man/enve.GrowthCurve-class.Rd +16 -21
  63. data/utils/enveomics/enveomics.R/man/enve.TRIBS-class.Rd +31 -28
  64. data/utils/enveomics/enveomics.R/man/enve.TRIBS.merge.Rd +23 -19
  65. data/utils/enveomics/enveomics.R/man/enve.TRIBStest-class.Rd +36 -26
  66. data/utils/enveomics/enveomics.R/man/enve.__prune.iter.Rd +23 -24
  67. data/utils/enveomics/enveomics.R/man/enve.__prune.reduce.Rd +23 -24
  68. data/utils/enveomics/enveomics.R/man/enve.__tribs.Rd +32 -33
  69. data/utils/enveomics/enveomics.R/man/enve.barplot.Rd +91 -64
  70. data/utils/enveomics/enveomics.R/man/enve.cliopts.Rd +57 -37
  71. data/utils/enveomics/enveomics.R/man/enve.col.alpha.Rd +24 -19
  72. data/utils/enveomics/enveomics.R/man/enve.col2alpha.Rd +19 -18
  73. data/utils/enveomics/enveomics.R/man/enve.df2dist.Rd +39 -26
  74. data/utils/enveomics/enveomics.R/man/enve.df2dist.group.Rd +38 -25
  75. data/utils/enveomics/enveomics.R/man/enve.df2dist.list.Rd +40 -26
  76. data/utils/enveomics/enveomics.R/man/enve.growthcurve.Rd +67 -49
  77. data/utils/enveomics/enveomics.R/man/enve.prune.dist.Rd +37 -28
  78. data/utils/enveomics/enveomics.R/man/enve.recplot.Rd +122 -97
  79. data/utils/enveomics/enveomics.R/man/enve.recplot2-class.Rd +35 -31
  80. data/utils/enveomics/enveomics.R/man/enve.recplot2.ANIr.Rd +24 -23
  81. data/utils/enveomics/enveomics.R/man/enve.recplot2.Rd +68 -51
  82. data/utils/enveomics/enveomics.R/man/enve.recplot2.__counts.Rd +25 -24
  83. data/utils/enveomics/enveomics.R/man/enve.recplot2.__peakHist.Rd +21 -22
  84. data/utils/enveomics/enveomics.R/man/enve.recplot2.__whichClosestPeak.Rd +19 -20
  85. data/utils/enveomics/enveomics.R/man/enve.recplot2.changeCutoff.Rd +19 -18
  86. data/utils/enveomics/enveomics.R/man/enve.recplot2.compareIdentities.Rd +41 -32
  87. data/utils/enveomics/enveomics.R/man/enve.recplot2.coordinates.Rd +29 -24
  88. data/utils/enveomics/enveomics.R/man/enve.recplot2.corePeak.Rd +18 -18
  89. data/utils/enveomics/enveomics.R/man/enve.recplot2.extractWindows.Rd +40 -34
  90. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.Rd +36 -24
  91. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__em_e.Rd +19 -20
  92. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__em_m.Rd +19 -20
  93. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__emauto_one.Rd +27 -29
  94. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__mow_one.Rd +41 -42
  95. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.__mower.Rd +17 -18
  96. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.em.Rd +43 -33
  97. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.emauto.Rd +36 -28
  98. data/utils/enveomics/enveomics.R/man/enve.recplot2.findPeaks.mower.Rd +74 -56
  99. data/utils/enveomics/enveomics.R/man/enve.recplot2.peak-class.Rd +44 -31
  100. data/utils/enveomics/enveomics.R/man/enve.recplot2.seqdepth.Rd +27 -22
  101. data/utils/enveomics/enveomics.R/man/enve.recplot2.windowDepthThreshold.Rd +32 -26
  102. data/utils/enveomics/enveomics.R/man/enve.tribs.Rd +59 -44
  103. data/utils/enveomics/enveomics.R/man/enve.tribs.test.Rd +28 -21
  104. data/utils/enveomics/enveomics.R/man/enve.truncate.Rd +27 -22
  105. data/utils/enveomics/enveomics.R/man/plot.enve.GrowthCurve.Rd +63 -43
  106. data/utils/enveomics/enveomics.R/man/plot.enve.TRIBS.Rd +38 -29
  107. data/utils/enveomics/enveomics.R/man/plot.enve.TRIBStest.Rd +38 -30
  108. data/utils/enveomics/enveomics.R/man/plot.enve.recplot2.Rd +111 -83
  109. data/utils/enveomics/enveomics.R/man/summary.enve.GrowthCurve.Rd +19 -18
  110. data/utils/enveomics/enveomics.R/man/summary.enve.TRIBS.Rd +19 -18
  111. data/utils/enveomics/enveomics.R/man/summary.enve.TRIBStest.Rd +19 -18
  112. data/utils/find-medoid.R +3 -2
  113. data/utils/representatives.rb +5 -3
  114. data/utils/subclade/pipeline.rb +22 -11
  115. data/utils/subclade/runner.rb +5 -1
  116. data/utils/subclades-compile.rb +1 -1
  117. data/utils/subclades.R +9 -3
  118. metadata +15 -4
  119. data/utils/enveomics/enveomics.R/man/enveomics.R-package.Rd +0 -15
  120. data/utils/enveomics/enveomics.R/man/z$-methods.Rd +0 -26
@@ -1,119 +1,135 @@
1
- enve.cliopts <- function(
2
- ### Generates nicely formatted command-line interfaces for
3
- ### functions (_closures_ only).
4
- fx,
5
- ### Function for which the interface should be generated.
6
- rd_file,
7
- ### (Optional) .Rd file with the standard documentation of the function.
8
- positional_arguments,
9
- ### (Optional) Number of _positional_ arguments passed to parse_args
10
- ### (package:optparse).
11
- usage,
12
- ### (Optional) Usage passed to OptionParser (package:optparse).
13
- mandatory=c(),
14
- ### Mandatory arguments.
15
- vectorize=c(),
16
- ### Arguments of the function to vectorize (comma-delimited). If numeric,
17
- ### use also `number`.
18
- ignore=c(),
19
- ### Arguments of the function to ignore.
20
- number=c(),
21
- ### Force these arguments as numerics. Useful for numeric
22
- ### vectors (see `vectorize`) or arguments with no defaults.
23
- defaults=list(),
24
- ### Defaults to use instead of the ones provided by the formals.
25
- o_desc=list(),
26
- ### Descriptions of the options. Help from `rd` is ignored for arguments
27
- ### present in this list.
28
- p_desc=""
29
- ### Description of the function. Help from `rd` is ignored for the
30
- ### function description unless this value is an empty string.
31
- ){
32
-
33
- #= Load stuff
34
- if(!suppressPackageStartupMessages(
35
- requireNamespace("optparse", quietly=TRUE)))
36
- stop("Package 'optparse' is required.")
37
- requireNamespace("tools", quietly=TRUE)
38
- if(missing(positional_arguments)) positional_arguments <- FALSE
39
- if(missing(usage)) usage <- "usage: %prog [options]"
40
-
41
- #= Get help (if any)
42
- if(!missing(rd_file)){
43
- rd <- tools::parse_Rd(rd_file)
44
- for(i in 1:length(rd)){
45
- tag <- attr(rd[[i]],'Rd_tag')
46
- if(tag=="\\description" && p_desc==""){
47
- p_desc <- paste("\n\t",as.character(rd[[i]]),sep='')
48
- }else if(tag=="\\arguments"){
49
- for(j in 1:length(rd[[i]])){
50
- if(length(rd[[i]][[j]])==2){
51
- name <- as.character(rd[[i]][[j]][[1]])
52
- if(length(o_desc[[name]])==1) next
53
- desc <- as.character(rd[[i]][[j]][[2]])
54
- o_desc[[name]] <- paste(gsub("\n","\n\t\t",desc), collapse='')
55
- }
56
- }
57
- }
58
- }
59
- }
60
-
61
- #= Set options
62
- o_i <- 0
63
- opts <- list()
64
- f <- formals(fx)
65
- if(length(defaults)>0){
66
- for(i in 1:length(defaults)) f[[names(defaults)[i]]] <- defaults[[i]]
67
- }
68
- for(i in names(f)){
69
- if(i=="..." || i %in% ignore) next
70
- o_i <- o_i + 1
71
- flag <- gsub("\\.","-",i)
1
+ #' Enveomics: Cliopts
2
+ #'
3
+ #' Generates nicely formatted command-line interfaces for functions
4
+ #' (\strong{closures} only).
5
+ #'
6
+ #' @param fx Function for which the interface should be generated.
7
+ #' @param rd_file (Optional) .Rd file with the standard documentation of
8
+ #' the function.
9
+ #' @param positional_arguments (Optional) Number of \strong{positional}
10
+ #' arguments passed to \code{\link[optparse]{parse_args}}
11
+ #' (package: \pkg{optparse}).
12
+ #' @param usage (Optional) Usage passed to \code{\link[optparse]{OptionParser}}
13
+ #' (package: \pkg{optparse}).
14
+ #' @param mandatory Mandatory arguments.
15
+ #' @param vectorize Arguments of the function to vectorize (comma-delimited).
16
+ #' If numeric, use also \code{number}.
17
+ #' @param ignore Arguments of the function to ignore.
18
+ #' @param number Force these arguments as numerics. Useful for numeric
19
+ #' vectors (see \code{vectorize}) or arguments with no defaults.
20
+ #' @param defaults Defaults to use instead of the ones provided by the
21
+ #' formals.
22
+ #' @param o_desc Descriptions of the options. Help from \code{rd} is ignored
23
+ #' for arguments present in this list.
24
+ #' @param p_desc Description Description of the function. Help from \code{rd}
25
+ #' is ignored for the function description unless this value is an empty string.
26
+ #'
27
+ #' @return Returns a list with keys:
28
+ #' \itemize{
29
+ #' \item{\code{options}, a named list with the values for the function's
30
+ #' arguments}
31
+ #' \item{\code{args}, a vector with zero or more strings containing the
32
+ #' positional arguments}}
33
+ #'
34
+ #' @author Luis M. Rodriguez-R [aut, cre]
35
+ #'
36
+ #' @export
72
37
 
73
- optopt <- list(help="")
74
- if(length(o_desc[[i]])==1) optopt$help <- o_desc[[i]]
75
- if(!is.null(f[[i]]) && !suppressWarnings(is.na(f[[i]])) && is.logical(f[[i]])){
76
- optopt$opt_str <- paste(ifelse(f[[i]], "--no-", "--"), flag, sep='')
77
- optopt$action <- ifelse(f[[i]], "store_false", "store_true")
78
- }else{
79
- optopt$opt_str <- paste("--", flag, sep='')
80
- optopt$action <- "store"
81
- optopt$help <- paste(optopt$help, "\n\t\t[",
82
- ifelse(i %in% mandatory, "** MANDATORY", "default %default"),
83
- ifelse(i %in% vectorize, ", separate values by commas", ""),
84
- "].", sep="")
85
- }
86
- if(!is.name(f[[i]])){
87
- optopt$default <- f[[i]]
88
- optopt$metavar <- class(f[[i]])
38
+ enve.cliopts <- function(
39
+ fx,
40
+ rd_file,
41
+ positional_arguments,
42
+ usage,
43
+ mandatory=c(),
44
+ vectorize=c(),
45
+ ignore=c(),
46
+ number=c(),
47
+ defaults=list(),
48
+ o_desc=list(),
49
+ p_desc=""
50
+ ){
51
+
52
+ #= Load stuff
53
+ if(!suppressPackageStartupMessages(
54
+ requireNamespace("optparse", quietly=TRUE)))
55
+ stop("Package 'optparse' is required.")
56
+ requireNamespace("tools", quietly=TRUE)
57
+ if(missing(positional_arguments)) positional_arguments <- FALSE
58
+ if(missing(usage)) usage <- "usage: %prog [options]"
59
+
60
+ #= Get help (if any)
61
+ if(!missing(rd_file)){
62
+ rd <- tools::parse_Rd(rd_file)
63
+ for(i in 1:length(rd)){
64
+ tag <- attr(rd[[i]],'Rd_tag')
65
+ if(tag=="\\description" && p_desc==""){
66
+ p_desc <- paste("\n\t",as.character(rd[[i]]),sep='')
67
+ }else if(tag=="\\arguments"){
68
+ for(j in 1:length(rd[[i]])){
69
+ if(length(rd[[i]][[j]])==2){
70
+ name <- as.character(rd[[i]][[j]][[1]])
71
+ if(length(o_desc[[name]])==1) next
72
+ desc <- as.character(rd[[i]][[j]][[2]])
73
+ o_desc[[name]] <- paste(gsub("\n","\n\t\t",desc), collapse='')
74
+ }
75
+ }
89
76
  }
90
- if(i %in% number) optopt$metavar <- "NUMERIC"
91
- optopt$dest <- i
92
-
93
- opts[[o_i]] <- do.call(optparse::make_option, optopt)
94
- }
95
- opt <- optparse::parse_args(
96
- optparse::OptionParser(option_list=opts, description=p_desc, usage=usage),
97
- positional_arguments=positional_arguments)
98
-
99
- #= Post-hoc checks
100
- if(length(opt[['options']])==0) opt <- list(options=opt, args=c())
101
- for(i in mandatory){
102
- if(length(opt$options[[i]])==0) stop('Missing mandatory argument: ',i)
103
- }
104
- for(i in vectorize){
105
- if(length(opt$options[[i]])==1)
106
- opt$options[[i]] <- strsplit(opt$options[[i]],",")[[1]]
107
- }
108
- for(i in number){
109
- if(length(opt$options[[i]])>0)
110
- opt$options[[i]] <- as.numeric(opt$options[[i]])
111
- }
112
- opt$options$help <- NULL
113
-
114
- return(opt)
115
- ### Returns a `list` with keys: `options`, a named list with the values for
116
- ### the function's arguments; and `args`, a vector with zero or more strings
117
- ### containing the positional arguments.
77
+ }
78
+ }
79
+
80
+ #= Set options
81
+ o_i <- 0
82
+ opts <- list()
83
+ f <- formals(fx)
84
+ if(length(defaults)>0){
85
+ for(i in 1:length(defaults)) f[[names(defaults)[i]]] <- defaults[[i]]
86
+ }
87
+ for(i in names(f)){
88
+ if(i=="..." || i %in% ignore) next
89
+ o_i <- o_i + 1
90
+ flag <- gsub("\\.","-",i)
91
+
92
+ optopt <- list(help="")
93
+ if(length(o_desc[[i]])==1) optopt$help <- o_desc[[i]]
94
+ if(!is.null(f[[i]]) && !suppressWarnings(is.na(f[[i]])) && is.logical(f[[i]])){
95
+ optopt$opt_str <- paste(ifelse(f[[i]], "--no-", "--"), flag, sep='')
96
+ optopt$action <- ifelse(f[[i]], "store_false", "store_true")
97
+ }else{
98
+ optopt$opt_str <- paste("--", flag, sep='')
99
+ optopt$action <- "store"
100
+ optopt$help <- paste(optopt$help, "\n\t\t[",
101
+ ifelse(i %in% mandatory, "** MANDATORY", "default %default"),
102
+ ifelse(i %in% vectorize, ", separate values by commas", ""),
103
+ "].", sep="")
104
+ }
105
+ if(!is.name(f[[i]])){
106
+ optopt$default <- f[[i]]
107
+ optopt$metavar <- class(f[[i]])
108
+ }
109
+ if(i %in% number) optopt$metavar <- "NUMERIC"
110
+ optopt$dest <- i
111
+
112
+ opts[[o_i]] <- do.call(optparse::make_option, optopt)
113
+ }
114
+ opt <- optparse::parse_args(
115
+ optparse::OptionParser(option_list=opts, description=p_desc, usage=usage),
116
+ positional_arguments=positional_arguments)
117
+
118
+ #= Post-hoc checks
119
+ if(length(opt[['options']])==0) opt <- list(options=opt, args=c())
120
+ for(i in mandatory){
121
+ if(length(opt$options[[i]])==0) stop('Missing mandatory argument: ',i)
122
+ }
123
+ for(i in vectorize){
124
+ if(length(opt$options[[i]])==1)
125
+ opt$options[[i]] <- strsplit(opt$options[[i]],",")[[1]]
126
+ }
127
+ for(i in number){
128
+ if(length(opt$options[[i]])>0)
129
+ opt$options[[i]] <- as.numeric(opt$options[[i]])
130
+ }
131
+ opt$options$help <- NULL
132
+
133
+ return(opt)
118
134
  }
119
135
 
@@ -1,117 +1,155 @@
1
+ #' Enveomics: Data Frame to Dist
2
+ #'
3
+ #' Transform a dataframe (or coercible object, like a table) into a
4
+ #' \strong{dist} object.
5
+ #'
6
+ #' @param x A dataframe (or coercible object) with at least three columns:
7
+ #' \enumerate{
8
+ #' \item ID of the object 1,
9
+ #' \item ID of the object 2, and
10
+ #' \item distance between the two objects.}
11
+ #' @param obj1.index Index of the column containing the ID of the object 1.
12
+ #' @param obj2.index Index of the column containing the ID of the object 2.
13
+ #' @param dist.index Index of the column containing the distance.
14
+ #' @param default.d Default value (for missing values).
15
+ #' @param max.sim If not zero, assumes that the values are similarity
16
+ #' (not distance) and this is the maximum similarity (corresponding to
17
+ #' distance 0). Applies transformation:
18
+ #' \eqn{distance = (max.sim - values)/max.sim.}
19
+ #'
20
+ #' @return Returns a \strong{dist} object.
21
+ #'
22
+ #' @author Luis M. Rodriguez-R [aut, cre]
23
+ #'
24
+ #' @export
1
25
 
2
26
  enve.df2dist <- function(
3
- ### Transform a dataframe (or coercible object, like a table) into a `dist` object.
4
- x,
5
- ### A table (or coercible object) with at least three columns: (1) ID of the object 1,
6
- ### (2) ID of the object 2, and (3) distance between the two objects.
7
- obj1.index=1,
8
- ### Index of the column containing the ID of the object 1.
9
- obj2.index=2,
10
- ### Index of the column containing the ID of the object 2.
11
- dist.index=3,
12
- ### Index of the column containing the distance.
13
- default.d=NA,
14
- ### Default value (for missing values)
15
- max.sim=0
16
- ### If not-zero, assumes that the values are similarity (not distance)
17
- ### and this is the maximum similarity (corresponding to distance 0).
18
- ### Applies transformation: distance = (max.sim - values)/max.sim.
19
- ){
20
- x <- as.data.frame(x);
21
- a <- as.character(x[, obj1.index]);
22
- b <- as.character(x[, obj2.index]);
23
- d <- as.double(x[, dist.index]);
24
- if(max.sim!=0) d <- (max.sim - d)/max.sim
25
- ids <- unique(c(a,b));
26
- m <- matrix(default.d, nrow=length(ids), ncol=length(ids), dimnames=list(ids, ids));
27
- diag(m) <- 0.0
28
- for(i in 1:nrow(x)){
29
- m[a[i], b[i]] <- d[i];
30
- }
31
- m <- pmin(m, t(m), na.rm=TRUE)
32
- return(as.dist(m));
33
- ### Returns a `dist` object.
27
+ x,
28
+ obj1.index=1,
29
+ obj2.index=2,
30
+ dist.index=3,
31
+ default.d=NA,
32
+ max.sim=0
33
+ ){
34
+ x <- as.data.frame(x);
35
+ a <- as.character(x[, obj1.index]);
36
+ b <- as.character(x[, obj2.index]);
37
+ d <- as.double(x[, dist.index]);
38
+ if(max.sim!=0) d <- (max.sim - d)/max.sim
39
+ ids <- unique(c(a,b));
40
+ m <- matrix(default.d, nrow=length(ids), ncol=length(ids), dimnames=list(ids, ids));
41
+ diag(m) <- 0.0
42
+ for(i in 1:nrow(x)){
43
+ m[a[i], b[i]] <- d[i];
44
+ }
45
+ m <- pmin(m, t(m), na.rm=TRUE)
46
+ return(as.dist(m));
34
47
  }
35
48
 
36
-
49
+ #' Enveomics: Data Frame to Dist (Group)
50
+ #'
51
+ #' Transform a dataframe (or coercible object, like a table) into a
52
+ #' \strong{dist} object, where there are 1 or more distances between each pair
53
+ #' of objects.
54
+ #'
55
+ #' @param x A dataframe (or coercible object) with at least three columns:
56
+ #' \enumerate{
57
+ #' \item ID of the object 1,
58
+ #' \item ID of the object 2, and
59
+ #' \item distance between the two objects.}
60
+ #' @param obj1.index Index of the column containing the ID of the object 1.
61
+ #' @param obj2.index Index of the column containing the ID of the object 2.
62
+ #' @param dist.index Index of the column containing the distance.
63
+ #' @param summary Function summarizing the different distances between the
64
+ #' two objects.
65
+ #' @param empty.rm Remove rows with empty or \code{NA} groups.
66
+ #'
67
+ #' @return Returns a \strong{dist} object.
68
+ #'
69
+ #' @author Luis M. Rodriguez-R [aut, cre]
70
+ #'
71
+ #' @export
37
72
 
38
73
  enve.df2dist.group <- function(
39
- ### Transform a dataframe (or coercible object, like a table) into a `dist` object, where
40
- ### there are 1 or more distances between each pair of objects.
41
- x,
42
- ### A dataframe (or coercible object) with at least three columns: (1) ID of the object 1,
43
- ### (2) ID of the object 2, and (3) distance between the two objects.
44
- obj1.index=1,
45
- ### Index of the column containing the ID of the object 1.
46
- obj2.index=2,
47
- ### Index of the column containing the ID of the object 2.
48
- dist.index=3,
49
- ### Index of the column containing the distance.
50
- summary=median,
51
- ### Function summarizing the different distances between the two objects.
52
- empty.rm=TRUE
53
- ### Remove rows with empty or NA groups
54
- ){
55
- x <- as.data.frame(x);
56
- if(empty.rm) x <- x[ !(is.na(x[,obj1.index]) | is.na(x[,obj2.index]) | x[,obj1.index]=='' | x[,obj2.index]==''), ]
57
- a <- as.character(x[, obj1.index]);
58
- b <- as.character(x[, obj2.index]);
59
- d <- as.double(x[, dist.index]);
60
- ids <- unique(c(a,b));
61
- if(length(ids)<2) return(NA);
62
- m <- matrix(NA, nrow=length(ids), ncol=length(ids), dimnames=list(ids, ids));
63
- diag(m) <- 0
64
- for(i in 2:length(ids)){
65
- id.i <- ids[i];
66
- for(j in 1:(i-1)){
67
- id.j <- ids[j];
68
- d.ij <- summary(c( d[ a==id.i & b==id.j], d[ b==id.i & a==id.j] ));
69
- m[id.i, id.j] <- d.ij;
70
- m[id.j, id.i] <- d.ij;
71
- }
72
- }
73
- return(as.dist(m));
74
- ### Returns a `dist` object.
74
+ x,
75
+ obj1.index=1,
76
+ obj2.index=2,
77
+ dist.index=3,
78
+ summary=median,
79
+ empty.rm=TRUE
80
+ ){
81
+ x <- as.data.frame(x);
82
+ if(empty.rm) x <- x[ !(is.na(x[,obj1.index]) | is.na(x[,obj2.index]) | x[,obj1.index]=='' | x[,obj2.index]==''), ]
83
+ a <- as.character(x[, obj1.index]);
84
+ b <- as.character(x[, obj2.index]);
85
+ d <- as.double(x[, dist.index]);
86
+ ids <- unique(c(a,b));
87
+ if(length(ids)<2) return(NA);
88
+ m <- matrix(NA, nrow=length(ids), ncol=length(ids), dimnames=list(ids, ids));
89
+ diag(m) <- 0
90
+ for(i in 2:length(ids)){
91
+ id.i <- ids[i];
92
+ for(j in 1:(i-1)){
93
+ id.j <- ids[j];
94
+ d.ij <- summary(c( d[ a==id.i & b==id.j], d[ b==id.i & a==id.j] ));
95
+ m[id.i, id.j] <- d.ij;
96
+ m[id.j, id.i] <- d.ij;
97
+ }
98
+ }
99
+ return(as.dist(m));
75
100
  }
76
101
 
102
+ #' Enveomics: Data Frame to Dist (List)
103
+ #'
104
+ #' Transform a dataframe (or coercible object, like a table)
105
+ #' into a \strong{dist} object.
106
+ #'
107
+ #' @param x A dataframe (or coercible object) with at least three columns:
108
+ #' \enumerate{
109
+ #' \item ID of the object 1,
110
+ #' \item ID of the object 2, and
111
+ #' \item distance between the two objects.}
112
+ #' @param groups Named array where the IDs correspond to the object IDs,
113
+ #' and the values correspond to the group.
114
+ #' @param obj1.index Index of the column containing the ID of the object 1.
115
+ #' @param obj2.index Index of the column containing the ID of the object 2.
116
+ #' @param dist.index Index of the column containing the distance.
117
+ #' @param empty.rm Remove incomplete matrices.
118
+ #' @param ... Any other parameters supported by
119
+ #' \code{\link{enve.df2dist.group}}.
120
+ #'
121
+ #' @return Returns a \strong{list} of \strong{dist} objects.
122
+ #'
123
+ #' @author Luis M. Rodriguez-R [aut, cre]
124
+ #'
125
+ #' @export
126
+
77
127
  enve.df2dist.list <- function(
78
- ### Transform a dataframe (or coercible object, like a table) into a `dist` object.
79
- x,
80
- ### A dataframe (or coercible object) with at least three columns: (1) ID of the object 1,
81
- ### (2) ID of the object 2, and (3) distance between the two objects.
82
- groups,
83
- ### Named array where the IDs correspond to the object IDs, and the values correspond to
84
- ### the group.
85
- obj1.index=1,
86
- ### Index of the column containing the ID of the object 1.
87
- obj2.index=2,
88
- ### Index of the column containing the ID of the object 2.
89
- dist.index=3,
90
- ### Index of the column containing the distance.
91
- empty.rm=TRUE,
92
- ### Remove incomplete matrices
93
- ...
94
- ### Any other parameters supported by `enve.df2dist.group`.
95
- ){
96
- x <- as.data.frame(x);
97
- a <- as.character(x[, obj1.index]);
98
- b <- as.character(x[, obj2.index]);
99
- d <- as.numeric(x[, dist.index]);
100
- ids.all <- unique(c(a,b));
101
- l <- list();
102
- same_group <- groups[a]==groups[b];
103
- same_group <- ifelse(is.na(same_group), FALSE, TRUE);
104
- for(group in unique(groups)){
105
- ids <- ids.all[ groups[ids.all]==group ];
106
- if(length(ids)>1 & group!=""){
107
- x.sub <- x[ same_group & (groups[a]==group) & (groups[b]==group), ]
108
- if(nrow(x.sub)>0){
109
- d.g <- enve.df2dist(x.sub, obj1.index, obj2.index, dist.index, ...);
110
- if(!empty.rm | !any(is.na(d.g))) l[[ group ]] <- d.g;
111
- }
128
+ x,
129
+ groups,
130
+ obj1.index=1,
131
+ obj2.index=2,
132
+ dist.index=3,
133
+ empty.rm=TRUE,
134
+ ...
135
+ ){
136
+ x <- as.data.frame(x);
137
+ a <- as.character(x[, obj1.index]);
138
+ b <- as.character(x[, obj2.index]);
139
+ d <- as.numeric(x[, dist.index]);
140
+ ids.all <- unique(c(a,b));
141
+ l <- list();
142
+ same_group <- groups[a]==groups[b];
143
+ same_group <- ifelse(is.na(same_group), FALSE, TRUE);
144
+ for(group in unique(groups)){
145
+ ids <- ids.all[ groups[ids.all]==group ];
146
+ if(length(ids)>1 & group!=""){
147
+ x.sub <- x[ same_group & (groups[a]==group) & (groups[b]==group), ]
148
+ if(nrow(x.sub)>0){
149
+ d.g <- enve.df2dist(x.sub, obj1.index, obj2.index, dist.index, ...);
150
+ if(!empty.rm | !any(is.na(d.g))) l[[ group ]] <- d.g;
112
151
  }
113
- }
114
- return(l);
115
- ### Returns a `list` of `dist` object.
152
+ }
153
+ }
154
+ return(l);
116
155
  }
117
-