From 4722e965b020db6a3f7c16e6dd7a81402acccb13 Mon Sep 17 00:00:00 2001 From: Melissa Linkert Date: Thu, 9 Dec 2021 16:21:08 -0600 Subject: [PATCH] Update well paths to use row and column names instead of indexes --- .../bioformats2raw/Converter.java | 22 +++--- .../bioformats2raw/HCSIndex.java | 33 ++++++++- .../bioformats2raw/test/ZarrTest.java | 68 +++++++++---------- 3 files changed, 74 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java index 4624cb0b..839ef6b2 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/Converter.java @@ -627,7 +627,7 @@ public void convert() } if (!noHCS) { - scaleFormatString = "%d/%d/%d/%d"; + scaleFormatString = "%s/%s/%d/%d"; } for (Integer index : seriesList) { @@ -711,8 +711,8 @@ private Object[] getScaleFormatStringArgs( List args = new ArrayList(); if (!noHCS) { HCSIndex index = hcsIndexes.get(series); - args.add(index.getWellRowIndex()); - args.add(index.getWellColumnIndex()); + args.add(index.getRowPath()); + args.add(index.getColumnPath()); args.add(index.getFieldIndex()); args.add(resolution); } @@ -1343,7 +1343,7 @@ private void saveHCSMetadata(IMetadata meta) throws IOException { } for (int r=0; r row = new HashMap(); - String rowName = String.valueOf(r); + String rowName = HCSIndex.getRowName(r); row.put("name", rowName); rows.add(row); } @@ -1358,7 +1358,7 @@ private void saveHCSMetadata(IMetadata meta) throws IOException { } for (int c=0; c column = new HashMap(); - String columnName = String.valueOf(c); + String columnName = HCSIndex.getColumnName(c); column.put("name", columnName); columns.add(column); } @@ -1413,33 +1413,33 @@ private void saveHCSMetadata(IMetadata meta) throws IOException { // make sure the row/column indexes are added to the plate attributes // this is necessary when Plate.Rows or Plate.Columns is not set - int column = index.getWellColumnIndex(); - int row = index.getWellRowIndex(); + String column = index.getColumnPath(); + String row = index.getRowPath(); int columnIndex = -1; for (int c=0; c colMap = new HashMap(); - colMap.put("name", String.valueOf(column)); + colMap.put("name", column); columnIndex = columns.size(); columns.add(colMap); } int rowIndex = -1; for (int r=0; r rowMap = new HashMap(); - rowMap.put("name", String.valueOf(row)); + rowMap.put("name", row); rowIndex = rows.size(); rows.add(rowMap); } diff --git a/src/main/java/com/glencoesoftware/bioformats2raw/HCSIndex.java b/src/main/java/com/glencoesoftware/bioformats2raw/HCSIndex.java index 89196563..b5f31afe 100644 --- a/src/main/java/com/glencoesoftware/bioformats2raw/HCSIndex.java +++ b/src/main/java/com/glencoesoftware/bioformats2raw/HCSIndex.java @@ -98,14 +98,14 @@ public int getFieldIndex() { * @return row path relative to the plate group */ public String getRowPath() { - return String.format("%d", getWellRowIndex()); + return getRowName(getWellRowIndex()); } /** * @return column path relative to the row group */ public String getColumnPath() { - return String.format("%d", getWellColumnIndex()); + return getColumnName(getWellColumnIndex()); } /** @@ -125,4 +125,33 @@ public String toString() { getFieldIndex()); } + /** + * Get a row name for the specified 0-based row index. + * The name is a single upper-case letter starting with A + * if the row index is less than 26, and two upper-case letters + * starting with AA for indexes greater than or equal to 26. + * + * @param rowIndex row index + * @return row name + */ + public static String getRowName(int rowIndex) { + String name = String.valueOf((char) ('A' + (rowIndex % 26))); + if (rowIndex >= 26) { + name = (char) ('A' + ((rowIndex / 26) - 1)) + name; + } + return name; + } + + /** + * Get a column name for the specified 0-based column index. + * The name is a string representation of the corresponding + * 1-based index. + * + * @param colIndex column index + * @return column name + */ + public static String getColumnName(int colIndex) { + return String.format("%d", colIndex + 1); + } + } diff --git a/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java b/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java index 6f39a5f0..8c93a7f2 100644 --- a/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java +++ b/src/test/java/com/glencoesoftware/bioformats2raw/test/ZarrTest.java @@ -824,8 +824,8 @@ public void testHCSMetadata() throws Exception { int colCount = 3; int fieldCount = 2; Map> plateMap = new HashMap>(); - plateMap.put("0", Arrays.asList("0", "1", "2")); - plateMap.put("1", Arrays.asList("0", "1", "2")); + plateMap.put("A", Arrays.asList("1", "2", "3")); + plateMap.put("B", Arrays.asList("1", "2", "3")); checkPlateGroupLayout(output, rowCount, colCount, plateMap, fieldCount, 512, 512); @@ -846,14 +846,16 @@ public void testHCSMetadata() throws Exception { assertEquals(1, acquisitions.size()); assertEquals("0", acquisitions.get(0).get("id")); - checkDimension(rows, rowCount); - checkDimension(columns, colCount); + assertEquals(rows.size(), rowCount); + assertEquals(columns.size(), colCount); assertEquals(rows.size() * columns.size(), wells.size()); for (int row=0; row> plateMap = new HashMap>(); - plateMap.put("0", Arrays.asList("0")); - plateMap.put("1", Arrays.asList("0")); + plateMap.put("A", Arrays.asList("1")); + plateMap.put("B", Arrays.asList("1")); checkPlateGroupLayout(output, rowCount, colCount, plateMap, fieldCount, 2, 2); @@ -909,16 +911,18 @@ public void testHCSMetadataNoAcquisitions() throws Exception { assertFalse(plate.containsKey("acquisitions")); - checkDimension(rows, rowCount); - checkDimension(columns, colCount); + assertEquals(rows.size(), rowCount); + assertEquals(columns.size(), colCount); assertEquals(2, wells.size()); for (Map well : wells) { int row = ((Number) well.get("rowIndex")).intValue(); int col = ((Number) well.get("columnIndex")).intValue(); + String rowName = rows.get(row).get("name").toString(); + String colName = columns.get(col).get("name").toString(); String wellPath = well.get("path").toString(); - assertEquals(row + "/" + col, wellPath); + assertEquals(rowName + "/" + colName, wellPath); ZarrGroup wellGroup = ZarrGroup.open(output.resolve(wellPath)); checkWell(wellGroup, fieldCount, null); @@ -944,7 +948,7 @@ public void testSingleWell() throws IOException { int fieldCount = 1; Map> plateMap = new HashMap>(); - plateMap.put("4", Arrays.asList("5")); + plateMap.put("E", Arrays.asList("6")); checkPlateGroupLayout(output, rowCount, colCount, plateMap, fieldCount, 2, 2); @@ -966,13 +970,13 @@ public void testSingleWell() throws IOException { assertEquals(1, acquisitions.size()); assertEquals("0", acquisitions.get(0).get("id")); - checkDimension(rows, rowCount); - checkDimension(columns, colCount); + assertEquals(rows.size(), rowCount); + assertEquals(columns.size(), colCount); assertEquals(1, wells.size()); Map well = wells.get(0); String wellPath = (String) well.get("path"); - assertEquals("4/5", wellPath); + assertEquals("E/6", wellPath); assertEquals(4, ((Number) well.get("rowIndex")).intValue()); assertEquals(5, ((Number) well.get("columnIndex")).intValue()); @@ -1004,8 +1008,8 @@ public void testTwoWells(String resourceName) throws IOException { int fieldCount = 1; Map> plateMap = new HashMap>(); - plateMap.put("2", Arrays.asList("11")); - plateMap.put("7", Arrays.asList("1")); + plateMap.put("C", Arrays.asList("12")); + plateMap.put("H", Arrays.asList("2")); checkPlateGroupLayout(output, rowCount, colCount, plateMap, fieldCount, 2, 2); @@ -1026,13 +1030,13 @@ public void testTwoWells(String resourceName) throws IOException { assertEquals(1, acquisitions.size()); assertEquals("0", acquisitions.get(0).get("id")); - checkDimension(rows, rowCount); - checkDimension(columns, colCount); + assertEquals(rows.size(), rowCount); + assertEquals(columns.size(), colCount); assertEquals(2, wells.size()); Map well = wells.get(0); String wellPath = (String) well.get("path"); - assertEquals("2/11", wellPath); + assertEquals("C/12", wellPath); assertEquals(2, ((Number) well.get("rowIndex")).intValue()); assertEquals(11, ((Number) well.get("columnIndex")).intValue()); ZarrGroup wellGroup = ZarrGroup.open(output.resolve(wellPath)); @@ -1040,7 +1044,7 @@ public void testTwoWells(String resourceName) throws IOException { well = wells.get(1); wellPath = (String) well.get("path"); - assertEquals("7/1", wellPath); + assertEquals("H/2", wellPath); assertEquals(7, ((Number) well.get("rowIndex")).intValue()); assertEquals(1, ((Number) well.get("columnIndex")).intValue()); wellGroup = ZarrGroup.open(output.resolve(wellPath)); @@ -1062,8 +1066,8 @@ public void testOnePlateRow() throws IOException { int fieldCount = 1; Map> plateMap = new HashMap>(); - plateMap.put("5", Arrays.asList( - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")); + plateMap.put("F", Arrays.asList( + "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12")); checkPlateGroupLayout(output, rowCount, colCount, plateMap, fieldCount, 2, 2); @@ -1084,14 +1088,15 @@ public void testOnePlateRow() throws IOException { assertEquals(1, acquisitions.size()); assertEquals("0", acquisitions.get(0).get("id")); - checkDimension(rows, rowCount); - checkDimension(columns, colCount); + assertEquals(rows.size(), rowCount); + assertEquals(columns.size(), colCount); assertEquals(colCount, wells.size()); for (int col=0; col well = wells.get(col); String wellPath = (String) well.get("path"); - assertEquals("5/" + col, wellPath); + String colName = columns.get(col).get("name").toString(); + assertEquals("F/" + colName, wellPath); assertEquals(5, ((Number) well.get("rowIndex")).intValue()); assertEquals(col, ((Number) well.get("columnIndex")).intValue()); ZarrGroup wellGroup = ZarrGroup.open(output.resolve(wellPath)); @@ -1314,7 +1319,7 @@ private void checkPlateGroupLayout(Path root, int rowCount, int colCount, // if there are any wells with data in the row, the row path must exist // if there are no wells with data in the row, the row path cannot exist for (int row=0; row> dims, int dimCount) - throws IOException - { - assertEquals(dimCount, dims.size()); - for (int dim=0; dim