From b60a3891c79bd4e075897909ee52502e9ef14969 Mon Sep 17 00:00:00 2001
From: Constantin Pape <constantin.pape@iwr.uni-heidelberg.de>
Date: Mon, 4 Nov 2019 13:48:10 +0100
Subject: [PATCH] Fix issues with segmentation attributes derived from virtual
 cells

---
 analysis/correct_intensities.py |  5 ++---
 scripts/attributes/master.py    |  6 +++---
 scripts/default_config.py       |  4 +++-
 update_patch.py                 | 24 ++++++++++++++++--------
 4 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/analysis/correct_intensities.py b/analysis/correct_intensities.py
index 37d5664..253b853 100644
--- a/analysis/correct_intensities.py
+++ b/analysis/correct_intensities.py
@@ -60,7 +60,6 @@ def correct_intensities_test(target='local', max_jobs=32):
                          target=target, max_jobs=max_jobs)
 
 
-# FIXME scale 0 is damaged in the h5 file !
 def correct_intensities(target='slurm', max_jobs=250):
     raw_path = '../data/rawdata/sbem-6dpf-1-whole-raw.h5'
     tmp_folder = './tmp_intensity_correction'
@@ -185,6 +184,6 @@ def make_extrapolation_mask():
 
 
 if __name__ == '__main__':
-    # correct_intensities('slurm', 125)
-    make_subsampled_volume()
+    correct_intensities('local', 1)
+    # make_subsampled_volume()
     # make_extrapolation_mask()
diff --git a/scripts/attributes/master.py b/scripts/attributes/master.py
index ffc5775..799a960 100644
--- a/scripts/attributes/master.py
+++ b/scripts/attributes/master.py
@@ -50,9 +50,9 @@ def make_cell_tables(old_folder, folder, name, tmp_folder, resolution,
                           tmp_folder, target)
 
     # make table with gene mapping via VCs
-    vc_vol_path = os.path.join('segmentations', 'prospr-6dpf-1-whole-virtual-cells-labels.xml')
-    vc_vol_path = get_h5_path_from_xml(vc_vol_path, return_absolute_path=True)
-    vc_expression_path = os.path.join('tables', 'prospr-6dpf-1-whole-virtual-cells-labels', 'profile_clust_curated.csv')
+    vc_vol_path = get_seg_path(folder, 'prospr-6dpf-1-whole-virtual-cells-labels', 't00000/s00/0/cells')
+    vc_expression_path = os.path.join(folder, 'tables',
+                                      'prospr-6dpf-1-whole-virtual-cells-labels', 'profile_clust_curated.csv')
     med_expression_path = gene_out
     vc_out = os.path.join(table_folder, 'vc_assignments.csv')
     vc_assignment_table(seg_path, vc_vol_path, vc_expression_path,
diff --git a/scripts/default_config.py b/scripts/default_config.py
index c0ac729..5ec3402 100644
--- a/scripts/default_config.py
+++ b/scripts/default_config.py
@@ -3,8 +3,10 @@ import json
 from cluster_tools.cluster_tasks import BaseClusterTask
 
 DEFAULT_GROUP = os.environ.get('PLATYBROWSER_GROUP', 'kreshuk')
+# DEFAULT_SHEBANG = os.environ.get('PLATYBROWSER_SHEBANG',
+#                                  '#! /g/arendt/EM_6dpf_segmentation/platy-browser-data/software/conda/miniconda3/envs/platybrowser/bin/python')
 DEFAULT_SHEBANG = os.environ.get('PLATYBROWSER_SHEBANG',
-                                 '#! /g/arendt/EM_6dpf_segmentation/platy-browser-data/software/conda/miniconda3/envs/platybrowser/bin/python')
+                                 '#! /g/kreshuk/pape/Work/software/conda/miniconda3/envs/cluster_env37/bin/python')
 DEFAULT_BLOCK_SHAPE = [64, 512, 512]
 
 
diff --git a/update_patch.py b/update_patch.py
index 23716e9..0761cc7 100755
--- a/update_patch.py
+++ b/update_patch.py
@@ -58,16 +58,24 @@ def update_table(name, seg_dict, folder, new_folder,
 def update_tables(folder, new_folder, names_to_update, target, max_jobs):
     segmentations = get_segmentations()
 
+    # first copy all tables that just need to be copied
     for name, seg in segmentations.items():
         has_table = seg.get('has_tables', False) or 'table_update_function' in seg
-        if name in names_to_update:
-            if not has_table:
-                raise RuntimeError("Segmentation %s does not have a table:" % name)
-            update_table(name, seg, folder, new_folder,
-                         target, max_jobs)
-        else:
-            if has_table:
-                copy_tables(folder, new_folder, name)
+        needs_update = name in names_to_update
+        if not has_table or needs_update:
+            continue
+        copy_tables(folder, new_folder, name)
+
+    # now update all tables that need to be updated
+    for name, seg in segmentations.items():
+        has_table = seg.get('has_tables', False) or 'table_update_function' in seg
+        needs_update = name in names_to_update
+        if not needs_update:
+            continue
+        if needs_update and not has_table:
+            raise RuntimeError("Segmentation %s does not have a table:" % name)
+        update_table(name, seg, folder, new_folder,
+                     target, max_jobs)
 
 
 # TODO check for errors
-- 
GitLab