Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'Roi' for name of RoiColumn #56

Merged
merged 5 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ In *both* cases, it is required that ROIs on the Image in OMERO have the ``Name`
image.csv::

# header roi,l,d,l
roi,object,probability,area
Roi,object,probability,area
501,1,0.8,250
502,1,0.9,500
503,1,0.2,25
Expand All @@ -162,7 +162,7 @@ image.csv::
This will create an OMERO.table linked to the Image like this:

=== ====== =========== ==== ========
roi object probability area Roi Name
Roi object probability area Roi Name
=== ====== =========== ==== ========
501 1 0.8 250 Sample1
502 1 0.9 500 Sample2
Expand Down
18 changes: 12 additions & 6 deletions src/omero_metadata/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,20 +298,26 @@ def _create_columns(self, klass):
if column.__class__ is PlateColumn:
append.append(StringColumn(PLATE_NAME_COLUMN, '',
self.DEFAULT_COLUMN_SIZE, list()))
column.name = "Plate"
if column.__class__ is WellColumn:
append.append(StringColumn(WELL_NAME_COLUMN, '',
self.DEFAULT_COLUMN_SIZE, list()))
column.name = "Well"
if column.__class__ is ImageColumn:
append.append(StringColumn(IMAGE_NAME_COLUMN, '',
self.DEFAULT_COLUMN_SIZE, list()))
# Currently hard-coded, but "if image name, then add image id"
if column.name == IMAGE_NAME_COLUMN:
append.append(ImageColumn("Image", '', list()))
# Ensure ImageColumn is named "Image"
column.name = "Image"
if column.__class__ is RoiColumn:
append.append(StringColumn(ROI_NAME_COLUMN, '',
self.DEFAULT_COLUMN_SIZE, list()))
# Ensure RoiColumn is named 'Roi'
column.name = "Roi"
# If image/roi name, then add ID column"
if column.name == IMAGE_NAME_COLUMN:
append.append(ImageColumn("Image", '', list()))
if column.name == ROI_NAME_COLUMN:
append.append(RoiColumn("roi", '', list()))
append.append(RoiColumn("Roi", '', list()))
if self.columns_sanity_check(columns):
columns.extend(append)
return columns
Expand Down Expand Up @@ -1174,11 +1180,11 @@ def populate_row(self, row):
for column in self.columns:
if not values:
if isinstance(column, ImageColumn) or \
isinstance(column, RoiColumn) or \
column.name in (PLATE_NAME_COLUMN,
WELL_NAME_COLUMN,
IMAGE_NAME_COLUMN,
ROI_NAME_COLUMN,
'roi'):
ROI_NAME_COLUMN):
# Then assume that the values will be calculated
# later based on another column.
continue
Expand Down
60 changes: 52 additions & 8 deletions test/integration/metadata/test_populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,13 @@ def get_cfg(self):
def get_namespaces(self):
return [NSBULKANNOTATIONS]

def assert_rows(self, rows):
def assert_row_count(self, rows):
assert rows == self.row_count * self.col_count

def assert_columns(self, columns):
col_names = "Well,Well Type,Concentration,Well Name"
assert col_names == ",".join([c.name for c in columns])

def assert_child_annotations(self, oas):
for ma, wid, wr, wc in oas:
assert isinstance(ma, MapAnnotationI)
Expand Down Expand Up @@ -206,12 +210,17 @@ def __init__(self):
"P002,A1,Control,0", "P002,A2,Treatment,10"))
self.screen = None

def assert_rows(self, rows):
def assert_row_count(self, rows):
"""
Double the number of rows due to 2 plates.
"""
assert rows == 2 * self.row_count * self.col_count

def assert_columns(self, columns):
# Adds Plate Name,Well Name columns
col_names = "Plate,Well,Well Type,Concentration,Plate Name,Well Name"
assert col_names == ",".join([c.name for c in columns])

def get_target(self):
if not self.screen:
self.screen = self.create_screen(self.row_count, self.col_count)
Expand Down Expand Up @@ -574,6 +583,10 @@ def __init__(self):
)
self.plate = None

def assert_columns(self, columns):
col_names = "Well,Gene,Gene Names"
assert col_names == ",".join([c.name for c in columns])

def get_cfg(self):
return os.path.join(os.path.dirname(__file__),
'bulk_to_map_annotation_context_ns2_empty.yml')
Expand Down Expand Up @@ -636,6 +649,10 @@ def __init__(self):
)
self.plate = None

def assert_columns(self, columns):
col_names = "Well,Gene,Gene Names"
assert col_names == ",".join([c.name for c in columns])

def get_cfg(self):
return os.path.join(os.path.dirname(__file__),
'bulk_to_map_annotation_context_ns2_fail.yml')
Expand All @@ -656,7 +673,12 @@ def __init__(self):
self.images = None
self.names = ("A1", "A2")

def assert_rows(self, rows):
def assert_columns(self, columns):
# adds "Image" column to table
col_names = "Image Name,Type,Concentration,Image"
assert col_names == ",".join([c.name for c in columns])

def assert_row_count(self, rows):
# Hard-coded in createCsv's arguments
assert rows == 2

Expand Down Expand Up @@ -734,7 +756,12 @@ def __init__(self):
self.rois = None
self.names = ("roi1", "roi2")

def assert_rows(self, rows):
def assert_columns(self, columns):
# Adds a new 'Roi' column
col_names = "Roi Name,Feature,Concentration,Count,Roi"
assert col_names == ",".join([c.name for c in columns])

def assert_row_count(self, rows):
# Hard-coded in createCsv's arguments
assert rows == 2

Expand Down Expand Up @@ -833,7 +860,11 @@ def __init__(self):
self.dataset = None
self.images = None

def assert_rows(self, rows):
def assert_columns(self, columns):
col_names = "Image Name,Type,Concentration,Image"
assert col_names == ",".join([c.name for c in columns])

def assert_row_count(self, rows):
assert rows == 102


Expand All @@ -859,6 +890,10 @@ def __init__(self):
row_data=(u"A1,Control,0,მიკროსკოპის", u"A2,Treatment,10,პონი"),
encoding="utf-8")

def assert_columns(self, columns):
col_names = "Well,Well Type,Concentration,Extra type,Well Name"
assert col_names == ",".join([c.name for c in columns])


class UnicodeBOM(Plate2Wells):

Expand All @@ -870,6 +905,10 @@ def __init__(self):
row_data=("A1,Control,0,მიკროსკოპის", "A2,Treatment,10,პონი"),
encoding="utf-8-sig")

def assert_columns(self, columns):
col_names = "Well,Well Type,Concentration,Extra type,Well Name"
assert col_names == ",".join([c.name for c in columns])


class Project2Datasets(Fixture):

Expand All @@ -882,7 +921,11 @@ def __init__(self):
"D002,A1,Control,0", "D002,A2,Treatment,10"))
self.project = None

def assert_rows(self, rows):
def assert_columns(self, columns):
col_names = "Dataset Name,Image Name,Type,Concentration,Image"
assert col_names == ",".join([c.name for c in columns])

def assert_row_count(self, rows):
# Hard-coded in create_csv's arguments
assert rows == 4

Expand Down Expand Up @@ -1020,7 +1063,8 @@ def _test_parsing_context(self, fixture, batch_size):
def _assert_parsing_context_values(self, t, fixture):
cols = t.getHeaders()
rows = t.getNumberOfRows()
fixture.assert_rows(rows)
fixture.assert_row_count(rows)
fixture.assert_columns(cols)
for hit in range(rows):
row_values = [col.values[0] for col in t.read(
list(range(len(cols))), hit, hit+1).columns]
Expand Down Expand Up @@ -1149,7 +1193,7 @@ def test_populate_metadata_ns_anns(self, fixture):

cols = t.getHeaders()
rows = t.getNumberOfRows()
fixture.assert_rows(rows)
fixture.assert_row_count(rows)
data = [c.values for c in t.read(
list(range(len(cols))), 0, rows).columns]
row_values = list(zip(*data))
Expand Down