Révision 9fdbfada

b/doc/sphinx_doc/conf.py
50 50
# built documents.
51 51
#
52 52
# The short X.Y version.
53
version = '2.3.32'
53
version = '2.3.33'
54 54
# The full version, including alpha/beta/rc tags.
55
release = '2.3.32'
55
release = '2.3.33'
56 56

  
57 57
# The language for content autogenerated by Sphinx. Refer to documentation
58 58
# for a list of supported languages.
b/doc/sphinx_doc/rref.rst
986 986

  
987 987
Florent Chuffart
988 988

  
989
R: Compute the fuzzy list for a given strain.
990

  
991
Compute the fuzzy list for a given strain.
992
------------------------------------------
993

  
994
Description
995
~~~~~~~~~~~
996

  
997
This function grabs the nucleosomes detxted by template\_filter that
998
have been rejected bt aggregate\_intra\_strain\_nucs as well positions.
999

  
1000
Usage
1001
~~~~~
1002

  
1003
::
1004

  
1005
    get_intra_strain_fuzzy(wp_maps, roi, strain, config = NULL)
1006

  
1007
Arguments
1008
~~~~~~~~~
1009

  
1010
``wp_maps``
1011

  
1012
Well positionned nucleosomes map.
1013

  
1014
``roi``
1015

  
1016
The region of interest.
1017

  
1018
``strain``
1019

  
1020
The strain we want to extracvt the fuzzy map.
1021

  
1022
``config``
1023

  
1024
GLOBAL config variable.
1025

  
1026
Author(s)
1027
~~~~~~~~~
1028

  
1029
Florent Chuffart
1030

  
989 1031
R: Compute the list of SNEPs for a given set of marker, strain...
990 1032

  
991 1033
Compute the list of SNEPs for a given set of marker, strain combination and nuc form.
......
1042 1084
    # foo = get_sneps(marker, combi, form)
1043 1085
    # foo = get_sneps("H4K12ac", c("BY", "RM"), "wp")
1044 1086

  
1087
R: Compute the unaligned nucleosomal regions (UNRs).
1088

  
1089
Compute the unaligned nucleosomal regions (UNRs).
1090
-------------------------------------------------
1091

  
1092
Description
1093
~~~~~~~~~~~
1094

  
1095
This function aggregate non common wp nucs for each strain and substract
1096
common wp nucs. It does not take care about the size of the resulting
1097
UNR. It will be take into account in the count read part og the
1098
pipeline.
1099

  
1100
Usage
1101
~~~~~
1102

  
1103
::
1104

  
1105
    get_unrs(combi, roi, roi_index, wp_maps, fuzzy_maps, common_nuc_results, 
1106
        config = NULL)
1107

  
1108
Arguments
1109
~~~~~~~~~
1110

  
1111
``combi``
1112

  
1113
The strain combination to consider.
1114

  
1115
``roi``
1116

  
1117
The region of interest.
1118

  
1119
``roi_index``
1120

  
1121
The region of interest index.
1122

  
1123
``wp_maps``
1124

  
1125
Well positionned nucleosomes maps.
1126

  
1127
``fuzzy_maps``
1128

  
1129
Fuzzy nucleosomes maps.
1130

  
1131
``common_nuc_results``
1132

  
1133
Common wp nuc maps
1134

  
1135
``config``
1136

  
1137
GLOBAL config variable
1138

  
1139
Author(s)
1140
~~~~~~~~~
1141

  
1142
Florent Chuffart
1143

  
1045 1144
R: Returns the intersection of 2 list on regions.
1046 1145

  
1047 1146
Returns the intersection of 2 list on regions.
......
1153 1252
+---------------+---------------------------------------------------+
1154 1253
| Author:       | Florent Chuffart                                  |
1155 1254
+---------------+---------------------------------------------------+
1156
| Version:      | 2.3.32                                            |
1255
| Version:      | 2.3.33                                            |
1157 1256
+---------------+---------------------------------------------------+
1158 1257
| License:      | CeCILL                                            |
1159 1258
+---------------+---------------------------------------------------+
......
1485 1584
        plot_arrow_raw_reads = TRUE, plot_arrow_nuc_reads = TRUE, 
1486 1585
        plot_squared_reads = TRUE, plot_coverage = FALSE, plot_gaussian_reads = TRUE, 
