Skip to content

Commit

Permalink
Refactor AutoMicTools specific code into general table opening code
Browse files Browse the repository at this point in the history
  • Loading branch information
tischi committed Oct 25, 2023
1 parent 44ca37c commit 717629b
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 203 deletions.
14 changes: 0 additions & 14 deletions src/main/java/org/embl/mobie/MoBIE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/embl/mobie/lib/MoBIEHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 )
{
Expand Down

This file was deleted.

31 changes: 28 additions & 3 deletions src/main/java/org/embl/mobie/lib/SourcesFromTableCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@
*/
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;
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;

Expand All @@ -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 )
{
Expand Down
31 changes: 14 additions & 17 deletions src/main/java/org/embl/mobie/lib/files/ImageFileSources.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/embl/mobie/lib/source/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -51,6 +53,7 @@ public Metadata( ImagePlus imagePlus )
contrastLimits = new double[]{ imagePlus.getDisplayRangeMin(), imagePlus.getDisplayRangeMax() };
numTimePoints = imagePlus.getNFrames();
numZSlices = imagePlus.getNSlices();
numChannelsContainer = imagePlus.getNChannels();
}

}
8 changes: 6 additions & 2 deletions src/test/java/develop/OpenAutoMicTable.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
}
}
Loading

0 comments on commit 717629b

Please sign in to comment.