Skip to content
Snippets Groups Projects
Commit eddbc834 authored by Constantin Pape's avatar Constantin Pape
Browse files

Add test for morphology attributes

parent fe2a9c01
No related branches found
No related tags found
No related merge requests found
*.h5
__pycache__/
tmp*
......@@ -50,7 +50,7 @@ def make_cell_tables(folder, name, tmp_folder, resolution,
if not os.path.exists(aux_gene_path):
raise RuntimeError("Can't find auxiliary gene file")
gene_out = os.path.join(table_folder, 'genes.csv')
# write_genes_table(seg_path, aux_gene_path, gene_out, label_ids)
write_genes_table(seg_path, aux_gene_path, gene_out, label_ids)
# make table with morphology
morpho_out = os.path.join(table_folder, 'morphology.csv')
......
import unittest
import sys
import os
import numpy as np
sys.path.append('../..')
# check new version of gene mapping against original
class TestMorphologyAttributes(unittest.TestCase):
test_file = 'test_table.csv'
def tearDown(self):
try:
os.remove(self.test_file)
except OSError:
pass
def load_table(self, table_file):
table = np.genfromtxt(table_file, delimiter='\t', skip_header=1,
dtype='float32')
return table
def test_nucleus_morphology(self):
from scripts.attributes.morphology import write_morphology_nuclei
# compute and load the morpho table
seg_path = '../../data/0.0.0/segmentations/em-segmented-nuclei-labels.h5'
table_in_path = '../../data/0.0.0/tables/em-segmented-nuclei-labels/default.csv'
table_out_path = self.test_file
print("Start computation ...")
write_morphology_nuclei(seg_path, table_in_path, table_out_path)
table = self.load_table(table_out_path)
# load original table, make sure new and old table agree
original_table_file = '../../data/0.0.0/tables/em-segmented-nuclei-labels/morphology.csv'
original_table = self.load_table(original_table_file)
self.assertEqual(table.shape, original_table.shape)
self.assertTrue(np.allclose(table, original_table))
def test_cell_morphology(self):
from scripts.attributes.morphology import write_morphology_cells
# compute and load the morpho table
seg_path = '../../data/0.0.0/segmentations/em-segmented-cells-labels.h5'
mapping_path = '../../data/0.0.0/tables/em-segmented-cells-labels/objects.csv'
table_in_path = '../../data/0.0.0/tables/em-segmented-cells-labels/default.csv'
table_out_path = self.test_file
print("Start computation ...")
write_morphology_cells(seg_path, table_in_path, mapping_path, table_out_path)
table = self.load_table(table_out_path)
# load original table, make sure new and old table agree
original_table_file = '../../data/0.0.0/tables/em-segmented-cells-labels/morphology.csv'
original_table = self.load_table(original_table_file)
self.assertEqual(table.shape, original_table.shape)
self.assertTrue(np.allclose(table, original_table))
if __name__ == '__main__':
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment