library(SoupX)
library(Seurat)
library(optparse)
library(magrittr)
options(future.globals.maxSize = 100000 * 1024^2)
option_list = list(
make_option(c("-n", "--name"), type="character", default=NULL,
help="dataset file name", metavar="character"),
make_option(c("-i", "--input10x"), type="character", default="outs",
help="10x input dirs [default= %default]", metavar="character"),
make_option(c("-c", "--input10x_h5"), action = 'store_true', default=FALSE,
help="Is the the file an H5 [default= %default]"),
make_option(c("-o", "--outdir"), type="character", default="./",
help="outpur dir [default= %default]", metavar="character")
)
opt_parser = OptionParser(option_list=option_list);
opt = parse_args(opt_parser);
outdir<- opt$outdir # All results will be saved here plots, RData file
#Should only take a single argument now. Don't support H5 files yet.
input10x<- stringr::str_split(opt$input10x,",")[[1]]
dir.create(outdir,recursive = TRUE)
# Read in count data ------------------------------------------------------
if(opt$input10x_h5){
print(paste0(input10x,'/filtered_feature_bc_matrix.h5'))
filt <- Read10X_h5(paste0(input10x,'/filtered_feature_bc_matrix.h5'))
raw<- Read10X_h5(paste0(input10x,'/raw_feature_bc_matrix.h5'))
filt <- filt$`Gene Expression`
raw <- raw$`Gene Expression`
}else{
filt <- Read10X(paste0(input10x,'/filtered/'))
raw<- Read10X(paste0(input10x,'/raw/'))
}
sc = SoupChannel(raw, filt)
#SoupX performs bettter with cluster info, do a basic analysis.
s <- CreateSeuratObject(counts = filt) %>%
SCTransform(verbose = F) %>%
RunPCA(verbose = F) %>%
RunUMAP(dims = 1:30, verbose = F) %>%
FindNeighbors(dims = 1:30, verbose = F) %>%
FindClusters(verbose = T)
meta <- s@meta.data
umap <- s@reductions$umap@cell.embeddings
sc <- setClusters(sc, setNames(meta$seurat_clusters, rownames(meta)))
sc <- setDR(sc, umap)
#Might need change forceAccept to true if get an error, should pass this as a cmdline argument
sc <- autoEstCont(sc,forceAccept = T)
adj.matrix <- adjustCounts(sc, roundToInt = T)
#DropletUtils:::write10xCounts("SoupTest", adj.matrix)
DropletUtils:::write10xCounts(
paste0(outdir,'/Filtered.h5'),
adj.matrix,
type = 'HDF5',
version = '3'
)