将Tolias实验室matlab细胞内电生理数据转换为NWB:N格式

tolias-lab-to-nwb的Python项目详细描述


tolias实验室到nwb

将Tolias实验室数据转换为NWB的代码。文本元数据存储在YAML文件中,必须使用要添加到NWB文件的正确字段进行编辑。在

作者:本·迪克特

这个软件是与托利亚斯和贝伦斯实验室合作在DANDI project下组装的。在

安装

pip install tolias-lab-to-nwb

使用

在python中全部转换:

^{pr2}$

在python中转换单个会话:

importosfromdateutilimportparserfromruamelimportyamlfromscipy.ioimportloadmatfromtolias_lab_to_nwb.convertimportToliasNWBConverterfromtolias_lab_to_nwb.data_prepimportdata_preparationinput_fpath='/path/to/08 01 2019 sample 1.mat'output_fpath='path/to/dest.nwb'metafile_fpath='path/to/metafile.yml'fpath_base,fname=os.path.split(input_fpath)session_id=os.path.splitext(fname)[0]withopen(metafile_fpath)asf:metadata=yaml.safe_load(f)metadata['NWBFile']['session_start_time']=parser.parse(session_id[:10])metadata['NWBFile']['session_id']=session_idtolias_converter=ToliasNWBConverter(metadata)data=loadmat(input_fpath)time,current,voltage,curr_index_0=data_preparation(data)tolias_converter.add_icephys_data(current,voltage,rate=25e3)tolias_converter.save(output_fpath)

在命令行中:

usage: convert.py [-h] [-o OUTPUT_FPATH] [-m METAFILE] input_fpath

convert .mat file to NWB

positional arguments:
  input_fpath           path of .mat file to convert

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT_FPATH, --output_fpath OUTPUT_FPATH
                        path to save NWB file. If not provided, file will
                        output as input_fname.nwb in the same directory 
                        as the input data.
  -m METAFILE, --metafile METAFILE
                        YAML file that contains metadata for experiment. 
                        If not provided, will look for metafile.yml in the
                        same directory as the input data.

example usage:
  python -m tolias_lab_to_nwb.convert '/path/to/08 01 2019 sample 1.mat'
  python -m tolias_lab_to_nwb.convert '/path/to/08 01 2019 sample 1.mat' -m path/to/metafile.yml
  python -m tolias_lab_to_nwb.convert '/path/to/08 01 2019 sample 1.mat' -m path/to/metafile.yml -o path/to/dest.nwb

在python中读取生成的NWB文件

frompynwbimportNWBHDF5IOimportnumpyasnpimportmatplotlib.pyplotaspltfpath='path/to/08 01 2019 sample 1.nwb'io=NWBHDF5IO(fpath,'r')nwb=io.read()defplot_sweep(sweep,ax=None):ifaxisNone:_,ax=plt.subplots()dat=sweep.data[:]yy=dat*sweep.conversionxx=np.arange(len(dat))/sweep.rateax.plot(xx,yy)ax.set_ylabel(sweep.unit)ax.set_xlabel('time (s)')defget_stim_and_response(nwb,stim_name):stimulus=nwb.stimulus[stim_name]df=nwb.sweep_table.to_dataframe()stim_select=df['series'].apply(lambdax:x[0].object_id)==stimulus.object_idsweep_number=df['sweep_number'][stim_select].values[0]resp_select=df['sweep_number']==sweep_number-stim_selectresponse=df['series'][resp_select].values[0][0]returnstimulus,responsestimulus,response=get_stim_and_response(nwb,'CurrentClampStimulusSeries002')fig,axs=plt.subplots(2,1,sharex=True)plot_sweep(stimulus,ax=axs[0])plot_sweep(response,ax=axs[1])_=axs[0].set_xlabel('')

在MATLAB中读取数据

%% readfpath='/Volumes/easystore5T/data/Tolias/08 01 2019 sample 1.nwb';nwb=nwbRead(fpath);stim_name='CurrentClampStimulusSeries002';stimulus=nwb.stimulus_presentation.get(stim_name);sweep_table=nwb.general_intracellular_ephys_sweep_table;sweep_numbers=sweep_table.sweep_number.data.load;fori=1:length(sweep_table.series.data)obj=sweep_table.series.data(i);ifobj.refresh(nwb)==stimulussweep_number=sweep_numbers(i);break;endendind=find(sweep_numbers==sweep_number);ind=ind(ind~=i);% remove stim indresponse=sweep_table.series.data(ind).refresh(nwb);%% plotyy=stimulus.data.load*stimulus.data_conversion;xx=(1:length(yy))/stimulus.starting_time_rate;subplot(2,1,1)plot(xx,yy)ylabel(stimulus.data_unit)yy=response.data.load*response.data_conversion;xx=(1:length(yy))/response.starting_time_rate;subplot(2,1,2)plot(xx,yy)ylabel(response.data_unit)xlabel('time (s)')

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何正确测试和调试使用照相机闪光灯的应用程序?   组织。jboss。放松点。spi。未处理的异常:java。lang.NoSuchMethodError:org。冬眠SessionFactory。openSession()Lorg/hibernate/Session;   在同一行上声明多个Java数组?   java Spring批处理管理员,无法替换占位符“批处理”。商业模式。脚本'   使用JQuery的网站上出现java HtmlUnit“不支持浏览器”错误   java JavaFX如何将图形“裁剪”到按钮   java处理mysql中包含逗号的数字   java Hibernate语法错误:应为点   如何根据给定的日期在java中获取30天的回溯日期   java Servlet URL映射   线程“awteventque0”java中的多线程java JFrame异常。util。EmptyStackException,即使堆栈先初始化   JavaSpring控制器/组件实现可序列化   java如何在游戏完成时启动带有按钮的对话框?   java Hibernate双向多对多实现   如何使用Xpath Java修改XML中的属性值,包括注释部分   java Mockito模拟构造函数示例   java如何在不重写的情况下写入文本文件?