OSCR

Dexterous single sniffs for ethological active olfaction.

Code ↔ Paper

5 matches 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 5 matches
  1. [1] § MATERIALS AND METHODS › Data acquisition and analysis: Breathing signals ↔ fig2_figS2.ipynb, lines 185–261 · score 0.70 · bandpass filtered, instantaneous phase, Hilbert, analytic, angle, PLVs
  2. [2] § MATERIALS AND METHODS › Data acquisition and analysis: Breathing signals ↔ fig2GHI_S3BC_Sniff_nonsniff_phase_cophase_analysis_clean.ipynb, lines 236–321 · score 0.63 · resetting model, cophase, regression, R2, iteration, slope
  3. [3] § MATERIALS AND METHODS › Data acquisition and analysis: Breathing signals ↔ sniff_analysis.py, lines 8–138 · score 0.61 · search window, filtered signal, extrema, amplitude, 500 ms, Breathing
  4. [4] § RESULTS › The breathing rhythm adjusts abruptly around food sniffs ↔ fig2GHI_S3BC_Sniff_nonsniff_phase_cophase_analysis_clean.ipynb, lines 236–321 · score 0.54 · resetting model, cophase, regression, S3, R2, slope
  5. [5] § RESULTS › The breathing rhythm adjusts abruptly around food sniffs ↔ fig2_figS2.ipynb, lines 449–517 · score 0.51 · instantaneous phase, breathing phase, S2, inspirations, Figure 2

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

