Take a subset of columns and create a new MTX file-set

rcpp_mmutil_copy_selected_columns(
  mtx_file,
  row_file,
  col_file,
  r_selected,
  output,
  MAX_COL_WORD = 100L,
  COL_WORD_SEP = "@"
)

Arguments

mtx_file

data file

row_file

row file

col_file

column file

selected

selected column names

Examples


options(stringsAsFactors=FALSE)
rr <- rgamma(20, 1, 1)
mm <- matrix(rgamma(10 * 2, 1, 1), 10, 2)
src.hdr <- "test_org"
src.files <- mmutilR::rcpp_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 20 sparse Matrix of class "dgTMatrix"
#>   [[ suppressing 20 column names ‘1’, ‘2’, ‘3’ ... ]]
#>                                                
#>  [1,] 1 4 3 1 1 3 1 5 . 2 1 2 . 2 1 1 1  3  6 1
#>  [2,] . 1 . . . 4 1 3 . 3 . 3 . . . . .  .  . .
#>  [3,] . 6 . 1 . 2 . 3 . 1 . 1 1 1 . . 3 12  7 2
#>  [4,] . 7 . 2 2 4 . 4 . 1 1 1 . . 1 2 1 30  7 1
#>  [5,] . 3 . . 1 2 1 2 . . 1 2 . . . . . 11  4 .
#>  [6,] . 4 2 . 3 1 1 8 1 3 1 5 . 1 . . 1  3  4 3
#>  [7,] 2 8 2 . 1 2 1 9 . 1 . 2 . 1 . 2 4 14 17 6
#>  [8,] . 2 1 1 4 4 2 8 . 1 2 2 1 . 1 3 2 26 18 4
#>  [9,] . . 1 . 2 . . 2 . . . 1 . . . . 4  5  5 .
#> [10,] . 3 1 1 2 3 . 2 . . 1 1 . . . . 1  5  1 .
sub.cols <- sort(read.table(src.files$col)$V1[sample(20,3)])
print(sub.cols)
#> [1]  9 10 11
tgt.hdr <- "test_sub"
tgt.files <- mmutilR::rcpp_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"
#>       9 10 11
#>  [1,] .  2  1
#>  [2,] .  3  .
#>  [3,] .  1  .
#>  [4,] .  1  1
#>  [5,] .  .  1
#>  [6,] 1  3  1
#>  [7,] .  1  .
#>  [8,] .  1  2
#>  [9,] .  .  .
#> [10,] .  .  1
unlink(list.files(pattern = src.hdr))
unlink(list.files(pattern = tgt.hdr))