Skip to content

Commit

Permalink
feature table
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkimbrel committed Sep 29, 2023
1 parent f09e681 commit f17eae6
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 91 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: qSIP2
Title: qSIP Analysis
Version: 0.4.5.9003
Version: 0.4.5.9004
Authors@R:
person("Jeff", "Kimbrel", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "YOUR-ORCID-ID"))
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export(gradient_pos_density_validation)
export(gradient_position_validation)
export(isotope_validation)
export(plot_sample_curves)
export(qsip_abundance_object)
export(qsip_feature_data)
export(qsip_sample_data)
export(qsip_source_data)
export(remove_isotopolog_label)
Expand Down
63 changes: 0 additions & 63 deletions R/qsip_abundance_object.R

This file was deleted.

75 changes: 75 additions & 0 deletions R/qsip_feature_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#' qSIP feature table class
#'
#' A class to hold and validate a feature abundance table
#'
#' @slot data A dataframe or tibble
#' @slot feature_id Column name with unique taxa IDs
#'
#' @export
#'
#' @keywords object

qsip_feature_data <- S7::new_class(
"qsip_feature_data",
properties = list(
data = S7::class_data.frame,
feature_id = S7::class_character,
taxonomy = S7::class_data.frame
),
constructor = function(data, feature_id, taxonomy = data.frame()) {

# rename columns to standardized names
data = data |>
dplyr::select(feature_id = feature_id,
dplyr::everything()) |>
dplyr::ungroup()

S7::new_object(S7::S7_object(),
data = data,
feature_id = feature_id,
taxonomy = taxonomy)
},
validator = function(self) {
if (any(duplicated(self@data['feature_id']))) {
message(glue::glue("There appear to be duplicate ids in the {self@id} column"))
}

#qSIP2::abundance_validation(self@data, 'feature_id')

}
)



#' Add a taxonomy table to qSIP abundance data
#'
#' @param x An object of `qsip_feature_data` class
#' @param taxa A taxa table
#' @param id The column name for the taxa ids that match the ids in the
#' abundance table
#'
#' @export
#'
#' @keywords abundance

add_taxonomy <- S7::new_generic("add_taxonomy", "x")

S7::method(add_taxonomy, qsip_feature_data) <- function(x, taxa, feature_id) {

x_ids = x@data |> dplyr::pull(feature_id)
taxa_ids = taxa |> dplyr::pull(feature_id)

if (length(setdiff(x_ids, taxa_ids)) > 0) {
stop("some ids found in the abundance object are not found in the taxa table")
} else if (length(setdiff(taxa_ids, x_ids)) > 0) {
setdiff(taxa_ids, x_ids)
stop("some ids found in the taxa table are not found in the abundance object")
} else {

# rename taxa id column to the object level ID
x@taxonomy = taxa |>
dplyr::rename("feature_id" := feature_id)

x
}
}
4 changes: 2 additions & 2 deletions man/add_taxonomy.Rd

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

24 changes: 0 additions & 24 deletions man/qsip_abundance_object.Rd

This file was deleted.

20 changes: 20 additions & 0 deletions man/qsip_feature_data.Rd

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

0 comments on commit f17eae6

Please sign in to comment.