Executing Cells2Stats
Learn how to execute the Cells2Stats CLI
Execute Cells2Stats on a local compute environment by entering a command in the CLI terminal. The command varies based on cloud storage setup and execution type, either Docker or static binary. Append options to the command to specify file generation settings.
The command has the following parts:
- The
cells2statsexecutable - A subcommand that selects the stage of analysis to run
- Optional arguments to manipulate the output
Cells2Stats 2.0.0 requires a subcommand. The examples on this page use analyze, which performs the full analysis that the top-level command performed in Cells2Stats 1.x. For the other subcommands, see Run a single stage.
Run a single stage
Cells2Stats splits its work into five subcommands. Use analyze for a full execution, and use the others to repeat one stage without reprocessing the whole run.
| Subcommand | Use it to |
|---|---|
analyze | Process a run directory into a Spatial Data Object, cell statistics, and the QC report |
visualize | Rebuild CytoCanvas™ visualization files from an existing Spatial Data Object archive |
generate_qc_report | Regenerate qc_report.html from an existing Spatial Data Object archive |
process_imaging_targets | Reprocess raw projection tiles into corrected projection images without running a full analysis |
process_segmentation | Generate new cell and nuclear segmentation masks from projection images with Cellpose |
To resegment a run, use process_segmentation to generate new masks with Cellpose, then pass the output directory to analyze with --segmentation. To segment and analyze in a single execution, run analyze with --process-segmentation. Segmentation writes masks to a new directory and does not modify the CellSegmentation directory of the run. Segmentation requires Cellpose and the Cellpose models, which the Docker image includes. For static binary requirements, see Segmentation dependencies.
For example, to regenerate visualization files for an archive whose visualization step previously failed, run the following command:
./cells2stats visualize path/to/RunName.zarr.zip -j 8
To see the options for any subcommand, place --help after the subcommand name:
./cells2stats analyze --help
For every option on every subcommand, see the CLI reference.
Execute the software
-
Copy the template execution command for your storage type from one of the following subsections:
-
Adjust the optional arguments in the run command.
- To add arguments, replace
{options}with any of the options listed in theanalyzeCLI reference. - To execute Cells2Stats without any arguments, delete
{options}.
- To add arguments, replace
-
Execute the command in the terminal.
-
The execution is completed successfully when the terminal displays the following log lines.
<timestamp> [info]: Analysis completed successfully.<timestamp> [info]: Output written to </output> -
Access the output files in the run directory. By default they go to the
Cytoprofiling/<timestamp>folder.
Execute with local storage
Copy the template execution command for Docker or static binary. Update the template command and execute Cells2Stats as described in steps 2–5 of the execution instructions.
- Docker
- Static Binary
When using Docker, the general execution command automatically pulls the image to the local environment if it is not already there. The command uses the following structure:
docker runinvokes the Docker daemon to start the specified image.--rmremoves the image after the execution completes. Element Biosciences recommends using this argument to keep your system clean.elembio/cells2statsidentifies the image that you want to pull. By default, this image is the latest. For a specific a version, include a tag, such aselembio/cells2stats:1.0.0.-jthreads Cells2Stats for faster parallel execution. The value depends on your system setup. The example command has a value of 8, which requires at least 8 CPUs.{options}defines theanalyzeoptions.{directory}defines the path to the directory for input and output files.
Executing in local environments might require mounting the directory to Docker:
-
-vmounts the local path to Docker as a volume. -
:/inputbinds the mounted path to a variable for use by Cells2Stats.docker run --rm elembio/cells2stats cells2stats analyze {directory} -j 8 {options}
The command for static binary uses the following structure:
-
./cells2statsinvokes the installed static binary executable. -
-jthreads Cells2Stats for faster parallel execution. The value depends on your system setup. The example command has a value of 8, which requires at least 8 CPUs. -
-sskips morphology feature extraction using CellProfiler. In order to run CellProfiler with a static binary, see installation instructions. -
{options}defines theanalyzeoptions. -
{directory}defines the path to the input run directory../cells2stats analyze {directory} -j 8 -s {options}
Execute with AWS S3
AWS S3 requires Uniform Resource Identifiers (URIs) to serve as paths to the Amazon S3 buckets that contain the input and output files. Accessing the buckets requires AWS credentials configured for the setup. If both input and output locations are AWS, they must use the same credentials.
- For AWS S3 within an EC2 instance, Cells2Stats detects the credentials or Identity and Access Management (IAM) role associated with the instance.
- For AWS S3 access without an EC2 instance, define AWS credentials with the following environment variables:
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_DEFAULT_REGION.
If Cells2Stats fails to detect credentials attached to an AWS storage location with an EC2 instance, the environment variable might be incorrect. Make sure this variable is set correctly in the EC2 instance: export AWS_DEFAULT_REGION=$aws_region.
-
Run the following
exportcommand in terminal to set the credentials as environment variables.export AWS_ACCESS_KEY_ID=ExampleAccessKeyexport AWS_SECRET_ACCESS_KEY=EXAMPLEnhMUUOhQF/T51c6A5+DtQas9ghebsexport AWS_DEFAULT_REGION=us-west-2 -
Copy the following template execution command for Docker or static binary.
- Docker
- Static Binary
For Docker, the execution command includes -e to pull in the credentials set as environment variables.
docker run --rm -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION elembio/cells2stats cells2stats analyze s3://bucket/input -o s3://bucket/output -j 8 {options}
./cells2stats analyze s3://bucket/input -o s3://bucket/output -j 8 -s {options}
- Update the template command and execute Cells2Stats as described in steps 2–5 of the execution instructions.
Execute with GCS
GCS storage requires URLs to serve as preconfigured paths to the Cloud Storage buckets that contain the input and output files. Accessing the buckets requires configuring GCS credentials for the setup. If both input and output locations are GCS, they must use the same credentials.
The environment variable GOOGLE_APPLICATION_CREDENTIALS must link to the file that contains the application credentials. For more information, see the Google documentation.
-
Run the following export command in terminal to set the credential as an environment variable.
export CREDENTIALS="/path/to/GCP-creds.json" -
Copy the following template execution command for Docker or static binary.
- Docker
- Static Binary
For Docker, the execution command includes -e to pull in the credential set as an environment variable.
docker run --rm -e GOOGLE_APPLICATION_CREDENTIALS=$CREDENTIALS elembio/cells2Stats cells2stats analyze gs://bucket/input -o gs://bucket/output -j 8 {options}
./cells2stats analyze gs://bucket/input -o gs://bucket/output -j 8 -s {options}
- Update the template command and execute Cells2Stats as described in steps 2–5 of the execution instructions.
Execute with Rclone-compatible cloud
Before executing Cells2Stats with rclone, review the rclone requirements for system setup.
If you are using rclone, Element recommends executing with static binary. For execution, use the --input-remote and --output-remote options as shown in the following code example. Then update the template command and execute Cells2Stats as described in steps 2–5 of the execution instructions.
- Static Binary
./cells2stats analyze path/to/input/remote -o path/to/output/remote --input-remote "input-name" --output-remote "output-name" -j 8 -s {options}