Created
February 20, 2019 21:27
-
-
Save dosorio/5850bad8c502e56d7ec8843e5c3aed98 to your computer and use it in GitHub Desktop.
Function to read the binary output of salmon alevin in R (single-cell RNA-seq)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
readSalmonAlevin <- function(alevinFolder){ | |
matrixFile <- paste0(alevinFolder, "/quants_mat.gz") | |
matrixFile <- gzfile(description = matrixFile, open = 'rb') | |
genes <- readLines(paste0(alevinFolder,"/quants_mat_cols.txt")) | |
cells <- readLines(paste0(alevinFolder,"/quants_mat_rows.txt")) | |
n <- length(genes)*length(cells) | |
counts <- readBin(matrixFile,what = 'numeric', n = n) | |
close.connection(matrixFile) | |
countMatrix <- matrix(data = counts, | |
nrow = length(cells), | |
ncol = length(genes), | |
byrow = TRUE) | |
colnames(countMatrix) <- genes | |
rownames(countMatrix) <- cells | |
require(Matrix) | |
countMatrix <- as(countMatrix, "sparseMatrix") | |
countMatrix <- t(countMatrix) | |
return(countMatrix) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment