diff --git a/src/main/java/org/embl/mobie/MoBIE.java b/src/main/java/org/embl/mobie/MoBIE.java index 8c7c884c9..5497f0fb7 100644 --- a/src/main/java/org/embl/mobie/MoBIE.java +++ b/src/main/java/org/embl/mobie/MoBIE.java @@ -187,20 +187,6 @@ public MoBIE( String tablePath, List< String > imageColumns, List< String > labe openImagesAndLabels( imageSources, labelSources ); } - // opens an AutoMicTools table - // FIXME: Can we generalise this? - public MoBIE( String autoMicTablePath, GridType gridType, MoBIESettings settings ) - { - this.settings = settings; - - // FIXME: Can we generalise this and use the normal sources creator? - SourcesFromAutoMicTableCreator sourcesCreator = new SourcesFromAutoMicTableCreator( autoMicTablePath, gridType ); - final List< ImageFileSources > imageSources = sourcesCreator.getImageSources(); - final List< LabelFileSources > labelSources = sourcesCreator.getLabelSources(); - - openImagesAndLabels( imageSources, labelSources ); - } - private void initTableSaw() { // force TableSaw class loading diff --git a/src/main/java/org/embl/mobie/command/open/OpenAutoMicToolsTableCommand.java b/src/main/java/org/embl/mobie/command/open/OpenAutoMicToolsTableCommand.java deleted file mode 100644 index b6a767f91..000000000 --- a/src/main/java/org/embl/mobie/command/open/OpenAutoMicToolsTableCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * #%L - * Fiji viewer for MoBIE projects - * %% - * Copyright (C) 2018 - 2023 EMBL - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ -package org.embl.mobie.command.open; - -import loci.common.DebugTools; -import org.embl.mobie.MoBIE; -import org.embl.mobie.MoBIESettings; -import org.embl.mobie.command.CommandConstants; -import org.embl.mobie.lib.transform.GridType; -import org.scijava.command.Command; -import org.scijava.plugin.Parameter; -import org.scijava.plugin.Plugin; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; - -@Plugin(type = Command.class, menuPath = CommandConstants.MOBIE_PLUGIN_OPEN + "Experimental>Open AutoMicTools Table..." ) -public class OpenAutoMicToolsTableCommand implements Command { - - static { net.imagej.patcher.LegacyInjector.preinit(); } - - @Parameter( label = "Table Path", required = true ) - public File table; - - @Override - public void run() - { - DebugTools.setRootLevel( "OFF" ); - - final GridType gridType = GridType.Transformed; // TODO: fetch from UI - - final MoBIESettings settings = new MoBIESettings(); - settings.removeSpatialCalibration( false ); - - new MoBIE( table.getAbsolutePath(), gridType, settings ); - } -} diff --git a/src/main/java/org/embl/mobie/command/open/OpenTableCommand.java b/src/main/java/org/embl/mobie/command/open/OpenTableCommand.java index 46e20d034..a9e40b505 100644 --- a/src/main/java/org/embl/mobie/command/open/OpenTableCommand.java +++ b/src/main/java/org/embl/mobie/command/open/OpenTableCommand.java @@ -28,6 +28,7 @@ */ package org.embl.mobie.command.open; +import loci.common.DebugTools; import org.embl.mobie.MoBIE; import org.embl.mobie.MoBIESettings; import org.embl.mobie.command.CommandConstants; @@ -66,6 +67,8 @@ public class OpenTableCommand implements Command { @Override public void run() { + DebugTools.setRootLevel( "OFF" ); + final GridType gridType = GridType.Stitched; // TODO: fetch from UI final MoBIESettings settings = new MoBIESettings(); diff --git a/src/main/java/org/embl/mobie/command/open/omezarr/OpenOMEZARRCommand.java b/src/main/java/org/embl/mobie/command/open/omezarr/OpenOMEZARRCommand.java index c8b413a81..d1f081bbc 100644 --- a/src/main/java/org/embl/mobie/command/open/omezarr/OpenOMEZARRCommand.java +++ b/src/main/java/org/embl/mobie/command/open/omezarr/OpenOMEZARRCommand.java @@ -44,8 +44,8 @@ public class OpenOMEZARRCommand implements Command { static { net.imagej.patcher.LegacyInjector.preinit(); } - @Parameter(label = "File path", style = "directory") - public File directory; + @Parameter(label = "OME-Zarr path", style = "directory") + public File omeZarrDirectory; protected static void openAndShow(String filePath) throws IOException { SpimData spimData = OMEZarrOpener.openFile(filePath); @@ -56,7 +56,7 @@ protected static void openAndShow(String filePath) throws IOException { @Override public void run() { try { - openAndShow( directory.toString() ); + openAndShow( omeZarrDirectory.toString() ); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/org/embl/mobie/lib/MoBIEHelper.java b/src/main/java/org/embl/mobie/lib/MoBIEHelper.java index 458966226..c4ffe260e 100644 --- a/src/main/java/org/embl/mobie/lib/MoBIEHelper.java +++ b/src/main/java/org/embl/mobie/lib/MoBIEHelper.java @@ -46,7 +46,9 @@ import org.embl.mobie.lib.source.SourceToImagePlusConverter; import spimdata.util.Displaysettings; import tech.tablesaw.api.Table; +import vib.app.FileGroup; +import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -185,6 +187,11 @@ public static List< String > getNamedGroups( String regex ) public static Metadata getMetadataFromImageFile( String path, int channelIndex ) { + if ( ! new File( path ).exists() ) + { + throw new RuntimeException( "Path does not exist: " + path ); + } + if ( path.contains( ".zarr" ) ) { try @@ -193,7 +200,9 @@ public static Metadata getMetadataFromImageFile( String path, int channelIndex ) final SpimSource< ? > source = new SpimSource( spimData, channelIndex, "" ); final int levels = source.getNumMipmapLevels(); final ImagePlus imagePlus = new SourceToImagePlusConverter<>( source ).getImagePlus( levels - 1 ); - return new Metadata( imagePlus ); + Metadata metadata = new Metadata( imagePlus ); + metadata.numChannelsContainer = spimData.getSequenceDescription().getViewSetups().size(); + return metadata; } catch ( SpimDataException e ) { diff --git a/src/main/java/org/embl/mobie/lib/SourcesFromAutoMicTableCreator.java b/src/main/java/org/embl/mobie/lib/SourcesFromAutoMicTableCreator.java deleted file mode 100644 index cfcd325cd..000000000 --- a/src/main/java/org/embl/mobie/lib/SourcesFromAutoMicTableCreator.java +++ /dev/null @@ -1,99 +0,0 @@ -/*- - * #%L - * Fiji viewer for MoBIE projects - * %% - * Copyright (C) 2018 - 2023 EMBL - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ -package org.embl.mobie.lib; - -import ij.IJ; -import ij.ImagePlus; -import org.embl.mobie.lib.files.ImageFileSources; -import org.embl.mobie.lib.files.LabelFileSources; -import org.embl.mobie.lib.table.saw.TableOpener; -import org.embl.mobie.lib.transform.GridType; -import tech.tablesaw.api.Table; - -import java.io.File; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; - -public class SourcesFromAutoMicTableCreator -{ - private final List< ImageFileSources > imageFileSources; - private final List< LabelFileSources > labelSources; - public SourcesFromAutoMicTableCreator( String tablePath, GridType gridType ) - { - File tableFile = new File( tablePath ); - Path rootFolder = Paths.get( tableFile.getParent() ); - final Table table = TableOpener.openDelimitedTextFile( tablePath ); - table.columnNames(); - - //String[] imageFileTags = tableModel.getImageFileTags(); - String[] imageTags = new String[]{ "Result.Image" }; // FIXME: Do not hard-code - - imageFileSources = new ArrayList<>(); - for ( String imageTag : imageTags ) - { - String referenceImagePath = MoBIEHelper.getAbsoluteImagePathFromAutoMicTable( table, imageTag, rootFolder, 0 ); - - int numChannels = getNumChannels( imageTag, referenceImagePath ); - - for ( int channelIndex = 0; channelIndex < numChannels; channelIndex++ ) - { - imageFileSources.add( new ImageFileSources( imageTag + "_C" + channelIndex, table, rootFolder, imageTag, channelIndex, gridType ) ); - } - } - - labelSources = new ArrayList<>(); // TODO: AutoMicTools uses ROIs.... - } - - private static int getNumChannels( String imageTag, String metadataImagePath ) { - try - { - IJ.log( "Determining number of channels of " + imageTag + "..."); - final ImagePlus imagePlus = MoBIEHelper.openWithBioFormats( metadataImagePath, 0 ); - int numChannels = imagePlus.getNChannels(); - IJ.log( "...number of channels is " + numChannels ); - return numChannels; - } - catch ( Exception e ) - { - throw new RuntimeException( e ); - } - } - - public List< ImageFileSources > getImageSources() - { - return imageFileSources; - } - - public List< LabelFileSources > getLabelSources() - { - return labelSources; - } -} diff --git a/src/main/java/org/embl/mobie/lib/SourcesFromTableCreator.java b/src/main/java/org/embl/mobie/lib/SourcesFromTableCreator.java index 4a9efa2bf..89ffa9a9c 100644 --- a/src/main/java/org/embl/mobie/lib/SourcesFromTableCreator.java +++ b/src/main/java/org/embl/mobie/lib/SourcesFromTableCreator.java @@ -28,6 +28,7 @@ */ package org.embl.mobie.lib; +import ij.IJ; import org.embl.mobie.lib.files.ImageFileSources; import org.embl.mobie.lib.files.LabelFileSources; import org.embl.mobie.lib.io.TableImageSource; @@ -35,6 +36,9 @@ import org.embl.mobie.lib.transform.GridType; import tech.tablesaw.api.Table; +import java.io.File; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -51,12 +55,33 @@ public SourcesFromTableCreator( String tablePath, List< String > imageColumns, L for ( String image : imageColumns ) { - final TableImageSource tableImageSource = new TableImageSource( image ); - imageFileSources.add( new ImageFileSources( tableImageSource.name, table, tableImageSource.columnName, tableImageSource.channelIndex, root, gridType ) ); + if ( table.columnNames().contains( "FileName_" + image + "_IMG" ) ) + { + // This is an AutoMicTools table, where the image path is distributed into the two columns (file name and folder) + gridType = GridType.Transformed; // To accommodate rotations + Path rootFolder = Paths.get( root ); + String referenceImagePath = MoBIEHelper.getAbsoluteImagePathFromAutoMicTable( table, image, rootFolder, 0 ); + IJ.log("Detected AutoMicTools table"); + IJ.log("Determining number of channels of " + image + ", using " + referenceImagePath + "..."); + int numChannels = MoBIEHelper.getMetadataFromImageFile( referenceImagePath, 0 ).numChannelsContainer; + IJ.log("Number of channels is " + numChannels); + for ( int channelIndex = 0; channelIndex < numChannels; channelIndex++ ) + { + imageFileSources.add( new ImageFileSources( image + "_C" + channelIndex, table, rootFolder, image, channelIndex, gridType ) ); + } + } + else + { + // Default table + final TableImageSource tableImageSource = new TableImageSource( image ); + imageFileSources.add( new ImageFileSources( tableImageSource.name, table, tableImageSource.columnName, tableImageSource.channelIndex, root, gridType ) ); + } } labelSources = new ArrayList<>(); - // see https://github.com/mobie/mobie-viewer-fiji/issues/1038 + if ( labelColumns.isEmpty() ) + return; + final String firstLabel = labelColumns.get( 0 ); for ( String label : labelColumns ) { diff --git a/src/main/java/org/embl/mobie/lib/files/ImageFileSources.java b/src/main/java/org/embl/mobie/lib/files/ImageFileSources.java index 20f9d15b1..dddd37f4e 100644 --- a/src/main/java/org/embl/mobie/lib/files/ImageFileSources.java +++ b/src/main/java/org/embl/mobie/lib/files/ImageFileSources.java @@ -121,23 +121,20 @@ public ImageFileSources( String name, Table table, String pathColumn, Integer ch // add table columns to region table final List< Column< ? > > columns = table.columns(); - final int numColumns = columns.size(); - for ( int columnIndex = 0; columnIndex < numColumns; columnIndex++ ) - { - final Column< ? > column = columns.get( columnIndex ); - - if ( column instanceof NumberColumn ) - { - final Table summary = table.summarize( column, mean ).by( pathColumn ); - regionTable = regionTable.joinOn( pathColumn ).leftOuter( summary ); - } - - if ( column instanceof StringColumn ) - { - final Table summary = table.summarize( column, Aggregators.firstString ).by( pathColumn ); - regionTable = regionTable.joinOn( pathColumn ).leftOuter( summary ); - } - } + for ( final Column< ? > column : columns ) + { + if ( column instanceof NumberColumn ) + { + final Table summary = table.summarize( column, mean ).by( pathColumn ); + regionTable = regionTable.joinOn( pathColumn ).leftOuter( summary ); + } + + if ( column instanceof StringColumn ) + { + final Table summary = table.summarize( column, Aggregators.firstString ).by( pathColumn ); + regionTable = regionTable.joinOn( pathColumn ).leftOuter( summary ); + } + } } // For creating image sources from an AutoMicTools table diff --git a/src/main/java/org/embl/mobie/lib/source/Metadata.java b/src/main/java/org/embl/mobie/lib/source/Metadata.java index 14b5c2c08..455cc1bf5 100644 --- a/src/main/java/org/embl/mobie/lib/source/Metadata.java +++ b/src/main/java/org/embl/mobie/lib/source/Metadata.java @@ -34,9 +34,11 @@ public class Metadata { public String color = "White"; + public double[] contrastLimits = null; public Integer numTimePoints = null; public Integer numZSlices = 1; + public Integer numChannelsContainer = 1; // in MoBIE each image has jsut one channel, but the container could have multiple public Metadata() { @@ -51,6 +53,7 @@ public Metadata( ImagePlus imagePlus ) contrastLimits = new double[]{ imagePlus.getDisplayRangeMin(), imagePlus.getDisplayRangeMax() }; numTimePoints = imagePlus.getNFrames(); numZSlices = imagePlus.getNSlices(); + numChannelsContainer = imagePlus.getNChannels(); } } diff --git a/src/test/java/develop/OpenAutoMicTable.java b/src/test/java/develop/OpenAutoMicTable.java index d78f5c9ac..3f4191d93 100644 --- a/src/test/java/develop/OpenAutoMicTable.java +++ b/src/test/java/develop/OpenAutoMicTable.java @@ -1,7 +1,7 @@ package develop; import net.imagej.ImageJ; -import org.embl.mobie.command.open.OpenAutoMicToolsTableCommand; +import org.embl.mobie.command.open.OpenTableCommand; import java.io.File; @@ -12,10 +12,14 @@ public static void main( String[] args ) final ImageJ imageJ = new ImageJ(); imageJ.ui().showUI(); - OpenAutoMicToolsTableCommand command = new OpenAutoMicToolsTableCommand(); + OpenTableCommand command = new OpenTableCommand(); //command.table = new File( "/Volumes/almf/group/Aliaksandr/User_data/Furlong_CrispR/test_data_20231018/20231004/20231004-172458/summary_calculated1.txt" ); //command.table = new File( "/Volumes/almf/group/Aliaksandr/User_data/Furlong_CrispR/test_data_20231018/20231004/20231004-172458/summary_calculated1_subset.txt" ); command.table = new File( "/Users/tischer/Desktop/teresa/summary_calculated1_subset.txt" ); + //command.table = new File( "/Volumes/cba/exchange/furlong_test/summary_calculated1_subset_zarr.txt" ); + //command.images = "Result.Image.Zarr"; // Result.Image.Zarr + command.root = command.table.getParentFile(); + command.images = "Result.Image"; // Result.Image.Zarr command.run(); } } diff --git a/src/test/java/develop/OpenOMEZarr.java b/src/test/java/develop/OpenOMEZarr.java new file mode 100644 index 000000000..04d1a3a54 --- /dev/null +++ b/src/test/java/develop/OpenOMEZarr.java @@ -0,0 +1,19 @@ +package develop; + +import net.imagej.ImageJ; +import org.embl.mobie.command.open.omezarr.OpenOMEZARRCommand; + +import java.io.File; + +public class OpenOMEZarr +{ + public static void main( String[] args ) + { + final ImageJ imageJ = new ImageJ(); + imageJ.ui().showUI(); + + OpenOMEZARRCommand command = new OpenOMEZARRCommand(); + command.omeZarrDirectory = new File( "/Volumes/cba/exchange/ome-zarr/bugra/Result-Image-Zarr/Result-Image--WA01--P0001--T0001--001.ome.zarr" ); + command.run(); + } +}