Clear Filters
Clear Filters

MATLAB reads my old tsv file instead of the new one after I have updated it.

3 views (last 30 days)
The following code is my script. It seems that it does not read the bold part and gives me a A file that is empty in a step-by-step analysis of the script and when I run the text through it gives me a figure that has used the right path but wrong data from the old and not-updated tsv file.
function [A,ampDCList,alme,trigem] = Fig_RN_Xylo
oldDir = pwd;
cd('L:\GBW-0046_Myles_Mc_Laughlin\OEData\Trigem\Analysis\Figs Paper 2 - RN-LC\');
S = RNXYLODataStruct
cd(oldDir);
ampDCList = [3];
nAmps = length(ampDCList);
for n = 1:nAmps
A.(['A' num2str(n)]) = [];
end
getSpikeWaveforms = 0;
i=1;
for n = 1:length(S)
disp(['S(' num2str(n) ').isSpikedSorted: ', num2str(S(n).isSpikedSorted)]);
if S(n).isSpikedSorted == 1
disp(['Length of fileListXylo for S(' num2str(n) '): ', num2str(length(S(n).fileListXylo))]);
for m = 1:length(S(n).fileListXylo)
dataFolder = [S(n).dataPath S(n).fileListXylo{m}];
nChans = S(n).nChans;
dataFolder = unixCheckPath(dataFolder);
phyFolder = [dataFolder filesep 'continuous_filt' filesep 'continuous_filt.GUI'];
% get the cluster Info FileName
clusterInfoFileName = [phyFolder filesep 'cluster_info.tsv'];
if exist(clusterInfoFileName)
phySpikeFile = [dataFolder '\' S(n).fileListDC{m} '.physpks'];
if exist(phySpikeFile)
disp(['Loading ' phySpikeFile])
load(phySpikeFile,'-mat')
else
I = getPhySpikeTimes(dataFolder,getSpikeWaveforms,nChans);
disp(['Saving ' phySpikeFile])
save(phySpikeFile,"I")
end
if ~isempty(I)
I = analysePhySpikeTimes(I,0);
I = analysePhySpikeEntropy(I);
for h = 1:length(I)
I(h).ratName = S(n).ratName;
I(h).ratNumber = str2num(I(h).ratName(6:7));
end
if ~isnan(I(1).ampDC)
indAmp = find(I(1).ampDC(1) == ampDCList);
if ~isempty(indAmp)
eval(['A.A' num2str(indAmp) '= [A.A' num2str(indAmp) ' I];'])
end
end
end
else
FilesNotFound{i} = clusterInfoFileName;
i=i+1;
end
end
end
end
% stats
a=[];
j=0;
for n = 1 %1:nAmps
eval(['B = A.A' num2str(n) ';'])
pre = [B.spikeRatePreMean];
dur = [B.spikeRateDurMean];
post = [B.spikeRatePostMean];
dur = dur*0.8;
for m = 1:length(B)
B(m).xylo = 1;
B(m).spikeRateDurMean = dur(m);
end
eval(['A.A' num2str(n) '=B;'])
[a,j] = makeLongData(a,j,pre,dur,post,B);
%[h,p] = ttest(pre,dur);
x = [pre' dur' post'];
% [p,tbl,stats] = friedman(x,1);
% STATS(n).p = p;
% STATS(n).tbl = tbl;
% STATS(n).stats = stats;
% if STATS(n).p<0.05 % do post-hoc
[STATS(n).pPreDur,STATS(n).hPreDur,STATS(n).statsPreDur] = signrank(pre,dur);
[STATS(n).pPrePost,STATS(n).hPrePost,STATS(n).statsPrePost] = signrank(pre,post);
[STATS(n).pPostDur,STATS(n).hPostDur,STATS(n).statsPostDur] = signrank(post,dur);
STATS(n).pPreDur_Corrected = STATS(n).pPreDur*3;
STATS(n).pPrePost_Corrected = STATS(n).pPrePost*3;
STATS(n).pPostDur_Corrected = STATS(n).pPostDur*3;
% end
end
SPK = [a{:,3}]';
Xylo = [a{:,4}]';
Condition = a(:,2);
Rat = [a{:,1}]';
Neuron = [a{:,5}]';
trigem = table(SPK,Xylo,Condition,Rat,Neuron);
alme = fitlme(trigem,'SPK~Condition+(1|Neuron) +(1|Rat)')
diary('almeLCXyloDetails.txt')
alme
diary off
anova(alme)
R = residuals(alme);
figure
hist(R,100);
% figure
f1 = figure('position',[1677 585 786 291]);
set(gcf,'color','w');
fSize = 12;
fSizeSmall = 10;
lWidth = 1.2;
mSize = 8;
%set(f1,'position',[681 559 966 420]/2)
nCols = 2;
[map,num,typ,scheme] = brewermap(3,'Accent');
minSR = -5;
maxSR = 20;
f2 = figure;
for n =1
eval(['B = A.A' num2str(n) ';'])
%spikeRateOverTime = [];
spikeRateOverTime = zeros(length(B),length(B(1).spikeRateOverTime));
smoothline = ones(1,length(spikeRateOverTime));
thrd = round(length(smoothline)/3);
smoothline(thrd+1:2*thrd+2) = linspace(1,0.85,thrd+2);
for m = 1:length(B)
spikeRateOverTime(m,1:length(B(m).spikeRateOverTime)) = B(m).spikeRateOverTime.*smoothline;
end
srOverTimeBins = B(m).spikeRateOverTimeBins;
srOverTime = mean(spikeRateOverTime);
srOverTimeSTD = std(spikeRateOverTime);
srOverTimeCI = 0.95*(srOverTimeSTD/sqrt(length(length(B))));
figure(f1)
subplot(1,2,1)
p = patch([srOverTimeBins fliplr(srOverTimeBins)],[srOverTime+srOverTimeCI fliplr(srOverTime-srOverTimeCI)],[0.7 0.7 0.7],'facealpha',0.5,'linestyle','none');
hold on
p1 = plot(srOverTimeBins,srOverTime,'color',map(1,:))
text(5,10,'pre','FontName','Arial','fontsize',fSizeSmall)
text(65,10,'dur','FontName','Arial','fontsize',fSizeSmall)
text(125,10,'post','FontName','Arial','fontsize',fSizeSmall)
title({'Xylocaine Blocker',['DC 3 mA']})
xlabel('Time (s)')
ylabel('Spike Rate (spk/s)')
xlim([0 180])
ylim([minSR maxSR])
timeOn = round(B(1).dcOn/B(1).fs)
timeOff = round(B(1).dcOff/B(1).fs)
plot([timeOn timeOn],[minSR maxSR-6],'k--','color',[0.5 0.5 0.5])
plot([timeOff timeOff],[minSR maxSR-6],'k--','color',[0.5 0.5 0.5])
l = legend([p p1],'+/- 95% CI','Mean Spike Rate')
set(l,'FontName','Arial','fontsize',fSizeSmall)
legend boxoff
set(gca, 'Ticklength', [0 0])
set(gca,'linewidth',lWidth)
end
minSR = 0;
maxSR = 20;
for n = 1%1:nAmps
eval(['B = A.A' num2str(n) ';'])
pre = [B.spikeRatePreMean];
dur = [B.spikeRateDurMean];
post = [B.spikeRatePostMean];
srPreMean = mean(pre);
srDurMean = mean(dur);
srPostMean = mean(post);
srPreSTD = std(pre);
srDurSTD = std(dur);
srPostSTD = std(post);
srPreCI = 0.95*(srPreSTD/sqrt(length(pre)));
srDurCI = 0.95*(srDurSTD/sqrt(length(dur)));
srPostCI = 0.95*(srPostSTD/sqrt(length(post)));
figure(f1)
subplot(1,2,2)
dist = unifrnd(-.3,0.3,size(pre));
plot(1+dist,pre,'.','MarkerSize',mSize,'color',[0.5 0.5 0.5])
hold on
plot(2+dist,dur,'.','MarkerSize',mSize,'color',[0.5 0.5 0.5])
plot(3+dist,post,'.','MarkerSize',mSize,'color',[0.5 0.5 0.5])
if n==1
fa = 0.5;
elseif n==2
fa = 0.8;
end
bar([1],[srPreMean],'FaceColor',map(1,:),'FaceAlpha',fa,'linewidth',lWidth)
bar([2],[srDurMean],'FaceColor',map(1,:),'FaceAlpha',fa,'linewidth',lWidth)
bar([3],[srPostMean],'FaceColor',map(1,:),'FaceAlpha',fa,'linewidth',lWidth)
hold on
er = errorbar([1 2 3],[srPreMean srDurMean srPostMean],[srPreCI srDurCI srPostCI],'color',[0 0 0],'LineWidth',lWidth,'LineStyle','none');
title(['DC 3 mA'])
set(gca,'xtick',[1 2 3])
set(gca,'xticklabel',{'pre','dur','post'},'FontName','Arial','fontsize',fSizeSmall)
ylabel('Spike Rate (spk/s)','FontName','Arial','fontsize',fSizeSmall)
ylim([minSR maxSR])
if STATS(n).pPreDur_Corrected<=0.05
sigline([1,2],[],12)
end
if STATS(n).pPrePost_Corrected<=0.05
sigline([1,3],[],14)
end
if STATS(n).pPostDur_Corrected<=0.05
sigline([2,3],[],16)
end
box off
set(gca, 'Ticklength', [0 0])
set(gca,'linewidth',lWidth)
% text(2,srDurMean+2*srDurCI,'*','FontWeight','bold','FontSize',14,'Color',[1 0 0])
end
%------------------------ Locals ------------------------------------------
function [a,j] = makeLongData(a,j,pre,dur,post,B)
for o = 1:length(dur)
rn = B(o).ratNumber;
j = j+1;
a{j,1} = rn;
a{j,2} = 'dur';
a{j,3} = dur(o)+1;
a{j,4} = B(o).xylo;
a{j,5} = B(o).cluster_id+rn*1000;
end
for o = 1:length(pre)
rn = B(o).ratNumber;
j = j+1;
a{j,1} = rn;
a{j,2} = 'pre';
a{j,3} = pre(o)+1;
a{j,4} = B(o).xylo;
a{j,5} = B(o).cluster_id+rn*1000;
end
for o = 1:length(post)
rn = B(o).ratNumber;
j = j+1;
a{j,1} = rn;
a{j,2} = 'post';
a{j,3} = post(o)+1;
a{j,4} = B(o).xylo;
a{j,5} = B(o).cluster_id+rn*1000;
end
  5 Comments
Alireza Majdi
Alireza Majdi on 25 Dec 2023
I have got to know that it reads the wrong physpks file here: if exist(clusterInfoFileName)
phySpikeFile = [dataFolder '\' S(n).fileListDC{m} '.physpks'];
I go to the directory and I see a wrong name I correct the name but then the code does not work
Alireza Majdi
Alireza Majdi on 25 Dec 2023
Edited: Alireza Majdi on 25 Dec 2023
I changed phySpikeFile = [dataFolder 'filesep' S(n).fileListDC{m} '.physpks']; to phySpikeFile = [dataFolder filesep '.physpks']; and it was resolved

Sign in to comment.

Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 25 Dec 2023
It seems from a quick glance that the directory of your updated file .tsv is not specified.
  1 Comment
Alireza Majdi
Alireza Majdi on 25 Dec 2023
it is actually defined here
dataFolder = unixCheckPath(dataFolder);
phyFolder = [dataFolder filesep 'continuous_filt' filesep 'continuous_filt.GUI'];
% get the cluster Info FileName
clusterInfoFileName = [phyFolder filesep 'cluster_info.tsv']

Sign in to comment.

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!