forked from jessedmarshall/CAPTURE_demo
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCAPTURE_quickdemo.m
More file actions
178 lines (144 loc) · 5.73 KB
/
CAPTURE_quickdemo.m
File metadata and controls
178 lines (144 loc) · 5.73 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
function [analysisstruct,hierarchystruct] = CAPTURE_quickdemo(inputfile,ratnames,coefficientfilename,linkname)
% File to generate tsne features and run reembedding on a mouse
% inputfile: a .mat file that contains a preprocessed dannce struct
% (see preprocess_dannce)
% ratnames: a string containing the name of the experiment/rat to be
% used in saving files
% coefficientnames: preexisting names of coefficients or file to save
% tsne coefficients to.
% linkname: the name of the animal (ie kyle_mouse or 'rats' or 'bird'
% to be used in computing tsne features)
%
% This repository contains contributions from the following FEX/Open source contributions which are included:
%Chronux
%Pca Randomized
%MTimesX
%othercolor
%Motionmapper
%Structvars
% ---------------------------
% (C) Jesse D Marshall 2020
% Harvard University
%load mocap file
if isempty(inputfile)
datafile = ...
load('C:\Users\Jesse Marshall\Documents\GitHub\Movement_analysis\Cortex_analysis\DemoRepo\Data\nolj_Recording_day8_caff1_nolj_imputed.mat');
else
datafile = load(inputfile);
if isstruct(datafile) && numel(fieldnames(datafile)) == 1
fname = fieldnames(datafile);
datafile = datafile.(fname{1});
end
end
mocapstruct = datafile;
if isempty(coefficientfilename)
coefficient_file = 'demo_coefficients.mat';
else
coefficient_file = coefficientfilename;
end
if isempty(ratnames)
ratname = 'myrat';
else
ratname = ratnames;
end
if isempty(ratnames)
ratname = 'myrat';
else
ratname = ratnames;
end
% could change
savefilename ='myextratsnefeature';
directory_here = pwd;
%feature filename and whether or not to overwrite
MLmatobjfile = 'myMLfeatures.mat';
overwrite_MLmatobjfile = 1;
overwrite_coefficient=1;
%visualize the mocap data
%animate_markers_nonaligned_fullmovie_demo(mocapstruct,1:10:10000);
%% Create behavioral features
%this determines the set of frames to use -- in general if the animal is
%resting for too long it will cause errors
mocapstruct.modular_cluster_properties.clipped_index{8} = 1:size(mocapstruct.aligned_mean_position,1 );
% to control the wavelet parameters, you can change the properties in the
% compute_wl_transform_features file
if ~exist(MLmatobjfile,'file') || overwrite_MLmatobjfile
MLmatobj = create_behavioral_features(mocapstruct,coefficient_file,overwrite_coefficient,linkname);
else
MLmatobj = load(MLmatobjfile);
end
% perform a tsne embedding subselecting every 50 frames
analysisparams.tsnegranularity = 50;
%subselect a particular set of features
analysisstruct = compute_tsne_features(MLmatobj,mocapstruct,analysisparams);
%run tsne
zvals = tsne(analysisstruct.jt_features);
figure(1)
plot(zvals(:,1),zvals(:,2),'ob','MarkerFaceColor','b')
analysisstruct.zValues = zvals;
%% clustering parameters
analysisstruct.params.density_res = 1001; %resolution of the map
analysisstruct.params.density_width = 2; %density kernel in tsne space
analysisstruct.params.expansion_factor = 1.1; %add a little room to the map after kernel smoothing
analysisstruct.params.density_threshold = 1*10^(-5); %remove regions in plots with low density
analysisstruct.matchedconds = {[unique(analysisstruct.condition_inds)]}; %if running over multiple conditions
analysisstruct.conditions_to_run = [unique(analysisstruct.condition_inds)];
analysisstruct.tsnegranularity = analysisparams.tsnegranularity;
params.reorder=1;
analysisstruct = compute_analysis_clusters_demo(analysisstruct,params);
%% behavior plots and movies
analysisstruct.conditionnames = ratname;
analysisstruct.ratnames = ratname;
analysisstruct.filesizes = {size(mocapstruct.aligned_mean_position,1 );};
%% plot a tsne map -- see plotting script for parameter definitions
h1=figure(609)
clf;
params.nameplot=0;
params.density_plot =0;
params.watershed = 1;
params.sorted = 1;
params.markersize = 1;
params.coarseboundary =0;
params.do_coarse = 0;
plot_clustercolored_tsne(analysisstruct,1,params.watershed,h1,params)
set(gcf,'Position',([100 100 1100 1100]))
% bird specific axes
axisparams.zlim = ([200 300]);
axisparams.xlim = ([-400 400]);
axisparams.ylim = ([-400 400]);
figure(370);
clf;
animate_markers_nonaligned_fullmovie_demo(analysisstruct.mocapstruct_reduced_agg{1},...
find(analysisstruct.annot_reordered{end}==10),[],axisparams);
animate_markers_aligned_fullmovie_demo(analysisstruct.mocapstruct_reduced_agg{1},...
find(analysisstruct.annot_reordered{end}==59));
%% or use extnded set of 140 features
if strcmp(ratname,'myrat')
MLmatobj_extra = create_extra_behavioral_features(mocapstruct,'myrat',savefilename,overwrite_coefficient,directory_here);
jt_features_extra = load_extra_tsne_features(mocapstruct,MLmatobj_extra,analysisparams);
% look at tsne of these added features
zvals_extra = tsne(jt_features_extra);
% or the combination
%zvals_extra = tsne(cat(2,analysisstruct.jt_features,jt_features_extra));
figure(2)
plot(zvals_extra(:,1),zvals_extra(:,2),'ob','MarkerFaceColor','b')
analysisstruct.zValues_extra = zvals;
end
%% run sequence and state analysis
params.do_show_pdistmatrix =1;
params.decimation_factor = 5; %downsample if needed to save on memory
params.doclustering = 1;
%clustering parameters
params.corr_threshold = 0.2;
params.clustercutoff = 0.65;
analysisstruct.plotdirectory = '';
%timescale to use, in seconds
params.timescales = [1./4 2];
analysisstruct.conditionnames = {'test'};
analysisstruct.ratname = {ratname};
hierarchystruct= find_sequences_states_demo(analysisstruct,1,params);
%animate_markers_nonaligned_fullmovie_demo(analysisstruct.mocapstruct_reduced_agg{1},...
% find(hierarchystruct.clustered_behavior{1}==2));
end
%visualize
%internal: check dependencies
%[fList,pList] = matlab.codetools.requiredFilesAndProducts('CAPTURE_quickdemo.m');