Take a subset of columns and create a new MTX file-set
mmutil_copy_selected_columns.Rd
Take a subset of columns and create a new MTX file-set
Usage
mmutil_copy_selected_columns(
mtx_file,
row_file,
col_file,
r_selected,
output,
MAX_COL_WORD = 100L,
COL_WORD_SEP = "@"
)
Examples
options(stringsAsFactors=FALSE)
rr <- rgamma(20, 1, 1)
mm <- matrix(rgamma(10 * 2, 1, 1), 10, 2)
src.hdr <- "test_org"
src.files <- mmutil_simulate_poisson(mm, rr, src.hdr)
Y <- Matrix::readMM(src.files$mtx)
colnames(Y) <- read.table(src.files$col)$V1
print(Y)
#> 10 x 17 sparse Matrix of class "dgTMatrix"
#> [[ suppressing 17 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> [1,] 2 . 2 . 1 . . . 4 2 . 1 . . . 3 2
#> [2,] . . . . . 1 . 1 2 . 1 1 . . . . .
#> [3,] . 1 . . . 2 1 . 1 . . 2 . . 1 1 .
#> [4,] . 1 . . 1 1 . . . . . . . . . . .
#> [5,] . . . . . 2 . . . . . . 1 . . . .
#> [6,] . . . . . . . . . 1 . . . . . 1 2
#> [7,] 5 4 3 . 3 5 3 . 12 4 . 10 . 1 . 2 1
#> [8,] . . . . 1 . . . . . . . 2 . . . .
#> [9,] 4 2 7 2 14 11 3 3 16 15 2 12 . . . 3 .
#> [10,] 1 . 1 1 1 1 . . . 1 . 1 . . 1 . 4
sub.cols <- sort(read.table(src.files$col)$V1[sample(20,3)])
print(sub.cols)
#> [1] 1 5 11
tgt.hdr <- "test_sub"
tgt.files <- mmutil_copy_selected_columns(
src.files$mtx,
src.files$row,
src.files$col,
sub.cols, tgt.hdr)
Y <- Matrix::readMM(tgt.files$mtx)
colnames(Y) <- read.table(tgt.files$col)$V1
print(Y)
#> 10 x 3 sparse Matrix of class "dgTMatrix"
#> 1 5 11
#> [1,] 2 1 .
#> [2,] . . 1
#> [3,] . . .
#> [4,] . 1 .
#> [5,] . . .
#> [6,] . . .
#> [7,] 5 3 .
#> [8,] . 1 .
#> [9,] 4 14 2
#> [10,] 1 1 .
unlink(list.files(pattern = src.hdr))
unlink(list.files(pattern = tgt.hdr))