rcpp_mmutil_copy_selected_rows.Rd
For the new mtx file, empty columns with only zero elements will be removed.
rcpp_mmutil_copy_selected_rows(
mtx_file,
row_file,
col_file,
r_selected,
output,
MAX_ROW_WORD = 100L,
ROW_WORD_SEP = "@",
MAX_COL_WORD = 100L,
COL_WORD_SEP = "@"
)
data file
row file
column file
output
selected row names
a list of file names: output.mtx,rows,cols.gz
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)
rownames(Y) <- read.table(src.files$row)$V1
print(Y)
#> 10 x 18 sparse Matrix of class "dgTMatrix"
#>
#> r01 3 1 2 . 1 . . 6 2 2 2 2 2 2 . . 1 1
#> r02 3 3 1 1 5 3 1 12 12 11 7 1 1 . . 1 . 3
#> r03 2 6 1 . 2 1 . 11 4 3 11 4 . . 2 2 3 4
#> r04 . 1 . . . . . . . . . . . . . . 1 .
#> r05 . 1 . . . . . 1 . 1 . . . . . . . 2
#> r06 . . 1 . . . . 5 2 3 1 1 . . . 1 . .
#> r07 2 3 1 . . . 1 3 1 1 1 1 . 1 . 1 2 2
#> r08 . . . . . . . . . . . . . 1 . 2 . .
#> r09 . . 1 1 . . . 2 1 2 . 1 . . 1 . . .
#> r10 2 4 3 2 3 1 . 7 4 4 7 3 . . . . . .
sub.rows <- sort(read.table(src.files$row)$V1[sample(10,3)])
print(sub.rows)
#> [1] "r01" "r05" "r10"
tgt.hdr <- "test_sub"
tgt.files <- mmutilR::rcpp_mmutil_copy_selected_rows(
src.files$mtx,
src.files$row,
src.files$col,
sub.rows,
tgt.hdr)
Y <- Matrix::readMM(tgt.files$mtx)
colnames(Y) <- read.table(tgt.files$col)$V1
rownames(Y) <- read.table(tgt.files$row)$V1
print(Y)
#> 3 x 15 sparse Matrix of class "dgTMatrix"
#> [[ suppressing 15 column names ‘1’, ‘2’, ‘3’ ... ]]
#>
#> r01 3 1 2 . 1 . 6 2 2 2 2 2 2 1 1
#> r05 . 1 . . . . 1 . 1 . . . . . 2
#> r10 2 4 3 2 3 1 7 4 4 7 3 . . . .
unlink(list.files(pattern = src.hdr))
unlink(list.files(pattern = tgt.hdr))