Skip to contents

For the new mtx file, empty columns with only zero elements will be removed.

Usage

mmutil_copy_selected_rows(
  mtx_file,
  row_file,
  col_file,
  r_selected,
  output,
  MAX_ROW_WORD = 2L,
  ROW_WORD_SEP = "_",
  MAX_COL_WORD = 100L,
  COL_WORD_SEP = "@"
)

Arguments

mtx_file

data file

row_file

row file

col_file

column file

output

output header

MAX_ROW_WORD

maximum words per line in row_file

ROW_WORD_SEP

word separation character to replace white space

selected

selected row names

Value

a list of file names: output.mtx,rows,cols.gz

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)
rownames(Y) <- read.table(src.files$row)$V1
print(Y)
#> 10 x 18 sparse Matrix of class "dgTMatrix"
#>                                        
#> r01 5 . 1 1 2 . 2 . . . 1 4 4 3 3 . . .
#> r02 3 . . 1 4 1 . 1 . 1 1 . . . . . . .
#> r03 1 1 . . 1 . . . . . 2 2 1 2 8 2 2 2
#> r04 . . . . . . . . . . . . 1 2 1 . 1 .
#> r05 . . . . . . . . . . . . . . . . . .
#> r06 . . . . . . . . . . . . 2 . 2 1 . .
#> r07 2 1 . . . . . . . . . 1 . 1 1 . 1 .
#> r08 3 . . 3 3 1 2 . 1 . 4 2 2 5 4 2 . .
#> r09 4 . . 4 2 1 1 . . 1 1 5 . . 3 . . .
#> r10 . . . . 1 . . . . . . . 3 3 6 . . .
sub.rows <- sort(read.table(src.files$row)$V1[sample(10,3)])
print(sub.rows)
#> [1] "r01" "r09" "r10"
tgt.hdr <- "test_sub"
tgt.files <- 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 12 sparse Matrix of class "dgTMatrix"
#>   [[ suppressing 12 column names ‘1’, ‘3’, ‘5’ ... ]]
#>                            
#> r01 5 1 1 2 . 2 . 1 4 4 3 3
#> r09 4 . 4 2 1 1 1 1 5 . . 3
#> r10 . . . 1 . . . . . 3 3 6
unlink(list.files(pattern = src.hdr))
unlink(list.files(pattern = tgt.hdr))