Learn R Programming

metacoder (version 0.3.7)

calc_prop_samples: Calculate the proportion of samples

Description

For a given table in a taxmap object, calculate the proportion of samples (i.e. columns) with greater than a minimum value.

Usage

calc_prop_samples(
  obj,
  data,
  cols = NULL,
  groups = "prop_samples",
  other_cols = FALSE,
  out_names = NULL,
  drop = FALSE,
  more_than = 0,
  dataset = NULL
)

Value

A tibble

Arguments

obj

A taxmap object

data

The name of a table in obj$data.

cols

The columns in data to use. By default, all numeric columns are used. Takes one of the following inputs:

TRUE/FALSE:

All/No columns will used.

Character vector:

The names of columns to use

Numeric vector:

The indexes of columns to use

Vector of TRUE/FALSE of length equal to the number of columns:

Use the columns corresponding to TRUE values.

groups

Group multiple columns per treatment/group. This should be a vector of group IDs (e.g. character, integer) the same length as cols that defines which samples go in which group. When used, there will be one column in the output for each unique value in groups.

other_cols

Preserve in the output non-target columns present in the input data. New columns will always be on the end. The "taxon_id" column will be preserved in the front. Takes one of the following inputs:

NULL:

No columns will be added back, not even the taxon id column.

TRUE/FALSE:

All/None of the non-target columns will be preserved.

Character vector:

The names of columns to preserve

Numeric vector:

The indexes of columns to preserve

Vector of TRUE/FALSE of length equal to the number of columns:

Preserve the columns corresponding to TRUE values.

out_names

The names of count columns in the output. Must be the same length and order as cols (or unique(groups), if groups is used).

drop

If groups is not used, return a vector of the results instead of a table with one column.

more_than

A sample must have greater than this value for it to be counted as present.

dataset

DEPRECIATED. use "data" instead.

See Also

Other calculations: calc_diff_abund_deseq2(), calc_group_mean(), calc_group_median(), calc_group_rsd(), calc_group_stat(), calc_n_samples(), calc_obs_props(), calc_taxon_abund(), compare_groups(), counts_to_presence(), rarefy_obs(), zero_low_counts()

Examples

Run this code
if (FALSE) {
# Parse data for example
x = parse_tax_data(hmp_otus, class_cols = "lineage", class_sep = ";",
                   class_key = c(tax_rank = "taxon_rank", tax_name = "taxon_name"),
                   class_regex = "^(.+)__(.+)$")
                   
# Count samples with at least one read
calc_prop_samples(x, data = "tax_data")

# Count samples with at least 5 reads
calc_prop_samples(x, data = "tax_data", more_than = 5)

# Return a vector instead of a table
calc_prop_samples(x, data = "tax_data", drop = TRUE)

# Only use some columns
calc_prop_samples(x, data = "tax_data", cols = hmp_samples$sample_id[1:5])

# Return a count for each treatment
calc_prop_samples(x, data = "tax_data", groups = hmp_samples$body_site)

# Rename output columns 
calc_prop_samples(x, data = "tax_data", groups = hmp_samples$body_site,
               out_names = c("A", "B", "C", "D", "E"))

# Preserve other columns from input
calc_prop_samples(x, data = "tax_data", other_cols = TRUE)
calc_prop_samples(x, data = "tax_data", other_cols = 2)
calc_prop_samples(x, data = "tax_data", other_cols = "otu_id")
}

Run the code above in your browser using DataLab