Skip to content

Commit

Permalink
build 0.98.7 hopefully final
Browse files Browse the repository at this point in the history
  • Loading branch information
eschen42 committed Jan 21, 2018
1 parent 81767bb commit f628764
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 25 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: w4mclassfilter
Version: 0.98.6
Date: 2017-12-08
Version: 0.98.7
Date: 2018-01-20
Title: W4M Class Filter
Description: Filter Workflow4Metabolomics dataMatrix, sampleMetadata, and variableMetadata files by sample-class or variable-attribute range, imputing zero for NA values and eliminating zero-variance rows and columns from the data-matrix.
Author: Arthur C Eschenlauer <[email protected]>
Expand Down
43 changes: 24 additions & 19 deletions R/ClassFilter.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ w4m__nonzero_var <- function(m) {
utils::str(x)
stop("matrix has no columns")
}
if ( is.numeric(x) ) {
# exclude any rows with zero variance
row.vars <- w4m__var_by_rank_or_file(x, dim = 1)
nonzero.row.vars <- row.vars > 0
nonzero.rows <- row.vars[nonzero.row.vars]
if ( is.numeric(x) ) {
if ( length(rownames(x)) != length(rownames(nonzero.rows)) ) {
row.names <- attr(nonzero.rows,"names")
x <- x[ row.names, , drop = FALSE ]
Expand Down Expand Up @@ -219,20 +219,21 @@ w4m__nonzero_var <- function(m) {
#'
#' Please see the package vignette for further details.
#'
#' @param dataMatrix_in input data matrix (rows are feature names, columns are sample names
#' @param sampleMetadata_in input sample metadata (rows are sample names, one column's name matches class_column)
#' @param variableMetadata_in input variable metadata (rows are variable names)
#' @param dataMatrix_out output data matrix (rows are feature names, columns are sample names
#' @param sampleMetadata_out output sample metadata (rows are sample names, one column's name matches class_column)
#' @param variableMetadata_out output variable metadata (rows are variable names)
#' @param classes character array: names of sample classes to include or exclude; default is an empty array
#' @param include logical: TRUE, include named sample classes; FALSE (the default), exclude named sample classes
#' @param class_column character: name of "class" column, defaults to "class"
#' @param samplename_column character: name of column with sample name, defaults to "sampleMetadata"
#' @param name_varmetadata_col1 logical: TRUE, name column 1 of variable metadata as "variableMetadata"; FALSE, no change; default is TRUE
#' @param variable_range_filter character array: array of filters specified as 'variableMetadataColumnName:min:max'; default is empty array
#' @param data_imputation function(m): default imputation method for 'intb' data, where intensities have background subtracted - impute zero for NA
#' @param failure_action function(x, ...): action to take upon failure - defaults to 'print(x,...)'
#' @param dataMatrix_in input data matrix (rows are feature names, columns are sample names
#' @param sampleMetadata_in input sample metadata (rows are sample names, one column's name matches class_column)
#' @param variableMetadata_in input variable metadata (rows are variable names)
#' @param dataMatrix_out output data matrix (rows are feature names, columns are sample names
#' @param sampleMetadata_out output sample metadata (rows are sample names, one column's name matches class_column)
#' @param variableMetadata_out output variable metadata (rows are variable names)
#' @param classes character array: names of sample classes to include or exclude; default is an empty array
#' @param include logical: TRUE, include named sample classes; FALSE (the default), exclude named sample classes
#' @param class_column character: name of "class" column, defaults to "class"
#' @param samplename_column character: name of column with sample name, defaults to "sampleMetadata"
#' @param name_varmetadata_col1 logical: TRUE, name column 1 of variable metadata as "variableMetadata"; FALSE, no change; default is TRUE
#' @param name_smplmetadata_col1 logical: TRUE, name column 1 of sample metadata as "sampleMetadata"; FALSE, no change; default is TRUE
#' @param variable_range_filter character array: array of filters specified as 'variableMetadataColumnName:min:max'; default is empty array
#' @param data_imputation function(m): default imputation method for 'intb' data, where intensities have background subtracted - impute zero for NA
#' @param failure_action function(x, ...): action to take upon failure - defaults to 'print(x,...)'
#'
#' @return logical: TRUE only if filtration succeeded
#'
Expand Down Expand Up @@ -284,6 +285,7 @@ w4m_filter_by_sample_class <- function(
, class_column = "class" # character: name of "class" column, defaults to "class"
, samplename_column = "sampleMetadata" # character: name of column with sample name, defaults to "sampleMetadata"
, name_varmetadata_col1 = TRUE # logical: TRUE, name column 1 of variable metadata as "variableMetadata"; FALSE, no change; default is TRUE
, name_smplmetadata_col1 = TRUE # logical: TRUE, name column 1 of variable metadata as "variableMetadata"; FALSE, no change; default is TRUE
, variable_range_filter = c() # character array: array of filters specified as 'variableMetadataColumnName:min:max'; default is empty array
, data_imputation = w4m_filter_imputation # function(m): default imputation method is for 'intb' data, where intensities have background subtracted - impute zero for NA
, failure_action = print # function(x, ...): action to take upon failure - defaults to 'print(x,...)'
Expand Down Expand Up @@ -435,7 +437,10 @@ w4m_filter_by_sample_class <- function(
}

# extract rownames
rownames(smpl_metadata) <- smpl_metadata[,samplename_column]
if (name_smplmetadata_col1) {
colnames(smpl_metadata)[1] <- "sampleMetadata"
}
rownames(smpl_metadata) <- smpl_metadata[ , samplename_column]

if (nchar(class_column) > 0 && length(classes) > 0) {
# select the first column of the rows indicated by classes, include, & class_column, but don't drop dimension
Expand All @@ -449,7 +454,7 @@ w4m_filter_by_sample_class <- function(
, Reduce(
`|`
, lapply(X = classes, FUN = function(pattern) {
grepl(pattern = pattern, x = smpl_metadata[,class_column])
grepl(pattern = pattern, x = smpl_metadata[ , class_column])
})
)
)
Expand Down Expand Up @@ -485,8 +490,8 @@ w4m_filter_by_sample_class <- function(
err.env$msg <- "no message setting vrbl_metadata rownames"
tryCatch(
expr = {
rownames(vrbl_metadata) <- make.names( vrbl_metadata[,1], unique = TRUE )
vrbl_metadata[,1] <- rownames(vrbl_metadata)
rownames(vrbl_metadata) <- make.names( vrbl_metadata[ , 1 ], unique = TRUE )
vrbl_metadata[ , 1 ] <- rownames(vrbl_metadata)
if (name_varmetadata_col1) {
colnames(vrbl_metadata)[1] <- "variableMetadata"
}
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ SOFTWARE.

## NEWS

### CHANGES IN VERSION 0.98.7

#### NEW FEATURES

* First column of sample metadata is by default renamed to "sampleMetadata" unless
argument 'name_smplmetadata_col1' is supplied and set to FALSE.

#### INTERNAL MODIFICATIONS

* none

### CHANGES IN VERSION 0.98.6

#### NEW FEATURES
Expand Down
7 changes: 7 additions & 0 deletions inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
CHANGES IN VERSION 0.98.7
------------------------------

SIGNIFICANT USER-VISIBLE CHANGES

o First column of sample metadata is by default renamed to "sampleMetadata" unless argument 'name_smplmetadata_col1' is supplied and set to FALSE.

CHANGES IN VERSION 0.98.6
------------------------------

Expand Down
6 changes: 4 additions & 2 deletions man/w4m_filter_by_sample_class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/input_sampleMetadata.tsv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sampleMetadata injectionOrder mode age bmi gender
smplMetadata injectionOrder mode age bmi gender
HU_017 2 pos 41 23.03 M
HU_028 7 pos 41 23.92 F
HU_034 9 pos 52 23.37 M
Expand Down
10 changes: 9 additions & 1 deletion vignettes/w4mclassfilter.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ or to address several data issues that may impede downstream statistical analysi
* Features may be eliminated by specifying minimum or maximum intensity (or both) allowable in columns of `dataMatrix` for at least one sample for each feature ("range of row-maximum for each feature").
* Missing values in `dataMatrix` are imputed either to zero (by default) or to the result of a user-supplied imputation function.
* Features and samples that have zero variance are eliminated.
* Samples and features are sorted alphabetically in rows and columns of `variableMetadata`, `sampleMetadata`, and `dataMatrix`
* Samples and features are sorted alphabetically in rows and columns of `variableMetadata`, `sampleMetadata`, and `dataMatrix`
* By default, the names of the first columns of `variableMetadata` and `sampleMetadata` are set respectively to `"variableMetadata"` and `"sampleMetadata"`

### How the `w4m_filter_by_sample_class` function is used

Expand Down Expand Up @@ -264,3 +265,10 @@ R package v0.98.6
- Support eliminating features whose attributes fall outside specified ranges.
For more detail, see "Feature- and Sample-Elimination" above.
- Sort sample names and feature names because some statistical tools expect the same order in `dataMatrix` row and column names as in the corresponding metadata files.

### New in release v0.98.7 - rename first column of sample metadata

R package v0.98.7

- First column of sample metadata is by default renamed to "sampleMetadata" unless
argument 'name_smplmetadata_col1' is supplied and set to FALSE.

0 comments on commit f628764

Please sign in to comment.