Jupyter notebook · 580 lines · 20 KB · CC-BY-4.0 · 2 matches

  1. # %%
  2. import numpy as np
  3. from matplotlib import pyplot as plt
  4. import matplotlib as mpl
  5. import scipy.signal as signal
  6. import pandas as pd
  7. import glob
  8. import seaborn as sns
  9. import scipy.ndimage as filters#changed from scipy.ndimage.filters as the namespace was deprecated 05/24/2023
  10. import pickle
  11. import scipy.stats as stats
  12. import astropy.stats.circstats as circstats
  13. # %%
  14. %matplotlib ipympl
  15. # %%
  16. from ploting import *
  17. # %%
  18. from extented_stats_tools import *
  19. # %%
  20. from signal_processing import *
  21. # %%
  22. set_plot_style()
  23. set_pub_plots()
  24. # %%
  25. out_folder='.\\source_data'
  26. # %%
  27. INSP_df_all2=pd.read_pickle(out_folder+'\\INSP_df_all2.pkl')
  28. # %%
  29. sniff_df=INSP_df_all2[(INSP_df_all2['IsSniff']==True)]
  30. # %%
  31. sniff_df_P=pd.read_pickle(out_folder+'\\sniff_df_P_6mice.pkl')
  32. trace_array_p=np.load(out_folder+'\\trace_array_6mice_all_pelltes.npy')
  33. # %%
  34. HN_d_interped_all_P=np.load(out_folder+'\\HN_d_interped_all_P.npy')
  35. # %%
  36. dt_p=sniff_df_P['hand_sniff']-sniff_df_P['t0']
  37. # %%
  38. def shuffle_trace(data,window_size=1,sr=10000):#data: 2d-array
  39. #random shuffling
  40. shuffle_point=np.random.randint(0,data.shape[-1]-int(sr*window_size),data.shape[0])
  41. window_array_x=np.stack([np.arange(data.shape[0])]*int(sr*window_size),axis=1)
  42. window_array_y=np.stack([np.arange(int(sr*window_size))]*data.shape[0])+shuffle_point[:,None]
  43. shuffled_data=data[(window_array_x,window_array_y)]
  44. return shuffled_data
  45. # %%
  46. def re_align_trace(data,event_times,insptimes,window_size=1,sr=10000):#data.shape[0]==len(event_times),
  47. #randomly choose peri-sniff insp time and use as mock sniff time wile perserve the "delta t" fro each real event
  48. all_time_shifts=[]
  49. for i in range (data.shape[0]):
  50. re_align_point_range=[(event_times.iloc[i]-window_size/2),(event_times.iloc[i]+window_size/2)]
  51. mask=np.logical_and(insptimes>re_align_point_range[0],insptimes<re_align_point_range[1])
  52. time_shifts=insptimes-event_times.iloc[i]
  53. time_shift=np.random.choice(time_shifts[mask])
  54. all_time_shifts.append(time_shift)
  55. all_time_shifts=(np.asarray(all_time_shifts)*sr).astype(int)
  56. window_array_x=np.stack([np.arange(data.shape[0])]*int(sr*window_size),axis=1)
  57. window_array_y=np.stack([np.arange(int(sr*window_size))]*data.shape[0])+all_time_shifts[:,None]+int(sr*window_size/2)
  58. aligned_data=data[(window_array_x,window_array_y)]
  59. return aligned_data
  60. # %%
  61. mice_ids=sniff_df_P['mouse_id'].unique()
  62. # %%
  63. trace_array_ave=[]
  64. HN_d_interped_ave=[]
  65. dt_p_mice=[]
  66. trace_array_allmice=[]
  67. HN_d_interped_trace_array_allmice=[]
  68. trace_array_p_min_sub=trace_array_p-trace_array_p[:,10000][:,None]
  69. for mouse_id in mice_ids:
  70. mouse_ind=sniff_df_P['mouse_id']==mouse_id
  71. trace_mouse=trace_array_p_min_sub[mouse_ind]
  72. HN_d_interped_mouse=HN_d_interped_all_P[mouse_ind]
  73. dt_p_mouse=dt_p[mouse_ind]
  74. trace_array_mouseave=np.mean(trace_mouse,axis=0)
  75. HN_d_interped_mouseave=np.mean(HN_d_interped_mouse,axis=0)
  76. trace_array_ave.append(trace_array_mouseave)
  77. HN_d_interped_ave.append(HN_d_interped_mouseave)
  78. trace_array_allmice.append(trace_mouse)
  79. HN_d_interped_trace_array_allmice.append(HN_d_interped_mouse)
  80. dt_p_mice.append(dt_p_mouse)
  81. # %%
  82. lowcut=1
  83. highcut=30
  84. order=3
  85. fs=10000
  86. # %%
  87. phase_hist_all=[]
  88. phase_hist_all_shuffled=[]
  89. phase_hist_all_realigned=[]
  90. phase_hist_all_realigned=[]
  91. instantaneous_phase_realigned_all=[]
  92. instantaneous_phase_mouse_all=[]
  93. lowcut=2
  94. γn_all_mice=[]
  95. for i,mouse_traces in enumerate(trace_array_allmice):
  96. mouse_id=mice_ids[i]
  97. mouse_traces_filtered=np.empty((mouse_traces.shape[0],mouse_traces.shape[1]))
  98. for i3 in range(mouse_traces.shape[0]):
  99. mouse_traces_filtered[i3]=butter_bandpass_filter(mouse_traces[i3],lowcut, highcut, fs, order)
  100. analytic_trace_mouse=signal.hilbert(mouse_traces_filtered)
  101. instantaneous_phase_mouse =np.angle(analytic_trace_mouse)
  102. instantaneous_phase_mouse = np.rad2deg(instantaneous_phase_mouse)
  103. instantaneous_phase_t=np.stack([np.arange(instantaneous_phase_mouse.shape[1])*1000/fs-1000]*instantaneous_phase_mouse.shape[0])
  104. instantaneous_phase_shuffled=shuffle_trace(instantaneous_phase_mouse)
  105. mouse_sniff_df=sniff_df_P[sniff_df_P['mouse_id']==mouse_id]
  106. vid_ids=mouse_sniff_df['vid_id'].unique()
  107. instantaneous_phase_realigned=[]
  108. for i2 in range(vid_ids.size):
  109. vid_sniff_df=mouse_sniff_df[mouse_sniff_df['vid_id']==vid_ids[i2]]
  110. vid_df=INSP_df_all2[INSP_df_all2['vid_id']==vid_ids[i2]]
  111. instantaneous_phase_mouse_vid=instantaneous_phase_mouse[mouse_sniff_df['vid_id']==vid_ids[i2]]
  112. event_times=vid_sniff_df['t0']
  113. insptimes=vid_df['t0'][vid_df['IsSniff']==False]
  114. instantaneous_phase_realigned_vid=re_align_trace(instantaneous_phase_mouse_vid,event_times,insptimes)
  115. instantaneous_phase_realigned.append(instantaneous_phase_realigned_vid)
  116. instantaneous_phase_realigned=np.concatenate(instantaneous_phase_realigned,axis=0)
  117. instantaneous_phase_realigned_all.append(instantaneous_phase_realigned)
  118. instantaneous_phase_mouse_all.append(instantaneous_phase_mouse)
  119. phase_hist_mouse=np.histogram2d(instantaneous_phase_t[:,5000:15000].ravel(),(instantaneous_phase_mouse[:,5000:15000]/180).ravel(),[150,36],density=True)
  120. phase_hist_mouse_shuffled=np.histogram2d(instantaneous_phase_t[:,5000:15000].ravel(),(instantaneous_phase_shuffled/180).ravel(),[150,36],density=True)
  121. phase_hist_mouse_realigned=np.histogram2d(instantaneous_phase_t[:,5000:15000].ravel(),(instantaneous_phase_realigned/180).ravel(),[150,36],density=True)
  122. mids=0.5*(phase_hist_mouse[2][1:] + phase_hist_mouse[2][:-1])
  123. phase_hist_mouse=phase_hist_mouse[0]/np.sum(phase_hist_mouse[0],axis=1)[:,None]
  124. phase_hist_mouse_shuffled=phase_hist_mouse_shuffled[0]/np.sum(phase_hist_mouse_shuffled[0],axis=1)[:,None]
  125. phase_hist_mouse_realigned=phase_hist_mouse_realigned[0]/np.sum(phase_hist_mouse_realigned[0],axis=1)[:,None]
  126. phase_hist_all_shuffled.append(phase_hist_mouse_shuffled)
  127. phase_hist_all_realigned.append(phase_hist_mouse_realigned)
  128. phase_hist_all.append(phase_hist_mouse)
  129. γn=1/2*np.sqrt(np.pi/(mouse_traces.shape[0]))
  130. γn_all_mice.append(γn)
  131. # %%
  132. iteration_n=10000
  133. PLV_realigned_allmice_ave_alliterations=[]
  134. for i in range (iteration_n):
  135. if i%500==0:
  136. print ('iteration: '+str(round(i/iteration_n,3)*100)+'%')
  137. phase_hist_all_shuffled=[]
  138. phase_hist_all_realigned=[]
  139. lowcut=2
  140. for i,mouse_traces in enumerate(trace_array_allmice):
  141. mouse_id=mice_ids[i]
  142. mouse_traces_filtered=np.empty((mouse_traces.shape[0],mouse_traces.shape[1]))
  143. for i3 in range(mouse_traces.shape[0]):
  144. mouse_traces_filtered[i3]=butter_bandpass_filter(mouse_traces[i3],lowcut, highcut, fs, order)
  145. analytic_trace_mouse=signal.hilbert(mouse_traces_filtered)
  146. instantaneous_phase_mouse =np.angle(analytic_trace_mouse)
  147. instantaneous_phase_mouse = np.rad2deg(instantaneous_phase_mouse)
  148. instantaneous_phase_t=np.stack([np.arange(instantaneous_phase_mouse.shape[1])*1000/fs-1000]*instantaneous_phase_mouse.shape[0])
  149. instantaneous_phase_shuffled=shuffle_trace(instantaneous_phase_mouse)
  150. mouse_sniff_df=sniff_df_P[sniff_df_P['mouse_id']==mouse_id]
  151. vid_ids=mouse_sniff_df['vid_id'].unique()
  152. instantaneous_phase_realigned=[]
  153. for i2 in range(vid_ids.size):
  154. vid_sniff_df=mouse_sniff_df[mouse_sniff_df['vid_id']==vid_ids[i2]]
  155. vid_df=INSP_df_all2[INSP_df_all2['vid_id']==vid_ids[i2]]
  156. instantaneous_phase_mouse_vid=instantaneous_phase_mouse[mouse_sniff_df['vid_id']==vid_ids[i2]]
  157. event_times=vid_sniff_df['t0']
  158. insptimes=vid_df['t0'][vid_df['IsSniff']==False]
  159. instantaneous_phase_realigned_vid=re_align_trace(instantaneous_phase_mouse_vid,event_times,insptimes)
  160. instantaneous_phase_realigned.append(instantaneous_phase_realigned_vid)
  161. instantaneous_phase_realigned=np.concatenate(instantaneous_phase_realigned,axis=0)
  162. phase_hist_mouse=np.histogram2d(instantaneous_phase_t[:,5000:15000].ravel(),(instantaneous_phase_mouse[:,5000:15000]/180).ravel(),[150,36],density=True)
  163. phase_hist_mouse_shuffled=np.histogram2d(instantaneous_phase_t[:,5000:15000].ravel(),(instantaneous_phase_shuffled/180).ravel(),[150,36],density=True)
  164. phase_hist_mouse_realigned=np.histogram2d(instantaneous_phase_t[:,5000:15000].ravel(),(instantaneous_phase_realigned/180).ravel(),[150,36],density=True)
  165. mids=0.5*(phase_hist_mouse[2][1:] + phase_hist_mouse[2][:-1])
  166. phase_hist_mouse=phase_hist_mouse[0]/np.sum(phase_hist_mouse[0],axis=1)[:,None]
  167. phase_hist_mouse_shuffled=phase_hist_mouse_shuffled[0]/np.sum(phase_hist_mouse_shuffled[0],axis=1)[:,None]
  168. phase_hist_mouse_realigned=phase_hist_mouse_realigned[0]/np.sum(phase_hist_mouse_realigned[0],axis=1)[:,None]
  169. phase_hist_all_shuffled.append(phase_hist_mouse_shuffled)
  170. phase_hist_all_realigned.append(phase_hist_mouse_realigned)
  171. phase_2dhist_realigned_ave=np.average(np.stack(phase_hist_all_realigned),axis=0)
  172. PLV_realigned_allmice=[]
  173. for i in range(len(phase_hist_all_realigned)):
  174. phase_2dhist_realigned_mouse=phase_hist_all_realigned[i]
  175. PLV_mouse_realigned=1-circstats.circvar(np.stack([mids*np.pi]*phase_2dhist_realigned_mouse.shape[0]),weights=phase_2dhist_realigned_mouse,axis=-1)
  176. PLV_realigned_allmice.append(PLV_mouse_realigned)
  177. PLV_realigned_allmice_ave=np.mean(np.array(PLV_realigned_allmice),axis=0)
  178. PLV_realigned_allmice_ave_alliterations.append(PLV_realigned_allmice_ave)
  179. PLV_realigned_allmice_ave_alliterations=np.stack(PLV_realigned_allmice_ave_alliterations)
  180. # %%
  181. phase_2dhist_ave=np.average(np.stack(phase_hist_all),axis=0)
  182. phase_2dhist_shuffled_ave=np.average(np.stack(phase_hist_all_shuffled),axis=0)
  183. phase_2dhist_realigned_ave=np.average(np.stack(phase_hist_all_realigned),axis=0)
  184. # %%
  185. phase_hist_mouse_realigned=np.load(out_folder+'\\phase_hist_mouse_realigned.npy')
  186. # %%
  187. phase_2dhist_shuffled_ave=np.load(out_folder+'\\phase_2dhist_shuffled_ave.npy')
  188. # %%
  189. PLV_realigned_allmice_ave_alliterations=np.load(out_folder+'\\10000iter_PLV_realigned_allmice_ave_alliterations.npy')
  190. # %%
  191. phase_hist_all_shuffled=np.load(out_folder+'\\phase_hist_all_shuffled.npy')
  192. # %%
  193. phase_hist_all_shuffled.shape
  194. # %%
  195. # %%
  196. real_PLV=1-circstats.circvar(np.stack([mids*np.pi]*phase_2dhist_ave.shape[0]),weights=phase_2dhist_ave,axis=1)
  197. # %%
  198. γn_all=1/2*np.sqrt(np.pi/344)
  199. # %%
  200. real_PLV_corected=(real_PLV-γn_all)/(1-γn_all)
  201. # %%
  202. PLV_realigned_allmice_ave_alliterations_corrected=(PLV_realigned_allmice_ave_alliterations-γn_all)/(1-γn_all)
  203. # %%
  204. cvar_data=np.stack([[mids*np.pi]*phase_hist_all_shuffled.shape[2]]*phase_hist_all_shuffled.shape[1])
  205. PLV_mice_avehist_shuffled=1-circstats.circvar(cvar_data,weights=np.mean(phase_hist_all_shuffled,axis=0),axis=-1)
  206. # %%
  207. PLV_mice_avehist_shuffled_corrected=(PLV_mice_avehist_shuffled-γn_all)/(1-γn_all)
  208. # %%
  209. PLV_mice_avehist_shuffled=PLV_mice_avehist_shuffled_corrected
  210. real_PLV=real_PLV_corected
  211. PLV_realigned_allmice_ave_alliterations=PLV_realigned_allmice_ave_alliterations_corrected
  212. # %%
  213. y1=weighted_quantiles_ndarray(values=PLV_mice_avehist_shuffled, weights=np.array([1]*PLV_mice_avehist_shuffled.shape[0]), axis=0,quantiles=0.999, interpolate=True)
  214. y2=weighted_quantiles_ndarray(values=PLV_mice_avehist_shuffled, weights=np.array([1]*PLV_mice_avehist_shuffled.shape[0]), axis=0,quantiles=0.001, interpolate=True)
  215. median=weighted_quantiles_ndarray(values=PLV_mice_avehist_shuffled, weights=np.array([1]*PLV_mice_avehist_shuffled.shape[0]), axis=0,quantiles=0.5, interpolate=True)
  216. # %%
  217. phase_hist_all[0].shape
  218. # %%
  219. zoom=1
  220. fig,axearr=plt.subplots(nrows=2,ncols=3,figsize=(5*zoom,3.2*zoom))
  221. ax1 = axearr[0, 0]
  222. ax4 = axearr[1,0]
  223. ax3 = axearr[0, 2]
  224. ax2 =axearr[0, 1]
  225. ax5 =axearr[1, 1]
  226. ax6 =axearr[1, 2]
  227. t_plot=np.array((instantaneous_phase_mouse_all[3].shape[0])*[np.arange(instantaneous_phase_mouse_all[3].shape[1])/fs-1])*1000
  228. set_ax_style(ax1)
  229. ax1.plot(t_plot.T,(instantaneous_phase_mouse_all[3].T)/180,'purple',alpha=0.05,linewidth=0.5)
  230. ax1.plot(t_plot[0],np.mean(instantaneous_phase_mouse_all[3],axis=0)/180,'purple',alpha=0.8)
  231. ax1.set_xbound(-500,500)
  232. ax1.set_yticks(np.arange(-1,1.1,0.25))
  233. ax1.set_yticklabels(['-π','','-π/2','','0','','π/2','','π'])
  234. ax1.set_ybound(-1,1)
  235. ax1.set_xticks([-400,-200,0,200,400])
  236. ax1.set_xticklabels([-400,-200,0,200,400])
  237. set_ax_style(ax2)
  238. y_plot=np.stack([np.mean(instantaneous_phase_mouse_all[i],axis=0) for i in range(len(instantaneous_phase_mouse_all))])/180
  239. t_plot=np.array((y_plot.shape[0])*[(np.arange((y_plot.shape[1]))/fs-1)*1000])
  240. ax2.plot(t_plot.T,y_plot.T,'purple',alpha=0.3)
  241. ax2.plot(t_plot[0],np.mean(y_plot,axis=0),'purple',alpha=1)
  242. ax2.set_yticks(np.arange(-1,1.1,0.25))
  243. ax2.set_yticklabels(['-π','','-π/2','','0','','π/2','','π'])
  244. ax2.set_xbound(-500,500)
  245. ax2.set_ybound(-1,1)
  246. ax2.set_xticks([-400,-200,0,200,400])
  247. ax2.set_xticklabels([-400,-200,0,200,400])
  248. set_ax_style(ax4)
  249. ax4.set_yticks(np.arange(0,36.1,4.5))
  250. ax4.set_yticklabels(['-π','','-π/2','','0','','π/2','','π'])
  251. ax4.set_xticklabels([-400,-200,0,200,400])
  252. ax4.set_xticks([75-60,75-30,75,75+30,75+60])
  253. ax4.set_xticklabels([-400,-200,0,200,400])
  254. ax1.set_ylabel('Breathing phase',color='k',fontsize=8)
  255. set_ax_style(ax5)
  256. cm_mouse=ax4.pcolormesh((phase_2dhist_ave).T,cmap='seismic',vmin=0,vmax=0.15)
  257. cm_mouse2=ax5.pcolormesh((phase_2dhist_shuffled_ave).T,cmap='seismic',vmin=0,vmax=0.15)
  258. ax4.set_title('Observed',color='r',fontsize=8)
  259. ax5.set_title('Shuffled',color='k',fontsize=8)
  260. ax5.set_yticks(np.arange(0,36.1,4.5))
  261. ax5.set_yticklabels(['-π','','-π/2','','0','','π/2','','π'])
  262. ax5.set_xticklabels([-400,-200,0,200,400])
  263. ax5.set_xticks([75-60,75-30,75,75+30,75+60])
  264. ax5.set_xticklabels([-400,-200,0,200,400])
  265. ax5.set_xlabel('Time (ms)',fontsize=8)
  266. ax=ax6
  267. set_ax_style(ax6)
  268. threshold_plv=0.27
  269. ax.axvline(np.argmax(real_PLV>threshold_plv)*1000/150-500,color='r')
  270. weights = np.ones_like(75-(np.argmin((PLV_realigned_allmice_ave_alliterations[:,:75]>threshold_plv)[:,::-1],axis=-1))) / len(75-(np.argmin((PLV_realigned_allmice_ave_alliterations[:,:75]>threshold_plv)[:,::-1],axis=-1)))
  271. bins=np.arange(50,100,1)*1000/150-500
  272. hist=ax.hist((75-(np.argmin((PLV_realigned_allmice_ave_alliterations[:,:75]>threshold_plv)[:,::-1],axis=-1)))*1000/150-500,weights=weights,bins=bins,color='grey')
  273. ax.set_xlabel('Time (s)')
  274. ax.set_ylabel('probability')
  275. ax3.plot(np.arange(real_PLV.shape[0]),real_PLV,'r')
  276. ax3.plot(np.arange(real_PLV.shape[0]),PLV_realigned_allmice_ave_alliterations[3],'b')
  277. ax3.set_xticks([75-60,75-30,75,75+30,75+60])
  278. ax3.set_xticklabels([-400,-200,0,200,400])
  279. ax3.axvline(75,ls='--',color='k')
  280. ax3.set_ybound([0,1])
  281. ax3.set_xbound([0,150])
  282. #axearr[1].set_ylabel('Breathing Phase',color='k',fontsize=8)
  283. ax3.set_ylabel('PLV',color='k',fontsize=8)
  284. fig.tight_layout()
  285. set_ax_style(ax3)
  286. # #pdf_max_phase_real=np.cumsum(np.max(phase_2dhist_ave,axis=1)/((np.max(phase_2dhist_ave,axis=1).sum()))*100)
  287. # #pdf_max_phase_shuffled=np.cumsum((np.max(phase_2dhist_shuffled_ave,axis=1)/(np.max(phase_2dhist_shuffled_ave,axis=1).sum())*100))
  288. for i in range((len(phase_hist_all))):
  289. ax=ax3
  290. #set_ax_style(ax)
  291. PLV=1-circstats.circvar(np.stack([mids*np.pi]*phase_hist_all[i].shape[0]),weights=phase_hist_all[i],axis=1)
  292. ax.plot(np.arange(PLV.shape[0]),PLV,'r',alpha=0.3)
  293. ax.fill_between(np.arange(np.mean(PLV_mice_avehist_shuffled,axis=0).shape[0]),y1=y1,y2=y2,color='k',alpha=0.5)
  294. fig.savefig(out_folder+'\\fig2ABC.pdf')
  295. # %%
  296. zoom=1
  297. fig,axearr=plt.subplots(nrows=2,ncols=3,figsize=(5*zoom,3.2*zoom))
  298. ax1 = axearr[0, 0]
  299. ax4 = axearr[1,0]
  300. ax3 = axearr[0, 2]
  301. ax2 =axearr[0, 1]
  302. ax5 =axearr[1, 1]
  303. ax6 =axearr[1, 2]
  304. t_plot=np.array((instantaneous_phase_realigned_all[3].shape[0])*[np.arange(instantaneous_phase_realigned_all[3].shape[1])/fs-0.5])*1000
  305. set_ax_style(ax1)
  306. ax1.plot(t_plot.T,(instantaneous_phase_realigned_all[3].T)/180,'purple',alpha=0.05,linewidth=0.5)
  307. ax1.plot(t_plot[0],np.mean(instantaneous_phase_realigned_all[3],axis=0)/180,'purple',alpha=0.8)
  308. ax1.set_xbound(-500,500)
  309. ax1.set_yticks(np.arange(-1,1.1,0.25))
  310. ax1.set_yticklabels(['-π','','-π/2','','0','','π/2','','π'])
  311. ax1.set_ybound(-1,1)
  312. ax1.set_xticks([-400,-200,0,200,400])
  313. ax1.set_xticklabels([-400,-200,0,200,400])
  314. set_ax_style(ax2)
  315. y_plot=np.stack([np.mean(instantaneous_phase_realigned_all[i],axis=0) for i in range(len(instantaneous_phase_realigned_all))])/180
  316. t_plot=np.array((y_plot.shape[0])*[(np.arange((y_plot.shape[1]))/fs-0.5)*1000])
  317. ax2.plot(t_plot.T,y_plot.T,'purple',alpha=0.3)
  318. ax2.plot(t_plot[0],np.mean(y_plot,axis=0),'purple',alpha=1)
  319. ax2.set_yticks(np.arange(-1,1.1,0.25))
  320. ax2.set_yticklabels(['-π','','-π/2','','0','','π/2','','π'])
  321. ax2.set_xbound(-500,500)
  322. ax2.set_ybound(-1,1)
  323. ax2.set_xticks([-400,-200,0,200,400])
  324. ax2.set_xticklabels([-400,-200,0,200,400])
  325. set_ax_style(ax3)
  326. ax3.set_yticks(np.arange(0,36.1,4.5))
  327. ax3.set_yticklabels(['-π','','-π/2','','0','','π/2','','π'])
  328. ax3.set_xticklabels([-400,-200,0,200,400])
  329. ax3.set_xticks([75-60,75-30,75,75+30,75+60])
  330. ax3.set_xticklabels([-400,-200,0,200,400])
  331. ax1.set_ylabel('Breathing phase',color='k',fontsize=8)
  332. set_ax_style(ax5)
  333. cm_mouse=ax3.pcolormesh((phase_2dhist_realigned_ave).T,cmap='seismic',vmin=0,vmax=0.15)
  334. ax3.set_title('Random inspiration',color='r',fontsize=8)
  335. ax=ax6
  336. set_ax_style(ax6)
  337. fig.tight_layout()
  338. fig.savefig(out_folder+'\\figS2.pdf')
  339. # %%
  340. time_intevals=[]
  341. mouse_df=INSP_df_all2[(INSP_df_all2['mouse_id']=='msn05')]
  342. for vid_id in mouse_df['vid_id'].unique():
  343. vid_id_sub=mouse_df[mouse_df['vid_id']==vid_id]
  344. hand_sniffs=vid_id_sub[vid_id_sub['IsSniff']==True]
  345. mouse_id=vid_id_sub['mouse_id'].unique()[0]
  346. hand_sniffs=hand_sniffs[hand_sniffs['foodtype']=='P']['hand_sniff']
  347. pre_durations=[]
  348. time_intevals_df_vid=pd.DataFrame()
  349. for hand_sniff in hand_sniffs:
  350. insp_time_intervals=vid_id_sub['t0'].values-hand_sniff
  351. insp_onset_ind=np.argmin(np.abs(insp_time_intervals))
  352. insp_indexing_arr=insp_onset_ind+np.arange(3)-1
  353. insp_indexing_arr_inrange_mask=insp_indexing_arr[np.logical_and(insp_indexing_arr<(insp_time_intervals.shape[0]),insp_indexing_arr>=0)]
  354. insp_indexing_arr_inrange_mask_type=(np.arange(3)-1)[np.logical_and(insp_indexing_arr<(insp_time_intervals.shape[0]),insp_indexing_arr>=0)]
  355. if (insp_indexing_arr_inrange_mask_type.size>=2) & (insp_indexing_arr_inrange_mask_type[0]==-1):
  356. time_interval=insp_time_intervals[insp_indexing_arr_inrange_mask[insp_indexing_arr_inrange_mask_type==-1]].round(5)
  357. time_intevals.append(time_interval)
  358. else:
  359. pass
  360. time_intevals=np.asarray(time_intevals).ravel()
  361. sorter=np.argsort(time_intevals)
  362. # %%
  363. fig,axearr=plt.subplots(nrows=1,ncols=1,figsize=(6.5/3,2))
  364. fs=10000
  365. set_ax_style(axearr)
  366. ax=axearr
  367. trace_array_plot=trace_array_allmice[3]
  368. norm_data=trace_array_plot-trace_array_plot[:,10000][:,None]
  369. data_plot=norm_data[sorter]
  370. q=10
  371. data_plot=signal.decimate(data_plot, q,axis=-1)
  372. data_plot=signal.decimate(data_plot, q,axis=-1)
  373. data_plot=data_plot*10
  374. cm0=ax.pcolormesh(data_plot,vmin=(np.mean(np.min(data_plot,axis=-1))),vmax=(np.mean(np.max(data_plot,axis=-1))),cmap='Greens_r')
  375. ax.axvline(1*fs/q/q,color='black',ls='--',alpha=1)
  376. ax.set_xticks(np.arange(0,20010/q/q,2000/q/q))
  377. ax.set_yticks(np.arange(0,155,50))
  378. ax.set_xticklabels('')
  379. ax.set_xticks(np.arange(0,20010/q/q,5000/q/q))
  380. ax.set_xticklabels(np.around(np.arange(-1,1.1,0.5),2).astype(str))
  381. ax.set_ylabel('Food Sniffs',fontsize=8)
  382. ax.set_xlabel('Time (s)',fontsize=8)
  383. ax.set_yticks(np.arange(0,155,50))
  384. l_limit=(-0.2+1)*fs
  385. r_limit=(0.2+1)*fs
  386. fig.tight_layout()
  387. fig.savefig(out_folder+'\\fig2D.pdf')
  388. # %%

