Commit cbdedb6c authored by Chaos's avatar Chaos
Browse files

modified RNA-seq.R in R

parent a109c4f3
Loading
Loading
Loading
Loading
+24 −15
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@ de.gene <- function(
	}
}


volcano_plot <- function(
					.data,
					top_gene_number = 10,
@@ -171,6 +172,7 @@ volcano_plot <- function(
					show_p = TRUE,
					show_fc = TRUE,
					show_gene_number = TRUE,
					show_legend = FALSE,
					sub_gene = NULL,
					sub_id = NULL,
					color_up = "#E64B35",
@@ -256,31 +258,33 @@ volcano_plot <- function(
				aes(log2FC,log10P),
				color = color_ns,
				size = 0.8,
				show.legend = F
				show.legend = show_legend
			) +
			geom_point(
				data = dt[color == "up"],
				aes(log2FC,log10P),
				color = color_up,
				size = 0.8,
				show.legend = F
				show.legend = show_legend
			) +
			geom_point(
					data = dt[color == "down"],
					aes(log2FC,log10P),
					color = color_down,
					size = 0.8,
					show.legend = F
					show.legend = show_legend
			) +
			geom_point(
					data = dt[color == "special"],
					aes(log2FC,log10P),
					color = color_special,
					size = 0.8,
					show.legend = F
					show.legend = show_legend
			)
	
	if(isFALSE(hyperbola)){
		xlimits <- max(abs(min(dt$log2FC)),abs(max(dt$log2FC)))

		plot <-	plot +
				geom_hline(
					yintercept = -log10(p_value),
@@ -291,21 +295,26 @@ volcano_plot <- function(
					xintercept = c(-log2(fold_change),log2(fold_change)),
					linetype = fc_line_type,
					color = right_fc_line_color
				)
				) +
				xlim(xlimits * -1, xlimits)
	}else{
		if(abs(min(dt$log2FC)) <= abs(max(dt$log2FC))){
			hyperbola_dt_r <-	dt[log2FC > 0,.(log2FC,hyperbola_log10P)]
			hyperbola_dt_l <-	dt[log2FC > 0,.(log2FC = log2FC * -1, hyperbola_log10P)]
		}else{
		   	hyperbola_dt_r <-	dt[log2FC < 0,.(log2FC,hyperbola_log10P)]
			hyperbola_dt_l <-	dt[log2FC < 0,.(log2FC = log2FC * -1, hyperbola_log10P)]
		}

		hyperbola_dt <- rbind(hyperbola_dt_l,hyperbola_dt_r)

		plot <-	plot +
				geom_line(
					data = dt[log2FC < 0],
					data = hyperbola_dt,
					aes(log2FC,hyperbola_log10P),
					linetype = fc_line_type,
					color = left_fc_line_color
				) +
				geom_line(
					data = dt[log2FC > 0],
					aes(log2FC,hyperbola_log10P),
					linetype = fc_line_type,
					color = right_fc_line_color
				) +
				scale_y_continuous(limits = c(0,max(dt$log10P) + 1))
	}

@@ -362,10 +371,10 @@ volcano_plot <- function(
		plot <-	plot +
				annotate(
					geom = "text",
					x = log2(fold_change) + 0.1,
					y = max(dt$log10P) + 1,
					x = min(dt$log2FC),
					y = -log10(p_value) - 0.3,
					hjust = 0,
					label = paste0("Fold Change threshold = ",fold_change)
					label = paste0("Fold Change = ",fold_change)
				)
	}