def state_dependent_allocation(state, chrom):
				allocation_of_coordinates, size_domains = interacting_domain.interacting_domains(interacting_enhancer_coordinates, possible_interaction_coordinates, chrom, state, matrix_version = False, chromosome_version = domain_like_chromosome_correction) # matrix_mode = False

				allocations_of_interacting_enhancers = allocation_of_coordinates[:len(interacting_enhancer_coordinates)]

				allocations_of_interacting_enhancer_possible_interactions = allocation_of_coordinates[len(interacting_enhancer_coordinates):]

				allocations_of_interacting_enhancer_possible_interactions = allocations_of_interacting_enhancer_possible_interactions.reshape(len(interacting_enhancer_coordinates), len(distances))	

				dummy_interactions_in_the_same_domain_as_enhancer = allocations_of_interacting_enhancers[:,None] == allocations_of_interacting_enhancer_possible_interactions
	
				return dummy_interactions_in_the_same_domain_as_enhancer, size_domains
	def interactions_above_threshold(posterior_t, posterior_f, threshold_up, threshold_low, chrom, domain = False):
		enh_coordinates, pro_coordinates, indexes_p, indexes_e, total_p, total_e = negative_interactions.initialise_variables(chrom)
		
		length_chr = len(indexes_p) + len(indexes_e)
		interaction_matrix = np.zeros((length_chr, length_chr))
		posterior_t, posterior_f = posterior_t[chrom], posterior_f[chrom]

		i_s_f, j_s_f = positive_negative_interactions_for_MAP(chrom)

		if domain:
			import interacting_domain_clean as interacting_domain
			if config_variables.TSS_or_intra_genic_for_domain_filter == "Intra_genic": coords_pro_domain = pro_coordinates[indexes_p]
			elif config_variables.TSS_or_intra_genic_for_domain_filter == "TSS_only": coords_pro_domain = np.column_stack((TSS_coordinates[indexes_p]-1, TSS_coordinates[indexes_p]+1))
			domain_matrix = interacting_domain.interacting_domains(coords_pro_domain, enh_coordinates[indexes_e], chrom, 'left', True)
			domain_matrix = domain_matrix + interacting_domain.interacting_domains(coords_pro_domain, enh_coordinates[indexes_e], chrom, 'right', True)
		else:
			domain_matrix = True

		if mode == "promoter_enhancer_interactions":

			if config_variables.disentagled_features_validation: 
				chr_interactions_pro_enh = config_variables.chr_interactions_dict_pro_enh_TSS[chrom]
			else:
				chr_interactions_pro_enh = config_variables.chr_interactions_dict_pro_enh[chrom]

			#chr_interactions_dict_pro_enh = config_variables.chr_interactions_dict_pro_enh
			#true_inter_pro = un_string(chr_interactions_dict_pro_enh[chrom][:, :2]).astype(int)
			true_inter_pro = un_string(chr_interactions_pro_enh[:, :2]).astype(int)

			i_s_t, j_s_t = true_inter_pro[:,0], true_inter_pro[:,1]

			#chr_interactions_dict_pro_enh = config_variables.chr_interactions_dict_pro_enh
			#true_inter_pro = un_string(chr_interactions_dict_pro_enh[chrom][:, :2]).astype(int)
			#i_s_t, j_s_t = true_inter_pro[:,0], true_inter_pro[:,1]

			interaction_matrix[:,:] = np.min([np.min(posterior_t), np.min(posterior_f)])*0.999
			interaction_matrix[i_s_t - total_p, j_s_t + len(indexes_p) - total_e] = posterior_t
			interaction_matrix[i_s_f - total_p, j_s_f + len(indexes_p) - total_e] = posterior_f

			#--------------------------------------------------------------------------the part to look at for Paolo !
			#np.save("interaction_matrix_float", interaction_matrix) #I'm saving the interaction matrix for you
	
			if normalised:
				norm_factors = np.sum(interaction_matrix, axis = 0)
				interaction_matrix = interaction_matrix/norm_factors
				interaction_matrix[np.isnan(interaction_matrix)] = 0.

			interacting_mask = np.zeros_like(interaction_matrix).astype(bool)
			interacting_mask[i_s_t - total_p, j_s_t + len(indexes_p) - total_e] = True

			true_pro_enh_inter_filtered = np.where(interacting_mask * (interaction_matrix >= threshold_low) * (interaction_matrix < threshold_up) * domain_matrix)
			i_s_t_filt, j_s_t_filt = true_pro_enh_inter_filtered[0] + total_p, true_pro_enh_inter_filtered[1] - len(indexes_p) + total_e # that line tells you which of the positive (green) ChIA-PET-confirmed interactions lay within threshold_low, threshold_up interval

			interacting_mask = np.zeros_like(interaction_matrix).astype(bool)
			interacting_mask[i_s_f - total_p, j_s_f + len(indexes_p) - total_e] = True

			false_pro_enh_inter_filtered = np.where(interacting_mask * (interaction_matrix >= threshold_low) * (interaction_matrix < threshold_up) * domain_matrix)
			i_s_f_filt, j_s_f_filt = false_pro_enh_inter_filtered[0] + total_p, false_pro_enh_inter_filtered[1] - len(indexes_p) + total_e # that line tells you which of the negative (gray) interactions lay within threshold_low, threshold_up interval

			#--------------------------------------------------------------------------the part to look at for Paolo !

			return	i_s_t_filt, j_s_t_filt, i_s_f_filt, j_s_f_filt # the function takes threshold_up, threshold_low as an argument and returns predicted interactions with probabilities within  [threshold_low, threshold_up) interval
			# i_s_t_filt, j_s_t_filt, i_s_f_filt, j_s_f_filt legend: i_s_t are promoters of ChIA-PET confirmed interactions, j_s_t are enhancers of the interactions, i_s_f, j_s_f are (promoters, enhancers) interactions which aren't ChIA-PET confirmed
			#for paolo

		if mode == "enhancer_enhancer_interactions":

			chr_interactions_dict_enh_enh = config_variables.chr_interactions_dict_enh_enh
			true_inter_enh = un_string(chr_interactions_dict_enh_enh[chrom][:, :2]).astype(int)
			i_s_t, j_s_t = true_inter_enh[:,0], true_inter_enh[:,1]

			interaction_matrix[:,:] = np.min([np.min(posterior_t), np.min(posterior_f)])*0.999
			interaction_matrix[i_s_t + len(indexes_p) - total_e, j_s_t + len(indexes_p) - total_e] = posterior_t
			interaction_matrix[i_s_f + len(indexes_p) - total_e, j_s_f + len(indexes_p) - total_e] = posterior_f
			interaction_matrix[j_s_t + len(indexes_p) - total_e, i_s_t + len(indexes_p) - total_e] = posterior_t # transpose to create a full matrix
			interaction_matrix[j_s_f + len(indexes_p) - total_e, i_s_f + len(indexes_p) - total_e] = posterior_f # transpose to create a full matrix


			if normalised: 
				norm_factors = np.sum(interaction_matrix, axis = 0)
				interaction_matrix = interaction_matrix/norm_factors
				interaction_matrix[np.isnan(interaction_matrix)] = 0.

			interacting_mask = np.zeros_like(interaction_matrix).astype(bool)
			interacting_mask[i_s_t + len(indexes_p) - total_e, j_s_t + len(indexes_p) - total_e] = True

			true_enh_enh_inter_filtered = np.where(interacting_mask * (interaction_matrix >= threshold_low) * (interaction_matrix < threshold_up))
			i_s_t_filt, j_s_t_filt = true_enh_enh_inter_filtered[0] - len(indexes_p) + total_e, true_enh_enh_inter_filtered[1] - len(indexes_p) + total_e

			interacting_mask = np.zeros_like(interaction_matrix).astype(bool)
			interacting_mask[i_s_f + len(indexes_p) - total_e, j_s_f + len(indexes_p) - total_e] = True

			false_enh_enh_inter_filtered = np.where(interacting_mask * (interaction_matrix >= threshold_low) * (interaction_matrix < threshold_up))
			i_s_f_filt, j_s_f_filt = false_enh_enh_inter_filtered[0] - len(indexes_p) + total_e, false_enh_enh_inter_filtered[1] - len(indexes_p) + total_e

			return i_s_t_filt, j_s_t_filt, i_s_f_filt, j_s_f_filt
    def interactions_above_threshold(posterior_t,
                                     posterior_f,
                                     threshold_up,
                                     threshold_low,
                                     chrom,
                                     domain=False):
        enh_coordinates, pro_coordinates, indexes_p, indexes_e, total_p, total_e = negative_interactions.initialise_variables(
            chrom)

        length_chr = len(indexes_p) + len(indexes_e)
        interaction_matrix = np.zeros((length_chr, length_chr))
        posterior_t, posterior_f = posterior_t[chrom], posterior_f[chrom]

        i_s_f, j_s_f = positive_negative_interactions_for_MAP(chrom)

        if domain:
            import interacting_domain_clean as interacting_domain
            if config_variables.TSS_or_intra_genic_for_domain_filter == "Intra_genic":
                coords_pro_domain = pro_coordinates[indexes_p]
            elif config_variables.TSS_or_intra_genic_for_domain_filter == "TSS_only":
                coords_pro_domain = np.column_stack(
                    (TSS_coordinates[indexes_p] - 1,
                     TSS_coordinates[indexes_p] + 1))
            domain_matrix = interacting_domain.interacting_domains(
                coords_pro_domain, enh_coordinates[indexes_e], chrom, 'left',
                True)
            domain_matrix = domain_matrix + interacting_domain.interacting_domains(
                coords_pro_domain, enh_coordinates[indexes_e], chrom, 'right',
                True)
        else:
            domain_matrix = True

        if mode == "promoter_enhancer_interactions":

            if config_variables.disentagled_features_validation:
                chr_interactions_pro_enh = config_variables.chr_interactions_dict_pro_enh_TSS[
                    chrom]
            else:
                chr_interactions_pro_enh = config_variables.chr_interactions_dict_pro_enh[
                    chrom]

            #chr_interactions_dict_pro_enh = config_variables.chr_interactions_dict_pro_enh
            #true_inter_pro = un_string(chr_interactions_dict_pro_enh[chrom][:, :2]).astype(int)
            true_inter_pro = un_string(
                chr_interactions_pro_enh[:, :2]).astype(int)

            i_s_t, j_s_t = true_inter_pro[:, 0], true_inter_pro[:, 1]

            #chr_interactions_dict_pro_enh = config_variables.chr_interactions_dict_pro_enh
            #true_inter_pro = un_string(chr_interactions_dict_pro_enh[chrom][:, :2]).astype(int)
            #i_s_t, j_s_t = true_inter_pro[:,0], true_inter_pro[:,1]

            interaction_matrix[:, :] = np.min(
                [np.min(posterior_t), np.min(posterior_f)]) * 0.999
            interaction_matrix[i_s_t - total_p,
                               j_s_t + len(indexes_p) - total_e] = posterior_t
            interaction_matrix[i_s_f - total_p,
                               j_s_f + len(indexes_p) - total_e] = posterior_f

            #--------------------------------------------------------------------------the part to look at for Paolo !
            #np.save("interaction_matrix_float", interaction_matrix) #I'm saving the interaction matrix for you

            if normalised:
                norm_factors = np.sum(interaction_matrix, axis=0)
                interaction_matrix = interaction_matrix / norm_factors
                interaction_matrix[np.isnan(interaction_matrix)] = 0.

            interacting_mask = np.zeros_like(interaction_matrix).astype(bool)
            interacting_mask[i_s_t - total_p,
                             j_s_t + len(indexes_p) - total_e] = True

            true_pro_enh_inter_filtered = np.where(
                interacting_mask * (interaction_matrix >= threshold_low) *
                (interaction_matrix < threshold_up) * domain_matrix)
            i_s_t_filt, j_s_t_filt = true_pro_enh_inter_filtered[
                0] + total_p, true_pro_enh_inter_filtered[1] - len(
                    indexes_p
                ) + total_e  # that line tells you which of the positive (green) ChIA-PET-confirmed interactions lay within threshold_low, threshold_up interval

            interacting_mask = np.zeros_like(interaction_matrix).astype(bool)
            interacting_mask[i_s_f - total_p,
                             j_s_f + len(indexes_p) - total_e] = True

            false_pro_enh_inter_filtered = np.where(
                interacting_mask * (interaction_matrix >= threshold_low) *
                (interaction_matrix < threshold_up) * domain_matrix)
            i_s_f_filt, j_s_f_filt = false_pro_enh_inter_filtered[
                0] + total_p, false_pro_enh_inter_filtered[1] - len(
                    indexes_p
                ) + total_e  # that line tells you which of the negative (gray) interactions lay within threshold_low, threshold_up interval

            #--------------------------------------------------------------------------the part to look at for Paolo !

            return i_s_t_filt, j_s_t_filt, i_s_f_filt, j_s_f_filt  # the function takes threshold_up, threshold_low as an argument and returns predicted interactions with probabilities within  [threshold_low, threshold_up) interval
            # i_s_t_filt, j_s_t_filt, i_s_f_filt, j_s_f_filt legend: i_s_t are promoters of ChIA-PET confirmed interactions, j_s_t are enhancers of the interactions, i_s_f, j_s_f are (promoters, enhancers) interactions which aren't ChIA-PET confirmed
            #for paolo

        if mode == "enhancer_enhancer_interactions":

            chr_interactions_dict_enh_enh = config_variables.chr_interactions_dict_enh_enh
            true_inter_enh = un_string(
                chr_interactions_dict_enh_enh[chrom][:, :2]).astype(int)
            i_s_t, j_s_t = true_inter_enh[:, 0], true_inter_enh[:, 1]

            interaction_matrix[:, :] = np.min(
                [np.min(posterior_t), np.min(posterior_f)]) * 0.999
            interaction_matrix[i_s_t + len(indexes_p) - total_e,
                               j_s_t + len(indexes_p) - total_e] = posterior_t
            interaction_matrix[i_s_f + len(indexes_p) - total_e,
                               j_s_f + len(indexes_p) - total_e] = posterior_f
            interaction_matrix[
                j_s_t + len(indexes_p) - total_e, i_s_t + len(indexes_p) -
                total_e] = posterior_t  # transpose to create a full matrix
            interaction_matrix[
                j_s_f + len(indexes_p) - total_e, i_s_f + len(indexes_p) -
                total_e] = posterior_f  # transpose to create a full matrix

            if normalised:
                norm_factors = np.sum(interaction_matrix, axis=0)
                interaction_matrix = interaction_matrix / norm_factors
                interaction_matrix[np.isnan(interaction_matrix)] = 0.

            interacting_mask = np.zeros_like(interaction_matrix).astype(bool)
            interacting_mask[i_s_t + len(indexes_p) - total_e,
                             j_s_t + len(indexes_p) - total_e] = True

            true_enh_enh_inter_filtered = np.where(
                interacting_mask * (interaction_matrix >= threshold_low) *
                (interaction_matrix < threshold_up))
            i_s_t_filt, j_s_t_filt = true_enh_enh_inter_filtered[0] - len(
                indexes_p) + total_e, true_enh_enh_inter_filtered[1] - len(
                    indexes_p) + total_e

            interacting_mask = np.zeros_like(interaction_matrix).astype(bool)
            interacting_mask[i_s_f + len(indexes_p) - total_e,
                             j_s_f + len(indexes_p) - total_e] = True

            false_enh_enh_inter_filtered = np.where(
                interacting_mask * (interaction_matrix >= threshold_low) *
                (interaction_matrix < threshold_up))
            i_s_f_filt, j_s_f_filt = false_enh_enh_inter_filtered[0] - len(
                indexes_p) + total_e, false_enh_enh_inter_filtered[1] - len(
                    indexes_p) + total_e

            return i_s_t_filt, j_s_t_filt, i_s_f_filt, j_s_f_filt