fig2_figS2.ipynb, under CC-BY-4.0 · at the source

Overview

  1. Department of Neuroscience, Feinberg School of Medicine, Northwestern University, Chicago, IL, USA
  2. Department of Pharmacology and Therapeutics, Florida Chemical Senses Institute, University of Florida College of Medicine, Gainesville, FL, USA
  3. Department of Neuroscience, University of Pennsylvania Perelman School of Medicine, Philadelphia, PA, USA
Institutions: Northwestern University (United States); University of Florida (United States); University of Pennsylvania (United States)
Journal: Science advances, volume 12, issue 27, article eaed3610
Dates: received 24 October 2025; accepted 21 May 2026; published online 3 July 2026; in print July 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1126/sciadv.aed3610 · PMID 42397911 · PMCID PMC13339859 · OpenAlex W7167208461
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: mouse (organism)
Methods: Spectral & time-frequency, Statistics, Connectivity, Evoked potentials
MeSH: Smell*, Animals, Biomechanical Phenomena, Feeding Behavior, Male, Mice, Respiration (* major topic)
Journal subjects: Neuroscience
Topic: Neuroscience of respiration and sleep (Endocrine and Autonomic Systems, Neuroscience), according to OpenAlex
Funding: NIH (R34DA059723, R37NS061963)
Citations: not cited yet (Europe PMC); 58 references in the paper

