Skip to content

Commit

Permalink
Merge pull request #11 from PreibischLab/cloud
Browse files Browse the repository at this point in the history
Partial cloud support
  • Loading branch information
minnerbe authored Oct 15, 2024
2 parents 84e323b + 6cd9850 commit 13275e6
Show file tree
Hide file tree
Showing 24 changed files with 471 additions and 220 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ pip install stimwrap

## Java code examples

There are example classes in this [Java package](https://github.com/PreibischLab/STIM/tree/master/src/main/java/examples) that can help you getting started with programming in STIM, specifically `VisualizeStack.java` and `TestDisplayModes.java` could be useful.
There are example classes in this [Java package](https://github.com/PreibischLab/STIM/tree/master/src/main/java/examples) that can help you to get started with programming in STIM, specifically `VisualizeStack.java` and `TestDisplayModes.java` could be useful.
Additionally, the code for all command-line tools can be found [here](https://github.com/PreibischLab/STIM/tree/master/src/main/java/cmd), which is also a good starting place in combination with the [tutorials](https://github.com/preibischlab/stim/wiki/tutorials).
*Note that the install scripts [install](https://github.com/PreibischLab/STIM/blob/master/install) and [install_windows.bat](https://github.com/PreibischLab/STIM/blob/master/install_windows.bat) show a link between the command-line tool name and Java class name, e.g., `st-bdv-view` is `cmd.DisplayStackedSlides`.*
42 changes: 34 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,28 @@
<license.licenseName>gpl_v2</license.licenseName>
<license.copyrightOwners>ImgLib2-st developers.</license.copyrightOwners>

<imglib2.version>7.1.2</imglib2.version>
<imglib2-realtransform.version>4.0.3</imglib2-realtransform.version>
<imglib2-cache.version>1.0.0-beta-19</imglib2-cache.version>
<imglib2-algorithm.version>0.16.0</imglib2-algorithm.version>
<imglib2-roi.version>0.15.1</imglib2-roi.version>
<n5-imglib2.version>7.0.2</n5-imglib2.version>
<bigdataviewer-core.version>10.6.1</bigdataviewer-core.version>
<bigdataviewer-vistools.version>1.0.0-beta-36</bigdataviewer-vistools.version>

</properties>
<!--
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build> -->

<developers>
<developer>
Expand All @@ -52,6 +73,7 @@
</roles>
</developer>
</developers>

<contributors>
<contributor>
<name>StephanPreibisch</name>
Expand Down Expand Up @@ -158,29 +180,33 @@
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-imglib2</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-hdf5</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-zarr</artifactId>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>org.janelia.n5anndata</groupId>
<artifactId>n5-anndata</artifactId>
<version>0.1</version>
</dependency>

<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-universe</artifactId>
</dependency>
<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-aws-s3</artifactId>
<version>4.2.0</version>
</dependency>
<!-- JUnit framework -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -193,7 +219,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.7</version>
<!-- <version>1.7</version> -->
</dependency>

<dependency>
Expand All @@ -213,13 +239,13 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.14.1</version>
<!-- <version>2.14.1</version> -->
</dependency>
<!-- Log4j API -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.14.1</version>
<!-- <version>2.14.1</version> -->
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cmd/AddPairwiseMatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
import picocli.CommandLine.Option;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.logging.log4j.Logger;

import util.LoggerUtil;

@Command(name = "st-align-pairs-add", mixinStandardHelpOptions = true, version = "0.3.1", description = "Spatial Transcriptomics as IMages project - add manual landmarks to align pairs of slices")
Expand Down Expand Up @@ -60,7 +60,7 @@ public class AddPairwiseMatch implements Callable<Void> {

@Override
public Void call() throws Exception {
if (!(new File(containerPath)).exists()) {
if (! SpatialDataContainer.exists(containerPath)) {
logger.error("Container '{}' does not exist. Stopping.", containerPath);
return null;
}
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/cmd/BigDataViewerDisplay.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cmd;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -46,11 +45,15 @@
import picocli.CommandLine.Option;
import render.Render;
import org.apache.logging.log4j.Logger;

import util.LoggerUtil;

@Command(name = "st-bdv-view", mixinStandardHelpOptions = true, version = "0.3.1", description = "Spatial Transcriptomics as IMages project - visualize ST data in BigDataViewer")
public class BigDataViewerDisplay implements Callable<Void>
{
// -i /Users/preibischs/Documents/BIMSB/Publications/imglib2-st/slide-seq/raw/slide-seq.n5 -d Puck_180531_23.n5 -g Calm2 -bmax 0.25
// -i /Users/preibischs/Documents/BIMSB/Publications/imglib2-st/slide-seq/raw/slide-seq.n5 -d Puck_180531_22.n5 -g Malat1,Calm2,Calm1 --rendering Gauss -bmin 0.0 -bmax 0.141 -rf 1.5384 --ffSingleSpot 1.25 -a cell type

private static final Logger logger = LoggerUtil.getLogger();

@Option(names = {"-i", "--input"}, required = true, description = "input file (AnnData) or N5 container, e.g. -i /home/ssq.n5")
Expand All @@ -59,7 +62,7 @@ public class BigDataViewerDisplay implements Callable<Void>
@Option(names = {"-g", "--genes"}, required = true, description = "comma separated list of one or more gene to visualize, e.g. -g Calm2,Ubb")
private String genes = null;

@Option(names = {"-a", "--annotation"}, required = false, description = "comma separated list of annotations to visualize, e.g. -a celltype")
@Option(names = {"-a", "--annotation"}, required = false, description = "comma separated list of annotations to visualize, e.g. -a cell type")
private String annotations = null;

@Option(names = {"-ar", "--annotationRadius"}, required = false, description = "radius of annotation spots as a factor of their median distance, e.g. -ar 2.0 (default: 0.75; in 3d: zSpacing*0.75)")
Expand All @@ -74,7 +77,7 @@ public class BigDataViewerDisplay implements Callable<Void>
@Option(names = {"-bmax", "--brightnessMax"}, required = false, description = "max initial brightness relative to the maximal value (default: 0.5)")
private double brightnessMax = 0.5;

@Option(names = {"--rendering"}, required = false, description = "inital rendering type (Gauss, Mean, NearestNeighbor, Linear), e.g --rendering Gauss (default: Gauss)")
@Option(names = {"--rendering"}, required = false, description = "initial rendering type (Gauss, Mean, NearestNeighbor, Linear), e.g --rendering Gauss (default: Gauss)")
private Rendering rendering = Rendering.Gauss;

@Option(names = {"-rf", "--renderingFactor"}, required = false, description = "factor for the amount of filtering or radius used for rendering, corresponds to smoothness for Gauss, e.g -rf 2.0 (default: 1.5)")
Expand All @@ -97,7 +100,7 @@ public Void call() throws Exception {

final boolean useTransform = true;

if (!(new File(inputPath)).exists()) {
if (! SpatialDataContainer.exists(inputPath)) {
logger.error("Container / dataset '{}' does not exist. Stopping.", inputPath);
return null;
}
Expand Down Expand Up @@ -158,16 +161,16 @@ public Void call() throws Exception {
//
for ( final String annotation : annotationList )
{
final IntType outofboundsInt = new IntType( -1 );
final IntType outOfBoundsInt = new IntType( -1 );
final double spotSize = dataToVisualize.statistics().getMedianDistance() * annotationRadius;
final HashMap<Long, ARGBType > lut = new HashMap<>();

final List< FilterFactory< IntType, IntType > > filterFactorysInt = new ArrayList<>();
final List< FilterFactory< IntType, IntType > > filterFactoriesInt = new ArrayList<>();

if ( ffSingleSpot != null && ffSingleSpot > 0 )
{
logger.debug("Using single-spot filtering, effective radius={}", dataToVisualize.statistics().getMedianDistance() * ffSingleSpot);
filterFactorysInt.add( new SingleSpotRemovingFilterFactory<>( outofboundsInt, dataToVisualize.statistics().getMedianDistance() * ffSingleSpot ) );
filterFactoriesInt.add( new SingleSpotRemovingFilterFactory<>( outOfBoundsInt, dataToVisualize.statistics().getMedianDistance() * ffSingleSpot ) );
}

final RealRandomAccessible< IntType > rra;
Expand All @@ -179,8 +182,8 @@ public Void call() throws Exception {
annotation,
spotSize,
dataToVisualize.transform(),
outofboundsInt,
filterFactorysInt,
outOfBoundsInt,
filterFactoriesInt,
lut );

interval = STDataUtils.getIterableInterval(
Expand All @@ -190,7 +193,7 @@ public Void call() throws Exception {

CellTypeExplorer cte = new CellTypeExplorer( lut );

final RealRandomAccessible< ARGBType > rraRGB = Render.switchableConvertToRGB( rra, outofboundsInt, new ARGBType(), lut, cte.panel() );
final RealRandomAccessible< ARGBType > rraRGB = Render.switchableConvertToRGB( rra, outOfBoundsInt, new ARGBType(), lut, cte.panel() );

BdvOptions options = BdvOptions.options().numRenderingThreads( Runtime.getRuntime().availableProcessors() ).addTo( source );
options = options.is2D();
Expand Down
36 changes: 16 additions & 20 deletions src/main/java/cmd/BigDataViewerStackDisplay.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cmd;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -39,6 +38,7 @@
import picocli.CommandLine.Option;
import render.Render;
import org.apache.logging.log4j.Logger;

import util.LoggerUtil;

@Command(name = "st-bdv-view3d", mixinStandardHelpOptions = true, version = "0.3.1", description = "Spatial Transcriptomics as IMages project - visualize ST data in BigDataViewer")
Expand All @@ -51,7 +51,7 @@ public class BigDataViewerStackDisplay implements Callable<Void> {
@Option(names = {"-g", "--genes"}, required = true, description = "comma separated list of one or more gene to visualize, e.g. -g Calm2,Ubb")
private String genes = null;

@Option(names = {"-a", "--annotation"}, required = false, description = "comma separated list of annotations to visualize, e.g. -a celltype")
@Option(names = {"-a", "--annotation"}, required = false, description = "comma separated list of annotations to visualize, e.g. -a cell type")
private String annotations = null;

@Option(names = {"-ar", "--annotationRadius"}, required = false, description = "radius of annotation spots as a factor of their median distance, e.g. -ar 2.0 (default: 0.75; in 3d: zSpacing*0.75)")
Expand All @@ -69,7 +69,7 @@ public class BigDataViewerStackDisplay implements Callable<Void> {
@Option(names = {"-bmax", "--brightnessMax"}, required = false, description = "max initial brightness relative to the maximal value (default: 0.5)")
private double brightnessMax = 0.5;

@Option(names = {"--rendering"}, required = false, description = "inital rendering type (Gauss, Mean, NearestNeighbor, Linear), e.g --rendering Gauss (default: Gauss)")
@Option(names = {"--rendering"}, required = false, description = "initial rendering type (Gauss, Mean, NearestNeighbor, Linear), e.g --rendering Gauss (default: Gauss)")
private Rendering rendering = Rendering.Gauss;

@Option(names = {"-rf", "--renderingFactor"}, required = false, description = "factor for the amount of filtering or radius used for rendering, corresponds to smoothness for Gauss, e.g -rf 2.0 (default: 1.5)")
Expand All @@ -92,7 +92,7 @@ public Void call() throws Exception {

final boolean useTransform = true;

if (!(new File(inputPath)).exists()) {
if (! SpatialDataContainer.exists(inputPath)) {
logger.error("Container / dataset '{}' does not exist. Stopping.", inputPath);
return null;
}
Expand Down Expand Up @@ -145,16 +145,12 @@ public Void call() throws Exception {
data.transform().set(new AffineTransform2D());
}

if (dataToVisualize.isEmpty()) {
logger.error("No datasets that contain sequencing data. stopping.");
return null;
}

List< String > annotationList;
if ( annotations != null && !annotations.isEmpty())
annotationList = Arrays.asList(annotations.split("," ) );
else
List<String> annotationList;
if (annotations != null && !annotations.isEmpty()) {
annotationList = Arrays.asList(annotations.split(","));
} else {
annotationList = new ArrayList<>();
}

BdvStackSource< ? > source = null;

Expand All @@ -163,29 +159,29 @@ public Void call() throws Exception {
//
for ( final String annotation : annotationList )
{
final IntType outofboundsInt = new IntType( -1 );
final IntType outOfBoundsInt = new IntType(-1);
final double spotSize = dataToVisualize.get( 0 ).statistics().getMedianDistance() * annotationRadius;
final HashMap<Long, ARGBType > lut = new HashMap<>();

final List< FilterFactory< IntType, IntType > > filterFactorysInt = new ArrayList<>();
final List<FilterFactory<IntType, IntType>> filterFactoriesInt = new ArrayList<>();

if ( ffSingleSpot != null && ffSingleSpot > 0 )
{
logger.debug("Using single-spot filtering, effective radius={}", dataToVisualize.get(0).statistics().getMedianDistance() * ffSingleSpot);
filterFactorysInt.add( new SingleSpotRemovingFilterFactory<>( outofboundsInt, dataToVisualize.get( 0 ).statistics().getMedianDistance() * ffSingleSpot ) );
filterFactoriesInt.add(new SingleSpotRemovingFilterFactory<>(outOfBoundsInt, dataToVisualize.get(0).statistics().getMedianDistance() * ffSingleSpot));
}

final RealRandomAccessible< IntType > rra;
final Interval interval;

final Pair< RealRandomAccessible< IntType >, Interval > stack =
VisualizeAnnotations.createStack(dataToVisualize, annotation, zSpacingFactor * 0.75 * spotSize, zSpacingFactor, outofboundsInt, filterFactorysInt, lut );
VisualizeAnnotations.createStack(dataToVisualize, annotation, zSpacingFactor * 0.75 * spotSize, zSpacingFactor, outOfBoundsInt, filterFactoriesInt, lut);
rra = stack.getA();
interval = stack.getB();

CellTypeExplorer cte = new CellTypeExplorer( lut );

final RealRandomAccessible< ARGBType > rraRGB = Render.switchableConvertToRGB( rra, outofboundsInt, new ARGBType(), lut, cte.panel() );
final RealRandomAccessible< ARGBType > rraRGB = Render.switchableConvertToRGB( rra, outOfBoundsInt, new ARGBType(), lut, cte.panel() );

BdvOptions options = BdvOptions.options().numRenderingThreads( Runtime.getRuntime().availableProcessors() ).addTo( source );
if ( dataToVisualize.size() == 1 )
Expand All @@ -200,7 +196,7 @@ public Void call() throws Exception {
//
// Display genes
//
final DoubleType outofbounds = new DoubleType( 0 );
final DoubleType outOfBounds = new DoubleType( 0 );
final List<FilterFactory<DoubleType, DoubleType>> filterFactories =
RenderImage.assembleFilterFactories(
new STDataStatistics( dataToVisualize.get( 0 ).data() ),
Expand All @@ -218,7 +214,7 @@ public Void call() throws Exception {
VisualizeStack.createStack(
dataToVisualize,
gene,
outofbounds,
outOfBounds,
zSpacingFactor,
brightnessMin,
brightnessMax,
Expand Down
Loading

0 comments on commit 13275e6

Please sign in to comment.