├── .gitignore ├── .gitmodules ├── ChangeLog ├── README.md ├── data_test.m ├── doc ├── .gitignore ├── Makefile ├── archives │ ├── .gitignore │ └── README ├── make.bat ├── requirements.txt ├── scripts │ ├── get_version.py │ ├── gitwash_dumper.py │ ├── make_apidocs.m │ └── write_doc_release.py └── source │ ├── about.rst │ ├── conf.py │ ├── development │ ├── apidocs.rst │ ├── code.rst │ ├── gitwash │ │ ├── branch_list.png │ │ ├── branch_list_compare.png │ │ ├── configure_git.rst │ │ ├── development_workflow.rst │ │ ├── dot2_dot3.rst │ │ ├── following_latest.rst │ │ ├── forking_button.png │ │ ├── forking_hell.rst │ │ ├── git_development.rst │ │ ├── git_install.rst │ │ ├── git_intro.rst │ │ ├── git_links.inc │ │ ├── git_resources.rst │ │ ├── index.rst │ │ ├── patching.rst │ │ ├── pull_button.png │ │ └── set_up_fork.rst │ └── index.rst │ ├── download.rst │ ├── faq.rst │ ├── index.rst │ ├── links_names.txt │ ├── releasing.rst │ ├── support.rst │ └── tutorial │ ├── andmore.rst │ ├── define.rst │ ├── estimate.rst │ ├── fig │ ├── data_menu.png │ ├── define_menu.png │ ├── defining_contrast.png │ ├── design_menu.png │ ├── main_marsbar.png │ ├── results_menu.png │ ├── roi_build.png │ ├── roi_view.png │ ├── spm_buttons.png │ ├── spm_graphics.png │ ├── spm_input.png │ ├── spm_run2.png │ ├── spm_select.png │ ├── uigetfile.png │ └── write_rois_menu.png │ ├── gettingstarted.rst │ ├── index.rst │ ├── interface.rst │ └── results.rst ├── gui_data_test.m ├── marsbar ├── @mardo │ ├── add_contrasts.m │ ├── adjusted_data.m │ ├── betas.m │ ├── block_mean_cols.m │ ├── block_means.m │ ├── cd_images.m │ ├── contrasts.m │ ├── data.m │ ├── des_struct.m │ ├── descrip.m │ ├── design_matrix.m │ ├── design_structure.m │ ├── display.m │ ├── error_df.m │ ├── event_fitted.m │ ├── event_fitted_fir.m │ ├── event_signal.m │ ├── event_types.m │ ├── event_types_named.m │ ├── flip_images.m │ ├── flip_option.m │ ├── full_vol.m │ ├── get_contrast_by_name.m │ ├── get_contrasts.m │ ├── get_data.m │ ├── get_vol_field.m │ ├── has_contrasts.m │ ├── has_filter.m │ ├── has_images.m │ ├── has_whitener.m │ ├── image_names.m │ ├── images.m │ ├── is_fmri.m │ ├── is_mars_estimated.m │ ├── is_marsed.m │ ├── is_spm_estimated.m │ ├── is_valid.m │ ├── isempty.m │ ├── isfield.m │ ├── mardo.m │ ├── mars_tag.m │ ├── marsy_data.m │ ├── masking_struct.m │ ├── modality.m │ ├── n_effects.m │ ├── n_time_points.m │ ├── native_vol_ver.m │ ├── paramfields.m │ ├── prefix_images.m │ ├── private │ │ ├── pr_ev_diff.m │ │ ├── pr_refresh_et.m │ │ └── pr_sort_evs.m │ ├── refresh_contrasts.m │ ├── residuals.m │ ├── savestruct.m │ ├── set_contrasts.m │ ├── set_data.m │ ├── set_vol_field.m │ ├── stat_table.m │ ├── subsasgn.m │ ├── subsref.m │ ├── summary.m │ ├── swd.m │ ├── swd_writable.m │ ├── type.m │ ├── ui_et_edit.m │ ├── ui_et_edit_cb.m │ ├── ui_event_types.m │ ├── ui_event_types_cb.m │ ├── ui_ft_design_data.m │ ├── ui_get_contrasts.m │ ├── unfiltered_efficiency.m │ └── verbose.m ├── @mardo_2 │ ├── add_trial_f.m │ ├── apply_filter.m │ ├── autocorr.m │ ├── bf_dt.m │ ├── block_cols.m │ ├── block_rows.m │ ├── can_mars_estimate.m │ ├── compute_contrasts.m │ ├── convert_vols.m │ ├── design_vol.m │ ├── estimate.m │ ├── event_cols.m │ ├── event_onsets.m │ ├── event_regressor.m │ ├── event_specs.m │ ├── event_x_fir.m │ ├── fill.m │ ├── fwhm.m │ ├── get_images.m │ ├── has_autocorr.m │ ├── has_filter.m │ ├── has_images.m │ ├── has_whitener.m │ ├── mardo_2.m │ ├── mardo_99.m │ ├── mars_spm_graph.m │ ├── modality.m │ ├── private │ │ ├── my_design.m │ │ ├── pr_estimate.m │ │ ├── pr_fmri_design.m │ │ ├── pr_fmristat_ar.m │ │ ├── pr_get_filter.m │ │ ├── pr_spm_ce.m │ │ ├── pr_spm_diff.m │ │ ├── pr_spm_filter.m │ │ ├── pr_spm_get_bf.m │ │ ├── pr_spm_get_ons.m │ │ ├── pr_spm_gpdf.m │ │ ├── pr_spm_hrf.m │ │ ├── pr_spm_orth.m │ │ ├── pr_spm_q.m │ │ ├── pr_spm_reml.m │ │ ├── pr_spm_svd.m │ │ ├── pr_spm_ui.m │ │ ├── pr_spm_volterra.m │ │ ├── pr_stat_compute.m │ │ └── pr_stat_compute_mv.m │ ├── save_spm.m │ ├── savestruct.m │ ├── set_images.m │ ├── tr.m │ ├── type.m │ ├── ui_build.m │ ├── ui_get_event.m │ ├── ui_get_filter.m │ ├── ui_report.m │ └── ui_report_fmri.m ├── @mardo_5 │ ├── autocorr.m │ ├── convert_vols.m │ ├── estimate.m │ ├── fill.m │ ├── mardo_5.m │ ├── native_vol_ver.m │ ├── private │ │ ├── my_design.m │ │ ├── pr_estimate.m │ │ ├── pr_fmri_design.m │ │ ├── pr_fmristat_ar.m │ │ ├── pr_get_filter.m │ │ ├── pr_spm_cat.m │ │ ├── pr_spm_ce.m │ │ ├── pr_spm_diff.m │ │ ├── pr_spm_en.m │ │ ├── pr_spm_fileparts.m │ │ ├── pr_spm_filter.m │ │ ├── pr_spm_get_bf.m │ │ ├── pr_spm_get_ons.m │ │ ├── pr_spm_gpdf.m │ │ ├── pr_spm_hrf.m │ │ ├── pr_spm_justify.m │ │ ├── pr_spm_logdet.m │ │ ├── pr_spm_non_sphericity.m │ │ ├── pr_spm_orth.m │ │ ├── pr_spm_q.m │ │ ├── pr_spm_reml.m │ │ ├── pr_spm_select.m │ │ ├── pr_spm_svd.m │ │ ├── pr_spm_ui.m │ │ ├── pr_spm_unvec.m │ │ ├── pr_spm_vec.m │ │ ├── pr_spm_volterra.m │ │ ├── pr_stat_compute.m │ │ └── pr_stat_compute_mv.m │ ├── type.m │ └── ui_build.m ├── @mardo_99 │ ├── add_trial_f.m │ ├── apply_filter.m │ ├── autocorr.m │ ├── bf_dt.m │ ├── block_cols.m │ ├── block_rows.m │ ├── can_mars_estimate.m │ ├── compute_contrasts.m │ ├── convert_vols.m │ ├── design_vol.m │ ├── estimate.m │ ├── event_cols.m │ ├── event_onsets.m │ ├── event_regressor.m │ ├── event_specs.m │ ├── event_x_fir.m │ ├── fill.m │ ├── fwhm.m │ ├── get_images.m │ ├── has_autocorr.m │ ├── has_filter.m │ ├── has_images.m │ ├── mardo_2.m │ ├── mardo_99.m │ ├── mars_spm_graph.m │ ├── modality.m │ ├── private │ │ ├── my_design.m │ │ ├── pr_estimate.m │ │ ├── pr_fmri_design.m │ │ ├── pr_get_filter.m │ │ ├── pr_spm_filter.m │ │ ├── pr_spm_get_bf.m │ │ ├── pr_spm_get_ons.m │ │ ├── pr_spm_hrf.m │ │ ├── pr_spm_orth.m │ │ ├── pr_spm_ui.m │ │ ├── pr_spm_volterra.m │ │ ├── pr_stat_compute.m │ │ └── pr_stat_compute_mv.m │ ├── save_spm.m │ ├── set_images.m │ ├── tr.m │ ├── type.m │ ├── ui_build.m │ ├── ui_get_event.m │ ├── ui_get_filter.m │ ├── ui_report.m │ └── ui_report_fmri.m ├── @marmoire │ ├── add_if_absent.m │ ├── add_item.m │ ├── clear_item_data.m │ ├── default_item.m │ ├── do_save.m │ ├── do_set.m │ ├── get_item_data.m │ ├── get_item_param.m │ ├── get_item_struct.m │ ├── isempty_item_data.m │ ├── item_exists.m │ ├── item_needs_save.m │ ├── marmoire.m │ ├── private │ │ ├── pr_is_nan.m │ │ ├── pr_is_nix.m │ │ ├── pr_isempty.m │ │ └── pr_needs_save.m │ ├── save_item_data.m │ ├── save_item_data_ui.m │ ├── set_item_data.m │ ├── set_item_data_ui.m │ ├── set_item_param.m │ ├── set_item_struct.m │ └── update_item_data.m ├── @maroi │ ├── and.m │ ├── are_same.m │ ├── back2base.m │ ├── binarize.m │ ├── c_o_m.m │ ├── classdata.m │ ├── descrip.m │ ├── display.m │ ├── eq.m │ ├── flip_lr.m │ ├── ge.m │ ├── get_marsy.m │ ├── getdata.m │ ├── gt.m │ ├── has_space.m │ ├── history.m │ ├── label.m │ ├── le.m │ ├── loadobj.m │ ├── lt.m │ ├── maroi.m │ ├── maroi_matrix.m │ ├── minus.m │ ├── mrdivide.m │ ├── mtimes.m │ ├── native_space.m │ ├── ne.m │ ├── not.m │ ├── or.m │ ├── paramfields.m │ ├── plus.m │ ├── private │ │ ├── my_classdata.m │ │ ├── my_loadroi.m │ │ └── my_roifname.m │ ├── rdivide.m │ ├── realpts.m │ ├── rle.m │ ├── roithresh.m │ ├── save_as_image.m │ ├── save_mricro.m │ ├── saveroi.m │ ├── source.m │ ├── spm_hold.m │ ├── times.m │ ├── volume.m │ └── xor.m ├── @maroi_box │ ├── centre.m │ ├── flip_lr.m │ ├── is_empty_roi.m │ ├── maroi_box.m │ ├── volume.m │ └── voxpts.m ├── @maroi_image │ ├── flip_lr.m │ ├── loadobj.m │ ├── maroi_image.m │ ├── maroi_matrix.m │ ├── private │ │ └── my_vol_func.m │ ├── saveobj.m │ └── vol.m ├── @maroi_matrix │ ├── do_write_image.m │ ├── domaths.m │ ├── flip_lr.m │ ├── is_empty_roi.m │ ├── loadobj.m │ ├── maroi_matrix.m │ ├── matrixdata.m │ ├── native_space.m │ ├── private │ │ ├── my_rld.m │ │ └── my_rle.m │ ├── rebase.m │ ├── saveobj.m │ ├── spm_mat.m │ └── voxpts.m ├── @maroi_pointlist │ ├── flip_lr.m │ ├── getvals.m │ ├── is_empty_roi.m │ ├── loadobj.m │ ├── maroi_matrix.m │ ├── maroi_pointlist.m │ ├── native_space.m │ ├── private │ │ └── my_voxblock.m │ ├── saveobj.m │ └── voxpts.m ├── @maroi_shape │ ├── c_o_m.m │ ├── has_space.m │ ├── maroi_matrix.m │ └── maroi_shape.m ├── @maroi_sphere │ ├── centre.m │ ├── flip_lr.m │ ├── is_empty_roi.m │ ├── maroi_sphere.m │ ├── volume.m │ └── voxpts.m ├── @mars_space │ ├── display.m │ ├── eq.m │ ├── mars_space.m │ ├── subsasgn.m │ └── subsref.m ├── @marsy │ ├── as_summary_only.m │ ├── block_rows.m │ ├── can_summarize.m │ ├── display.m │ ├── eq.m │ ├── is_summarized.m │ ├── is_summary_only.m │ ├── is_valid.m │ ├── join.m │ ├── marsy.m │ ├── n_blocks.m │ ├── n_regions.m │ ├── n_time_points.m │ ├── ne.m │ ├── private │ │ └── pr_sum_func.m │ ├── region.m │ ├── region_data.m │ ├── region_descrip.m │ ├── region_field.m │ ├── region_info.m │ ├── region_name.m │ ├── region_size.m │ ├── region_weights.m │ ├── resummarize.m │ ├── savestruct.m │ ├── split.m │ ├── sumfunc.m │ ├── summary.m │ ├── summary_block_means.m │ ├── summary_data.m │ ├── summary_descrip.m │ ├── summary_info.m │ ├── summary_size.m │ ├── ui_plot.m │ ├── verbose.m │ ├── xyz.m │ └── y_struct.m ├── examples │ └── batch │ │ ├── README │ │ ├── configure_er_model.m │ │ ├── do_bch_wrapper.m │ │ ├── er_contrast_spm99.m │ │ ├── er_model_spm2.m │ │ ├── er_model_spm99.m │ │ ├── er_smooth.m │ │ ├── estimate_er_model.m │ │ ├── get_subjroot.m │ │ ├── run_preprocess.m │ │ ├── run_s3_model.m │ │ └── run_tutorial.m ├── install.txt ├── mars_arm.m ├── mars_arm_call.m ├── mars_armoire.m ├── mars_blob2roi.m ├── mars_blob_menu.m ├── mars_blobs2rois.m ├── mars_build_roi.m ├── mars_display_roi.m ├── mars_get_option.m ├── mars_image_scaling.m ├── mars_img2rois.m ├── mars_licence.man ├── mars_new_space.m ├── mars_options.m ├── mars_orthviews.m ├── mars_rois2img.m ├── mars_struct.m ├── mars_uifile.m ├── mars_utils.m ├── mars_vol_check.m ├── mars_vol_utils.m ├── marsbar.jpg ├── marsbar.m ├── release │ ├── make_contents.m │ ├── pre_release.m │ └── test_rig.m ├── savestruct.m ├── spm2 │ ├── mars_blob_ui.m │ ├── mars_veropts.m │ └── spm_create_image.m ├── spm5 │ ├── mars_blob_ui.m │ ├── mars_veropts.m │ ├── spm_create_image.m │ └── spm_get.m ├── spm99 │ ├── mars_blob_ui.m │ ├── mars_veropts.m │ ├── spm_close_vol.m │ ├── spm_create_vol.m │ ├── spm_read_hdr.m │ ├── spm_write_plane.m │ └── spm_write_vol.m └── todo.txt ├── test.m └── tests ├── bad_mres.mat ├── img01.hdr ├── img01.img ├── img01.mat ├── img02.hdr ├── img02.img ├── img02.mat ├── img03.hdr ├── img03.img ├── img03.mat ├── test_add_contrasts.m ├── test_get_marsy.m ├── test_get_option.m ├── test_mardos.m ├── test_maroi_image.m ├── test_marsy.m └── test_marsy_stripreg.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | dist/ 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "testing"] 2 | path = testing 3 | url = https://github.com/matthew-brett/matlabtesting 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Marsbar 2 | 3 | This is the Marsbar repository. 4 | 5 | Please see: for documentation, 6 | and for the code. 7 | 8 | ## Tests 9 | 10 | To run the tests from the development repository, don\'t forget: 11 | 12 | git submodule init 13 | git submodule update 14 | 15 | to get the testing code. 16 | 17 | Then make sure: 18 | 19 | * SPM is on the Matlab path 20 | * `/path/to/marsbar-repo/testing` is on the Matlab path 21 | 22 | Finally, in Matlab: 23 | 24 | ``` 25 | run_tests tests 26 | ``` 27 | 28 | from the repository home directory (the directory containing sub-directories 29 | `testing` and `marsbar` and `marsbar_example_data`). 30 | 31 | ## Data 32 | 33 | There is a `marsbar_example_data` sub-directory, but this is only to store 34 | a few smaller files that will go into the Marsbar data package. To reconstruct 35 | the Marsbar example data, download and unpack the current Marsbar example data 36 | somewhere (outside the repository working tree), copy the 37 | `marsbar_example_data` files into this tree, bump the version number in the 38 | directory name of the example data, and re-release. 39 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | *-stamp 2 | build/ 3 | dist/ 4 | -------------------------------------------------------------------------------- /doc/archives/.gitignore: -------------------------------------------------------------------------------- 1 | *.zip 2 | *.tar.gz 3 | -------------------------------------------------------------------------------- /doc/archives/README: -------------------------------------------------------------------------------- 1 | This is the directory for storing built archives of code or docs 2 | -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | # Requirements for build.[:w 2 | sphinx-book-theme 3 | -------------------------------------------------------------------------------- /doc/scripts/get_version.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import sys 5 | import re 6 | 7 | 8 | def get_version(release_dir): 9 | ver_re = re.compile(" *MBver = '([0-9.]+)';") 10 | fname = os.path.join(release_dir, 'marsbar.m') 11 | for line in open(fname): 12 | m = ver_re.match(line) 13 | if m: 14 | return m.groups()[0] 15 | raise RuntimeError('Did not find version') 16 | 17 | 18 | if __name__ == '__main__': 19 | try: 20 | release_dir = sys.argv[1] 21 | except IndexError: 22 | raise OSError('Expecting directory as argument') 23 | print get_version(release_dir) 24 | -------------------------------------------------------------------------------- /doc/scripts/make_apidocs.m: -------------------------------------------------------------------------------- 1 | cd ../.. 2 | m2html('mfiles', 'marsbar', ... 3 | 'htmldir', 'doc/dist/apidocs', ... 4 | 'graph', 'on', ... 5 | 'recursive', 'on', ... 6 | 'global', 'on'); 7 | -------------------------------------------------------------------------------- /doc/scripts/write_doc_release.py: -------------------------------------------------------------------------------- 1 | #!/bin/env/python 2 | """ Write documentation archive for release """ 3 | 4 | import os 5 | from os.path import abspath 6 | import sys 7 | import re 8 | from functools import partial 9 | import subprocess 10 | 11 | caller = partial(subprocess.call, shell=True) 12 | 13 | 14 | def get_version(code_dir): 15 | ver_re = re.compile(" *MBver = '([0-9.]+)';") 16 | fname = os.path.join(code_dir, 'marsbar.m') 17 | for line in open(fname): 18 | m = ver_re.match(line) 19 | if m: 20 | return m.groups()[0] 21 | raise RuntimeError('Did not find version') 22 | 23 | 24 | if __name__ == '__main__': 25 | try: 26 | release_dir = sys.argv[1] 27 | except IndexError: 28 | raise OSError('Expecting built doc directory as first argument') 29 | release_dir = abspath(release_dir) 30 | try: 31 | code_dir = sys.argv[2] 32 | except IndexError: 33 | raise OSError('Expecting code directory as second argument') 34 | code_dir = abspath(code_dir) 35 | try: 36 | archive_dir = sys.argv[3] 37 | except IndexError: 38 | pass 39 | else: 40 | os.chdir(archive_dir) 41 | ver = get_version(code_dir) 42 | froot = 'marsbar-doc-%s' % ver 43 | caller('ln -s %s %s' % (release_dir, froot)) 44 | caller('zip -r %s.zip %s' % (froot, froot)) 45 | os.unlink(froot) 46 | -------------------------------------------------------------------------------- /doc/source/about.rst: -------------------------------------------------------------------------------- 1 | About MarsBaR 2 | ============= 3 | 4 | Citing MarsBaR 5 | ~~~~~~~~~~~~~~ 6 | 7 | We presented an abstract to the Human Brain Mapping conference for 2002; 8 | this may be useful as a reference: `MarsBaR HBM abstract`_. It should 9 | apparently be cited as: 10 | 11 | Matthew Brett, Jean-Luc Anton, Romain Valabregue, Jean-Baptiste 12 | Poline. Region of interest analysis using an SPM toolbox [abstract] 13 | Presented at the 8th International Conference on Functional Mapping of 14 | the Human Brain, June 2-6, 2002, Sendai, Japan. Available on CD-ROM in 15 | NeuroImage, Vol 16, No 2. 16 | 17 | Support 18 | ~~~~~~~ 19 | 20 | See the :doc:`support page `. 21 | 22 | Thanks 23 | ~~~~~~ 24 | 25 | For writing credits and some little jokes, see the `marsbar.m file 26 | <./apidocs/marsbar/marsbar.html>`_ file in the MarsBaR release. 27 | 28 | .. include:: links_names.txt 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /doc/source/development/apidocs.rst: -------------------------------------------------------------------------------- 1 | =================== 2 | API documentation 3 | =================== 4 | 5 | The MarsBaR code is reasonably well documented; we export this 6 | documentation as web pages using Guillaume Flandin's excellent 7 | `m2html`_. The API documents are in the `apidocs <../apidocs/index.html>`_ 8 | directory of the documentation. 9 | 10 | .. include:: ../links_names.txt 11 | -------------------------------------------------------------------------------- /doc/source/development/code.rst: -------------------------------------------------------------------------------- 1 | ===================================== 2 | Getting the latest development code 3 | ===================================== 4 | 5 | MarsBaR code is on github - see `marsbar github`_. 6 | 7 | For instructions on getting the code, making patches or being a developer, see :ref:`using-git`. 8 | 9 | .. include:: ../links_names.txt 10 | -------------------------------------------------------------------------------- /doc/source/development/gitwash/branch_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/development/gitwash/branch_list.png -------------------------------------------------------------------------------- /doc/source/development/gitwash/branch_list_compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/development/gitwash/branch_list_compare.png -------------------------------------------------------------------------------- /doc/source/development/gitwash/dot2_dot3.rst: -------------------------------------------------------------------------------- 1 | .. _dot2-dot3: 2 | 3 | ======================================== 4 | Two and three dots in difference specs 5 | ======================================== 6 | 7 | Thanks to Yarik Halchenko for this explanation. 8 | 9 | Imagine a series of commits A, B, C, D... Imagine that there are two 10 | branches, *topic* and *master*. You branched *topic* off *master* when 11 | *master* was at commit 'E'. The graph of the commits looks like this:: 12 | 13 | 14 | A---B---C topic 15 | / 16 | D---E---F---G master 17 | 18 | Then:: 19 | 20 | git diff master..topic 21 | 22 | will output the difference from G to C (i.e. with effects of F and G), 23 | while:: 24 | 25 | git diff master...topic 26 | 27 | would output just differences in the topic branch (i.e. only A, B, and 28 | C). 29 | -------------------------------------------------------------------------------- /doc/source/development/gitwash/following_latest.rst: -------------------------------------------------------------------------------- 1 | .. _following-latest: 2 | 3 | ============================= 4 | Following the latest source 5 | ============================= 6 | 7 | These are the instructions if you just want to follow the latest 8 | *marsbar* source, but you don't need to do any development for now. 9 | 10 | The steps are: 11 | 12 | * :ref:`install-git` 13 | * get local copy of the git repository from github_ 14 | * update local copy from time to time 15 | 16 | Get the local copy of the code 17 | ============================== 18 | 19 | From the command line:: 20 | 21 | git clone git://github.com/matthew-brett/marsbar.git 22 | 23 | You now have a copy of the code tree in the new ``marsbar`` directory. 24 | 25 | Updating the code 26 | ================= 27 | 28 | From time to time you may want to pull down the latest code. Do this with:: 29 | 30 | cd marsbar 31 | git pull 32 | 33 | The tree in ``marsbar`` will now have the latest changes from the initial 34 | repository. 35 | 36 | .. include:: git_links.inc 37 | -------------------------------------------------------------------------------- /doc/source/development/gitwash/forking_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/development/gitwash/forking_button.png -------------------------------------------------------------------------------- /doc/source/development/gitwash/forking_hell.rst: -------------------------------------------------------------------------------- 1 | .. _forking: 2 | 3 | ========================================== 4 | Making your own copy (fork) of marsbar 5 | ========================================== 6 | 7 | You need to do this only once. The instructions here are very similar 8 | to the instructions at http://help.github.com/forking/ - please see that 9 | page for more detail. We're repeating some of it here just to give the 10 | specifics for the marsbar_ project, and to suggest some default names. 11 | 12 | Set up and configure a github_ account 13 | ====================================== 14 | 15 | If you don't have a github_ account, go to the github_ page, and make one. 16 | 17 | You then need to configure your account to allow write access - see the 18 | ``Generating SSH keys`` help on `github help`_. 19 | 20 | Create your own forked copy of marsbar_ 21 | ========================================= 22 | 23 | #. Log into your github_ account. 24 | #. Go to the marsbar_ github home at `marsbar github`_. 25 | #. Click on the *fork* button: 26 | 27 | .. image:: forking_button.png 28 | 29 | Now, after a short pause and some 'Hardcore forking action', you 30 | should find yourself at the home page for your own forked copy of marsbar_. 31 | 32 | .. include:: git_links.inc 33 | 34 | -------------------------------------------------------------------------------- /doc/source/development/gitwash/git_development.rst: -------------------------------------------------------------------------------- 1 | .. _git-development: 2 | 3 | ===================== 4 | Git for development 5 | ===================== 6 | 7 | Contents: 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | forking_hell 13 | set_up_fork 14 | configure_git 15 | development_workflow 16 | 17 | -------------------------------------------------------------------------------- /doc/source/development/gitwash/git_install.rst: -------------------------------------------------------------------------------- 1 | .. _install-git: 2 | 3 | ============= 4 | Install git 5 | ============= 6 | 7 | Overview 8 | ======== 9 | 10 | ================ ============= 11 | Debian / Ubuntu ``sudo apt-get install git-core`` 12 | Fedora ``sudo yum install git-core`` 13 | Windows Download and install msysGit_ 14 | OS X Use the git-osx-installer_ 15 | ================ ============= 16 | 17 | In detail 18 | ========= 19 | 20 | See the git_ page for the most recent information. 21 | 22 | Have a look at the github_ install help pages available from `github help`_ 23 | 24 | There are good instructions here: http://book.git-scm.com/2_installing_git.html 25 | 26 | .. include:: git_links.inc 27 | -------------------------------------------------------------------------------- /doc/source/development/gitwash/git_intro.rst: -------------------------------------------------------------------------------- 1 | ============== 2 | Introduction 3 | ============== 4 | 5 | These pages describe a git_ and github_ workflow for the marsbar_ 6 | project. 7 | 8 | There are several different workflows here, for different ways of 9 | working with *marsbar*. 10 | 11 | This is not a comprehensive git_ reference, it's just a workflow for our 12 | own project. It's tailored to the github_ hosting service. You may well 13 | find better or quicker ways of getting stuff done with git_, but these 14 | should get you started. 15 | 16 | For general resources for learning git_ see :ref:`git-resources`. 17 | 18 | .. include:: git_links.inc 19 | -------------------------------------------------------------------------------- /doc/source/development/gitwash/index.rst: -------------------------------------------------------------------------------- 1 | .. _using-git: 2 | 3 | Working with *marsbar* source code 4 | ====================================== 5 | 6 | Contents: 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | 11 | git_intro 12 | git_install 13 | following_latest 14 | patching 15 | git_development 16 | git_resources 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/source/development/gitwash/pull_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/development/gitwash/pull_button.png -------------------------------------------------------------------------------- /doc/source/development/index.rst: -------------------------------------------------------------------------------- 1 | ================================== 2 | Reading and writing MarsBaR code 3 | ================================== 4 | 5 | Contents: 6 | 7 | .. toctree:: 8 | :maxdepth: 2 9 | 10 | code 11 | apidocs 12 | 13 | -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. marsbar documentation master file, created by 2 | sphinx-quickstart on Sat Jul 4 17:12:59 2009. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | ============================================ 7 | MarsBaR region of interest toolbox for SPM 8 | ============================================ 9 | 10 | MarsBaR (MARSeille Boîte À Région d'Intérêt) is a toolbox for 11 | `SPM`_ which provides routines for region of interest analysis. 12 | Features include region of interest definition, combination of 13 | regions of interest with simple algebra, extraction of data for 14 | regions with and without SPM preprocessing (scaling, filtering), and 15 | statistical analyses of ROI data using the SPM statistics machinery. 16 | 17 | 18 | .. only:: html 19 | 20 | :Release: |version| 21 | :Date: |today| 22 | 23 | Download `MarsBaR documentation as PDF `_ 24 | 25 | .. toctree:: 26 | :maxdepth: 2 27 | 28 | about 29 | download 30 | tutorial/index 31 | faq 32 | support 33 | development/index 34 | 35 | Indices and tables 36 | ================== 37 | 38 | * :ref:`genindex` 39 | * :ref:`search` 40 | 41 | .. include:: links_names.txt 42 | -------------------------------------------------------------------------------- /doc/source/links_names.txt: -------------------------------------------------------------------------------- 1 | .. This (-*- rst -*-) format file contains commonly used link targets 2 | and name substitutions. It may be included in many files, 3 | therefore it should only contain link targets and name 4 | substitutions. Try grepping for "^\.\. _" to find plausible 5 | candidates for this list. 6 | 7 | .. NOTE: reST targets are 8 | __not_case_sensitive__, so only one target definition is needed for 9 | nipy, NIPY, Nipy, etc... 10 | 11 | .. _`SPM`: http://www.fil.ion.ucl.ac.uk/spm 12 | .. _`marsbar hbm abstract`: https://matthew.dynevor.org/research/abstracts/marsbar/marsbar_abstract.pdf 13 | .. _`MarsBaR project download page`: https://github.com/marsbar-toolbox/marsbar/releases 14 | .. _`MarsBaR example data download page`: https://github.com/marsbar-toolbox/marsbar-example-data/releases 15 | .. _`MarsBaR AAL download page`: https://github.com/marsbar-toolbox/marsbar-aal-rois/releases 16 | .. _`m2html`: http://www.artefact.tk/software/matlab/m2html/ 17 | .. _`MarsBaR users mailing list`: https://lists.sourceforge.net/lists/listinfo/marsbar-users 18 | .. _`MarsBaR mailing list archive`: http://sourceforge.net/mailarchive/forum.php?forum_name=marsbar-users 19 | .. _`MarsBaR Github discussions`: https://github.com/marsbar-toolbox/marsbar/discussions 20 | .. _`Gmane`: http://gmane.org/ 21 | .. _`SourceForge`: http://sourceforge.net 22 | .. _`mricro`: http://www.mricro.com/ 23 | 24 | .. _`marsbar github`: http://github.com/matthew-brett/marsbar 25 | -------------------------------------------------------------------------------- /doc/source/support.rst: -------------------------------------------------------------------------------- 1 | .. _support: 2 | 3 | Support 4 | ~~~~~~~ 5 | 6 | We hope it is clear how to use MarsBaR, but please let us know if you 7 | have problems. In particular, we would be very glad to hear of any 8 | bugs or inconsistencies. 9 | 10 | You can ask questions or start discussions at `MarsBaR Github discussions`_. 11 | 12 | There is a mailing list for MarsBaR; list archives and instructions 13 | for posting are available via the `MarsBaR users mailing list`_ page. 14 | There is also a `MarsBaR mailing list archive`_. 15 | 16 | .. include:: links_names.txt 17 | -------------------------------------------------------------------------------- /doc/source/tutorial/fig/data_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/data_menu.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/define_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/define_menu.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/defining_contrast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/defining_contrast.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/design_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/design_menu.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/main_marsbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/main_marsbar.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/results_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/results_menu.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/roi_build.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/roi_build.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/roi_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/roi_view.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/spm_buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/spm_buttons.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/spm_graphics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/spm_graphics.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/spm_input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/spm_input.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/spm_run2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/spm_run2.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/spm_select.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/spm_select.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/uigetfile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/uigetfile.png -------------------------------------------------------------------------------- /doc/source/tutorial/fig/write_rois_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/doc/source/tutorial/fig/write_rois_menu.png -------------------------------------------------------------------------------- /doc/source/tutorial/index.rst: -------------------------------------------------------------------------------- 1 | .. _tutorial: 2 | 3 | ================ 4 | MarsBaR tutorial 5 | ================ 6 | 7 | This is a short introduction to MarsBaR, a region of interest toolbox 8 | for SPM. It takes the form of a guided tour, showing the usage of 9 | MarsBaR with a standard dataset. 10 | 11 | The tutorial assumes you have some experience using SPM_ 12 | 13 | .. toctree:: 14 | :maxdepth: 2 15 | 16 | gettingstarted 17 | interface 18 | define 19 | estimate 20 | results 21 | andmore 22 | 23 | .. include:: ../links_names.txt 24 | -------------------------------------------------------------------------------- /doc/source/tutorial/interface.rst: -------------------------------------------------------------------------------- 1 | The MarsBaR / SPM interface 2 | --------------------------- 3 | 4 | Let's begin by naming the windows used by SPM and MarsBaR. After you have 5 | started SPM and MarsBaR, you should have the following set of windows: 6 | 7 | The MarsBaR window: 8 | 9 | .. image:: fig/main_marsbar.png 10 | 11 | Then, at the top left of the screen, the SPM buttons window 12 | 13 | .. image:: fig/spm_buttons.png 14 | 15 | Underneath the SPM buttons window, at the bottom left of the screen, is 16 | the SPM input window: 17 | 18 | .. image:: fig/spm_input.png 19 | 20 | SPM and MarsBaR use this window to get input from you, gentle user, such as 21 | text, numbers, or menu choices. Usually on the right hand side of the screen, 22 | there is the SPM graphics window: 23 | 24 | .. image:: fig/spm_graphics.png 25 | 26 | which is used to display results and other graphics. 27 | 28 | When SPM and MarsBaR want file or directory names from you, they may use 29 | the file selection window: 30 | 31 | .. image:: fig/spm_select.png 32 | 33 | Sometimes MarsBaR does not use the SPM selection dialog above, but the 34 | standard Matlab dialog, that will differ for each platform (linux, 35 | windows, mac). Here's a linux version: 36 | 37 | .. image:: fig/uigetfile.png 38 | 39 | -------------------------------------------------------------------------------- /gui_data_test.m: -------------------------------------------------------------------------------- 1 | % Run GUI tests that depend on estimations from data_test.m script 2 | % Please run data_test before this script 3 | cwd = pwd; 4 | addpath(fullfile(cwd, 'marsbar')); 5 | % Activate marsbar for correct spm_get routine 6 | marsbar('on'); 7 | % Get location of data from environment variable 8 | subjroot = getenv('MARSBAR_EG_DATAPATH'); 9 | % Otherwise fetch via the GUI 10 | if isempty(subjroot) 11 | subjroot = spm_get(-1, '', 'Root directory of example data'); 12 | setenv('MARSBAR_EG_DATAPATH', subjroot); 13 | end 14 | % Collect designs for test_rig 15 | spm_ver = spm('ver'); 16 | sdirname = [spm_ver '_ana']; 17 | if strcmp(spm_ver, 'SPM99') 18 | conf_design_name = 'SPMcfg.mat'; 19 | else 20 | conf_design_name = 'SPM.mat'; 21 | end 22 | design = fullfile(subjroot, 'sess1', sdirname, conf_design_name); 23 | if ~exist(design, 'file') 24 | error(sprintf('Missing design at %s', design)) 25 | end 26 | % Check that fill works 27 | D = mardo(design); 28 | D2 = fill(D, {'images'}) 29 | -------------------------------------------------------------------------------- /marsbar/@mardo/adjusted_data.m: -------------------------------------------------------------------------------- 1 | function Ya = adjusted_data(D, Ic) 2 | % Return adjusted data for estimated design and contrast no 3 | % FORMAT Ya = adjusted_data(D, Ic) 4 | % 5 | % D - Estimated marsbar design 6 | % Ic - Contrast number to adjust for 7 | % 8 | % Outputs 9 | % Ya - Adjusted data, N by M, where N is number of time points 10 | % and M is number of regions in estimated marsbar design 11 | % 12 | % e.g 13 | % E = estimate(D, Y); 14 | % [E Ic] = add_contrasts(E, 'task', 'T', [1 0 0]); 15 | % Ya = adjusted_data(E, Ic); 16 | % 17 | % Matthew Brett 18 | 19 | if nargin < 2 20 | error('Need contrast number'); 21 | end 22 | if nargin < 3 23 | r_no = 1; 24 | end 25 | Ya = []; 26 | if ~is_mars_estimated(D) 27 | error('Need a MarsBaR estimated design'); 28 | end 29 | 30 | SPM = des_struct(D); 31 | B = betas(D); 32 | xCon = get_contrasts(D); 33 | Ya = spm_FcUtil('Yc', xCon(Ic),SPM.xX.xKXs, B); 34 | -------------------------------------------------------------------------------- /marsbar/@mardo/betas.m: -------------------------------------------------------------------------------- 1 | function r = betas(o) 2 | % method to get estimated betas 3 | % 4 | % $Id$ 5 | 6 | if ~is_mars_estimated(o) 7 | error('No betas, model not estimated'); 8 | end 9 | SPM = des_struct(o); 10 | r = SPM.betas; 11 | -------------------------------------------------------------------------------- /marsbar/@mardo/block_mean_cols.m: -------------------------------------------------------------------------------- 1 | function bmrs = block_mean_rows(D) 2 | % method returns rows for means for blocks in design 3 | % 4 | % $Id$ 5 | 6 | bmrs = []; 7 | SPM = des_struct(D); 8 | bmrs = SPM.xX.iB; 9 | 10 | -------------------------------------------------------------------------------- /marsbar/@mardo/block_means.m: -------------------------------------------------------------------------------- 1 | function bms = block_means(D) 2 | % method returns means for blocks in design 3 | % 4 | % Inputs 5 | % D - design object 6 | % 7 | % Outputs 8 | % bms - means over block. Returns B x N matrix 9 | % where B is number of blocks, and N is number 10 | % of ROIs 11 | % 12 | % $Id$ 13 | 14 | Y = data(D); 15 | if isempty(Y) 16 | error('Design does not yet have data'); 17 | end 18 | bms = summary_block_means(data(D)); 19 | 20 | 21 | -------------------------------------------------------------------------------- /marsbar/@mardo/contrasts.m: -------------------------------------------------------------------------------- 1 | function r = contrasts(o, xcon) 2 | % method to get or set contrasts 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | r = get_contrasts(o); 8 | else 9 | % Always refreshes the contrasts for safety 10 | r = set_contrasts(o, xcon); 11 | end 12 | -------------------------------------------------------------------------------- /marsbar/@mardo/data.m: -------------------------------------------------------------------------------- 1 | function r = data(o, Y) 2 | % method to get or set data object 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | r = get_data(o); 8 | else 9 | r = set_data(o, Y); 10 | end -------------------------------------------------------------------------------- /marsbar/@mardo/des_struct.m: -------------------------------------------------------------------------------- 1 | function res = des_struct(obj, Struct) 2 | % get/set method for des_struct field 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.des_struct = Struct; 8 | res = obj; 9 | else 10 | res = obj.des_struct; 11 | end -------------------------------------------------------------------------------- /marsbar/@mardo/descrip.m: -------------------------------------------------------------------------------- 1 | function strs = descrip(D) 2 | % method gets cell string description of design 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | strs = {'Not specified'}; 8 | if ~isfield(SPM, 'xsDes'); 9 | return 10 | end 11 | strs = mars_struct('celldisp', SPM.xsDes); -------------------------------------------------------------------------------- /marsbar/@mardo/design_matrix.m: -------------------------------------------------------------------------------- 1 | function X = design_matrix(D) 2 | % method returns design matrix from design 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | X = mars_struct('getifthere', SPM, 'xX', 'X'); 8 | -------------------------------------------------------------------------------- /marsbar/@mardo/design_structure.m: -------------------------------------------------------------------------------- 1 | function r = design_structure(o, xX) 2 | % method to get or set SPM design structure 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(o); 7 | if nargin < 2 8 | r = mars_struct('getifthere', SPM, 'xX'); 9 | else 10 | SPM.xX = xX; 11 | r = des_struct(o, SPM); 12 | end -------------------------------------------------------------------------------- /marsbar/@mardo/display.m: -------------------------------------------------------------------------------- 1 | function display(obj) 2 | % display method for mardo objects 3 | % 4 | % $Id$ 5 | 6 | src = ['[' class(obj) ' design object]']; 7 | if length(obj) > 1 % array of objects 8 | sz = size(obj); 9 | src = sprintf('%d by %d array of %s', sz(1), sz(2), src); 10 | if isequal(get(0,'FormatSpacing'),'compact') 11 | disp([inputname(1) ' =']); 12 | disp(src); 13 | else 14 | disp(' ') 15 | disp([inputname(1) ' =']); 16 | disp(' '); 17 | disp(src); 18 | disp(' '); 19 | end 20 | else % single object 21 | X = char(summary(obj)); 22 | if isequal(get(0,'FormatSpacing'),'compact') 23 | disp([inputname(1) ' =']); 24 | disp(src); 25 | disp(X) 26 | else 27 | disp(' ') 28 | disp([inputname(1) ' =']); 29 | disp(' '); 30 | disp(src); 31 | disp(' '); 32 | disp(X) 33 | disp(' '); 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /marsbar/@mardo/error_df.m: -------------------------------------------------------------------------------- 1 | function e = error_df(D) 2 | % method returns error df from design 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | e = mars_struct('getifthere', SPM, 'xX', 'erdf'); 8 | -------------------------------------------------------------------------------- /marsbar/@mardo/event_fitted.m: -------------------------------------------------------------------------------- 1 | function [tc, dt] = event_fitted(D, e_spec, dur) 2 | % method to compute fitted event time course 3 | % FORMAT [tc dt] = event_fitted(D, e_spec, dur) 4 | % 5 | % D - design 6 | % e_spec - 2 by N array specifying events to combine 7 | % with row 1 giving session number 8 | % and row 2 giving event number in session 9 | % This may in due course become an object type 10 | % dur - duration in seconds of event to estimate for 11 | % 12 | % Returns 13 | % tc - fitted event time course, averaged over events 14 | % dt - time units (seconds per row in X) 15 | % 16 | % $Id$ 17 | 18 | if nargin < 2 19 | error('Need event specification'); 20 | end 21 | if nargin < 3 22 | dur = 0; 23 | end 24 | 25 | if ~is_fmri(D) | isempty(e_spec) 26 | tc = []; 27 | return 28 | end 29 | if ~is_mars_estimated(D) 30 | error('Need a MarsBaR estimated design'); 31 | end 32 | if size(e_spec, 1) == 1, e_spec = e_spec'; end 33 | 34 | e_s_l = size(e_spec, 2); 35 | SPM = des_struct(D); 36 | betas = SPM.betas; 37 | tc = zeros(1, size(betas, 2)); 38 | for e_i = 1:e_s_l 39 | es = e_spec(:, e_i); 40 | ss = es(1); 41 | [X dt]= event_regressor(D, es, dur); 42 | B = betas(event_cols(D, es), :); 43 | Yh = X*B; 44 | 45 | % Sum over events 46 | sz = size(Yh, 1); 47 | szo = size(tc, 1); 48 | if sz > szo 49 | tc(end+1:sz, :) = 0; 50 | end 51 | tc(1:sz,:) = tc(1:sz,:) + Yh; 52 | 53 | end 54 | tc = tc / e_s_l; -------------------------------------------------------------------------------- /marsbar/@mardo/event_types.m: -------------------------------------------------------------------------------- 1 | function res = event_types(D, et) 2 | % method to get / set event types for design 3 | % FORMAT et = event_types(D) 4 | % to return event types for design 5 | % 6 | % FORMAT D = event_types(D, et) 7 | % to set event types for design 8 | % 9 | % $Id$ 10 | 11 | SPM = des_struct(D); 12 | if nargin < 2 13 | % get 14 | res = mars_struct('getifthere', SPM, 'event_types'); 15 | else 16 | % set 17 | SPM.event_types = et; 18 | res = des_struct(D, SPM); 19 | end -------------------------------------------------------------------------------- /marsbar/@mardo/event_types_named.m: -------------------------------------------------------------------------------- 1 | function et = event_types_named(D) 2 | % method returns event types structures for events with same names 3 | % FORMAT et = event_types_named(D) 4 | % 5 | % $Id$ 6 | 7 | [e_s enames] = event_specs(D); 8 | 9 | ets = unique(enames); 10 | 11 | for e = 1:length(ets) 12 | et(e).name = ets{e}; 13 | in_evs = ismember(enames, ets{e}); 14 | et(e).e_spec = e_s(:, in_evs); 15 | end 16 | -------------------------------------------------------------------------------- /marsbar/@mardo/flip_images.m: -------------------------------------------------------------------------------- 1 | function o = flip_images(o) 2 | % flips images in design 3 | % 4 | % $Id$ 5 | 6 | if ~has_images(o), return, end 7 | VY = get_images(o); 8 | M = diag([-1 1 1 1]); 9 | for i = 1:length(VY) 10 | VY(i).mat = M * VY(i).mat; 11 | end 12 | o = set_images(o, VY); 13 | -------------------------------------------------------------------------------- /marsbar/@mardo/flip_option.m: -------------------------------------------------------------------------------- 1 | function res = flip_option(obj, data) 2 | % get/set flag for flipping images in design 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.flip_option = data; 8 | res = obj; 9 | else 10 | res = obj.flip_option; 11 | end -------------------------------------------------------------------------------- /marsbar/@mardo/full_vol.m: -------------------------------------------------------------------------------- 1 | function V = full_vol(D, imgs) 2 | % returns vol with full path, from vols, or image names 3 | % FORMAT V = full_vol(D, imgs) 4 | % 5 | % Input 6 | % D - mardo design object 7 | % imgs - image names or vol structs 8 | % 9 | % Output 10 | % V - vol structs with full path names 11 | % 12 | % If the filename for the image does not exist, the routine returns an 13 | % empty vol struct - which has the filename set, but all other fields are 14 | % empty 15 | % 16 | % $Id$ 17 | 18 | if nargin < 2 19 | error('Need image information'); 20 | end 21 | 22 | Swd = swd(D); 23 | if isempty(Swd) 24 | error('Need directory of design; it is missing'); 25 | end 26 | 27 | def_struct = mars_vol_utils('def_vol'); 28 | 29 | if isempty(imgs) 30 | V = def_struct; 31 | return 32 | end 33 | 34 | if iscell(imgs) 35 | imgs = char(imgs); 36 | end 37 | if isstruct(imgs) % vol struct, check for absolute path name 38 | V = imgs; 39 | nimgs = prod(size(imgs)); 40 | for i = 1:nimgs 41 | fname = V(i).fname; 42 | if ~mars_utils('isabspath', fname); 43 | fname = fullfile(Swd, fname); 44 | end 45 | V(i).fname = fname; 46 | end 47 | elseif ischar(imgs) 48 | for i = 1:size(imgs, 1) 49 | fname = deblank(imgs(i,:)); 50 | if ~mars_utils('isabspath', fname) 51 | fname = fullfile(Swd, fname); 52 | end 53 | if exist(fname, 'file') 54 | V(i) = spm_vol(fname); 55 | else 56 | V(i).fname = fname; 57 | end 58 | end 59 | else 60 | error('Odd input format for images'); 61 | end 62 | 63 | -------------------------------------------------------------------------------- /marsbar/@mardo/get_contrast_by_name.m: -------------------------------------------------------------------------------- 1 | function [xc, ic] = get_contrast_by_name(D, cname) 2 | % get named contrast(s) from design contrast structure 3 | % FORMAT [xc, ic] = get_contrast_by_name(D, cname) 4 | % 5 | % D - design object 6 | % cname - contrast name(s) (string or cell array) 7 | % 8 | % Returns 9 | % xc - xCon structure containing only named contrast 10 | % ic - index of contrast in design contrast structure 11 | % 12 | % e.g. [con ic] = get_named_contrasts(D, 'effects of interest'); 13 | % 14 | % $Id$ 15 | 16 | if nargin < 2 17 | error('Need contrast name(s)'); 18 | end 19 | if ischar(cname) 20 | cname = cellstr(cname); 21 | end 22 | 23 | xc = get_contrasts(D); 24 | if isempty(xc) 25 | ic = []; 26 | else 27 | ic = find(ismember({xc(:).name}, cname)); 28 | end 29 | xc = xc(ic); -------------------------------------------------------------------------------- /marsbar/@mardo/get_contrasts.m: -------------------------------------------------------------------------------- 1 | function xCon = get_contrasts(D) 2 | % method to get contrasts from design object 3 | % FORMAT xCon = get_contrasts(D) 4 | % 5 | % Returns contrast structure from design 6 | % See ui_get_contrasts for UI to get individual contrasts 7 | % 8 | % $Id$ 9 | 10 | SPM = des_struct(D); 11 | xCon = mars_struct('getifthere', SPM, 'xCon'); 12 | -------------------------------------------------------------------------------- /marsbar/@mardo/get_data.m: -------------------------------------------------------------------------------- 1 | function d = get_data(D) 2 | % method to get data from design object 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | d = []; 8 | if isfield(SPM, 'marsY') 9 | d = SPM.marsY; 10 | end -------------------------------------------------------------------------------- /marsbar/@mardo/get_vol_field.m: -------------------------------------------------------------------------------- 1 | function V = get_vol_field(D, fieldn) 2 | % method to get named field, containing or referring to vol structs 3 | % FORMAT V = get_vol_field(D, fieldn) 4 | % 5 | % D - design object 6 | % fieldn - field name 7 | % 8 | % Returns 9 | % V - vol struct 10 | % 11 | % e.g Vbeta = get_vol_field(D, 'Vbeta'); 12 | % 13 | % We need to deal with the fact that vol fields can be char or vol_structs. 14 | % SPM99, for good reason, stored the design structs from the results of the 15 | % estimation as file names, which then had to be remapped with spm_vol to 16 | % get the vol structs. The good reason was that this avoided 17 | % byte-swapping problems if the design was copied to another system. 18 | % 19 | % $Id$ 20 | 21 | if nargin < 2 22 | error('Need field name'); 23 | end 24 | 25 | SPM = des_struct(D); 26 | if ~isfield(SPM, fieldn) 27 | error([ fieldn ' is not a field in design']); 28 | end 29 | V = getfield(SPM, fieldn); 30 | V = full_vol(D, V); 31 | -------------------------------------------------------------------------------- /marsbar/@mardo/has_contrasts.m: -------------------------------------------------------------------------------- 1 | function tf = has_contrasts(D) 2 | % method returns 1 if design has contrasts 3 | % 4 | % $Id$ 5 | 6 | tf = isfield(des_struct(D), 'xCon'); -------------------------------------------------------------------------------- /marsbar/@mardo/has_filter.m: -------------------------------------------------------------------------------- 1 | function tf = has_filter(o) 2 | % returns 1 if object contains filter 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | des = des_struct(o); 8 | if isfield(des, 'xX') 9 | tf = isfield(des.xX, 'K'); 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo/has_images.m: -------------------------------------------------------------------------------- 1 | function tf = has_images(o) 2 | % returns 1 if design contains images, NaN if not known 3 | % 4 | % $Id$ 5 | 6 | tf = NaN; -------------------------------------------------------------------------------- /marsbar/@mardo/has_whitener.m: -------------------------------------------------------------------------------- 1 | function tf = has_whitener(D) 2 | % returns 1 if design has whitening filter 3 | % 4 | % $Id$ 5 | 6 | % Which is not the case for default, SPM99 designs 7 | tf = 0; -------------------------------------------------------------------------------- /marsbar/@mardo/image_names.m: -------------------------------------------------------------------------------- 1 | function P = image_names(D) 2 | % method returning image file names for design 3 | % Returns cell array of same dimension of image list 4 | % 5 | % $Id$ 6 | 7 | P = {}; 8 | if has_images(D) 9 | VY = get_images(D); 10 | P = reshape({VY.fname},size(VY)); 11 | end -------------------------------------------------------------------------------- /marsbar/@mardo/images.m: -------------------------------------------------------------------------------- 1 | function r = images(o, imgs) 2 | % method to get or set images 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | r = get_images(o); 8 | else 9 | r = set_images(o, imgs); 10 | end -------------------------------------------------------------------------------- /marsbar/@mardo/is_fmri.m: -------------------------------------------------------------------------------- 1 | function tf = is_fmri(D) 2 | % method returns 1 if this is an fmri design 3 | % 4 | % $Id$ 5 | 6 | tf = strcmp(modality(D), 'fmri'); -------------------------------------------------------------------------------- /marsbar/@mardo/is_mars_estimated.m: -------------------------------------------------------------------------------- 1 | function tf = is_mars_estimated(D) 2 | % method returns 1 if design has been estimated in MarsBaR 3 | % 4 | % $Id$ 5 | 6 | tf = isfield(D.des_struct, 'marsY'); -------------------------------------------------------------------------------- /marsbar/@mardo/is_marsed.m: -------------------------------------------------------------------------------- 1 | function tf = is_marsed(o) 2 | % returns 1 if design has been processed with MarsBaR 3 | tf = isfield(o.des_struct, 'xMars'); 4 | -------------------------------------------------------------------------------- /marsbar/@mardo/is_spm_estimated.m: -------------------------------------------------------------------------------- 1 | function tf = is_spm_estimated(D) 2 | % returns 1 if design has been estimated in SPM 3 | % 4 | % $Id$ 5 | 6 | tf = isfield(D.des_struct, 'VResMS'); -------------------------------------------------------------------------------- /marsbar/@mardo/is_valid.m: -------------------------------------------------------------------------------- 1 | function tf = is_valid(o) 2 | % returns 1 if object contains valid SPM/MarsBaR design 3 | % 4 | % $Id$ 5 | 6 | tf = isfield(des_struct(o), 'xX'); 7 | -------------------------------------------------------------------------------- /marsbar/@mardo/isempty.m: -------------------------------------------------------------------------------- 1 | function tf = isempty(o) 2 | % overloaded isempty method for mardo object 3 | % 4 | % $Id$ 5 | 6 | tf = isempty(o.des_struct); 7 | -------------------------------------------------------------------------------- /marsbar/@mardo/isfield.m: -------------------------------------------------------------------------------- 1 | function result = isfield(this, fieldn) 2 | % method to overload isfield for mardo objects 3 | % isfield for mardo objects replies according to the contents of 4 | % the des_struct field 5 | % 6 | % $Id$ 7 | 8 | result =isfield(this.des_struct, fieldn); -------------------------------------------------------------------------------- /marsbar/@mardo/mars_tag.m: -------------------------------------------------------------------------------- 1 | function res = mars_tag(o, data) 2 | % returns, or sets, Mars tagging structure in design 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 % set 7 | res = o; 8 | res.des_struct.xMars = data; 9 | return 10 | end 11 | 12 | if isfield(o.des_struct, 'xMars') % get 13 | res = o.des_struct.xMars; 14 | else 15 | res = []; 16 | end 17 | -------------------------------------------------------------------------------- /marsbar/@mardo/marsy_data.m: -------------------------------------------------------------------------------- 1 | function r = marsy_data(o, Y) 2 | % method to get or set marsy data 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | r = get_data(o); 8 | else 9 | r = set_data(o, Y); 10 | end -------------------------------------------------------------------------------- /marsbar/@mardo/masking_struct.m: -------------------------------------------------------------------------------- 1 | function r = masking_struct(o, xM) 2 | % method to get or set SPM masking structure 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(o); 7 | if nargin < 2 8 | r = mars_struct('getifthere', SPM, 'xM'); 9 | else 10 | SPM.xM = xM; 11 | r = des_struct(o, SPM); 12 | end -------------------------------------------------------------------------------- /marsbar/@mardo/modality.m: -------------------------------------------------------------------------------- 1 | function mod_str = modality(D) 2 | % method returns modality of design 3 | % 4 | % $Id$ 5 | 6 | mod_str = 'unknown'; 7 | -------------------------------------------------------------------------------- /marsbar/@mardo/n_effects.m: -------------------------------------------------------------------------------- 1 | function n = n_effects(o) 2 | % get number of effects (columns) in design 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(o); 7 | n = size(SPM.xX.X, 2); -------------------------------------------------------------------------------- /marsbar/@mardo/n_time_points.m: -------------------------------------------------------------------------------- 1 | function n = n_time_points(o) 2 | % get number of time_points in design 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(o); 7 | n = size(SPM.xX.X, 1); -------------------------------------------------------------------------------- /marsbar/@mardo/native_vol_ver.m: -------------------------------------------------------------------------------- 1 | function res = native_vol_ver(obj) 2 | % return string specifying native vol type 3 | % 4 | % $Id: verbose.m 87 2004-01-06 01:48:35Z matthewbrett $ 5 | 6 | res = '99'; -------------------------------------------------------------------------------- /marsbar/@mardo/paramfields.m: -------------------------------------------------------------------------------- 1 | function params = paramfields(o) 2 | % returns struct with fields from maroi object useful for copying objects 3 | % 4 | % $Id$ 5 | 6 | params = struct('des_struct', o.des_struct,... 7 | 'flip_option', o.flip_option,... 8 | 'verbose', o.verbose); -------------------------------------------------------------------------------- /marsbar/@mardo/private/pr_ev_diff.m: -------------------------------------------------------------------------------- 1 | function d = pr_ev_diff(ev_tc, diff_func, varargin) 2 | % method to calculate event height for % signal change 3 | % FORMAT d = pr_ev_diff(ev_tc, diff_func, varargin) 4 | % 5 | % Inputs 6 | % ev_tc - event time course 7 | % diff_func - difference function; one of 8 | % 'max' - the maximum of the time course 9 | % 'max-min' - the max minus the min 10 | % 'abs max' - if abs(max) > abs(min) => max otherwise => min 11 | % 'abs max-min' - if abs(max) > abs(min) => (max - min) 12 | % otherwise => (min - max) 13 | % 14 | % $Id$ 15 | 16 | if nargin < 2 17 | diff_func = ''; 18 | end 19 | if isempty(diff_func) 20 | diff_func = 'max'; 21 | end 22 | 23 | [m n] = size(ev_tc); 24 | d = zeros(1, n); 25 | switch lower(diff_func) 26 | case 'max' 27 | d = max(ev_tc, [], 1); 28 | case 'max-min' 29 | d = max(ev_tc, [], 1) - min(ev_tc, [], 1); 30 | case 'abs max' 31 | [d i] = max(abs(ev_tc), [], 1); 32 | for s = 1:n, d(s) = ev_tc(i(s), s); end 33 | case 'abs max-min' 34 | mx = max(ev_tc, [], 1); 35 | mn = min(ev_tc, [], 1); 36 | i = abs(mx) > abs(mn); 37 | d(i) = mx(i)-mn(i); 38 | d(~i) = mn(~i)-mx(~i); 39 | case 'window' 40 | if nargin < 4, error('Need window and dt'); end 41 | w = round(varargin{1} / varargin{2}) + 1; 42 | d = mean(ev_tc(w(1):w(2), :), 1); 43 | otherwise 44 | error(sprintf('What is this difference function: %s?', diff_func)); 45 | end 46 | -------------------------------------------------------------------------------- /marsbar/@mardo/private/pr_refresh_et.m: -------------------------------------------------------------------------------- 1 | function F = pr_refresh_et(D, ic, F, hList, hEdit) 2 | % Refreshes data and display of event type window after edit 3 | % FORMAT F = pr_refresh_et(D, ic, F, hList) 4 | % 5 | % D - design object 6 | % ic - indices to events to select 7 | % F - (optional) figure handle 8 | % hList - (optional) handle to list uicontrol 9 | % hEdit - (optional) handle to Edit uicontrol 10 | % 11 | % Returns 12 | % F - figure handle (in case you didn't have it) 13 | % 14 | % $Id$ 15 | 16 | if nargin < 1 17 | error('Need object'); 18 | end 19 | if nargin < 2 20 | ic = []; 21 | end 22 | if nargin < 3 23 | F = findobj(get(0, 'Children'), 'Flat', 'Tag', 'ui_event_types'); 24 | end 25 | if nargin < 4 26 | hList = findobj(F, 'Tag','eList'); 27 | end 28 | if nargin < 5 29 | hEdit = findobj(F, 'Tag','eEdit'); 30 | end 31 | 32 | if ~ishandle(F) 33 | error('Could not find ui_event_types window'); 34 | end 35 | 36 | et = event_types(D); 37 | 38 | % Event type list to put 39 | if isfield(et, 'name') 40 | eNames = {et(:).name}; 41 | else 42 | eNames = {}; 43 | end 44 | 45 | set(hList, 'String', eNames); 46 | set(hList, 'Value', ic); 47 | set(F, 'Userdata', D); 48 | set(hEdit, 'UserData', 1); -------------------------------------------------------------------------------- /marsbar/@mardo/private/pr_sort_evs.m: -------------------------------------------------------------------------------- 1 | function evs = pr_sort_evs(evs, sort_type, downf) 2 | % function to sort event according to sort type 3 | % FORMAT evs = pr_sort_evs(evs, sort_type, downf) 4 | % 5 | % evs - structure containing fields 6 | % 'names': names of events 7 | % 'e_spec': row1 = session row2 = event number 8 | % sort_type - one of 'session' 'event' 'name' 9 | % downf - 1 if descending sort, 0 otherwise (0 default) 10 | % 11 | % Returns 12 | % evs - sorted event structure 13 | % 14 | % $Id$ 15 | 16 | if nargin < 2 17 | error('Need event specs and sort type'); 18 | end 19 | if nargin < 3 20 | downf = 0; 21 | end 22 | 23 | e_s = [evs.e_spec]'; 24 | 25 | switch lower(sort_type) 26 | case {'session no', 'session'} 27 | [tmp I] = sortrows(e_s); 28 | case {'event no', 'event'} 29 | [tmp I] = sortrows(e_s, [2 1]); 30 | case {'event name', 'name'} 31 | [tmp I] = sort(evs.names); 32 | otherwise 33 | error(['Crazy sorting too much with ' sort_type]); 34 | end 35 | 36 | if downf, I = flipud(I); end 37 | 38 | evs.names = evs.names(I); 39 | evs.e_spec = evs.e_spec(:, I); 40 | 41 | return 42 | -------------------------------------------------------------------------------- /marsbar/@mardo/refresh_contrasts.m: -------------------------------------------------------------------------------- 1 | function o = refresh_contrasts(o) 2 | % method to refresh contrasts to match design 3 | o = set_contrasts(o, get_contrasts(o)); 4 | -------------------------------------------------------------------------------- /marsbar/@mardo/residuals.m: -------------------------------------------------------------------------------- 1 | function r = residuals(D) 2 | % method returns residuals from model 3 | % 4 | % $Id$ 5 | 6 | if ~is_mars_estimated(D) 7 | error('Need estimated model'); 8 | end 9 | Y = get_data(D); 10 | if ~is_summarized(Y) 11 | Y = resummarize(Y); 12 | end 13 | if ~is_summarized(Y) 14 | error('Cannot get summarized data from model data'); 15 | end 16 | y = summary_data(Y); 17 | 18 | if is_fmri(D) 19 | if ~has_filter(D) 20 | error('FMRI design lacks filter'); 21 | end 22 | y = apply_filter(D, y); 23 | end 24 | 25 | SPM = des_struct(D); 26 | r = marsy(spm_sp('r',SPM.xX.xKXs,y), ... 27 | region_name(Y), ... 28 | struct('info', summary_info(Y),... 29 | 'descrip', ['Residuals for ' summary_descrip(Y)],... 30 | 'block_rows', {block_rows(D)})); 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /marsbar/@mardo/savestruct.m: -------------------------------------------------------------------------------- 1 | function savestruct(obj, filename) 2 | % saves data in def_struct as variables in .mat file 3 | % FORMAT savestruct(object, matname) 4 | % 5 | % $Id$ 6 | 7 | if nargin ~= 2 8 | error('Need matfile name'); 9 | end 10 | 11 | % allow args to be in reverse order 12 | if ischar(obj) 13 | tmp = obj; 14 | obj = filename; 15 | filename = tmp; 16 | end 17 | 18 | % Convert vols to native format 19 | obj = convert_vols(obj, native_vol_ver(obj)); 20 | 21 | % unobjectify marsy object before save 22 | SPM = des_struct(obj); 23 | if isfield(SPM, 'marsY') 24 | SPM.marsY = y_struct(SPM.marsY); 25 | end 26 | savestruct(SPM, filename) 27 | 28 | return -------------------------------------------------------------------------------- /marsbar/@mardo/set_contrasts.m: -------------------------------------------------------------------------------- 1 | function D = set_contrasts(D, C, refreshf) 2 | % method to set contrasts into design object 3 | % 4 | % D - design 5 | % C - contrasts 6 | % C can be a contrast structure, or a structure containing 7 | % a contrast structure 8 | % refreshf - if 1 then refresh contrasts with respect to design matrix 9 | % structures in `D`. Default is 1 10 | % 11 | % Returns 12 | % D - design with contrasts set to C 13 | % 14 | % $Id$ 15 | 16 | if nargin < 2 17 | error('Need contrasts'); 18 | end 19 | if nargin < 3 20 | refreshf = 1; 21 | end 22 | if isfield(C, 'xCon'); 23 | C = C.xCon; 24 | end 25 | SPM = des_struct(D); 26 | if refreshf 27 | % Use add contrasts routine to refresh contrasts 28 | SPM.xCon = []; 29 | D = des_struct(D, SPM); 30 | D = add_contrasts(D, C); 31 | else % Hope for the best 32 | SPM.xCon = C; 33 | D = des_struct(D, SPM); 34 | end 35 | -------------------------------------------------------------------------------- /marsbar/@mardo/set_data.m: -------------------------------------------------------------------------------- 1 | function D = set_data(D, d) 2 | % method to set data for design object 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | SPM.marsY = marsy(d); 8 | D = des_struct(D, SPM); -------------------------------------------------------------------------------- /marsbar/@mardo/set_vol_field.m: -------------------------------------------------------------------------------- 1 | function D = set_vol_field(D, fieldn, imgs) 2 | % method to set named field, containing or referring to vol structs 3 | % FORMAT D = get_vol_field(D, fieldn, imgs) 4 | % 5 | % D - design object 6 | % fieldn - field name 7 | % imgs - image names or vol structs 8 | % 9 | % Returns 10 | % D - changed object 11 | % 12 | % e.g D = get_vol_field(D, 'Vbeta', Vbeta); 13 | % 14 | % We need to deal with the fact that vol fields can be char or vol_structs. 15 | % SPM99, for good reason, stored the design structs from the results of the 16 | % estimation as file names, which then had to be remapped with spm_vol to 17 | % get the vol structs. The good reason was that this avoided 18 | % byte-swapping problems if the design was copied to another system. 19 | % 20 | % $Id$ 21 | 22 | if nargin < 2 23 | error('Need field name'); 24 | end 25 | 26 | SPM = des_struct(D); 27 | 28 | V = design_vol(D, imgs); 29 | 30 | SPM = setfield(SPM, fieldn, V); 31 | D = des_struct(D, SPM); -------------------------------------------------------------------------------- /marsbar/@mardo/subsasgn.m: -------------------------------------------------------------------------------- 1 | function result = subsasgn(this, Struct, rhs) 2 | % method to overload . notation in assignments. 3 | % . assignment for mardo objects acts on the contents of des_struct 4 | % 5 | % $Id$ 6 | 7 | SPM = des_struct(this); 8 | SPM = builtin('subsasgn', SPM, Struct, rhs); 9 | result = des_struct(this, SPM); -------------------------------------------------------------------------------- /marsbar/@mardo/subsref.m: -------------------------------------------------------------------------------- 1 | function result = subsref(this, Struct) 2 | % method to overload the . notation. 3 | % . reference for mardo objects returns contents of des_struct 4 | % 5 | % $Id$ 6 | 7 | result = builtin('subsref', des_struct(this), Struct ); -------------------------------------------------------------------------------- /marsbar/@mardo/summary.m: -------------------------------------------------------------------------------- 1 | function strs = summary(D) 2 | % method returns cell array of strings describing design 3 | % 4 | % $Id$ 5 | 6 | strs{1} = sprintf('SPM working dir \t%s', swd(D)); 7 | strs{2} = sprintf('Design type: \t%s', type(D)); 8 | strs{3} = sprintf('Modality: \t%s', modality(D)); 9 | if is_fmri(D) 10 | tmp = sf_recode(has_filter(D)); 11 | else 12 | tmp = 'N/A'; 13 | end 14 | strs{4} = sprintf('Has filter?: \t%s', tmp); 15 | strs{5} = sprintf('Has images?: \t%s', ... 16 | sf_recode(has_images(D))); 17 | strs{6} = sprintf('MarsBaR estimated?:\t%s', ... 18 | sf_recode(is_mars_estimated(D))); 19 | strs = [strs {'Description:'}, descrip(D)]; 20 | 21 | return 22 | 23 | function str = sf_recode(tf) 24 | if isnan(tf), str = 'unknown'; 25 | elseif tf, str = 'yes'; 26 | else str = 'no'; 27 | end 28 | -------------------------------------------------------------------------------- /marsbar/@mardo/swd.m: -------------------------------------------------------------------------------- 1 | function res = swd(D, dir) 2 | % method to get/set design directory 3 | % FORMAT dir = swd(D); % get 4 | % FORMAT D = swd(D, dir); % set 5 | % 6 | % $Id$ 7 | 8 | SPM = des_struct(D); 9 | if nargin < 2 10 | res = mars_struct('getifthere', SPM, 'swd'); 11 | else 12 | SPM.swd = dir; 13 | res = des_struct(D, SPM); 14 | end -------------------------------------------------------------------------------- /marsbar/@mardo/swd_writable.m: -------------------------------------------------------------------------------- 1 | function tf = swd_writable(D) 2 | % returns true if swd directory can be written to 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | Swd = swd(D); 8 | if isempty(Swd), return, end 9 | 10 | test_file = fullfile(Swd, 'write_test.txt'); 11 | try 12 | save(test_file, 'test_file'); 13 | tf = 1; 14 | end 15 | if tf, delete(test_file); end -------------------------------------------------------------------------------- /marsbar/@mardo/type.m: -------------------------------------------------------------------------------- 1 | function str = type(o) 2 | % returns SPM version string corresponding to design type 3 | % 4 | % $Id$ 5 | 6 | str = 'Unknown'; -------------------------------------------------------------------------------- /marsbar/@mardo/ui_event_types_cb.m: -------------------------------------------------------------------------------- 1 | function varargout = ui_event_types_cb(D, action, varargin) 2 | % method to handle callbacks from ui_event_types 3 | % FORMAT varargout = ui_event_types_cb(D, action, varargin) 4 | % 5 | % $Id$ 6 | 7 | if nargin < 2 8 | error('Need action'); 9 | end 10 | 11 | et = event_types(D); 12 | F = gcbf; 13 | 14 | switch lower(action) 15 | case 'ok' 16 | set(findobj(F,'Tag','Done'),'UserData',1) 17 | case 'cancel' 18 | set(findobj(F,'Tag','Done'),'UserData',0) 19 | case 'new' 20 | e = struct('name', 'New event', 'e_spec', []); 21 | if isempty(et), et = e; else et = [et e]; end 22 | D = event_types(D, et); 23 | [D ic] = ui_et_edit(D, length(et)); 24 | if ~isempty(ic) % not cancelled 25 | pr_refresh_et(D, ic, F); 26 | end 27 | case 'edit' 28 | hList = findobj(F,'Tag','eList'); 29 | ic = get(hList, 'Value'); 30 | if isempty(ic) 31 | msgbox('Please select an event type to edit'); 32 | elseif length(ic) > 1 33 | msgbox('Please select a single event type to edit'); 34 | else 35 | et = event_types(D); 36 | [D ic] = ui_et_edit(D, ic); 37 | if ~isempty(ic) % not cancelled 38 | pr_refresh_et(D, ic, F, hList); 39 | end 40 | end 41 | case 'delete' 42 | hList = findobj(F,'Tag','eList'); 43 | ic = get(hList, 'Value'); 44 | if isempty(ic) 45 | msgbox('Please select event type(s) to delete'); 46 | else 47 | et(ic) = []; 48 | D = event_types(D, et); 49 | pr_refresh_et(D, 1, F, hList); 50 | end 51 | otherwise 52 | error([ action ' is deviant' ]); 53 | end 54 | 55 | return 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /marsbar/@mardo/unfiltered_efficiency.m: -------------------------------------------------------------------------------- 1 | function e = unfiltered_efficiency(D, Ic) 2 | % Calculate unfiltered efficiency for given SPM design and contrast 3 | 4 | if nargin < 2 5 | error('Need design and contrast number'); 6 | end 7 | if ~has_contrasts(D) 8 | error('Need design with contrasts'); 9 | end 10 | 11 | % Get contrast matrix to test for 12 | xCon = get_contrasts(D); 13 | con = xCon(Ic).c; 14 | 15 | X = design_matrix(D); 16 | e = 1 / trace(con' * pinv(X' * X) * con); 17 | return 18 | -------------------------------------------------------------------------------- /marsbar/@mardo/verbose.m: -------------------------------------------------------------------------------- 1 | function res = verbose(obj, data) 2 | % get/set method for verbose field 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.verbose = data; 8 | res = obj; 9 | else 10 | res = obj.verbose; 11 | end -------------------------------------------------------------------------------- /marsbar/@mardo_2/add_trial_f.m: -------------------------------------------------------------------------------- 1 | function [D, changef] = add_trial_f(D) 2 | % method to add trial-specific F contrasts 3 | % 4 | % D - design to put contrasts into 5 | % 6 | % Returns 7 | % D - design with any added contrasts 8 | % changef - set to 1 if any contrasts have been added 9 | % 10 | % The routine only adds contrasts that are not already present 11 | % 12 | % $Id$ 13 | 14 | if ~strcmp(modality(D), 'fmri') 15 | error('Can only set trial-specific F contrasts for FMRI designs'); 16 | end 17 | SPM = des_struct(D); 18 | xX = SPM.xX; 19 | [nScan nBeta] = size(xX.X); 20 | 21 | %-Append contrasts for fMRI - specified by SPM.Sess(s).Fc(i) 22 | %----------------------------------------------------------------------- 23 | xCon = []; 24 | if isfield(SPM,'Sess') 25 | for s = 1:length(SPM.Sess) 26 | for i = 1:length(SPM.Sess(s).Fc) 27 | iX0 = 1:nBeta; 28 | iX = SPM.Sess(s).col(SPM.Sess(s).Fc(i).i); 29 | iX0(iX) = []; 30 | Fcname = sprintf('Sess(%d):%s',s,SPM.Sess(s).Fc(i).name); 31 | xcon = spm_FcUtil('Set',Fcname,'F','iX0',iX0,xX.xKXs); 32 | xCon = [xCon xcon]; 33 | end 34 | end 35 | end 36 | [D Ic changef] = add_contrasts(D, xCon); -------------------------------------------------------------------------------- /marsbar/@mardo_2/bf_dt.m: -------------------------------------------------------------------------------- 1 | function d = bf_dt(D) 2 | % method returns length of time bin for basis functions 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | d = mars_struct('getifthere', SPM, 'xBF', 'dt'); 8 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/block_cols.m: -------------------------------------------------------------------------------- 1 | function cols = block_cols(D) 2 | % method gets design columns for block (session / subject) 3 | % FORMAT cols = block_cols(D) 4 | % 5 | % Returns cell array of column indices (one per session) 6 | % 7 | % $Id$ 8 | 9 | if ~is_fmri(D) 10 | error('Needs FMRI design'); 11 | end 12 | 13 | SPM = des_struct(D); 14 | cols = {SPM.Sess(:).col}; -------------------------------------------------------------------------------- /marsbar/@mardo_2/block_rows.m: -------------------------------------------------------------------------------- 1 | function rows = block_rows(D) 2 | % returns cell array of rows for each (subject/session) block 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | if strcmp(modality(D), 'fmri') 8 | Sess = SPM.Sess; 9 | rows = {Sess(:).row}; 10 | else % PET I guess 11 | xX = SPM.xX; 12 | if ~isfield(xX, 'I') 13 | error('Expecting I field in SPM design'); 14 | end 15 | scol = xX.I(:, 3); % the subject column 16 | subjnos = unique(scol); 17 | for s = 1:length(subjnos); 18 | rows{s} = find(scol == subjnos(s)); 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/can_mars_estimate.m: -------------------------------------------------------------------------------- 1 | function tf = can_mars_estimate(D) 2 | % method returns 1 if design can be estimated in MarsBaR 3 | % 4 | % $Id$ 5 | 6 | tf = ~is_fmri(D) | (has_filter(D) & has_autocorr(D)); 7 | 8 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/convert_vols.m: -------------------------------------------------------------------------------- 1 | function o = convert_vols(o, ver) 2 | % method that converts vol structs in design and converts to format 'ver' 3 | % FORMAT o = convert_fo(o, ver) 4 | % 5 | % Input 6 | % o - design object 7 | % ver - optional version for vols from '99' or '5' 8 | % Defaults to version for current SPM version 9 | % 10 | % Output 11 | % o - object with converted vols 12 | % 13 | % Example 14 | % % Convert vols to current format 15 | % o = convert_vols(o); 16 | % 17 | % % Convert to native format for SPM99 designs 18 | % o = convert_vols(o, native_vol_ver(o)); 19 | % 20 | % $Id$ 21 | 22 | if nargin < 2 23 | ver = mars_vol_utils('current_ver'); 24 | end 25 | 26 | SPM = des_struct(o); 27 | SPM = sf_conv(SPM, ver, 'xY', 'VY'); 28 | SPM = sf_conv(SPM, ver, 'xM', 'VM'); 29 | SPM = sf_conv(SPM, ver, 'xVol', 'VRpv'); 30 | SPM = sf_conv(SPM, ver, 'Vbeta'); 31 | SPM = sf_conv(SPM, ver, 'VResMS'); 32 | SPM = sf_conv(SPM, ver, 'VM'); 33 | o = des_struct(o, SPM); 34 | 35 | xCon = get_contrasts(o); 36 | if ~isempty(xCon) 37 | for i = 1:length(xCon) 38 | xCon(i) = sf_conv(xCon(i), ver, 'Vcon'); 39 | xCon(i) = sf_conv(xCon(i), ver, 'Vspm'); 40 | end 41 | end 42 | o = set_contrasts(o, xCon, 0); 43 | return 44 | 45 | function S = sf_conv(S, ver, varargin) 46 | V = mars_struct('getifthere', S, varargin{:}); 47 | if ~isempty(V) 48 | V = mars_vol_utils('convert', V, ver); 49 | S = setfield(S, varargin{:}, V); 50 | end 51 | return 52 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/design_vol.m: -------------------------------------------------------------------------------- 1 | function V = design_vol(D, imgs) 2 | % returns vols in appropriate format for saving in design 3 | % FORMAT V = design_vol(D, imgs) 4 | % 5 | % Input 6 | % D - mardo design object 7 | % imgs - image names or vol structs 8 | % 9 | % Output 10 | % V - paths relative to swd 11 | % 12 | % $Id$ 13 | 14 | if nargin < 2 15 | error('Need image information'); 16 | end 17 | 18 | if iscell(imgs) 19 | imgs = char(imgs); 20 | end 21 | if ischar(imgs) 22 | imgs = full_vol(D, imgs); 23 | end 24 | if isstruct(imgs) 25 | V = imgs; 26 | fnames = spm_str_manip(strvcat(imgs(:).fname), 't'); 27 | for i = 1:prod(size(imgs)) 28 | V(i).fname = deblank(fnames(i,:)); 29 | end 30 | else 31 | error('Odd input format for images'); 32 | end 33 | 34 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/event_cols.m: -------------------------------------------------------------------------------- 1 | function I = event_cols(D, e_spec) 2 | % method gets design columns for single event 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need design and event spec'); 8 | end 9 | if ~is_fmri(D) 10 | error('Needs FMRI design'); 11 | end 12 | 13 | SPM = des_struct(D); 14 | Sess = SPM.Sess; 15 | bf = SPM.xBF.bf; 16 | ss = e_spec(1); 17 | en = e_spec(2); 18 | I = Sess(ss).col(Sess(ss).Fc(en).i(1:size(bf,2))); 19 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/event_onsets.m: -------------------------------------------------------------------------------- 1 | function [onsets, durations] = event_onsets(D, e_spec) 2 | % method gets onsets and durations for event/session 3 | % FORMAT [onsets durations] = event_onsets(D, e_spec) 4 | % 5 | % D - design object 6 | % e_spec - event specification (see event_fitted for details) 7 | % 8 | % Returns 9 | % onsets - onset times in TRs 10 | % durations - duration of events in TRs 11 | % 12 | % $Id$ 13 | 14 | if nargin < 2 15 | error('Need design and event spec'); 16 | end 17 | if ~is_fmri(D) 18 | error('Needs FMRI design'); 19 | end 20 | if prod(size(e_spec)) > 2 21 | error('Can only deal with one event at a time'); 22 | end 23 | 24 | s = e_spec(1); 25 | e = e_spec(2); 26 | SPM = des_struct(D); 27 | 28 | U = SPM.Sess(s).U(e); 29 | onsets = U.ons; 30 | durations = U.dur; 31 | 32 | if strcmp(SPM.xBF.UNITS, 'secs') 33 | TR = tr(D); 34 | onsets = onsets / TR; 35 | durations = durations / TR; 36 | end 37 | 38 | if prod(size(durations)) == 1 39 | durations = ones(size(onsets)) * durations; 40 | end 41 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/event_regressor.m: -------------------------------------------------------------------------------- 1 | function [X, dt] = event_regressor(D, e_spec, dur) 2 | % method gets estimated regressor for single event 3 | % FORMAT [X dt] = event_regressor(D, e_spec, dur) 4 | % 5 | % D - design object 6 | % e_spec - event specification (see event_fitted for details) 7 | % dur - event duration in seconds (default = 0) 8 | % 9 | % Returns 10 | % X - event regressor for single event 11 | % (one column per basis function used to model event) 12 | % dt - time units (seconds per row in X) 13 | % 14 | % $Id$ 15 | 16 | if nargin < 2 17 | error('Need design and event spec'); 18 | end 19 | if nargin < 3 20 | dur = 0; 21 | end 22 | if ~is_fmri(D) 23 | error('Needs FMRI design'); 24 | end 25 | 26 | if size(e_spec, 1) == 1, e_spec = e_spec'; end 27 | 28 | SPM = des_struct(D); 29 | Sess = SPM.Sess; 30 | dt = SPM.xBF.dt; 31 | bf = SPM.xBF.bf; 32 | ss = e_spec(1); 33 | en = e_spec(2); 34 | 35 | if ~dur 36 | % SPM2 does a second's worth of spike for events without durations 37 | sf = 1/dt; 38 | else 39 | sf = ones(round(dur/dt), 1); 40 | end 41 | X = []; 42 | for b = 1:size(bf,2) 43 | X = [X conv(sf, bf(:,b))]; 44 | end 45 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/event_specs.m: -------------------------------------------------------------------------------- 1 | function [e_specs, e_names] = event_specs(D) 2 | % method to return event specifications for all event in model 3 | % FORMAT [e_specs, e_names] = event_specs(D) 4 | % 5 | % D - design object 6 | % 7 | % Returns 8 | % e_specs - event specification 2 by N matrix where row 1 is the 9 | % session number of the event, row 2 is the event number in 10 | % the session 11 | % 12 | % e_names - names of each event 13 | % 14 | % $Id$ 15 | 16 | if ~is_fmri(D) 17 | error('Needs FMRI design'); 18 | end 19 | 20 | SPM = des_struct(D); 21 | Sess = SPM.Sess; 22 | nsess = length(Sess); 23 | 24 | e_specs = []; 25 | e_names = {}; 26 | e_ctr = 1; 27 | for ss = 1:nsess 28 | nevs = length(Sess(ss).U); 29 | e_specs = [e_specs [ones(1, nevs) * ss; 1:nevs]]; 30 | e_names = [e_names {Sess(ss).Fc(:).name}]; 31 | end 32 | 33 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/fwhm.m: -------------------------------------------------------------------------------- 1 | function f = fwhm(o) 2 | % method returns FWHM, or empty if not available 3 | % 4 | % $Id: tr.m,v 1.1 2004/01/26 22:08:55 matthewbrett Exp $ 5 | 6 | f = []; 7 | SPM = des_struct(o); 8 | if mars_struct('isthere', SPM, 'xVol', 'FWHM') 9 | f = SPM.xVol.FWHM; 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/get_images.m: -------------------------------------------------------------------------------- 1 | function VY = get_images(marsD) 2 | % method to get image vols from design 3 | % FORMAT VY = get_images(marsD) 4 | % 5 | % $Id$ 6 | 7 | D = des_struct(marsD); 8 | VY = D.xY.VY; -------------------------------------------------------------------------------- /marsbar/@mardo_2/has_autocorr.m: -------------------------------------------------------------------------------- 1 | function tf = has_autocorr(o) 2 | % returns 1 if object contains autocorrelation specification 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | des = des_struct(o); 8 | if isfield(des, 'xVi') 9 | tf = isfield(des.xVi, 'Vi') | isfield(des.xVi, 'V'); 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/has_filter.m: -------------------------------------------------------------------------------- 1 | function tf = has_filter(o) 2 | % returns 1 if object contains filter 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | des = des_struct(o); 8 | if isfield(des, 'xX') 9 | tf = isfield(des.xX, 'K'); 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/has_images.m: -------------------------------------------------------------------------------- 1 | function tf = has_images(o) 2 | % returns 1 if design contains images 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | des = des_struct(o); 8 | if isfield(des, 'xY') 9 | tf = isfield(des.xY, 'VY'); 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/has_whitener.m: -------------------------------------------------------------------------------- 1 | function tf = has_whitener(D) 2 | % returns 1 if design has whitening filter 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | SPM = des_struct(D); 8 | if isfield(SPM, 'xX') 9 | tf = isfield(SPM.xX, 'W'); 10 | end -------------------------------------------------------------------------------- /marsbar/@mardo_2/modality.m: -------------------------------------------------------------------------------- 1 | function mod_str = modality(D) 2 | % method returns modality of design 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | try 8 | SPM.Sess(1); 9 | mod_str = 'fmri'; 10 | catch 11 | mod_str = 'pet'; 12 | end 13 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/private/my_design.m: -------------------------------------------------------------------------------- 1 | function tf = my_design(des) 2 | % returns 1 if design looks like it is of SPM99 type 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | if isfield(des, 'SPM'), des = des.SPM; end 8 | if isfield(des, 'SPMid') 9 | tf = ~isempty(strmatch('SPM2', des.SPMid)); 10 | end -------------------------------------------------------------------------------- /marsbar/@mardo_2/private/pr_get_filter.m: -------------------------------------------------------------------------------- 1 | function [K, str] = pr_get_filter(RT, row) 2 | % gets filter using spm_fmri_spm_ui routines 3 | % FORMAT [K, str]= pr_get_filter(RT, row) 4 | % or 5 | % FORMAT [K, str]= pr_get_filter(RT, Sess) 6 | % 7 | % $Id$ 8 | 9 | if nargin < 2 10 | error('Need TR, row / Sess matrix'); 11 | end 12 | 13 | % number of sessions 14 | nsess = length(row); 15 | 16 | % rows from Sess 17 | if isfield(row(1), 'row') 18 | Sess = row; 19 | row = {}; 20 | for s = 1:nsess 21 | row{s} = Sess(s).row; 22 | end 23 | else 24 | Sess = []; 25 | end 26 | 27 | switch spm_input('High-pass filter?','+1','b','none|specify'); 28 | 29 | case 'specify' 30 | % default 128 seconds 31 | %------------------------------------------------------- 32 | HParam = 128*ones(1,nsess); 33 | p_str = 'cutoff period (secs)'; 34 | HParam = spm_input(p_str,'+1','e',HParam,[1 nsess]); 35 | str = sprintf('Cutoff: %d {s}', HParam); 36 | 37 | case 'none' 38 | % Inf seconds (i.e. constant term only) 39 | %------------------------------------------------------- 40 | HParam = Inf*ones(1,nsess); 41 | str = 'none'; 42 | end 43 | 44 | % create and set filter struct 45 | %--------------------------------------------------------------- 46 | for i = 1:nsess 47 | K(i) = struct( 'HParam', HParam(i),... 48 | 'row', row{i},... 49 | 'RT', RT); 50 | end 51 | K = pr_spm_filter(K); 52 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/private/pr_spm_ce.m: -------------------------------------------------------------------------------- 1 | function [C] = pr_spm_ce(v,a) 2 | % return error covariance constraints for serially correlated data 3 | % FORMAT [C] = spm_Ce(v,a) 4 | % v - (1 x l) v(i) = number of obervations for ith block 5 | % a - AR coeficient expansion point (default a = []) 6 | % 7 | % C{1} = h(1)*AR(a) 8 | % C{2} = h(1)*AR(a) + h(2)*dAR(a)/da(1); 9 | % C{3} = h(1)*AR(a) + h(2)*dAR(a)/da(1) + h(3)*dAR(a)/da(2); 10 | % 11 | % See also; spm_Q.m 12 | %___________________________________________________________________________ 13 | % @(#)spm_Ce.m 2.7 Karl Friston 03/03/15 14 | 15 | 16 | % defaults 17 | %--------------------------------------------------------------------------- 18 | if nargin == 1 19 | a = []; 20 | end 21 | 22 | 23 | % create blocks 24 | %--------------------------------------------------------------------------- 25 | C = {}; 26 | l = length(v); 27 | n = sum(v); 28 | k = 0; 29 | if l > 1 30 | for i = 1:l 31 | dCda = spm_Ce(v(i),a); 32 | for j = 1:length(dCda) 33 | [x y q] = find(dCda{j}); 34 | x = x + k; 35 | y = y + k; 36 | C{end + 1} = sparse(x,y,q,n,n); 37 | end 38 | k = v(i) + k; 39 | end 40 | else 41 | % dCda 42 | %================================================================== 43 | C{1} = pr_spm_q(a,v); 44 | dCda = pr_spm_diff('pr_spm_q',a,v,1); 45 | for i = 1:length(a) 46 | C{i + 1} = reshape(dCda(:,i),v,v); 47 | end 48 | 49 | end 50 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/private/pr_spm_diff.m: -------------------------------------------------------------------------------- 1 | function [J] = pr_spm_diff(varargin) 2 | % matrix differential 3 | % FORMAT [dfdx] = pr_spm_diff(f,x,...,P,n) 4 | % 5 | % f - [inline] function f(x,P) 6 | % x - argument[s] 7 | % P - parameter[s] 8 | % n - argument or parameter to differentiate w.r.t. 9 | % 10 | % dfdx - df(x,P)/dx{n} 11 | %___________________________________________________________________________ 12 | % @(#)pr_spm_diff.m 2.1 Karl Friston 03/03/03 13 | 14 | 15 | % create inline object 16 | %--------------------------------------------------------------------------- 17 | f = fcnchk(varargin{1}); 18 | x = varargin(2:(end - 1)); 19 | n = varargin{end}; 20 | dx = 1e-6; 21 | 22 | if length(n) == 1 23 | 24 | % dfdx 25 | %------------------------------------------------------------------ 26 | f0 = feval(f,x{:}); 27 | J = sparse(length(f0(:)),length(x{n}(:))); 28 | for i = 1:length(x{n}(:)) 29 | xi = x; 30 | xi{n}(i) = xi{n}(i) + dx; 31 | dfdx = (feval(f,xi{:}) - f0)/dx; 32 | J(:,i) = sparse(dfdx(:)); 33 | end 34 | else 35 | % dfdxdx 36 | %------------------------------------------------------------------ 37 | f0 = pr_spm_diff(f,x{:},n(1)); 38 | J = cell(1,length(x{n(2)}(:))); 39 | for i = 1:length(x{n(2)}(:)) 40 | xi = x; 41 | xi{n(2)}(i) = xi{n(2)}(i) + dx; 42 | dfdx = (pr_spm_diff(f,xi{:},n(1)) - f0)/dx; 43 | J{i} = sparse(dfdx); 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/private/pr_spm_hrf.m: -------------------------------------------------------------------------------- 1 | function [hrf,p] = pr_spm_hrf(RT,P); 2 | % returns a hemodynamic response function 3 | % FORMAT [hrf,p] = pr_spm_hrf(RT,[p]); 4 | % RT - scan repeat time 5 | % p - parameters of the response function (two gamma functions) 6 | % 7 | % defaults 8 | % (seconds) 9 | % p(1) - delay of response (relative to onset) 6 10 | % p(2) - delay of undershoot (relative to onset) 16 11 | % p(3) - dispersion of response 1 12 | % p(4) - dispersion of undershoot 1 13 | % p(5) - ratio of response to undershoot 6 14 | % p(6) - onset (seconds) 0 15 | % p(7) - length of kernel (seconds) 32 16 | % 17 | % hrf - hemodynamic response function 18 | % p - parameters of the response function 19 | %_______________________________________________________________________ 20 | % @(#)spm_hrf.m 2.8 Karl Friston 02/07/31 21 | 22 | % global parameter 23 | %----------------------------------------------------------------------- 24 | global defaults 25 | if ~isempty(defaults), 26 | fMRI_T = defaults.stats.fmri.t; 27 | else, 28 | fMRI_T = 16; 29 | end; 30 | 31 | % default parameters 32 | %----------------------------------------------------------------------- 33 | p = [6 16 1 1 6 0 32]; 34 | if nargin > 1 35 | p(1:length(P)) = P; 36 | end 37 | 38 | % modelled hemodynamic response function - {mixture of Gammas} 39 | %----------------------------------------------------------------------- 40 | dt = RT/fMRI_T; 41 | u = [0:(p(7)/dt)] - p(6)/dt; 42 | hrf = spm_Gpdf(u,p(1)/p(3),dt/p(3)) - spm_Gpdf(u,p(2)/p(4),dt/p(4))/p(5); 43 | hrf = hrf([0:(p(7)/RT)]*fMRI_T + 1); 44 | hrf = hrf'/sum(hrf); 45 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/private/pr_spm_orth.m: -------------------------------------------------------------------------------- 1 | function x = spm_orth(X) 2 | % recursive orthogonalization of basis functions 3 | % FORMAT x = spm_orth(X) 4 | % 5 | % serial orthogionalization starting with the first column 6 | %_______________________________________________________________________ 7 | % @(#)spm_orth.m 2.1 Karl Friston 02/02/07 8 | 9 | x = X(:,1); 10 | for i = 2:size(X,2) 11 | D = X(:,i); 12 | D = D - x*(pinv(x)*D); 13 | if any(D) 14 | x = [x D]; 15 | end 16 | end 17 | 18 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/private/pr_spm_q.m: -------------------------------------------------------------------------------- 1 | function [Q] = pr_spm_q(A,n) 2 | % returns an (n x n) autocorrelation matrix for an AR(p) process 3 | % FORMAT [Q] = spm_Q(A,n) 4 | % 5 | % A - vector pf p AR coeficients 6 | % n - size of Q 7 | %___________________________________________________________________________ 8 | % @(#)spm_Q.m 2.2 Karl Friston 03/03/03 9 | 10 | % compute Q 11 | %--------------------------------------------------------------------------- 12 | p = length(A); 13 | A = [1 -A(:)']; 14 | K = inv(spdiags(ones(n,1)*A,-[0:p],n,n)); 15 | K = K.*(abs(K) > 1e-4); 16 | Q = K*K'; 17 | D = spdiags(sqrt(1./diag(Q)),0,n,n); 18 | Q = D*Q*D; 19 | Q = Q.*(abs(Q) > 1e-4); 20 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/save_spm.m: -------------------------------------------------------------------------------- 1 | function tf = save_spm(D, fname); 2 | % method to save design as SPM format design structure 3 | % FORMAT tf = save_spm(D, fname); 4 | % 5 | % Inputs 6 | % D - design object 7 | % fname - filename 8 | % 9 | % Outputs 10 | % tf - flag ==1 if successful 11 | % 12 | % $Id$ 13 | 14 | if nargin < 2 15 | fname = 'SPM.mat'; 16 | end 17 | 18 | % Convert vols to native format 19 | D = convert_vols(D, native_vol_ver(D)); 20 | 21 | SPM = des_struct(D); 22 | if ~mars_utils('isabspath', fname) 23 | Swd = mars_struct('getifthere', SPM, 'swd'); 24 | if isempty(Swd) 25 | error('No path passed, and none in design'); 26 | end 27 | fname = fullfile(Swd, fname); 28 | else 29 | SPM.swd = fileparts(fname); 30 | end 31 | 32 | 33 | try 34 | if verbose(D) 35 | fprintf('Saving design to file %s\n', fname); 36 | end 37 | save(fname, 'SPM'); 38 | tf = 1; 39 | catch 40 | warning(lasterr); 41 | tf = 0; 42 | end -------------------------------------------------------------------------------- /marsbar/@mardo_2/savestruct.m: -------------------------------------------------------------------------------- 1 | function savestruct(obj, filename) 2 | % saves data in def_struct into .mat file with variable name SPM 3 | % FORMAT savestruct(object, matname) 4 | % 5 | % $Id$ 6 | 7 | if nargin ~= 2 8 | error('Need matfile name'); 9 | end 10 | 11 | % allow args to be in reverse order 12 | if ischar(obj) 13 | tmp = obj; 14 | obj = filename; 15 | filename = tmp; 16 | end 17 | 18 | % Convert vols to native format 19 | obj = convert_vols(obj, native_vol_ver(obj)); 20 | 21 | % unobjectify marsy object before save 22 | SPM = des_struct(obj); 23 | if isfield(SPM, 'marsY') 24 | SPM.marsY = y_struct(SPM.marsY); 25 | end 26 | 27 | save(filename,'SPM'); 28 | return -------------------------------------------------------------------------------- /marsbar/@mardo_2/set_images.m: -------------------------------------------------------------------------------- 1 | function marsD = set_images(marsD, VY) 2 | % method to set image vols to design 3 | % 4 | % $Id% 5 | 6 | if nargin < 2 7 | error('Need image volumes'); 8 | end 9 | D = des_struct(marsD); 10 | D.xY.VY = VY; 11 | D.xY.P = strvcat(VY(:).fname); 12 | marsD = des_struct(marsD, D); 13 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/tr.m: -------------------------------------------------------------------------------- 1 | function t = tr(o) 2 | % method returns TR in seconds, or empty if not available 3 | % 4 | % $Id$ 5 | 6 | t = []; 7 | SPM = des_struct(o); 8 | if mars_struct('isthere', SPM, 'xY', 'RT') 9 | t = SPM.xY.RT; 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo_2/type.m: -------------------------------------------------------------------------------- 1 | function str = type(o) 2 | % returns SPM version string corresponding to design type 3 | % 4 | % $Id$ 5 | 6 | str = 'SPM2'; -------------------------------------------------------------------------------- /marsbar/@mardo_2/ui_build.m: -------------------------------------------------------------------------------- 1 | function D = ui_build(D, dtype) 2 | % method to create / fill design via GUI 3 | % FORMAT D = ui_build(D, dtype) 4 | % 5 | % D - design object 6 | % dtype - one of 'PET', 'FMRI', 'Basic') 7 | % 8 | % Returns 9 | % D - design object with new design 10 | % 11 | % $Id$ 12 | 13 | if nargin < 2 14 | error('Need design type'); 15 | end 16 | 17 | switch lower(dtype) 18 | case 'pet' 19 | SPM = pr_spm_ui('cfg',spm_spm_ui('DesDefs_PET')); 20 | case 'basic' 21 | SPM = pr_spm_ui('cfg',spm_spm_ui('DesDefs_Stats')); 22 | case 'fmri' 23 | SPM = pr_fmri_design; 24 | otherwise 25 | error(['Did not recognize design type: ' dtype]); 26 | end 27 | D = des_struct(D, SPM); -------------------------------------------------------------------------------- /marsbar/@mardo_2/ui_get_event.m: -------------------------------------------------------------------------------- 1 | function [e_spec, e_name] = ui_get_event(D) 2 | % method to select an event 3 | % FORMAT [e_spec, e_name] = ui_get_event(D) 4 | % D - design 5 | % 6 | % Returns 7 | % e_spec - 2 by 1 matrix with 8 | % e_epec(1) - session number 9 | % e_spec(2) - event number in session 10 | % e_name - name of event 11 | % 12 | % $Id$ 13 | 14 | if ~is_fmri(D) 15 | error('Need FMRI design'); 16 | end 17 | SPM = des_struct(D); 18 | Sess = SPM.Sess; 19 | 20 | % get session 21 | %-------------------------------------------------------------- 22 | s = length(Sess); 23 | if s > 1 24 | s = spm_input('which session','+1','n1',1,s); 25 | end 26 | 27 | u = length(Sess(s).U); 28 | Uname = {}; 29 | for i = 1:u 30 | Uname{i} = Sess(s).Fc(i).name; 31 | end 32 | 33 | % get effect 34 | %-------------------------------------------------------------- 35 | str = sprintf('which effect'); 36 | u = spm_input(str,'+1','m',Uname); 37 | 38 | e_spec = [s u]'; 39 | e_name = Uname{u}; -------------------------------------------------------------------------------- /marsbar/@mardo_2/ui_get_filter.m: -------------------------------------------------------------------------------- 1 | function [D,descrip] = ui_get_filter(D) 2 | % method to get filter via GUI 3 | % FORMAT [D,descrip] = ui_get_filter(D) 4 | % 5 | % Input 6 | % D - design 7 | % 8 | % Returns 9 | % D - design with modified filter 10 | % descrip - cell array of strings describing filter 11 | % 12 | % $Id$ 13 | 14 | SPM = des_struct(D); 15 | [SPM.xX.K str] = pr_get_filter(SPM.xY.RT, SPM.Sess); 16 | if ~isfield(SPM, 'xsDes') 17 | SPM.xsDes = []; 18 | end 19 | SPM.xsDes.High_pass_Filter = str; 20 | 21 | % return args 22 | D = des_struct(D, SPM); 23 | descrip = {str}; 24 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/convert_vols.m: -------------------------------------------------------------------------------- 1 | function o = convert_vols(o, ver) 2 | % method that converts vol structs in design and converts to format 'ver' 3 | % FORMAT o = convert_fo(o, ver) 4 | % 5 | % Input 6 | % o - design object 7 | % ver - optional version for vols from '99' or '5' 8 | % Defaults to version for current SPM version 9 | % 10 | % Output 11 | % o - object with converted vols 12 | % 13 | % Example 14 | % % Convert vols to current format 15 | % o = convert_vols(o); 16 | % 17 | % % Convert to native format for SPM99 designs 18 | % o = convert_vols(o, native_vol_ver(o)); 19 | % 20 | % $Id$ 21 | 22 | if nargin < 2 23 | ver = mars_vol_utils('current_ver'); 24 | end 25 | 26 | SPM = des_struct(o); 27 | SPM = sf_conv(SPM, ver, 'xY', 'VY'); 28 | SPM = sf_conv(SPM, ver, 'xM', 'VM'); 29 | SPM = sf_conv(SPM, ver, 'xVol', 'VRpv'); 30 | SPM = sf_conv(SPM, ver, 'Vbeta'); 31 | SPM = sf_conv(SPM, ver, 'VResMS'); 32 | SPM = sf_conv(SPM, ver, 'VM'); 33 | o = des_struct(o, SPM); 34 | 35 | xCon = get_contrasts(o); 36 | if ~isempty(xCon) 37 | for i = 1:length(xCon) 38 | xCon(i) = sf_conv(xCon(i), ver, 'Vcon'); 39 | xCon(i) = sf_conv(xCon(i), ver, 'Vspm'); 40 | end 41 | end 42 | o = set_contrasts(o, xCon, 0); 43 | return 44 | 45 | function S = sf_conv(S, ver, varargin) 46 | V = mars_struct('getifthere', S, varargin{:}); 47 | if ~isempty(V) 48 | V = mars_vol_utils('convert', V, ver); 49 | S = setfield(S, varargin{:}, V); 50 | end 51 | return 52 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/native_vol_ver.m: -------------------------------------------------------------------------------- 1 | function res = native_vol_ver(obj) 2 | % return string specifying native vol type 3 | % 4 | % $Id: verbose.m 87 2004-01-06 01:48:35Z matthewbrett $ 5 | 6 | res = '5'; -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/my_design.m: -------------------------------------------------------------------------------- 1 | function tf = my_design(des) 2 | % returns 1 if design looks like it is of SPM5 / 8 type 3 | % 4 | % $Id: my_design.m 328 2004-03-03 01:56:03Z matthewbrett $ 5 | 6 | tf = 0; 7 | if isfield(des, 'SPM'), des = des.SPM; end 8 | if isfield(des, 'SPMid') 9 | tf = ~isempty(strmatch('SPM5', des.SPMid)) | ... 10 | ~isempty(strmatch('SPM8', des.SPMid)) | ... 11 | ~isempty(strmatch('SPM12', des.SPMid)); 12 | end 13 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/pr_get_filter.m: -------------------------------------------------------------------------------- 1 | function [K, str] = pr_get_filter(RT, row) 2 | % gets filter using spm_fmri_spm_ui routines 3 | % FORMAT [K, str]= pr_get_filter(RT, row) 4 | % or 5 | % FORMAT [K, str]= pr_get_filter(RT, Sess) 6 | % 7 | % $Id: pr_get_filter.m 77 2003-12-25 09:00:03Z matthewbrett $ 8 | 9 | if nargin < 2 10 | error('Need TR, row / Sess matrix'); 11 | end 12 | 13 | % number of sessions 14 | nsess = length(row); 15 | 16 | % rows from Sess 17 | if isfield(row(1), 'row') 18 | Sess = row; 19 | row = {}; 20 | for s = 1:nsess 21 | row{s} = Sess(s).row; 22 | end 23 | else 24 | Sess = []; 25 | end 26 | 27 | switch spm_input('High-pass filter?','+1','b','none|specify'); 28 | 29 | case 'specify' 30 | % default 128 seconds 31 | %------------------------------------------------------- 32 | HParam = 128*ones(1,nsess); 33 | p_str = 'cutoff period (secs)'; 34 | HParam = spm_input(p_str,'+1','e',HParam,[1 nsess]); 35 | str = sprintf('Cutoff: %d {s}', HParam); 36 | 37 | case 'none' 38 | % Inf seconds (i.e. constant term only) 39 | %------------------------------------------------------- 40 | HParam = Inf*ones(1,nsess); 41 | str = 'none'; 42 | end 43 | 44 | % create and set filter struct 45 | %--------------------------------------------------------------- 46 | for i = 1:nsess 47 | K(i) = struct( 'HParam', HParam(i),... 48 | 'row', row{i},... 49 | 'RT', RT); 50 | end 51 | K = pr_spm_filter(K); 52 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/pr_spm_ce.m: -------------------------------------------------------------------------------- 1 | function [C] = pr_spm_ce(v,a) 2 | % return error covariance constraints for serially correlated data 3 | % FORMAT [C] = pr_spm_ce(v,a) 4 | % v - (1 x l) v(i) = number of observations for ith block 5 | % a - AR coefficient expansion point (default a = []) 6 | % 7 | % C{1} = h(1)*AR(a) 8 | % C{2} = h(1)*AR(a) + h(2)*dAR(a)/da(1); 9 | % C{3} = h(1)*AR(a) + h(2)*dAR(a)/da(1) + h(3)*dAR(a)/da(2); 10 | % 11 | % See also: spm_Q.m 12 | %___________________________________________________________________________ 13 | % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 14 | 15 | % Karl Friston 16 | % $Id: spm_Ce.m 190 2005-06-20 07:04:35Z klaas $ 17 | 18 | 19 | 20 | % defaults 21 | %--------------------------------------------------------------------------- 22 | if nargin == 1 23 | a = []; 24 | end 25 | 26 | 27 | % create blocks 28 | %--------------------------------------------------------------------------- 29 | C = {}; 30 | l = length(v); 31 | n = sum(v); 32 | k = 0; 33 | if l > 1 34 | for i = 1:l 35 | dCda = pr_spm_ce(v(i),a); 36 | for j = 1:length(dCda) 37 | [x y q] = find(dCda{j}); 38 | x = x + k; 39 | y = y + k; 40 | C{end + 1} = sparse(x,y,q,n,n); 41 | end 42 | k = v(i) + k; 43 | end 44 | else 45 | % dCda 46 | %================================================================== 47 | C{1} = pr_spm_q(a,v); 48 | dCda = pr_spm_diff('pr_spm_q',a,v,1); 49 | for i = 1:length(a) 50 | try 51 | C{i + 1} = dCda{i}; 52 | catch 53 | C{i + 1} = dCda; 54 | end 55 | end 56 | 57 | end 58 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/pr_spm_en.m: -------------------------------------------------------------------------------- 1 | function [X] = pr_spm_en(X) 2 | % Euclidean normalization 3 | % FORMAT [X] = pr_spm_en(X); 4 | % X - matrix 5 | %_______________________________________________________________________ 6 | % 7 | % spm_en performs a Euclidean normalization setting column-wise sum of 8 | % squares to unity 9 | %_______________________________________________________________________ 10 | % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 11 | 12 | % Karl Friston 13 | % $Id: spm_en.m 112 2005-05-04 18:20:52Z john $ 14 | 15 | 16 | for i = 1:size(X,2) 17 | X(:,i) = X(:,i)/sqrt(sum(X(:,i).^2)); 18 | end 19 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/pr_spm_fileparts.m: -------------------------------------------------------------------------------- 1 | function [pth,nam,ext,num] = spm_fileparts(fname) 2 | % Like fileparts, but separates off a comma separated list at the end 3 | % FORMAT [pth,nam,ext,num] = spm_fileparts(fname) 4 | % fname - original filename 5 | % pth - path 6 | % nam - filename 7 | % ext - extension 8 | % num - comma separated list of values 9 | % 10 | %_______________________________________________________________________ 11 | % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 12 | 13 | % John Ashburner 14 | % $Id: spm_fileparts.m 112 2005-05-04 18:20:52Z john $ 15 | 16 | 17 | num = ''; 18 | [pth,nam,ext] = fileparts(fname); 19 | ind = find(ext==','); 20 | if ~isempty(ind), 21 | num = ext(ind(1):end); 22 | ext = ext(1:(ind(1)-1)); 23 | end; 24 | 25 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/pr_spm_logdet.m: -------------------------------------------------------------------------------- 1 | function [H] = pr_spm_logdet(C) 2 | % returns the log of the determinant of positive semi-definite matrix C 3 | % FORMAT [H] = pr_spm_logdet(C) 4 | % H = log(det(C)) 5 | % 6 | % spm_logdet is a computationally efficient operator that can deal with 7 | % sparse matrices 8 | %_______________________________________________________________________ 9 | % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 10 | 11 | % Karl Friston 12 | % $Id: spm_logdet.m 309 2005-11-24 16:24:04Z karl $ 13 | 14 | % assume diagonal form 15 | %----------------------------------------------------------------------- 16 | TOL = 1e-8; % c.f. n*max(s)*eps 17 | n = length(C); 18 | s = diag(C); 19 | i = find(s > TOL & s < 1/TOL); 20 | C = C(i,i); 21 | H = sum(log(diag(C))); 22 | 23 | % invoke det if non-diagonal 24 | %----------------------------------------------------------------------- 25 | w = warning; 26 | warning off 27 | [i j] = find(C); 28 | if any(i ~= j) 29 | n = length(C); 30 | a = exp(H/n); 31 | H = H + log(det(C/a)); 32 | end 33 | warning(w) 34 | 35 | % invoke svd is rank deficient 36 | %----------------------------------------------------------------------- 37 | if imag(H) | isinf(H) 38 | s = svd(full(C)); 39 | H = sum(log(s(s > TOL & s < 1/TOL))); 40 | end 41 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/pr_spm_orth.m: -------------------------------------------------------------------------------- 1 | function x = pr_spm_orth(X) 2 | % recursive orthogonalization of basis functions 3 | % FORMAT x = pr_spm_orth(X) 4 | % 5 | % serial orthogionalization starting with the first column 6 | %_______________________________________________________________________ 7 | % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 8 | 9 | % Karl Friston 10 | % $Id: spm_orth.m 112 2005-05-04 18:20:52Z john $ 11 | 12 | 13 | x = X(:,1); 14 | for i = 2:size(X,2) 15 | D = X(:,i); 16 | D = D - x*(pinv(x)*D); 17 | if any(D) 18 | x = [x D]; 19 | end 20 | end 21 | 22 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/pr_spm_q.m: -------------------------------------------------------------------------------- 1 | function [Q] = pr_spm_q(A,n) 2 | % returns an (n x n) autocorrelation matrix for an AR(p) process 3 | % FORMAT [Q] = pr_spm_q(A,n) 4 | % 5 | % A - vector pf p AR coeficients 6 | % n - size of Q 7 | %__________________________________________________________________________ 8 | % spm_Q uses a Yule-Walker device to compute K where: 9 | % 10 | % y = K*z 11 | % 12 | % such that y is an AR(n) process generated from an i.i.d innovation 13 | % z. This means 14 | % 15 | % cov(y) = = K*K' 16 | % 17 | % Critically, this is not the correlation because if cov(z) = eye(n) 18 | % then trace(cov(y)) ~= n. This is why the normalization is required 19 | % 20 | % corr(y) = D*K*K'*D'; 21 | % 22 | % The reason the diagonals of corr(y) are not constant is that we 23 | % are modeling finite length AR sequences, which incur boundary effects 24 | % at the beginning and end of the sequence. 25 | %__________________________________________________________________________ 26 | % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 27 | 28 | % Karl Friston 29 | % $Id: spm_Q.m 372 2005-12-08 17:12:13Z karl $ 30 | 31 | 32 | % compute Q 33 | %-------------------------------------------------------------------------- 34 | p = length(A); 35 | A = [1 -A(:)']; 36 | K = inv(spdiags(ones(n,1)*A,-[0:p],n,n)); 37 | K = K.*(abs(K) > 1e-4); 38 | Q = K*K'; 39 | D = spdiags(sqrt(1./diag(Q)),0,n,n); 40 | Q = D*Q*D; 41 | Q = Q.*(abs(Q) > 1e-4); -------------------------------------------------------------------------------- /marsbar/@mardo_5/private/pr_spm_vec.m: -------------------------------------------------------------------------------- 1 | function [vX] = pr_spm_vec(varargin) 2 | % vectorises a numeric, cell or structure array 3 | % FORMAT [vX] = pr_spm_vec(X); 4 | % X - numeric, cell or stucture array[s] 5 | % vX - vec(X) 6 | %__________________________________________________________________________ 7 | % 8 | % e.g.: 9 | % spm_vec({eye(2) 3}) = [1 0 0 1 3]' 10 | %__________________________________________________________________________ 11 | % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 12 | 13 | % Karl Friston 14 | % $Id: spm_vec.m 279 2005-11-08 19:11:28Z karl $ 15 | 16 | % initialise X and vX 17 | %-------------------------------------------------------------------------- 18 | X = varargin; 19 | if length(X) == 1 20 | X = X{1}; 21 | end 22 | vX = []; 23 | 24 | % vectorise structure into cell arrays 25 | %-------------------------------------------------------------------------- 26 | if isstruct(X) 27 | f = fieldnames(X); 28 | X = X(:); 29 | for i = 1:length(f) 30 | vX = cat(1,vX,pr_spm_vec({X.(f{i})})); 31 | end 32 | return 33 | end 34 | 35 | % vectorise cells into numerical arrays 36 | %-------------------------------------------------------------------------- 37 | if iscell(X) 38 | X = X(:); 39 | for i = 1:length(X) 40 | vX = cat(1,vX,pr_spm_vec(X{i})); 41 | end 42 | return 43 | end 44 | 45 | % vectorise numerical arrays 46 | %-------------------------------------------------------------------------- 47 | if isnumeric(X) 48 | vX = X(:); 49 | end 50 | 51 | -------------------------------------------------------------------------------- /marsbar/@mardo_5/type.m: -------------------------------------------------------------------------------- 1 | function str = type(o) 2 | % returns SPM version string corresponding to design type 3 | % 4 | % $Id: type.m 76 2003-12-25 08:19:13Z matthewbrett $ 5 | 6 | str = 'SPM5'; -------------------------------------------------------------------------------- /marsbar/@mardo_5/ui_build.m: -------------------------------------------------------------------------------- 1 | function D = ui_build(D, dtype) 2 | % method to create / fill design via GUI 3 | % FORMAT D = ui_build(D, dtype) 4 | % 5 | % D - design object 6 | % dtype - one of 'PET', 'FMRI', 'Basic') 7 | % 8 | % Returns 9 | % D - design object with new design 10 | % 11 | % $Id: ui_build.m 263 2004-01-31 07:19:35Z matthewbrett $ 12 | 13 | if nargin < 2 14 | error('Need design type'); 15 | end 16 | 17 | switch lower(dtype) 18 | case 'pet' 19 | SPM = pr_spm_ui('cfg',spm_spm_ui('DesDefs_PET')); 20 | case 'basic' 21 | SPM = pr_spm_ui('cfg',spm_spm_ui('DesDefs_Stats')); 22 | case 'fmri' 23 | SPM = pr_fmri_design; 24 | otherwise 25 | error(['Did not recognize design type: ' dtype]); 26 | end 27 | D = des_struct(D, SPM); -------------------------------------------------------------------------------- /marsbar/@mardo_99/add_trial_f.m: -------------------------------------------------------------------------------- 1 | function [D, changef] = add_trial_f(D) 2 | % method to add trial-specific F contrasts 3 | % 4 | % D - design to put contrasts into 5 | % 6 | % Returns 7 | % D - design with any added contrasts 8 | % changef - set to 1 if any contrasts have been added 9 | % 10 | % The routine only adds contrasts that are not already present 11 | % 12 | % $Id$ 13 | 14 | if ~strcmp(modality(D), 'fmri') 15 | error('Can only set trial-specific F contrasts for FMRI designs'); 16 | end 17 | SPM = des_struct(D); 18 | xX = SPM.xX; 19 | 20 | %-Append contrasts for fMRI - specified by SPM.Sess(s).Fc(i) 21 | %----------------------------------------------------------------------- 22 | if ~isfield(SPM,'Sess') 23 | changef = 0; 24 | return; 25 | end 26 | 27 | Sess = SPM.Sess; 28 | xCon = []; 29 | if (Sess{1}.rep) 30 | for t = 1:length(Sess{1}.name) 31 | u = []; 32 | for s = 1:length(Sess) 33 | u = [u Sess{s}.col(Sess{s}.ind{t})]; 34 | end 35 | q = 1:size(xX.X,2); 36 | q(u) = []; 37 | Fcname = Sess{s}.name{t}; 38 | xcon = spm_FcUtil('Set',Fcname,'F','iX0',q,xX.xKXs); 39 | xCon = [xCon xcon]; 40 | end 41 | else % Sessions are not repeated 42 | for s = 1:length(Sess) 43 | str = sprintf('Session %d: ',s); 44 | for t = 1:length(Sess{s}.name) 45 | q = 1:size(xX.X,2); 46 | q(Sess{s}.col(Sess{s}.ind{t})) = []; 47 | Fcname = [str Sess{s}.name{t}]; 48 | xcon = spm_FcUtil('Set',Fcname,'F','iX0',q,xX.xKXs); 49 | xCon = [xCon xcon]; 50 | end 51 | end 52 | end 53 | 54 | [D Ic changef] = add_contrasts(D, xCon); -------------------------------------------------------------------------------- /marsbar/@mardo_99/autocorr.m: -------------------------------------------------------------------------------- 1 | function D = autocorr(D, varargin) 2 | % method to report lack of autocorrelation options for SPM99 3 | % FORMAT D = autocorr(D, varargin) 4 | % 5 | % D - design object 6 | % varargin - any other parameters that may have been passed 7 | % 8 | % $Id$ 9 | 10 | warning('There are no SPM99 autocorrelation options'); 11 | return 12 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/bf_dt.m: -------------------------------------------------------------------------------- 1 | function d = bf_dt(D) 2 | % method returns length of time bin for basis functions 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | d = mars_struct('getifthere', SPM, 'xX', 'dt'); 8 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/block_cols.m: -------------------------------------------------------------------------------- 1 | function cols = block_cols(D) 2 | % method gets design columns for block (session / subject) 3 | % FORMAT cols = block_cols(D) 4 | % 5 | % Returns cell array of column indices (one per session) 6 | % 7 | % $Id$ 8 | 9 | if ~is_fmri(D) 10 | error('Needs FMRI design'); 11 | end 12 | 13 | SPM = des_struct(D); 14 | Sess = SPM.Sess; 15 | for i = 1:length(Sess) 16 | cols{i} = Sess{i}.col; 17 | end 18 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/block_rows.m: -------------------------------------------------------------------------------- 1 | function rows = block_rows(D) 2 | % returns cell array of rows for each (subject/session) block 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | if strcmp(modality(D), 'fmri') 8 | Sess = SPM.Sess; 9 | for i = 1:length(Sess) 10 | rows{i} = Sess{i}.row; 11 | end 12 | else % PET I guess 13 | xX = SPM.xX; 14 | if ~isfield(xX, 'I') 15 | error('Expecting I field in SPM design'); 16 | end 17 | scol = xX.I(:, 3); % the subject column 18 | subjnos = unique(scol); 19 | for s = 1:length(subjnos); 20 | rows{s} = find(scol == subjnos(s)); 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/can_mars_estimate.m: -------------------------------------------------------------------------------- 1 | function tf = can_mars_estimate(D) 2 | % method returns 1 if design can be estimated in MarsBaR 3 | % 4 | % $Id$ 5 | 6 | tf = ~is_fmri(D) | has_filter(D); 7 | 8 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/convert_vols.m: -------------------------------------------------------------------------------- 1 | function o = convert_vols(o, ver) 2 | % method that converts vol structs in design and converts to format 'ver' 3 | % FORMAT o = convert_fo(o, ver) 4 | % 5 | % Input 6 | % o - design object 7 | % ver - optional version for vols from '99' or '5' 8 | % Defaults to version for current SPM version 9 | % 10 | % Output 11 | % o - object with converted vols 12 | % 13 | % Example 14 | % % Convert vols to current format 15 | % o = convert_vols(o); 16 | % 17 | % % Convert to native format for SPM99 designs 18 | % o = convert_vols(o, native_vol_ver(o)); 19 | % 20 | % $Id$ 21 | 22 | if nargin < 2 23 | ver = mars_vol_utils('current_ver'); 24 | end 25 | 26 | SPM = des_struct(o); 27 | SPM = sf_conv(SPM, ver, 'VY'); 28 | SPM = sf_conv(SPM, ver, 'xM', 'VM'); 29 | o = des_struct(o, SPM); 30 | 31 | return 32 | 33 | function S = sf_conv(S, ver, varargin) 34 | V = mars_struct('getifthere', S, varargin{:}); 35 | if ~isempty(V) 36 | V = mars_vol_utils('convert', V, ver); 37 | S = setfield(S, varargin{:}, V); 38 | end 39 | return -------------------------------------------------------------------------------- /marsbar/@mardo_99/design_vol.m: -------------------------------------------------------------------------------- 1 | function V = design_vol(D, imgs) 2 | % returns vols in appropriate format for saving in design 3 | % FORMAT V = design_vol(D, imgs) 4 | % 5 | % Input 6 | % D - mardo design object 7 | % imgs - image names or vol structs 8 | % 9 | % Output 10 | % V - paths relative to swd 11 | % 12 | % $Id$ 13 | 14 | if nargin < 2 15 | error('Need image information'); 16 | end 17 | 18 | if isstruct(imgs) % vol struct, check for absolute path name 19 | imgs = strvcat(imgs(:).fname); 20 | end 21 | if iscell(imgs) 22 | imgs = char(imgs); 23 | end 24 | if ischar(imgs) 25 | V = spm_str_manip(imgs, 't'); 26 | else 27 | error('Odd input format for images'); 28 | end 29 | 30 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/estimate.m: -------------------------------------------------------------------------------- 1 | function [marsD] = estimate(marsD, marsY, params) 2 | % estimate method - estimates GLM for SPM99 model 3 | % 4 | % marsD - SPM design object 5 | % marsY - MarsBaR data object, or 2D matrix 6 | % param - struct containing options 7 | % (not currently used) 8 | % 9 | % e.g. 10 | % % Estimate model on design D and data Y 11 | % E = estimate(D, Y); 12 | % 13 | % $Id$ 14 | 15 | if nargin < 2 16 | error('Need data to estimate'); 17 | end 18 | if nargin < 3 19 | params = []; 20 | end 21 | 22 | % ensure we have a data object 23 | marsY = marsy(marsY); 24 | 25 | % check design is complete 26 | if ~can_mars_estimate(marsD) 27 | error('This design needs more information before it can be estimated'); 28 | end 29 | 30 | % Check data and design dimensions 31 | if n_time_points(marsY) ~= n_time_points(marsD) 32 | error('The data and design must have the same number of rows'); 33 | end 34 | 35 | % get SPM design structure 36 | SPM = des_struct(marsD); 37 | 38 | % do estimation 39 | SPM = pr_estimate(SPM, marsY); 40 | SPM.marsY = marsY; 41 | 42 | % We must set SPMid to contain SPM99 string in order for the mardo_99 to 43 | % recognize this as an SPM99 design 44 | SPM.SPMid = sprintf('SPM99: MarsBaR estimation. mardo_99 version %s', ... 45 | marsD.cvs_version); 46 | 47 | % return modified structure 48 | marsD = des_struct(marsD, SPM); 49 | 50 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/event_cols.m: -------------------------------------------------------------------------------- 1 | function I = event_cols(D, e_spec) 2 | % method gets design columns for single event 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need design and event spec'); 8 | end 9 | if ~is_fmri(D) 10 | error('Needs FMRI design'); 11 | end 12 | 13 | SPM = des_struct(D); 14 | Sess = SPM.Sess; 15 | ss = e_spec(1); 16 | en = e_spec(2); 17 | 18 | j = 1:size(Sess{ss}.sf{en},2):length(Sess{ss}.ind{en}); 19 | I = Sess{ss}.col(Sess{ss}.ind{en}(j)); 20 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/event_regressor.m: -------------------------------------------------------------------------------- 1 | function [X, dt] = event_regressor(D, e_spec, dur) 2 | % method gets estimated regressor for single event 3 | % FORMAT [X dt] = event_regressor(D, e_spec, dur) 4 | % 5 | % D - design object 6 | % e_spec - event specification (see event_fitted for details) 7 | % dur - event duration in seconds (default = 0) 8 | % 9 | % Returns 10 | % X - event regressor for single event 11 | % (one column per basis function used to model event) 12 | % dt - time units (seconds per row in X) 13 | % 14 | % $Id$ 15 | 16 | if nargin < 2 17 | error('Need design and event spec'); 18 | end 19 | if nargin < 3 20 | dur = 0; 21 | end 22 | if ~is_fmri(D) 23 | error('Needs FMRI design'); 24 | end 25 | 26 | if size(e_spec, 1) == 1, e_spec = e_spec'; end 27 | 28 | SPM = des_struct(D); 29 | Sess = SPM.Sess; 30 | xX = SPM.xX; 31 | dt = xX.dt; 32 | ss = e_spec(1); 33 | en = e_spec(2); 34 | bf = full(Sess{ss}.bf{en}); 35 | 36 | if ~dur 37 | % SPM99 uses one time bin for events with no duration 38 | sf = 1; 39 | else 40 | sf = ones(round(dur/dt), 1); 41 | end 42 | X = []; 43 | 44 | for b = 1:size(bf,2) 45 | X = [X conv(sf, bf(:,b))]; 46 | end 47 | 48 | return 49 | 50 | % In SPM99 spm_graph, we also apply the filter 51 | K{1} = struct('HChoice', 'none',... 52 | 'HParam', [],... 53 | 'LChoice', xX.K{ss}.LChoice,... 54 | 'LParam', xX.K{ss}.LParam,... 55 | 'row', 1:size(X,1),... 56 | 'RT', dt); 57 | X = pr_spm_filter('apply',K,X); 58 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/event_specs.m: -------------------------------------------------------------------------------- 1 | function [e_specs, e_names] = event_specs(D) 2 | % method to return event specifications for all event in model 3 | % FORMAT [e_specs e_names] = event_specs(D) 4 | % 5 | % D - design object 6 | % 7 | % Returns 8 | % e_specs - event specification 2 by N matrix where row 1 is the 9 | % session number of the event, row 2 is the event number in 10 | % the session 11 | % 12 | % e_names - names of each event 13 | % 14 | % $Id$ 15 | 16 | if ~is_fmri(D) 17 | error('Needs FMRI design'); 18 | end 19 | 20 | SPM = des_struct(D); 21 | Sess = SPM.Sess; 22 | nsess = length(Sess); 23 | 24 | e_specs = []; 25 | e_names = {}; 26 | e_ctr = 1; 27 | for ss = 1:nsess 28 | nevs = length(Sess{ss}.name); 29 | e_specs = [e_specs [ones(1, nevs) * ss; 1:nevs]]; 30 | e_names = [e_names Sess{ss}.name]; 31 | end 32 | 33 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/fwhm.m: -------------------------------------------------------------------------------- 1 | function f = fwhm(o) 2 | % method returns FWHM, or empty if not available 3 | % 4 | % $Id: tr.m,v 1.1 2004/01/26 22:08:55 matthewbrett Exp $ 5 | 6 | f = []; 7 | SPM = des_struct(o); 8 | if mars_struct('isthere', SPM, 'FWHM') 9 | f = SPM.FWHM; 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/get_images.m: -------------------------------------------------------------------------------- 1 | function VY = get_images(marsD) 2 | % method to get image vols from design 3 | % FORMAT VY = get_images(marsD) 4 | % 5 | % $Id$ 6 | 7 | D = des_struct(marsD); 8 | VY = D.VY; -------------------------------------------------------------------------------- /marsbar/@mardo_99/has_autocorr.m: -------------------------------------------------------------------------------- 1 | function tf = has_autocorr(o) 2 | % returns 1 if object contains autocorrelation specification 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/has_filter.m: -------------------------------------------------------------------------------- 1 | function tf = has_filter(o) 2 | % returns 1 if object contains filter 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | des = des_struct(o); 8 | if isfield(des, 'xX') 9 | tf = isfield(des.xX, 'K'); 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/has_images.m: -------------------------------------------------------------------------------- 1 | function tf = has_images(o) 2 | % returns 1 if design contains images 3 | % 4 | % $Id$ 5 | 6 | tf = isfield(des_struct(o), 'VY'); 7 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/modality.m: -------------------------------------------------------------------------------- 1 | function mod_str = modality(D) 2 | % method returns modality of design 3 | % 4 | % $Id$ 5 | 6 | SPM = des_struct(D); 7 | try 8 | SPM.Sess{1}; 9 | mod_str = 'fmri'; 10 | catch 11 | mod_str = 'pet'; 12 | end 13 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/private/my_design.m: -------------------------------------------------------------------------------- 1 | function tf = my_design(des) 2 | % returns 1 if design looks like it is of SPM99 type 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | if isfield(des, 'SPMid') 8 | % Can be SPM99 design with SPM99 tag or MarsBaR tag 9 | % (MarsBaR tag used only by MarsBaR <= 0.23) 10 | tf = ~isempty(strmatch('SPM99', des.SPMid)) | ... 11 | ~isempty(strmatch('MarsBar', des.SPMid)); 12 | end -------------------------------------------------------------------------------- /marsbar/@mardo_99/private/pr_spm_hrf.m: -------------------------------------------------------------------------------- 1 | function [hrf,p] = pr_spm_hrf(RT,P); 2 | % returns a hemodynamic response function 3 | % FORMAT [hrf,p] = pr_spm_hrf(RT,[p]); 4 | % RT - scan repeat time 5 | % p - parameters of the response function (two gamma functions) 6 | % 7 | % defaults 8 | % (seconds) 9 | % p(1) - delay of response (relative to onset) 6 10 | % p(2) - delay of undershoot (relative to onset) 16 11 | % p(3) - dispersion of response 1 12 | % p(4) - dispersion of undershoot 1 13 | % p(5) - ratio of response to undershoot 6 14 | % p(6) - onset (seconds) 0 15 | % p(7) - length of kernel (seconds) 32 16 | % 17 | % hrf - hemodynamic response function 18 | % p - parameters of the response function 19 | %_______________________________________________________________________ 20 | % @(#)spm_hrf.m 2.7 Karl Friston 99/05/17 21 | 22 | % global parameter 23 | %----------------------------------------------------------------------- 24 | global fMRI_T; 25 | if isempty(fMRI_T), fMRI_T = 16; end; 26 | 27 | % default parameters 28 | %----------------------------------------------------------------------- 29 | p = [6 16 1 1 6 0 32]; 30 | if nargin > 1 31 | p(1:length(P)) = P; 32 | end 33 | 34 | % modelled hemodynamic response function - {mixture of Gammas} 35 | %----------------------------------------------------------------------- 36 | dt = RT/fMRI_T; 37 | u = [0:(p(7)/dt)] - p(6)/dt; 38 | hrf = spm_Gpdf(u,p(1)/p(3),dt/p(3)) - spm_Gpdf(u,p(2)/p(4),dt/p(4))/p(5); 39 | hrf = hrf([0:(p(7)/RT)]*fMRI_T + 1); 40 | hrf = hrf'/sum(hrf); 41 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/private/pr_spm_orth.m: -------------------------------------------------------------------------------- 1 | function bf = pr_spm_orth(BF) 2 | % recursive orthogonalization of basis functions 3 | % FORMAT bf = pr_spm_orth(bf) 4 | % 5 | % From spm_get_bf.m, see that file for credits 6 | % 7 | % $Id$ 8 | 9 | if nargin < 1 10 | error('Need BF'); 11 | end 12 | 13 | bf = BF(:,1); 14 | bf = bf/sqrt(mean(bf.^2)); 15 | for i = 2:size(BF,2) 16 | D = BF(:,i); 17 | D = D - bf*(pinv(bf)*D); 18 | if any(D) 19 | bf = [bf D/sqrt(mean(D.^2))]; 20 | end 21 | end 22 | 23 | 24 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/save_spm.m: -------------------------------------------------------------------------------- 1 | function tf = save_spm(D, fname); 2 | % method to save design as SPM format design structure 3 | % FORMAT tf = save_spm(D, fname); 4 | % 5 | % Inputs 6 | % D - design object 7 | % fname - filename 8 | % 9 | % Outputs 10 | % tf - flag ==1 if successful 11 | % 12 | % $Id$ 13 | 14 | if nargin < 2 15 | if is_spm_estimated(D) 16 | fname = 'SPM.mat'; 17 | elseif has_images(D) 18 | fname = 'SPMcfg.mat'; 19 | elseif is_fmri(D) 20 | fname = 'SPM_fMRIDesMtx.mat'; 21 | else 22 | error('Cannot work out design type for default filename'); 23 | end 24 | end 25 | 26 | % Convert vols to native format 27 | D = convert_vols(D, native_vol_ver(D)); 28 | 29 | SPM = des_struct(D); 30 | if ~mars_utils('isabspath', fname) 31 | Swd = mars_struct('getifthere', SPM, 'swd'); 32 | if isempty(Swd) 33 | error('No path passed, and none in design'); 34 | end 35 | fname = fullfile(Swd, fname); 36 | else 37 | SPM.swd = fileparts(fname); 38 | end 39 | 40 | try 41 | if verbose(D) 42 | fprintf('Saving design to file %s\n', fname); 43 | end 44 | savestruct(SPM, fname); 45 | tf = 1; 46 | catch 47 | warning(lasterr); 48 | tf = 0; 49 | end -------------------------------------------------------------------------------- /marsbar/@mardo_99/set_images.m: -------------------------------------------------------------------------------- 1 | function marsD = set_images(marsD, VY) 2 | % method to set image vols into design 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need image volumes'); 8 | end 9 | D = des_struct(marsD); 10 | D.VY = VY; 11 | marsD = des_struct(marsD, D); -------------------------------------------------------------------------------- /marsbar/@mardo_99/tr.m: -------------------------------------------------------------------------------- 1 | function t = tr(o) 2 | % method returns TR in seconds, or empty if not available 3 | % 4 | % $Id$ 5 | 6 | t = []; 7 | SPM = des_struct(o); 8 | if mars_struct('isthere', SPM, 'xX', 'RT') 9 | t = SPM.xX.RT; 10 | end 11 | -------------------------------------------------------------------------------- /marsbar/@mardo_99/type.m: -------------------------------------------------------------------------------- 1 | function str = type(o) 2 | % returns SPM version string corresponding to design type 3 | % 4 | % $Id$ 5 | 6 | str = 'SPM99'; -------------------------------------------------------------------------------- /marsbar/@mardo_99/ui_build.m: -------------------------------------------------------------------------------- 1 | function D = ui_build(D, dtype) 2 | % method to create / fill design via GUI 3 | % FORMAT D = ui_build(D, dtype) 4 | % 5 | % D - design object 6 | % dtype - one of 'PET', 'FMRI', 'Basic') 7 | % 8 | % Returns 9 | % D - design object with new design 10 | % 11 | % $Id$ 12 | 13 | if nargin < 2 14 | error('Need design type'); 15 | end 16 | 17 | switch lower(dtype) 18 | case 'pet' 19 | SPM = pr_spm_ui('cfg',spm_spm_ui('DesDefs_PET')); 20 | case 'basic' 21 | SPM = pr_spm_ui('cfg',spm_spm_ui('DesDefs_Stats')); 22 | case 'fmri' 23 | SPM = pr_fmri_design; 24 | otherwise 25 | error(['Did not recognize design type: ' dtype]); 26 | end 27 | D = des_struct(D, SPM); -------------------------------------------------------------------------------- /marsbar/@mardo_99/ui_get_event.m: -------------------------------------------------------------------------------- 1 | function [e_spec, e_name] = ui_get_event(D) 2 | % method to select an event 3 | % FORMAT [e_spec, e_name] = ui_get_event(D) 4 | % D - design 5 | % 6 | % Returns 7 | % e_spec - 2 by 1 matrix with 8 | % e_epec(1) - session number 9 | % e_spec(2) - event number in session 10 | % e_name - name of event 11 | % 12 | % $Id$ 13 | 14 | if ~is_fmri(D) 15 | error('Need FMRI design'); 16 | end 17 | SPM = des_struct(D); 18 | Sess = SPM.Sess; 19 | 20 | % get session 21 | %-------------------------------------------------------------- 22 | s = length(Sess); 23 | if s > 1 24 | s = spm_input('which session','+1','n1',1,s); 25 | end 26 | 27 | u = length(Sess{s}.name); 28 | Uname = {}; 29 | for i = 1:u 30 | Uname{i} = Sess{s}.name{i}; 31 | end 32 | 33 | % get effect 34 | %-------------------------------------------------------------- 35 | str = sprintf('which effect'); 36 | u = spm_input(str,'+1','m',Uname); 37 | 38 | e_spec = [s u]'; 39 | e_name = Uname{u}; -------------------------------------------------------------------------------- /marsbar/@mardo_99/ui_get_filter.m: -------------------------------------------------------------------------------- 1 | function [D,descrip] = ui_get_filter(D) 2 | % method to get filter via GUI 3 | % FORMAT [D,descrip] = ui_get_filter(D) 4 | % 5 | % Input 6 | % D - design 7 | % 8 | % Returns 9 | % D - design with modified filter 10 | % descrip - cell array of strings describing filter 11 | % 12 | % $Id$ 13 | 14 | SPM = des_struct(D); 15 | [K Hf Lf] = pr_get_filter(SPM.xX.RT, SPM.Sess); 16 | SPM.xX.K = K; 17 | if ~isfield(SPM, 'xsDes') 18 | SPM.xsDes = []; 19 | end 20 | SPM.xsDes.High_pass_Filter = Lf; 21 | SPM.xsDes.Low_pass_Filter = Hf; 22 | 23 | % return args 24 | D = des_struct(D, SPM); 25 | 26 | descrip = {['High_pass_Filter:\t%s', Lf],... 27 | ['Low_pass_Filter: \t%s', Hf]}; 28 | -------------------------------------------------------------------------------- /marsbar/@marmoire/add_if_absent.m: -------------------------------------------------------------------------------- 1 | function o = add_if_absent(o, item, data) 2 | % Adds item only if not already present 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need name of item to add'); 8 | end 9 | if nargin < 3 10 | error('Need data to put into item'); 11 | end 12 | if ~item_exists(o, item) 13 | o = add_item(o, item, data); 14 | end -------------------------------------------------------------------------------- /marsbar/@marmoire/add_item.m: -------------------------------------------------------------------------------- 1 | function o = add_item(o, item_name, item_contents) 2 | % add item to armoire 3 | % FORMAT o = add_item(o, item, I) 4 | % 5 | % o - object 6 | % item_name - item name 7 | % item_contents = item ... contents 8 | % 9 | % $Id $ 10 | 11 | if nargin < 2 12 | error('Need item name to add'); 13 | end 14 | if nargin < 3 15 | item_contents = []; 16 | end 17 | I = default_item(o); 18 | if isempty(item_contents) 19 | item_contents = I; 20 | else 21 | def_fns = fieldnames(I); 22 | new_fns = def_fns(~ismember(def_fns, fieldnames(item_contents))); 23 | for fn = new_fns' 24 | item_contents = setfield(item_contents, fn{1}, getfield(I, fn{1})); 25 | end 26 | end 27 | o = set_item_struct(o, item_name, item_contents); 28 | -------------------------------------------------------------------------------- /marsbar/@marmoire/clear_item_data.m: -------------------------------------------------------------------------------- 1 | function [o, errf] = clear_item_data(o, item) 2 | % sets data for item to empty 3 | % FORMAT [o errf] = clear_item_data(o, item); 4 | % 5 | % o - object 6 | % item - name of item to clear data for 7 | % 8 | % Returns 9 | % o - object with data cleared for this item 10 | % errf - flag is 1 if data was not cleared for some reason 11 | % 12 | % $Id$ 13 | 14 | if nargin < 2 15 | error('Need item to clear data'); 16 | end 17 | 18 | [o errf] = do_set(o, item, 'clear', [], ''); 19 | -------------------------------------------------------------------------------- /marsbar/@marmoire/default_item.m: -------------------------------------------------------------------------------- 1 | function I = default_item(o) 2 | % returns default item 3 | % 4 | % $Id$ 5 | 6 | I = struct('data', [],... 7 | 'file_name', '',... 8 | 'default_file_name','',... 9 | 'has_changed', 0,... 10 | 'leave_as_file', 0,... 11 | 'save_if_changed', 1,... 12 | 'file_type', 'mat',... 13 | 'char_is_filename',1,... 14 | 'set_action_if_update', 0 ,... 15 | 'set_action_if_clear', 0 ,... 16 | 'verbose', 1,... 17 | 'title', 'file',... 18 | 'filter_spec', '',... 19 | 'set_action', ''); 20 | -------------------------------------------------------------------------------- /marsbar/@marmoire/get_item_data.m: -------------------------------------------------------------------------------- 1 | function [res, o, errf] = get_item_data(o, item) 2 | % get data for item 3 | % FORMAT [res o errf] = get_item_data(o, item); 4 | % 5 | % o - object 6 | % item - name of item to get data for 7 | % 8 | % If the item contains no data, GUI set is assumed 9 | % data is loaded from data filename if empty. 10 | % 11 | % Returns 12 | % res - data for item 13 | % o - object, which may have been modified if has done GUI set 14 | % errf - flag is 1 if data modification was attempted but failed 15 | % 16 | % $Id$ 17 | 18 | if nargin < 2 19 | error('Need item'); 20 | end 21 | errf = 0; 22 | if isempty_item_data(o, item) 23 | [o errf] = do_set(o, item, 'set_ui'); 24 | end 25 | I = get_item_struct(o, item); 26 | res = I.data; 27 | if isempty(res) & ~isempty(I.file_name) 28 | res = load(I.file_name, ['-' I.file_type]); 29 | end 30 | 31 | -------------------------------------------------------------------------------- /marsbar/@marmoire/get_item_param.m: -------------------------------------------------------------------------------- 1 | function value = get_item_param(o, item, param) 2 | % method to get item parameters 3 | % FORMAT value = get_item_param(o, item, param) 4 | % 5 | % o - object 6 | % item - item name 7 | % param - parameter name 8 | % 9 | % Returns 10 | % value - value for parameter 11 | % 12 | % $Id$ 13 | 14 | if nargin < 2 15 | error('Need item name'); 16 | end 17 | if nargin < 3 18 | error('Need parameter name'); 19 | end 20 | 21 | I = get_item_struct(o, item); 22 | 23 | fns = fieldnames(I); 24 | tmp = strmatch('data', fns, 'exact'); 25 | fns(tmp) = []; 26 | 27 | if ~ismember(param, fns) 28 | error(['There is no parameter callled: ' param]); 29 | end 30 | 31 | value = getfield(I, param); 32 | -------------------------------------------------------------------------------- /marsbar/@marmoire/get_item_struct.m: -------------------------------------------------------------------------------- 1 | function I = get_item_struct(o, item) 2 | % get whole item structure, including parameters 3 | % FORMAT I = get_item_struct(o, item) 4 | % 5 | % This is used internally, and might be useful for debugging 6 | % 7 | % o - object 8 | % item - item name 9 | % 10 | % Returns 11 | % I - item structure, with data in field 'data' and/or specified in 12 | % field 'filename' 13 | % 14 | % $Id$ 15 | 16 | if ~item_exists(o, item) 17 | error('Item does not exist'); 18 | end 19 | I = getfield(o.items, item); 20 | -------------------------------------------------------------------------------- /marsbar/@marmoire/isempty_item_data.m: -------------------------------------------------------------------------------- 1 | function tf = isempty_item_data(o, item) 2 | % returns 1 if no data for this item 3 | % FORMAT tf = sjjs(o, item) 4 | % 5 | % o - object 6 | % item - item name 7 | % 8 | % tf - flag, 1 if not empty 9 | % 10 | % $Id$ 11 | 12 | if nargin < 2 13 | error('Need item') 14 | end 15 | I = get_item_struct(o, item); 16 | tf = pr_isempty(I); 17 | -------------------------------------------------------------------------------- /marsbar/@marmoire/item_exists.m: -------------------------------------------------------------------------------- 1 | function tf = item_exists(o, item) 2 | % returns true if there is an item of this name 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | if ~isempty(o.items) 8 | tf = ismember(item, fieldnames(o.items)); 9 | end -------------------------------------------------------------------------------- /marsbar/@marmoire/item_needs_save.m: -------------------------------------------------------------------------------- 1 | function tf = item_needs_save(o, item) 2 | % return 1 if item requires a save 3 | % FORMAT tf = item_needs_save(o, item) 4 | % 5 | % $Id$ 6 | 7 | if nargin < 2 8 | error('Need item') 9 | end 10 | tf = pr_needs_save(get_item_struct(o, item)); -------------------------------------------------------------------------------- /marsbar/@marmoire/private/pr_is_nan.m: -------------------------------------------------------------------------------- 1 | function res = pr_is_nan(v) 2 | res = 0; 3 | if isnumeric(v) && ~isempty(v) 4 | res = isnan(v); 5 | end 6 | return 7 | -------------------------------------------------------------------------------- /marsbar/@marmoire/private/pr_is_nix.m: -------------------------------------------------------------------------------- 1 | function res = pr_is_nix(v) 2 | res = isempty(v) | pr_is_nan(v); 3 | return 4 | -------------------------------------------------------------------------------- /marsbar/@marmoire/private/pr_isempty.m: -------------------------------------------------------------------------------- 1 | function res = pr_isempty(I) 2 | % private function returns 1 if there is no data, or filename 3 | % 4 | % $Id$ 5 | 6 | res = isempty(I.data) & isempty(I.file_name); 7 | -------------------------------------------------------------------------------- /marsbar/@marmoire/private/pr_needs_save.m: -------------------------------------------------------------------------------- 1 | function res = pr_needs_save(I) 2 | % private function returning 1 if item data needs save 3 | % 4 | % $Id$ 5 | 6 | res = ~pr_isempty(I) & I.has_changed & I.save_if_changed; 7 | -------------------------------------------------------------------------------- /marsbar/@marmoire/save_item_data_ui.m: -------------------------------------------------------------------------------- 1 | function [saved_f, o] = save_item_data_ui(o, item, flags, filename) 2 | % save data for item to file using GUI 3 | % FORMAT [saved_f o] = save_item_data_ui(o, item, flags, filename) 4 | % 5 | % o - object 6 | % item - name of item 7 | % flags - flags for save; see save_item_data.m for details 8 | % filename - filename for save 9 | % 10 | % Returns 11 | % saved_f - flag set to 1 if save done, 0 not done, -1 if cancel 12 | % Note that, if saving with more than one item, then the value 13 | % is from the last value saved/not saved. Cancel aborts the 14 | % attempt to save. 15 | % o - possibly modified object (changed filename, maybe data is 16 | % left as a file, and data field made empty) 17 | % 18 | % $Id$ 19 | 20 | if nargin < 2 21 | error('Need item'); 22 | end 23 | if nargin < 3 24 | flags = NaN; 25 | end 26 | if nargin < 4 27 | filename = NaN; 28 | end 29 | 30 | if ~isstruct(flags), flags = []; end 31 | flags.ui = 1; 32 | 33 | [saved_f o] = save_item_data(o, item, flags, filename); -------------------------------------------------------------------------------- /marsbar/@marmoire/set_item_data.m: -------------------------------------------------------------------------------- 1 | function [o, errf] = set_item_data(o, item, data, filename) 2 | % sets data for item 3 | % FORMAT [o errf] = set_item_data(o, item, data, filename) 4 | % 5 | % o - object 6 | % item - name of item to set for 7 | % data - data to set 8 | % filename - filename for data 9 | % 10 | % If neither data nor filename are set, then GUI set is assumed 11 | % 12 | % Returns 13 | % o - object with data set 14 | % errf - flag is 1 if data was not set 15 | % 16 | % $Id$ 17 | 18 | if nargin < 2 19 | error('Need item to set to'); 20 | end 21 | if nargin < 3 22 | data = NaN; 23 | end 24 | if nargin < 4 25 | filename = NaN; 26 | end 27 | 28 | if pr_is_nan(data) & pr_is_nan(filename) 29 | action = 'set_ui'; 30 | else 31 | action = 'set'; 32 | end 33 | [o errf] = do_set(o, item, action, data, filename); 34 | -------------------------------------------------------------------------------- /marsbar/@marmoire/set_item_data_ui.m: -------------------------------------------------------------------------------- 1 | function [o, errf] = set_item_data_ui(o, item) 2 | % sets data for item using GUI 3 | % FORMAT [o, errf] = set_item_data_ui(o, item) 4 | % 5 | % o - object 6 | % item - name of item to set for 7 | % 8 | % Returns 9 | % o - object with data set (probably) 10 | % errf - flag is 1 if data was not set 11 | % 12 | % $Id$ 13 | 14 | if nargin < 2 15 | error('Need item to set to'); 16 | end 17 | 18 | [o errf] = do_set(o, item, 'set_ui'); 19 | -------------------------------------------------------------------------------- /marsbar/@marmoire/set_item_param.m: -------------------------------------------------------------------------------- 1 | function o = set_item_param(o, item, param, value) 2 | % method to set item parameters 3 | % FORMAT o = set_item_param(o, item, param, value) 4 | % 5 | % o - object 6 | % item - item name 7 | % param - parameter name 8 | % value - value to set 9 | % 10 | % Returns 11 | % o - object 12 | % 13 | % $Id$ 14 | 15 | if nargin < 2 16 | error('Need item name'); 17 | end 18 | if nargin < 3 19 | error('Need parameter name'); 20 | end 21 | if nargin < 4 22 | error('Need value to set') 23 | end 24 | 25 | I = get_item_struct(o, item); 26 | 27 | fns = fieldnames(I); 28 | tmp = strmatch('data', fns, 'exact'); 29 | fns(tmp) = []; 30 | 31 | if ~ismember(param, fns) 32 | error(['There is no parameter callled: ' param]); 33 | end 34 | 35 | I = setfield(I, param, value); 36 | o = set_item_struct(o, item, I); -------------------------------------------------------------------------------- /marsbar/@marmoire/set_item_struct.m: -------------------------------------------------------------------------------- 1 | function o = set_item_struct(o, item, item_struct) 2 | % set whole item structure, including parameters 3 | % FORMAT I = get_item_struct(o, item, item_struct) 4 | % 5 | % o - object 6 | % item - item name 7 | % item_struct - item structure 8 | % 9 | % Returns 10 | % o - object with item structure set 11 | % 12 | % $Id$ 13 | 14 | % We might consider error checking here. But hey. 15 | o.items = setfield(o.items, item, item_struct); 16 | -------------------------------------------------------------------------------- /marsbar/@marmoire/update_item_data.m: -------------------------------------------------------------------------------- 1 | function [o, errf] = update_item_data(o, item, data, filename) 2 | % updates data for item (sets data, flags change) 3 | % FORMAT [o, errf] = update_item_data(o, item, data, filename) 4 | % 5 | % o - object 6 | % item - name of item to update for 7 | % data - data to set 8 | % filename - filename for data 9 | % 10 | % Returns 11 | % o - object with data (probably) updated 12 | % errf - flag is 1 if data was not updated for some reason 13 | % 14 | % $Id$ 15 | 16 | if nargin < 2 17 | error('Need item to set to'); 18 | end 19 | if nargin < 3 20 | data = NaN; 21 | end 22 | if nargin < 4 23 | filename = NaN; 24 | end 25 | 26 | [o errf] = do_set(o, item, 'update', data, filename); 27 | -------------------------------------------------------------------------------- /marsbar/@maroi/and.m: -------------------------------------------------------------------------------- 1 | function o = and(o1, o2) 2 | % overloaded add function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('and', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/are_same.m: -------------------------------------------------------------------------------- 1 | function tf = are_same(roi1, roi2, sp) 2 | % returns 1 if rois are the same 3 | % FORMAT tf = are_same(roi1, roi2) 4 | % 5 | % $Id$ 6 | 7 | if nargin < 2 8 | error('Need two ROIs'); 9 | end 10 | if nargin < 3 11 | sp = native_space(roi1); 12 | if isempty(sp) 13 | sp = native_space(roi2); 14 | end 15 | if isempty(sp) 16 | error('Need space for comparison'); 17 | end 18 | end 19 | 20 | mat1 = matrixdata(maroi_matrix(roi1, sp)); 21 | mat2 = matrixdata(maroi_matrix(roi2, sp)); 22 | 23 | tf = all(mat1(:)==mat2(:)); -------------------------------------------------------------------------------- /marsbar/@maroi/back2base.m: -------------------------------------------------------------------------------- 1 | function o = back2base(o) 2 | % back2base method - check for spacebase, transform thereto 3 | % 4 | % $Id$ 5 | 6 | spb = my_classdata('spacebase'); 7 | if isempty(spb) 8 | error('Cannot do arithmetic without defined base space'); 9 | end 10 | o = maroi_matrix(o, spb); -------------------------------------------------------------------------------- /marsbar/@maroi/binarize.m: -------------------------------------------------------------------------------- 1 | function h = binarize(obj, val) 2 | % binarize - returns / sets binarize value for object 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | if ~(val == 0 | val == 1) 8 | error('binarize is 0 or 1 flag'); 9 | end 10 | obj.binarize = val; 11 | h = obj; 12 | else 13 | h = obj.binarize; 14 | end -------------------------------------------------------------------------------- /marsbar/@maroi/c_o_m.m: -------------------------------------------------------------------------------- 1 | function pt = c_o_m(o, sp, pt_type) 2 | % c_o_m method - calculates unweighted centre of mass 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | sp = native_space(o); 8 | end 9 | if nargin < 3 10 | pt_type = 'real'; 11 | end 12 | coords = voxpts(o, sp); 13 | switch pt_type 14 | case {'real','mm'} 15 | coords = realpts(o, sp); 16 | case 'vox' 17 | coords = voxpts(o, sp); 18 | otherwise 19 | error(['Do not recognize point type' pt_type]); 20 | end 21 | pt = mean(coords, 2); -------------------------------------------------------------------------------- /marsbar/@maroi/classdata.m: -------------------------------------------------------------------------------- 1 | function cdata = classdata(obj, varargin) 2 | % classdata method - sets/gets class data 3 | % See help for private/my_classdata for more details 4 | % 5 | % $Id$ 6 | 7 | cdata = my_classdata(varargin{:}); -------------------------------------------------------------------------------- /marsbar/@maroi/descrip.m: -------------------------------------------------------------------------------- 1 | function h = descrip(obj, val) 2 | % name - returns / sets name value for object 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.descrip = val; 8 | h = obj; 9 | else 10 | h = obj.descrip; 11 | end -------------------------------------------------------------------------------- /marsbar/@maroi/display.m: -------------------------------------------------------------------------------- 1 | function display(obj) 2 | % display - method 3 | % 4 | % $Id$ 5 | 6 | inp_str = [inputname(1) ' =']; 7 | 8 | sz = size(obj); 9 | if prod(sz)>1 10 | arr_str = num2str(sz(1)); 11 | for d = 2:length(sz) 12 | arr_str = [arr_str 'x' num2str(sz(d))]; 13 | end 14 | arr_str = [arr_str ' maroi array with first element:']; 15 | 16 | if isequal(get(0,'FormatSpacing'),'compact') 17 | disp(inp_str); 18 | disp(arr_str); 19 | else 20 | disp(' ') 21 | disp(inp_str); 22 | disp(' '); 23 | disp(arr_str); 24 | end 25 | inp_str = [inputname(1) '(1) =']; 26 | obj = obj(1); 27 | end 28 | 29 | X = struct(obj); 30 | bO.label = label(obj); 31 | bO.source = source(obj); 32 | bO.binarize = binarize(obj); 33 | bO.roithresh = roithresh(obj); 34 | bO.spm_hold = spm_hold(obj); 35 | 36 | n = descrip(obj); 37 | if isempty(n), n = '(no descrip)';end 38 | src = ['[' class(obj) ' - ' n ']']; 39 | if isequal(get(0,'FormatSpacing'),'compact') 40 | disp(inp_str); 41 | disp(src); 42 | disp(bO) 43 | disp(X) 44 | else 45 | disp(' ') 46 | disp(inp_str); 47 | disp(' '); 48 | disp(src); 49 | disp(' '); 50 | disp(bO) 51 | disp(' '); 52 | disp(X) 53 | end -------------------------------------------------------------------------------- /marsbar/@maroi/eq.m: -------------------------------------------------------------------------------- 1 | function o = eq(o1, o2) 2 | % overloaded eq function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('eq', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/flip_lr.m: -------------------------------------------------------------------------------- 1 | function o = flip_lr(o) 2 | % flips ROI left / right 3 | % 4 | % $Id$ 5 | 6 | error('Not defined for this ROI type'); -------------------------------------------------------------------------------- /marsbar/@maroi/ge.m: -------------------------------------------------------------------------------- 1 | function o = ge(o1, o2) 2 | % overloaded ge function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('ge', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/gt.m: -------------------------------------------------------------------------------- 1 | function o = gt(o1, o2) 2 | % overloaded gt (greater than) function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('gt', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/has_space.m: -------------------------------------------------------------------------------- 1 | function tf = has_space(obj) 2 | % has_space method - returns true if object has a native space 3 | % 4 | % $Id$ 5 | 6 | tf = 1; % default is true -------------------------------------------------------------------------------- /marsbar/@maroi/history.m: -------------------------------------------------------------------------------- 1 | function h = history(obj, val) 2 | % history - returns / sets history value for object 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.history = val; 8 | h = obj; 9 | else 10 | h = obj.history; 11 | end -------------------------------------------------------------------------------- /marsbar/@maroi/label.m: -------------------------------------------------------------------------------- 1 | function h = label(obj, val) 2 | % label - returns / sets label value for object 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.label = val; 8 | h = obj; 9 | else 10 | h = obj.label; 11 | end -------------------------------------------------------------------------------- /marsbar/@maroi/le.m: -------------------------------------------------------------------------------- 1 | function o = le(o1, o2) 2 | % overloaded le (less than or equal to) function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('le', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/loadobj.m: -------------------------------------------------------------------------------- 1 | function o = loadobj(o) 2 | % loadobj method - fills fields needed for backwards compatibility 3 | % 4 | % $Id$ 5 | 6 | % add cvs tag 7 | if ~isfield(o, 'cvs_version') 8 | o.cvs_version = ''; 9 | end 10 | -------------------------------------------------------------------------------- /marsbar/@maroi/lt.m: -------------------------------------------------------------------------------- 1 | function o = lt(o1, o2) 2 | % overloaded lt (less than) function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('lt', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/maroi_matrix.m: -------------------------------------------------------------------------------- 1 | function obj2 = maroi_matrix(obj, sp) 2 | % maroi_matrix method - converts roi to maroi matrix type 3 | % In this case, the function only checks why it has been inappropriately 4 | % called (if useful, it should have been overridden) 5 | % 6 | % $Id$ 7 | 8 | error('Unexpected call to maroi_matrix on object with no method'); -------------------------------------------------------------------------------- /marsbar/@maroi/minus.m: -------------------------------------------------------------------------------- 1 | function o = minus(o1, o2) 2 | % overloaded minus function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('minus', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/mrdivide.m: -------------------------------------------------------------------------------- 1 | function o = mrdivide(o1, o2) 2 | % overloaded mrdivide (matrix right divide) function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('divide', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/mtimes.m: -------------------------------------------------------------------------------- 1 | function o = mtimes(o1, o2) 2 | % overloaded mtimes function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('times', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/native_space.m: -------------------------------------------------------------------------------- 1 | function sp = native_space(obj) 2 | % native_space method - returns native space of object 3 | % 4 | % $Id$ 5 | 6 | sp = maroi('classdata', 'spacebase'); -------------------------------------------------------------------------------- /marsbar/@maroi/ne.m: -------------------------------------------------------------------------------- 1 | function o = ne(o1, o2) 2 | % overloaded ne function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('ne', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/not.m: -------------------------------------------------------------------------------- 1 | function o = not(o1) 2 | % overloaded not function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | o = domaths('not', o1); -------------------------------------------------------------------------------- /marsbar/@maroi/or.m: -------------------------------------------------------------------------------- 1 | function o = or(o1, o2) 2 | % overloaded or function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('or', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/paramfields.m: -------------------------------------------------------------------------------- 1 | function params = paramfields(o) 2 | % returns struct with fields from maroi object useful for copying objects 3 | % 4 | % $Id$ 5 | 6 | params = struct('spm_hold', o.spm_hold,... 7 | 'binarize', o.binarize,... 8 | 'roithresh', o.roithresh,... 9 | 'descrip', o.descrip,... 10 | 'label', o.label); -------------------------------------------------------------------------------- /marsbar/@maroi/plus.m: -------------------------------------------------------------------------------- 1 | function o = plus(o1, o2) 2 | % overloaded plus function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('plus', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/private/my_loadroi.m: -------------------------------------------------------------------------------- 1 | function o = my_loadroi(fname) 2 | % my_loadroi function - loads ROI from file, sets source field 3 | % 4 | % $Id$ 5 | 6 | if isa(fname, 'maroi') % already loaded 7 | o = fname; 8 | return 9 | end 10 | 11 | o = []; 12 | if iscell(fname), fname = char(fname); end 13 | if size(fname, 1) > 1, error('Can only load one ROI at a time'); end 14 | if isempty(fname), warning('Empty filename'), return, end 15 | fname = deblank(fname); 16 | F = load(fname); 17 | if isfield(F, 'roi') & isa(F.roi, 'maroi') 18 | o = F.roi; 19 | o = source(o, fname); 20 | else 21 | warning(['Loading file ' fname ' did not return an ROI'])' 22 | end 23 | -------------------------------------------------------------------------------- /marsbar/@maroi/private/my_roifname.m: -------------------------------------------------------------------------------- 1 | function roifname = my_roifname(fname) 2 | % changes fname to appropriate ROI format 3 | % 4 | % $Id$ 5 | 6 | if nargin < 1 7 | fname = []; 8 | end 9 | roifname = fname; 10 | if isempty(fname) 11 | return 12 | end 13 | gend = maroi('classdata', 'fileend'); 14 | lg = length(gend); 15 | 16 | [p f e] = fileparts(roifname); 17 | f2 = [f e]; 18 | if length(f2) 1 7 | if val < 0 | val > 1 8 | error('Value must be between 0 and 1'); 9 | end 10 | obj.roithresh = val; 11 | h = obj; 12 | else 13 | h = obj.roithresh; 14 | end -------------------------------------------------------------------------------- /marsbar/@maroi/save_as_image.m: -------------------------------------------------------------------------------- 1 | function v = save_as_image(o, fname, sp) 2 | % method save_as_image - saves ROI as image 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need ROI and filename'); 8 | end 9 | if nargin < 3 10 | sp = []; 11 | end 12 | o = maroi_matrix(o, sp); 13 | v = do_write_image(o, fname); -------------------------------------------------------------------------------- /marsbar/@maroi/save_mricro.m: -------------------------------------------------------------------------------- 1 | function save_mricro(o, fname, sp) 2 | % saves in MRIcro format 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need filename for MRIcro save'); 8 | end 9 | if nargin < 3 10 | sp = native_space(o); 11 | end 12 | rlem = rle(o, sp); 13 | fid = fopen(fname, 'wb'); 14 | if fid == -1 15 | error(['Could not open file ' fname]); 16 | end 17 | fclose(fid); 18 | error('Come to think of it, I don''t understand the format anyhow'); -------------------------------------------------------------------------------- /marsbar/@maroi/saveroi.m: -------------------------------------------------------------------------------- 1 | function roi = saveroi(roi, fname) 2 | % saveroi method - checks fname, sets source field, saves object 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | fname = source(roi); 8 | end 9 | if isempty(fname) 10 | error('Need filename for save'); 11 | end 12 | roi.source = fname; 13 | save(roi.source, 'roi'); -------------------------------------------------------------------------------- /marsbar/@maroi/source.m: -------------------------------------------------------------------------------- 1 | function h = source(obj, val) 2 | % source - returns / sets source value for object 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.source = val; 8 | h = obj; 9 | else 10 | h = obj.source; 11 | end -------------------------------------------------------------------------------- /marsbar/@maroi/spm_hold.m: -------------------------------------------------------------------------------- 1 | function h = spm_hold(obj, val) 2 | % hold - returns / sets hold value for object 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.spm_hold = val; 8 | h = obj; 9 | else 10 | h = obj.spm_hold; 11 | end -------------------------------------------------------------------------------- /marsbar/@maroi/times.m: -------------------------------------------------------------------------------- 1 | function o = times(o1, o2) 2 | % overloaded times function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('times', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi/volume.m: -------------------------------------------------------------------------------- 1 | function v = volume(obj) 2 | % volume method - returns volume of ROI in mm 3 | % 4 | % $Id$ 5 | 6 | sp = native_space(obj); 7 | XYZ = voxpts(obj,sp); 8 | vox = sqrt(sum(sp.mat(1:3,1:3)'.^2)); 9 | v = size(XYZ,2) * prod(vox); -------------------------------------------------------------------------------- /marsbar/@maroi/xor.m: -------------------------------------------------------------------------------- 1 | function o = xor(o1, o2) 2 | % overloaded xor function 3 | % 4 | % $Id$ 5 | 6 | if isa(o1, 'maroi'),o1 = back2base(o1);end 7 | if isa(o2, 'maroi'),o2 = back2base(o2);end 8 | o = domaths('xor', o1, o2); -------------------------------------------------------------------------------- /marsbar/@maroi_box/centre.m: -------------------------------------------------------------------------------- 1 | function c = centre(obj, val) 2 | % centre method - sets / returns centre of ROI in mm 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.centre = val; 8 | end 9 | c = obj.centre; -------------------------------------------------------------------------------- /marsbar/@maroi_box/flip_lr.m: -------------------------------------------------------------------------------- 1 | function o = flip_lr(o) 2 | % flips ROI left / right 3 | % 4 | % $Id$ 5 | 6 | o.centre(1) = o.centre(1)*-1; 7 | -------------------------------------------------------------------------------- /marsbar/@maroi_box/is_empty_roi.m: -------------------------------------------------------------------------------- 1 | function tf = is_empty_roi(o) 2 | % returns 1 if ROI contains no volume 3 | % 4 | % $Id$ 5 | 6 | tf = isempty(o.centre); -------------------------------------------------------------------------------- /marsbar/@maroi_box/maroi_box.m: -------------------------------------------------------------------------------- 1 | function o = maroi_box(params) 2 | % maroi_box - class constructor 3 | % inputs [defaults] 4 | % params - a structure containing any fields for a maroi parent and 5 | % .centre - a 1x3 coordinate in mm 6 | % .widths - 1x3 widths in X Y Z in mm 7 | % 8 | % $Id$ 9 | 10 | myclass = 'maroi_box'; 11 | defstruct = struct('centre', [0 0 0], 'widths', [0 0 0]); 12 | 13 | if nargin < 1 14 | params = []; 15 | end 16 | if isa(params, myclass) 17 | o = params; 18 | return 19 | end 20 | 21 | % fill with defaults 22 | pparams = mars_struct('ffillmerge', defstruct, params); 23 | 24 | % umbrella object, parse out fields for (this object and children) 25 | [uo, pparams] = maroi_shape(pparams); 26 | 27 | % reparse parameters into those for this object, children 28 | [pparams, others] = mars_struct('split', pparams, defstruct); 29 | 30 | % check resulting input 31 | if size(pparams.centre, 2) == 1 32 | pparams.centre = pparams.centre'; 33 | end 34 | if size(pparams.widths, 2) == 1 35 | pparams.widths = pparams.widths'; 36 | end 37 | if size(pparams.widths, 2) == 1 38 | pparams.widths = ones(1,3) * pparams.widths; 39 | end 40 | 41 | o = class(pparams, myclass, uo); 42 | return -------------------------------------------------------------------------------- /marsbar/@maroi_box/volume.m: -------------------------------------------------------------------------------- 1 | function v = volume(obj) 2 | % volume method - returns volume of ROI in mm 3 | % 4 | % $Id$ 5 | 6 | v = prod(obj.widths); -------------------------------------------------------------------------------- /marsbar/@maroi_box/voxpts.m: -------------------------------------------------------------------------------- 1 | function [pts, vals] = voxpts(obj, sp) 2 | % voxpts method - voxels within a box in given space 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need object and space arguments'); 8 | end 9 | sp = mars_space(sp); 10 | 11 | mc = obj.centre; 12 | mw = obj.widths; 13 | 14 | % find voxels that are within box 15 | dim = sp.dim(1:3); dim = dim(:); 16 | vox = sqrt(sum(sp.mat(1:3,1:3)'.^2)); 17 | vd = mw ./ vox / 2; 18 | vc = sp.mat \ [mc(1:3) 1]'; 19 | vc = vc(1:3)'; 20 | blim = [max([1 1 1; ceil(vc-vd)]); min([sp.dim(1:3); floor(vc+vd)])]; 21 | [R,C,P]=ndgrid(... 22 | blim(1,1):blim(2,1),blim(1,2):blim(2,2),blim(1,3):blim(2,3)); 23 | pts = [R(:)';C(:)';P(:)']; 24 | 25 | vals = ones(1, size(pts, 2)); -------------------------------------------------------------------------------- /marsbar/@maroi_image/flip_lr.m: -------------------------------------------------------------------------------- 1 | function o = flip_lr(o) 2 | % flips ROI left / right 3 | % 4 | % $Id 5 | 6 | % Requires change to ROI data -> return as maroi_matrix 7 | 8 | o = flip_lr(maroi_matrix(o)); 9 | -------------------------------------------------------------------------------- /marsbar/@maroi_image/loadobj.m: -------------------------------------------------------------------------------- 1 | function o = loadobj(o) 2 | % loadobj method - reloads matrix from img file 3 | % 4 | % $Id$ 5 | 6 | % Note that the image needs full processing before 7 | % setting into the matrix. After this, the processed 8 | % natrix data becomes an image snapshot for the memory 9 | % lifetime of the object 10 | 11 | [img errstr] = my_vol_func(o); 12 | if isempty(img) 13 | if strcmp(errstr, 'Cant open image file.') 14 | errstr = sprintf('%s\nHas ROI image %s been moved?\n%s\n', ... 15 | errstr, o.vol.fname,... 16 | 'Try to reattach with marsbar(''attach_image'')'); 17 | end 18 | error(errstr); 19 | end 20 | 21 | % set using maroi_matrix object to avoid object conversion 22 | o.maroi_matrix = matrixdata(o.maroi_matrix,img); 23 | -------------------------------------------------------------------------------- /marsbar/@maroi_image/maroi_matrix.m: -------------------------------------------------------------------------------- 1 | function o = maroi_matrix(o, sp) 2 | % maroi_matrix method - converts maroi_image to maroi_matrix 3 | % 4 | % $Id$ 5 | 6 | o = o.maroi_matrix; 7 | if nargin > 1 8 | o = maroi_matrix(o, sp); 9 | end -------------------------------------------------------------------------------- /marsbar/@maroi_image/private/my_vol_func.m: -------------------------------------------------------------------------------- 1 | function [img, errstr] = my_vol_func(vol, func) 2 | % checks vol and func, returns processed image matrix or error 3 | % 4 | % $Id$ 5 | 6 | if nargin < 1 7 | error('Need object or vol struct'); 8 | end 9 | if isa(vol, 'maroi_image') 10 | [vol def_func] = deal(vol.vol, vol.func); 11 | else 12 | def_func = ''; 13 | end 14 | if nargin < 2 15 | func = ''; 16 | end 17 | if isempty(func), func = def_func; end 18 | 19 | img = []; 20 | errstr = ''; 21 | 22 | if ischar(vol) % filename passed? 23 | try 24 | vol = spm_vol(vol); 25 | catch 26 | errstr = lasterr; 27 | return 28 | end 29 | end 30 | 31 | if isempty(vol) 32 | errstr = 'vol is empty'; 33 | return 34 | end 35 | if ~isstruct(vol) 36 | errstr = 'vol is not struct'; 37 | return 38 | end 39 | if ~isfield(vol, 'fname') 40 | errstr = 'vol does not contain fname field'; 41 | return 42 | end 43 | 44 | try 45 | % load image into matrix 46 | img = spm_read_vols(vol); 47 | catch 48 | errstr = lasterr; 49 | return 50 | end 51 | 52 | % apply and check function if passed 53 | if ~isempty(func) 54 | sz = size(img); 55 | try 56 | img = double(eval(func)); 57 | catch 58 | errstr = lasterr; 59 | img = []; 60 | return 61 | end 62 | 63 | % check that the image has not changed size 64 | sz2 = size(img); 65 | if length(sz) ~= length(sz2) | any(sz ~= sz2) 66 | img = []; 67 | errstr = sprintf('Bad function "%s" - the image has changed size',... 68 | func); 69 | end 70 | end -------------------------------------------------------------------------------- /marsbar/@maroi_image/saveobj.m: -------------------------------------------------------------------------------- 1 | function o = saveobj(o) 2 | % saveobj method - removes matrix information from parent to save space 3 | % 4 | % $Id$ 5 | 6 | % set using maroi_matrix object to avoid object conversion 7 | o.maroi_matrix = matrixdata(o.maroi_matrix, []); 8 | -------------------------------------------------------------------------------- /marsbar/@maroi_image/vol.m: -------------------------------------------------------------------------------- 1 | function h = vol(obj, val) 2 | % vol - returns / sets image vol for object 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | img = my_vol_func(val, obj.func); 8 | obj.vol = val; 9 | obj = matrixdata(obj, img); 10 | h = obj; 11 | else 12 | h = obj.vol; 13 | end -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/do_write_image.m: -------------------------------------------------------------------------------- 1 | function v = do_write_image(o, fname) 2 | % method saves matrix as image and returns spm_vol 3 | % 4 | % $Id$ 5 | 6 | v = mars_vol_utils('def_vol'); 7 | v.fname = fname; 8 | v.mat = o.mat; 9 | v.dim = size(o.dat); 10 | 11 | if binarize(o) 12 | v = mars_vol_utils('set_type', v, 'uint8'); 13 | else 14 | v = mars_vol_utils('set_type', v, 'float'); 15 | end 16 | 17 | v = spm_create_vol(v); 18 | v = spm_write_vol(v, o.dat); -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/flip_lr.m: -------------------------------------------------------------------------------- 1 | function o = flip_lr(o) 2 | % flips ROI left / right 3 | % 4 | % $Id$ 5 | 6 | M = eye(4); M(1) = -1; 7 | o.mat = M * o.mat; 8 | -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/is_empty_roi.m: -------------------------------------------------------------------------------- 1 | function tf = is_empty_roi(o) 2 | % is_empty_roi - returns true if ROI contains no volume 3 | % 4 | % $Id$ 5 | 6 | tf = ~any(o.dat(:)); -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/loadobj.m: -------------------------------------------------------------------------------- 1 | function o = loadobj(o) 2 | % loadobj function - undoes run length encoding if appropriate 3 | % 4 | % $Id$ 5 | 6 | m = o.dat; 7 | if isfield(m, 'rlem') 8 | dat = my_rld(m.rlem); 9 | o.dat = reshape(dat, m.dim); 10 | end -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/matrixdata.m: -------------------------------------------------------------------------------- 1 | function dat = matrixdata(o, dat) 2 | % matrixdata method - gets matrix from ROI object 3 | % 4 | % $Id$ 5 | 6 | % a warning here about empty matrices 7 | if nargin > 1 % call to set matrix data 8 | % change to maroi_matrix type before setting data 9 | o = maroi_matrix(o); 10 | 11 | % apply implied thresholding 12 | tmp = find(isnan(dat) | abs(dat) < roithresh(o)); 13 | if binarize(o), dat(:) = 1; end 14 | dat(tmp) = 0; 15 | 16 | o.dat = dat; 17 | dat = o; 18 | 19 | else 20 | dat = o.dat; 21 | end -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/native_space.m: -------------------------------------------------------------------------------- 1 | function sp = native_space(obj) 2 | % native_space method - returns native space of object 3 | % 4 | % $Id$ 5 | 6 | sp = mars_space(size(obj.dat), obj.mat); -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/private/my_rld.m: -------------------------------------------------------------------------------- 1 | function mat = my_rld(rlem, dim) 2 | % function to do run length decoding 3 | % 4 | % $Id$ 5 | 6 | sz = sum(rlem(:,1)); 7 | mat = zeros(sz, 1); 8 | st = 1; 9 | for i = 1:size(rlem, 1) 10 | tm = zeros(rlem(i,1),1) + rlem(i,2); 11 | st2 = st + rlem(i,1); 12 | mat(st:st2-1) = tm; 13 | st = st2; 14 | end -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/private/my_rle.m: -------------------------------------------------------------------------------- 1 | function rlem = my_rle(m) 2 | % method to do run length encoding on matrix 3 | % 4 | % $Id$ 5 | 6 | m = m(:); 7 | dps = [1; find(diff(m))+1]; 8 | rlem = [diff([dps; length(m)+1]), m(dps)]; -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/rebase.m: -------------------------------------------------------------------------------- 1 | function [pts, vals] = rebase(obj, sp, flags) 2 | % rebase method - returns data from maroi_matrix in new space 3 | % Unless flags contains 'i', returns [pts, vals] 4 | % otherwise returns matrix in new space 5 | % 6 | % $Id$ 7 | 8 | if nargin < 2 9 | error('Need space to give voxel points'); 10 | end 11 | if nargin < 3 12 | flags = ''; 13 | end 14 | if isempty(flags), flags = ' ';end 15 | 16 | sp = mars_space(sp); 17 | vol = obj.dat; 18 | mat = spm_mat(obj); 19 | Hold = spm_hold(obj); 20 | th = roithresh(obj); 21 | binf = binarize(obj); 22 | 23 | if any(flags == 'i') 24 | pts = zeros(sp.dim(1:3)); 25 | vals = []; 26 | else % points call 27 | pts = cell(1, sp.dim(3)); 28 | multvc = cell(1, sp.dim(3)); 29 | end 30 | 31 | for z=1:sp.dim(3), 32 | M = inv(mat) * sp.mat * spm_matrix([0 0 z]); 33 | img = spm_slice_vol(vol,M,sp.dim(1:2),Hold); 34 | tmp = abs(img) >= th; 35 | img(~tmp) = 0; 36 | if any(tmp(:)) 37 | if binf, img(tmp) = 1; end 38 | if any(flags == 'i') % image to return 39 | pts(:,:,z) = img; 40 | else % point list 41 | tmp = find(tmp); 42 | multvc(z) = {img(tmp)'}; 43 | tmp = tmp-1; 44 | y = floor(tmp/sp.dim(1)); 45 | x = tmp - (y*sp.dim(1)); 46 | o = ones(1, length(x)); 47 | pts(z) = {[[x y]'+1; o*z]}; 48 | end 49 | end 50 | end 51 | if ~any(flags == 'i') 52 | pts = [pts{:}]; 53 | vals = [multvc{:}]; 54 | end -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/saveobj.m: -------------------------------------------------------------------------------- 1 | function o = saveobj(o) 2 | % saveobj function - does run length encoding if helpful 3 | % 4 | % $Id$ 5 | 6 | m = o.dat; 7 | if isnumeric(m) 8 | rlem = my_rle(m); 9 | if prod(size(rlem)) < prod(size(m)) 10 | o.dat = struct('rlem', rlem, 'dim', size(m)); 11 | end 12 | end -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/spm_mat.m: -------------------------------------------------------------------------------- 1 | function M = spm_mat(obj) 2 | % spm_mat method - returns mat file defining orientation etc 3 | % 4 | % $Id$ 5 | 6 | M = obj.mat; -------------------------------------------------------------------------------- /marsbar/@maroi_matrix/voxpts.m: -------------------------------------------------------------------------------- 1 | function [pts, vals] = voxpts(obj, sp) 2 | % voxpts method - returns 3xN ijk matrix in voxels 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need space to give voxel points'); 8 | end 9 | [pts, vals] = rebase(obj, sp, ''); -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/flip_lr.m: -------------------------------------------------------------------------------- 1 | function o = flip_lr(o) 2 | % flips ROI left / right 3 | % 4 | % $Id$ 5 | 6 | M = eye(4); M(1) = -1; 7 | o.mat = M * o.mat; 8 | o.voxblock = my_voxblock(o.XYZ, o.mat, o.vals); 9 | -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/getvals.m: -------------------------------------------------------------------------------- 1 | function v = getvals(o) 2 | % returns vals for pointlist object 3 | % 4 | % $Id$ 5 | 6 | if ~isempty(o.vals) 7 | v = o.vals; 8 | else 9 | v = ones(1, size(o.XYZ,2)); 10 | end -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/is_empty_roi.m: -------------------------------------------------------------------------------- 1 | function tf = is_empty_roi(o) 2 | % is_empty_roi - returns true if ROI contains no volume 3 | % 4 | % $Id$ 5 | 6 | tf = isempty(o.XYZ); -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/loadobj.m: -------------------------------------------------------------------------------- 1 | function o = loadobj(o) 2 | % loadobj method - creates temporary voxel block 3 | % 4 | % $Id$ 5 | 6 | o.voxblock = my_voxblock(o.XYZ, o.mat, o.vals); -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/maroi_matrix.m: -------------------------------------------------------------------------------- 1 | function obj2 = maroi_matrix(obj, space) 2 | % maroi_matrix method - converts roi to maroi matrix type 3 | % 4 | % Without space arg, returns object in native space 5 | % 6 | % $Id$ 7 | 8 | params = paramfields(obj); 9 | params.dat = obj.voxblock.dat; 10 | params.mat = obj.voxblock.mat; 11 | 12 | % put into maroi_matrix object 13 | obj2 = maroi_matrix(params); 14 | 15 | % rebase using maroi_matrix method if space argument passed 16 | if nargin > 1 17 | obj2 = maroi_matrix(obj2, space); 18 | end -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/native_space.m: -------------------------------------------------------------------------------- 1 | function sp = native_space(obj) 2 | % native_space method - returns native space of object 3 | % 4 | % $Id$ 5 | 6 | sp = mars_space(size(obj.voxblock.dat), obj.voxblock.mat); -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/private/my_voxblock.m: -------------------------------------------------------------------------------- 1 | function vblock = my_voxblock(pts, mat, vals) 2 | % returns voxel block and modified mat file for pointlist 3 | % 4 | % $Id$ 5 | 6 | if isempty(vals) 7 | vals = ones(1, size(pts,2)); 8 | end 9 | 10 | % dimensions of containing block 11 | st = min(pts, [], 2)'; 12 | fn = max(pts, [], 2)'; 13 | dsz = fn-st+1; 14 | 15 | % reset mat according to voxel block 16 | newM = mat * spm_matrix(st-1); 17 | 18 | % set voxels in block 19 | dat1 = zeros(dsz); 20 | dpts = pts - (st'-1) * ones(1, size(pts,2)); 21 | dinds = dpts(1,:) + ... 22 | (dpts(2,:)-1) * dsz(1) + ... 23 | (dpts(3,:)-1) * dsz(1)*dsz(2); 24 | dat1(dinds) = vals; 25 | 26 | % add a shell of one voxel to isolate from interpolation 0s 27 | dat = zeros(dsz+2); 28 | dat(2:end-1,2:end-1,2:end-1) = dat1; 29 | mat = newM * spm_matrix([-1 -1 -1]); 30 | 31 | vblock = struct('dat', dat, 'mat', mat); -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/saveobj.m: -------------------------------------------------------------------------------- 1 | function o = saveobj(o) 2 | % saveobj method - removes temporary voxblock structure 3 | % 4 | % $Id$ 5 | 6 | o.voxblock = []; -------------------------------------------------------------------------------- /marsbar/@maroi_pointlist/voxpts.m: -------------------------------------------------------------------------------- 1 | function [pts, vals] = voxpts(o, sp) 2 | % voxpts method - returns 3xN ijk matrix in voxels 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need space for voxpts call') 8 | end 9 | 10 | sp = mars_space(sp); 11 | 12 | % to maroi_matrix object 13 | mo = maroi_matrix(o); 14 | 15 | % and return values 16 | [pts, vals] = voxpts(mo, sp); -------------------------------------------------------------------------------- /marsbar/@maroi_shape/c_o_m.m: -------------------------------------------------------------------------------- 1 | function pt = c_o_m(o, sp, pt_type) 2 | % c_o_m method - calculates centre of mass 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | sp = ''; 8 | end 9 | if nargin < 3 10 | pt_type = 'real'; 11 | end 12 | pt = centre(o); 13 | switch pt_type 14 | case {'real','mm'} 15 | case 'vox' 16 | if isempty(sp) 17 | error('Need space to define voxel centre of mass'); 18 | end 19 | pt = sp.mat * [pt; 1]; 20 | pt = pt(1:3)'; 21 | otherwise 22 | error(['Do not recognize point type' pt_type]); 23 | end 24 | -------------------------------------------------------------------------------- /marsbar/@maroi_shape/has_space.m: -------------------------------------------------------------------------------- 1 | function tf = has_space(obj) 2 | % has_space method - returns true if object has a native space 3 | % 4 | % $Id$ 5 | 6 | tf = 0; % not true of shape object -------------------------------------------------------------------------------- /marsbar/@maroi_shape/maroi_matrix.m: -------------------------------------------------------------------------------- 1 | function o2 = maroi_matrix(o, space) 2 | % method to convert shape objects to maroi_matrix objects 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | space = []; 8 | end 9 | if isempty(space) 10 | space = native_space(o); 11 | end 12 | if isempty(space) 13 | error('Need space to create maroi_matrix'); 14 | end 15 | 16 | params = paramfields(o); 17 | params.mat = space.mat; 18 | dim = space.dim(1:3); 19 | params.dat = zeros(dim); 20 | 21 | [pts vals] = voxpts(o, space); 22 | dinds = pts(1,:) + ... 23 | (pts(2,:)-1) * dim(1) + ... 24 | (pts(3,:)-1) * dim(1)*dim(2); 25 | 26 | params.dat(dinds) = vals; 27 | o2 = maroi_matrix(params); -------------------------------------------------------------------------------- /marsbar/@maroi_shape/maroi_shape.m: -------------------------------------------------------------------------------- 1 | function [o, others] = maroi_shape(params) 2 | % maroi_shape - (virtual) shape roi class constructor 3 | % FORMAT [o, others] = maroi_shape(params) 4 | % Inputs [defaults] 5 | % params - a structure containing any fields for a maroi parent 6 | % 7 | % Only used by inheriting objects 8 | % 9 | % $Id$ 10 | 11 | myclass = 'maroi_shape'; 12 | defstruct = struct('shape', []); 13 | 14 | if nargin < 1 15 | params = []; 16 | end 17 | if isa(params, myclass) 18 | o = params; 19 | return 20 | end 21 | 22 | % fill with defaults 23 | pparams = mars_struct('ffillmerge', defstruct, params); 24 | 25 | % umbrella object, parse out fields for (this object and children) 26 | [uo, pparams] = maroi(pparams); 27 | 28 | % reparse parameters into those for this object, children 29 | [pparams, others] = mars_struct('split', pparams, defstruct); 30 | 31 | o = class(pparams, myclass, uo); 32 | 33 | return -------------------------------------------------------------------------------- /marsbar/@maroi_sphere/centre.m: -------------------------------------------------------------------------------- 1 | function c = centre(obj, val) 2 | % centre method - sets / returns centre of ROI in mm 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.centre = val; 8 | end 9 | c = obj.centre; -------------------------------------------------------------------------------- /marsbar/@maroi_sphere/flip_lr.m: -------------------------------------------------------------------------------- 1 | function o = flip_lr(o) 2 | % flips ROI left / right 3 | % 4 | % $Id$ 5 | 6 | o.centre(1) = o.centre(1)*-1; 7 | -------------------------------------------------------------------------------- /marsbar/@maroi_sphere/is_empty_roi.m: -------------------------------------------------------------------------------- 1 | function tf = is_empty_roi(o) 2 | % is_empty_roi - returns true if ROI contains no volume 3 | % 4 | % $Id$ 5 | 6 | tf = isempty(o.centre); -------------------------------------------------------------------------------- /marsbar/@maroi_sphere/maroi_sphere.m: -------------------------------------------------------------------------------- 1 | function [o, others] = maroi_sphere(params) 2 | % maroi_sphere - class constructor 3 | % FORMAT [o, others] = maroi_sphere(params) 4 | % Inputs [defaults] 5 | % params - a structure containing any fields for a maroi parent and 6 | % .centre - a 1x3 coordinate in mm 7 | % .radius - a 1x1 radius in mm 8 | % 9 | % 10 | % $Id$ 11 | 12 | myclass = 'maroi_sphere'; 13 | defstruct = struct('centre', [0 0 0],'radius', 0); 14 | 15 | if nargin < 1 16 | params = []; 17 | end 18 | if isa(params, myclass) 19 | o = params; 20 | return 21 | end 22 | 23 | % fill with defaults 24 | pparams = mars_struct('ffillmerge', defstruct, params); 25 | 26 | % umbrella object, parse out fields for (this object and children) 27 | [uo, pparams] = maroi_shape(pparams); 28 | 29 | % reparse parameters into those for this object, children 30 | [pparams, others] = mars_struct('split', pparams, defstruct); 31 | 32 | % check resulting input 33 | if size(pparams.centre, 2) == 1 34 | pparams.centre = pparams.centre'; 35 | end 36 | % enforce radius as double for vox->mm conversions 37 | pparams.radius = double(pparams.radius) 38 | 39 | o = class(pparams, myclass, uo); 40 | return 41 | -------------------------------------------------------------------------------- /marsbar/@maroi_sphere/volume.m: -------------------------------------------------------------------------------- 1 | function v = volume(obj) 2 | % volume method - returns volume of ROI in mm 3 | % 4 | % $Id$ 5 | 6 | v = (4/3*pi)*obj.radius^3; -------------------------------------------------------------------------------- /marsbar/@maroi_sphere/voxpts.m: -------------------------------------------------------------------------------- 1 | function [pts, vals] = voxpts(obj, sp) 2 | % voxpts method - voxels within a sphere in given space 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | error('Need object and space arguments'); 8 | end 9 | sp = mars_space(sp); 10 | 11 | mc = obj.centre; 12 | mr = obj.radius; 13 | 14 | % find voxels that are within sphere 15 | vox = sqrt(sum(sp.mat(1:3,1:3)'.^2)); 16 | vr = mr ./ vox; 17 | vc = sp.mat \ [mc(1:3) 1]'; 18 | vc = vc(1:3)'; 19 | blim = [max([1 1 1; ceil(vc-vr)]); min([sp.dim(1:3); floor(vc+vr)])]; 20 | [R,C,P]=ndgrid(... 21 | blim(1,1):blim(2,1),blim(1,2):blim(2,2),blim(1,3):blim(2,3)); 22 | vXYZ = [R(:)';C(:)';P(:)']; 23 | o = ones(1, size(vXYZ, 2)); 24 | pts = find(sqrt(sum(((vXYZ-(vc'*o)) .* (vox'*o)).^2)) <= mr); 25 | pts = vXYZ(:,pts); 26 | vals = ones(1, size(pts, 2)); -------------------------------------------------------------------------------- /marsbar/@mars_space/display.m: -------------------------------------------------------------------------------- 1 | function display(obj) 2 | % display method for mars_space object 3 | % 4 | % $Id$ 5 | 6 | X = struct(obj); 7 | src = ['[mars_space object]']; 8 | if isequal(get(0,'FormatSpacing'),'compact') 9 | disp([inputname(1) ' =']); 10 | disp(src); 11 | disp(X) 12 | else 13 | disp(' ') 14 | disp([inputname(1) ' =']); 15 | disp(' '); 16 | disp(src); 17 | disp(' '); 18 | disp(X) 19 | end -------------------------------------------------------------------------------- /marsbar/@mars_space/eq.m: -------------------------------------------------------------------------------- 1 | function tf = eq(sp1, sp2) 2 | % overloaded eq method for mars_space objects 3 | % 4 | % $Id$ 5 | 6 | if all(sp1.dim == sp2.dim) & all((abs(sp1.mat(:) - sp2.mat(:)))< eps) 7 | tf = 1; 8 | else 9 | tf = 0; 10 | end -------------------------------------------------------------------------------- /marsbar/@mars_space/subsasgn.m: -------------------------------------------------------------------------------- 1 | function result = subsasgn(this, Struct, rhs) 2 | % method to over load . notation in assignments. 3 | % Publicize subscripted assignments to private fields of object. 4 | % 5 | % $Id$ 6 | 7 | result = builtin('subsasgn', this, Struct, rhs ); -------------------------------------------------------------------------------- /marsbar/@mars_space/subsref.m: -------------------------------------------------------------------------------- 1 | function result = subsref(this, Struct) 2 | % method to overload the . notation. 3 | % Publicize subscripted reference to private fields of object. 4 | % 5 | % $Id$ 6 | 7 | result = builtin('subsref', this, Struct ); -------------------------------------------------------------------------------- /marsbar/@marsy/as_summary_only.m: -------------------------------------------------------------------------------- 1 | function out_o = as_summary_only(o) 2 | % returns object with region data removed 3 | % 4 | % Useful to save memory 5 | if ~is_summarized(o) 6 | out_o = resummarize(o); 7 | else 8 | out_o = o; 9 | end 10 | st = y_struct(o); 11 | if ~isfield(st, 'regions') 12 | return 13 | end 14 | for rno = 1:length(st.regions) 15 | st.regions{rno} = mars_struct('strip', st.regions{rno}, ... 16 | {'Y', 'weights','vXYZ'}); 17 | end 18 | out_o = y_struct(out_o, st); 19 | return 20 | -------------------------------------------------------------------------------- /marsbar/@marsy/block_rows.m: -------------------------------------------------------------------------------- 1 | function r = block_rows(Y, rows) 2 | % gets/sets cell array of rows for each (subject/session) block 3 | % 4 | % $Id$ 5 | 6 | ys = y_struct(Y); 7 | n = n_time_points(Y); 8 | if nargin < 2 % get 9 | if ~isfield(ys, 'block_rows') 10 | r = {[1:n]'}; 11 | else 12 | r = ys.block_rows; 13 | end 14 | else % set 15 | if ~iscell(rows) 16 | error('Need cell array of matrices for blocks'); 17 | end 18 | for i = 1:prod(size(rows)) 19 | rows{i} = rows{i}(:); 20 | if any(rows{i} < 1 | rows{i} > n) 21 | error(sprintf('Row %d: values out of range', i)); 22 | end 23 | end 24 | ys.block_rows = rows; 25 | r = y_struct(Y, ys); 26 | end -------------------------------------------------------------------------------- /marsbar/@marsy/can_summarize.m: -------------------------------------------------------------------------------- 1 | function tf = can_summarize(o) 2 | % returns 1 if object contains enough information to be summarized 3 | % or is already summarized 4 | % 5 | % $Id$ 6 | 7 | tf = 1; 8 | if is_summarized(o), return, end 9 | for i = 1:n_regions(o); 10 | r_samp = region_size(o, i, 2); 11 | if r_samp > 1 % at least one region needs summarizing 12 | % check for summary function 13 | s = sumfunc(o); 14 | tf = ~isempty(s) & ~strcmp(s, 'unknown'); 15 | break 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /marsbar/@marsy/display.m: -------------------------------------------------------------------------------- 1 | function display(obj) 2 | % display method for marsy objects 3 | % 4 | % $Id$ 5 | 6 | src = '[MarsBaR data object]'; 7 | if length(obj) > 1 % array of objects 8 | sz = size(obj); 9 | src = sprintf('%d by %d array of %s', sz(1), sz(2), src); 10 | if isequal(get(0,'FormatSpacing'),'compact') 11 | disp([inputname(1) ' =']); 12 | disp(src); 13 | else 14 | disp(' ') 15 | disp([inputname(1) ' =']); 16 | disp(' '); 17 | disp(src); 18 | disp(' '); 19 | end 20 | else % single object 21 | X = char(summary(obj)); 22 | if isequal(get(0,'FormatSpacing'),'compact') 23 | disp([inputname(1) ' =']); 24 | disp(src); 25 | disp(X) 26 | else 27 | disp(' ') 28 | disp([inputname(1) ' =']); 29 | disp(' '); 30 | disp(src); 31 | disp(' '); 32 | disp(X) 33 | disp(' '); 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /marsbar/@marsy/eq.m: -------------------------------------------------------------------------------- 1 | function tf = eq(Y1, Y2) 2 | % method overrides == operator 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | if ~isa(Y1, 'marsy') | ~isa(Y2, 'marsy'), return, end 8 | if ~all(summary_size(Y1) == summary_size(Y2)), return, end 9 | if is_summarized(Y1) ~= is_summarized(Y2), return, end 10 | if is_summarized(Y1) 11 | y1 = summary_data(Y1); 12 | y2 = summary_data(Y2); 13 | else 14 | y1 = region_data(Y1); 15 | y1 = [y1{:}]; 16 | y2 = region_data(Y2); 17 | y2 = [y2{:}]; 18 | end 19 | tf = all(all(y1 == y2)); 20 | 21 | -------------------------------------------------------------------------------- /marsbar/@marsy/is_summarized.m: -------------------------------------------------------------------------------- 1 | function tf = is_summarized(o) 2 | % returns 1 if object contains calculated summary data 3 | % 4 | % $Id$ 5 | 6 | st = y_struct(o); 7 | tf = isfield(st, 'Y') & isfield(st, 'Yvar'); -------------------------------------------------------------------------------- /marsbar/@marsy/is_summary_only.m: -------------------------------------------------------------------------------- 1 | function tf = is_summary_only(o) 2 | % method returns 1 if object only contains summary data 3 | % 4 | % $Id$ 5 | 6 | tf = 0; 7 | st = y_struct(o); 8 | if isfield(st, 'Y') 9 | if ~isfield(st, 'regions') 10 | tf = 1; 11 | else 12 | Y = region_data(o); 13 | Y = [Y{:}]; 14 | tf = size(Y, 2) == size(st.Y, 2); 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /marsbar/@marsy/is_valid.m: -------------------------------------------------------------------------------- 1 | function tf = is_valid(o) 2 | % method returns 1 if object contains valid data 3 | % 4 | % $Id$ 5 | 6 | st = y_struct(o); 7 | tf = isfield(st, 'Y') | isfield(st, 'regions'); -------------------------------------------------------------------------------- /marsbar/@marsy/join.m: -------------------------------------------------------------------------------- 1 | function o = join(varargin) 2 | % joins marsy objects into one object 3 | % 4 | % $Id$ 5 | 6 | % assemble all input object into a cell array 7 | % (deals with arrays of objects) 8 | o_c_a = {}; 9 | ctr = 0; 10 | n_n = []; 11 | for v = 1:nargin 12 | o_arr = varargin{v}; 13 | for i = 1:prod(size(o_arr)) 14 | ctr = ctr + 1; 15 | 16 | % Check number of time points 17 | n = n_time_points(o_arr(i)); 18 | if isempty(n_n), n_n = n; 19 | else 20 | if n ~= n_n 21 | error(sprintf(... 22 | 'Regions %d and %d have different numbers of time points',... 23 | ctr, ctr-1)); 24 | end 25 | end 26 | 27 | o_c_a{ctr} = o_arr(i); 28 | end 29 | end 30 | 31 | o = o_c_a{1}; 32 | want_sum_f = 1; 33 | sum_func = sumfunc(o); 34 | regions = {}; 35 | Y = []; 36 | Yvar = []; 37 | for i = 1:ctr 38 | o_a = o_c_a{i}; 39 | if want_sum_f 40 | % if summary function differs from other 41 | % objects, abort collecting summary data 42 | if ~strcmp(sum_func,sumfunc(o_a)) | ... 43 | ~can_summarize(o_a) 44 | want_sum_f = 0; 45 | else 46 | if ~is_summarized(o_a) 47 | o_a = resummarize(o_a); 48 | end 49 | [t1 t2] = summary_data(o_a); 50 | Y = [Y t1]; 51 | Yvar = [Yvar t2]; 52 | end 53 | end 54 | regions = [regions region(o_a)]; 55 | end 56 | 57 | st = y_struct(o); 58 | if want_sum_f 59 | st.Y = Y; 60 | st.Yvar = Yvar; 61 | st.sumfunc = sum_func; 62 | else 63 | st = mars_struct('strip', st, {'Y','Yvar','sumfunc'}); 64 | end 65 | st.regions = regions; 66 | o = y_struct(o, st); -------------------------------------------------------------------------------- /marsbar/@marsy/n_blocks.m: -------------------------------------------------------------------------------- 1 | function n = n_blocks(Y) 2 | % method returns number of subjects/sessions in data 3 | % 4 | % $Id$ 5 | 6 | n = length(block_rows(Y)); -------------------------------------------------------------------------------- /marsbar/@marsy/n_regions.m: -------------------------------------------------------------------------------- 1 | function n = n_regions(o) 2 | % get number of regions 3 | % 4 | % $Id$ 5 | 6 | n = summary_size(o, 2); -------------------------------------------------------------------------------- /marsbar/@marsy/n_time_points.m: -------------------------------------------------------------------------------- 1 | function n = n_time_points(o) 2 | % get number of time_points 3 | % 4 | % $Id$ 5 | 6 | n = summary_size(o, 1); -------------------------------------------------------------------------------- /marsbar/@marsy/ne.m: -------------------------------------------------------------------------------- 1 | function tf = ne(Y1, Y2) 2 | % method overrides ~= operator 3 | % 4 | % $Id$ 5 | 6 | tf = ~eq(Y1, Y2); -------------------------------------------------------------------------------- /marsbar/@marsy/region_data.m: -------------------------------------------------------------------------------- 1 | function res = region_data(varargin) 2 | % method gets or sets data for region(s) as cell array 3 | % FORMAT res = region_data(o, r_nos) (get) OR 4 | % FORMAT res = region_data(o, r_nos, new_data) (set) 5 | % 6 | % See region_field for details 7 | % 8 | % $Id$ 9 | 10 | res = region_field('Y', varargin{:}); 11 | 12 | -------------------------------------------------------------------------------- /marsbar/@marsy/region_descrip.m: -------------------------------------------------------------------------------- 1 | function res = region_descrip(varargin) 2 | % method gets or sets descrip for region(s) as cell array 3 | % FORMAT res = region_descrip(o, r_nos) (get) OR 4 | % FORMAT res = region_descrip(o, r_nos, new_data) (set) 5 | % 6 | % See region_field for details 7 | % 8 | % $Id$ 9 | 10 | res = region_field('descrip', varargin{:}); 11 | 12 | -------------------------------------------------------------------------------- /marsbar/@marsy/region_field.m: -------------------------------------------------------------------------------- 1 | function res = region_field(fieldname, o, r_nos, new_data) 2 | % method gets or sets data for region field 3 | % FORMAT res = region_field(fieldname, o, r_nos) (get) OR 4 | % FORMAT res = region_field(fieldname, o, r_nos, new_data) (set) 5 | % 6 | % Inputs 7 | % fieldname - name of field to get / set 8 | % o - marsy object 9 | % r_nos - region number 10 | % or array of region numbers 11 | % or empty - giving all regions 12 | % new_data - cell array, containing new data to set 13 | % 14 | % Returns 15 | % (get call) 16 | % res - cell array of region field values OR 17 | % (set call) 18 | % res - object with new field data set 19 | % 20 | % $Id$ 21 | 22 | if nargin < 2 23 | error('Need fieldname'); 24 | end 25 | if nargin < 3 26 | r_nos = []; 27 | end 28 | if nargin < 4 % get call 29 | [rs r_nos] = region(o, r_nos); 30 | for i = 1:length(r_nos) 31 | res{i} = getfield(rs{i}, fieldname); 32 | end 33 | else % set call 34 | res = region(o, r_nos, new_data, fieldname); 35 | end 36 | 37 | 38 | -------------------------------------------------------------------------------- /marsbar/@marsy/region_info.m: -------------------------------------------------------------------------------- 1 | function res = region_info(varargin) 2 | % method gets or sets info for region(s) as cell array 3 | % FORMAT res = region_info(o, r_nos) (get) OR 4 | % FORMAT res = region_info(o, r_nos, new_data) (set) 5 | % 6 | % See region_field for details 7 | % 8 | % $Id$ 9 | 10 | res = region_field('info', varargin{:}); 11 | 12 | -------------------------------------------------------------------------------- /marsbar/@marsy/region_weights.m: -------------------------------------------------------------------------------- 1 | function res = region_weights(varargin) 2 | % method gets or sets weights for region(s) as cell array 3 | % FORMAT res = region_weights(o, r_nos) (get) OR 4 | % FORMAT res = region_weights(o, r_nos, new_data) (set) 5 | % 6 | % See region_field for details 7 | % 8 | % $Id$ 9 | 10 | res = region_field('weights', varargin{:}); 11 | 12 | -------------------------------------------------------------------------------- /marsbar/@marsy/resummarize.m: -------------------------------------------------------------------------------- 1 | function o = resummarize(o) 2 | % recalculate summary data if possible 3 | % 4 | % $Id$ 5 | 6 | s_f = sumfunc(o); 7 | if ~isempty(s_f) & ~strcmp(s_f, 'unknown') 8 | [t1 t2 o] = summary_data(o, s_f); 9 | end -------------------------------------------------------------------------------- /marsbar/@marsy/savestruct.m: -------------------------------------------------------------------------------- 1 | function savestruct(obj, filename) 2 | % saves data in y_struct as variables in .mat file 3 | % FORMAT savestruct(object, matname) 4 | % 5 | % $Id$ 6 | 7 | if nargin ~= 2 8 | error('Need matfile name'); 9 | end 10 | savestruct(y_struct(obj), filename) 11 | return -------------------------------------------------------------------------------- /marsbar/@marsy/split.m: -------------------------------------------------------------------------------- 1 | function o_arr = split(o) 2 | % method splits regions in object into separate objects 3 | % 4 | % $Id$ 5 | 6 | r = region(o); 7 | st = y_struct(o); 8 | is_s = isfield(st, 'Y') & isfield(st, 'Yvar'); 9 | if is_s 10 | Y = st.Y; 11 | Yvar = st.Yvar; 12 | else 13 | % remove any rogue Y or Yvar fields 14 | st = mars_struct('strip', st, {'Y','Yvar'}); 15 | end 16 | for i = 1:length(r) 17 | r_st = st; 18 | r_st.regions = r(i); 19 | if is_s 20 | r_st.Y = Y(:, i); 21 | r_st.Yvar = Yvar(:, i); 22 | end 23 | o_arr(i) = y_struct(o, r_st); 24 | end 25 | -------------------------------------------------------------------------------- /marsbar/@marsy/sumfunc.m: -------------------------------------------------------------------------------- 1 | function o = sumfunc(o, sumfunc) 2 | % method to get or set sumfunc 3 | % 4 | % $Id$ 5 | 6 | if nargin < 2 7 | % get 8 | st = y_struct(o); 9 | if isfield(st, 'sumfunc') 10 | o = st.sumfunc; 11 | else 12 | o = ''; 13 | end 14 | else 15 | % set 16 | o.y_struct.sumfunc = sumfunc; 17 | end -------------------------------------------------------------------------------- /marsbar/@marsy/summary.m: -------------------------------------------------------------------------------- 1 | function strs = summary(M) 2 | % method returns cell array of strings describing marsy object 3 | % 4 | % $Id$ 5 | 6 | strs{1} = sprintf('Description: \t%s', summary_descrip(M)); 7 | strs{2} = sprintf('Number of time points: \t%d', n_time_points(M)); 8 | strs{3} = sprintf('Number of regions: \t%d', n_regions(M)); 9 | s_f = is_summarized(M); 10 | strs{4} = sprintf('Is summarized?: \t%s', sf_recode(s_f)); 11 | strs{5} = sprintf('Summary function: \t%s', sumfunc(M)); 12 | if ~s_f 13 | strs{end+1} = sprintf('Can be summarized?: \t%s', ... 14 | sf_recode(can_summarize(M))); 15 | end 16 | ns = region_name(M, [], [], ''); 17 | if isempty(strvcat(ns)) 18 | strs{end+1} = sprintf('Region names: \t%s', ... 19 | 'not specified'); 20 | else 21 | strs{end+1} = 'Region names:'; 22 | for i = 1:length(ns) 23 | strs{end+1} = sprintf('Region %d: %s', i, ns{i}); 24 | end 25 | end 26 | return 27 | 28 | function str = sf_recode(tf) 29 | if isnan(tf), str = 'unknown'; 30 | elseif tf, str = 'yes'; 31 | else str = 'no'; 32 | end 33 | -------------------------------------------------------------------------------- /marsbar/@marsy/summary_block_means.m: -------------------------------------------------------------------------------- 1 | function mus = summary_block_means(Y) 2 | % return raw means over blocks in summary data 3 | % 4 | % Input 5 | % Y - marsy object 6 | % 7 | % mus - means over block. Returns B x N matrix 8 | % where B is number of blocks, and N is number 9 | % of ROIs 10 | % 11 | % $Id$ 12 | 13 | y = summary_data(Y); 14 | r = block_rows(Y); 15 | 16 | B = length(r); 17 | N = size(y, 2); 18 | 19 | mus = zeros(B, N); 20 | 21 | for b = 1:B 22 | mus(b, :) = mean(y(r{b},:),1); 23 | end -------------------------------------------------------------------------------- /marsbar/@marsy/summary_descrip.m: -------------------------------------------------------------------------------- 1 | function res = summary_descrip(o, descrip) 2 | % get/set method for summary data description 3 | % 4 | % $Id$ 5 | 6 | st = y_struct(o); 7 | if nargin < 2 % get 8 | res = ''; 9 | if isfield(st, 'descrip') 10 | res = st.descrip; 11 | end 12 | else % set 13 | st.descrip = descrip; 14 | o = y_struct(o, st); 15 | res = o; 16 | end -------------------------------------------------------------------------------- /marsbar/@marsy/summary_info.m: -------------------------------------------------------------------------------- 1 | function res = summary_info(o, descrip) 2 | % get/set method for summary data info 3 | % 4 | % $Id$ 5 | 6 | st = y_struct(o); 7 | if nargin < 2 % get 8 | res = []; 9 | if isfield(st, 'info') 10 | res = st.info; 11 | end 12 | else % set 13 | st.info = info; 14 | o = y_struct(o, st); 15 | res = o; 16 | end -------------------------------------------------------------------------------- /marsbar/@marsy/summary_size.m: -------------------------------------------------------------------------------- 1 | function [m,n] = summary_size(o, dim) 2 | % method returns number of time points x number of regions 3 | % 4 | % $Id$ 5 | 6 | st = o.y_struct; 7 | sz = [0 0]; 8 | if isfield(st, 'Y') 9 | sz = size(st.Y); 10 | elseif isfield(st, 'regions') 11 | if iscell(st.regions) 12 | if isfield(st.regions{1}, 'Y') 13 | sz(1) = size(st.regions{1}.Y, 1); 14 | end 15 | end 16 | sz(2) = length(st.regions); 17 | end 18 | 19 | if nargin < 2 20 | if nargout > 1 21 | m = sz(1); n = sz(2); 22 | else 23 | m = sz; 24 | end 25 | else 26 | if dim > 2 27 | m = (m+n > 0) 28 | else 29 | m = sz(dim); 30 | end 31 | end -------------------------------------------------------------------------------- /marsbar/@marsy/verbose.m: -------------------------------------------------------------------------------- 1 | function res = verbose(obj, data) 2 | % get/set method for verbose field 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.verbose = data; 8 | res = obj; 9 | else 10 | res = obj.verbose; 11 | end -------------------------------------------------------------------------------- /marsbar/@marsy/xyz.m: -------------------------------------------------------------------------------- 1 | function [XYZ, M]= xyz(o, r_no, xyz_type) 2 | % gets XYZ coordinates for region 3 | % FORMAT [XYZ M]= xyz(o, r_no, xyz_type) 4 | % 5 | % Inputs 6 | % o - marsy object 7 | % r_no - region number 8 | % xyz_type - string, one of 'mm','real','vox' 9 | % where 'real' is a synonym for 'mm' 10 | % and 'mm' is the default (if not passed) 11 | % 'mm' results in coordinates in mm 12 | % 'vox' gives coordinates in voxels 13 | % 14 | % Outputs 15 | % XYZ - coordinates in specified reference 16 | % M - 4x4 transformation mapping voxels to mm 17 | % 18 | % $Id$ 19 | 20 | r = n_regions(o); 21 | if nargin < 2 22 | error('Need region number to get XYZ coordinates') 23 | end 24 | if r_no > r 25 | error('Region number too large'); 26 | end 27 | if nargin < 3 28 | xyz_type = 'mm'; 29 | end 30 | 31 | XYZ = []; 32 | M = eye(4); 33 | st = y_struct(o); 34 | if ~isfield(st, 'regions') 35 | return 36 | end 37 | r_st = st.regions{r_no}; 38 | if ~isfield(r_st, 'vXYZ') | ~isfield(r_st, 'mat') 39 | return 40 | end 41 | XYZ = r_st.vXYZ; 42 | if isempty(XYZ), return, end 43 | switch xyz_type 44 | case 'vox' 45 | case {'mm', 'real'} 46 | [m n] = size(XYZ); 47 | if m == 3, XYZ = [XYZ; ones(1, n)]; end 48 | M = r_st.mat; 49 | XYZ = M * XYZ; 50 | otherwise 51 | error(['Unknown coordinate type: ' xyz_type]); 52 | end 53 | XYZ = XYZ(1:3,:); 54 | -------------------------------------------------------------------------------- /marsbar/@marsy/y_struct.m: -------------------------------------------------------------------------------- 1 | function res = y_struct(obj, Struct) 2 | % get/set method for y_struct field 3 | % 4 | % $Id$ 5 | 6 | if nargin > 1 7 | obj.y_struct = Struct; 8 | res = obj; 9 | else 10 | res = obj.y_struct; 11 | end -------------------------------------------------------------------------------- /marsbar/examples/batch/README: -------------------------------------------------------------------------------- 1 | Batch processing scripts for MarsBaR example data 2 | ------------------------------------------------- 3 | 4 | This directory contains the batch scripts for preprocessing of the 5 | MarsBaR example dataset. You can get the dataset from the MarsBaR 6 | dateset download page: 7 | 8 | https://github.com/marsbar-toolbox/marsbar-example-data/releases 9 | 10 | To run initial processing on the dataset in SPM, start matlab, change 11 | ('cd') to the '/examples/batch' directory, and, from the 12 | console window run: 13 | 14 | run_preprocess 15 | 16 | The routines will create smoothed images and run a standard 17 | SPM statistical model on each of the three sessions. 18 | 19 | The routines should work with SPM99 through SPM12. 20 | 21 | There is also an example batch script for MarsBaR that replicates the 22 | analyses described in the MarsBaR tutorial; see 23 | https://marsbar-toolbox.github.io. To run: 24 | 25 | run_tutorial 26 | 27 | Please use the MarsBaR mailing list for any questions or to report 28 | problems: 29 | 30 | https://lists.souceforge.net/lists/listinfo/marsbar-users 31 | 32 | We wish you a pleasant FMRI experience, 33 | 34 | Matthew Brett - for the team 35 | -------------------------------------------------------------------------------- /marsbar/examples/batch/do_bch_wrapper.m: -------------------------------------------------------------------------------- 1 | %--------------------------------------------------------------- 2 | % Generic single analysis wrapper for SPM99 crash mode. 3 | % Sorry, I mean SPM99 batch mode. 4 | %--------------------------------------------------------------- 5 | % The analysis parameters are specified here using the global variable 6 | % SPM_BCH_VARS 7 | % Fields are: 8 | % work_dir - work_dir 9 | % ana_type - number specifying analysis type 10 | % m_file - string giving mfile to run 11 | % 12 | % We have to use the global variable to pass parameters here because of 13 | % the peculiarities of the batch mode. 14 | %--------------------------------------------------------------- 15 | % 16 | % $Id: do_bch_wrapper.m,v 1.1.1.1 2004/08/14 00:07:52 matthewbrett Exp $ 17 | 18 | global SPM_BCH_VARS 19 | 20 | % get (and make) the subdirectory in the main directory 21 | work_dir = {SPM_BCH_VARS.work_dir}; 22 | [pn1 pn2] = fileparts(work_dir{1}); 23 | if ~exist(work_dir{1}, 'dir') 24 | mkdir(pn1, pn2); 25 | end 26 | 27 | analyses = struct( ... 28 | 'type', SPM_BCH_VARS.ana_type, ... 29 | 'index', 1, ... 30 | 'work_dir', 1, ... 31 | 'mfile', 1 ... 32 | ); 33 | 34 | type = {'model','contrasts','defaults_edit','headers',... 35 | 'means','realign','normalize','smooth'}; 36 | 37 | mfile = {SPM_BCH_VARS.m_file}; 38 | -------------------------------------------------------------------------------- /marsbar/examples/batch/er_contrast_spm99.m: -------------------------------------------------------------------------------- 1 | %------------------------------------------------------------------ 2 | % SPM99 batch mfile to configure contrasts 3 | %------------------------------------------------------------------ 4 | % 5 | % $Id: er_contrast_spm99.m,v 1.1.1.1 2004/08/14 00:07:52 matthewbrett Exp $ 6 | 7 | global SPM_BCH_VARS 8 | 9 | con = SPM_BCH_VARS.contrasts; 10 | contrasts(1).names = con.names; 11 | contrasts(1).types = con.types; 12 | contrasts(1).values = con.values; 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /marsbar/examples/batch/er_smooth.m: -------------------------------------------------------------------------------- 1 | function er_smooth(subjroot, sesses, filt, fwhm) 2 | % smooth images prior to analysis 3 | % 4 | % Inputs 5 | % subjroot - root directory containing session directories 6 | % sesses - cell array containing session subdirectories 7 | % filt - shell exp filter for selecting files 8 | % fwhm - FWHM in mm for smoothing 9 | % 10 | % $Id: er_smooth.m,v 1.1.1.1 2004/08/14 00:07:52 matthewbrett Exp $ 11 | 12 | nsesses = length(sesses); 13 | 14 | imgs = ''; 15 | for s = 1:nsesses 16 | dirn = fullfile(subjroot,sesses{s}); 17 | % get files in this directory 18 | imgs = strvcat(imgs, spm_get('files', dirn, filt)); 19 | end 20 | 21 | % and this is just spm_smooth_ui pasted/edited 22 | P = imgs; 23 | n = size(P,1); 24 | 25 | % implement the convolution 26 | %--------------------------------------------------------------------------- 27 | for i = 1:n 28 | Q = deblank(P(i,:)); 29 | [pth,nm,xt] = fileparts(deblank(Q)); 30 | U = fullfile(pth,['s' nm xt]); 31 | spm_smooth(Q,U,fwhm); 32 | end 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /marsbar/examples/batch/get_subjroot.m: -------------------------------------------------------------------------------- 1 | function subjroot = get_subjroot() 2 | % FORMAT subjroot = get_subjroot() 3 | % 4 | % Gets the root path for the example data. 5 | % Looks first for an environment variable, if not defined, uses GUI 6 | subjroot = getenv('MARSBAR_EG_DATAPATH'); 7 | % Otherwise fetch via the GUI 8 | if isempty(subjroot) 9 | subjroot = spm_get(-1, '', 'Root directory of example data'); 10 | end 11 | if ~exist(fullfile(subjroot, 'sess1'), 'dir') 12 | error(sprintf('Expecting "sess1" directory in %s', subjroot)) 13 | end 14 | return 15 | -------------------------------------------------------------------------------- /marsbar/examples/batch/run_preprocess.m: -------------------------------------------------------------------------------- 1 | % Run smoothing and SPM analysis for MarsBaR ER sample data 2 | % 3 | % $Id: run_preprocess.m,v 1.2 2004/08/15 01:19:43 matthewbrett Exp $ 4 | 5 | % Start marsbar to make sure spm_get works 6 | marsbar('on') 7 | 8 | % You might want to define the path to the example data here, as in 9 | % subjroot = '/my/path/somewhere'; 10 | subjroot = get_subjroot(); 11 | 12 | sesses = {'sess1','sess2','sess3'}; 13 | 14 | spm_v = spm('ver'); 15 | sdirname = [spm_v '_ana']; 16 | if ~strcmp(spm_v, 'SPM99'), spm_defaults; end 17 | 18 | % Make sure SPM modality-specific defaults are set 19 | spm('defaults', 'fmri'); 20 | 21 | % do smoothing 22 | er_smooth(subjroot, sesses, 'nu*.img', 8); 23 | 24 | % Run statistics, contrasts 25 | for ss = 1:length(sesses) 26 | model_file = configure_er_model(subjroot, sesses{ss}, sdirname); 27 | estimate_er_model(model_file, [1 0]); 28 | end 29 | -------------------------------------------------------------------------------- /marsbar/examples/batch/run_s3_model.m: -------------------------------------------------------------------------------- 1 | % Run SPM 2-session model for MarsBaR ER sample data 2 | % 3 | % You might want to define the path to the example data here, as in 4 | % subjroot = '/my/path/somewhere'; 5 | subjroot = get_subjroot(); 6 | 7 | sesses = {'sess1','sess2','sess3'}; 8 | 9 | spm_v = spm('ver'); 10 | sdirname = [spm_v '_ana']; 11 | if ~strcmp(spm_v, 'SPM99'), spm_defaults; end 12 | 13 | % Make sure SPM modality-specific defaults are set 14 | spm('defaults', 'fmri'); 15 | 16 | % Run statistics, contrasts 17 | model_file = configure_er_model(subjroot, sesses, sdirname); 18 | estimate_er_model(model_file, [1 0]); 19 | -------------------------------------------------------------------------------- /marsbar/install.txt: -------------------------------------------------------------------------------- 1 | MarsBaR installation 2 | --------------------- 3 | 4 | MarsBaR is a region of interest toolbox for use within SPM 5 | (http://wwww.fil.ion.ucl.ac.uk/spm). 6 | 7 | When you unpack the MarsBaR archive, you should have a new directory 8 | named after the MarsBaR release number for example "marsbar-0.21" 9 | 10 | You have two options for using MarsBaR within SPM. 11 | 12 | First, you can add the new MarsBaR directory to your matlab path. To 13 | use MarsBaR, start it from the matlab prompt with the command 14 | "marsbar". 15 | 16 | Second, you could copy / move or link the MarsBaR directory to the 17 | "marsbar" directory in the SPM "toolbox" directory. If you do this, 18 | the next time you start spm you can start the toolbox by selecting 19 | 'marsbar' from the toolbox button on the SPM interface. 20 | 21 | Matthew Brett, 19 April 2003 22 | -------------------------------------------------------------------------------- /marsbar/mars_blob2roi.m: -------------------------------------------------------------------------------- 1 | function mars_blob2roi(xSPM, pt) 2 | % saves ROI for cluster in xSPM structure, containing point pt 3 | % FORMAT mars_blob2roi(xSPM, pt) 4 | % 5 | % Input 6 | % xSPM - SPM results structure with needed fields 7 | % title 8 | % XYZ - voxel coordinates of activated points 9 | % Z - statistic values for activated points 10 | % M - 4x4 matrix from voxels to mm 11 | % 12 | % $Id$ 13 | 14 | if nargin < 1 15 | error('Need SPM structure'); 16 | end 17 | if nargin < 2 18 | error('Need point to identify cluster'); 19 | end 20 | 21 | vx_i = spm_XYZreg('findxyz', pt, xSPM.XYZmm); 22 | if isempty(vx_i) 23 | msgbox('No activated voxel at this location'); 24 | return 25 | end 26 | Clusters = spm_clusters(xSPM.XYZ); 27 | cXYZ = xSPM.XYZmm(:, Clusters==Clusters(vx_i)); 28 | if isempty(cXYZ), return, end 29 | d = sprintf('%s cluster at [%0.1f %0.1f %0.1f]', xSPM.title, pt); 30 | l = sprintf('%s_%0.0f_%0.0f_%0.0f', xSPM.title, pt); 31 | o = maroi_pointlist(struct('XYZ',cXYZ, 'mat', xSPM.M, ... 32 | 'label', l, 'descrip', d)); 33 | marsbar('saveroi', o); 34 | -------------------------------------------------------------------------------- /marsbar/mars_get_option.m: -------------------------------------------------------------------------------- 1 | function optval = mars_get_option(varargin) 2 | % Get option subfield as named by ``varargin``. 3 | % 4 | % FORMAT optval = mars_get_option(varargin) 5 | % 6 | % Tries to get base default if option is not set. Returns empty matrix if 7 | % there is no information for this option (for example, if the option fields 8 | % were mis-spelled). 9 | mars = mars_struct('getifthere', spm('getglobal','MARS'), 'OPTIONS'); 10 | if isempty(mars) 11 | mars = mars_options('basedefaults'); 12 | end 13 | optval = mars_struct('getifthere', mars, varargin{:}); 14 | -------------------------------------------------------------------------------- /marsbar/marsbar.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/marsbar/marsbar.jpg -------------------------------------------------------------------------------- /marsbar/savestruct.m: -------------------------------------------------------------------------------- 1 | function savestruct(varargin) 2 | % saves data in structure as variables in .mat file 3 | % FORMAT savestruct(matname, struct) or 4 | % FORMAT savestruct(struct, matname) 5 | % 6 | % $Id$ 7 | 8 | if nargin ~= 2 9 | error('Need matfile name and structure (only)'); 10 | end 11 | if isstruct(varargin{1}), varargin = varargin([2 1]); end 12 | varargin{3} = fieldnames(varargin{2}); 13 | if any(ismember(varargin{3}, {'wombat_tongue'})) 14 | error('Whoops, unexpected use of wombat_tongue'); 15 | end 16 | for wombat_tongue = 1:length(varargin{3}) 17 | eval([varargin{3}{wombat_tongue} ' = varargin{2}.' varargin{3}{wombat_tongue} ... 18 | ';']); 19 | end 20 | save(varargin{1}, varargin{3}{:}); 21 | return -------------------------------------------------------------------------------- /marsbar/spm2/mars_blob_ui.m: -------------------------------------------------------------------------------- 1 | function mars_blob_ui(action) 2 | % Displays SPM results, and ROI menu in SPM input window 3 | % FORMAT mars_blob_ui(action) 4 | % 5 | % This is the SPM2 version 6 | % 7 | % action - action string; can be 8 | % 'init' - initialise results interface 9 | % 'save_one' - UI to save current cluster 10 | % 'save_many' - UI to save all clusters 11 | % 12 | % This routine does SPM version specific stuff, the main 13 | % work is in mars_blob2roi.m and mars_blobs2rois.m 14 | % 15 | % $Id$ 16 | 17 | if nargin < 1 18 | action = 'init'; 19 | end 20 | 21 | errstr = sprintf(['''Cannot find xSPM struct in the workspace; '... 22 | 'Please (re)run SPM results GUI''']); 23 | 24 | switch lower(action) 25 | case 'init' 26 | try % and find valid SPM results stuff 27 | evalin('base', 'xSPM;'); 28 | hReg = evalin('base', 'hReg;'); 29 | spm_XYZreg('CleanReg',hReg); 30 | mars_blob_menu; 31 | catch % give up and get a new one 32 | mars_blob_ui('reinit'); 33 | end 34 | case 'reinit' 35 | % Display SPM results 36 | evalin('base', '[hReg,xSPM,SPM] = spm_results_ui;'); 37 | % Menu 38 | mars_blob_menu; 39 | case 'save_one' 40 | xSPM = evalin('base', 'xSPM', ['error(' errstr ')']); 41 | %-Get current location 42 | pt = spm_results_ui('GetCoords'); 43 | mars_blob2roi(xSPM, pt); 44 | case 'save_many' 45 | xSPM = evalin('base', 'xSPM', ['error(' errstr ')']); 46 | mars_blobs2rois(xSPM); 47 | otherwise 48 | error(['Worried by request for ' action]); 49 | end 50 | -------------------------------------------------------------------------------- /marsbar/spm2/mars_veropts.m: -------------------------------------------------------------------------------- 1 | function varargout = mars_veropts(arg, varargin) 2 | % returns SPM version specific parameters 3 | % FORMAT varargout = mars_veropts(arg, varargin) 4 | % 5 | % This is the SPM 2 version 6 | % 7 | % $Id$ 8 | 9 | if nargin < 1 10 | varargout = {}; 11 | return 12 | end 13 | 14 | switch lower(arg) 15 | case 'defaults' 16 | global defaults 17 | if isempty(defaults) 18 | spm_defaults; 19 | spm('defaults','FMRI'); 20 | end 21 | varargout = {defaults}; 22 | case 'default_design' 23 | varargout = {mardo_2}; 24 | case 'template_ext' % extension for template images 25 | varargout = {'.mnc'}; 26 | case 'get_img_ext' % default image extension for spm_get 27 | varargout = {'IMAGE'}; 28 | case 'pref_img_out_ext' % preferred extension for writing images 29 | varargout = {'img'}; 30 | case 'des_conf' % filter for configured, not estimated SPM designs 31 | varargout = {'SPM.mat'}; 32 | case 'flip_option' 33 | varargout = {spm_flip_analyze_images}; 34 | case 'design_filter_spec' 35 | varargout = {{... 36 | 'SPM.mat','SPM.mat; 2(all)/99 (estimated: SPM.mat)';... 37 | 'SPMcfg.mat','99 with imgs: SPMcfg.mat';... 38 | 'SPM_fMRIDesMtx.mat','99,FMRI,no imgs: SPM*fMRI*'}}; 39 | otherwise 40 | error(['You asked for ' arg ', which is strange']); 41 | end 42 | -------------------------------------------------------------------------------- /marsbar/spm2/spm_create_image.m: -------------------------------------------------------------------------------- 1 | function V = spm_create_image(V) 2 | % Wrapper for spm_create_vol, for compatibility with SPM99 3 | % FORMAT V = spm_create_image(V) 4 | % 5 | % Actually, MarsBaR itself does not use this function; it's included here 6 | % for compatibility with Phiwave (phiwave.sourceforge.net), that depends 7 | % on MarsBaR for its design interface and such. 8 | % 9 | % $Id$ 10 | 11 | V = spm_create_vol(V); 12 | -------------------------------------------------------------------------------- /marsbar/spm5/mars_blob_ui.m: -------------------------------------------------------------------------------- 1 | function mars_blob_ui(action) 2 | % Displays SPM results, and ROI menu in SPM input window 3 | % FORMAT mars_blob_ui(action) 4 | % 5 | % This is the SPM2 / SPM5 version 6 | % 7 | % action - action string; can be 8 | % 'init' - initialise results interface 9 | % 'save_one' - UI to save current cluster 10 | % 'save_many' - UI to save all clusters 11 | % 12 | % This routine does SPM version specific stuff, the main 13 | % work is in mars_blob2roi.m and mars_blobs2rois.m 14 | % 15 | % $Id: mars_blob_ui.m 184 2004-01-18 11:26:08Z matthewbrett $ 16 | 17 | if nargin < 1 18 | action = 'init'; 19 | end 20 | 21 | errstr = sprintf(['''Cannot find xSPM struct in the workspace; '... 22 | 'Please (re)run SPM results GUI''']); 23 | 24 | switch lower(action) 25 | case 'init' 26 | try % and find valid SPM results stuff 27 | evalin('base', 'xSPM;'); 28 | hReg = evalin('base', 'hReg;'); 29 | spm_XYZreg('CleanReg',hReg); 30 | mars_blob_menu; 31 | catch % give up and get a new one 32 | mars_blob_ui('reinit'); 33 | end 34 | case 'reinit' 35 | % Display SPM results 36 | evalin('base', '[hReg,xSPM,SPM] = spm_results_ui;'); 37 | % Menu 38 | mars_blob_menu; 39 | case 'save_one' 40 | xSPM = evalin('base', 'xSPM', ['error(' errstr ')']); 41 | %-Get current location 42 | pt = spm_results_ui('GetCoords'); 43 | mars_blob2roi(xSPM, pt); 44 | case 'save_many' 45 | xSPM = evalin('base', 'xSPM', ['error(' errstr ')']); 46 | mars_blobs2rois(xSPM); 47 | otherwise 48 | error(['Worried by request for ' action]); 49 | end 50 | -------------------------------------------------------------------------------- /marsbar/spm5/mars_veropts.m: -------------------------------------------------------------------------------- 1 | function varargout = mars_veropts(arg, varargin) 2 | % returns SPM version specific parameters 3 | % FORMAT varargout = mars_veropts(arg, varargin) 4 | % 5 | % This is the SPM 5 version 6 | % 7 | % $Id: mars_veropts.m 350 2004-08-12 06:52:18Z matthewbrett $ 8 | 9 | if nargin < 1 10 | varargout = {}; 11 | return 12 | end 13 | 14 | switch lower(arg) 15 | case 'defaults' 16 | global defaults 17 | if isempty(defaults) 18 | try 19 | % SPM8 likes to return the defaults 20 | defaults = spm('defaults','FMRI'); 21 | catch 22 | % SPM5 does not 23 | spm_defaults; 24 | spm('defaults','FMRI'); 25 | end 26 | end 27 | varargout = {defaults}; 28 | case 'default_design' 29 | varargout = {mardo_5}; 30 | case 'template_ext' % extension for template images 31 | varargout = {'.nii'}; 32 | case 'get_img_ext' % default image extension for spm_get 33 | varargout = {'image'}; 34 | case 'pref_img_out_ext' % preferred extension for writing images 35 | varargout = {'.nii'}; 36 | case 'des_conf' % filter for configured, not estimated SPM designs 37 | varargout = {'SPM.mat'}; 38 | case 'flip_option' 39 | varargout = {spm_flip_analyze_images}; 40 | case 'design_filter_spec' 41 | varargout = {{... 42 | 'SPM.mat','SPM.mat; 5,2 (all)/99 (estimated: SPM.mat)';... 43 | 'SPMcfg.mat','99 with imgs: SPMcfg.mat';... 44 | 'SPM_fMRIDesMtx.mat','99,FMRI,no imgs: SPM*fMRI*'}}; 45 | otherwise 46 | error(['You asked for ' arg ', which is strange']); 47 | end 48 | -------------------------------------------------------------------------------- /marsbar/spm5/spm_create_image.m: -------------------------------------------------------------------------------- 1 | function V = spm_create_image(V) 2 | % Wrapper for spm_create_vol, for compatibility with SPM99 3 | % FORMAT V = spm_create_image(V) 4 | % 5 | % Actually, MarsBaR itself does not use this function; it's included here 6 | % for compatibility with Phiwave (phiwave.sourceforge.net), that depends 7 | % on MarsBaR for its design interface and such. 8 | % 9 | % $Id: spm_create_image.m 510 2004-11-17 01:51:58Z matthewbrett $ 10 | 11 | V = spm_create_vol(V); 12 | -------------------------------------------------------------------------------- /marsbar/spm99/mars_veropts.m: -------------------------------------------------------------------------------- 1 | function varargout = mars_veropts(arg, varargin) 2 | % returns SPM version specific parameters 3 | % FORMAT varargout = mars_veropts(arg, varargin) 4 | % 5 | % This the SPM 99 version 6 | % 7 | % $Id$ 8 | 9 | if nargin < 1 10 | varargout = {}; 11 | return 12 | end 13 | 14 | switch lower(arg) 15 | case 'defaults' 16 | varargout = {}; 17 | case 'default_design' 18 | varargout = {mardo_99}; 19 | case 'template_ext' % extension for template images 20 | varargout = {'.img'}; 21 | case 'get_img_ext' % default image extension for spm_get 22 | varargout = {'img'}; 23 | case 'pref_img_out_ext' % preferred extension for writing images 24 | varargout = {'img'}; 25 | case 'des_conf' % filter for configured, not estimated SPM designs 26 | varargout = {'SPMcfg.mat'}; 27 | case 'flip_option' 28 | varargout = {0}; 29 | case 'design_filter_spec' 30 | varargout = {{... 31 | 'SPMcfg.mat','99 with imgs: SPMcfg.mat';... 32 | 'SPM.mat','SPM.mat; 2(all)/99 (estimated: SPM.mat)';... 33 | 'SPM_fMRIDesMtx.mat','99,FMRI,no imgs: SPM*fMRI*'}}; 34 | otherwise 35 | error(['You asked for ' arg ', which is strange']); 36 | end -------------------------------------------------------------------------------- /marsbar/spm99/spm_close_vol.m: -------------------------------------------------------------------------------- 1 | function Vo = spm_close_vol(Vi) 2 | % Close image volume - for SPM2 / SPM99 compatibility 3 | % See: spm_create_vol and spm_write_plane. 4 | % 5 | % SPM99 seems to use spm_create_image to close volumes 6 | % 7 | % $Id$ 8 | 9 | for i=1:prod(size(Vi)), 10 | Vo(i) = spm_create_image(Vi(i)); 11 | end 12 | -------------------------------------------------------------------------------- /marsbar/spm99/spm_create_vol.m: -------------------------------------------------------------------------------- 1 | function V = spm_create_vol(V) 2 | % Wrapper for spm_create_image, for compatibility with SPM2 3 | % FORMAT V = spm_create_vol(V) 4 | % 5 | % $Id$ 6 | 7 | V = spm_create_image(V); 8 | -------------------------------------------------------------------------------- /marsbar/todo.txt: -------------------------------------------------------------------------------- 1 | To do list 2 | ---------- 3 | 4 | Odd EoI + subset contrast error in MV routine. 5 | Random effects structure, with import / export etc 6 | Simple means store for event signal plotting (in case of estimation failure) -------------------------------------------------------------------------------- /test.m: -------------------------------------------------------------------------------- 1 | % Script to run tests 2 | % Be careful, this will clear all your matlab variables 3 | % 4 | % Remember to run `git submodule update --init` to get the testing machinery 5 | % 6 | % See data_test.m for regression testing on data. 7 | clear classes 8 | addpath(fullfile(pwd, 'marsbar')) 9 | addpath(fullfile(pwd, 'testing')) 10 | marsbar on 11 | run_tests tests 12 | -------------------------------------------------------------------------------- /tests/bad_mres.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/bad_mres.mat -------------------------------------------------------------------------------- /tests/img01.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img01.hdr -------------------------------------------------------------------------------- /tests/img01.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img01.img -------------------------------------------------------------------------------- /tests/img01.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img01.mat -------------------------------------------------------------------------------- /tests/img02.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img02.hdr -------------------------------------------------------------------------------- /tests/img02.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img02.img -------------------------------------------------------------------------------- /tests/img02.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img02.mat -------------------------------------------------------------------------------- /tests/img03.hdr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img03.hdr -------------------------------------------------------------------------------- /tests/img03.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img03.img -------------------------------------------------------------------------------- /tests/img03.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/marsbar-toolbox/marsbar/3ecdabaf3efda0d24b7b36bc7c2fa6c3f900c291/tests/img03.mat -------------------------------------------------------------------------------- /tests/test_get_option.m: -------------------------------------------------------------------------------- 1 | function test_get_option 2 | % Test mars_get_option 3 | % Tests assume no default configuration change 4 | assert_equal(mars_get_option('statistics', 'voxfilter'), 0); 5 | global MARS 6 | MARS.OPTIONS.statistics.voxfilter = 1; 7 | assert_equal(mars_get_option('statistics', 'voxfilter'), 1); 8 | MARS.OPTIONS.statistics.voxfilter = 0; 9 | assert_equal(mars_get_option('statistics', 'voxfilter'), 0); 10 | % Not existing in base defaults, is empty 11 | assert_equal(mars_get_option('not_likely', 'voxfilter'), []) 12 | -------------------------------------------------------------------------------- /tests/test_mardos.m: -------------------------------------------------------------------------------- 1 | function test_mardos 2 | % Test the mardo initializations 3 | pth = fileparts(mfilename('fullpath')); 4 | des_pth = fullfile(pth, 'bad_mres.mat'); 5 | D = mardo(des_pth); 6 | assert_equal(class(D), 'mardo_2'); 7 | % Filenames don't work for specific constructors 8 | all_errors = 0; 9 | try 10 | D = mardo_99(des_pth); 11 | catch 12 | was_error = 1; 13 | end 14 | assert_true(was_error); 15 | all_errors = 0; 16 | try 17 | D = mardo_2(des_pth); 18 | catch 19 | was_error = 1; 20 | end 21 | assert_true(was_error); 22 | all_errors = 0; 23 | try 24 | D = mardo_5(des_pth); 25 | catch 26 | was_error = 1; 27 | end 28 | assert_true(was_error); 29 | % From structure is OK 30 | D = mardo_2(des_struct(D)); 31 | assert_equal(class(D), 'mardo_2'); 32 | -------------------------------------------------------------------------------- /tests/test_maroi_image.m: -------------------------------------------------------------------------------- 1 | function test_maroi_image; 2 | % Test creation of maroi_image objects 3 | pth = fileparts(mfilename('fullpath')); 4 | img_fname = fullfile(pth, 'img01.img'); 5 | vol = spm_vol(img_fname); 6 | data = spm_read_vols(vol); 7 | msk = data ~= 0; 8 | vol_mean = mean(data(msk)); 9 | roi1 = maroi_image(img_fname); 10 | assert_equal(vol_mean, mean(getdata(roi1, img_fname))) 11 | roi2 = maroi_image(vol); 12 | assert_equal(vol_mean, mean(getdata(roi2, img_fname))) 13 | -------------------------------------------------------------------------------- /tests/test_marsy.m: -------------------------------------------------------------------------------- 1 | function test_marsy; 2 | % Test creation of marsy objects 3 | % Simple vector 4 | y = ones(20,1); 5 | my = marsy(y); 6 | assert_equal(summary_data(my), y); 7 | % Regions 8 | ry = ones(22,3); 9 | ri = struct('name', 'roi'); 10 | my = marsy({ry}, ri, 'mean'); 11 | assert_equal(summary_data(my), ones(22,1)); 12 | -------------------------------------------------------------------------------- /tests/test_marsy_stripreg.m: -------------------------------------------------------------------------------- 1 | function test_marsy_stripreg; 2 | % Test stripping of regions 3 | % Regions 4 | ry = ones(22,1) * [0 1 2]; 5 | ri = struct('name', {'roi1', 'roi1'}); 6 | my = marsy({ry, ry}, ri, 'mean'); 7 | assert_equal(summary_data(my), ones(22,2)); 8 | assert_equal(region_data(my, []), {ry, ry}); 9 | my_stripped = as_summary_only(my); 10 | assert_equal(summary_data(my_stripped), ones(22,2)); 11 | assert_equal(region_data(my_stripped, []), {ones(22,1), ones(22,1)}) 12 | --------------------------------------------------------------------------------