Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raw signals do not match suite2p raw signals for the same rois #286

Open
just-meng opened this issue Jul 29, 2022 · 1 comment
Open

Raw signals do not match suite2p raw signals for the same rois #286

just-meng opened this issue Jul 29, 2022 · 1 comment

Comments

@just-meng
Copy link

Hi there,

I was running fissa on suite2p motion-corrected reg_tif files following this instruction. When comparing the result with the subtraction method (F = 0.7*Fneu) I noticed that they were nowhere similar to each other. Having a look at the extracted raw signals by fissa (experiment.raw) and by suite2p (F.npy) of the same roi I noticed that also the raw traces were not similar.

image

I triple-checked the roi identity and plotted experiment.roi_polys[i_roi, trial][0] to compare with suite2p GUI). It definitely is the same roi. Any idea why the raw traces do no agree?

  • python: 3.9.12
  • suite2p: 0.11.0
  • fissa: 1.0.0
  • operating system: Windows 11

Just to be sure, the code is attached here:

images = "./reg_tif"

# Get image size
Lx = ops["Lx"]
Ly = ops["Ly"]

# Generate ROI masks in a format usable by FISSA (in this case, a list of masks)
rois = [np.zeros((Ly, Lx), dtype=bool) for n in range(n_cells)]

for i, n in enumerate(cell_ids):
    # i is the position in cell_ids, and n is the actual cell number
    ypix = stat[n]["ypix"][~stat[n]["overlap"]] # get only the non-overlapping pixels
    xpix = stat[n]["xpix"][~stat[n]["overlap"]]
    rois[i][ypix, xpix] = 1
    
fissa_folder = "../../fissa"
fissa_experiment = fissa.Experiment(images, [rois], fissa_folder)
fissa_experiment.separate()

n_cells and cell_ids are previously obtained from F.npy and iscell.npy.

@just-meng
Copy link
Author

I found the bug: if the folder of the suite2p registered images is passed to fissa.Experiment(images, rois, folder) as argument images, the tif files will be sorted according to
self.images = sorted(glob.glob(os.path.join(images, "*.tif*")))
This leads to incorrectly sorted images simply due to the naming of the tif files:
file000_chan0, file500_chan0, file1000_chan0
After sorting it lists:
file000_chan0, file1000_chan0, file500_chan0
The result is temporally mis-appended signals.

A quick fix to my code (not elegant but works):

images_folder = "./reg_tif"
images_path = glob.glob(os.path.join(images_folder, "*.tif*"))
# extract the interger that indicates the number of the starting frame of the tif and add to the path as a tuple
images_path = [(int(path.split('_')[-2].split('file')[-1]), path) for path in images_path]
# sort the path list according to the frame numbers
sorted_path = sorted(images_path)
# get rid of the integer and make a list of the now sorted paths
sorted_path = list(np.array(sorted_path)[:,1])

Now one can run fissa.Experiment(sorted_path, rois, folder).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant