JinghaoLu / MIN1PIPE

A MINiscope 1-photon-based Calcium Imaging Signal Extraction PIPEline.
GNU General Public License v3.0
56 stars 25 forks source link

Is sigfn already normalized? #53

Closed martinjendryka closed 3 years ago

martinjendryka commented 3 years ago

Dear Jinghao and min1pipe community,

What exactly is 'sigfn'? The readme.md page says "processed calcium traces of corresponding ROIs". However, I want to know if it was already normalized in any way and if further normalization is required or not. I want to have my baseline activity near to zero. Therefore, I calculated dF/F = (F − F0)/F0 where F0 is the mean of the trace for each neuron. But this gives me an inverted trace, where peaks are negative. Calculating the zscore instead, didnt change anything. I therefore assume, traces are already normalized. Is that true?

Looking into the code, I find the following refinement steps where 'sigfn' is involved:

  1. refine_roi (refine roi by basis pursuit denoising)
  2. refine_sig (refine signal by CNMF)
  3. final_seeds_select
  4. trace_clean signal is smoothed by bayesian method (wavelet signal denoising)
  5. pure_refine_sig
  6. (last step) sigfn = max(roifn, [], 1)' .* sigfn;

I cant find where sigfn is normalized. Can you please tell me at which step this is done? And how? In addition, after the last step delta F is calculated by dff = sigfn ./ mean(sigfn, 2). Normally, this is calculated by (sigfn - mean(sigfn,2)) ./ mean(sigfn,2)
Why does MIN1PIPE differ in this respect?

Best regards, Martin

JinghaoLu commented 3 years ago

TL;DR One sentence summary: sigfn is not normalized the way you thought, but it is not dff either.

First, it involves more details than you thought to calculate df/f0. Usually if you are directly using the raw fluorescence, you can do normal df/f0, because you have f0, f exactly the variables from the definition of the formula. Note 1. f0=mean(f) is just an approximate of the baseline rather than the true value. Ideally you need to take the mean for all baseline frames of that neuron, but still that is just a more accurate approximate. 2. This measure (df/f0) is susceptible to the measure of f0, which means if you happen to have an almost muted baseline for a neuron, the f0 is close to 0, then you will have infinite df/f0 for that neuron. 3. Usually the baseline could not be flat zero, due to many factors, such as photobleaching.

Second, "sigfn" is not the processed trace directly from raw fluorescence. It is the processed trace after neural enhanced and motion corrected data. While motion correction doesn't change intensity, what exactly does neural enhancing do? Well it directly remove the background of each frame, so combining all the frames together, if you then extract the signal of an ROI, the baseline should be zeros, because ideally all the single points of the baseline (which is the pixel(s) reflecting the background activity of that ROI in that frame) are removed. In this way, you cannot calculate df/f0 directly, because you will always have large intensity for that measure, due to the small value of the baseline. Then what exactly "sigfn" is? It is the scaled (first pointwise nonlinear transformed and then globally affine transformed) trace of each ROI, but the inter-ROI order (of intensity) is preserved, meaning the large intensity ROIs you see by eyes will always have large "sigfn".

Third, the way MIN1PIPE calculates the df/f0 is more complicated. It need to consider the background subtracted in the neural enhancing step to resume the raw f, and need to take care in avoiding too small f0, as well as to better approximate variables. BTW, MIN1PIPE returns a variable called "dff" that you can directly use.

Now back to your question: sigfn is not normalized the way you thought, but it is not dff either. BTW: zscore does not change the shape, it only rescale the signal, so you won't see difference but only the scale changes.

martinjendryka commented 3 years ago

Thanks for the quick response! I am using the hpc version min1pipe_HPC.m. Here dff is calculated as in the following: dff = sigfn ./ mean(sigfn, 2); (see line 177) Therefore my earlier comment. I just realized its completely different in the min1pipe.m

JinghaoLu commented 3 years ago

Yeah forgot to update hpc file. Should be updated now. Thanks for the comment!