Abstract

Rhythmic sniffing is considered intrinsic to active olfaction among terrestrial mammals. However, mice are known to briefly hold food under their nares while feeding, suggesting coordination of oromanual dexterity, breathing, and olfaction for nonrhythmic single sniffs. Here, we recorded kinematics and breathing as mice foraged and fed, finding that mice indeed, with clockwork-like dexterity and millisecond timing, synchronize a single inspiration with rapid head and hand movements. These solitary food sniffs are associated with abrupt resetting of the breathing rhythm, differ from stereotypical rhythmic sniffing, and exhibit behavioral modulations for different food properties. Olfactory and motor circuit manipulations demonstrate motor cortical dependence rather than reflexive neural control. Our study extends the concept of active olfaction to include this distinct form of complex motor-sensory coordination, features of which accord with the idea of discrete “snapshot” olfaction.

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

Repository

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

Zenodo 17065558

License: CC-BY-4.0
State: the link answers, verified on 27 September 2026
Evidence: files inventoried
Languages: Jupyter (8), Python (6)
Size: 16 files, 14 scripts
Software Heritage: not checked
Found in: “Data, code, and materials availability:”
Holds: 8 notebooks
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (14 files), SciPy (11 files), pandas (10 files), Matplotlib (9 files), seaborn (9 files), OpenCV (1 file), Pingouin (1 file)
Availability: 1 check, the latest on 27 September 2026: the link answers (HTTP 200)
  • 27 September 2026: the link answers (HTTP 200)
