<commit_before># Some functions to generate plots for specific genes
# 
# Author: schlandi
###############################################################################

##' Generates a boxplot from the given data.
##' @param group1 values for sample group1
##' @param group2 values for sample group2
##' @param lab.group1 label for group1
##' @param lab.group2 label for group2
##' @param xlabel x-axis label 
##' @param ylabel y-axis label
##' @param main main header for the plot
##' @param pvalue pvalue that will be added to the plot as text
##' @param color.palette character vector with colors for plotting
##' @return the boxplot
##' @author <NAME>
boxplot = function(group1, group2, 
				   lab.group1="group1", lab.group2="group2", 
				   xlabel=NULL, ylabel=NULL, main=NULL, pvalue=NULL,
				   color.palette=c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) {
	if (!require(ggplot2)) {
		stop("Can't load required package \"ggplot2\"!")
	}
	
	temp = data.frame(values=c(group1, group2), 
			group=c(rep(lab.group1, times=length(group1)),
					rep(lab.group2, times=length(group2))))
	
	p = ggplot(temp, aes(x=group, y=values, fill=group)) +
			geom_boxplot(outlier.size=0, aes(alpha=0.3)) +
			geom_jitter(size=3) +
			guides(fill=FALSE, alpha=FALSE) +
			scale_colour_manual(values=color.palette) +
			generateTheme()
	
	if (!is.null(xlabel)) {
		p = p + xlab(xlabel)
	}
	if (!is.null(ylabel)) {
		p = p + ylab(ylabel)
	}
	if (!is.null(main)) {
		p = p + ggtitle(main)
	}
	if (!is.null(pvalue) && !is.na(pvalue)) {
		xpos = 1
		if (max(subset(temp, group==lab.group2)$values, na.rm=TRUE) > max(subset(temp, group==lab.group1)$values, na.rm=TRUE)) {
			xpos = 2
		}
		p = p + geom_text(x=xpos, y=max(temp$values, na.rm=TRUE), label=paste("FDR = ", signif(pvalue, digits=2), sep=""))
	}
	
	p
}

##' Generates a barplot from Project Achilles data. 
##' @param scores vector of phenotype scores from Project Achilles
##' @param upper.threshold threshold above which phenotype scores are considered to be significant
##' @param lower.threshold threshold below which phenotype scores are considered to be significant
##' @param main main header for the plot 
##' @return the plot
##' @author <NAME>
barplot = function(scores, upper.threshold=NULL, lower.threshold=NULL, main=NULL) {
	if (!require(ggplot2)) {
		stop("Can't load required package \"ggplot2\"!")
	}
	
	plotting.df = data.frame(phenoscore=scores, 
							 cls=sapply(names(scores), function(x) { str_sub(x, start=1, end=str_locate(x, "_")[1, 1]-1) }))
	
	p = ggplot(plotting.df, aes(x=cls, y=phenoscore, fill="#767676")) +
		geom_bar(stat="identity", position=position_dodge()) +
		geom_hline(yintercept=0, linetype=1) +
		xlab("Cell lines") +
		ylab("Achilles phenotype score") +
		guides(fill=FALSE) +
		generateTheme()<commit_msg>Add required package to barplot()<commit_after># Some functions to generate plots for specific genes
# 
# Author: schlandi
###############################################################################

##' Generates a boxplot from the given data.
##' @param group1 values for sample group1
##' @param group2 values for sample group2
##' @param lab.group1 label for group1
##' @param lab.group2 label for group2
##' @param xlabel x-axis label 
##' @param ylabel y-axis label
##' @param main main header for the plot
##' @param pvalue pvalue that will be added to the plot as text
##' @param color.palette character vector with colors for plotting
##' @return the boxplot
##' @author <NAME>
boxplot = function(group1, group2, 
				   lab.group1="group1", lab.group2="group2", 
				   xlabel=NULL, ylabel=NULL, main=NULL, pvalue=NULL,
				   color.palette=c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")) {
	if (!require(ggplot2)) {
		stop("Can't load required package \"ggplot2\"!")
	}
	
	temp = data.frame(values=c(group1, group2), 
			group=c(rep(lab.group1, times=length(group1)),
					rep(lab.group2, times=length(group2))))
	
	p = ggplot(temp, aes(x=group, y=values, fill=group)) +
			geom_boxplot(outlier.size=0, aes(alpha=0.3)) +
			geom_jitter(size=3) +
			guides(fill=FALSE, alpha=FALSE) +
			scale_colour_manual(values=color.palette) +
			generateTheme()
	
	if (!is.null(xlabel)) {
		p = p + xlab(xlabel)
	}
	if (!is.null(ylabel)) {
		p = p + ylab(ylabel)
	}
	if (!is.null(main)) {
		p = p + ggtitle(main)
	}
	if (!is.null(pvalue) && !is.na(pvalue)) {
		xpos = 1
		if (max(subset(temp, group==lab.group2)$values, na.rm=TRUE) > max(subset(temp, group==lab.group1)$values, na.rm=TRUE)) {
			xpos = 2
		}
		p = p + geom_text(x=xpos, y=max(temp$values, na.rm=TRUE), label=paste("FDR = ", signif(pvalue, digits=2), sep=""))
	}
	
	p
}

##' Generates a barplot from Project Achilles data. 
##' @param scores vector of phenotype scores from Project Achilles
##' @param upper.threshold threshold above which phenotype scores are considered to be significant
##' @param lower.threshold threshold below which phenotype scores are considered to be significant
##' @param main main header for the plot 
##' @return the plot
##' @author <NAME>
barplot = function(scores, upper.threshold=NULL, lower.threshold=NULL, main=NULL) {
	if (!require(ggplot2)) {
		stop("Can't load required package \"ggplot2\"!")
	}
	
	if (!require(stringr)) {
		stop("Can't load required package \"stringr\"!")
	}
	
	plotting.df = data.frame(phenoscore=scores, 
							 cls=sapply(names(scores), function(x) { str_sub(x, start=1, end=str_locate(x, "_")[1, 1]-1) }))
	
	p = ggplot(plotting.df, aes(x=cls, y=phenoscore, fill="#767676")) +
		geom_bar(stat="identity", position=position_dodge()) +
		geom_hline(yintercept=0, linetype=1) +
		xlab("Cell lines") +
		ylab("Achilles phenotype score") +
		guides(fill=FALSE) +
		generateTheme()
{'fraction_non_alphanumeric': 0.18721856598545203, 'fraction_numerical': 0.025632144094215447, 'mean_word_length': 4.8451417004048585, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '555691', 'n_tokens_mistral': 2267, 'n_tokens_neox': 2052, 'n_words': 510}