Révision 7646593d src/R/nucleominer.R

b/src/R/nucleominer.R
445 445
	print(aggregate_intra_strain_nucs(samples))
446 446
})
447 447

  
448

  
449

  
450

  
451

  
448
flat_aggregated_intra_strain_nucs = function(# to flat aggregate_intra_strain_nucs function output
449
### This function builds a dataframe of all clusters obtain from aggregate_intra_strain_nucs function.
450
partial_strain_maps, ##<< the output of aggregate_intra_strain_nucs function
451
roi_index ##<< the index of the roi involved
452
) {
453
	if  (length(partial_strain_maps) == 0 ){
454
		print(paste("Empty partial_strain_maps for roi", roi_index, "ands strain", strain, "." ))
455
    tmp_strain_maps = list()  
456
	} else {
457
		tmp_strain_map = apply(t(1:length(partial_strain_maps)), 2, function(i){
458
			tmp_nuc = partial_strain_maps[[i]]
459
			tmp_nuc_as_list = list()
460
			tmp_nuc_as_list[["chr"]] = tmp_nuc[["chr"]]
461
			tmp_nuc_as_list[["lower_bound"]] = ceiling(tmp_nuc[["lower_bound"]])
462
			tmp_nuc_as_list[["upper_bound"]] = floor(tmp_nuc[["upper_bound"]])
463
			tmp_nuc_as_list[["roi_index"]] = roi_index
464
			tmp_nuc_as_list[["index_nuc"]] = i
465
			tmp_nuc_as_list[["wp"]] = as.integer(tmp_nuc$wp)
466
			all_original_reads = c()
467
			for (j in 1:length(tmp_nuc$nucs)) {
468
				all_original_reads = c(all_original_reads, tmp_nuc$nucs[[j]]$original_reads)
469
			}
470
			tmp_nuc_as_list[["nb_reads"]] = length(all_original_reads)
471
			if (tmp_nuc$wp) {
472
				tmp_nuc_as_list[["lod_1"]] = signif(tmp_nuc$nucs[[2]]$lod_score,5)
473
				tmp_nuc_as_list[["lod_2"]] = signif(tmp_nuc$nucs[[3]]$lod_score,5)
474
			} else {
475
				tmp_nuc_as_list[["lod_1"]] = NA
476
				tmp_nuc_as_list[["lod_2"]] = NA							
477
			}
478
      return(tmp_nuc_as_list)
479
    })
480
    tmp_strain_maps = do.call("rbind", tmp_strain_map)
481
	}
482
  return(data.frame(tmp_strain_maps))
483
### Returns a dataframe of all clusters obtain from aggregate_intra_strain_nucs function.
484
}
452 485

  
453 486
align_inter_strain_nucs = structure(function(# Aligns nucleosomes between 2 strains.
454 487
### This function aligns nucs between two strains for a given genome region.
......
2056 2089
plot_gaussian_reads = TRUE,  ##<< Plot (or not) gaussian model of a F anf R reads.
2057 2090
plot_gaussian_unified_reads = TRUE,  ##<< Plot (or not) gaussian model of a nuc.
2058 2091
plot_ellipse_nucs = TRUE,  ##<< Plot (or not) ellipse for a nuc.
2092
change_col = TRUE, ##<< Change the color of each nucleosome.
2059 2093
plot_wp_nucs = TRUE,  ##<< Plot (or not) cluster of nucs
2060 2094
plot_wp_nuc_model = TRUE,  ##<< Plot (or not) gaussian model for a cluster of nucs
2061 2095
plot_common_nucs = TRUE,  ##<< Plot (or not) aligned reads.
......
2166 2200
				if (length(nucs$center) > 0) {
2167 2201
					col = 1
2168 2202
		      for (i in 1:length(nucs$center)) {
2169
						col = col + 1
2203
            if (change_col) {
2204
  						col = col + 1              
2205
            }
2170 2206
		        nuc = nucs[i,]
2171 2207
						involved_reads = filter_tf_inputs(reads, sample$roi$chr, nuc$lower_bound, nuc$upper_bound, nuc_width = nuc$width)
2172 2208
				  	involved_signs = apply(t(involved_reads[,3]), 2, function(strand) {	if (strand == "F") return(1) else return(-1)})
......
2202 2238
	  # Plot wp nucs
2203 2239
		if ((plot_wp_nucs_4_nonmnase | sample$marker == "Mnase_Seq") & (plot_wp_nucs | plot_common_nucs | plot_chain)) {
2204 2240
			if (samples[[1]]$marker == "Mnase_Seq") {
2205
				if (is.null(aggregated_intra_strain_nucs)) {
2241
				if (is.null(aggregated_intra_strain_nucs)) {      
2206 2242
	  			wp_nucs = aggregate_intra_strain_nucs(samples)[[1]]			
2207
          foo <<- wp_nucs
2208 2243
				} else {
2209 2244
					wp_nucs = aggregated_intra_strain_nucs[[replicate_rank]]
2210 2245
				}
2211 2246
		  } else {
2212 2247
  			wp_nucs = replicates_wp_nucs[[replicate_rank-2]]
2213 2248
		  }
2214
      
2215 2249
      if (plot_chain) {
2216 2250
        tf_nucs = lapply(wp_nucs, function(nuc) {      
2217 2251
          bar = apply(t(nuc$nucs), 2, function(tmp_nuc){
......
2251 2285
        points(tmp_x, tmp_y, cex=4, pch=16, col="white")
2252 2286
        points(tmp_x, tmp_y, cex=4, lw=2)
2253 2287
        text(tmp_x, tmp_y, 1:nrow(tf_nucs))
2254
        text(tmp_x_inter, tmp_y_inter, tmp_lod_inter, col=(tmp_lod_inter < 20) + 2)  
2288
        text(tmp_x_inter, tmp_y_inter, tmp_lod_inter, srt=90, cex=0.9, bg = "yellow")#, col=(tmp_lod_inter < 20) + 2)  
2255 2289
      }
2256 2290
  
2257 2291
      if (plot_wp_nucs | plot_common_nucs ) {

Formats disponibles : Unified diff