labsyspharm / quantification

Quantification module for mcmicro
https://github.com/labsyspharm/mcmicro
9 stars 13 forks source link

Bug: IndexError in mcmicro and standalone #41

Closed josenimo closed 1 year ago

josenimo commented 2 years ago

Hello all,

I am trying to run mcquant with a segmentation mask from cellpose, but keep running into index errors.

  1. Trying with MCMICRO: I have placed the mask.tif file in the segmentation folder, the image stack in the registration folder, the marker.csv is there, and the parameter file I use. I get the following error: Index 1 out of bounds for length 1

Feel free to browse and test, link to download below: https://filetransfer.mdc-berlin.de/?u=THtMhEtn&p=6ht4Qp4e

  1. Trying with CommandSingleCellExtraction.py directly: IndexError: index out of range for full stack trace Index out of range.txt

I am sure I am missing something silly, thank you for the help.

Best, Jose

ArtemSokolov commented 2 years ago

Hi Jose,

Quantification assumes that the input TIFF file has each channel in a separate page. Looks like your image puts all three channels onto the first page. Here is a quick Python script to convert your image to the proper structure:

import tifffile
import numpy as np

# Load the original file
img = tifffile.imread('downsample.tif')

# Transpose (Y, X, C) -> (C, Y, X)
img_cyx = np.transpose(img, [2,0,1])

# Write each channel as a separate page
tifffile.imwrite('image.tif', img_cyx, photometric='minisblack')

The new image.tif should work with the mask that you provided:

docker run -v "$PWD":/data labsyspharm/quantification:1.5.2 \
  python /app/CommandSingleCellExtraction.py \
    --image /data/image.tif \
    --masks /data/downsample_mask.tif \
    --channel_names /data/markers.csv \
    --output /data/

where I placed the new image.tif in the same directory as your downsample_mask.tif and markers.csv, and ran the above command from that directory. (The command maps Present Working Directory [$PWD] to be available as /data inside the container.)

I haven't tested it with MCMICRO, but let me know if you are still running into issues there.

josenimo commented 1 year ago

Hey @ArtemSokolov,

Ah I see the mistake, for some reason this was the setup for the cropped image, however, the full image was already in the cyx conformation.. another thing to look out for! Thank you again.

Best, Jose