Skip to main content
. 2022 Jan 27;1:757291. doi: 10.3389/fbinf.2021.757291

TABLE 1.

Code used in the step-by-step protocol for establishing a container using a definition file. Please note that copying some code directly from the table might induce errors due to formatting. Hence, we suggest to type the commands newly in case of errors, and refer to the files on github: https://github.com/DaetwylerStephan/Containerize_ImageAnalysis or in the Supplementary Material.

Code Project title
Code 2 > mkdir container_example/
> cd container_example/
Code 3 > vagrant init sylabs/singularity-3.7-ubuntu-bionic64
Code 4 > vim Vagrantfile
Code 5a config.vm.synced_folder "C:/your/local/cellimages/filepath", "/home/vagrant/cellpose_testdata"
Code 5b config.vm.provider "virtualbox" do |vb|
 #Customize the amount of memory on the VM:
 vb.memory = "9000"
end
Code 6 > vagrant up
Code 7 > vagrant ssh-config
Code 8 > scp -P 2222 python_main.py vagrant@127.0.0.1:.
Code 9 > vagrant ssh
Code 10 vagrant@vagrant> sudo apt-get update
vagrant@vagrant> sudo apt-get install vimvagrant@vagrant> vim cellpose_container.recipe
Code 11 Bootstrap: docker
From: ubuntu:18.04
Code 12 %labels
 AUTHOR: Shilpita Mitra-Behura, Reto Fiolka, Stephan Daetwyler
Code 13 %files
 /home/vagrant/python_main.py /mnt
Code 14 %post
 #Downloads the latest package lists.
 apt-get update -y
 #Install python and other tools.
 #Non-interactive is used to ensure prompts are not needed.
 DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
 python3 python3-pip\
 python3-setuptools
 #Update pip
 python3 -m pip install --upgrade pip==21.2.4
 #Install python libraries needed for Cellpose to run
 python3 -m pip install wheel==0.37
 python3 -m pip install --no-cache-dir torch==1.8.1
 python3 -m pip install opencv-python-headless==4.5.3.56
 python3 -m pip install cellpose==0.6.5
Code 15 %runscript
 exec /usr/bin/python3 /mnt/python_main.py “$@”
Code 16 %help
 This is a Singularity container to segment images using Cellpose.
 To run this container, use, for example, 'singularity run cellpose_container.sif --filedir
 /folder/where/files/to/segment/are --savedir /folder/where/segmented/files/should/be/saved --pretrained_model cyto --chan 2 --save_tif'
 The user must put the folder where the files to be segmented are after the flag “--filedir.” The directory where the user wants to save their files is optional, with the tag “--savedir.”
 The flag “--pretrained_model” is required and must have either the input “cyto” or “nuclei.” The flags “--chan” and “--chan2”
 are optional and allude to the channels of the image that will be segmented.
 The flag “--diameter” is optional and can be added for the user to specify the diameter of the nuclei in image.
 The flags “--flow_threshold”, “--cellprob_threshold” are further optional flags to specify cellpose parameters.
 The flags “--save_png” and “--save_tif” are used to denote what file type the segmented files are saved as. The default is to save as a Tiff.
Code 17 vagrant@vagrant> sudo singularity build cellpose_container.sif cellpose_container.recipe
Code 18 vagrant@vagrant> singularity run cellpose_container.sif --filedir /home/vagrant/cellpose_testdata --savedir /home/vagrant/cellpose_testdata/save_segmentedimages --pretrained_model nuclei --chan 1 --flow_threshold 0 --cellprob_threshold −1 --diameter 19 --save_tif
Code 19 > scp -P 2222 vagrant@127.0.0.1:/home/vagrant/cellpose_container.sif .
Code 20 > sbatch run_on_cluster.sh