Mercurial > repos > proteore > proteore_clusterprofiler
diff GO-enrich.R @ 5:36c586c918eb draft
planemo upload commit 654ba92763264fb669b084d7939700f8f1180217-dirty
| author | proteore |
|---|---|
| date | Tue, 18 Sep 2018 08:25:17 -0400 |
| parents | 18275725e7cf |
| children | 2b14f4f8e128 |
line wrap: on
line diff
--- a/GO-enrich.R Mon Sep 17 10:30:30 2018 -0400 +++ b/GO-enrich.R Tue Sep 18 08:25:17 2018 -0400 @@ -20,6 +20,7 @@ return(file) } +#return the number of character from the longest description found (from the 10 first) max_str_length_10_first <- function(vector){ vector <- as.vector(vector) nb_description = length(vector) @@ -27,6 +28,18 @@ return(max(nchar(vector[1:nb_description]))) } +width_by_max_char <- function (nb_max_char) { + if (nb_max_char < 50 ){ + width=600 + } else if (nb_max_char < 75) { + width=800 + } else if (nb_max_char < 100) { + width=900 + } else { + width=1000 + } + return (width) +} repartition.GO <- function(geneid, orgdb, ontology, level=3, readable=TRUE) { ggo<-groupGO(gene=geneid, @@ -35,12 +48,9 @@ level=level, readable=TRUE) - if (max_str_length_10_first(ggo$Description) > 50 ){ - width=720 - } else { - width=600 - } - + ggo@result$Description <- sapply(ggo@result$Description, function(x) {ifelse(nchar(x)>100, substr(x,1,100),x)},USE.NAMES = FALSE) + nb_max_char = max_str_length_10_first(ggo$Description) + width = width_by_max_char(nb_max_char) name <- paste("GGO_", ontology, "_bar-plot", sep = "") png(name,height = 720, width = width) p <- barplot(ggo, showCategory=10) @@ -55,21 +65,19 @@ universe=universe, OrgDb=orgdb, ont=ontology, - keytype="ENTREZID", pAdjustMethod="BH", pvalueCutoff=pval_cutoff, qvalueCutoff=qval_cutoff, readable=TRUE) - if (max_str_length_10_first(ego$Description) > 50 ){ - width=800 - } else { - width=600 - } - # Plot bar & dot plots #if there are enriched GopTerms if (length(ego$ID)>0){ + + ego@result$Description <- sapply(ego@result$Description, function(x) {ifelse(nchar(x)>100, substr(x,1,100),x)},USE.NAMES = FALSE) + nb_max_char = max_str_length_10_first(ego$Description) + width = width_by_max_char(nb_max_char) + if ("dotplot" %in% plot ){ dot_name <- paste("EGO_", ontology, "_dot-plot", sep = "") png(dot_name,height = 720, width = width)
