-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquant_specific_co2.m
66 lines (55 loc) · 3.32 KB
/
quant_specific_co2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
function [n, nfinal, neutZone]= quant_specific_co2(plotxvals, CportStdLoc)
%% quant_specific_co2
% includes additional analyses specific for for single-worm CO2 tracking assays
% that are done using a CO2 gradient.
%
% Currently, calculating number of worms that end in scoring regions, as
% well as time spent in scoring regions by individual worms.
%
%% Inputs/Outputs
% Inputs:
% plotxvals: the compiled xvals of worm tracks, standardized to the
% "experimental" port. Using this I can easily calculate the amount of time
% the worm spends on the experimental side vs control side of its starting
% position.
%
% Outputs:
% n.E, n.C: the amount of time (in seconds) that individual worms spent
% outside of a 1 cm neutral exclusion zone towards the Experimental or
% Control sides.
% nfinal.E, nfinal.C: the number of animals that end the experiment in the
% experimental zone and the control zone
% nenter.E, nenter.C: the number of animals that enter the
% experimental zone and the control zone at least once. This value is
% currently commented out.
%
global info
%% Time spend on experimental vs control side
% A pretty easy calculation, given that the x values are aligned to the
% experimental port (at the origin). Will exclude a 1 cm neutral zone
% centered on the median between the two ports.
neutZone.center = median(CportStdLoc.x/2); %in cm
neutZone.lowerlimit= neutZone.center - 0.5; %in cm
neutZone.upperlimit= neutZone.center + 0.5; %in cm
cE = plotxvals<neutZone.lowerlimit; % a lower x value than the lower bound of the neutral zone means the worm is towards the experimental port and outside the neutral zone.
cC = plotxvals > neutZone.upperlimit; % a higher x value than the upper bound of the neutral zone means the worm is towards the control port and outside the neutral zone.
nE = arrayfun(@(x) nnz(cE(:,x)), 1:size(plotxvals,2)); % applying the function nnz to every x column in cE
nC = arrayfun(@(x) nnz(cC(:,x)), 1:size(plotxvals,2)); % applying the function nnz to every x column in cC
n.E=nE.*info.samplefreq'; % this tells us the amount of time (number of seconds) the worm spent closer to the experimental side.
n.C=nC.*info.samplefreq'; % this tells us the amount of time (number of seconds) the worm spent closer to the control side.
%% Number of animals that end the assay on the experimental vs control side
% First find the end of the track
B= ~isnan(plotxvals);
Indices = arrayfun(@(x) find(B(:,x),1,'last'), 1:size(plotxvals,2)); % logical array
% For how many worms is the final x position on the experimental side?
fE = arrayfun(@(x,y) cE(x,y), Indices, 1:size(plotxvals,2));
nfinal.E = nnz(fE); % number of nonzero elements
% Is the final x position on the control side?
fC = arrayfun(@(x,y) cC(x,y), Indices, 1:size(plotxvals,2));
nfinal.C = nnz(fC); % number of nonzero elements
%% Number of animals entering experimental vs control side
% Currently, this value is +1 if an animal ever enters an active zone; it
% does not add more counts in the animal enters multiple times
% nenter.E = nnz(nE); % number of non-zero elements in the count of how many frames each worm was in the experimental zone
% nenter.C = nnz(nC); % number of non-zero elements in the count of how many frames each worm was in the control zone
end