Commit 5516fd5b authored by Chaos's avatar Chaos
Browse files

更新 R/utilities.R, R/gtf.R, R/chr_size.R

parent 3db9a761
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ chr_size <- function(
				extra = FALSE,
				online = FALSE
){
	extdata_dir <- "~/.config/chaos.tools"
	extdata_dir <- chaos_info("data_dir")
	chr_size_data <- file.path(extdata_dir,"chr_size.rds")

	if(!file.exists(chr_size_data)){
+39 −17
Original line number Diff line number Diff line
chaos_anno <- function(organism,type = NA){
	if(organism == "human"){
		info <- c(ref = "hg38", anno_v = "v42")
	}else if(organism == "mouse"){
		info <- c(ref = "mm39", anno_v = "vM31")
	}
	if(is.na(type)){
		info
	}else if(type %in% names(info)){
		info[type]
	}
}

gtf <-	function(
			organism,
			type = NA
){
	ref <- chaos_anno(organism,"ref")
	anno_v <- chaos_anno(organism,"anno_v")

	gtf_file <- paste0(
					"~/Reference/",
					chaos_anno(organism,"ref"),
					ref,
					"/annotation/gencode.",
					chaos_anno(organism,"anno_v"),
					anno_v,
					".annotation.gtf.gz"
				)

	type.list <- c("gene","transcript","exon","CDS","start_codon","stop_codon","UTR","Selenocysteine")
	type <- type %>% .[. %in% type.list]

	if(length(type) == 0){type <- NA}

	if(length(type) == 1){
		if(is.na(type)){
			rds_file <- gsub(".gz",".rds",gtf_file)
			type.str <- NULL
	if(length(type) == 0){
		type_str <- NULL
	}else{
			rds_file <- gsub(".gz",paste0(".",type,".rds"),gtf_file)
			type.str <- type
		type_str <-	type.list %>% 
					.[. %in% type] %>% 
					paste0(collapse = ".") %>% 
					paste0(".",.,".rds")
	}
		if(!file.exists(rds_file)){
			r <- import(gtf_file,feature.type = type.str)
			saveRDS(r,rds_file)
			r
		}else{

	rds_file <-	paste0(
					chaos_info("data_dir"),
					"/",
					ref,
					".gencode.",
					anno_v,
					".annotation.gtf",
					type_str
				)

	if(file.exists(rds_file)){
		readRDS(rds_file)
		}
	}else{
		import(gtf_file,feature.type = type.str)
		gtf <- BiocIO::import(gtf_file,feature.type = type)
		saveRDS(gtf,rds_file,compress = "xz")
		gtf
	}
}
 No newline at end of file
+11 −29
Original line number Diff line number Diff line
@@ -4,15 +4,17 @@ cumdiff <- function(x)
}

chaos_info <-	function(
	type
					type = NA
){
	if(type == "data_dir"){
		"~/.config/chaos.tools"
	}else if(type == "name")
	{
		"chaos.tools"
	n <-	c(
				data_dir = "~/.extdata/chaos.tools",
				package_name = "chaos.tools"
			)
	if(is.na(type)){
		n
	}else if(type %in% names(n)){
		n[type]
	}
	
}

chaos_create_dir <-	function(
@@ -21,33 +23,13 @@ chaos_create_dir <- function(
	if(!dir.exists(dir)){dir.create(dir)}
}

chaos_anno <- function(organism,type = NA){
	if(organism == "human"){
		ref <- "hg38"
		anno_v <- "v42"
	}else if(organism == "mouse"){
		ref <- "mm39"
		anno_v <- "vM31"
	}
	if(is.na(type)){
		c(ref,anno_v)
	}else if(type == "ref"){
		ref
	}else if(type == "anno_v"){
		anno_v
	}
}

update_chaos <- function(
){
	package_name <- chaos_info("name")
	
	if(package_name %in% (.packages()))
	{
	if(chaos_info("package") %in% (.packages())){
		detach("package:chaos.tools",unload = T)
	}

	paste0("https://mirrors.sustech.edu.cn/git/fc-ibb105/", package_name,".git") |>
	paste0("https://mirrors.sustech.edu.cn/git/fc-ibb105/",chaos_info[package_name],".git") |>
	devtools::install_git()

	library(chaos.tools)