Commit 402f0249 authored by Chaos's avatar Chaos
Browse files

modified RNA-seq.R in R

parent 41bd55ff
Loading
Loading
Loading
Loading
+70 −0
Original line number Diff line number Diff line
@@ -600,3 +600,73 @@ rnaseqqc <- function(
		cor(x) |> pheatmap::pheatmap(display_numbers = T)
	}
}


venn_plot <-	function(
					.data,
					regulation = "up",
					fold_change = 2,
					p_value = 0.01,
					dt = FALSE,
					list = FALSE,
					group = NULL
){
	other_cols <-  c("gene_id","gene_name","AveExpr","F","P.Value","adj.P.Val")
	samples <-	colnames(.data) %>% 
				.[! . %in% other_cols]

	x.list <-	lapply(
					samples,
					\(x){
						cols <- c(x,other_cols)
						.data[,..cols] %>% 
						setnames(
							old = x,
							new = "log2FC"
						) %>% 
						de.gene(
							regulation = regulation,
							fold_change = fold_change,
							p_value = p_value
						)
					}
				) %>%
				setNames(.,samples)

	venn_dt <-	Venn(x.list) |>
				process_region_data() %>%
				data.table()

	if(isTRUE(list)){
		x.list
	}else{
		if(isFALSE(dt)){
			ggVennDiagram(
				x.list,
				label_percent_digit = 2,
				label_alpha = 0
			) +
			scale_fill_gradient(
				low = "white",
				high = "#b9292b",
				name = "gene count"
			) +
			annotate(
				"text",
				label = paste0("Fold change > ",fold_change,"\np-value < ",p_value),
				x = 1,
				y = 1,
				hjust = 0
			)
		}else{
			if(is.null(group)){
				venn_dt
			}else{
				if(group %in% 1:7){
					venn_dt[group,item] %>% 
					unlist()
				}
			}
		}
	}
}
 No newline at end of file