Skip to content

Commit

Permalink
Merge pull request #117 from Klangina/Issue-116
Browse files Browse the repository at this point in the history
Fixes Issue #116
  • Loading branch information
the-mayer authored Nov 1, 2024
2 parents b758992 + 6d13451 commit aacda7d
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 60 deletions.
100 changes: 54 additions & 46 deletions R/summarize.R
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ summarizeByLineage <- function(prot = "prot", column = "DomArch", by = "Lineage"
#' named `DomArch` and `Lineage`.
#'
#' @importFrom dplyr arrange count desc filter group_by summarise
#' @importFrom rlang .data
#'
#' @return A tibble summarizing the counts of unique domain architectures
#' (`DomArch`) per lineage (`Lineage`). The resulting table contains three
Expand All @@ -443,7 +444,7 @@ summarizeByLineage <- function(prot = "prot", column = "DomArch", by = "Lineage"
#'
#' @examples
#' \dontrun{
#' summarizeDomArch_ByLineage()
#' summarizeDomArch_ByLineage(data1)
#' }
summarizeDomArch_ByLineage <- function(x) {
# Check if 'x' is a data frame
Expand All @@ -460,8 +461,8 @@ summarizeDomArch_ByLineage <- function(x) {
missing:", paste(missing_columns, collapse = ", ")))
}
x %>%
filter(!grepl("^-$", DomArch)) %>%
group_by(DomArch, Lineage) %>%
filter(!grepl("^-$", .data$DomArch)) %>%
group_by(.data$DomArch, .data$Lineage) %>%
summarise(count = n()) %>% # , bin=as.numeric(as.logical(n()))
arrange(desc(count))
}
Expand All @@ -476,7 +477,8 @@ summarizeDomArch_ByLineage <- function(x) {
#' named `DomArch` and a count column, such as `count`, which represents the
#' occurrences of each architecture in various lineages.
#'
#' @importFrom dplyr arrange group_by filter summarise
#' @importFrom dplyr arrange group_by filter summarise desc
#' @importFrom rlang .data
#'
#' @return A tibble summarizing each unique `DomArch`, along with the following
#' columns:
Expand All @@ -489,19 +491,22 @@ summarizeDomArch_ByLineage <- function(x) {
#'
#' @examples
#' \dontrun{
#' summarizeDomArch()
#' summarizeDomArch(data1)
#' }
summarizeDomArch <- function(x) {
# Check if 'x' is a data frame
if (!is.data.frame(x)) {
abort("Error: 'x' must be a data frame.")
}
x %>%
group_by(DomArch) %>%
summarise(totalcount = sum(count), totallin = n()) %>% # totallin=n_distinct(Lineage),
arrange(desc(totallin), desc(totalcount)) %>%
filter(!grepl(" \\{n\\}", DomArch)) %>%
filter(!grepl("^-$", DomArch))
group_by(.data$DomArch) %>%
summarise(
totalcount = sum(.data$count),
totallin = n()
) %>%
arrange(desc(.data$totallin), desc(.data$totalcount)) %>%
filter(!grepl(" \\{n\\}", .data$DomArch)) %>%
filter(!grepl("^-$", .data$DomArch))
}

#' summarizeGenContext_ByDomArchLineage
Expand All @@ -510,6 +515,7 @@ summarizeDomArch <- function(x) {
#' named `GenContext`, `DomArch`, and `Lineage`.
#'
#' @importFrom dplyr arrange desc filter group_by n summarise
#' @importFrom rlang .data
#'
#' @return A tibble summarizing each unique combination of `GenContext`,
#' `DomArch`, and `Lineage`, along with the following columns:
Expand All @@ -525,89 +531,91 @@ summarizeDomArch <- function(x) {
#'
#' @examples
#' \dontrun{
#' summarizeGenContext_ByDomArchLineage
#' summarizeGenContext_ByDomArchLineage(your_data)
#' }
summarizeGenContext_ByDomArchLineage <- function(x) {
# Check if 'x' is a data frame
if (!is.data.frame(x)) {
abort("Error: 'x' must be a data frame.")
}
x %>%
filter(!grepl("^-$", GenContext)) %>%
filter(!grepl("^-$", DomArch)) %>%
filter(!grepl("^-$", Lineage)) %>%
filter(!grepl("^NA$", DomArch)) %>%
group_by(GenContext, DomArch, Lineage) %>%
summarise(count = n()) %>% # , bin=as.numeric(as.logical(n()))
arrange(desc(count))
filter(!grepl("^-$", .data$GenContext)) %>%
filter(!grepl("^-$", .data$DomArch)) %>%
filter(!grepl("^-$", .data$Lineage)) %>%
filter(!grepl("^NA$", .data$DomArch)) %>%
group_by(.data$GenContext, .data$DomArch, .data$Lineage) %>%
summarise(count = n()) %>%
arrange(desc(.data$count))
}

#' summarizeGenContext_ByLineage
#'
#' @param x A dataframe or tibble containing the data.
#' @param x A dataframe or tibble containing the data. It must have columns
#' named `GenContext`, `DomArch`, and `Lineage`.
#'
#' @importFrom dplyr arrange desc filter group_by n summarise
#' @importFrom rlang .data
#'
#' @return Describe return, in detail
#' @return A tibble summarizing each unique combination of `GenContext` and `Lineage`,
#' along with the count of occurrences. The results are arranged in descending order of count.
#' @rdname MolEvolvR_summary
#' @export
#'
#' @examples
#' \dontrun{
#' summarizeGenContext_ByLineage()
#' summarizeGenContext_ByLineage(your_data)
#' }
summarizeGenContext_ByLineage <- function(x) {
# Check if 'x' is a data frame
if (!is.data.frame(x)) {
abort("Error: 'x' must be a data frame.")
}
x %>%
filter(!grepl("^-$", GenContext)) %>%
filter(!grepl("^-$", DomArch)) %>%
filter(!grepl("^-$", Lineage)) %>%
filter(!grepl("^NA$", DomArch)) %>%
group_by(GenContext, Lineage) %>% # DomArch.norep,
summarise(count = n()) %>% # , bin=as.numeric(as.logical(n()))
arrange(desc(count))
filter(!grepl("^-$", .data$GenContext)) %>%
filter(!grepl("^-$", .data$DomArch)) %>%
filter(!grepl("^-$", .data$Lineage)) %>%
filter(!grepl("^NA$", .data$DomArch)) %>%
group_by(.data$GenContext, .data$Lineage) %>%
summarise(count = n()) %>%
arrange(desc(.data$count))
}

#' summarizeGenContext
#'
#' @param x A dataframe or tibble containing the data. It must have columns
#' named `GenContext`, `DomArch`, and `Lineage`.
#' named `GenContext`, `DomArch`, `Lineage`, and `count`.
#'
#' @importFrom dplyr arrange desc filter group_by n n_distinct summarise
#' @importFrom dplyr arrange desc filter group_by n_distinct summarise
#' @importFrom rlang .data
#'
#' @return A tibble summarizing each unique combination of `GenContext` and
#' `Lineage`, along with the following columns:
#' - `GenContext`: The genomic context for each entry.
#' - `Lineage`: The lineage associated with each entry.
#' - `count`: The total number of occurrences for each combination of
#' `GenContext` and `Lineage`.
#' @return A tibble summarizing each unique `GenContext`, along with the following columns:
#' - `totalcount`: The total count for each `GenContext`.
#' - `totalDA`: The number of distinct `DomArch` for each `GenContext`.
#' - `totallin`: The number of distinct `Lineage` for each `GenContext`.
#'
#' The results are arranged in descending order of `count`.
#' The results are arranged in descending order of `totalcount`, `totalDA`, and `totallin`.
#' @rdname MolEvolvR_summary
#' @export
#'
#' @examples
#' \dontrun{
#' summarizeGenContext()
#' summarizeGenContext(data1)
#' }
summarizeGenContext <- function(x) {
# Check if 'x' is a data frame
if (!is.data.frame(x)) {
abort("Error: 'x' must be a data frame.")
}
x %>%
group_by(GenContext) %>%
group_by(.data$GenContext) %>%
summarise(
totalcount = sum(count),
totalDA = n_distinct(DomArch),
totallin = n_distinct(Lineage)
) %>% # totallin=n_distinct(Lineage),
arrange(desc(totalcount), desc(totalDA), desc(totallin)) %>%
filter(!grepl(" \\{n\\}", GenContext)) %>%
filter(!grepl("^-$", GenContext))
totalcount = sum(.data$count),
totalDA = n_distinct(.data$DomArch),
totallin = n_distinct(.data$Lineage)
) %>%
arrange(desc(.data$totalcount), desc(.data$totalDA), desc(.data$totallin)) %>%
filter(!grepl(" \\{n\\}", .data$GenContext)) %>%
filter(!grepl("^-$", .data$GenContext))
}


Expand Down
27 changes: 13 additions & 14 deletions man/MolEvolvR_summary.Rd

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

0 comments on commit aacda7d

Please sign in to comment.