Commit 08ac8497 authored by Jiri Borovec's avatar Jiri Borovec

fixing & update

parent 90235a72
......@@ -133,7 +133,7 @@ def parse_arg_params(parser):
args = vars(parser.parse_args())
# remove not filled parameters
args = {k: args[k] for k in args if args[k] is not None}
for n in (k for k in args.keys() if 'path' in k):
for n in (k for k in args if 'path' in k):
args[n] = os.path.abspath(os.path.expanduser(args[n]))
return args
......@@ -282,7 +282,7 @@ class ExperimentAPD(tl_expt.Experiment):
self.df_stat = pd.DataFrame()
for stat in self.l_stat:
self.df_stat = self.df_stat.append(stat, ignore_index=True)
if self.iter_var_name in stat.keys():
if self.iter_var_name in stat:
self.df_stat = self.df_stat.set_index(self.iter_var_name)
path_csv = os.path.join(self.params.get('path_exp'), self.RESULTS_CSV)
logger.debug('save results: "%s"', path_csv)
......
......@@ -12,13 +12,14 @@ def compare_atlas_rnd_pairs(a1, a2):
:param a2: np.array<w, h>
:return: float with 0 means no difference
"""
logger.debug('comparing two atlases '
'of shapes {} <-> {}'.format(a1.shape, a2.shape))
logger.debug('comparing two atlases of shapes %s <-> %s',
repr(a1.shape), repr(a2.shape))
assert np.array_equal(a1.shape, a2.shape)
# assert A1.shape[0]==A2.shape[0] and A1.shape[1]==A2.shape[1]
logger.debug('unique labels are {} and {}'.format(np.unique(a1).tolist(), np.unique(a2).tolist()))
X, Y = np.meshgrid(range(a1.shape[0]), range(a1.shape[1]))
vec_x, vec_y = X.flatten(), Y.flatten()
logger.debug('unique labels are %s and %s', repr(np.unique(a1).tolist()),
repr(np.unique(a2).tolist()))
matrix_x, matrix_y = np.meshgrid(range(a1.shape[0]), range(a1.shape[1]))
vec_x, vec_y = matrix_x.flatten(), matrix_y.flatten()
vec_x_perm = np.random.permutation(vec_x)
vec_y_perm = np.random.permutation(vec_y)
diffs = 0
......@@ -64,14 +65,14 @@ def overlap_matrix_mlabel_segm(seg1, seg2):
:param seg2: np.array<w, h>
:return: np.array<w, h>
"""
logger.debug('computing overlap of two segm '
'of shapes {} <-> {}'.format(seg1.shape, seg2.shape))
logger.debug('computing overlap of two segm of shapes %s <-> %s',
repr(seg1.shape), repr(seg2.shape))
assert np.array_equal(seg1.shape, seg2.shape)
u_lb1 = np.unique(seg1)
u_lb2 = np.unique(seg2)
u_lb1 = dict(zip(u_lb1,range(len(u_lb1))))
u_lb2 = dict(zip(u_lb2,range(len(u_lb2))))
logger.debug('unique labels:\n {}\n {}'.format(u_lb1, u_lb2))
u_lb1 = dict(zip(u_lb1, range(len(u_lb1))))
u_lb2 = dict(zip(u_lb2, range(len(u_lb2))))
logger.debug('unique labels:\n %s\n %s', repr(u_lb1), repr(u_lb2))
res = np.zeros([len(u_lb1), len(u_lb2)])
for i in range(seg1.shape[0]):
for j in range(seg1.shape[1]):
......@@ -112,10 +113,10 @@ def test_atlases():
a2[a2==0] = -1
b = np.random.randint(0,4,(5,5))
logger.debug('compare_atlas_rnd_pairs, a <-> a: {}'.format(compare_atlas_rnd_pairs(a, a2)))
logger.debug('compare_atlas_rnd_pairs, a <-> b: {}'.format(compare_atlas_rnd_pairs(a, b)))
logger.debug('compare_atlas_adjusted_rand, a <-> a: {}'.format(compare_atlas_adjusted_rand(a, a2)))
logger.debug('compare_atlas_adjusted_rand, a <-> b: {}'.format(compare_atlas_adjusted_rand(a, b)))
logger.debug('compare_atlas_rnd_pairs, a <-> a: %d', compare_atlas_rnd_pairs(a, a2))
logger.debug('compare_atlas_rnd_pairs, a <-> b: %d', compare_atlas_rnd_pairs(a, b))
logger.debug('compare_atlas_adjusted_rand, a <-> a: %d', compare_atlas_adjusted_rand(a, a2))
logger.debug('compare_atlas_adjusted_rand, a <-> b: %d', compare_atlas_adjusted_rand(a, b))
return None
......
......@@ -135,7 +135,7 @@ def insert_new_pattern(imgs, imgs_rc, atlas, lb):
return atlas
def reinit_atlas_likely_patterns(imgs, w_bins, atlas, lb_max=None):
def reinit_atlas_likely_patterns(imgs, w_bins, atlas, label_max=None):
""" walk and find all all free labels and try to reinit them by new patterns
:param imgs: [np.array<w, h>] list of input images
......@@ -144,30 +144,30 @@ def reinit_atlas_likely_patterns(imgs, w_bins, atlas, lb_max=None):
:return: np.array<w, h>, np.array<nb_imgs, nb_lbs>
"""
# find empty patterns
if lb_max is None:
lb_max = max(np.max(atlas), w_bins.shape[1])
if label_max is None:
label_max = max(np.max(atlas), w_bins.shape[1])
else:
logger.debug('compare w_bin %s to max %i', repr(w_bins.shape), lb_max)
for i in range(w_bins.shape[1], lb_max):
logger.debug('compare w_bin %s to max %i', repr(w_bins.shape), label_max)
for i in range(w_bins.shape[1], label_max):
logger.debug('adding disappeared weigh column %i', i)
w_bins = np.append(w_bins, np.zeros((w_bins.shape[0], 1)), axis=1)
w_bin_ext = np.append(np.zeros((w_bins.shape[0], 1)), w_bins, axis=1)
logger.debug('IN > sum over weights: %s', repr(np.sum(w_bin_ext, axis=0)))
# add one while indexes does not cover 0 - bg
logger.debug('total nb labels: %i', lb_max)
for lb in range(1, lb_max + 1):
lb_w = lb - 1
w_sum = np.sum(w_bins[:, lb_w])
logger.debug('total nb labels: %i', label_max)
for lb in range(1, label_max + 1):
w_index = lb - 1
w_sum = np.sum(w_bins[:, w_index])
logger.debug('reinit lb: %i with weight sum %i', lb, w_sum)
if w_sum > 0:
continue
imgs_rc = reconstruct_samples(atlas, w_bins)
atlas = insert_new_pattern(imgs, imgs_rc, atlas, lb)
logger.debug('w_bins before: %i', np.sum(w_bins[:, lb_w]))
logger.debug('w_bins before: %i', np.sum(w_bins[:, w_index]))
lim_repopulate = 100. / np.prod(atlas.shape)
w_bins[:, lb_w] = ptn_weight.weights_label_atlas_overlap_threshold(imgs,
w_bins[:, w_index] = ptn_weight.weights_label_atlas_overlap_threshold(imgs,
atlas, lb, lim_repopulate)
logger.debug('w_bins after: %i', np.sum(w_bins[:, lb_w]))
logger.debug('w_bins after: %i', np.sum(w_bins[:, w_index]))
return atlas, w_bins
......@@ -178,18 +178,18 @@ def atlas_split_indep_ptn(atlas, lb_max):
:param lb_max: int
:return:
"""
l_ptns = []
patterns = []
for lb in np.unique(atlas):
labeled, nb_objects = ndimage.label(atlas == lb)
logger.debug('for label %i detected #%i', lb, nb_objects)
ptn = [(labeled == j) for j in np.unique(labeled)]
# skip the largest one assuming to be background
l_ptns += sorted(ptn, key=lambda x: np.sum(x), reverse=True)[1:]
l_ptns = sorted(l_ptns, key=lambda x: np.sum(x), reverse=True)
logger.debug('list of all areas %s', repr([np.sum(p) for p in l_ptns]))
patterns += sorted(ptn, key=lambda x: np.sum(x), reverse=True)[1:]
patterns = sorted(patterns, key=lambda x: np.sum(x), reverse=True)
logger.debug('list of all areas %s', repr([np.sum(p) for p in patterns]))
atlas_new = np.zeros(atlas.shape, dtype=np.int)
# take just lb_max largest elements
for i, ptn in enumerate(l_ptns[:lb_max]):
for i, ptn in enumerate(patterns[:lb_max]):
lb = i + 1
logger.debug('pattern #%i area %i', lb, np.sum(ptn))
# plt.subplot(1,lb_max,l), plt.imshow(ptn), plt.colorbar()
......
......@@ -30,16 +30,16 @@ def convert_weights_binary2indexes(weights):
logger.debug('convert binary weights %s to list of indexes with True',
repr(weights.shape))
# if type(weights)==np.ndarray: weights = weights.tolist()
w_idx = [None] * weights.shape[0]
w_index = [None] * weights.shape[0]
for i in range(weights.shape[0]):
# find postions equal 1
# vec = [j for j in range(weights.shape[1]) if weights[i,j]==1]
vec = np.where(weights[i, :] == 1)[0]
w_idx[i] = vec + 1
w_index[i] = vec + 1
# idxs = np.where(weights == 1)
# for i in range(weights.shape[0]):
# w_idx[i] = idxs[1][idxs[0]==i] +1
return w_idx
return w_index
def weights_image_atlas_overlap_major(img, atlas):
......@@ -60,8 +60,8 @@ def weights_image_atlas_overlap_partial(img, atlas):
:return: [int] * nb_lbs of values {0, 1}
"""
# logger.debug('weights input image according given atlas')
lbs = np.unique(atlas).tolist()
weights = weights_image_atlas_overlap_threshold(img, atlas, (1. / len(lbs)))
labels = np.unique(atlas).tolist()
weights = weights_image_atlas_overlap_threshold(img, atlas, (1. / len(labels)))
return weights
......@@ -76,35 +76,35 @@ def weights_image_atlas_overlap_threshold(img, atlas, thr=0.5):
"""
# logger.debug('weights input image according given atlas')
# simple weight
lbs = np.unique(atlas).tolist()
labels = np.unique(atlas).tolist()
# logger.debug('weights image by atlas with labels: {}'.format(lbs))
if 0 in lbs: lbs.remove(0)
weight = [0] * np.max(lbs)
for l in lbs:
equal = np.sum(img[atlas == l])
total = np.sum(atlas == l)
if 0 in labels: labels.remove(0)
weight = [0] * np.max(labels)
for lb in labels:
equal = np.sum(img[atlas == lb])
total = np.sum(atlas == lb)
score = equal / float(total)
if score >= thr:
weight[l - 1] = 1
weight[lb - 1] = 1
return weight
def weights_label_atlas_overlap_threshold(imgs, atlas, lb, thr=1e-3):
def weights_label_atlas_overlap_threshold(imgs, atlas, label, threshold=1e-3):
""" estimate what patterns are activated with given atlas and input image
compute overlap matrix and eval nr of overlapping and non pixels and threshold
:param imgs: [np.array<w, h>]
:param atlas: np.array<w, h>
:param lb: int
:param thr: float, represent the ration between overlapping and non pixels
:param label: int
:param threshold: float, represent the ration between overlapping and non pixels
:return: np.array<nb_imgs> of values {0, 1}
"""
weight = [0] * len(imgs)
for i, img in enumerate(imgs):
equal = np.sum(img[atlas == lb])
total = np.sum(atlas == lb)
equal = np.sum(img[atlas == label])
total = np.sum(atlas == label)
score = equal / float(total)
if score >= thr:
if score >= threshold:
weight[i] = 1
return np.array(weight)
......@@ -17,18 +17,19 @@ import pandas as pd
from PIL import Image
import matplotlib.pyplot as plt
# import src.segmentation.tool_superpixels as tl_spx
# import pattern_weights as ptn_weight
logger = logging.getLogger(__name__)
b_debug = False
RUN_DEBUG = True
VISUAL = True
PATH_BASE = '/datagrid/Medical/microscopy/drosophila/'
if b_debug:
if RUN_DEBUG:
NB_THREADS = 1
PATH_EXPERIMENTS = os.path.join(PATH_BASE, 'TEMPORARY', 'experiments_APD_temp')
SAMPLE_PATH_EXPERIMENT = os.path.join(PATH_EXPERIMENTS,
'ExperimentALPE_mp_real_type_3_segm_reg_binary_gene_ssmall_20160509-045213')
'ExperimentALPE_mp_real_type_3_segm_reg_binary_gene_ssmall_20160507-000427')
else:
NB_THREADS = int(mproc.cpu_count() * .8)
PATH_EXPERIMENTS = os.path.join(PATH_BASE, 'TEMPORARY', 'experiments_APD_new')
......@@ -39,7 +40,7 @@ PREFIX_ENCODE = 'encoding_'
PREFIX_RECONST = 'reconstruct_'
def draw_reconstruction(path_out, name, segm_orig, segm_reconst, img_atlas):
def export_fig_reconstruction(path_out, name, segm_orig, segm_reconst, img_atlas):
""" visualise reconstruction together with the original segmentation
:param path_out: str
......@@ -48,19 +49,21 @@ def draw_reconstruction(path_out, name, segm_orig, segm_reconst, img_atlas):
:param segm_reconst: np.array<height, width>
:param img_atlas: np.array<height, width>
"""
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(16, 8))
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(20, 8))
ax[0].set_title('original segmentation')
ax[0].imshow(1 - segm_orig, cmap='Greys'), ax[0].axis('off')
ax[0].contour(segm_reconst > 0, linewidth=2)
ax[0].contour(segm_reconst, linewidth=2, cmap=plt.cm.jet)
ax[1].set_title('reconstructed segmentation')
ax[1].imshow(segm_reconst), ax[1].axis('off')
ax[1].contour(segm_orig, linewidth=2)
ax[1].contour(segm_orig, linewidth=2, cmap=plt.cm.Greens)
segm_select = np.array(segm_reconst > 0, dtype=np.int)
segm_select[np.logical_and(img_atlas > 0, segm_reconst == 0)] = -1
segm_select[0, :2] = [-1, 1]
ax[2].set_title('selected vs not selected segm.')
ax[2].imshow(segm_select, cmap=plt.cm.RdYlGn), ax[2].axis('off')
ax[2].contour(segm_orig, linewidth=2, cmap=plt.cm.Blues)
ax[2].contour(segm_orig, linewidth=3, cmap=plt.cm.Blues)
ax[2].contour(img_atlas, linewidth=1, cmap=plt.cm.Pastel1)
p_fig = os.path.join(path_out, name + '.png')
fig.savefig(p_fig, bbox_inches='tight')
plt.close(fig)
......@@ -85,9 +88,10 @@ def compute_reconstruction(dict_params, path_out, img_atlas, weights, img_name):
logger.debug('segm unique: %s', repr(np.unique(segm_rect)))
if VISUAL:
try:
draw_reconstruction(path_out, img_name, segm_orig, segm_rect, img_atlas)
export_fig_reconstruction(path_out, img_name, segm_orig, segm_rect, img_atlas)
except:
logger.error(traceback.format_exc())
# logger.error(traceback.format_exc())
logger.warning('drawing fail for "%s"...', img_name)
segm_bin = (segm_rect >= 1)
diff = np.sum(segm_orig != segm_bin) / float(np.prod(segm_orig.shape))
return img_name, diff
......@@ -114,14 +118,19 @@ def load_atlas_image(path_atlas):
:param path_atlas: str
:return: np.array<height, width>
"""
img_atlas = np.array(Image.open(path_atlas))
assert os.path.exists(path_atlas)
img_atlas = Image.open(path_atlas)
# norm image to have labels as [0, 1, 2, ...]
img_atlas /= (img_atlas.max() / (len(np.unique(img_atlas)) + 1))
uq_labels = sorted([lb for nb, lb in img_atlas.getcolors() if nb > 0])
lut = np.zeros(max(uq_labels) + 1)
for i, lb in enumerate(uq_labels):
lut[lb] = i
img_atlas = lut[np.array(img_atlas)]
# subtract background (set it as -1)
# img_atlas -= 1
logger.debug('Atlas: %s with labels: %s', repr(img_atlas.shape),
repr(np.unique(img_atlas).tolist()))
return img_atlas
return img_atlas.astype(np.int)
def load_segmentation(dict_params, img_name):
......@@ -138,26 +147,26 @@ def load_segmentation(dict_params, img_name):
return img
def perform_reconstruction(dict_params, df_encode, img_atlas):
""" with loaded encoding and atlas does reconstruction for each image
:param dict_params: {str: value}
:param df_encode: DF<images>
:param img_atlas: np.array<height, width>
:return: DF<images>
"""
list_patterns = [col for col in df_encode.columns if col.startswith('ptn ')]
logger.debug('list of pattern names: %s', repr(list_patterns))
df_diff = pd.DataFrame()
# walk over images
for idx, row in df_encode.iterrows():
weights = row[list_patterns].values
name, diff = compute_reconstruction(dict_params, img_atlas, weights,
row['image'])
df_diff = df_diff.append({'image': name, 'diff': diff}, ignore_index=True)
df_diff = df_diff.set_index('image')
logger.debug(repr(df_diff.describe()))
return df_diff
# def perform_reconstruction(dict_params, df_encode, img_atlas):
# """ with loaded encoding and atlas does reconstruction for each image
#
# :param dict_params: {str: value}
# :param df_encode: DF<images>
# :param img_atlas: np.array<height, width>
# :return: DF<images>
# """
# list_patterns = [col for col in df_encode.columns if col.startswith('ptn ')]
# logger.debug('list of pattern names: %s', repr(list_patterns))
# df_diff = pd.DataFrame()
# # walk over images
# for idx, row in df_encode.iterrows():
# weights = row[list_patterns].values
# name, diff = compute_reconstruction(dict_params, path_out, img_atlas, weights,
# row['image'])
# df_diff = df_diff.append({'image': name, 'diff': diff}, ignore_index=True)
# df_diff = df_diff.set_index('image')
# logger.debug(repr(df_diff.describe()))
# return df_diff
def mproc_wrapper(mp_tuple):
......@@ -172,20 +181,36 @@ def mproc_wrapper(mp_tuple):
# return compute_reconstruction(dict_params, path_out, img_atlas, weights, img_name)
def export_fig_atlas(path_out, name, img_atlas):
fig = plt.figure(figsize=(8, 6))
ax = fig.gca().imshow(img_atlas)
uq_labels = np.unique(img_atlas)
boundaries = (uq_labels - 0.5).tolist() + [uq_labels.max() + 0.5]
cbar = plt.colorbar(ax, boundaries=boundaries)
cbar.set_ticks(uq_labels)
cbar.set_ticklabels(['ptn %i' % lb for lb in uq_labels])
fig.savefig(os.path.join(path_out, name + '_rgb.png'), bbox_inches='tight')
plt.close(fig)
def perform_reconstruction_mproc(dict_params, name_csv, df_encode, img_atlas):
path_out = os.path.join(dict_params['path_exp'],
name_csv.replace(PREFIX_ENCODE, PREFIX_RECONST))
if not os.path.exists(path_out):
os.mkdir(path_out)
if VISUAL:
export_fig_atlas(path_out, 'atlas', img_atlas)
list_patterns = [col for col in df_encode.columns if col.startswith('ptn ')]
logger.debug('list of pattern names: %s', repr(list_patterns))
list_idxs = [int(col[3:]) for col in list_patterns]
assert list_idxs == sorted(list_idxs)
assert np.max(img_atlas) <= len(list_patterns)
mp_tuples = ((dict_params, path_out, img_atlas, row[list_patterns].values, idx)
for idx, row in df_encode.iterrows())
if NB_THREADS > 1:
logger.debug('computing %i samples in %i threads', len(df_encode), NB_THREADS)
mproc_pool = mproc.Pool(NB_THREADS)
results = mproc_pool.map(mproc_wrapper, mp_tuples)
mproc_pool.close()
......@@ -225,9 +250,10 @@ def process_experiment(path_expt=SAMPLE_PATH_EXPERIMENT):
df_diffs_all = pd.concat([df_diffs_all, df_diff], axis=1)
df_diffs_all.to_csv(os.path.join(path_expt, 'reconstruction_diff.csv'))
if len(df_diffs_all) > 0:
logger.info(repr(df_diffs_all.describe()))
df_res = df_diffs_all.describe().transpose()[['count', 'mean', 'std', 'min', 'max']]
logger.info(repr(df_res))
with open(os.path.join(path_expt, 'reconstruction_diff.txt'), 'w') as fp:
fp.write(repr(df_diffs_all.describe()))
fp.write(repr(df_res))
else:
logger.error('no result parsed!')
......@@ -246,9 +272,11 @@ def main(path_base=PATH_EXPERIMENTS):
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
if RUN_DEBUG:
logging.basicConfig(level=logging.DEBUG)
logger.info('running...')
if b_debug:
if RUN_DEBUG:
process_experiment()
else:
main()
......
......@@ -142,6 +142,7 @@ class ExperimentALPE(experiment_apd.ExperimentAPD):
logger.error(traceback.format_exc())
atlas = np.zeros_like(self.imgs[0])
w_bins = np.zeros((len(self.imgs), 1))
assert atlas.max() == w_bins.shape[1]
return atlas, w_bins
def _perform_once(self, v):
......
"""
This script parse the csv with encoding and extend then by information
from general drosophila information file
Second it does mean activation on aggregated gene ids
"""
import os
import sys
import glob
import logging
import multiprocessing as mproc
import numpy as np
import pandas as pd
sys.path.append(os.path.abspath(os.path.join('..','..'))) # Add path to root
import src.segmentation.tool_superpixels as tl_spx
import src.atm_ptn_dict.run_apd_reconstruction as r_reconst
NB_THREADS = int(mproc.cpu_count() * .8)
PATH_BASE = '/datagrid/Medical/microscopy/drosophila/'
PATH_CSV_MAIN = os.path.join(PATH_BASE, 'all_disc_image_info_for_prague.txt')
PATH_EXPERIMENTS = os.path.join(PATH_BASE, 'TEMPORARY', 'experiments_APD_new')
# PATH_EXPERIMENTS = os.path.join(PATH_BASE, 'RESULTS', 'experiments_APD')
PREFIX_ATLAS = 'atlas_'
PREFIX_ENCODE = 'encoding_'
PREFIX_CONNECT = 'connectivity_'
POSIX_GENE = '_gene.csv'
logger = logging.getLogger(__name__)
# the debug mode use just map not parallel
RUN_DEBUG = False
def extend_df(df_encode, df_main):
if not 'gene_id' in df_encode.columns:
df_encode = df_encode.merge(df_main, left_index=True, right_on='image',
how='inner')
return df_encode
def aggregate_encoding(df_encode, column='gene_id', func=np.mean):
df_result = pd.DataFrame()
list_ptns = [c for c in df_encode if c.startswith('ptn ')]
grouped = df_encode.groupby(column)
for value, df_group in grouped:
data = df_group[list_ptns].values
result = np.apply_along_axis(func, axis=0, arr=data)
dict_res = dict(zip(list_ptns, result.tolist()))
dict_res.update({column: value, 'count': len(df_group)})
df_result = df_result.append(dict_res, ignore_index=True)
df_result = df_result.set_index(column)
return df_result
def export_atlas_connectivity(path_atlas):
logger.info('atlas (%s) of "%s"', os.path.exists(path_atlas), path_atlas)
img_atlas = r_reconst.load_atlas_image(path_atlas)
name_atlas = os.path.splitext(os.path.basename(path_atlas))[0]
r_reconst.export_fig_atlas(os.path.dirname(path_atlas), name_atlas, img_atlas)
vertices, edges = tl_spx.make_graph_segm_connect2d_conn4(img_atlas)
nb_lbs = max(vertices) + 1
matrix_connect = np.zeros((nb_lbs, nb_lbs))
for e1, e2 in edges:
matrix_connect[e1, e2] = 1
matrix_connect[e2, e1] = 1
list_ptns = ['ptn {}'.format(i) for i in range(nb_lbs)]
df_connect = pd.DataFrame(matrix_connect, columns=list_ptns, index=list_ptns)
path_csv = path_atlas.replace(PREFIX_ATLAS, PREFIX_CONNECT).replace('.png', '.csv')
df_connect.to_csv(path_csv)
def mproc_wrapper(mp_tuple):
return process_experiment(*mp_tuple)
def process_experiment(path_csv, df_main):
logger.info(' -> %s', os.path.basename(path_csv))
df_encode = pd.DataFrame.from_csv(path_csv)
df_encode = extend_df(df_encode, df_main)
if 'image' in df_encode.columns:
df_encode = df_encode.set_index('image')
df_encode.to_csv(path_csv)
df_result = aggregate_encoding(df_encode)
df_result.to_csv(path_csv.replace('.csv', '_gene.csv'))
path_atlas = path_csv.replace(PREFIX_ENCODE, PREFIX_ATLAS).replace('.csv', '.png')
export_atlas_connectivity(path_atlas)
def main(path_csv_main=PATH_CSV_MAIN, path_experiemnts=PATH_EXPERIMENTS):
logging.basicConfig(level=logging.INFO)
logger.info('exist: %i, %i', os.path.exists(PATH_CSV_MAIN), os.path.exists(PATH_EXPERIMENTS))
df_main = pd.DataFrame.from_csv(path_csv_main, sep='\t')
df_main['image'] = df_main['image_path'].apply(lambda x: x.split('.')[0])
list_expt = [p for p in glob.glob(os.path.join(path_experiemnts, '*'))
if os.path.isdir(p)]
for i, path_dir in enumerate(list_expt):
logger.info('EXPERIMENT: (%i / %i)', (i + 1), len(list_expt))
logger.info(os.path.basename(path_dir))
list_csv = [p for p in glob.glob(os.path.join(path_dir, 'encoding_*.csv'))
if not p.endswith('_gene.csv')]
mp_tuples = zip(list_csv, [df_main] * len(list_csv))
if RUN_DEBUG:
map(mproc_wrapper, mp_tuples)
else:
mproc_pool = mproc.Pool(len(mp_tuples))
mproc_pool.map(mproc_wrapper, mp_tuples)
mproc_pool.close()
mproc_pool.join()
logger.info('DONE')
if __name__ == '__main__':
main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment