Commit 366a7d07 authored by fc-ibb105's avatar fc-ibb105
Browse files

add function to read velocyto matrix from STARsolo

parent 3bf3353e
Loading
Loading
Loading
Loading

R/scRNA.R

0 → 100644
+50 −0
Original line number Diff line number Diff line
chaos.read_solo_meta <-	function(
							id,
							type,
							star_dir = "~/project.isynbio/mengqian/STAR_result",
							filtered = TRUE
){
	if(isTRUE(filtered)){
		filter_str <- "filtered"
	}else{
		filter_str <- "raw"
	}

	solo_dir <- file.path(star_dir,id,"Solo.out/Gene",filter_str)

	if(tolower(type) == "ensg"){
		file.path(solo_dir,"features.tsv.gz") |>
		fread(header = F) %>%
		.$V1
	}else if(tolower(type) == "symbol"){
		file.path(solo_dir,"features.tsv.gz") |>
		fread(header = F) %>%
		.$V2
	}else if(tolower(type) == "barcode"){
		file.path(solo_dir,"barcodes.tsv.gz") |>
		fread(header = F) %>%
		.$V1 %>%
		paste(id,.,sep = ":")
	}
}

chaos.read_solo_velocyto <-	function(
							id,
							star_dir = "~/project.isynbio/mengqian/STAR_result"
){
	mtx_dir <- file.path(star_dir,id,"Solo.out/Velocyto/filtered")

	mtxs <- c("unspliced","spliced","ambiguous")
	parallel::mclapply(
		mtxs,
		\(x){
			paste0(x,".mtx.gz") %>%
			file.path(mtx_dir,.) %>%
			Matrix::readMM() |>
			set_colnames(chaos.read_solo_meta(id,type = "barcode")) |>
			set_rownames(chaos.read_solo_meta(id,type = "symbol"))
		},
		mc.cores = 3
	) |>
	setNames(mtxs)
}
 No newline at end of file