commit 7646593d26b4c098753c6dd9519fa429ff5230d8
Author: Florent Chuffart <florent.chuffart@ens-lyon.fr>
Date:   Tue Mar 4 14:43:40 2014 +0100

    Emproving flat_aggregated_intra_strain_nucs function

diff --git a/src/R/nucleominer.R b/src/R/nucleominer.R
index f4b8c85..6393b02 100644
--- a/src/R/nucleominer.R
+++ b/src/R/nucleominer.R
@@ -445,10 +445,43 @@ coord_max=20000000 ##<< A too big value to be a coord for a nucleosome lower bou
 	print(aggregate_intra_strain_nucs(samples))
 })
 
-
-
-
-
+flat_aggregated_intra_strain_nucs = function(# to flat aggregate_intra_strain_nucs function output
+### This function builds a dataframe of all clusters obtain from aggregate_intra_strain_nucs function.
+partial_strain_maps, ##<< the output of aggregate_intra_strain_nucs function
+roi_index ##<< the index of the roi involved
+) {
+	if  (length(partial_strain_maps) == 0 ){
+		print(paste("Empty partial_strain_maps for roi", roi_index, "ands strain", strain, "." ))
+    tmp_strain_maps = list()  
+	} else {
+		tmp_strain_map = apply(t(1:length(partial_strain_maps)), 2, function(i){
+			tmp_nuc = partial_strain_maps[[i]]
+			tmp_nuc_as_list = list()
+			tmp_nuc_as_list[["chr"]] = tmp_nuc[["chr"]]
+			tmp_nuc_as_list[["lower_bound"]] = ceiling(tmp_nuc[["lower_bound"]])
+			tmp_nuc_as_list[["upper_bound"]] = floor(tmp_nuc[["upper_bound"]])
+			tmp_nuc_as_list[["roi_index"]] = roi_index
+			tmp_nuc_as_list[["index_nuc"]] = i
+			tmp_nuc_as_list[["wp"]] = as.integer(tmp_nuc$wp)
+			all_original_reads = c()
+			for (j in 1:length(tmp_nuc$nucs)) {
+				all_original_reads = c(all_original_reads, tmp_nuc$nucs[[j]]$original_reads)
+			}
+			tmp_nuc_as_list[["nb_reads"]] = length(all_original_reads)
+			if (tmp_nuc$wp) {
+				tmp_nuc_as_list[["lod_1"]] = signif(tmp_nuc$nucs[[2]]$lod_score,5)
+				tmp_nuc_as_list[["lod_2"]] = signif(tmp_nuc$nucs[[3]]$lod_score,5)
+			} else {
+				tmp_nuc_as_list[["lod_1"]] = NA
+				tmp_nuc_as_list[["lod_2"]] = NA							
+			}
+      return(tmp_nuc_as_list)
+    })
+    tmp_strain_maps = do.call("rbind", tmp_strain_map)
+	}
+  return(data.frame(tmp_strain_maps))
+### Returns a dataframe of all clusters obtain from aggregate_intra_strain_nucs function.
+}
 
 align_inter_strain_nucs = structure(function(# Aligns nucleosomes between 2 strains.
 ### This function aligns nucs between two strains for a given genome region.
@@ -2056,6 +2089,7 @@ plot_coverage = FALSE,  ##<< Plot (or not) reads in the covergae fashion. fashio
 plot_gaussian_reads = TRUE,  ##<< Plot (or not) gaussian model of a F anf R reads.
 plot_gaussian_unified_reads = TRUE,  ##<< Plot (or not) gaussian model of a nuc.
 plot_ellipse_nucs = TRUE,  ##<< Plot (or not) ellipse for a nuc.
+change_col = TRUE, ##<< Change the color of each nucleosome.
 plot_wp_nucs = TRUE,  ##<< Plot (or not) cluster of nucs
 plot_wp_nuc_model = TRUE,  ##<< Plot (or not) gaussian model for a cluster of nucs
 plot_common_nucs = TRUE,  ##<< Plot (or not) aligned reads.
@@ -2166,7 +2200,9 @@ config=NULL ##<< GLOBAL config variable
 				if (length(nucs$center) > 0) {
 					col = 1
 		      for (i in 1:length(nucs$center)) {
-						col = col + 1
+            if (change_col) {
+  						col = col + 1              
+            }
 		        nuc = nucs[i,]
 						involved_reads = filter_tf_inputs(reads, sample$roi$chr, nuc$lower_bound, nuc$upper_bound, nuc_width = nuc$width)
 				  	involved_signs = apply(t(involved_reads[,3]), 2, function(strand) {	if (strand == "F") return(1) else return(-1)})
@@ -2202,16 +2238,14 @@ config=NULL ##<< GLOBAL config variable
 	  # Plot wp nucs
 		if ((plot_wp_nucs_4_nonmnase | sample$marker == "Mnase_Seq") & (plot_wp_nucs | plot_common_nucs | plot_chain)) {
 			if (samples[[1]]$marker == "Mnase_Seq") {
-				if (is.null(aggregated_intra_strain_nucs)) {
+				if (is.null(aggregated_intra_strain_nucs)) {      
 	  			wp_nucs = aggregate_intra_strain_nucs(samples)[[1]]			
-          foo <<- wp_nucs
 				} else {
 					wp_nucs = aggregated_intra_strain_nucs[[replicate_rank]]
 				}
 		  } else {
   			wp_nucs = replicates_wp_nucs[[replicate_rank-2]]
 		  }
-      
       if (plot_chain) {
         tf_nucs = lapply(wp_nucs, function(nuc) {      
           bar = apply(t(nuc$nucs), 2, function(tmp_nuc){
@@ -2251,7 +2285,7 @@ config=NULL ##<< GLOBAL config variable
         points(tmp_x, tmp_y, cex=4, pch=16, col="white")
         points(tmp_x, tmp_y, cex=4, lw=2)
         text(tmp_x, tmp_y, 1:nrow(tf_nucs))
-        text(tmp_x_inter, tmp_y_inter, tmp_lod_inter, col=(tmp_lod_inter < 20) + 2)  
+        text(tmp_x_inter, tmp_y_inter, tmp_lod_inter, srt=90, cex=0.9, bg = "yellow")#, col=(tmp_lod_inter < 20) + 2)  
       }
   
       if (plot_wp_nucs | plot_common_nucs ) {
