OSCR

Social reward outcompetes drug seeking dopaminergic ensembles to prevent relapse.

Code ↔ Paper

1 match between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 1 match
  1. [1] § Methods › Cell registration across sessions ↔ GUI/CellReg.m, lines 1–91 · score 0.61 · CellReg, cellular activity, scored, events, MATLAB, neurons

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 2,236 lines · 108 KB · GPL-2.0 · 1 match

  1. function varargout = CellReg(varargin)
  2. % This GUI is an implementation of a probabilistic approach for the
  3. % identification of the same neurons (cell registration) across multiple sessions
  4. % in Ca2+ imaging data, developed by Sheintuch et al., 2017.
  5. % Input: The inputs for the cell registration method are the spatial footprints of
  6. % cellular activity of the cells that were detected in the different
  7. % sessions. Each spatial footprint is a matrix the size of the frame and
  8. % each pixel's value represents its contribution to the
  9. % cell's fluorescence.
  10. % Output: The main output for the cell registration method is the obtained mapping of
  11. % cell identity across all registered sessions. It is a matrix the size of
  12. % the final number of registered cells by the number of registered
  13. % sessions. Each entry holds the index for the cell in a given session.
  14. % Other outputs include:
  15. % 1) register scores - providing with the registration quality of each cell register
  16. % 2) log file - with all the relevant information regarding the data, registration
  17. % configurations, and a summary of the registration results and quality.
  18. % 3) figures - important figures that are saved automatically.
  19. % The GUI includes the following stages:
  20. % 1) Loading the spatial footprints of cellular activity from the different sessions.
  21. % 2) Transforming all the sessions to a reference coordinate system using
  22. % rigid-body transformation.
  23. % 3) Computing a probabilistic model of the spatial footprints similarities
  24. % of neighboring cell-pairs from different sessions using the centroid
  25. % distances and spatial correlations.
  26. % 4) Obtaining an initial cell registration according to an optimized registration threshold.
  27. % 5) Obtaining the final cell registration based on a correlation clustering algorithm.
  28. % CellReg MATLAB code for CellReg.fig
  29. % CellReg, by itself, creates a new CellReg or raises the existing
  30. % singleton*.
  31. %
  32. % H = CellReg returns the handle to a new CellReg or the handle to
  33. % the existing singleton*.
  34. %
  35. % CellReg('CALLBACK',hObject,eventData,handles,...) calls the local
  36. % function named CALLBACK in CellReg.M with the given input arguments.
  37. %
  38. % CellReg('Property','Value',...) creates a new CellReg or raises the
  39. % existing singleton*. Starting from the left, property value pairs are
  40. % applied to the GUI before CellReg_OpeningFcn gets called. An
  41. % unrecognized property name or invalid value makes property application
  42. % stop. All inputs are passed to CellReg_OpeningFcn via varargin.
  43. %
  44. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
  45. % instance to run (singleton)".
  46. %
  47. % See also: GUIDE, GUIDATA, GUIHANDLES
  48. % Edit the above text to modify the response to help CellReg
  49. % Last Modified by GUIDE v2.5 19-Mar-2018 16:44:19
  50. % reset figure properties to default:
  51. if verLessThan('matlab','8.4')
  52. % MATLAB R2014a and earlier
  53. % if there are problems with GUI and figures change properties back to default
  54. else
  55. % MATLAB R2014b and later
  56. reset(0);
  57. end
  58. % Begin initialization code - DO NOT EDIT
  59. gui_Singleton = 1;
  60. gui_State = struct('gui_Name', mfilename, ...
  61. 'gui_Singleton', gui_Singleton, ...
  62. 'gui_OpeningFcn', @CellReg_OpeningFcn, ...
  63. 'gui_OutputFcn', @CellReg_OutputFcn, ...
  64. 'gui_LayoutFcn', [] , ...
  65. 'gui_Callback', []);
  66. if nargin && ischar(varargin{1})
  67. gui_State.gui_Callback = str2func(varargin{1});
  68. end
  69. if nargout
  70. [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
  71. else
  72. gui_mainfcn(gui_State, varargin{:});
  73. end
  74. % End initialization code - DO NOT EDIT
  75. % --- Executes just before CellReg is made visible.
  76. function CellReg_OpeningFcn(hObject,~, handles, varargin)
  77. % This function has no output args, see OutputFcn.
  78. % hObject handle to figure
  79. % eventdata reserved - to be defined in a future version of MATLAB
  80. % handles struct with handles and user data (see GUIDATA)
  81. % varargin command line arguments to CellReg (see VARARGIN)
  82. % Choose default command line output for CellReg
  83. handles.output = hObject;
  84. % Update handles struct
  85. guidata(hObject, handles);
  86. % UIWAIT makes CellReg wait for user response (see UIRESUME)
  87. % uiwait(handles.figure1);
  88. % defining data struct:
  89. data_struct=struct;
  90. data_struct.sessions_list=[];
  91. % Reseting figures and GUI parameters:
  92. cla(handles.axes1,'reset')
  93. axes(handles.axes1);
  94. plot([],[])
  95. set(gca,'xtick',[])
  96. set(gca,'ytick',[])
  97. cla(handles.axes2,'reset')
  98. axes(handles.axes2);
  99. plot([],[])
  100. set(gca,'xtick',[])
  101. set(gca,'ytick',[])
  102. cla(handles.axes3,'reset')
  103. axes(handles.axes3);
  104. plot([],[])
  105. set(gca,'xtick',[])
  106. set(gca,'ytick',[])
  107. cla(handles.axes4,'reset')
  108. axes(handles.axes4);
  109. plot([],[])
  110. set(gca,'xtick',[])
  111. set(gca,'ytick',[])
  112. cla(handles.axes5,'reset')
  113. axes(handles.axes5);
  114. plot([],[])
  115. set(gca,'xtick',[])
  116. set(gca,'ytick',[])
  117. cla(handles.axes6,'reset')
  118. axes(handles.axes6);
  119. plot([],[])
  120. set(gca,'xtick',[])
  121. set(gca,'ytick',[])
  122. cla(handles.axes7,'reset')
  123. axes(handles.axes7);
  124. logo=imread('CellReg_Logo.png');
  125. imagesc(logo);
  126. set(gca,'xtick',[])
  127. set(gca,'ytick',[])
  128. data_struct.sessions_list=[];
  129. set(handles.list_of_sessions,'value',1)
  130. set(handles.list_of_sessions,'string',[]);
  131. set(handles.green_session,'string','2')
  132. set(handles.blue_session,'string','3')
  133. set(handles.decision_thresh,'string','0.5')
  134. set(handles.initial_p_same_slider,'value',0.5);
  135. set(handles.initial_p_same_threshold,'string','0.5');
  136. set(handles.final_p_same_slider,'value',0.5);
  137. set(handles.model_maximal_distance,'string','14')
  138. set(handles.distance_threshold,'string','5')
  139. set(handles.correlation_threshold,'string','0.65')
  140. set(handles.simple_distance_threshold,'string','5')
  141. set(handles.simple_correlation_threshold,'string','0.65')
  142. set(handles.figures_visibility_on,'Value',1);
  143. set(handles.write2file_on, 'Value', 0);
  144. set(handles.translations_rotations,'Value',1);
  145. set(handles.spatial_correlations_2,'Value',1);
  146. set(handles.spatial_correlations,'Value',1);
  147. set(handles.use_model,'Value',1);
  148. set(handles.microns_per_pixel,'string',[])
  149. set(handles.microns_per_pixel,'value',0)
  150. set(handles.microns_per_pixel,'backgroundColor',[1 1 1]);
  151. set(handles.reference_session_index,'string','1')
  152. set(handles.maximal_rotation','string','30')
  153. set(handles.maximal_rotation','enable','on')
  154. set(handles.transformation_smoothness,'string','2')
  155. set(handles.transformation_smoothness,'enable','off')
  156. set(handles.distance_threshold,'enable','off')
  157. set(handles.correlation_threshold,'enable','on')
  158. set(handles.decision_thresh,'enable','on')
  159. set(handles.simple_distance_threshold,'enable','off')
  160. set(handles.simple_correlation_threshold,'enable','off')
  161. set(handles.comments,'string',[])
  162. handles.data_struct=data_struct;
  163. guidata(hObject, handles);
  164. % --- Outputs from this function are returned to the command line.
  165. function varargout = CellReg_OutputFcn(~, ~, handles)
  166. % varargout cell array for returning output args (see VARARGOUT);
  167. % hObject handle to figure
  168. % eventdata reserved - to be defined in a future version of MATLAB
  169. % handles struct with handles and user data (see GUIDATA)
  170. % Get default command line output from handles struct
  171. varargout{1} = handles.output;
  172. % --------------------------------------------------------------------
  173. function load_new_data_Callback(hObject,~, handles)
  174. % hObject handle to load_new_data (see GCBO)
  175. % eventdata reserved - to be defined in a future version of MATLAB
  176. % handles struct with handles and user data (see GUIDATA)
  177. % Stage 1: Loading the spatial footprints of cellular activity from the different
  178. % sessions.
  179. % This callback loads a new data set which includes several sessions with
  180. % their spatial footprints, centroid locations (optional), and events (optional). A
  181. % single folder should be selected with all the mat files with number:
  182. % example: "finalFiltersMat_1", "finalFiltersMat_2", "finalEventsMat_1", "finalEventsMat_2"
  183. data_struct=handles.data_struct;
  184. % choosing the files to load:
  185. msgbox_timed('Please choose the files containing the spatial footprints from all the sessions: ',3)
  186. [file_names,files_path]=uigetfile('*.mat','MultiSelect','on',...
  187. 'Choose spatial footprints from all the sessions: ' );
  188. % in case only one file is selected uigetfile will return a char and not a
  189. % cell, and thus make later code bug.
  190. if ischar(file_names)
  191. warndlg_timed('To process only one session you should use Add Session button',3)
  192. return
  193. end
  194. number_of_sessions=size(file_names,2);
  195. sessions_list=cell(1,number_of_sessions);
  196. temp_file_names=cell(1,number_of_sessions);
  197. for n=1:number_of_sessions
  198. sessions_list{1,n}=['Session ' num2str(n) ' - ' files_path file_names{1,n}];
  199. temp_file_names{1,n}=[files_path file_names{1,n}];
  200. end
  201. file_names=temp_file_names;
  202. % defining the microns per pixel ratio:
  203. microns_per_pixel=str2num(get(handles.microns_per_pixel,'string'));
  204. if isempty(microns_per_pixel)
  205. msgbox_timed('Please insert the pixel size in microns and press enter ',3);
  206. set(handles.microns_per_pixel,'backgroundColor',[1 0.5 0.5]);
  207. waitfor(handles.microns_per_pixel,'value',1);
  208. microns_per_pixel=str2num(get(handles.microns_per_pixel,'string'));
  209. end
  210. set(handles.microns_per_pixel,'string',num2str(round(100*microns_per_pixel)/100));
  211. set(handles.microns_per_pixel,'backgroundColor',[1 1 1]);
  212. % defining the results directory:
  213. msgbox_timed('Please select the folder in which the results will be saved',3)
  214. results_directory=uigetdir(files_path); % the directory which the final results will be saved
  215. figures_directory=fullfile(results_directory,'Figures');
  216. if exist(figures_directory,'dir')~=7
  217. mkdir(figures_directory);
  218. end
  219. if get(handles.figures_visibility_on,'Value');
  220. figures_visibility='On';
  221. else
  222. figures_visibility='Off';
  223. end
  224. % loading the spatial footprints:
  225. disp('Stage 1 - Loading sessions')
  226. if get(handles.write2file_on,'Value')
  227. spatial_footprints = file_names;
  228. number_of_sessions = length(file_names);
  229. else
  230. [spatial_footprints,number_of_sessions]=load_multiple_sessions(file_names);
  231. end
  232. [footprints_projections]=compute_footprints_projections(spatial_footprints);
  233. plot_all_sessions_projections(footprints_projections,figures_directory,figures_visibility)
  234. % saving the loaded data into the data struct for the GUI
  235. if get(handles.write2file_on,'Value')
  236. data_struct.temp_dir = [figures_directory, filesep, 'temp'];
  237. if ~exist(data_struct.temp_dir)
  238. mkdir(data_struct.temp_dir);
  239. end
  240. else
  241. data_struct.temp_dir = [];
  242. end
  243. data_struct.results_directory=results_directory;
  244. data_struct.figures_directory=figures_directory;
  245. data_struct.microns_per_pixel=microns_per_pixel;
  246. data_struct.spatial_footprints=spatial_footprints;
  247. data_struct.footprints_projections=footprints_projections;
  248. data_struct.number_of_sessions=number_of_sessions;
  249. data_struct.sessions_list=sessions_list;
  250. data_struct.file_names=file_names;
  251. set(handles.list_of_sessions,'string',data_struct.sessions_list);
  252. handles.data_struct=data_struct;
  253. guidata(hObject, handles)
  254. disp('Done')
  255. msgbox_timed('Finished loading sessions',3)
  256. % --- Executes on button press in add_session.
  257. function add_session_Callback(hObject,~, handles)
  258. % hObject handle to add_session (see GCBO)
  259. % eventdata reserved - to be defined in a future version of MATLAB
  260. % handles struct with handles and user data (see GUIDATA)
  261. % This callback adds another session to the list of sessions to be
  262. % registered. The folder containg the filters, centroid_locations, and events
  263. % (optional) should be selected
  264. data_struct=handles.data_struct;
  265. if get(handles.figures_visibility_on,'Value');
  266. figures_visibility='On';
  267. else
  268. figures_visibility='Off';
  269. end
  270. if isfield(data_struct,'spatial_footprints') % some sessions were already loaded
  271. spatial_footprints=data_struct.spatial_footprints;
  272. number_of_sessions=data_struct.number_of_sessions;
  273. file_names=data_struct.file_names;
  274. sessions_list=data_struct.sessions_list;
  275. results_directory=data_struct.results_directory;
  276. % loading the session:
  277. msgbox_timed('Please choose the file with the spatial footprints for this session: ',1)
  278. [file_name,file_path]=uigetfile(strcat(results_directory,filesep,'*.mat'),...
  279. 'Choose the file with the spatial footprints for this session: ','MultiSelect','off');
  280. number_of_sessions=number_of_sessions+1;
  281. file_names{number_of_sessions}=[file_path file_name];
  282. sessions_list{number_of_sessions}=['Session ' num2str(number_of_sessions) ' - ' file_path file_name];
  283. disp('Stage 1 - Loading sessions')
  284. if get(handles.write2file_on,'Value')
  285. added_spatial_footprints = file_names{number_of_sessions};
  286. else
  287. [added_spatial_footprints]=load_single_session(file_names{number_of_sessions});
  288. end
  289. spatial_footprints{number_of_sessions}=added_spatial_footprints;
  290. [added_footprints_projection]=compute_footprints_projections({added_spatial_footprints});
  291. footprints_projections{number_of_sessions}=added_footprints_projection;
  292. plot_single_session_projections(added_footprints_projection,num2str(number_of_sessions),figures_visibility)
  293. else % first loaded session
  294. data_struct=handles.data_struct;
  295. % chosing the file to load:
  296. msgbox_timed('Please choose the file with the spatial footprints for this session: ',1)
  297. [file_name,file_path]=uigetfile('*.mat',...
  298. 'Choose the file with the spatial footprints for this session: ','MultiSelect','off');
  299. number_of_sessions=1;
  300. sessions_list={['Session 1 - ' file_path file_name]};
  301. file_names={[file_path file_name]};
  302. % defining the microns per pixel ratio:
  303. microns_per_pixel=str2num(get(handles.microns_per_pixel,'string'));
  304. if isempty(microns_per_pixel)
  305. msgbox_timed('Please insert the pixel size in microns and press enter ',3);
  306. set(handles.microns_per_pixel,'backgroundColor',[1 0.5 0.5]);
  307. waitfor(handles.microns_per_pixel,'value',1);
  308. microns_per_pixel=str2num(get(handles.microns_per_pixel,'string'));
  309. end
  310. set(handles.microns_per_pixel,'string',num2str(round(100*microns_per_pixel)/100));
  311. set(handles.microns_per_pixel,'backgroundColor',[1 1 1]);
  312. % defining the results directory:
  313. msgbox_timed('Please select the folder in which the results will be saved',3)
  314. results_directory=uigetdir(file_path); % the directory which the final results will be saved
  315. figures_directory=fullfile(results_directory,'Figures');
  316. if exist(figures_directory,'dir')~=7
  317. mkdir(figures_directory);
  318. end
  319. % loading the spatial footprints:
  320. disp('Stage 1 - Loading sessions')
  321. if get(handles.write2file_on,'Value');
  322. spatial_footprints = {file_names{1}};
  323. else
  324. [spatial_footprints]={load_single_session(file_names{1})};
  325. end
  326. [footprints_projections]=compute_footprints_projections(spatial_footprints);
  327. plot_single_session_projections(footprints_projections,1,figures_visibility)
  328. % saving the loaded data into the data struct for the GUI
  329. data_struct.results_directory=results_directory;
  330. data_struct.figures_directory=figures_directory;
  331. data_struct.microns_per_pixel=microns_per_pixel;
  332. end
  333. % saving the loaded data into the data struct for the GUI
  334. if get(handles.write2file_on,'Value')
  335. data_struct.temp_dir = [figures_directory, filesep, 'temp'];
  336. if ~exist(data_struct.temp_dir)
  337. mkdir(data_struct.temp_dir);
  338. end
  339. else
  340. data_struct.temp_dir = [];
  341. end
  342. data_struct.spatial_footprints=spatial_footprints;
  343. data_struct.footprints_projections=footprints_projections;
  344. data_struct.number_of_sessions=number_of_sessions;
  345. data_struct.sessions_list=sessions_list;
  346. data_struct.file_names=file_names;
  347. set(handles.list_of_sessions,'string',data_struct.sessions_list);
  348. handles.data_struct=data_struct;
  349. guidata(hObject, handles)
  350. disp('Done')
  351. msgbox_timed('Finished loading session',1)
  352. % --- Executes on button press in remove_session.
  353. function remove_session_Callback(hObject,~, handles)
  354. % hObject handle to remove_session (see GCBO)
  355. % eventdata reserved - to be defined in a future version of MATLAB
  356. % handles struct with handles and user data (see GUIDATA)
  357. % This callback removes the selected session from the list of sessions to be registered
  358. data_struct=handles.data_struct;
  359. if isfield(data_struct,'spatial_footprints')
  360. % selecting the session to remove:
  361. number_of_sessions=data_struct.number_of_sessions;
  362. chosen_session=get(handles.list_of_sessions,'value');
  363. sessions_to_keep=setdiff(1:number_of_sessions,chosen_session);
  364. set(handles.list_of_sessions,'value',1)
  365. number_of_sessions=number_of_sessions-1;
  366. % removing the session from the data:
  367. if isfield(data_struct,'spatial_footprints_corrected') % if data was aligned
  368. centroid_locations=data_struct.centroid_locations(sessions_to_keep);
  369. adjusted_footprints_projections=data_struct.adjusted_footprints_projections(sessions_to_keep);
  370. spatial_footprints_corrected=data_struct.spatial_footprints_corrected(sessions_to_keep);
  371. centroid_locations_corrected=data_struct.centroid_locations_corrected(sessions_to_keep);
  372. footprints_projections_corrected=data_struct.footprints_projections_corrected(sessions_to_keep);
  373. % for variables that are compared to a reference session:
  374. reference_session_index=data_struct.reference_session_index;
  375. if reference_session_index==chosen_session
  376. errordlg('This session was used as a reference for alignment and therefore cannot be removed')
  377. error('This session was used as a reference for alignment and therefore cannot be removed')
  378. else
  379. sessions_without_reference=setdiff(1:number_of_sessions+1,reference_session_index);
  380. chosen_session_compared_to_reference_index=find(sessions_without_reference==chosen_session);
  381. sessions_to_keep_compared_to_reference=setdiff(1:number_of_sessions,chosen_session_compared_to_reference_index);
  382. maximal_cross_correlation=data_struct.maximal_cross_correlation(sessions_to_keep_compared_to_reference);
  383. alignment_translations=data_struct.alignment_translations(:,sessions_to_keep_compared_to_reference);
  384. end
  385. if reference_session_index>chosen_session % index of reference should change
  386. reference_session_index=reference_session_index-1;
  387. end
  388. data_struct.centroid_locations=centroid_locations;
  389. data_struct.adjusted_footprints_projections=adjusted_footprints_projections;
  390. data_struct.spatial_footprints_corrected=spatial_footprints_corrected;
  391. data_struct.centroid_locations_corrected=centroid_locations_corrected;
  392. data_struct.footprints_projections_corrected=footprints_projections_corrected;
  393. data_struct.maximal_cross_correlation=maximal_cross_correlation;
  394. data_struct.alignment_translations=alignment_translations;
  395. data_struct.reference_session_index=reference_session_index;
  396. end
  397. spatial_footprints=data_struct.spatial_footprints;
  398. footprints_projections=data_struct.footprints_projections;
  399. spatial_footprints=spatial_footprints(sessions_to_keep);
  400. footprints_projections=footprints_projections(sessions_to_keep);
  401. file_names=data_struct.file_names(sessions_to_keep);
  402. sessions_list=cell(1,number_of_sessions);
  403. for n=1:number_of_sessions
  404. sessions_list{1,n}=['Session ' num2str(n) ' - ' file_names{1,n}];
  405. end
  406. data_struct.number_of_sessions=number_of_sessions;
  407. data_struct.spatial_footprints=spatial_footprints;
  408. data_struct.footprints_projections=footprints_projections;
  409. data_struct.sessions_list=sessions_list;
  410. data_struct.file_names=file_names;
  411. data_struct.sessions_list=sessions_list;
  412. set(handles.list_of_sessions,'string',data_struct.sessions_list);
  413. handles.data_struct=data_struct;
  414. guidata(hObject, handles)
  415. msgbox_timed('Finished removing session',1)
  416. end
  417. % --------------------------------------------------------------------
  418. function load_transformed_data_Callback(hObject,~, handles)
  419. % hObject handle to load_transformed_data (see GCBO)
  420. % eventdata reserved - to be defined in a future version of MATLAB
  421. % handles struct with handles and user data (see GUIDATA)
  422. % This callback loads sessions that were already aligned into a reference coordinate system.
  423. % For such data the compute model should be the next step.
  424. msgbox_timed('Please choose the file containing the aligned data structure: ',3)
  425. [file_name,file_path]=uigetfile('*.mat',...
  426. 'Choose the file containing the aligned data: ','MultiSelect','off');
  427. disp('Loading aligned data')
  428. aligned_data_struct=load(fullfile(file_path,file_name));
  429. if ~isstruct(aligned_data_struct)
  430. errordlg('This file does not contain data with the required format')
  431. error('This file does not contain data with the required format')
  432. elseif ~isfield(aligned_data_struct,'aligned_data_struct')
  433. errordlg('This file does not contain data with the required format')
  434. error('This file does not contain data with the required format')
  435. else
  436. % loading the aligned data:
  437. msgbox_timed('Please select the folder in which the results will be saved',3)
  438. results_directory=uigetdir(file_path); % the directory which the final results will be saved
  439. data_struct=aligned_data_struct.aligned_data_struct;
  440. data_struct.results_directory=results_directory;
  441. figures_directory=fullfile(results_directory,'Figures');
  442. data_struct.figures_directory=figures_directory;
  443. if exist(figures_directory,'dir')~=7
  444. mkdir(figures_directory);
  445. end
  446. % plotting the aligned data:
  447. footprints_projections_corrected=data_struct.footprints_projections_corrected;
  448. overlapping_FOV=data_struct.overlapping_FOV;
  449. if get(handles.figures_visibility_on,'Value');
  450. figures_visibility='On';
  451. else
  452. figures_visibility='Off';
  453. end
  454. plot_all_sessions_projections(footprints_projections_corrected,figures_directory,figures_visibility)
  455. number_of_sessions=length(footprints_projections_corrected);
  456. if number_of_sessions>2
  457. RGB_indexes=[1 2 3];
  458. else
  459. RGB_indexes=[1 2];
  460. end
  461. axes(handles.axes1);
  462. plot_RGB_overlay(footprints_projections_corrected,RGB_indexes,overlapping_FOV)
  463. figure('units','normalized','outerposition',[0.325 0.25 0.35 0.5],'Visible',figures_visibility)
  464. plot_RGB_overlay(footprints_projections_corrected,RGB_indexes,overlapping_FOV)
  465. % loading configurations to GUI:
  466. set(handles.microns_per_pixel,'string',num2str(round(100*data_struct.microns_per_pixel)/100));
  467. set(handles.reference_session_index,'string',num2str(data_struct.reference_session_index))
  468. set(handles.list_of_sessions,'string',data_struct.sessions_list)
  469. if strcmp(data_struct.alignment_type,'Translations')
  470. set(handles.translations,'Value',1);
  471. elseif strcmp(data_struct.alignment_type,'Translations and Rotations')
  472. set(handles.translations_rotations,'Value',1);
  473. else
  474. set(handles.non_rigid,'Value',1);
  475. end
  476. end
  477. handles.data_struct=data_struct;
  478. guidata(hObject, handles)
  479. disp('Done')
  480. msgbox_timed('Finished loading aligned sessions',3)
  481. % --- Executes on button press in load_modeled_data.
  482. function load_modeled_data_Callback(hObject, eventdata, handles)
  483. % hObject handle to load_modeled_data (see GCBO)
  484. % eventdata reserved - to be defined in a future version of MATLAB
  485. % handles structure with handles and user data (see GUIDATA)
  486. % This callback loads data that were already modeled.
  487. % For such data the initial registration should be the next step.
  488. msgbox_timed('Please choose the file containing the modeled data structure: ',3)
  489. [file_name,file_path]=uigetfile('*.mat',...
  490. 'Choose the file containing the modeled data','MultiSelect','off');
  491. disp('Loading modeled data')
  492. modeled_data_struct=load(fullfile(file_path,file_name));
  493. if ~isstruct(modeled_data_struct)
  494. errordlg('This file does not contain data with the required format')
  495. error('This file does not contain data with the required format')
  496. elseif ~isfield(modeled_data_struct,'modeled_data_struct')
  497. errordlg('This file does not contain data with the required format')
  498. error('This file does not contain data with the required format')
  499. else
  500. % loading the aligned data:
  501. msgbox_timed('Please select the folder in which the results will be saved',3)
  502. results_directory=uigetdir(file_path); % the directory which the final results will be saved
  503. data_struct=modeled_data_struct.modeled_data_struct;
  504. data_struct.results_directory=results_directory;
  505. figures_directory=fullfile(results_directory,'Figures');
  506. data_struct.figures_directory=figures_directory;
  507. if exist(figures_directory,'dir')~=7
  508. mkdir(figures_directory);
  509. end
  510. % plotting the data:
  511. footprints_projections_corrected=data_struct.footprints_projections_corrected;
  512. overlapping_FOV=data_struct.overlapping_FOV;
  513. if get(handles.figures_visibility_on,'Value');
  514. figures_visibility='On';
  515. else
  516. figures_visibility='Off';
  517. end
  518. plot_all_sessions_projections(footprints_projections_corrected,figures_directory,figures_visibility)
  519. number_of_sessions=length(footprints_projections_corrected);
  520. if number_of_sessions>2
  521. RGB_indexes=[1 2 3];
  522. else
  523. RGB_indexes=[1 2];
  524. end
  525. axes(handles.axes1);
  526. plot_RGB_overlay(footprints_projections_corrected,RGB_indexes,overlapping_FOV)
  527. figure('units','normalized','outerposition',[0.325 0.25 0.35 0.5],'Visible',figures_visibility)
  528. plot_RGB_overlay(footprints_projections_corrected,RGB_indexes,overlapping_FOV)
  529. % loading configurations to GUI:
  530. set(handles.microns_per_pixel,'string',num2str(round(100*data_struct.microns_per_pixel)/100));
  531. set(handles.reference_session_index,'string',num2str(data_struct.reference_session_index))
  532. set(handles.list_of_sessions,'string',data_struct.sessions_list)
  533. set(handles.model_maximal_distance,'string',num2str(data_struct.maximal_distance));
  534. if strcmp(data_struct.alignment_type,'Translations')
  535. set(handles.translations,'Value',1);
  536. elseif strcmp(data_struct.alignment_type,'Translations and Rotations')
  537. set(handles.translations_rotations,'Value',1);
  538. else
  539. set(handles.non_rigid,'Value',1);
  540. end
  541. end
  542. handles.data_struct=data_struct;
  543. guidata(hObject, handles)
  544. disp('Done')
  545. msgbox_timed('Finished loading modeled data',1)
  546. % --- Executes on button press in transform_sessions.
  547. function transform_sessions_Callback(hObject,~, handles)
  548. % hObject handle to transform_sessions (see GCBO)
  549. % eventdata reserved - to be defined in a future version of MATLAB
  550. % handles struct with handles and user data (see GUIDATA)
  551. % Stage 2: Aligning all the sessions to a reference coordinate system using
  552. % rigid-body transformation
  553. % This callback performs rigid-body transfomration to all the sessions
  554. % according to a chosen reference ssseion. This stage:
  555. % 1) Corrects sessions for translation/rotations and transforming the
  556. % spatial footprints into a single coordinate frame
  557. % 2) Matches the sizes of all the spatial footprints from the different sessions
  558. % to the intersction of the different FOVs
  559. % 3) Evaluate whether or not it is suitable for
  560. % longitudinal analysis
  561. use_parallel_processing=true; % either true or false
  562. data_struct=handles.data_struct;
  563. number_of_sessions=data_struct.number_of_sessions;
  564. spatial_footprints=data_struct.spatial_footprints;
  565. results_directory=data_struct.results_directory;
  566. figures_directory=data_struct.figures_directory;
  567. microns_per_pixel=data_struct.microns_per_pixel;
  568. % defining the aligned data structure:
  569. aligned_data_struct=struct;
  570. aligned_data_struct.number_of_sessions=number_of_sessions;
  571. aligned_data_struct.spatial_footprints=spatial_footprints;
  572. aligned_data_struct.results_directory=results_directory;
  573. aligned_data_struct.figures_directory=figures_directory;
  574. aligned_data_struct.microns_per_pixel=microns_per_pixel;
  575. aligned_data_struct.footprints_projections=data_struct.footprints_projections;
  576. aligned_data_struct.sessions_list=data_struct.sessions_list;
  577. aligned_data_struct.file_names=data_struct.file_names;
  578. if get(handles.figures_visibility_on,'Value');
  579. figures_visibility='On';
  580. else
  581. figures_visibility='Off';
  582. end
  583. % Defining the parameters for image alignment:
  584. translations_value=get(handles.translations,'Value');
  585. rotations_value=get(handles.translations_rotations,'Value');
  586. if translations_value==1
  587. alignment_type='Translations';
  588. elseif rotations_value==1
  589. alignment_type='Translations and Rotations';
  590. else
  591. alignment_type='Non-rigid';
  592. end
  593. if strcmp(alignment_type,'Translations and Rotations')
  594. maximal_rotation=str2num(get(handles.maximal_rotation,'string'));
  595. end
  596. if strcmp(alignment_type,'Non-rigid')
  597. transformation_smoothness=str2num(get(handles.transformation_smoothness,'string'));
  598. if transformation_smoothness>3 || transformation_smoothness<0.5
  599. errordlg('FOV smoothing parameter should be between 0.5-3')
  600. error('FOV smoothing parameter should be between 0.5-3')
  601. end
  602. end
  603. reference_session_index=str2num(get(handles.reference_session_index,'string'));
  604. reference_valid=1;
  605. if isempty(reference_session_index) || reference_session_index<1 || reference_session_index>number_of_sessions
  606. reference_valid=0;
  607. end
  608. while reference_valid==0
  609. set(handles.reference_session_index,'value',0)
  610. msgbox_timed('Please insert a valid reference session number and press enter ',3);
  611. waitfor(handles.reference_session_index,'value',1);
  612. reference_session_index=str2num(get(handles.reference_session_index,'string'));
  613. if ~isempty(reference_session_index) && reference_session_index>=1 && reference_session_index<=number_of_sessions
  614. reference_valid=1;
  615. end
  616. end
  617. % Preparing the data for alignment:
  618. disp('Stage 2 - Aligning sessions')
  619. if ~isempty(data_struct.temp_dir)
  620. [normalized_spatial_footprints]=normalize_spatial_footprints(spatial_footprints, data_struct.temp_dir);
  621. else
  622. [normalized_spatial_footprints]=normalize_spatial_footprints(spatial_footprints);
  623. end
  624. [adjusted_spatial_footprints,adjusted_FOV,adjusted_x_size,adjusted_y_size,adjustment_zero_padding]=...
  625. adjust_FOV_size(normalized_spatial_footprints);
  626. [adjusted_footprints_projections]=compute_footprints_projections(adjusted_spatial_footprints);
  627. [centroid_locations]=compute_centroid_locations(adjusted_spatial_footprints,microns_per_pixel);
  628. [centroid_projections]=compute_centroids_projections(centroid_locations,adjusted_spatial_footprints);
  629. % Aligning the cells according to the tranlations/rotations that maximize their similarity:
  630. sufficient_correlation_centroids=0.2; % smaller correlation imply no similarity between sessions
  631. sufficient_correlation_footprints=0.2; % smaller correlation imply no similarity between sessions
  632. if strcmp(alignment_type,'Translations and Rotations')
  633. [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV]=...
  634. align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing,maximal_rotation);
  635. elseif strcmp(alignment_type,'Non-rigid')
  636. [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV,displacement_fields]=...
  637. align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing,transformation_smoothness);
  638. else
  639. [spatial_footprints_corrected,centroid_locations_corrected,footprints_projections_corrected,centroid_projections_corrected,maximal_cross_correlation,alignment_translations,overlapping_FOV]=...
  640. align_images(adjusted_spatial_footprints,centroid_locations,adjusted_footprints_projections,centroid_projections,adjusted_FOV,microns_per_pixel,reference_session_index,alignment_type,sufficient_correlation_centroids,sufficient_correlation_footprints,use_parallel_processing);
  641. end
  642. % Evaluating data quality:
  643. [all_projections_correlations,number_of_cells_per_session]=...
  644. evaluate_data_quality(spatial_footprints_corrected,centroid_projections_corrected,footprints_projections_corrected,maximal_cross_correlation,alignment_translations,reference_session_index,sufficient_correlation_footprints,alignment_type);
  645. % plotting alignment results:
  646. if strcmp(alignment_type,'Non-rigid')
  647. plot_alignment_results(adjusted_spatial_footprints,centroid_locations,spatial_footprints_corrected,centroid_locations_corrected,adjusted_footprints_projections,footprints_projections_corrected,reference_session_index,all_projections_correlations,maximal_cross_correlation,alignment_translations,overlapping_FOV,alignment_type,number_of_cells_per_session,figures_directory,figures_visibility,displacement_fields)
  648. else
  649. plot_alignment_results(adjusted_spatial_footprints,centroid_locations,spatial_footprints_corrected,centroid_locations_corrected,adjusted_footprints_projections,footprints_projections_corrected,reference_session_index,all_projections_correlations,maximal_cross_correlation,alignment_translations,overlapping_FOV,alignment_type,number_of_cells_per_session,figures_directory,figures_visibility)
  650. end
  651. if number_of_sessions>2
  652. RGB_indexes=[1 2 3];
  653. else
  654. RGB_indexes=[1 2];
  655. end
  656. axes(handles.axes1);
  657. plot_RGB_overlay(footprints_projections_corrected,RGB_indexes,overlapping_FOV)
  658. % saving the results into the data struct for the GUI
  659. data_struct.reference_session_index=reference_session_index;
  660. data_struct.alignment_type=alignment_type;
  661. data_struct.centroid_locations=centroid_locations;
  662. data_struct.spatial_footprints_corrected=spatial_footprints_corrected;
  663. data_struct.centroid_locations_corrected=centroid_locations_corrected;
  664. data_struct.adjusted_footprints_projections=adjusted_footprints_projections;
  665. data_struct.footprints_projections_corrected=footprints_projections_corrected;
  666. data_struct.adjusted_x_size=adjusted_x_size;
  667. data_struct.adjusted_y_size=adjusted_y_size;
  668. data_struct.overlapping_FOV=overlapping_FOV;
  669. data_struct.maximal_cross_correlation=maximal_cross_correlation;
  670. data_struct.alignment_translations=alignment_translations;
  671. data_struct.adjustment_zero_padding=adjustment_zero_padding;
  672. % saving the results into the aligned data structure:
  673. aligned_data_struct.reference_session_index=reference_session_index;
  674. aligned_data_struct.alignment_type=alignment_type;
  675. aligned_data_struct.centroid_locations=centroid_locations;
  676. aligned_data_struct.spatial_footprints_corrected=spatial_footprints_corrected;
  677. aligned_data_struct.centroid_locations_corrected=centroid_locations_corrected;
  678. aligned_data_struct.adjusted_footprints_projections=adjusted_footprints_projections;
  679. aligned_data_struct.footprints_projections_corrected=footprints_projections_corrected;
  680. aligned_data_struct.adjusted_x_size=adjusted_x_size;
  681. aligned_data_struct.adjusted_y_size=adjusted_y_size;
  682. aligned_data_struct.overlapping_FOV=overlapping_FOV;
  683. aligned_data_struct.maximal_cross_correlation=maximal_cross_correlation;
  684. aligned_data_struct.alignment_translations=alignment_translations;
  685. aligned_data_struct.adjustment_zero_padding=adjustment_zero_padding;
  686. handles.data_struct=data_struct;
  687. disp('Saving the aligned data structure')
  688. save(fullfile(results_directory,'aligned_data_struct.mat'),'aligned_data_struct','-v7.3')
  689. guidata(hObject,handles)
  690. if use_parallel_processing
  691. delete(gcp);
  692. end
  693. disp('Done')
  694. msgbox_timed('Finished aligning sessions',1)
  695. % --- Executes on button press in compute_model.
  696. function compute_model_Callback(hObject,~, handles)
  697. % hObject handle to compute_model (see GCBO)
  698. % eventdata reserved - to be defined in a future version of MATLAB
  699. % handles struct with handles and user data (see GUIDATA)
  700. % Stage 3: Computing a probabilistic model of the spatial footprints similarities
  701. % of neighboring cell-pairs from different sessions using the centroid_locations
  702. % distances and spatial correlations
  703. % This callback computes the probability model for the same cells and
  704. % different cells according to either spatial correlations, centroid
  705. % distances, or both measures. The output is all the probabilities of
  706. % neighboring cell-pairs to be the same cell - P_same.
  707. % reseting figures
  708. cla(handles.axes2,'reset')
  709. axes(handles.axes2);
  710. plot([],[])
  711. set(gca,'xtick',[])
  712. set(gca,'ytick',[])
  713. cla(handles.axes3,'reset')
  714. axes(handles.axes3);
  715. plot([],[])
  716. set(gca,'xtick',[])
  717. set(gca,'ytick',[])
  718. cla(handles.axes4,'reset')
  719. axes(handles.axes4);
  720. plot([],[])
  721. set(gca,'xtick',[])
  722. set(gca,'ytick',[])
  723. cla(handles.axes5,'reset')
  724. axes(handles.axes5);
  725. plot([],[])
  726. set(gca,'xtick',[])
  727. set(gca,'ytick',[])
  728. cla(handles.axes6,'reset')
  729. axes(handles.axes6);
  730. plot([],[])
  731. set(gca,'xtick',[])
  732. set(gca,'ytick',[])
  733. data_struct=handles.data_struct;
  734. spatial_footprints_corrected=data_struct.spatial_footprints_corrected;
  735. centroid_locations_corrected=data_struct.centroid_locations_corrected;
  736. microns_per_pixel=data_struct.microns_per_pixel;
  737. results_directory=data_struct.results_directory;
  738. figures_directory=data_struct.figures_directory;
  739. % defining the modeled data structure:
  740. modeled_data_struct=struct;
  741. modeled_data_struct.number_of_sessions=data_struct.number_of_sessions;
  742. modeled_data_struct.spatial_footprints=data_struct.spatial_footprints;
  743. modeled_data_struct.results_directory=results_directory;
  744. modeled_data_struct.figures_directory=figures_directory;
  745. modeled_data_struct.microns_per_pixel=microns_per_pixel;
  746. modeled_data_struct.reference_session_index=data_struct.reference_session_index;
  747. modeled_data_struct.alignment_type=data_struct.alignment_type;
  748. modeled_data_struct.centroid_locations=data_struct.centroid_locations;
  749. modeled_data_struct.spatial_footprints_corrected=spatial_footprints_corrected;
  750. modeled_data_struct.centroid_locations_corrected=centroid_locations_corrected;
  751. modeled_data_struct.adjusted_footprints_projections=data_struct.adjusted_footprints_projections;
  752. modeled_data_struct.footprints_projections_corrected=data_struct.footprints_projections_corrected;
  753. modeled_data_struct.adjusted_x_size=data_struct.adjusted_x_size;
  754. modeled_data_struct.adjusted_y_size=data_struct.adjusted_y_size;
  755. modeled_data_struct.overlapping_FOV=data_struct.overlapping_FOV;
  756. modeled_data_struct.maximal_cross_correlation=data_struct.maximal_cross_correlation;
  757. modeled_data_struct.alignment_translations=data_struct.alignment_translations;
  758. modeled_data_struct.adjustment_zero_padding=data_struct.adjustment_zero_padding;
  759. modeled_data_struct.footprints_projections=data_struct.footprints_projections;
  760. modeled_data_struct.sessions_list=data_struct.sessions_list;
  761. modeled_data_struct.file_names=data_struct.file_names;
  762. if get(handles.figures_visibility_on,'Value')
  763. figures_visibility='On';
  764. else
  765. figures_visibility='Off';
  766. end
  767. % Defining the parameters for the probabilstic modeling:
  768. maximal_distance=str2num(get(handles.model_maximal_distance,'string'));
  769. normalized_maximal_distance=maximal_distance/microns_per_pixel;
  770. p_same_certainty_threshold=0.95; % certain cells are those with p_same>threshld or <1-threshold
  771. [number_of_bins,centers_of_bins]=estimate_number_of_bins(spatial_footprints_corrected,normalized_maximal_distance);
  772. disp('Stage 3 - Calculating a probabilistic model of the data')
  773. [all_to_all_indexes,all_to_all_spatial_correlations,all_to_all_centroid_distances,neighbors_spatial_correlations,neighbors_centroid_distances,neighbors_x_displacements,neighbors_y_displacements,NN_spatial_correlations,NNN_spatial_correlations,NN_centroid_distances,NNN_centroid_distances]=...
  774. compute_data_distribution(spatial_footprints_corrected,centroid_locations_corrected,normalized_maximal_distance);
  775. % saving the results into the data struct for the GUI
  776. data_struct.all_to_all_indexes=all_to_all_indexes;
  777. data_struct.all_to_all_spatial_correlations=all_to_all_spatial_correlations;
  778. data_struct.all_to_all_centroid_distances=all_to_all_centroid_distances;
  779. data_struct.neighbors_spatial_correlations=neighbors_spatial_correlations;
  780. data_struct.neighbors_centroid_distances=neighbors_centroid_distances;
  781. data_struct.neighbors_x_displacements=neighbors_x_displacements;
  782. data_struct.neighbors_y_displacements=neighbors_y_displacements;
  783. data_struct.NN_spatial_correlations=NN_spatial_correlations;
  784. data_struct.NNN_spatial_correlations=NNN_spatial_correlations;
  785. data_struct.NN_centroid_distances=NN_centroid_distances;
  786. data_struct.NNN_centroid_distances=NNN_centroid_distances;
  787. % saving the results into the modeled data structure:
  788. modeled_data_struct.all_to_all_indexes=all_to_all_indexes;
  789. modeled_data_struct.all_to_all_spatial_correlations=all_to_all_spatial_correlations;
  790. modeled_data_struct.all_to_all_centroid_distances=all_to_all_centroid_distances;
  791. modeled_data_struct.neighbors_spatial_correlations=neighbors_spatial_correlations;
  792. modeled_data_struct.neighbors_centroid_distances=neighbors_centroid_distances;
  793. modeled_data_struct.neighbors_x_displacements=neighbors_x_displacements;
  794. modeled_data_struct.neighbors_y_displacements=neighbors_y_displacements;
  795. modeled_data_struct.NN_spatial_correlations=NN_spatial_correlations;
  796. modeled_data_struct.NNN_spatial_correlations=NNN_spatial_correlations;
  797. modeled_data_struct.NN_centroid_distances=NN_centroid_distances;
  798. modeled_data_struct.NNN_centroid_distances=NNN_centroid_distances;
  799. handles.data_struct=data_struct;
  800. guidata(hObject, handles)
  801. % Plotting the (x,y) displacements:
  802. x_y_displacements=plot_x_y_displacements(neighbors_x_displacements,neighbors_y_displacements,microns_per_pixel,normalized_maximal_distance,number_of_bins,centers_of_bins,figures_directory,figures_visibility);
  803. axes(handles.axes2)
  804. plot_x_y_displacements_GUI(x_y_displacements,microns_per_pixel,centers_of_bins,normalized_maximal_distance,number_of_bins)
  805. disp('Calculating a probabilistic model of the data')
  806. % Modeling the distribution of centroid distances:
  807. [centroid_distances_model_parameters,p_same_given_centroid_distance,centroid_distances_distribution,centroid_distances_model_same_cells,centroid_distances_model_different_cells,centroid_distances_model_weighted_sum,MSE_centroid_distances_model,centroid_distance_intersection]=...
  808. compute_centroid_distances_model(neighbors_centroid_distances,microns_per_pixel,centers_of_bins);
  809. % Modeling the distribution of spatial correlations:
  810. [spatial_correlations_model_parameters,p_same_given_spatial_correlation,spatial_correlations_distribution,spatial_correlations_model_same_cells,spatial_correlations_model_different_cells,spatial_correlations_model_weighted_sum,MSE_spatial_correlations_model,spatial_correlation_intersection]=...
  811. compute_spatial_correlations_model(neighbors_spatial_correlations,centers_of_bins);
  812. % estimating registration accuracy:
  813. [p_same_centers_of_bins,uncertain_fraction_centroid_distances,cdf_p_same_centroid_distances,false_positive_per_distance_threshold,true_positive_per_distance_threshold,uncertain_fraction_spatial_correlations,cdf_p_same_spatial_correlations,false_positive_per_correlation_threshold,true_positive_per_correlation_threshold]=...
  814. estimate_registration_accuracy(p_same_certainty_threshold,neighbors_centroid_distances,centroid_distances_model_same_cells,centroid_distances_model_different_cells,p_same_given_centroid_distance,centers_of_bins,neighbors_spatial_correlations,spatial_correlations_model_same_cells,spatial_correlations_model_different_cells,p_same_given_spatial_correlation);
  815. % Checking which model is better according to a defined cost function:
  816. [best_model_string]=choose_best_model(MSE_centroid_distances_model,centroid_distances_model_same_cells,centroid_distances_model_different_cells,p_same_given_centroid_distance,MSE_spatial_correlations_model,spatial_correlations_model_same_cells,spatial_correlations_model_different_cells,p_same_given_spatial_correlation);
  817. % change the initial and final registration according to the best model:
  818. if strcmp(best_model_string,'Spatial correlation')
  819. set(handles.spatial_correlations,'Value',1);
  820. set(handles.spatial_correlations_2,'Value',1);
  821. set(handles.distance_threshold,'enable','off')
  822. set(handles.correlation_threshold,'enable','on')
  823. else
  824. set(handles.centroid_distances,'Value',1);
  825. set(handles.centroid_distances_2,'Value',1);
  826. set(handles.correlation_threshold,'enable','off')
  827. set(handles.distance_threshold,'enable','on')
  828. end
  829. % Plotting the probabilistic models and estimated registration accuracy:
  830. plot_models(centroid_distances_model_parameters,NN_centroid_distances,NNN_centroid_distances,centroid_distances_distribution,centroid_distances_model_same_cells,centroid_distances_model_different_cells,centroid_distances_model_weighted_sum,centroid_distance_intersection,centers_of_bins,microns_per_pixel,normalized_maximal_distance,figures_directory,figures_visibility,spatial_correlations_model_parameters,NN_spatial_correlations,NNN_spatial_correlations,spatial_correlations_distribution,spatial_correlations_model_same_cells,spatial_correlations_model_different_cells,spatial_correlations_model_weighted_sum,spatial_correlation_intersection)
  831. plot_estimated_registration_accuracy(p_same_centers_of_bins,p_same_certainty_threshold,p_same_given_centroid_distance,centroid_distances_distribution,cdf_p_same_centroid_distances,uncertain_fraction_centroid_distances,true_positive_per_distance_threshold,false_positive_per_distance_threshold,centers_of_bins,normalized_maximal_distance,microns_per_pixel,figures_directory,figures_visibility,p_same_given_spatial_correlation,spatial_correlations_distribution,cdf_p_same_spatial_correlations,uncertain_fraction_spatial_correlations,true_positive_per_correlation_threshold,false_positive_per_correlation_threshold)
  832. plot_estimated_accuracy_GUI(handles,p_same_centers_of_bins,p_same_certainty_threshold,p_same_given_centroid_distance,centroid_distances_distribution,cdf_p_same_centroid_distances,true_positive_per_distance_threshold,false_positive_per_distance_threshold,centers_of_bins,normalized_maximal_distance,microns_per_pixel,p_same_given_spatial_correlation,spatial_correlations_distribution,cdf_p_same_spatial_correlations,true_positive_per_correlation_threshold,false_positive_per_correlation_threshold)
  833. % Computing the P_same for each neighboring cell-pair according to the different models:
  834. [all_to_all_p_same_centroid_distance_model,all_to_all_p_same_spatial_correlation_model]=...
  835. compute_p_same(all_to_all_centroid_distances,p_same_given_centroid_distance,centers_of_bins,all_to_all_spatial_correlations,p_same_given_spatial_correlation);
  836. % saving the results into the data struct for GUI:
  837. data_struct.best_model_string=best_model_string;
  838. data_struct.maximal_distance=maximal_distance;
  839. data_struct.number_of_bins=number_of_bins;
  840. data_struct.centers_of_bins=centers_of_bins;
  841. data_struct.false_positive_per_distance_threshold=false_positive_per_distance_threshold;
  842. data_struct.true_positive_per_distance_threshold=true_positive_per_distance_threshold;
  843. data_struct.cdf_p_same_centroid_distances=cdf_p_same_centroid_distances;
  844. data_struct.uncertain_fraction_centroid_distances=uncertain_fraction_centroid_distances;
  845. data_struct.p_same_given_centroid_distance=p_same_given_centroid_distance;
  846. data_struct.neighbors_centroid_distances=neighbors_centroid_distances;
  847. data_struct.MSE_centroid_distances_model=MSE_centroid_distances_model;
  848. data_struct.centroid_distances_model_parameters=centroid_distances_model_parameters;
  849. data_struct.centroid_distances_distribution=centroid_distances_distribution;
  850. data_struct.centroid_distance_intersection=centroid_distance_intersection;
  851. data_struct.all_to_all_p_same_centroid_distance_model=all_to_all_p_same_centroid_distance_model;
  852. % saving the results into the modeled data structure:
  853. modeled_data_struct.best_model_string=best_model_string;
  854. modeled_data_struct.maximal_distance=maximal_distance;
  855. modeled_data_struct.number_of_bins=number_of_bins;
  856. modeled_data_struct.centers_of_bins=centers_of_bins;
  857. modeled_data_struct.false_positive_per_distance_threshold=false_positive_per_distance_threshold;
  858. modeled_data_struct.true_positive_per_distance_threshold=true_positive_per_distance_threshold;
  859. modeled_data_struct.cdf_p_same_centroid_distances=cdf_p_same_centroid_distances;
  860. modeled_data_struct.uncertain_fraction_centroid_distances=uncertain_fraction_centroid_distances;
  861. modeled_data_struct.p_same_given_centroid_distance=p_same_given_centroid_distance;
  862. modeled_data_struct.neighbors_centroid_distances=neighbors_centroid_distances;
  863. modeled_data_struct.MSE_centroid_distances_model=MSE_centroid_distances_model;
  864. modeled_data_struct.centroid_distances_model_parameters=centroid_distances_model_parameters;
  865. modeled_data_struct.centroid_distances_distribution=centroid_distances_distribution;
  866. modeled_data_struct.centroid_distance_intersection=centroid_distance_intersection;
  867. modeled_data_struct.all_to_all_p_same_centroid_distance_model=all_to_all_p_same_centroid_distance_model;
  868. data_struct.false_positive_per_correlation_threshold=false_positive_per_correlation_threshold;
  869. data_struct.true_positive_per_correlation_threshold=true_positive_per_correlation_threshold;
  870. data_struct.cdf_p_same_spatial_correlations=cdf_p_same_spatial_correlations;
  871. data_struct.uncertain_fraction_spatial_correlations=uncertain_fraction_spatial_correlations;
  872. data_struct.all_to_all_spatial_correlations=all_to_all_spatial_correlations;
  873. data_struct.MSE_spatial_correlations_model=MSE_spatial_correlations_model;
  874. data_struct.spatial_correlations_model_parameters=spatial_correlations_model_parameters;
  875. data_struct.p_same_given_spatial_correlation=p_same_given_spatial_correlation;
  876. data_struct.spatial_correlations_distribution=spatial_correlations_distribution;
  877. data_struct.spatial_correlation_intersection=spatial_correlation_intersection;
  878. data_struct.all_to_all_p_same_spatial_correlation_model=all_to_all_p_same_spatial_correlation_model;
  879. % saving the results into the modeled data structure:
  880. modeled_data_struct.false_positive_per_correlation_threshold=false_positive_per_correlation_threshold;
  881. modeled_data_struct.true_positive_per_correlation_threshold=true_positive_per_correlation_threshold;
  882. modeled_data_struct.cdf_p_same_spatial_correlations=cdf_p_same_spatial_correlations;
  883. modeled_data_struct.uncertain_fraction_spatial_correlations=uncertain_fraction_spatial_correlations;
  884. modeled_data_struct.all_to_all_spatial_correlations=all_to_all_spatial_correlations;
  885. modeled_data_struct.MSE_spatial_correlations_model=MSE_spatial_correlations_model;
  886. modeled_data_struct.spatial_correlations_model_parameters=spatial_correlations_model_parameters;
  887. modeled_data_struct.p_same_given_spatial_correlation=p_same_given_spatial_correlation;
  888. modeled_data_struct.spatial_correlations_distribution=spatial_correlations_distribution;
  889. modeled_data_struct.spatial_correlation_intersection=spatial_correlation_intersection;
  890. modeled_data_struct.all_to_all_p_same_spatial_correlation_model=all_to_all_p_same_spatial_correlation_model;
  891. % setting the intersection point as the threshold
  892. set(handles.correlation_threshold,'string',num2str(spatial_correlation_intersection))
  893. set(handles.distance_threshold,'string',num2str(centroid_distance_intersection))
  894. handles.data_struct=data_struct;
  895. disp('Saving the modeled data structure')
  896. save(fullfile(results_directory,'modeled_data_struct.mat'),'modeled_data_struct','-v7.3')
  897. guidata(hObject, handles)
  898. disp('Done')
  899. msgbox_timed(['Finished computing probabilistic model - The ' best_model_string ' model is best suited for the data'],3)
  900. % --- Executes on button press in register_cells_initial.
  901. function register_cells_initial_Callback(hObject,~,handles)
  902. % hObject handle to register_cells_initial (see GCBO)
  903. % eventdata reserved - to be defined in a future version of MATLAB
  904. % handles struct with handles and user data (see GUIDATA)
  905. % Stage 4: Obtaining an initial cell registration according to an optimized
  906. % registration threshold.
  907. % This callback performs initial cell registration according to either
  908. % spatial correlations or centroid distances:
  909. data_struct=handles.data_struct;
  910. microns_per_pixel=data_struct.microns_per_pixel;
  911. spatial_footprints_corrected=data_struct.spatial_footprints_corrected;
  912. centroid_locations_corrected=data_struct.centroid_locations_corrected;
  913. normalized_maximal_distance=data_struct.maximal_distance/microns_per_pixel;
  914. number_of_bins=data_struct.number_of_bins;
  915. figures_directory=data_struct.figures_directory;
  916. if get(handles.figures_visibility_on,'Value');
  917. figures_visibility='On';
  918. else
  919. figures_visibility='Off';
  920. end
  921. % Computing the initial registration according to a simple threshold:
  922. if get(handles.spatial_correlations,'Value')==1 % if spatial correlations are used
  923. initial_registration_type='Spatial correlation';
  924. initial_threshold=str2num(get(handles.correlation_threshold,'string'));
  925. [cell_to_index_map,registered_cells_spatial_correlations,non_registered_cells_spatial_correlations]=...
  926. initial_registration_spatial_correlations(normalized_maximal_distance,initial_threshold,spatial_footprints_corrected,centroid_locations_corrected);
  927. plot_initial_registration(cell_to_index_map,number_of_bins,spatial_footprints_corrected,initial_registration_type,figures_directory,figures_visibility,registered_cells_spatial_correlations,non_registered_cells_spatial_correlations)
  928. else
  929. initial_registration_type='Centroid distances';
  930. initial_threshold=str2num(get(handles.distance_threshold,'string'));
  931. centroid_distances_distribution_threshold=initial_threshold/microns_per_pixel;
  932. [cell_to_index_map,registered_cells_centroid_distances,non_registered_cells_centroid_distances]=...
  933. initial_registration_centroid_distances(normalized_maximal_distance,centroid_distances_distribution_threshold,centroid_locations_corrected);
  934. plot_initial_registration(cell_to_index_map,number_of_bins,spatial_footprints_corrected,initial_registration_type,figures_directory,figures_visibility,registered_cells_centroid_distances,non_registered_cells_centroid_distances,microns_per_pixel,normalized_maximal_distance)
  935. end
  936. disp([num2str(size(cell_to_index_map,1)) ' cells were found'])
  937. disp('Done')
  938. data_struct.initial_registration_type=initial_registration_type;
  939. data_struct.cell_to_index_map=cell_to_index_map;
  940. data_struct.initial_threshold=initial_threshold;
  941. data_struct.initial_registration_type=initial_registration_type;
  942. handles.data_struct=data_struct;
  943. guidata(hObject, handles)
  944. msgbox_timed(['Finished performing initial cell registration - ' num2str(size(cell_to_index_map,1)) ' were found'],3)
  945. % --- Executes on button press in register_cells_final.
  946. function register_cells_final_Callback(hObject,~, handles)
  947. % hObject handle to register_cells_final (see GCBO)
  948. % eventdata reserved - to be defined in a future version of MATLAB
  949. % handles struct with handles and user data (see GUIDATA)
  950. % Stage 5: Obtaining the final cell registration based on a correlation clustering algorithm.
  951. % This callback performs the final cell registration according to the
  952. % probability model for same cells and different cells. P_same can be
  953. % either according to centroid distances, spatial correlations or both:
  954. data_struct=handles.data_struct;
  955. if ~isfield(data_struct,'cell_to_index_map')
  956. errordlg('Final registration cannot be performed before initial registration')
  957. error('Final registration cannot be performed before initial registration')
  958. end
  959. if get(handles.spatial_correlations_2,'Value')==1
  960. if isfield(data_struct,'all_to_all_p_same_spatial_correlation_model')
  961. all_to_all_p_same_spatial_correlation_model=data_struct.all_to_all_p_same_spatial_correlation_model;
  962. all_to_all_indexes=data_struct.all_to_all_indexes;
  963. all_to_all_spatial_correlations=data_struct.all_to_all_spatial_correlations;
  964. else
  965. errordlg('Please compute the spatial correlations probability model before performing final cell registration')
  966. error('Please compute the spatial correlations probability model before performing final cell registration')
  967. end
  968. elseif get(handles.centroid_distances_2,'Value')==1
  969. if isfield(data_struct,'all_to_all_p_same_centroid_distance_model')
  970. all_to_all_p_same_centroid_distance_model=data_struct.all_to_all_p_same_centroid_distance_model;
  971. all_to_all_indexes=data_struct.all_to_all_indexes;
  972. all_to_all_centroid_distances=data_struct.all_to_all_centroid_distances;
  973. end
  974. end
  975. results_directory=data_struct.results_directory;
  976. figures_directory=data_struct.figures_directory;
  977. overlapping_FOV=data_struct.overlapping_FOV;
  978. cell_to_index_map=data_struct.cell_to_index_map;
  979. centroid_locations_corrected=data_struct.centroid_locations_corrected;
  980. spatial_footprints_corrected=data_struct.spatial_footprints_corrected;
  981. number_of_sessions=data_struct.number_of_sessions;
  982. microns_per_pixel=data_struct.microns_per_pixel;
  983. maximal_distance=data_struct.maximal_distance;
  984. normalized_maximal_distance=maximal_distance/microns_per_pixel;
  985. if get(handles.figures_visibility_on,'Value');
  986. figures_visibility='On';
  987. else
  988. figures_visibility='Off';
  989. end
  990. if get(handles.spatial_correlations_2,'Value')==1;
  991. model_type='Spatial correlation';
  992. else
  993. model_type='Centroid distance';
  994. end
  995. transform_data=false;
  996. if get(handles.use_model,'Value')==1;
  997. p_same_threshold=str2num(get(handles.decision_thresh,'string'));
  998. final_threshold=p_same_threshold;
  999. registration_approach='Probabilistic';
  1000. else
  1001. registration_approach='Simple threshold';
  1002. if strcmp(model_type,'Spatial correlation')
  1003. final_threshold=str2num(get(handles.simple_correlation_threshold,'string'));
  1004. elseif strcmp(model_type,'Centroid distance')
  1005. final_threshold=str2num(get(handles.simple_distance_threshold,'string'));
  1006. centroid_distances_distribution_threshold=(maximal_distance-final_threshold)/maximal_distance;
  1007. transform_data=true;
  1008. end
  1009. end
  1010. data_struct.final_threshold=final_threshold;
  1011. data_struct.registration_approach=registration_approach;
  1012. data_struct.model_type=model_type;
  1013. % Registering the cells with the clustering algorithm:
  1014. disp('Stage 5 - Performing final registration')
  1015. if strcmp(registration_approach,'Probabilistic')
  1016. if strcmp(model_type,'Spatial correlation')
  1017. [optimal_cell_to_index_map,registered_cells_centroids,cell_scores,cell_scores_positive,cell_scores_negative,cell_scores_exclusive,p_same_registered_pairs]=...
  1018. cluster_cells(cell_to_index_map,all_to_all_p_same_spatial_correlation_model,all_to_all_indexes,normalized_maximal_distance,p_same_threshold,centroid_locations_corrected,registration_approach,transform_data);
  1019. elseif strcmp(model_type,'Centroid distance')
  1020. [optimal_cell_to_index_map,registered_cells_centroids,cell_scores,cell_scores_positive,cell_scores_negative,cell_scores_exclusive,p_same_registered_pairs]=...
  1021. cluster_cells(cell_to_index_map,all_to_all_p_same_centroid_distance_model,all_to_all_indexes,normalized_maximal_distance,p_same_threshold,centroid_locations_corrected,registration_approach,transform_data);
  1022. end
  1023. plot_cell_scores(cell_scores_positive,cell_scores_negative,cell_scores_exclusive,cell_scores,p_same_registered_pairs,figures_directory,figures_visibility)
  1024. elseif strcmp(registration_approach,'Simple threshold')
  1025. if strcmp(model_type,'Spatial correlation')
  1026. [optimal_cell_to_index_map,registered_cells_centroids]=...
  1027. cluster_cells(cell_to_index_map,all_to_all_spatial_correlations,all_to_all_indexes,normalized_maximal_distance,final_threshold,centroid_locations_corrected,registration_approach,transform_data);
  1028. elseif strcmp(model_type,'Centroid distance')
  1029. [optimal_cell_to_index_map,registered_cells_centroids]=...
  1030. cluster_cells(cell_to_index_map,all_to_all_centroid_distances,all_to_all_indexes,normalized_maximal_distance,centroid_distances_distribution_threshold,centroid_locations_corrected,registration_approach,transform_data);
  1031. end
  1032. end
  1033. [is_in_overlapping_FOV]=check_if_in_overlapping_FOV(registered_cells_centroids,overlapping_FOV);
  1034. % Plotting the registration results with the cell maps from all sessions:
  1035. plot_all_registered_projections(spatial_footprints_corrected,optimal_cell_to_index_map,figures_directory,figures_visibility)
  1036. % saving the clustering results:
  1037. disp('Saving the results')
  1038. cell_registered_struct=struct;
  1039. cell_registered_struct.cell_to_index_map=optimal_cell_to_index_map;
  1040. if strcmp(registration_approach,'Probabilistic');
  1041. cell_registered_struct.cell_scores=cell_scores';
  1042. cell_registered_struct.true_positive_scores=cell_scores_positive';
  1043. cell_registered_struct.true_negative_scores=cell_scores_negative';
  1044. cell_registered_struct.exclusivity_scores=cell_scores_exclusive';
  1045. cell_registered_struct.p_same_registered_pairs=p_same_registered_pairs';
  1046. end
  1047. cell_registered_struct.is_cell_in_overlapping_FOV=is_in_overlapping_FOV';
  1048. cell_registered_struct.registered_cells_centroids=registered_cells_centroids';
  1049. cell_registered_struct.centroid_locations_corrected=centroid_locations_corrected';
  1050. cell_registered_struct.spatial_footprints_corrected=spatial_footprints_corrected';
  1051. cell_registered_struct.alignment_x_translations=data_struct.alignment_translations(1,:);
  1052. cell_registered_struct.alignment_y_translations=data_struct.alignment_translations(2,:);
  1053. if strcmp(data_struct.alignment_type,'Translations and Rotations')
  1054. cell_registered_struct.alignment_rotations=data_struct.alignment_translations(3,:);
  1055. end
  1056. cell_registered_struct.adjustment_x_zero_padding=data_struct.adjustment_zero_padding(1,:);
  1057. cell_registered_struct.adjustment_y_zero_padding=data_struct.adjustment_zero_padding(2,:);
  1058. save(fullfile(results_directory,['cellRegistered_' datestr(clock,'yyyymmdd_HHMMss') '.mat']),'cell_registered_struct','-v7.3')
  1059. % Saving a log file with all the chosen parameters:
  1060. comments=get(handles.comments,'string');
  1061. file_names=data_struct.file_names;
  1062. adjusted_x_size=data_struct.adjusted_x_size;
  1063. adjusted_y_size=data_struct.adjusted_y_size;
  1064. alignment_type=data_struct.alignment_type;
  1065. reference_session_index=data_struct.reference_session_index;
  1066. number_of_bins=data_struct.number_of_bins;
  1067. initial_registration_type=data_struct.initial_registration_type;
  1068. initial_threshold=data_struct.initial_threshold;
  1069. if strcmp(registration_approach,'Probabilistic')
  1070. if strcmp(model_type,'Spatial correlation')
  1071. uncertain_fraction_spatial_correlations=data_struct.uncertain_fraction_spatial_correlations;
  1072. false_positive_per_correlation_threshold=data_struct.false_positive_per_correlation_threshold;
  1073. true_positive_per_correlation_threshold=data_struct.true_positive_per_correlation_threshold;
  1074. MSE_spatial_correlations_model=data_struct.MSE_spatial_correlations_model;
  1075. save_log_file(results_directory,file_names,microns_per_pixel,adjusted_x_size,adjusted_y_size,alignment_type,reference_session_index,maximal_distance,number_of_bins,initial_registration_type,initial_threshold,registration_approach,model_type,final_threshold,optimal_cell_to_index_map,cell_registered_struct,comments,uncertain_fraction_spatial_correlations,false_positive_per_correlation_threshold,true_positive_per_correlation_threshold,MSE_spatial_correlations_model)
  1076. elseif strcmp(model_type,'Centroid distance')
  1077. uncertain_fraction_centroid_distances=data_struct.uncertain_fraction_centroid_distances;
  1078. false_positive_per_distance_threshold=data_struct.false_positive_per_distance_threshold;
  1079. true_positive_per_distance_threshold=data_struct.true_positive_per_distance_threshold;
  1080. MSE_centroid_distances_model=data_struct.MSE_centroid_distances_model;
  1081. save_log_file(results_directory,file_names,microns_per_pixel,adjusted_x_size,adjusted_y_size,alignment_type,reference_session_index,maximal_distance,number_of_bins,initial_registration_type,initial_threshold,registration_approach,model_type,final_threshold,optimal_cell_to_index_map,cell_registered_struct,comments,uncertain_fraction_centroid_distances,false_positive_per_distance_threshold,true_positive_per_distance_threshold,MSE_centroid_distances_model)
  1082. end
  1083. elseif strcmp(registration_approach,'Simple threshold')
  1084. if strcmp(model_type,'Spatial correlation')
  1085. save_log_file(results_directory,file_names,microns_per_pixel,adjusted_x_size,adjusted_y_size,alignment_type,reference_session_index,maximal_distance,number_of_bins,initial_registration_type,initial_threshold,registration_approach,model_type,final_threshold,optimal_cell_to_index_map,cell_registered_struct,comments)
  1086. elseif strcmp(model_type,'Centroid distance')
  1087. save_log_file(results_directory,file_names,microns_per_pixel,adjusted_x_size,adjusted_y_size,alignment_type,reference_session_index,maximal_distance,number_of_bins,initial_registration_type,initial_threshold,registration_approach,model_type,final_threshold,optimal_cell_to_index_map,cell_registered_struct,comments)
  1088. end
  1089. end
  1090. if ~isempty(data_struct.temp_dir)
  1091. for file_n = 1:length(spatial_footprints_corrected)
  1092. split_name = strsplit(spatial_footprints_corrected{file_n},filesep);
  1093. f_name = split_name{end};
  1094. footprints = get_spatial_footprints(spatial_footprints_corrected{file_n});
  1095. footprints = footprints.load_footprints;
  1096. footprints = footprints.footprints;
  1097. footprint = mat_to_sparse_cell(footprints);
  1098. spatial_footprints_corrected{file_n} = fullfile(results_directory,f_name);
  1099. save(fullfile(results_directory,f_name),'footprint');
  1100. end
  1101. rmdir(data_struct.temp_dir,'s');
  1102. end
  1103. disp([num2str(size(optimal_cell_to_index_map,1)) ' cells were found'])
  1104. disp('End of cell registration procedure')
  1105. handles.data_struct=data_struct;
  1106. guidata(hObject, handles)
  1107. msgbox_timed(['Finished performing final cell registration - ' num2str(size(optimal_cell_to_index_map,1)) ' were found'],3)
  1108. % --- Executes on button press in reset.
  1109. function reset_Callback(hObject,~, handles)
  1110. % hObject handle to reset (see GCBO)
  1111. % eventdata reserved - to be defined in a future version of MATLAB
  1112. % handles struct with handles and user data (see GUIDATA)
  1113. % defining data struct:
  1114. guidata(hObject, handles);
  1115. data_struct=struct;
  1116. data_struct.sessions_list=[];
  1117. % Reseting Figures and GUI parameters:
  1118. cla(handles.axes1,'reset')
  1119. axes(handles.axes1);
  1120. plot([],[])
  1121. set(gca,'xtick',[])
  1122. set(gca,'ytick',[])
  1123. cla(handles.axes2,'reset')
  1124. axes(handles.axes2);
  1125. plot([],[])
  1126. set(gca,'xtick',[])
  1127. set(gca,'ytick',[])
  1128. cla(handles.axes3,'reset')
  1129. axes(handles.axes3);
  1130. plot([],[])
  1131. set(gca,'xtick',[])
  1132. set(gca,'ytick',[])
  1133. cla(handles.axes4,'reset')
  1134. axes(handles.axes4);
  1135. plot([],[])
  1136. set(gca,'xtick',[])
  1137. set(gca,'ytick',[])
  1138. cla(handles.axes5,'reset')
  1139. axes(handles.axes5);
  1140. plot([],[])
  1141. set(gca,'xtick',[])
  1142. set(gca,'ytick',[])
  1143. cla(handles.axes6,'reset')
  1144. axes(handles.axes6);
  1145. plot([],[])
  1146. set(gca,'xtick',[])
  1147. set(gca,'ytick',[])
  1148. set(handles.list_of_sessions,'value',1)
  1149. set(handles.list_of_sessions,'string',[]);
  1150. set(handles.red_session,'string','1')
  1151. set(handles.green_session,'string','2')
  1152. set(handles.blue_session,'string','3')
  1153. set(handles.decision_thresh,'string','0.5')
  1154. set(handles.initial_p_same_slider,'value',0.5);
  1155. set(handles.initial_p_same_threshold,'string','0.5');
  1156. set(handles.final_p_same_slider,'value',0.5);
  1157. set(handles.model_maximal_distance,'string','14')
  1158. set(handles.distance_threshold,'string','5')
  1159. set(handles.correlation_threshold,'string','0.65')
  1160. set(handles.simple_distance_threshold,'string','5')
  1161. set(handles.simple_correlation_threshold,'string','0.65')
  1162. set(handles.figures_visibility_on,'Value',1);
  1163. set(handles.translations_rotations,'Value',1);
  1164. set(handles.spatial_correlations_2,'Value',1);
  1165. set(handles.use_model,'Value',1);
  1166. set(handles.spatial_correlations,'Value',1);
  1167. set(handles.microns_per_pixel,'value',0)
  1168. set(handles.microns_per_pixel,'string',[])
  1169. set(handles.microns_per_pixel,'backgroundColor',[1 1 1]);
  1170. set(handles.reference_session_index,'string','1')
  1171. set(handles.maximal_rotation','string','30')
  1172. set(handles.maximal_rotation','enable','on')
  1173. set(handles.transformation_smoothness,'string','2')
  1174. set(handles.transformation_smoothness,'enable','off')
  1175. set(handles.distance_threshold,'enable','off')
  1176. set(handles.correlation_threshold,'enable','on')
  1177. set(handles.simple_distance_threshold,'enable','off')
  1178. set(handles.simple_correlation_threshold,'enable','off')
  1179. set(handles.comments,'string',[])
  1180. handles.data_struct=data_struct;
  1181. guidata(hObject, handles)
  1182. % --- Executes during object creation, after setting all properties.
  1183. function correlation_threshold_CreateFcn(~,hObject,~)
  1184. % hObject handle to correlation_threshold (see GCBO)
  1185. % eventdata reserved - to be defined in a future version of MATLAB
  1186. % handles empty - handles not created until after all CreateFcns called
  1187. % Hint: edit controls usually have a white background on Windows.
  1188. % See ISPC and COMPUTER.
  1189. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1190. set(hObject,'BackgroundColor','white');
  1191. end
  1192. % --- Executes during object creation, after setting all properties.
  1193. function distance_threshold_CreateFcn(hObject,~,~)
  1194. % hObject handle to distance_threshold (see GCBO)
  1195. % eventdata reserved - to be defined in a future version of MATLAB
  1196. % handles empty - handles not created until after all CreateFcns called
  1197. % Hint: edit controls usually have a white background on Windows.
  1198. % See ISPC and COMPUTER.
  1199. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1200. set(hObject,'BackgroundColor','white');
  1201. end
  1202. % --- Executes during object creation, after setting all properties.
  1203. function list_of_sessions_CreateFcn(hObject, ~,~)
  1204. % hObject handle to list_of_sessions (see GCBO)
  1205. % eventdata reserved - to be defined in a future version of MATLAB
  1206. % handles empty - handles not created until after all CreateFcns called
  1207. % Hint: listbox controls usually have a white background on Windows.
  1208. % See ISPC and COMPUTER.
  1209. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1210. set(hObject,'BackgroundColor','white');
  1211. end
  1212. % --- Executes during object creation, after setting all properties.
  1213. function maximal_distance_CreateFcn(hObject,~,~)
  1214. % hObject handle to maximal_distance (see GCBO)
  1215. % eventdata reserved - to be defined in a future version of MATLAB
  1216. % handles empty - handles not created until after all CreateFcns called
  1217. % Hint: edit controls usually have a white background on Windows.
  1218. % See ISPC and COMPUTER.
  1219. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1220. set(hObject,'BackgroundColor','white');
  1221. end
  1222. % --- Executes during object creation, after setting all properties.
  1223. function number_of_bins_CreateFcn(hObject,~,~)
  1224. % hObject handle to number_of_bins (see GCBO)
  1225. % eventdata reserved - to be defined in a future version of MATLAB
  1226. % handles empty - handles not created until after all CreateFcns called
  1227. % Hint: edit controls usually have a white background on Windows.
  1228. % See ISPC and COMPUTER.
  1229. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1230. set(hObject,'BackgroundColor','white');
  1231. end
  1232. % --- Executes during object creation, after setting all properties.
  1233. function compute_model_CreateFcn(~,~,~)
  1234. % hObject handle to compute_model (see GCBO)
  1235. % eventdata reserved - to be defined in a future version of MATLAB
  1236. % handles empty - handles not created until after all CreateFcns called
  1237. % --- Executes during object creation, after setting all properties.
  1238. function transformation_type_CreateFcn(~,~,~)
  1239. % hObject handle to transformation_type (see GCBO)
  1240. % eventdata reserved - to be defined in a future version of MATLAB
  1241. % handles empty - handles not created until after all CreateFcns called
  1242. function microns_per_pixel_Callback(~,~, handles)
  1243. % hObject handle to microns_per_pixel (see GCBO)
  1244. % eventdata reserved - to be defined in a future version of MATLAB
  1245. % handles struct with handles and user data (see GUIDATA)
  1246. % Hints: get(hObject,'String') returns contents of microns_per_pixel as text
  1247. % str2num(get(hObject,'String')) returns contents of microns_per_pixel as a double
  1248. microns_per_pixel=get(handles.microns_per_pixel,'string');
  1249. if ~isempty(microns_per_pixel)
  1250. set(handles.microns_per_pixel,'value',1)
  1251. end
  1252. % --- Executes during object creation, after setting all properties.
  1253. function microns_per_pixel_CreateFcn(hObject,~,~)
  1254. % hObject handle to microns_per_pixel (see GCBO)
  1255. % eventdata reserved - to be defined in a future version of MATLAB
  1256. % handles empty - handles not created until after all CreateFcns called
  1257. % Hint: edit controls usually have a white background on Windows.
  1258. % See ISPC and COMPUTER.
  1259. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1260. set(hObject,'BackgroundColor','white');
  1261. end
  1262. function reference_session_index_Callback(~,~, handles)
  1263. % hObject handle to reference_session_index (see GCBO)
  1264. % eventdata reserved - to be defined in a future version of MATLAB
  1265. % handles struct with handles and user data (see GUIDATA)
  1266. % Hints: get(hObject,'String') returns contents of reference_session_index as text
  1267. % str2num(get(hObject,'String')) returns contents of reference_session_index as a double
  1268. reference_session_index=get(handles.reference_session_index,'string');
  1269. if ~isempty(reference_session_index)
  1270. set(handles.reference_session_index,'value',1)
  1271. end
  1272. % --- Executes during object creation, after setting all properties.
  1273. function reference_session_index_CreateFcn(hObject, ~, ~)
  1274. % hObject handle to reference_session_index (see GCBO)
  1275. % eventdata reserved - to be defined in a future version of MATLAB
  1276. % handles empty - handles not created until after all CreateFcns called
  1277. % Hint: edit controls usually have a white background on Windows.
  1278. % See ISPC and COMPUTER.
  1279. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1280. set(hObject,'BackgroundColor','white');
  1281. end
  1282. % --- Executes during object creation, after setting all properties.
  1283. function model_maximal_distance_CreateFcn(hObject,~,~)
  1284. % hObject handle to model_maximal_distance (see GCBO)
  1285. % eventdata reserved - to be defined in a future version of MATLAB
  1286. % handles empty - handles not created until after all CreateFcns called
  1287. % Hint: edit controls usually have a white background on Windows.
  1288. % See ISPC and COMPUTER.
  1289. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1290. set(hObject,'BackgroundColor','white');
  1291. end
  1292. % --- Executes during object creation, after setting all properties.
  1293. function cluster_maximal_distance_CreateFcn(hObject,~,~)
  1294. % hObject handle to cluster_maximal_distance (see GCBO)
  1295. % eventdata reserved - to be defined in a future version of MATLAB
  1296. % handles empty - handles not created until after all CreateFcns called
  1297. % Hint: edit controls usually have a white background on Windows.
  1298. % See ISPC and COMPUTER.
  1299. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1300. set(hObject,'BackgroundColor','white');
  1301. end
  1302. % --- Executes during object creation, after setting all properties.
  1303. function max_iterations_CreateFcn(hObject,~,~)
  1304. % hObject handle to max_iterations (see GCBO)
  1305. % eventdata reserved - to be defined in a future version of MATLAB
  1306. % handles empty - handles not created until after all CreateFcns called
  1307. % Hint: edit controls usually have a white background on Windows.
  1308. % See ISPC and COMPUTER.
  1309. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1310. set(hObject,'BackgroundColor','white');
  1311. end
  1312. % --- Executes during object creation, after setting all properties.
  1313. function decision_thresh_CreateFcn(hObject,~,~)
  1314. % hObject handle to decision_thresh (see GCBO)
  1315. % eventdata reserved - to be defined in a future version of MATLAB
  1316. % handles empty - handles not created until after all CreateFcns called
  1317. % Hint: edit controls usually have a white background on Windows.
  1318. % See ISPC and COMPUTER.
  1319. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1320. set(hObject,'BackgroundColor','white');
  1321. end
  1322. function load_Callback(~,~,~)
  1323. % hObject handle to load (see GCBO)
  1324. % eventdata reserved - to be defined in a future version of MATLAB
  1325. % handles struct with handles and user data (see GUIDATA)
  1326. % --- Executes on selection change in list_of_sessions.
  1327. function list_of_sessions_Callback(hObject, eventdata, handles)
  1328. % hObject handle to list_of_sessions (see GCBO)
  1329. % eventdata reserved - to be defined in a future version of MATLAB
  1330. % handles struct with handles and user data (see GUIDATA)
  1331. % Hints: contents = cellstr(get(hObject,'String')) returns list_of_sessions contents as cell array
  1332. % contents{get(hObject,'Value')} returns selected item from list_of_sessions
  1333. function model_maximal_distance_Callback(hObject, eventdata, handles)
  1334. % hObject handle to model_maximal_distance (see GCBO)
  1335. % eventdata reserved - to be defined in a future version of MATLAB
  1336. % handles struct with handles and user data (see GUIDATA)
  1337. % Hints: get(hObject,'String') returns contents of model_maximal_distance as text
  1338. % str2num(get(hObject,'String')) returns contents of model_maximal_distance as a double
  1339. function number_of_bins_Callback(hObject, eventdata, handles)
  1340. % hObject handle to number_of_bins (see GCBO)
  1341. % eventdata reserved - to be defined in a future version of MATLAB
  1342. % handles struct with handles and user data (see GUIDATA)
  1343. % Hints: get(hObject,'String') returns contents of number_of_bins as text
  1344. % str2num(get(hObject,'String')) returns contents of number_of_bins as a double
  1345. % --- Executes when selected object is changed in transformation_type.
  1346. function transformation_type_SelectionChangeFcn(hObject, eventdata, handles)
  1347. % hObject handle to the selected object in transformation_type
  1348. % eventdata struct with the following fields (see UIBUTTONGROUP)
  1349. % EventName: string 'SelectionChanged' (read only)
  1350. % OldValue: handle of the previously selected object or empty if none was selected
  1351. % NewValue: handle of the currently selected object
  1352. % handles struct with handles and user data (see GUIDATA)
  1353. if get(handles.translations,'Value')==1;
  1354. set(handles.maximal_rotation','enable','off')
  1355. else
  1356. set(handles.maximal_rotation','enable','on')
  1357. set(handles.maximal_rotation','string','30')
  1358. end
  1359. function maximal_rotation_Callback(hObject, eventdata, handles)
  1360. % hObject handle to maximal_rotation (see GCBO)
  1361. % eventdata reserved - to be defined in a future version of MATLAB
  1362. % handles struct with handles and user data (see GUIDATA)
  1363. % Hints: get(hObject,'String') returns contents of maximal_rotation as text
  1364. % str2num(get(hObject,'String')) returns contents of maximal_rotation as a double
  1365. % --- Executes during object creation, after setting all properties.
  1366. function maximal_rotation_CreateFcn(hObject, eventdata, handles)
  1367. % hObject handle to maximal_rotation (see GCBO)
  1368. % eventdata reserved - to be defined in a future version of MATLAB
  1369. % handles empty - handles not created until after all CreateFcns called
  1370. % Hint: edit controls usually have a white background on Windows.
  1371. % See ISPC and COMPUTER.
  1372. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1373. set(hObject,'BackgroundColor','white');
  1374. end
  1375. % --- Executes during object creation, after setting all properties.
  1376. function figure1_CreateFcn(hObject, eventdata, handles)
  1377. % hObject handle to figure1 (see GCBO)
  1378. % eventdata reserved - to be defined in a future version of MATLAB
  1379. % handles empty - handles not created until after all CreateFcns called
  1380. % --- Executes when selected object is changed in initial_register_select.
  1381. function initial_register_select_SelectionChangedFcn(hObject, eventdata, handles)
  1382. % hObject handle to the selected object in initial_register_select
  1383. % eventdata reserved - to be defined in a future version of MATLAB
  1384. % handles struct with handles and user data (see GUIDATA)
  1385. if get(handles.spatial_correlations,'Value')==1;
  1386. set(handles.distance_threshold,'enable','off')
  1387. set(handles.correlation_threshold,'enable','on')
  1388. else
  1389. set(handles.correlation_threshold,'enable','off')
  1390. set(handles.distance_threshold,'enable','on')
  1391. end
  1392. function comments_Callback(hObject, eventdata, handles)
  1393. % hObject handle to comments (see GCBO)
  1394. % eventdata reserved - to be defined in a future version of MATLAB
  1395. % handles struct with handles and user data (see GUIDATA)
  1396. % Hints: get(hObject,'String') returns contents of comments as text
  1397. % str2num(get(hObject,'String')) returns contents of comments as a double
  1398. % --- Executes during object creation, after setting all properties.
  1399. function comments_CreateFcn(hObject, eventdata, handles)
  1400. % hObject handle to comments (see GCBO)
  1401. % eventdata reserved - to be defined in a future version of MATLAB
  1402. % handles empty - handles not created until after all CreateFcns called
  1403. % Hint: edit controls usually have a white background on Windows.
  1404. % See ISPC and COMPUTER.
  1405. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1406. set(hObject,'BackgroundColor','white');
  1407. end
  1408. % --- Executes on button press in display_rgb.
  1409. function display_rgb_Callback(hObject, eventdata, handles)
  1410. % hObject handle to display_rgb (see GCBO)
  1411. % eventdata reserved - to be defined in a future version of MATLAB
  1412. % handles struct with handles and user data (see GUIDATA)
  1413. data_struct=handles.data_struct;
  1414. if ~isfield(data_struct,'footprints_projections_corrected')
  1415. errordlg('RGB overlay cannot be displayed before transformation is performed')
  1416. else
  1417. spatial_footprints_projections=data_struct.footprints_projections_corrected;
  1418. overlapping_FOV=data_struct.overlapping_FOV;
  1419. if get(handles.figures_visibility_on,'Value');
  1420. figures_visibility='On';
  1421. else
  1422. figures_visibility='Off';
  1423. end
  1424. number_of_sessions=data_struct.number_of_sessions;
  1425. red_session=str2num(get(handles.red_session,'string'));
  1426. green_session=str2num(get(handles.green_session,'string'));
  1427. if number_of_sessions>2
  1428. blue_session=str2num(get(handles.blue_session,'string'));
  1429. RGB_indexes=[red_session green_session blue_session];
  1430. else
  1431. RGB_indexes=[red_session green_session];
  1432. end
  1433. axes(handles.axes1);
  1434. plot_RGB_overlay(spatial_footprints_projections,RGB_indexes,overlapping_FOV)
  1435. figure('units','normalized','outerposition',[0.325 0.25 0.35 0.5],'Visible',figures_visibility)
  1436. plot_RGB_overlay(spatial_footprints_projections,RGB_indexes,overlapping_FOV)
  1437. end
  1438. handles.data_struct=data_struct;
  1439. guidata(hObject, handles)
  1440. function red_session_Callback(hObject, eventdata, handles)
  1441. % hObject handle to red_session (see GCBO)
  1442. % eventdata reserved - to be defined in a future version of MATLAB
  1443. % handles struct with handles and user data (see GUIDATA)
  1444. % Hints: get(hObject,'String') returns contents of red_session as text
  1445. % str2num(get(hObject,'String')) returns contents of red_session as a double
  1446. % --- Executes during object creation, after setting all properties.
  1447. function red_session_CreateFcn(hObject, eventdata, handles)
  1448. % hObject handle to red_session (see GCBO)
  1449. % eventdata reserved - to be defined in a future version of MATLAB
  1450. % handles empty - handles not created until after all CreateFcns called
  1451. % Hint: edit controls usually have a white background on Windows.
  1452. % See ISPC and COMPUTER.
  1453. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1454. set(hObject,'BackgroundColor','white');
  1455. end
  1456. function green_session_Callback(hObject, eventdata, handles)
  1457. % hObject handle to green_session (see GCBO)
  1458. % eventdata reserved - to be defined in a future version of MATLAB
  1459. % handles struct with handles and user data (see GUIDATA)
  1460. % Hints: get(hObject,'String') returns contents of green_session as text
  1461. % str2num(get(hObject,'String')) returns contents of green_session as a double
  1462. % --- Executes during object creation, after setting all properties.
  1463. function green_session_CreateFcn(hObject, eventdata, handles)
  1464. % hObject handle to green_session (see GCBO)
  1465. % eventdata reserved - to be defined in a future version of MATLAB
  1466. % handles empty - handles not created until after all CreateFcns called
  1467. % Hint: edit controls usually have a white background on Windows.
  1468. % See ISPC and COMPUTER.
  1469. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1470. set(hObject,'BackgroundColor','white');
  1471. end
  1472. function blue_session_Callback(hObject, eventdata, handles)
  1473. % hObject handle to blue_session (see GCBO)
  1474. % eventdata reserved - to be defined in a future version of MATLAB
  1475. % handles struct with handles and user data (see GUIDATA)
  1476. % Hints: get(hObject,'String') returns contents of blue_session as text
  1477. % str2num(get(hObject,'String')) returns contents of blue_session as a double
  1478. % --- Executes during object creation, after setting all properties.
  1479. function blue_session_CreateFcn(hObject, eventdata, handles)
  1480. % hObject handle to blue_session (see GCBO)
  1481. % eventdata reserved - to be defined in a future version of MATLAB
  1482. % handles empty - handles not created until after all CreateFcns called
  1483. % Hint: edit controls usually have a white background on Windows.
  1484. % See ISPC and COMPUTER.
  1485. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1486. set(hObject,'BackgroundColor','white');
  1487. end
  1488. % --- Executes on slider movement.
  1489. function initial_p_same_slider_Callback(hObject, eventdata, handles)
  1490. % hObject handle to initial_p_same_slider (see GCBO)
  1491. % eventdata reserved - to be defined in a future version of MATLAB
  1492. % handles struct with handles and user data (see GUIDATA)
  1493. % Hints: get(hObject,'Value') returns position of slider
  1494. % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  1495. data_struct=handles.data_struct;
  1496. initial_p_same_slider_value=round(100*get(handles.initial_p_same_slider,'value'))/100;
  1497. set(handles.initial_p_same_threshold,'string',num2str(initial_p_same_slider_value));
  1498. centers_of_bins=data_struct.centers_of_bins;
  1499. if get(handles.spatial_correlations,'Value')==1
  1500. spatial_correlations_distribution=data_struct.spatial_correlations_distribution;
  1501. p_same_given_spatial_correlation=data_struct.p_same_given_spatial_correlation;
  1502. [~,p_same_ind]=min(abs(initial_p_same_slider_value-(p_same_given_spatial_correlation)));
  1503. spatial_correlation_threshold=round(100*centers_of_bins{2}(p_same_ind))/100;
  1504. set(handles.correlation_threshold,'string',num2str(spatial_correlation_threshold));
  1505. axes(handles.axes4)
  1506. cla(handles.axes4,'reset')
  1507. plot_p_same_spatial_correlation_slider(spatial_correlations_distribution,p_same_given_spatial_correlation,spatial_correlation_threshold,centers_of_bins)
  1508. else
  1509. centroid_distances_distribution=data_struct.centroid_distances_distribution;
  1510. p_same_given_centroid_distance=data_struct.p_same_given_centroid_distance;
  1511. microns_per_pixel=data_struct.microns_per_pixel;
  1512. maximal_distance=data_struct.maximal_distance/microns_per_pixel;
  1513. [~,p_same_ind]=min(abs(initial_p_same_slider_value-(p_same_given_centroid_distance)));
  1514. centroid_distance_threshold=round(microns_per_pixel*100*centers_of_bins{1}(p_same_ind))/100;
  1515. set(handles.distance_threshold,'string',num2str(centroid_distance_threshold));
  1516. axes(handles.axes3)
  1517. cla(handles.axes3,'reset')
  1518. plot_p_same_centroid_distance_slider(centroid_distances_distribution,p_same_given_centroid_distance,centroid_distance_threshold,centers_of_bins,maximal_distance,microns_per_pixel)
  1519. end
  1520. handles.data_struct=data_struct;
  1521. guidata(hObject, handles)
  1522. % --- Executes during object creation, after setting all properties.
  1523. function initial_p_same_slider_CreateFcn(hObject, eventdata, handles)
  1524. % hObject handle to initial_p_same_slider (see GCBO)
  1525. % eventdata reserved - to be defined in a future version of MATLAB
  1526. % handles empty - handles not created until after all CreateFcns called
  1527. % Hint: slider controls usually have a light gray background.
  1528. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1529. set(hObject,'BackgroundColor',[.9 .9 .9]);
  1530. end
  1531. function initial_p_same_threshold_Callback(hObject, eventdata, handles)
  1532. % hObject handle to initial_all_to_all_centroid_distances (see GCBO)
  1533. % eventdata reserved - to be defined in a future version of MATLAB
  1534. % handles struct with handles and user data (see GUIDATA)
  1535. % Hints: get(hObject,'String') returns contents of initial_all_to_all_centroid_distances as text
  1536. % str2num(get(hObject,'String')) returns contents of initial_all_to_all_centroid_distances as a double
  1537. data_struct=handles.data_struct;
  1538. initial_p_same_slider_value=str2num(get(handles.initial_p_same_threshold,'string'));
  1539. set(handles.initial_p_same_slider,'value',initial_p_same_slider_value);
  1540. centers_of_bins=data_struct.centers_of_bins;
  1541. if get(handles.spatial_correlations,'Value')==1
  1542. spatial_correlations_distribution=data_struct.spatial_correlations_distribution;
  1543. p_same_given_spatial_correlation=data_struct.p_same_given_spatial_correlation;
  1544. [~,p_same_ind]=min(abs(initial_p_same_slider_value-(p_same_given_spatial_correlation)));
  1545. spatial_correlation_threshold=round(100*centers_of_bins{2}(p_same_ind))/100;
  1546. set(handles.correlation_threshold,'string',num2str(spatial_correlation_threshold));
  1547. axes(handles.axes4)
  1548. cla(handles.axes4,'reset')
  1549. plot_p_same_spatial_correlation_slider(spatial_correlations_distribution,p_same_given_spatial_correlation,spatial_correlation_threshold,centers_of_bins)
  1550. else
  1551. centroid_distances_distribution=data_struct.centroid_distances_distribution;
  1552. p_same_given_centroid_distance=data_struct.p_same_given_centroid_distance;
  1553. microns_per_pixel=data_struct.microns_per_pixel;
  1554. maximal_distance=data_struct.maximal_distance/microns_per_pixel;
  1555. [~,p_same_ind]=min(abs(initial_p_same_slider_value-(p_same_given_centroid_distance)));
  1556. centroid_distance_threshold=round(microns_per_pixel*100*centers_of_bins{1}(p_same_ind))/100;
  1557. set(handles.distance_threshold,'string',num2str(centroid_distance_threshold));
  1558. axes(handles.axes3)
  1559. cla(handles.axes3,'reset')
  1560. plot_p_same_centroid_distance_slider(centroid_distances_distribution,p_same_given_centroid_distance,centroid_distance_threshold,centers_of_bins,maximal_distance,microns_per_pixel)
  1561. end
  1562. handles.data_struct=data_struct;
  1563. guidata(hObject, handles)
  1564. % --- Executes during object creation, after setting all properties.
  1565. function initial_p_same_threshold_CreateFcn(hObject, eventdata, handles)
  1566. % hObject handle to initial_all_to_all_centroid_distances (see GCBO)
  1567. % eventdata reserved - to be defined in a future version of MATLAB
  1568. % handles empty - handles not created until after all CreateFcns called
  1569. % Hint: edit controls usually have a white background on Windows.
  1570. % See ISPC and COMPUTER.
  1571. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1572. set(hObject,'BackgroundColor','white');
  1573. end
  1574. % --- Executes on button press in default_initial_registration.
  1575. function default_initial_registration_Callback(hObject, eventdata, handles)
  1576. % hObject handle to default_initial_registration (see GCBO)
  1577. % eventdata reserved - to be defined in a future version of MATLAB
  1578. % handles struct with handles and user data (see GUIDATA)
  1579. initial_p_same_slider_value=0.5;
  1580. data_struct=handles.data_struct;
  1581. set(handles.initial_p_same_slider,'value',initial_p_same_slider_value);
  1582. set(handles.initial_p_same_threshold,'string',num2str(initial_p_same_slider_value));
  1583. centers_of_bins=data_struct.centers_of_bins;
  1584. spatial_correlations_distribution=data_struct.spatial_correlations_distribution;
  1585. p_same_given_spatial_correlation=data_struct.p_same_given_spatial_correlation;
  1586. [~,p_same_ind]=min(abs(initial_p_same_slider_value-(p_same_given_spatial_correlation)));
  1587. spatial_correlation_threshold=round(100*centers_of_bins{2}(p_same_ind))/100;
  1588. set(handles.correlation_threshold,'string',num2str(spatial_correlation_threshold));
  1589. axes(handles.axes4)
  1590. cla(handles.axes4,'reset')
  1591. plot_p_same_spatial_correlation_slider(spatial_correlations_distribution,p_same_given_spatial_correlation,spatial_correlation_threshold,centers_of_bins)
  1592. centroid_distances_distribution=data_struct.centroid_distances_distribution;
  1593. p_same_given_centroid_distance=data_struct.p_same_given_centroid_distance;
  1594. microns_per_pixel=data_struct.microns_per_pixel;
  1595. maximal_distance=data_struct.maximal_distance/microns_per_pixel;
  1596. [~,p_same_ind]=min(abs(initial_p_same_slider_value-(p_same_given_centroid_distance)));
  1597. centroid_distance_threshold=round(microns_per_pixel*100*centers_of_bins{1}(p_same_ind))/100;
  1598. set(handles.distance_threshold,'string',num2str(centroid_distance_threshold));
  1599. axes(handles.axes3)
  1600. cla(handles.axes3,'reset')
  1601. plot_p_same_centroid_distance_slider(centroid_distances_distribution,p_same_given_centroid_distance,centroid_distance_threshold,centers_of_bins,maximal_distance,microns_per_pixel)
  1602. handles.data_struct=data_struct;
  1603. guidata(hObject, handles)
  1604. % --- Executes on slider movement.
  1605. function final_p_same_slider_Callback(hObject, eventdata, handles)
  1606. % hObject handle to final_p_same_slider (see GCBO)
  1607. % eventdata reserved - to be defined in a future version of MATLAB
  1608. % handles structure with handles and user data (see GUIDATA)
  1609. % Hints: get(hObject,'Value') returns position of slider
  1610. % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
  1611. if get(handles.use_model,'Value')==1;
  1612. data_struct=handles.data_struct;
  1613. final_p_same_slider_value=round(100*get(handles.final_p_same_slider,'value'))/100;
  1614. set(handles.decision_thresh,'string',num2str(final_p_same_slider_value));
  1615. centers_of_bins=data_struct.centers_of_bins;
  1616. if get(handles.spatial_correlations_2,'Value')==1
  1617. spatial_correlations_distribution=data_struct.spatial_correlations_distribution;
  1618. p_same_given_spatial_correlation=data_struct.p_same_given_spatial_correlation;
  1619. [~,p_same_ind]=min(abs(final_p_same_slider_value-(p_same_given_spatial_correlation)));
  1620. spatial_correlation_threshold=round(100*centers_of_bins{2}(p_same_ind))/100;
  1621. set(handles.correlation_threshold,'string',num2str(spatial_correlation_threshold));
  1622. axes(handles.axes4)
  1623. cla(handles.axes4,'reset')
  1624. plot_p_same_spatial_correlation_slider(spatial_correlations_distribution,p_same_given_spatial_correlation,spatial_correlation_threshold,centers_of_bins)
  1625. else
  1626. centroid_distances_distribution=data_struct.centroid_distances_distribution;
  1627. p_same_given_centroid_distance=data_struct.p_same_given_centroid_distance;
  1628. microns_per_pixel=data_struct.microns_per_pixel;
  1629. maximal_distance=data_struct.maximal_distance/microns_per_pixel;
  1630. [~,p_same_ind]=min(abs(final_p_same_slider_value-(p_same_given_centroid_distance)));
  1631. centroid_distance_threshold=round(microns_per_pixel*100*centers_of_bins{1}(p_same_ind))/100;
  1632. set(handles.distance_threshold,'string',num2str(centroid_distance_threshold));
  1633. axes(handles.axes3)
  1634. cla(handles.axes3,'reset')
  1635. plot_p_same_centroid_distance_slider(centroid_distances_distribution,p_same_given_centroid_distance,centroid_distance_threshold,centers_of_bins,maximal_distance,microns_per_pixel)
  1636. end
  1637. handles.data_struct=data_struct;
  1638. guidata(hObject, handles)
  1639. end
  1640. % --- Executes during object creation, after setting all properties.
  1641. function final_p_same_slider_CreateFcn(hObject, eventdata, handles)
  1642. % hObject handle to final_p_same_slider (see GCBO)
  1643. % eventdata reserved - to be defined in a future version of MATLAB
  1644. % handles empty - handles not created until after all CreateFcns called
  1645. % Hint: slider controls usually have a light gray background.
  1646. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1647. set(hObject,'BackgroundColor',[.9 .9 .9]);
  1648. end
  1649. % --- Executes on button press in default_final_registration.
  1650. function default_final_registration_Callback(hObject, eventdata, handles)
  1651. % hObject handle to default_final_registration (see GCBO)
  1652. % eventdata reserved - to be defined in a future version of MATLAB
  1653. % handles struct with handles and user data (see GUIDATA)
  1654. if get(handles.use_model,'Value')==1;
  1655. final_p_same_slider_value=0.5;
  1656. data_struct=handles.data_struct;
  1657. set(handles.final_p_same_slider,'value',final_p_same_slider_value);
  1658. set(handles.decision_thresh,'string',num2str(final_p_same_slider_value));
  1659. optimal_threshold=data_struct.spatial_correlation_intersection;
  1660. set(handles.simple_correlation_threshold,'string',optimal_threshold);
  1661. centers_of_bins=data_struct.centers_of_bins;
  1662. spatial_correlations_distribution=data_struct.spatial_correlations_distribution;
  1663. p_same_given_spatial_correlation=data_struct.p_same_given_spatial_correlation;
  1664. [~,p_same_ind]=min(abs(final_p_same_slider_value-(p_same_given_spatial_correlation)));
  1665. spatial_correlation_threshold=round(100*centers_of_bins{2}(p_same_ind))/100;
  1666. set(handles.correlation_threshold,'string',num2str(spatial_correlation_threshold));
  1667. axes(handles.axes4)
  1668. cla(handles.axes4,'reset')
  1669. plot_p_same_spatial_correlation_slider(spatial_correlations_distribution,p_same_given_spatial_correlation,spatial_correlation_threshold,centers_of_bins)
  1670. centroid_distances_distribution=data_struct.centroid_distances_distribution;
  1671. p_same_given_centroid_distance=data_struct.p_same_given_centroid_distance;
  1672. microns_per_pixel=data_struct.microns_per_pixel;
  1673. maximal_distance=data_struct.maximal_distance/microns_per_pixel;
  1674. [~,p_same_ind]=min(abs(final_p_same_slider_value-(p_same_given_centroid_distance)));
  1675. centroid_distance_threshold=round(microns_per_pixel*100*centers_of_bins{1}(p_same_ind))/100;
  1676. set(handles.distance_threshold,'string',num2str(centroid_distance_threshold));
  1677. axes(handles.axes3)
  1678. cla(handles.axes3,'reset')
  1679. plot_p_same_centroid_distance_slider(centroid_distances_distribution,p_same_given_centroid_distance,centroid_distance_threshold,centers_of_bins,maximal_distance,microns_per_pixel)
  1680. handles.data_struct=data_struct;
  1681. guidata(hObject, handles)
  1682. end
  1683. function decision_thresh_Callback(hObject, eventdata, handles)
  1684. % hObject handle to decision_thresh (see GCBO)
  1685. % eventdata reserved - to be defined in a future version of MATLAB
  1686. % handles struct with handles and user data (see GUIDATA)
  1687. % Hints: get(hObject,'String') returns contents of decision_thresh as text
  1688. % str2num(get(hObject,'String')) returns contents of decision_thresh as a double
  1689. if get(handles.use_model,'Value')==1;
  1690. data_struct=handles.data_struct;
  1691. final_p_same_slider_value=str2num(get(handles.decision_thresh,'string'));
  1692. set(handles.final_p_same_slider,'value',final_p_same_slider_value);
  1693. centers_of_bins=data_struct.centers_of_bins;
  1694. if get(handles.spatial_correlations_2,'Value')==1
  1695. spatial_correlations_distribution=data_struct.spatial_correlations_distribution;
  1696. p_same_given_spatial_correlation=data_struct.p_same_given_spatial_correlation;
  1697. [~,p_same_ind]=min(abs(final_p_same_slider_value-(p_same_given_spatial_correlation)));
  1698. spatial_correlation_threshold=round(100*centers_of_bins{2}(p_same_ind))/100;
  1699. set(handles.correlation_threshold,'string',num2str(spatial_correlation_threshold));
  1700. axes(handles.axes4)
  1701. cla(handles.axes4,'reset')
  1702. plot_p_same_spatial_correlation_slider(spatial_correlations_distribution,p_same_given_spatial_correlation,spatial_correlation_threshold,centers_of_bins)
  1703. else
  1704. centroid_distances_distribution=data_struct.centroid_distances_distribution;
  1705. p_same_given_centroid_distance=data_struct.p_same_given_centroid_distance;
  1706. microns_per_pixel=data_struct.microns_per_pixel;
  1707. maximal_distance=data_struct.maximal_distance/microns_per_pixel;
  1708. [~,p_same_ind]=min(abs(final_p_same_slider_value-(p_same_given_centroid_distance)));
  1709. centroid_distance_threshold=round(microns_per_pixel*100*centers_of_bins{1}(p_same_ind))/100;
  1710. set(handles.distance_threshold,'string',num2str(centroid_distance_threshold));
  1711. axes(handles.axes3)
  1712. cla(handles.axes3,'reset')
  1713. plot_p_same_centroid_distance_slider(centroid_distances_distribution,p_same_given_centroid_distance,centroid_distance_threshold,centers_of_bins,maximal_distance,microns_per_pixel)
  1714. end
  1715. handles.data_struct=data_struct;
  1716. guidata(hObject, handles)
  1717. end
  1718. % --- Executes on button press in use_simple_threshold.
  1719. function use_simple_threshold_Callback(hObject, eventdata, handles)
  1720. % hObject handle to use_simple_threshold (see GCBO)
  1721. % eventdata reserved - to be defined in a future version of MATLAB
  1722. % handles struct with handles and user data (see GUIDATA)
  1723. % Hint: get(hObject,'Value') returns toggle state of use_simple_threshold
  1724. % --- Executes on button press in use_model.
  1725. function use_model_Callback(hObject, eventdata, handles)
  1726. % hObject handle to use_model (see GCBO)
  1727. % eventdata reserved - to be defined in a future version of MATLAB
  1728. % handles struct with handles and user data (see GUIDATA)
  1729. % Hint: get(hObject,'Value') returns toggle state of use_model
  1730. % --- Executes during object creation, after setting all properties.
  1731. function Registration_approach_CreateFcn(hObject, eventdata, handles)
  1732. % hObject handle to Registration_approach (see GCBO)
  1733. % eventdata reserved - to be defined in a future version of MATLAB
  1734. % handles empty - handles not created until after all CreateFcns called
  1735. % --- Executes when selected object is changed in Registration_approach.
  1736. function Registration_approach_SelectionChangeFcn(hObject, eventdata, handles)
  1737. % hObject handle to the selected object in transformation_type
  1738. % eventdata struct with the following fields (see UIBUTTONGROUP)
  1739. % EventName: string 'SelectionChanged' (read only)
  1740. % OldValue: handle of the previously selected object or empty if none was selected
  1741. % NewValue: handle of the currently selected object
  1742. % handles struct with handles and user data (see GUIDATA)
  1743. if get(handles.use_model,'Value')==1;
  1744. set(handles.use_simple_threshold,'value',0)
  1745. set(handles.decision_thresh,'enable','on')
  1746. set(handles.simple_correlation_threshold,'enable','off')
  1747. set(handles.simple_distance_threshold,'enable','off')
  1748. elseif get(handles.use_simple_threshold,'Value')==1;
  1749. set(handles.use_model,'value',0)
  1750. set(handles.decision_thresh,'enable','off')
  1751. if get(handles.spatial_correlations_2,'value')==1
  1752. set(handles.simple_correlation_threshold,'enable','on')
  1753. set(handles.simple_distance_threshold,'enable','off')
  1754. elseif get(handles.centroid_distances_2,'value')==1
  1755. set(handles.simple_correlation_threshold,'enable','off')
  1756. set(handles.simple_distance_threshold,'enable','on')
  1757. end
  1758. end
  1759. function simple_correlation_threshold_Callback(hObject, eventdata, handles)
  1760. % hObject handle to simple_correlation_threshold (see GCBO)
  1761. % eventdata reserved - to be defined in a future version of MATLAB
  1762. % handles struct with handles and user data (see GUIDATA)
  1763. % Hints: get(hObject,'String') returns contents of simple_correlation_threshold as text
  1764. % str2num(get(hObject,'String')) returns contents of simple_correlation_threshold as a double
  1765. % --- Executes during object creation, after setting all properties.
  1766. function simple_correlation_threshold_CreateFcn(hObject, eventdata, handles)
  1767. % hObject handle to simple_correlation_threshold (see GCBO)
  1768. % eventdata reserved - to be defined in a future version of MATLAB
  1769. % handles empty - handles not created until after all CreateFcns called
  1770. % Hint: edit controls usually have a white background on Windows.
  1771. % See ISPC and COMPUTER.
  1772. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1773. set(hObject,'BackgroundColor','white');
  1774. end
  1775. % --- Executes when selected object is changed in probability_model_select.
  1776. function probability_model_select_SelectionChangedFcn(hObject, eventdata, handles)
  1777. % hObject handle to the selected object in probability_model_select
  1778. % eventdata reserved - to be defined in a future version of MATLAB
  1779. % handles struct with handles and user data (see GUIDATA)
  1780. if get(handles.use_model,'Value')==1;
  1781. set(handles.use_simple_threshold,'value',0)
  1782. set(handles.decision_thresh,'enable','on')
  1783. set(handles.simple_correlation_threshold,'enable','off')
  1784. set(handles.simple_distance_threshold,'enable','off')
  1785. elseif get(handles.use_simple_threshold,'Value')==1;
  1786. set(handles.use_model,'value',0)
  1787. set(handles.decision_thresh,'enable','off')
  1788. if get(handles.spatial_correlations_2,'value')==1
  1789. set(handles.simple_correlation_threshold,'enable','on')
  1790. set(handles.simple_distance_threshold,'enable','off')
  1791. elseif get(handles.centroid_distances_2,'value')==1
  1792. set(handles.simple_correlation_threshold,'enable','off')
  1793. set(handles.simple_distance_threshold,'enable','on')
  1794. end
  1795. end
  1796. function simple_distance_threshold_Callback(hObject, eventdata, handles)
  1797. % hObject handle to simple_distance_threshold (see GCBO)
  1798. % eventdata reserved - to be defined in a future version of MATLAB
  1799. % handles struct with handles and user data (see GUIDATA)
  1800. % Hints: get(hObject,'String') returns contents of simple_distance_threshold as text
  1801. % str2num(get(hObject,'String')) returns contents of simple_distance_threshold as a double
  1802. % --- Executes during object creation, after setting all properties.
  1803. function simple_distance_threshold_CreateFcn(hObject, eventdata, handles)
  1804. % hObject handle to simple_distance_threshold (see GCBO)
  1805. % eventdata reserved - to be defined in a future version of MATLAB
  1806. % handles empty - handles not created until after all CreateFcns called
  1807. % Hint: edit controls usually have a white background on Windows.
  1808. % See ISPC and COMPUTER.
  1809. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1810. set(hObject,'BackgroundColor','white');
  1811. end
  1812. function distance_threshold_Callback(hObject, eventdata, handles)
  1813. % hObject handle to distance_threshold (see GCBO)
  1814. % eventdata reserved - to be defined in a future version of MATLAB
  1815. % handles structure with handles and user data (see GUIDATA)
  1816. % Hints: get(hObject,'String') returns contents of distance_threshold as text
  1817. % str2double(get(hObject,'String')) returns contents of distance_threshold as a double
  1818. function correlation_threshold_Callback(hObject, eventdata, handles)
  1819. % hObject handle to correlation_threshold (see GCBO)
  1820. % eventdata reserved - to be defined in a future version of MATLAB
  1821. % handles structure with handles and user data (see GUIDATA)
  1822. % Hints: get(hObject,'String') returns contents of correlation_threshold as text
  1823. % str2double(get(hObject,'String')) returns contents of correlation_threshold as a double
  1824. % --- Executes on button press in non_rigid.
  1825. function non_rigid_Callback(hObject, eventdata, handles)
  1826. % hObject handle to non_rigid (see GCBO)
  1827. % eventdata reserved - to be defined in a future version of MATLAB
  1828. % handles structure with handles and user data (see GUIDATA)
  1829. % Hint: get(hObject,'Value') returns toggle state of non_rigid
  1830. if get(handles.non_rigid,'Value')==1
  1831. set(handles.maximal_rotation,'enable','off')
  1832. set(handles.transformation_smoothness,'enable','on')
  1833. end
  1834. function transformation_smoothness_Callback(hObject, eventdata, handles)
  1835. % hObject handle to transformation_smoothness (see GCBO)
  1836. % eventdata reserved - to be defined in a future version of MATLAB
  1837. % handles structure with handles and user data (see GUIDATA)
  1838. % Hints: get(hObject,'String') returns contents of transformation_smoothness as text
  1839. % str2double(get(hObject,'String')) returns contents of transformation_smoothness as a double
  1840. transformation_smoothness=str2num(get(handles.transformation_smoothness,'string'));
  1841. if transformation_smoothness>3 || transformation_smoothness<0.5
  1842. errordlg('FOV smoothing parameter should be between 0.5-3')
  1843. error('FOV smoothing parameter should be between 0.5-3')
  1844. end
  1845. % --- Executes during object creation, after setting all properties.
  1846. function transformation_smoothness_CreateFcn(hObject, eventdata, handles)
  1847. % hObject handle to transformation_smoothness (see GCBO)
  1848. % eventdata reserved - to be defined in a future version of MATLAB
  1849. % handles empty - handles not created until after all CreateFcns called
  1850. % Hint: edit controls usually have a white background on Windows.
  1851. % See ISPC and COMPUTER.
  1852. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
  1853. set(hObject,'BackgroundColor','white');
  1854. end
  1855. % --- Executes on button press in translations.
  1856. function translations_Callback(hObject, eventdata, handles)
  1857. % hObject handle to translations (see GCBO)
  1858. % eventdata reserved - to be defined in a future version of MATLAB
  1859. % handles structure with handles and user data (see GUIDATA)
  1860. % Hint: get(hObject,'Value') returns toggle state of translations
  1861. if get(handles.translations,'Value')==1
  1862. set(handles.maximal_rotation,'enable','off')
  1863. set(handles.transformation_smoothness,'enable','off')
  1864. end
  1865. % --- Executes on button press in translations_rotations.
  1866. function translations_rotations_Callback(hObject, eventdata, handles)
  1867. % hObject handle to translations_rotations (see GCBO)
  1868. % eventdata reserved - to be defined in a future version of MATLAB
  1869. % handles structure with handles and user data (see GUIDATA)
  1870. % Hint: get(hObject,'Value') returns toggle state of translations_rotations
  1871. if get(handles.translations_rotations,'Value')==1
  1872. set(handles.maximal_rotation,'enable','on')
  1873. set(handles.transformation_smoothness,'enable','off')
  1874. end

CellReg.m at commit 7066851, under GPL-2.0 · at the source

Overview

Authors: Wei Zheng1, Xiaoxing Liu2, Tangsheng Lu3, Xinyou Lv4, Xuefang Guan5, Yifan Yu2, Xue Li3, Zhe Wang6, Kai Yuan2, Jeffrey W Grimm7, Trevor W Robbins8,9, Jie Shi3, Lin Lu1,2,3,6, Yan-Xue Xue3,10
  1. Peking-Tsinghua Center for Life Sciences, PKU-IDG/McGovern Institute for Brain Research, Peking University, Beijing, China
  2. Peking University Sixth Hospital, Peking University Institute of Mental Health, NHC Key Laboratory of Mental Health (Peking University), National Clinical Research Center for Mental Disorders (Peking University Sixth Hospital), Beijing, China
  3. National Institute on Drug Dependence, Beijing Key Laboratory of Drug Dependence, Peking University, Beijing, China
  4. Department of Psychology, School of Humanities and Social Sciences, University of Science and Technology of China, Hefei, China
  5. Henan Academy of Innovation in Medical Science, Henan University, Kaifeng, China
  6. Institute of Brain Science and Brain-inspired Research, Shandong First Medical University and Shandong Academy of Medical Sciences, Jinan, China
  7. Department of Psychology and Program in Behavioral Neuroscience, Western Washington University, Bellingham, WA USA
  8. Behavioural and Clinical Neuroscience Institute, Department of Psychology, University of Cambridge, Cambridge, UK
  9. Institute of Science and Technology for Brain-Inspired Intelligence, MOE Frontiers Center for Brain Science, Fudan University, Shanghai, China
  10. Chinese Institute for Brain Research, Beijing, Beijing, China
Journal: Nature communications, volume 17, issue 1, article 3462
Dates: received 3 October 2025; accepted 17 March 2026; published online 3 April 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1038/s41467-026-71357-4 · PMID 41932919 · PMCID PMC13076667 · OpenAlex W7148871776
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: rat (organism), other condition (population), systems (subfield)
Methods: Connectivity, Statistics, Preprocessing, Evoked potentials, fMRI & imaging, Single-unit activity, calcium imaging
Keywords: Reward, Addiction
MeSH: Dopaminergic Neurons*, Drug-Seeking Behavior*, Reward*, Social Behavior*, Substance-Related Disorders*, Ventral Tegmental Area*, Animals, Dopamine, Dorsal Raphe Nucleus, Male, Mesolimbic System, Optogenetics, Rats, Rats, Sprague-Dawley (* major topic)
Topic: Neurotransmitter Receptor Influence on Behavior (Cellular and Molecular Neuroscience, Neuroscience), according to OpenAlex
Funding: National Natural Science Foundation of China (National Science Foundation of China) (82071498)
Citations: not cited yet (Europe PMC); 65 references in the paper

Abstract

Drugs of abuse promote substance use disorder (SUD) by hijacking mesolimbic circuits that normally process natural rewards. Among these, social rewards exhibit therapeutic potential, but the underlying neural substrates remain unclear. Using a multimodal approach integrating in vivo single-neuron calcium imaging, optogenetic manipulation, and electrophysiology in male rats, we identified two distinct dopaminergic ensembles in the ventral tegmental area (VTA) that respectively encode social reward and drug seeking. Notably, these antagonistic ensembles exert reciprocal influence through competitive interactions that shape behavioral outcomes. Furthermore, circuit mapping revealed divergent connectivity patterns, with social reward-responsive dopaminergic ensembles receiving preferential input from the dorsal raphe nucleus (DRN). Activation of the DRN-VTA pathway recapitulates the protective effects of social reward against drug seeking. In this study, we uncovered a dynamic competition between functionally specialized dopaminergic ensembles through which social reward attenuates drug seeking, offering insights that may inform development of novel strategies for SUD treatment.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above, with 1 match between paragraphs and lines of code.

zhoupc/CNMF_E

License: GPL-3.0
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: 0f49eb08186c6aca2df0fd4873ec733d0810f1a2, 2 August 2024
Languages: MATLAB (260), Python (2), C++ (1), Jupyter (1)
Size: 334 files, 264 scripts
Software Heritage: not archived
Found in: the text, “Calcium imaging pre-processing and fluorescence ”
Holds: README, license file, 1 notebook
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: Image Processing Toolbox (41 files), Signal Processing Toolbox (8 files), Statistics and Machine Learning Toolbox (6 files), Optimization Toolbox (4 files), Matplotlib (2 files), NumPy (2 files), SciPy (2 files)
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
266 files

zivlab/CellReg

License: GPL-2.0
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Commit: 70668513c665e1cb0de218c33264b8736f2976eb, 2 July 2026
Languages: MATLAB (60)
Size: 84 files, 60 scripts
Software Heritage: not archived
Found in: the text, “Cell registration across sessions”
Holds: README, license file, documentation
Not found: CITATION.cff, environment file, tests, continuous integration
Availability: 1 check, the latest on 28 September 2026: the link answers
  • 28 September 2026: the link answers
62 files

Zenodo 18279500

License: CC-BY-4.0
State: the link answers, verified on 28 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 28 September 2026: the link answers (HTTP 200)
  • 28 September 2026: the link answers (HTTP 200)
At the source:

Code availability

Raw Ca²⁺ imaging data were processed using commercial software (Thinkerbiotech, Nanjing, China). The custom MATLAB scripts developed for this data processing are publicly available on Zenodo (10.5281/zenodo.18279500).

Reproduced under the paper's license (CC BY), from the paper cited above.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 3 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 324 scripts, each with its path and the digest of its content;
  • 1 match between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

Datasets cited

Data availability

All the data generated in this study are provided in the article and the Supplementary Information. The relevant raw data are provided as a Source data file. Source data are provided with this paper.

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 28 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 14 authors, 2 keywords, 14 MeSH terms, 1 funder, 65 references.

Cite

This paper

Zheng, W., Liu, X., Lu, T., Lv, X., Guan, X., Yu, Y., Li, X., Wang, Z., Yuan, K., Grimm, J. W., Robbins, T. W., Shi, J., Lu, L., & Xue, Y.-X. (2026). Social reward outcompetes drug seeking dopaminergic ensembles to prevent relapse. Nature communications, 17(1), 3462. https://doi.org/10.1038/s41467-026-71357-4

BibTeX

@article{zheng2026social,
author = {Zheng, Wei and Liu, Xiaoxing and Lu, Tangsheng and Lv, Xinyou and Guan, Xuefang and Yu, Yifan and Li, Xue and Wang, Zhe and Yuan, Kai and Grimm, Jeffrey W and Robbins, Trevor W and Shi, Jie and Lu, Lin and Xue, Yan-Xue},
title = {{Social reward outcompetes drug seeking dopaminergic ensembles to prevent relapse}},
journal = {Nature communications},
year = {2026},
month = apr,
volume = {17},
number = {1},
pages = {3462},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/s41467-026-71357-4},
url = {https://doi.org/10.1038/s41467-026-71357-4},
pmid = {41932919},
pmcid = {PMC13076667}
}

RIS

TY - JOUR
AU - Zheng, Wei
AU - Liu, Xiaoxing
AU - Lu, Tangsheng
AU - Lv, Xinyou
AU - Guan, Xuefang
AU - Yu, Yifan
AU - Li, Xue
AU - Wang, Zhe
AU - Yuan, Kai
AU - Grimm, Jeffrey W
AU - Robbins, Trevor W
AU - Shi, Jie
AU - Lu, Lin
AU - Xue, Yan-Xue
TI - Social reward outcompetes drug seeking dopaminergic ensembles to prevent relapse
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/04/03
VL - 17
IS - 1
SP - 3462
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-71357-4
UR - https://doi.org/10.1038/s41467-026-71357-4
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-71357-4",
"type": "article-journal",
"title": "Social reward outcompetes drug seeking dopaminergic ensembles to prevent relapse",
"container-title": "Nature communications",
"author": [
{
"family": "Zheng",
"given": "Wei"
},
{
"family": "Liu",
"given": "Xiaoxing"
},
{
"family": "Lu",
"given": "Tangsheng"
},
{
"family": "Lv",
"given": "Xinyou"
},
{
"family": "Guan",
"given": "Xuefang"
},
{
"family": "Yu",
"given": "Yifan"
},
{
"family": "Li",
"given": "Xue"
},
{
"family": "Wang",
"given": "Zhe"
},
{
"family": "Yuan",
"given": "Kai"
},
{
"family": "Grimm",
"given": "Jeffrey W"
},
{
"family": "Robbins",
"given": "Trevor W"
},
{
"family": "Shi",
"given": "Jie"
},
{
"family": "Lu",
"given": "Lin"
},
{
"family": "Xue",
"given": "Yan-Xue"
}
],
"container-title-short": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "3462",
"DOI": "10.1038/s41467-026-71357-4",
"PMID": "41932919",
"PMCID": "PMC13076667",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-71357-4",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
3
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-73994-1 [code]
Prediction error correlates in the striosome-dopamine circuit emerge from information gain.
Journal: Nature communications
In common: Optimization Toolbox, Statistics and Machine Learning Toolbox, SciPy, 2 other tools, 6 references
[2] doi:10.7554/elife.93664 [code]
Drug-induced changes in connectivity to midbrain dopamine cells revealed by rabies monosynaptic tracing.
Journal: eLife
In common: SciPy, Matplotlib, NumPy, other condition, 7 references
[3] doi:10.1016/j.isci.2026.117130 [code]
Region-specific weighting of sensory intensity and reward prediction error by dopamine signals.
Journal: iScience
In common: SciPy, Matplotlib, NumPy, 7 references
[4] doi:10.1038/s41467-026-75371-4 [code]
Cerebellar neural populations orchestrate dopamine reward signaling with single-trial precision.
Journal: Nature communications
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, SciPy, 2 other tools, systems, 5 references
[5] doi:10.1523/jneurosci.2001-25.2026 [code]
Dynamics of Dentate Gyrus Place Cells and Dentate Spikes during Spatial and Nonspatial Changes in Environments.
Journal: The Journal of neuroscience : the official journal of the Society for Neuroscience
In common: Optimization Toolbox, Image Processing Toolbox, Signal Processing Toolbox, 4 other tools, rat, systems
[6] doi:10.1038/s41467-026-75490-y [code]
Topographically organized dorsal raphe activity modulates forebrain sensory-motor representations and contributes to defensive behaviors.
Journal: Nature communications
In common: Image Processing Toolbox, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, 3 references
[7] doi:10.1038/s41467-026-70519-8 [code]
Dopamine and serotonin inversely modulate D2 medium spiny neurons to regulate cocaine reward.
Journal: Nature communications
In common: other condition, 5 references
[8] doi:10.1016/j.isci.2026.117375 [code]
Motor priming is associated with widespread recruitment into neural ensembles and more rapid ensemble transitions.
Journal: iScience
In common: Optimization Toolbox, Image Processing Toolbox, Signal Processing Toolbox, 4 other tools, systems
[9] doi:10.1038/s41467-026-75347-4 [code]
Sleep reveals dynamics integrating and segregating movement and stimulus representations in V1.
Journal: Nature communications
In common: Optimization Toolbox, Image Processing Toolbox, Signal Processing Toolbox, 4 other tools, systems
[10] doi:10.1016/j.celrep.2026.117646 [code]
Medial entorhinal-hippocampal desynchronization parallels the emergence of memory impairment in a mouse model of Alzheimer's disease pathology.
Journal: Cell reports
In common: Optimization Toolbox, Image Processing Toolbox, Signal Processing Toolbox, 4 other tools, systems

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.