Commit 0223151b authored by Chaos's avatar Chaos
Browse files

add function rnaseqqc()

parent e74fed4b
Loading
Loading
Loading
Loading
+57 −0
Original line number Diff line number Diff line
@@ -475,3 +475,60 @@ sub_volcano_plot <- function(
	}
}

rnaseqqc <- function(
				count_file,
				sample = NA,
				group = NA,
				organism = "human",
				count_type = "star",
				plot_type = "mds"
){
	g.number <- length(group)

	if(g.number != length(count_file)){
		stop()
	}else{
		g.color <- as.factor(group)
		if(g.number <= 10){
			levels(g.color) <- sample(chaos_color(),g.number)
		}else{
			levels(g.color) <- colorRampPalette(chaos_color())(n)
		}
		g.color <- as.character(g.color)
	}

	if(is.na(sample) | length(sample) != length(count_file)){
		sample <- gsub("_ReadsPerGene.out.tab","",count_file)
	}

	if(tolower(count_type) == "star"){
		cols <- c(1, 2)
		header_str <- TRUE
		skip_rows <- 4
	}else if(tolower(count_type) == "featurecounts")
	{
		cols <- c(1, 7)
		header_str <- FALSE
		skip_rows <- 1
	}

	x <-	readDGE(
				count_file,
				columns = cols,
				header = header_str,
				skip = skip_rows
			) %>% 
			.[
				filterByExpr(.), 
				keep.lib.sizes = F
			] |>
			calcNormFactors(method = "TMM") |>
			cpm(log = T)

	if(plot_type == "mds"){
		plotMDS(x, labels = sample,col = g.color)
	}else if(plot_type == "glmds"){
		Glimma::glMDSPlot(x, labels = sample, launch = F,groups = group)
		print("figure saved in ./glimma-plots")
	}
}
 No newline at end of file