1487 1586
        plot_gaussian_unified_reads = TRUE, plot_ellipse_nucs = TRUE, 
1488
        change_col = TRUE, plot_wp_nucs = TRUE, plot_wp_nuc_model = TRUE, 
1489
        plot_common_nucs = TRUE, plot_wp_nucs_4_nonmnase = FALSE, 
1490
        plot_chain = FALSE, aggregated_intra_strain_nucs = NULL, 
1587
        change_col = TRUE, plot_wp_nucs = TRUE, plot_fuzzy_nucs = TRUE, 
1588
        plot_wp_nuc_model = TRUE, plot_common_nucs = FALSE, plot_common_unrs = FALSE, 
1589
        plot_wp_nucs_4_nonmnase = FALSE, plot_chain = FALSE, aggregated_intra_strain_nucs = NULL, 
1491 1590
        aligned_inter_strain_nucs = NULL, height = 10, config = NULL)
1492 1591

  
1493 1592
Arguments
......
1541 1640

  
1542 1641
Plot (or not) cluster of nucs
1543 1642

  
1643
``plot_fuzzy_nucs``
1644

  
1645
Plot (or not) cluster of fuzzy
1646

  
1544 1647
``plot_wp_nuc_model``
1545 1648

  
1546 1649
Plot (or not) gaussian model for a cluster of nucs
......
1549 1652

  
1550 1653
Plot (or not) aligned reads.
1551 1654

  
1655
``plot_common_unrs``
1656

  
1657
Plot (or not) unaligned nucleosomal refgions (UNRs).
1658

  
1552 1659
``plot_wp_nucs_4_nonmnase``
1553 1660

  
1554 1661
Plot (or not) clusters for non inputs samples.
b/src/DESCRIPTION
1 1
Package: nucleominer
2 2
Maintainer: Florent Chuffart <florent.chuffart@ens-lyon.fr>
3 3
Author: Florent Chuffart
4
Version: 2.3.32
4
Version: 2.3.33
5 5
License: CeCILL 
6 6
Title: nm
7 7
Depends: seqinr, plotrix, DESeq, cachecache
b/src/NAMESPACE
1
export(flat_aggregated_intra_strain_nucs, FDR, lod_score_vecs, dfadd, filter_tf_inputs, filter_tf_outputs, sign_from_strand, flat_reads, get_comp_strand, aggregate_intra_strain_nucs, align_inter_strain_nucs, translate_roi, fetch_mnase_replicates, substract_region, union_regions, collapse_regions, translate_regions, crop_fuzzy, get_all_reads, get_design, plot_dist_samples, analyse_design, get_sneps, watch_samples, compute_inter_all_strain_curs, switch_pairlist, build_replicates, ARAB2ROM, ROM2ARAB)
1
export(flat_aggregated_intra_strain_nucs, FDR, lod_score_vecs, dfadd, filter_tf_inputs, filter_tf_outputs, sign_from_strand, flat_reads, get_comp_strand, aggregate_intra_strain_nucs, align_inter_strain_nucs, translate_roi, fetch_mnase_replicates, substract_region, union_regions, collapse_regions, translate_regions, crop_fuzzy, get_all_reads, get_design, plot_dist_samples, analyse_design, get_sneps, watch_samples, compute_inter_all_strain_curs, switch_pairlist, build_replicates, ARAB2ROM, ROM2ARAB, get_intra_strain_fuzzy, get_unrs)
b/src/R/nucleominer.R
876 876
roi ##<< The region of interest.
877 877
) {
878 878
  tr_regions = apply(t(1:length(regions[,1])), 2, function(i) {
879
    print(i)
880 879
    tmp_regions_ref2 = list(name="foo", begin=regions[i,]$lower_bound, end=regions[i,]$upper_bound, chr=as.character(regions[i,]$chr), strain_ref = combi[2])
881 880
    big_roi =  roi
882 881
    trs_tmp_regions_ref2 = translate_roi(tmp_regions_ref2, combi[1], config = config, big_roi = big_roi)
......
1833 1832
plot_ellipse_nucs = TRUE,  ##<< Plot (or not) ellipse for a nuc.
1834 1833
change_col = TRUE, ##<< Change the color of each nucleosome.
1835 1834
plot_wp_nucs = TRUE,  ##<< Plot (or not) cluster of nucs
1835
plot_fuzzy_nucs = TRUE,  ##<< Plot (or not) cluster of fuzzy
1836 1836
plot_wp_nuc_model = TRUE,  ##<< Plot (or not) gaussian model for a cluster of nucs
1837
plot_common_nucs = TRUE,  ##<< Plot (or not) aligned reads.
1837
plot_common_nucs = FALSE,  ##<< Plot (or not) aligned reads.
1838
plot_common_unrs = FALSE,  ##<< Plot (or not) unaligned nucleosomal refgions (UNRs).
1838 1839
plot_wp_nucs_4_nonmnase = FALSE,  ##<< Plot (or not) clusters for non inputs samples.
1839 1840
plot_chain = FALSE,  ##<< Plot (or not) clusterised nuceosomes between mnase samples.
1840 1841
aggregated_intra_strain_nucs = NULL, ##<< list of aggregated intra strain nucs. If NULL, it will be computed.
......
1865 1866
  axis(2, at=0:(nb_rank_glo*2) * delta_y_glo / (nb_rank_glo*2), labels=c(rep(c(height/2,0),nb_rank_glo),height/2))
1866 1867
  # Go
1867 1868
	replicates_wp_nucs = list()
1869
  wp_maps = list()
1870
  fuzzy_maps = list()
1868 1871
  for (replicate_rank in 1:length(replicates)) {
1869 1872
		# Computing replicate parameters
1870 1873
		nb_rank = length(samples)
......
1976 1979
	  }
1977 1980

  
1978 1981
	  # Plot wp nucs
1979
		if ((plot_wp_nucs_4_nonmnase | sample$marker == "Mnase_Seq") & (plot_wp_nucs | plot_common_nucs | plot_chain)) {
1982
		if ((plot_wp_nucs_4_nonmnase | sample$marker == "Mnase_Seq") & (plot_wp_nucs | plot_fuzzy_nucs | plot_common_nucs | plot_chain)) {
1980 1983
			if (samples[[1]]$marker == "Mnase_Seq") {
1981 1984
				if (is.null(aggregated_intra_strain_nucs)) {
1982 1985
	  			wp_nucs = aggregate_intra_strain_nucs(samples)[[1]]
......
2028 2031
        text(tmp_x_inter, tmp_y_inter, tmp_lod_inter, srt=90, cex=0.9, bg = "yellow")#, col=(tmp_lod_inter < 20) + 2)
2029 2032
      }
2030 2033

  
2031
      if (plot_wp_nucs | plot_common_nucs ) {
2034
      if (plot_wp_nucs | plot_fuzzy_nucs | plot_common_nucs ) {
2032 2035
    		replicates_wp_nucs[[replicate_rank]] = wp_nucs
2033
  			for (wp_nuc in wp_nucs) {
2034
  				if (wp_nuc$wp){
2035
  					rect(sign(x_min) * wp_nuc$lower_bound + shift, y_min, sign(x_min) * wp_nuc$upper_bound + shift, y_max, col=adjustcolor(2, alpha.f = 0.1), border=1)
2036
  					all_original_reads = c()
2037
  					for(initial_nuc in wp_nuc$nucs) {
2038
  						all_original_reads = c(all_original_reads, initial_nuc$original_reads)
2039
  					}
2040
  					delta_x = wp_nuc$lower_bound:wp_nuc$upper_bound
2041
  					if (FALSE) {
2042
  					  rect(sign(x_min) * wp_nuc$lower_bound + shift, y_min, sign(x_min) * wp_nuc$upper_bound + shift, y_max, col="#EEEEEE", border=1)
2043
  				  }
2044
  					if (plot_wp_nuc_model) {
2045
  					  lines(sign(x_min) * delta_x + shift, dnorm(delta_x, mean(all_original_reads), sd(all_original_reads)) * length(all_original_reads) * height/5 + y_min, col=1)
2036
        strain = samples[[1]]$strain
2037
        wp_maps[[strain]] = flat_aggregated_intra_strain_nucs(wp_nucs, "foo")
2038
        fuzzy_maps[[strain]] = get_intra_strain_fuzzy(wp_maps[[strain]], as.list(samples[[1]]$roi), samples[[1]]$strain, config=config)
2039

  
2040
        if (plot_fuzzy_nucs) {
2041
          fuzzy_map = fuzzy_maps[[strain]]
2042
          rect(sign(x_min) * fuzzy_map$lower_bound + shift, y_min, sign(x_min) * fuzzy_map$upper_bound + shift, y_max, col=adjustcolor(3, alpha.f = 0.1), border=1)        
2043
        } 
2044

  
2045
        if (plot_wp_nucs) {
2046
    			for (wp_nuc in wp_nucs) {
2047
    				if (wp_nuc$wp){
2048
    					rect(sign(x_min) * wp_nuc$lower_bound + shift, y_min, sign(x_min) * wp_nuc$upper_bound + shift, y_max, col=adjustcolor(2, alpha.f = 0.1), border=1)
2049
    					if (plot_wp_nuc_model) {
2050
      					all_original_reads = c()
2051
      					for(initial_nuc in wp_nuc$nucs) {
2052
      						all_original_reads = c(all_original_reads, initial_nuc$original_reads)
2053
      					}
2054
      					delta_x = wp_nuc$lower_bound:wp_nuc$upper_bound
2055
    					  lines(sign(x_min) * delta_x + shift, dnorm(delta_x, mean(all_original_reads), sd(all_original_reads)) * length(all_original_reads) * height/5 + y_min, col=1)
2056
    				  }
2046 2057
  				  }
2047 2058
  				}
2048 2059
  			}
......
2051 2062
	}
2052 2063

  
2053 2064
	if (plot_common_nucs) {
2054
		if (is.null(aligned_inter_strain_nucs)) {
2055
			aligned_inter_strain_nucs = align_inter_strain_nucs(replicates, replicates_wp_nucs[[1]], replicates_wp_nucs[[2]], config=config)[[1]]
2056
		}
2057
		if (plot_common_nucs) {
2058
      #Plot common wp nucs
2059
      mid_y = shift = x_min = x_max = nb_rank = base = ylim = ymin = y_max = delta_y = list()
2060
            for (replicate_rank in 1:length(replicates)) {
2061
        nb_rank[[replicate_rank]] = length(samples)
2062
        base[[replicate_rank]] = (replicate_rank-1) * height * nb_rank[[replicate_rank]]
2063
        ylim[[replicate_rank]] = c(base[[replicate_rank]], base[[replicate_rank]] + height * nb_rank[[replicate_rank]])
2064
        y_min[[replicate_rank]] = min(ylim[[replicate_rank]])
2065
        y_max[[replicate_rank]] = max(ylim[[replicate_rank]])
2066
        delta_y[[replicate_rank]] = y_max[[replicate_rank]] - y_min[[replicate_rank]]
2067
        mid_y[[replicate_rank]] = (y_max[[replicate_rank]] + y_min[[replicate_rank]]) / 2
2065
    if (is.null(aligned_inter_strain_nucs)) {
2066
      aligned_inter_strain_nucs = align_inter_strain_nucs(replicates, replicates_wp_nucs[[1]], replicates_wp_nucs[[2]], config=config)[[1]]
2067
      aligned_inter_strain_nucs$roi_index = "foo" 
2068
    }
2068 2069

  
2069
        samples = replicates[[replicate_rank]]
2070
        for (sample_rank in 1:length(samples)) {
2071
          sample = samples[[sample_rank]]
2072
          y_lev = y_min[[replicate_rank]] + (sample_rank - 0.5) * delta_y[[replicate_rank]]/nb_rank[[replicate_rank]]
2073
          if (sample$roi[["begin"]] < sample$roi[["end"]]) {
2074
            x_min[[replicate_rank]] = sample$roi[["begin"]]
2075
            x_max[[replicate_rank]] = sample$roi[["end"]]
2076
          } else {
2077
            x_min[[replicate_rank]] = - sample$roi[["begin"]]
2078
            x_max[[replicate_rank]] = - sample$roi[["end"]]
2079
          }
2080
          shift[[replicate_rank]] = x_min[[1]] - x_min[[replicate_rank]]
2070
    #Plot common wp nucs
2071
    mid_y = shift = x_min = x_max = nb_rank = base = ylim = ymin = y_max = delta_y = list()
2072
    for (replicate_rank in 1:length(replicates)) {
2073
      nb_rank[[replicate_rank]] = length(samples)
2074
      base[[replicate_rank]] = (replicate_rank-1) * height * nb_rank[[replicate_rank]]
2075
      ylim[[replicate_rank]] = c(base[[replicate_rank]], base[[replicate_rank]] + height * nb_rank[[replicate_rank]])
2076
      y_min[[replicate_rank]] = min(ylim[[replicate_rank]])
2077
      y_max[[replicate_rank]] = max(ylim[[replicate_rank]])
2078
      delta_y[[replicate_rank]] = y_max[[replicate_rank]] - y_min[[replicate_rank]]
2079
      mid_y[[replicate_rank]] = (y_max[[replicate_rank]] + y_min[[replicate_rank]]) / 2
2080

  
2081
      samples = replicates[[replicate_rank]]
2082
      for (sample_rank in 1:length(samples)) {
2083
        sample = samples[[sample_rank]]
2084
        y_lev = y_min[[replicate_rank]] + (sample_rank - 0.5) * delta_y[[replicate_rank]]/nb_rank[[replicate_rank]]
2085
        if (sample$roi[["begin"]] < sample$roi[["end"]]) {
2086
          x_min[[replicate_rank]] = sample$roi[["begin"]]
2087
          x_max[[replicate_rank]] = sample$roi[["end"]]
2088
        } else {
2089
          x_min[[replicate_rank]] = - sample$roi[["begin"]]
2090
          x_max[[replicate_rank]] = - sample$roi[["end"]]
2081 2091
        }
2092
        shift[[replicate_rank]] = x_min[[1]] - x_min[[replicate_rank]]
2082 2093
      }
2083
      for (inter_strain_nuc_index in 1:length(aligned_inter_strain_nucs[,1])) {
2084
        inter_strain_nuc = aligned_inter_strain_nucs[inter_strain_nuc_index,]
2085
        tmp_xs = tmp_ys = c()
2086
        for (replicate_rank in 1:length(replicates)) {
2087
          samples = replicates[[replicate_rank]]
2088
          strain = samples[[1]]$strain
2089
          tmp_xs = c(tmp_xs, sign(x_min[[replicate_rank]]) * (inter_strain_nuc[[paste("lower_bound_",strain,sep="")]] + inter_strain_nuc[[paste("upper_bound_",strain,sep="")]])/2 + shift[[replicate_rank]])
2090
          tmp_ys = c(tmp_ys, mid_y[[replicate_rank]])
2091
        }
2092
        lines(tmp_xs, tmp_ys, col=2, type="b", lwd=dev.size()[1]*100/(x_max[[1]]-x_min[[1]]), cex=dev.size()[1]*200/(x_max[[1]]-x_min[[1]]), pch=19)
2094
    }
2095
    for (inter_strain_nuc_index in 1:length(aligned_inter_strain_nucs[,1])) {
2096
      inter_strain_nuc = aligned_inter_strain_nucs[inter_strain_nuc_index,]
2097
      tmp_xs = tmp_ys = c()
2098
      for (replicate_rank in 1:length(replicates)) {
2099
        samples = replicates[[replicate_rank]]
2100
        strain = samples[[1]]$strain
2101
        tmp_xs = c(tmp_xs, sign(x_min[[replicate_rank]]) * (inter_strain_nuc[[paste("lower_bound_",strain,sep="")]] + inter_strain_nuc[[paste("upper_bound_",strain,sep="")]])/2 + shift[[replicate_rank]])
2102
        tmp_ys = c(tmp_ys, mid_y[[replicate_rank]])
2093 2103
      }
2094
		}
2104
      lines(tmp_xs, tmp_ys, col=2, type="b", lwd=dev.size()[1]*100/(x_max[[1]]-x_min[[1]]), cex=dev.size()[1]*200/(x_max[[1]]-x_min[[1]]), pch=19)
2105
    }
2106
    
2107
    if (plot_common_unrs) {
2108
      combi = c(replicates[[1]][[1]]$strain, replicates[[2]][[1]]$strain)
2109
      roi = as.list(samples[[1]]$roi)
2110
      roi_index = "foo"
2111
      common_nuc_results = list()
2112
      common_nuc_results[[paste(combi[1], combi[2], sep="_")]] = aligned_inter_strain_nucs
2113
      unrs = get_unrs(combi, roi, roi_index, wp_maps, fuzzy_maps, common_nuc_results, config = config) 
2114
      rect(sign(x_min[[1]]) * unrs$lower_bound + shift[[1]], y_min[[1]], sign(x_min[[1]]) * unrs$upper_bound + shift[[1]], y_max[[2]], col=adjustcolor(4, alpha.f = 0.3), border=1)        
2115
    }
2116

  
2095 2117
	}
2096 2118
  return(returned_list)
2097 2119
}
2098 2120

  
2099 2121

  
2100 2122

  
2123
get_intra_strain_fuzzy = function(# Compute the fuzzy list for a given strain.
2124
### This function grabs the nucleosomes detxted by template_filter that have been rejected bt aggregate_intra_strain_nucs as well positions.
2125
wp_maps, ##<< Well positionned nucleosomes map.
2126
roi, ##<< The region of interest.
2127
strain, ##<< The strain we want to extracvt the fuzzy map.
2128
config=NULL ##<< GLOBAL config variable.
2129
) {
2130
  fuzzy_map = wp_map[wp_map$wp==0, ]
2131
  if (nrow(fuzzy_map) > 0) {
2132
    fuzzy_map = substract_region(fuzzy_map, wp_map[wp_map$wp==1,])
2133
    if (!is.null(fuzzy_map)) {
2134
      fuzzy_map = union_regions(fuzzy_map)
2135
      fuzzy_map = crop_fuzzy(fuzzy_map, roi, strain, config)
2136
    }
2137
  }
2138
  return(fuzzy_map)
2139
}
2140

  
2141

  
2142

  
2143

  
2144

  
2145
get_unrs = function(# Compute the unaligned nucleosomal regions (UNRs).
2146
### This function aggregate non common wp nucs for each strain and substract common wp nucs. It does not take care about the size of the resulting UNR. It will be take into account in the count read part og the pipeline.
2147
combi, ##<< The strain combination to consider.
2148
roi, ##<< The region of interest.
2149
roi_index, ##<< The region of interest index.
2150
wp_maps, ##<< Well positionned nucleosomes maps.
2151
fuzzy_maps, ##<< Fuzzy nucleosomes maps.
2152
common_nuc_results, ##<< Common wp nuc maps
2153
config=NULL ##<< GLOBAL config variable
2154
) {
2155
  print(roi_index)
2156

  
2157
  tmp_combi_key = paste(combi[1], combi[2], sep="_")
2158
  tmp_common_nucs = common_nuc_results[[tmp_combi_key]]
2159
  tmp_common_nucs = tmp_common_nucs[tmp_common_nucs$roi_index == roi_index, ]
2160

  
2161
  print(paste("Dealing with unr from", combi[1]))
2162
  tmp_fuzzy = fuzzy_maps[[combi[1]]]
2163
  tmp_fuzzy = tmp_fuzzy[tmp_fuzzy$roi_index == roi_index, ]
2164
  tmp_wp = wp_maps[[combi[1]]]
2165
  tmp_wp = tmp_wp[tmp_wp$wp==1,]
2166
  tmp_wp = tmp_wp[tmp_wp$roi_index == roi_index, ]
2167
  # Let's go!
2168
  tmp_index = unlist(apply(t(tmp_wp$index_nuc), 2, function(index_nuc) {
2169
    if (index_nuc %in% tmp_common_nucs[[paste("index_nuc", combi[1], sep="_")]]) {
2170
      return(NULL)
2171
    } else {
2172
      return (index_nuc)
2173
    }
2174
  }))
2175
  tmp_unaligned_wp = tmp_wp[tmp_wp$index_nuc %in% tmp_index, ]
2176
  tmp_unr = rbind(tmp_fuzzy,tmp_unaligned_wp[,1:4])
2177
  if (length(tmp_unr) != 0) {
2178
    tmp_unr = union_regions(tmp_unr)
2179
  }
2180
  tmp_unr_nucs_1 = tmp_unr
2181
  if (length(tmp_unr_nucs_1[,1]) == 0) {return(NULL)}
2182
  agg_unr_1 = tmp_unr_nucs_1
2183

  
2184
  print(paste("Dealing with unr from ", combi[2]))
2185
  tmp_fuzzy = fuzzy_maps[[combi[2]]]
2186
  tmp_fuzzy = tmp_fuzzy[tmp_fuzzy$roi_index == roi_index, ]
2187
  tmp_wp = wp_maps[[combi[2]]]
2188
  tmp_wp = tmp_wp[tmp_wp$wp==1,]
2189
  tmp_wp = tmp_wp[tmp_wp$roi_index == roi_index, ]
2190
  # Let's go!
2191
  tmp_index = unlist(apply(t(tmp_wp$index_nuc), 2, function(index_nuc) {
2192
    if (index_nuc %in% tmp_common_nucs[[paste("index_nuc", combi[2], sep="_")]]) {
2193
      return(NULL)
2194
    } else {
2195
      return (index_nuc)
2196
    }
2197
  }))
2198
  tmp_unaligned_wp = tmp_wp[tmp_wp$index_nuc %in% tmp_index, ]
2199
  tmp_unr = rbind(tmp_fuzzy,tmp_unaligned_wp[,1:4])
2200
  if (length(tmp_unr) != 0) {
2201
    tmp_unr = union_regions(tmp_unr)
2202
  }
2203
  tmp_unr_nucs_2 = tmp_unr
2204
  if (length(tmp_unr_nucs_2[,1]) == 0) {return(NULL)}
2205
  agg_unr_2 = crop_fuzzy(tmp_unr_nucs_2, roi, combi[2], config)
2206
  tr_agg_unr_2 = translate_regions(agg_unr_2, combi, roi_index, roi=roi, config=config)
2207
  tr_agg_unr_2 = union_regions(tr_agg_unr_2)
2208

  
2209
  print("Dealing with unr from both...")
2210
  all_unr = union_regions(rbind(agg_unr_1, tr_agg_unr_2))
2211

  
2212
  print(paste("Dealing with wp from", combi[1]))
2213
  tmp_wp = wp_maps[[combi[1]]]
2214
  tmp_wp = tmp_wp[tmp_wp$wp==1,]
2215
  tmp_wp = tmp_wp[tmp_wp$roi_index == roi_index, ]
2216
  # Let's go!
2217
  tmp_index = unlist(apply(t(tmp_wp$index_nuc), 2, function(index_nuc) {
2218
    if (index_nuc %in% tmp_common_nucs[[paste("index_nuc", combi[1], sep="_")]]) {
2219
      return (index_nuc)
2220
    } else {
2221
      return(NULL)
2222
    }
2223
  }))
2224
  wp_nucs_1 = tmp_wp[tmp_wp$index_nuc %in% tmp_index, ]
2225
  
2226
  print(paste("Dealing with wp from", combi[2]))
2227
  tmp_wp = wp_maps[[combi[2]]]
2228
  tmp_wp = tmp_wp[tmp_wp$wp==1,]
2229
  tmp_wp = tmp_wp[tmp_wp$roi_index == roi_index, ]
2230
  # Let's go!
2231
  tmp_index = unlist(apply(t(tmp_wp$index_nuc), 2, function(index_nuc) {
2232
    if (index_nuc %in% tmp_common_nucs[[paste("index_nuc", combi[2], sep="_")]]) {
2233
      return (index_nuc)
2234
    } else {
2235
      return(NULL)
2236
    }
2237
  }))
2238
  wp_nucs_2 = tmp_wp[tmp_wp$index_nuc %in% tmp_index, ]
2239
  wp_nucs_2 = crop_fuzzy(wp_nucs_2, roi, combi[2], config)
2240
  if (nrow(wp_nucs_2) == 0) {
2241
    tr_wp_nucs_2 = wp_nucs_2
2242
  } else {
2243
    tr_wp_nucs_2 = translate_regions(wp_nucs_2, combi, roi_index, roi=roi, config=config)      
2244
  }
2245

  
2246
  print("Dealing with wp from both...")
2247
  all_wp = union_regions(rbind(wp_nucs_1[,1:4], tr_wp_nucs_2))
2248

  
2249
  print("Dealing with unr and wp...")
2250
  non_inter_unr = substract_region(all_unr, all_wp)
2251
  non_inter_unr = crop_fuzzy(non_inter_unr, roi, combi[1], config)
2252
  if (is.null(non_inter_unr)) { return(NULL) }
2253
  non_inter_unr$len = non_inter_unr$upper_bound - non_inter_unr$lower_bound
2254
  # non_inter_fuzzy = non_inter_fuzzy[non_inter_fuzzy$len >= min_fuzz_width,]
2255

  
2256
  non_inter_unr$index_nuc = 1:length(non_inter_unr[,1])
2257
  return (non_inter_unr)
2258
}
2259

  
2260

  
2101 2261

  

Formats disponibles : Unified diff