-
Thierry Balliau authoredThierry Balliau authored
mcq_plot_aera_multiplex_effect.R 3.17 KiB
### method to plot area in log by triplex to show if there is a specifique effect for each triplex
mcq.plot.aera.multiplex.effect <- function(object, file=NULL, binwidth=0.25, type="histogram") {
error_messages <- list()
j=1
# if (!is.numeric(class)&!is.null(class)){
# error_messages[[j]] <- "class argument must be numeric"
# j=j+1
# }
if (!is.numeric(binwidth)){
error_messages[[j]] <- "binwidth argument must be numeric"
j=j+1
}
if(!is.character(file)&!is.null(file)){
error_messages[[j]] <- "file argument must be characters"
j=j+1
}
if (!(type %in% c("histogram", "density", "experimental"))){
error_messages[[j]] <- "file argument must be characters"
j=j+1
}
if (length(error_messages) != 0){
stop(paste("Error on argument format:\n", paste(error_messages, collapse="\n"), sep=""))
}
# if(class(object) == "cmcq.pepq.sds"){
# if(class(object[[1]]) %in% c("cmcq.pepq.masschroq.labeling","cmcq.pepq.masschroq")){
# ## preparing data
# data <- mcq.union.fraction.sds.corrected(object, verbose=FALSE)[[1]]
# inj <- data@metadata@injections
# meta <- data@metadata@metadata
# ### workaround because meta contains fraction column if generated with mcq.union.fraction.sds
# if("fraction" %in% colnames(meta)){
# meta <- meta[,-which(colnames(meta) %in% "fraction")]
# }
# inj$msrun_label <- paste(inj$msrun, inj$label, sep="_")
# meta <- cbind(inj, meta)
# pep <- as.data.table(data@peptides)
# meta <- as.data.table(meta)
# pep <- merge(pep, meta)
# }
# }else
if (class(object) == "cmcq.pepq.masschroq.labeling"){
inj <- object@metadata@injections
meta <- object@metadata@metadata
### workaround because meta contains fraction column if generated with mcq.union.fraction.sds
if("fraction" %in% colnames(meta)){
meta <- meta[,-which(colnames(meta) %in% "fraction")]
}
inj$msrun_label <- paste(inj$msrun, inj$label, sep="_")
meta <- cbind(inj, meta)
pep <- as.data.table(object@peptides)
meta <- as.data.table(meta)
pep <- merge(pep, meta)
}else{
stop(paste("the class \"", class(object),"\" is not taken into account by mcq.plot.aera.triplex.effect",sep=""))
}
p<- list()
if(type == "histogram"){
temp <- ggplot(pep, aes(x=logarea, fill=track))+geom_histogram(position= position_dodge2(padding= 0.1), binwidth = binwidth)+xlab("log10(area)")
temp <- temp + ggtitle("Distribution of log10(area) by triplex")
p[[1]] <- temp
}else if(type == "density"){
temp <- ggplot(pep, aes(x=logarea, fill=track, color=track))+geom_density(alpha=0.1)
temp <- temp + ggtitle("Distribution of log10(area) by triplex")
p[[1]] <- temp
}else if(type == "experimental"){
toplot <- priv.mcq.compute.hist(as.data.frame(pep), class=20, by="track", value="logarea")
temp <-ggplot(toplot, aes(x=mids, y=count, fill=track))+geom_bar(stat="identity", position=position_dodge2(padding=0.2))+ theme(axis.text.x = element_text(angle = 90, hjust = 1))+xlab("log10(area)")+ylab("count")
temp <- temp + ggtitle("Distribution of log10(area) by triplex")
p[[1]] <- temp
}
priv.mcq.visualisation.graph(p, file)
}