14 files

The paper's code and data availability statement is in the Data section.

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:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 14 scripts, each with its path and the digest of its content;
  • 5 matches 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

No dataset and no data link were found in the paper.

Data, code, and materials availability

All data and code needed to evaluate and reproduce the results in the paper are present in the paper and/or the Supplementary Materials. Data for this study are available at the EMBER-DANDI repository (emberarchive.org): https://dandi.emberarchive.org/dandiset/000463 (DOI pending). Code used in this study is available at Zenodo: https://doi.org/10.5281/zenodo.17065558. This study did not generate new materials.

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, 27 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 7 authors, 7 MeSH terms, 1 funder, 55 references.

Cite

This paper

Gao, M., Barrett, J. M., Fischer, R., McCrimmon, D. R., Wesson, D. W., Ma, M., & Shepherd, G. M. G. (2026). Dexterous single sniffs for ethological active olfaction. Science advances, 12(27), eaed3610. https://doi.org/10.1126/sciadv.aed3610

BibTeX

@article{gao2026dexterous,
author = {Gao, Mang and Barrett, John M. and Fischer, Rita and McCrimmon, Donald R. and Wesson, Daniel W. and Ma, Minghong and Shepherd, Gordon M. G.},
title = {{Dexterous single sniffs for ethological active olfaction}},
journal = {Science advances},
year = {2026},
month = jul,
volume = {12},
number = {27},
pages = {eaed3610},
publisher = {American Association for the Advancement of Science},
issn = {2375-2548},
doi = {10.1126/sciadv.aed3610},
url = {https://doi.org/10.1126/sciadv.aed3610},
pmid = {42397911},
pmcid = {PMC13339859}
}

RIS

TY - JOUR
AU - Gao, Mang
AU - Barrett, John M.
AU - Fischer, Rita
AU - McCrimmon, Donald R.
AU - Wesson, Daniel W.
AU - Ma, Minghong
AU - Shepherd, Gordon M. G.
TI - Dexterous single sniffs for ethological active olfaction
T2 - Science advances
J2 - Sci Adv
PY - 2026
DA - 2026/07/03
VL - 12
IS - 27
SP - eaed3610
SN - 2375-2548
PB - American Association for the Advancement of Science
DO - 10.1126/sciadv.aed3610
UR - https://doi.org/10.1126/sciadv.aed3610
LA - en
ER -

CSL-JSON

{
"id": "10.1126/sciadv.aed3610",
"type": "article-journal",
"title": "Dexterous single sniffs for ethological active olfaction",
"container-title": "Science advances",
"author": [
{
"family": "Gao",
"given": "Mang"
},
{
"family": "Barrett",
"given": "John M."
},
{
"family": "Fischer",
"given": "Rita"
},
{
"family": "McCrimmon",
"given": "Donald R."
},
{
"family": "Wesson",
"given": "Daniel W."
},
{
"family": "Ma",
"given": "Minghong"
},
{
"family": "Shepherd",
"given": "Gordon M. G."
}
],
"container-title-short": "Sci Adv",
"volume": "12",
"issue": "27",
"page": "eaed3610",
"DOI": "10.1126/sciadv.aed3610",
"PMID": "42397911",
"PMCID": "PMC13339859",
"ISSN": "2375-2548",
"publisher": "American Association for the Advancement of Science",
"URL": "https://doi.org/10.1126/sciadv.aed3610",
"language": "en",
"issued": {
"date-parts": [
[
2026,
7,
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-72445-1 [code]
Perception and neural representation of intermittent odor stimuli in mice.
Journal: Nature communications
In common: Pingouin, seaborn, pandas, 3 other tools, mouse, 6 references
[2] doi:10.1126/sciadv.aee1002 [code]
Theta oscillations are an organizational unit of odor processing in the olfactory bulb.
Journal: Science advances
In common: 8 references
[3] doi:10.1038/s41467-026-73106-z [code]
Respiratory pauses highlight sleep architecture in mice.
Journal: Nature communications
In common: SciPy, Matplotlib, NumPy, mouse, 5 references
[4] doi:10.1073/pnas.2603853123 [code]
A nose-to-brain circuit underlies anxiety regulation by nasal afferent frequency in mice.
Journal: Proceedings of the National Academy of Sciences of the United States of America
In common: mouse, 3 references, author Minghong Ma
[5] doi: [code]
Real-time closed-loop feedback system for mouse mesoscale cortical signal and movement control
Journal: eLife
In common: Pingouin, OpenCV, seaborn, 4 other tools, mouse, 2 references
[6] doi:10.1126/sciadv.adv5652 [code]
The anterior cingulate cortex modulates pupil-linked arousal.
Journal: Science advances
In common: OpenCV, seaborn, pandas, 3 other tools, 3 references
[7] doi:10.1016/j.isci.2026.116825 [code]
Social hierarchy shapes behavioral and transcriptional responses to chronic stress and ketamine in male mice.
Journal: iScience
In common: Pingouin, OpenCV, seaborn, 4 other tools, mouse, 1 reference
[8] doi:10.1038/s41467-026-74823-1 [code]
Cerebellar activity is triggered by reach endpoint during learning of a complex locomotor task.
Journal: Nature communications
In common: Pingouin, OpenCV, seaborn, 4 other tools, mouse, 1 reference
[9] doi:10.1038/s41593-026-02318-9 [code]
Induction of cortical on/off periods in awake mice fulfills sleep functions.
Journal: Nature neuroscience
In common: Pingouin, OpenCV, seaborn, 4 other tools, mouse, 1 reference
[10] doi:10.1038/s41593-026-02232-0 [code]
Entorhinal cortex represents task-relevant remote locations independently of CA1.
Journal: Nature neuroscience
In common: Pingouin, OpenCV, seaborn, 4 other tools, mouse, 1 reference

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.