Produce a weitrix of proportions between 0 and 1. The input is read counts at a collection of features in a collection of samples. The features need to be grouped, for example by gene. The proportions will add to 1 within each group.

counts_proportions(counts, grouping, verbose = TRUE, typecast = identity)

Arguments

counts

A matrix of read counts. Rows are peaks and columns are samples.

grouping

A data frame defining the grouping of features. Should have a column "group" naming the group and a column "name" naming the feature (corresponding to rownames(counts)).

verbose

If TRUE, output some debugging and progress information.

typecast

A function to convert a matrix to a matrix-like type. Applied at the chunk level, before all chunks are rbinded. Allows use of memory-efficient matrix representations.

Value

A SummarizedExperiment object with metadata fields marking it as a weitrix.

Examples

grouping <- data.frame( group=c("A","A","A","B","B"), name=c("p1","p2","p3","p4","p5")) counts <- rbind( p1=c(1,2,0), p2=c(0,1,0), p3=c(1,0,0), p4=c(0,0,1), p5=c(0,2,1)) wei <- counts_proportions(counts, grouping)
#> Calculating proportions in 1 blocks
weitrix_x(wei)
#> [,1] [,2] [,3] #> p1 0.5 0.6666667 NA #> p2 0.0 0.3333333 NA #> p3 0.5 0.0000000 NA #> p4 NA 0.0000000 0.5 #> p5 NA 1.0000000 0.5
#> [,1] [,2] [,3] #> p1 2 3 0 #> p2 2 3 0 #> p3 2 3 0 #> p4 0 2 2 #> p5 0 2 2
rowData(wei)
#> DataFrame with 5 rows and 3 columns #> group total_reads per_read_var #> <character> <numeric> <numeric> #> p1 A 5 0.2400 #> p2 A 5 0.1600 #> p3 A 5 0.1600 #> p4 B 4 0.1875 #> p5 B 4 0.1875