labsyspharm / ashlar

ASHLAR: Alignment by Simultaneous Harmonization of Layer/Adjacency Registration
https://labsyspharm.github.io/ashlar/
MIT License
119 stars 42 forks source link

Output only specified channels for each cycle error #202

Open ShihongWu opened 11 months ago

ShihongWu commented 11 months ago

Hi Jeremy and Yu-An @jmuhlich @Yu-AnChen, Thanks for your time and help! The package is wonderful. Now I could stitch and merge my CellDIVE tif images! It's just when I tried to specify the output channels for each cycle, I ran into an error. I have 12 cycles and 10th cycle (cycle 9 if starts from cycle 0) only contains 3 channels (dapi fitc and cy3), the rest 11 cycles contain all 4 channels. For each cycle, I only want specific channels as the output ones. So I used the --output-channels argument like this:

ashlar \
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S001_bkgnd_dapi_bkgnd_fitc_bkgnd_cy3_bkgnd_cy5/S001_bkgnd_dapi_b$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S002_DAPI_dapi_aSMA_fitc_TNC_cy3_PNAd_cy5/S002_DAPI_dapi_aSMA_fi$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S003_bleach_dapi_bleach_fitc_bleach_cy3_bleach_cy5/S003_bleach_d$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S004_DAPI_dapi_HLA_DR_fitc_FN_cy3_PDPN_cy5/S004_DAPI_dapi_HLA_DR$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S005_bleach_dapi_bleach_fitc_bleach_cy3_bleach_cy5/S005_bleach_d$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S006_dapi_dapi_CLU_fitc_PDGFRa_cy3_CD31_cy5/S006_dapi_dapi_CLU_f$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S007_bleach_dapi_bleach_fitc_bleach_cy3_bleach_cy5/S007_bleach_d$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S008_dapi_dapi_COL3_fitc_MMP9_cy3_VIM_cy5/S008_dapi_dapi_COL3_fi$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S009_bleach_dapi_bleach_fitc_bleach_cy3_bleach_cy5/S009_bleach_d$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S010_DAPI_dapi_COL1A1_fitc_SPP1_cy3/S010_DAPI_dapi_COL1A1_fitc_S$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S011_bleach_dapi_bleach_fitc_bleach_cy3_bleach_cy5/S011_bleach_d$
/gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/S012_dapi_dapi_PCK_fitc_FAP_cy3_CD45_cy5/S012_dapi_dapi_PCK_fitc$
--flip-y \
-o /gpfs3/well/immune-rep/users/tma392/mcmicro/45041_19_4AIP_1/registration/45041_19_4AIP_1_n.ome.tif \
--output-channels 0 1 2 3 \
--output-channels 1 2 3 \
--output-channels 1 2 3 \
--output-channels 1 2 3 \
--output-channels 1 2 3 \
--output-channels 1 2 3 \
--output-channels 1 2 3 \
--output-channels 1 2 3 \
--output-channels 1 2 3 \
--output-channels 1 2 \
--output-channels 1 2 3 \
--output-channels 0 1 2 3

But when it hit the 10th cycle, it gave me this error:

Traceback (most recent call last):
  File "/gpfs3/well/immune-rep/users/tma392/python/ashlar-skylake/bin/ashlar", line 33, in <module>
    sys.exit(load_entry_point('ashlar==1.17.0', 'console_scripts', 'ashlar')())
  File "/gpfs3/well/immune-rep/users/tma392/python/ashlar-skylake/lib/python3.10/site-packages/ashlar/scripts/ashlar.py", line 212, in main
    return process_single(
  File "/gpfs3/well/immune-rep/users/tma392/python/ashlar-skylake/lib/python3.10/site-packages/ashlar/scripts/ashlar.py", line 265, in process_single
    mosaics.append(reg.Mosaic(layer_aligner, mshape, **mosaic_args_final))
  File "/gpfs3/well/immune-rep/users/tma392/python/ashlar-skylake/lib/python3.10/site-packages/ashlar/reg.py", line 991, in __init__
    self.channels = self._sanitize_channels(channels)
  File "/gpfs3/well/immune-rep/users/tma392/python/ashlar-skylake/lib/python3.10/site-packages/ashlar/reg.py", line 1004, in _sanitize_channels
    raise ValueError("invalid channels: %s" % invalid_channels)
ValueError: invalid channels: [3]

I was wondering if it's because ashlar only recognise the first --output-channels argument and use the first argument for every cycle. How should I specify the output channels here? Thanks for your time and assistance! Much appreciated!

Best wishes,

Shihong

jmuhlich commented 2 months ago

Sorry, --output-channels only accepts one list of channel numbers and applies this to all cycles. I think you will need to omit --output-channels so all channels are written, then post-process the ome-tiff to delete the channels you don't want to keep. We wrote a script to do this, which you can obtain here: https://github.com/labsyspharm/mcmicro/blob/master/roadie/scripts/recyze.py It requires the python modules numpy, tifffile, zarr, and ome_types.