SAND-Lab / MEA-NAP

MEA-NAP. A streamlined diagnostic and analytic tool for data obtained using microelectrode arrays.
GNU General Public License v3.0
12 stars 6 forks source link

Analysis pipeline gets stuck at step 2A #42

Closed adampavlinek closed 4 months ago

adampavlinek commented 5 months ago

Hello,

The analysis pipeline runs fine until step 2A, where it successfully generates one raster plot and then gets stuck and matlab stops responding, with Figure 2 electrode heatmap shown.

Not sure if this is relevant but I also get this warning: Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 1.409245e-16.

In fLOESS (line 90) In getISInTh (line 62) In burstDetect (line 182) In firingRatesBursts (line 42) In MEApipeline (line 296)

Timothysit commented 5 months ago

Hi, if the pipeline didn't crash with an error, then it may be to do with the size of the file / long processing time (the warning can occur when there are electrodes with very similar activity, but is not unusual). How long is your recording and sampling rate? And how much RAM do you have on your computer? Was it stuck on the first file? I will suggest running it again (perhaps skipping straight to step 2, since the spike detection is already done) and see if the error still occurs. Let me know how it goes!

adampavlinek commented 5 months ago

Hi so I am trying a computer with more RAM, but I am now encountering an error prior to spike detection:

Unrecognized function or variable 'option'.

Error in MEApipeline (line 197) batchDetectSpikes(rawData, savePath, option, ExpName, Params);

Timothysit commented 5 months ago

Hi, sorry for the delay! This should be fixed now

Timothysit commented 5 months ago

Hi, just want to update you that I found a few more related bugs and fixed those as well, so please get the latest version, thanks!

adampavlinek commented 5 months ago

Hi I'm getting the following errors during spike detection, not sure if this is because I set something wrong?:

Error using butter>butterImpl The cutoff frequencies must be within the interval of (0,1).

Error in butter (line 59) [varargout{1:nargout}] = butterImpl(n,Wn,varargin{:});

Error in detectSpikesCWT (line 93) [b, a] = butter(filterOrder, wn);

Error in batchDetectSpikes (line 271) detectSpikesCWT(trace,fs,wid,actual_wname,L,nScales, ...

Error in MEApipeline (line 197) batchDetectSpikes(rawData, savePath, option, ExpName, Params);

Timothysit commented 4 months ago

Hi, sorry for the delay! This should be fixed in this commit made yesterday: 1fed13af7889b948b463f4e0c3afbfee141145d6, let me know how it goes!

adampavlinek commented 4 months ago

Hi, this fixed it and spike detection runs fully. I am however getting an error before step 2B:

Unrecognized function or variable 'eGrp'.

Error in PlotEphysStats (line 136) VNe = strcat(eGrp,'.',eDiv,'.',eMet);

Error in MEApipeline (line 333) PlotEphysStats(ExpName,Params,HomeDir, oneFigureHandle)

Timothysit commented 4 months ago

Ah interesting, did you have a column named "Genotype" in your .csv file?

adampavlinek commented 4 months ago

Ah yes but I left the column blank, should I fill it in/delete it?

Timothysit commented 4 months ago

You should fill it with "WT" (meaning wild-type) or any combination of letters that make sense to you. Thanks! (In a future update we will make it so if you leave it blank this will be done for you automatically)

adampavlinek commented 4 months ago

Thank you I fixed this but am getting a different error now at the same step, not sure if this is something I need to configure? :

Error using matlab.internal.math.validateOrEstimateBW Expected Bandwidth to be positive.

Error in mvksdensity>apply_censoring_get_bandwidth (line 309) u = matlab.internal.math.validateOrEstimateBW(errPrefix, ty, u, d, bounds);

Error in mvksdensity (line 112) [ty,~,weight,u,foldpoint,maxp] = apply_censoring_get_bandwidth(cens,yData,ty,ymax,weight,u,d, [L U]);

Error in ksdensity (line 235) [fout,xout,u,plottype] = mvksdensity(yData,xi,varargin{:});

Error in HalfViolinPlot (line 59) [f,xi] = ksdensity(data, 'Bandwidth',bandwidth);

Error in PlotEphysStats (line 319) eval(['HalfViolinPlot(PlotDat,xt(d),cDiv' num2str(d) ', Params.kdeHeight, Params.kdeWidthForOnePoint)']);

Error in MEApipeline (line 333) PlotEphysStats(ExpName,Params,HomeDir, oneFigureHandle)

Timothysit commented 4 months ago

Hi, this see to be caused by a rare case where the bandwidth estimation fails because there are too few datapoints / the data is somehow a bit weird, I just pushed a fix to that, see if that helps :)

adampavlinek commented 4 months ago

Hi,

I'm still getting the same errors. Could it be something to do with me using a 24w plate layout that has fewer electrodes?

Timothysit commented 4 months ago

Hmm strange, I don't think they are related, can you enter debug mode in line 319 of PlotEphysStats and tell me what are the values of the variables: PlotDat, xt(d), cDiv, num2str(d), Params.kdeHeight, and Params.kdeWidthForOnePoint? Thanks!

adampavlinek commented 4 months ago

Hi the values are: K>> dbstack

In PlotEphysStats (line 319) In MEApipeline (line 333) K>> PlotDat PlotDat = 16 K>> xt(d) ans = 1 K>> cDiv Unrecognized function or variable 'cDiv'. K>> num2str(d) ans = '1' K>> Params.kdeHeight ans = 0.3000 K>> Params.kdeWidthForOnePoint ans = 0

Timothysit commented 4 months ago

Hi, which version of matlab are you using? I suspect that the bandwidth parameter must be strictly positive in newer version, but not in older versions (I am testing the code on Matlab 2021b), I just pushed some code to make the bandwidth always positive, can you see if it works now?

adampavlinek commented 4 months ago

Thanks that worked! I'm using Matlab R2023b.