├── doc ├── setup.png ├── init_Tree.png ├── killPipe.png ├── results.png ├── runPipe.png └── scriptTree.png ├── niak ├── demoniak.png ├── angelniak.png ├── extensions │ └── psom-1.0.2 │ │ ├── demo_pipe1.jpg │ │ ├── demo_pipe2.jpg │ │ ├── logo_psom.png │ │ ├── logo_psom_black.png │ │ ├── example_init_qsub.csh │ │ ├── example_init_qsub.sh │ │ ├── psom_update_svn.m │ │ ├── psom_status_svn.m │ │ ├── psom_submit.sh │ │ ├── psom_char2cell.m │ │ ├── psom_rm_blank.m │ │ ├── psom_read_xml.m │ │ ├── psom_subset_pipeline.m │ │ ├── psom_string_remove.m │ │ ├── psom_string2words.m │ │ ├── psom_run_job.sh │ │ ├── psom_file_tmp.m │ │ ├── psom_merge_pipeline.m │ │ ├── psom_path_tmp.m │ │ ├── psom_exist.m │ │ ├── psom_find_str_cell.m │ │ ├── psom_struct_cell_string2char.m │ │ └── psom_is_dag.m └── commands │ ├── clustering │ ├── niak_normalize_stability.m │ └── niak_hier2order.m │ ├── formats │ ├── niak_rm_field.m │ ├── niak_string2lines.m │ ├── niak_full_file.m │ ├── niak_cmp_str_cell.m │ ├── niak_mat2vec.m │ ├── niak_mat2lvec.m │ ├── niak_files2str.m │ ├── niak_rm_blank.m │ ├── niak_lvec2mat.m │ ├── niak_merge_structs.m │ ├── niak_neig2mat.m │ ├── niak_scales2cell.m │ ├── niak_string2words.m │ ├── niak_sub2ind_2d.m │ ├── niak_replace_str.m │ ├── niak_sub2ind_3d.m │ ├── niak_vol2tseries.m │ ├── niak_tseries2vol.m │ ├── niak_vec2mat.m │ ├── niak_hdr_minc2mat.m │ ├── niak_find_str_cell.m │ ├── niak_get_minc_att.m │ ├── niak_part2mat.m │ ├── niak_part2vol.m │ ├── niak_scales2mat.m │ ├── niak_param2transf.m │ └── niak_full_path.m │ ├── visualization │ ├── niak_visu_corr.m │ └── niak_hot_cold.m │ ├── SI_processing │ ├── niak_flip_vol.m │ ├── niak_gaussian_fit.m │ ├── niak_unpad_vol.m │ ├── niak_compcor_mask.m │ ├── niak_find_local_max_1d.m │ ├── niak_build_adjacency.m │ └── niak_build_density_mask.m │ ├── statistics │ ├── niak_fisher.m │ ├── niak_build_rmap.m │ ├── niak_mad.m │ ├── niak_build_covariance.m │ ├── niak_build_concentration.m │ ├── niak_build_correlation.m │ ├── niak_build_partial_correlation.m │ ├── niak_gen_connectome.m │ └── niak_correct_vol.m │ ├── misc │ ├── niak_progress.m │ └── niak_version.m │ └── read_write │ ├── niak_read_transf.m │ ├── niak_path_tmp.m │ ├── niak_file_tmp.m │ ├── niak_resample_to_self.m │ ├── niak_write_transf.m │ ├── niak_read_tags.m │ └── niak_cp_fmri.m ├── shedulerConfig ├── shedulerOAR.sh └── shedulerSLURM.sh ├── runCompSC.sh ├── runTracking.sh ├── runOctave.sh ├── killPipe.sh ├── genMaskDK.sh ├── trackingClusterDK.sh ├── matlab_scripts ├── meshMapping.m ├── tck2voxel_cluster.m └── read_mrtrix_tracks.m ├── runPipeline.sh ├── pipeSetup.sh ├── aggregateSC.sh └── checkArchive.sh /doc/setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/doc/setup.png -------------------------------------------------------------------------------- /doc/init_Tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/doc/init_Tree.png -------------------------------------------------------------------------------- /doc/killPipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/doc/killPipe.png -------------------------------------------------------------------------------- /doc/results.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/doc/results.png -------------------------------------------------------------------------------- /doc/runPipe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/doc/runPipe.png -------------------------------------------------------------------------------- /niak/demoniak.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/niak/demoniak.png -------------------------------------------------------------------------------- /doc/scriptTree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/doc/scriptTree.png -------------------------------------------------------------------------------- /niak/angelniak.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/niak/angelniak.png -------------------------------------------------------------------------------- /shedulerConfig/shedulerOAR.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Control script for the batch scheduler commands 3 | # Use this file if your HPC uses OAR 4 | -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/demo_pipe1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/niak/extensions/psom-1.0.2/demo_pipe1.jpg -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/demo_pipe2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/niak/extensions/psom-1.0.2/demo_pipe2.jpg -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/logo_psom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/niak/extensions/psom-1.0.2/logo_psom.png -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/logo_psom_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BrainModes/TVB-empirical-data-pipeline/HEAD/niak/extensions/psom-1.0.2/logo_psom_black.png -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/example_init_qsub.csh: -------------------------------------------------------------------------------- 1 | set my_path = ($path) 2 | source /data/aces/aces1/quarantines/Linux-i686/Feb-14-2008/init-sge.csh > /dev/null 3 | set path = ($my_path $path) 4 | setenv MINC_COMPRESS 0 5 | unsetenv MINC_FORCE_V2 6 | -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/example_init_qsub.sh: -------------------------------------------------------------------------------- 1 | export MY_PATH=$PATH 2 | source /data/aces/aces1/quarantines/Linux-i686/Feb-14-2008/init-sge.sh > /dev/null 3 | export PATH=$PATH:$MY_PATH 4 | export MINC_COMPRESS=0 5 | unset MINC_FORCE_V2 6 | 7 | -------------------------------------------------------------------------------- /runCompSC.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Init all Toolboxes 4 | source ./pipeSetup.sh 5 | 6 | #Get the hostlist 7 | hostlist=$(scontrol show hostname $SLURM_NODELIST | paste -d, -s) 8 | 9 | #Run jobs in parallel 10 | parallel --sshlogin $hostlist --delay .2 -j $(( $SLURM_CPUS_ON_NODE / 2 )) --workdir $(pwd) --joblog runtask.log --resume ./runOctave.sh {} < ./compSCcommand.txt 11 | -------------------------------------------------------------------------------- /runTracking.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #This files performs the execution of xargs to compute the fiber tracking 4 | #in parallel 5 | #cat ./batch_track.sh | xargs -n 4 -P 0 ./trackingClusterDK.sh 6 | 7 | #Init all Toolboxes 8 | source ./pipeSetup.sh 9 | 10 | #Get the hostlist 11 | hostlist=$(scontrol show hostname $SLURM_NODELIST | paste -d, -s) 12 | 13 | #Run the jobs 14 | parallel -C ' ' --sshlogin $hostlist --delay .2 -j $SLURM_CPUS_ON_NODE --workdir $(pwd) --joblog runtask.log --resume ./trackingClusterDK.sh {1} {2} {3} {4} < ./batch_track.sh 15 | -------------------------------------------------------------------------------- /niak/commands/clustering/niak_normalize_stability.m: -------------------------------------------------------------------------------- 1 | function stab_c = niak_normalize_stability(stab,list_scales,flag_verbose) 2 | % Normalization of stability matrices 3 | % 4 | % This function is called by NIAK_MSTEPS and is not meant to be used independently 5 | if nargin < 3 6 | flag_verbose = true; 7 | end 8 | if flag_verbose 9 | fprintf('Normalizing the stability matrices ...\n'); 10 | end 11 | stab_c = zeros(size(stab)); 12 | for num_sc = 1:length(list_scales) 13 | sc = list_scales(num_sc); 14 | if sc > 1 15 | stab_tmp = stab(:,num_sc)-sc^(-1); 16 | stab_tmp(stab_tmp<0) = 0; 17 | stab_tmp = stab_tmp/(1-sc^(-1)); 18 | stab_c(:,num_sc) = stab_tmp; 19 | else 20 | stab_c(:,num_sc) = 0; 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /runOctave.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ============================================================================= 3 | # Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 4 | # BrainModes Research Group (head: P. Ritter) 5 | # Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 6 | # Correspondence: petra.ritter@charite.de 7 | # 8 | # When using this code please cite as follows: 9 | # Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P (in prep) 10 | # Constructing subject-specific Virtual Brains from multimodal neuroimaging 11 | # 12 | # This software is distributed under the terms of the GNU General Public License 13 | # as published by the Free Software Foundation. Further details on the GPL 14 | # license can be found at http://www.gnu.org/copyleft/gpl.html. 15 | # ============================================================================= 16 | 17 | octaveCommand=$1 18 | 19 | #Init 20 | module load octave 21 | 22 | #Exec octave command 23 | octave --eval "${octaveCommand}" 24 | 25 | #Unload 26 | module unload octave 27 | -------------------------------------------------------------------------------- /killPipe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ============================================================================= 3 | # Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 4 | # BrainModes Research Group (head: P. Ritter) 5 | # Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 6 | # Correspondence: petra.ritter@charite.de 7 | # 8 | # When using this code please cite as follows: 9 | # Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P (in prep) 10 | # Constructing subject-specific Virtual Brains from multimodal neuroimaging 11 | # 12 | # This software is distributed under the terms of the GNU General Public License 13 | # as published by the Free Software Foundation. Further details on the GPL 14 | # license can be found at http://www.gnu.org/copyleft/gpl.html. 15 | # ============================================================================= 16 | 17 | #If the user decides to abort the pipeline run, this script kills all the slurm jobs for the job-chain of this specific run 18 | while read jobID 19 | do 20 | 21 | echo "Killing Job ${jobID}" 22 | scancel $jobID 23 | sleep 0.2 24 | 25 | done < ./jobList*.txt 26 | -------------------------------------------------------------------------------- /genMaskDK.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ============================================================================= 3 | # Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 4 | # BrainModes Research Group (head: P. Ritter) 5 | # Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 6 | # Correspondence: petra.ritter@charite.de 7 | # 8 | # When using this code please cite as follows: 9 | # Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P (in prep) 10 | # Constructing subject-specific Virtual Brains from multimodal neuroimaging 11 | # 12 | # This software is distributed under the terms of the GNU General Public License 13 | # as published by the Free Software Foundation. Further details on the GPL 14 | # license can be found at http://www.gnu.org/copyleft/gpl.html. 15 | # ============================================================================= 16 | 17 | # Required arguments: 18 | # 1. e.g. CN 19 | path=$1 20 | pfx=$2 21 | rootPath=$3 22 | 23 | cd ${rootPath}/matlab_scripts 24 | module load octave 25 | octave --eval "addpath(genpath('${rootPath}/niak')); generateMasksDK('${path}/${pfx}/','${path}/${pfx}/')" 26 | module unload octave 27 | 28 | ##Tell the Mothership we're done here... 29 | touch ${path}/${pfx}/doneMask.txt 30 | -------------------------------------------------------------------------------- /shedulerConfig/shedulerSLURM.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Control script for the batch scheduler commands 3 | # Use this file if your HPC uses SLURM 4 | 5 | ##### Commands located inside the file pipeSubDK.sh #### 6 | ####____________________________________________________#### 7 | # 8 | ### 1.) The Preprocessinge-Job 9 | sbatch -J pipe_${subID} -t 00:08:00 -n 1 -N 1 -p normal -o ${logFolder}/${subID}_preproc.o%j ${rootPath}/preprocDK.sh ${subFolder}/ ${subID} > $jobFile 10 | 11 | ### 2.1) RUN functional Processing 12 | sbatch -J fc_${subID} --dependency=afterok:${jobID} -o ${logFolder}/${subID}_functional.o%j -N 1 -n 1 -p normal -t 00:55:00 ${rootPath}/fmriFC.sh ${subFolder}/ ${subID} > $jobFile 13 | 14 | ### 2.2) RUN generateMask.m ################################## 15 | sbatch -J Mask_${subID} --dependency=afterok:${jobID} -o ${logFolder}/${subID}_mask.o%j -N 1 -n 1 -p normal -t 01:00:00 ${rootPath}/genMaskDK.sh ${subFolder} ${subID} ${rootPath} > $jobFile 16 | 17 | ### 3.) RUN the Tracking #################################### 18 | sbatch -J trk_${subID} --dependency=afterok:${jobID} -n 192 -p normal -o ${logFolder}/${subID}_tracking.o%j -t 03:30:00 ./runTracking.sh > $jobFile 19 | 20 | ### 4.) RUN computeSC_cluster_new.m ######################### 21 | sbatch -J cSC_${subID} --dependency=afterok:${jobID} -o ${logFolder}/${subID}_compSC.o%j -n 68 -p normal -t 03:30:00 ./runCompSC.sh > $jobFile 22 | 23 | ### 5). RUN aggregateSC_new.m ################################ 24 | sbatch -J aggreg_${subID} --dependency=afterok:${jobID} -o ${logFolder}/${subID}_aggregateSC.o%j -t 02:00:00 -N 1 -n 1 -p normal ./aggregateSC.sh $subID $subFolder > $jobFile 25 | -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_update_svn.m: -------------------------------------------------------------------------------- 1 | function []=psom_update_svn() 2 | % Update all SVN libraries in the search path 3 | % 4 | % SYNTAX : 5 | % PSOM_UPDATE_SVN() 6 | % 7 | % Copyright (c) Christian L. Dansereau, 8 | % Centre de recherche de l'Institut universitaire de gériatrie de Montréal, 2011. 9 | % Maintainer : pierre.bellec@criugm.qc.ca 10 | % See licensing information in the code. 11 | % Keywords : svn,version,update 12 | 13 | % Permission is hereby granted, free of charge, to any person obtaining a copy 14 | % of this software and associated documentation files (the "Software"), to deal 15 | % in the Software without restriction, including without limitation the rights 16 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | % copies of the Software, and to permit persons to whom the Software is 18 | % furnished to do so, subject to the following conditions: 19 | % 20 | % The above copyright notice and this permission notice shall be included in 21 | % all copies or substantial portions of the Software. 22 | % 23 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | % THE SOFTWARE. 30 | 31 | 32 | vers = psom_version_svn(); 33 | 34 | for k=1:size(vers,2) 35 | disp(cat(2,'Check for "',vers(k).name,'" updates ...')) 36 | [status, output]=system(fullfile('svn update ',vers(k).path,' 2>&1')); 37 | disp(output) 38 | end 39 | end -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_status_svn.m: -------------------------------------------------------------------------------- 1 | function []=psom_status_svn() 2 | % Get the status of all SVN libraries in the search path 3 | % 4 | % SYNTAX : 5 | % PSOM_STATUS_SVN() 6 | % 7 | % Copyright (c) Christian L. Dansereau, 8 | % Centre de recherche de l'Institut universitaire de gériatrie de Montréal, 2011. 9 | % Maintainer : pierre.bellec@criugm.qc.ca 10 | % See licensing information in the code. 11 | % Keywords : svn,version,update 12 | 13 | % Permission is hereby granted, free of charge, to any person obtaining a copy 14 | % of this software and associated documentation files (the "Software"), to deal 15 | % in the Software without restriction, including without limitation the rights 16 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 | % copies of the Software, and to permit persons to whom the Software is 18 | % furnished to do so, subject to the following conditions: 19 | % 20 | % The above copyright notice and this permission notice shall be included in 21 | % all copies or substantial portions of the Software. 22 | % 23 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 | % THE SOFTWARE. 30 | 31 | vers = psom_version_svn(); 32 | 33 | for k=1:size(vers,2) 34 | disp(cat(2,'Status of the project "',vers(k).name,'" ...')) 35 | [status, output]=system(fullfile('svn status ',vers(k).path,' 2>&1')); 36 | disp(output) 37 | end 38 | end -------------------------------------------------------------------------------- /trackingClusterDK.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ============================================================================= 3 | # Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 4 | # BrainModes Research Group (head: P. Ritter) 5 | # Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 6 | # Correspondence: petra.ritter@charite.de 7 | # 8 | # When using this code please cite as follows: 9 | # Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P (in prep) 10 | # Constructing subject-specific Virtual Brains from multimodal neuroimaging 11 | # 12 | # This software is distributed under the terms of the GNU General Public License 13 | # as published by the Free Software Foundation. Further details on the GPL 14 | # license can be found at http://www.gnu.org/copyleft/gpl.html. 15 | # ============================================================================= 16 | 17 | # Required arguments: 18 | # 1. 19 | # This requires the following folder structure for each subject: 20 | # - SubjectXX/ 21 | # +-mrtrix/ 22 | # +--tracks/ 23 | # +--masks/ 24 | # + CSD8.mif 25 | # 2. 26 | 27 | #Usually this file is called by the batch script created by the MATLAB Script createMasks.m 28 | 29 | #Init all Toolboxes 30 | source ./pipeSetup.sh 31 | 32 | export subjpath=${1}/mrtrix_68 33 | export maskfolder=${subjpath}/masks_68 34 | 35 | export seedmaskindex=$2 36 | export seedCount=$3 37 | export roi=$4 38 | 39 | #### Fiber tracking 40 | echo "Currently Processing ROI $seedmaskindex" 41 | 42 | streamtrack SD_PROB ${subjpath}/CSD8.mif -seed $maskfolder/seedmask${seedmaskindex}_1mm.nii.gz -include $maskfolder/targetmask${roi}_1mm.nii.gz -minlength 30 -stop -mask ${1}/calc_images/wmmask_1mm_68.nii.gz -nomaskinterp -unidirectional -num $seedCount ${subjpath}/tracks_68/${seedmaskindex}_tracksCN.tck 43 | -------------------------------------------------------------------------------- /matlab_scripts/meshMapping.m: -------------------------------------------------------------------------------- 1 | %Map the vertices of the brainsuite cortex mesh (downsampled) onto the 2 | %freesurfer mesh coordinates to transfer the Desikan Killaney parcellation 3 | %onto the Brainsuite Mesh 4 | 5 | %load the meshes 6 | load('meshes.mat'); 7 | 8 | %Set the Atlas 9 | AtlasNumber = 3; %Desikan Killaney 10 | atlas = cortex_freesurfer.Atlas(AtlasNumber); 11 | 12 | %Init new atlas in brainsuite cortex 13 | cortex_brainsuite.Atlas(AtlasNumber).Scouts = []; 14 | cortex_brainsuite.Atlas(AtlasNumber).Scouts(length(atlas.Scouts)).Vertices = []; 15 | 16 | %Now loop over all Regions in the given Atlas (e.g. Desikan Killaney) and 17 | %create a hash table of which vertices do belong to which parcellation 18 | hash_tab_fs = []; 19 | for i = 1:length(atlas.Scouts) 20 | 21 | %Extract the mesh from the constructs 22 | vertices_fs = cortex_freesurfer.Vertices(atlas.Scouts(i).Vertices,:); 23 | 24 | hash_tab_fs = [hash_tab_fs; vertices_fs ones(size(vertices_fs,1),1)*i]; 25 | 26 | end 27 | 28 | %Create a list of the brainsuite mesh vertices which are to be mapped 29 | vertices_bs = []; 30 | for i=1:length(cortex_brainsuite.Atlas(2).Scouts) 31 | 32 | vertices_bs = [vertices_bs; cortex_brainsuite.Vertices(cortex_brainsuite.Atlas(2).Scouts(i).Vertices,:) cortex_brainsuite.Atlas(2).Scouts(i).Vertices]; 33 | 34 | end 35 | 36 | %Search the nearest neighbours 37 | IDX = knnsearch(hash_tab_fs(:,1:3), vertices_bs(:,1:3)); 38 | %TRANSLATED INto labels 39 | new_labels = hash_tab_fs(IDX,4); 40 | 41 | %Loop over all vertices and insertt them into a new Atlas 42 | for i = 1:length(new_labels) 43 | 44 | label = new_labels(i); 45 | 46 | %Insert 47 | cortex_brainsuite.Atlas(AtlasNumber).Scouts(label).Vertices = [cortex_brainsuite.Atlas(AtlasNumber).Scouts(label).Vertices; vertices_bs(i,4)]; 48 | 49 | end 50 | 51 | %Save the Mesh 52 | save('tess_cortex_pial_low.mat', '-struct', 'cortex_brainsuite'); -------------------------------------------------------------------------------- /niak/commands/formats/niak_rm_field.m: -------------------------------------------------------------------------------- 1 | function struct2 = niak_rm_field(struct,str_field) 2 | 3 | % Remove all fields from a structure whose field name contains a given 4 | % string. 5 | % 6 | % SYNTAX: 7 | % STRUCT2 = NIAK_RM_FIELD(STRUCT,STR_FIELD) 8 | % 9 | % INPUTS: 10 | % STRUCT (structure) 11 | % STR_FIELD (string) 12 | % 13 | % OUTPUTS: 14 | % STRUCT2 (structure) same as STRUCT, but all fields whose name contains 15 | % the string STR_FIELD have been removed. 16 | % 17 | % COMMENTS: 18 | % 19 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 20 | % Maintainer : pbellec@bic.mni.mcgill.ca 21 | % See licensing information in the code. 22 | % Keywords : structure 23 | 24 | % Permission is hereby granted, free of charge, to any person obtaining a copy 25 | % of this software and associated documentation files (the "Software"), to deal 26 | % in the Software without restriction, including without limitation the rights 27 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | % copies of the Software, and to permit persons to whom the Software is 29 | % furnished to do so, subject to the following conditions: 30 | % 31 | % The above copyright notice and this permission notice shall be included in 32 | % all copies or substantial portions of the Software. 33 | % 34 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 40 | % THE SOFTWARE. 41 | 42 | list_fields = fieldnames(struct); 43 | mask_f = niak_find_str_cell(list_fields,str_field); 44 | struct2 = rmfield(struct,list_fields(mask_f)); -------------------------------------------------------------------------------- /niak/commands/formats/niak_string2lines.m: -------------------------------------------------------------------------------- 1 | function cell_lines = niak_string2lines(vec_string) 2 | 3 | % Converts a strings into a cell of strings with individual lines 4 | % 5 | % SYNTAX 6 | % cell_lines = niak_string2lines(vec_string) 7 | % 8 | % INPUT 9 | % vec_string (vector of strings) containing words separated by blanks 10 | % 11 | % OUTPUT 12 | % cell_lines (cell of string) cell_words{n} is the nth line in 13 | % vec_string 14 | % COMMENTS 15 | % 16 | % Copyright (c) Pierre Bellec 01/2008 17 | % 18 | % Permission is hereby granted, free of charge, to any person obtaining a copy 19 | % of this software and associated documentation files (the "Software"), to deal 20 | % in the Software without restriction, including without limitation the rights 21 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 22 | % copies of the Software, and to permit persons to whom the Software is 23 | % furnished to do so, subject to the following conditions: 24 | % 25 | % The above copyright notice and this permission notice shall be included in 26 | % all copies or substantial portions of the Software. 27 | % 28 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 33 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 34 | % THE SOFTWARE. 35 | if isempty(vec_string) 36 | cell_lines{1} = ''; 37 | return 38 | end 39 | if ~strcmp(vec_string(end),char(10)); 40 | vec_string = [vec_string char(10)]; 41 | end 42 | pos_ent = findstr(vec_string,char(10)); 43 | pos_ent = [0 ; pos_ent(:)]; 44 | cell_lines = cell(length(pos_ent)-1,1); 45 | for num_p = 1:length(pos_ent)-1 46 | cell_lines{num_p} = vec_string(pos_ent(num_p)+1:pos_ent(num_p+1)-1); 47 | end 48 | 49 | -------------------------------------------------------------------------------- /matlab_scripts/tck2voxel_cluster.m: -------------------------------------------------------------------------------- 1 | function tck = tck2voxel_cluster(tck,affine_matrix) 2 | %This function converts the Scanner coordinates from MRTRix's tck-Files to 3 | %Voxel Coordinates using the affine Transformation matrix inside the header 4 | %of a reference image (e.g. the Brainmask used for tracking!) 5 | %INPUT: 6 | %tck - The Struct obtained via the MRTrix MATLAB function read_mrtrix_tracks 7 | %refimage - The NIFTI File with the affine Matrix in it's header 8 | %OUTPUT: 9 | %The tck-Struct with transformed coordinates 10 | % 11 | % ============================================================================= 12 | % Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 13 | % BrainModes Research Group (head: P. Ritter) 14 | % Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 15 | % Correspondence: petra.ritter@charite.de 16 | % 17 | % When using this code please cite as follows: 18 | % Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P (in prep) 19 | % Constructing subject-specific Virtual Brains from multimodal neuroimaging 20 | % 21 | % This software is distributed under the terms of the GNU General Public License 22 | % as published by the Free Software Foundation. Further details on the GPL 23 | % license can be found at http://www.gnu.org/copyleft/gpl.html. 24 | % ============================================================================= 25 | 26 | 27 | %First load the header information of the image to get the matrix 28 | %header = load_untouch_header_only(refimage); 29 | %Inside the header, one can find the affine transformation to get from 30 | %voxel's to scanner coords. Hence the matrix needs to be inverted 31 | %affine_matrix = inv([header.hist.srow_x; header.hist.srow_y; header.hist.srow_z; 0 0 0 1]); 32 | 33 | %Loop over all the Tracts in the Structure 34 | for ii = 1:length(tck.data) 35 | %Transform the Coordinates by multiplying the Matrix of Coordinates 36 | %with the affine transformation matrix 37 | zw = round([tck.data{ii} ones(size(tck.data{ii},1),1)]*affine_matrix'); 38 | %Write into the structure 39 | tck.data{ii} = zw(:,1:3) + 1; 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /niak/commands/visualization/niak_visu_corr.m: -------------------------------------------------------------------------------- 1 | function [results]=niak_visu_corr(file_in,folder_out,db_name) 2 | % gen a video of all the correlation matrix 3 | % In 4 | % FILES_IN 5 | % FOLDER_OUT 6 | % DB_NAME 7 | % 8 | % Out 9 | % RESULTS 10 | % R_MEAN Average correlation matrix 11 | % 12 | % R_STD Standard deviation correlation matrix 13 | % 14 | % ORDER Order of the matrix based on the average correlation matrix 15 | 16 | 17 | data = load(file_in); 18 | 19 | R_mean = niak_vec2mat(mean(data.y,1)); 20 | R_std = niak_vec2mat(std(data.y,[],1)); 21 | 22 | hier = niak_hierarchical_clustering(R_mean); 23 | order = niak_hier2order(hier); 24 | opt_v.order = order; 25 | 26 | opt_mat.limits = [-1,1]; 27 | f_handle_mean = figure; 28 | niak_visu_matrix(R_mean(order,order),opt_mat); 29 | title([db_name ' R mean']); 30 | print(f_handle_mean,[folder_out filesep 'R_all_mean.pdf'],'-dpdf'); 31 | close(f_handle_mean); 32 | 33 | opt_mat.limits = [0,0.3]; 34 | f_handle_std = figure; 35 | niak_visu_matrix(R_std(order,order),opt_mat); 36 | title([db_name ' R std']); 37 | print(f_handle_std,[folder_out filesep 'R_all_std.pdf'],'-dpdf'); 38 | close(f_handle_std); 39 | 40 | results.R_mean = R_mean; 41 | results.R_std = R_std; 42 | results.order = order; 43 | 44 | %niak_visu_motion(data.y',opt_v); 45 | 46 | system(['mkdir ' folder_out filesep 'png' filesep ]); 47 | opt_mat.limits = [-1,1]; 48 | 49 | % Print the correlation matrices for video 50 | for n_s = 1:size(data.labels_subject,1) 51 | R_ind = niak_vec2mat(data.y(n_s,:)); 52 | f_handle=figure; 53 | niak_visu_matrix(R_ind(order,order),opt_mat); 54 | title([db_name ' ' data.labels_subject{n_s}]); 55 | print(f_handle,[folder_out filesep 'png' filesep 'R_' data.labels_subject{n_s} '.png'],'-dpng'); 56 | close(f_handle); 57 | end 58 | ['mencoder mf://' folder_out filesep 'png' filesep '*.png -ovc lavc -lavcopts vcodec=msmpeg4v2 -mf fps=5 -o ' folder_out filesep 'corr_' db_name '.avi'] 59 | % Generate the video 60 | system(['mencoder mf://' folder_out filesep 'png' filesep '*.png -ovc lavc -lavcopts vcodec=msmpeg4v2 -mf fps=5 -o ' folder_out filesep 'corr_' db_name '.avi']); 61 | 62 | 63 | -------------------------------------------------------------------------------- /runPipeline.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ============================================================================= 3 | # Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 4 | # BrainModes Research Group (head: P. Ritter) 5 | # Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 6 | # Correspondence: petra.ritter@charite.de 7 | # 8 | # When using this code please cite as follows: 9 | # Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P (in prep) 10 | # Constructing subject-specific Virtual Brains from multimodal neuroimaging 11 | # 12 | # This software is distributed under the terms of the GNU General Public License 13 | # as published by the Free Software Foundation. Further details on the GPL 14 | # license can be found at http://www.gnu.org/copyleft/gpl.html. 15 | # ============================================================================= 16 | 17 | # Required arguments: 18 | # -s : The subjects Name i.e. the foldername 19 | # -a : Abbreviation of the name, used by OSIRIX when reorganising the DICOMS into subfolders. See example below 20 | #Example: ./runPipeline.sh -s CN_20120324 21 | 22 | ### Check Input ### 23 | export usage="Example: ./pipeline.sh -s CN_20120324" 24 | export subID=none 25 | #export split=none 26 | while [ $# -gt 0 ] 27 | do 28 | case "$1" in 29 | -s) subID="$2"; shift;; 30 | #-a) split="$2"; shift;; 31 | #-m) emailAdress="$2"; shift;; 32 | -*) echo >&2 \ 33 | $usage 34 | exit 1;; 35 | *) break;; # terminate while loop 36 | esac 37 | shift 38 | done 39 | #Check if -a & -s have been set 40 | if [ "$subID" == "none" ] 41 | then 42 | echo >&2 \ 43 | "Subjectname is missing! +++" \ 44 | $usage 45 | exit 1; 46 | # elif [ "$split" == "none" ] 47 | # then 48 | # echo >&2 \ 49 | # "Abbreviation is missing! +++" \ 50 | # $usage 51 | # exit 1; 52 | fi 53 | ### Check Input ### 54 | 55 | rootPath=$(pwd) 56 | 57 | #Run the Script in background 58 | nohup ./pipeSubDK.sh ${subID} ${rootPath} >& logfiles/${subID}_pipe.log & 59 | #Get the PID of the previously submitted pipeline call... 60 | #pipe_PID=$! 61 | 62 | echo "The pipeline is now running in the background. Check the logs ${subID}_pipe.log." 63 | -------------------------------------------------------------------------------- /niak/commands/visualization/niak_hot_cold.m: -------------------------------------------------------------------------------- 1 | function c = niak_hot_cold(n,per); 2 | % Hot-col color map 3 | % 4 | % SYNTAX: 5 | % C = NIAK_HOT_COLD(N,PER) 6 | % 7 | % INPUTS: 8 | % N (integer, default 256) number of colors in the map 9 | % PER (scalar, default 0.5) the proportion of hot colors 10 | % 11 | % OUTPUTS: 12 | % C (matrix Nx3) each row is the red/green/blue intensity in the color (from 0 to 1) 13 | 14 | % Copyright (c) Pierre Bellec, Centre de recherche de l'institut de 15 | % Gériatrie de Montréal, Département d'informatique et de recherche 16 | % opérationnelle, Université de Montréal, 2010-2011. 17 | % Maintainer : pierre.bellec@criugm.qc.ca 18 | % Keywords : 19 | % 20 | % Permission is hereby granted, free of charge, to any person obtaining a copy 21 | % of this software and associated documentation files (the "Software"), to deal 22 | % in the Software without restriction, including without limitation the rights 23 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | % copies of the Software, and to permit persons to whom the Software is 25 | % furnished to do so, subject to the following conditions: 26 | % 27 | % The above copyright notice and this permission notice shall be included in 28 | % all copies or substantial portions of the Software. 29 | % 30 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | % THE SOFTWARE. 37 | 38 | if nargin < 1 39 | n = 256; 40 | end 41 | if nargin < 2 42 | per = 0.5; 43 | end 44 | 45 | c1 = hot(ceil(1.28*n*per)); 46 | if ~isempty(c1) 47 | c1 = c1(1:ceil(n*per),:); 48 | end 49 | c2 = hot(ceil(1.28*n*(1-per))); 50 | if ~isempty(c2) 51 | c2 = c2(1:(n-length(c1)),:); 52 | c2 = c2(:,[3 2 1]); 53 | c2(size(c2,1):-1:1,:); 54 | end 55 | c = [c2(size(c2,1):-1:1,:) ; c1]; 56 | 57 | -------------------------------------------------------------------------------- /niak/commands/SI_processing/niak_flip_vol.m: -------------------------------------------------------------------------------- 1 | function vol2 = niak_flip_vol(vol,type) 2 | 3 | % Flip or rotate a 3D volume 4 | % 5 | % vol2 = niak_flip_vol(vol,type) 6 | % 7 | % ENTREES 8 | % vol (3D array) 3D volume 9 | % type (string) a transform (possible values : 'rot90','rot180','rot270','fliplr') 10 | % 11 | % SORTIES 12 | % vol2 (3D volume) volume vol after application of the transform. 13 | % 14 | % COMMENTS 15 | % 16 | % Copyright (c) Odile Jolivet 05/2005 Pierre Bellec 01/2008 17 | % 18 | % Permission is hereby granted, free of charge, to any person obtaining a copy 19 | % of this software and associated documentation files (the "Software"), to deal 20 | % in the Software without restriction, including without limitation the rights 21 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 22 | % copies of the Software, and to permit persons to whom the Software is 23 | % furnished to do so, subject to the following conditions: 24 | % 25 | % The above copyright notice and this permission notice shall be included in 26 | % all copies or substantial portions of the Software. 27 | % 28 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 29 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 30 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 31 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 32 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 33 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 34 | % THE SOFTWARE. 35 | 36 | nc=size(vol,3); 37 | if nargin ~=2 38 | vol2=vol; 39 | return; 40 | end 41 | for z=1:nc 42 | switch lower(type) 43 | case 'rot90' 44 | vol2(:,:,z)=flipud(vol(:,:,z)'); 45 | 46 | case 'rot180' 47 | vol2(:,:,z)=flipud(fliplr(vol(:,:,z))); 48 | 49 | case 'rot270' 50 | vol2(:,:,z)=fliplr(vol(:,:,z)'); 51 | 52 | case 'fliplr' 53 | vol2(:,:,z)=fliplr(vol(:,:,z)); 54 | 55 | otherwise 56 | vol2(:,:,z)=vol(:,:,z); 57 | end 58 | end -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_submit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # NAME 4 | # psom_submit - submit a job and reports failure with tag files 5 | # 6 | # SYNOPSIS 7 | # psom_submit COMMAND FILE_FAILED FILE_EXIT FILE_OQSUB 8 | # 9 | # DESCRIPTION 10 | # This is a simple script to submit jobs (or execute any command, really) 11 | # and generate empty tag files (as well as a warning) if the submission fails. 12 | # CMD is the command to execute 13 | # FILE_FAILED, FILE_EXIT and FLAG_OQSUB are the name of the tag files generated 14 | # in case of failure 15 | # 16 | # COPYRIGHT 17 | # Pierre Bellec, Departement d'informatique et de recherche operationnelle 18 | # Centre de recherche de l'institut de Geriatrie de Montreal 19 | # Universite de Montreal, 2012. 20 | # Maintainer : pierre.bellec@criugm.qc.ca 21 | # See licensing information in the code. 22 | 23 | # Permission is hereby granted, free of charge, to any person obtaining a copy 24 | # of this software and associated documentation files (the "Software"), to deal 25 | # in the Software without restriction, including without limitation the rights 26 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | # copies of the Software, and to permit persons to whom the Software is 28 | # furnished to do so, subject to the following conditions: 29 | # 30 | # The above copyright notice and this permission notice shall be included in 31 | # all copies or substantial portions of the Software. 32 | # 33 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 38 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 39 | # THE SOFTWARE. 40 | echo Submitting the job with the following command: 41 | echo $1 42 | eval $1 43 | if [ $? -ne 0 ] 44 | then 45 | echo The submission of the job through $1 failed 46 | touch $2 47 | touch $3 48 | touch $4 49 | fi 50 | -------------------------------------------------------------------------------- /niak/commands/statistics/niak_fisher.m: -------------------------------------------------------------------------------- 1 | function z = niak_fisher(r); 2 | % Fisher transformation of correlation coefficients. 3 | % 4 | % SYNTAX: 5 | % Z = NIAK_FISHER(R) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % R 11 | % (vector or matrix) some correlation coefficients 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS: 15 | % 16 | % Z 17 | % (same as R) the Fisher transform on R, i.e. (1/2) ln( (1+R)./(1-R) ) 18 | % 19 | % _________________________________________________________________________ 20 | % SEE ALSO: 21 | % 22 | % _________________________________________________________________________ 23 | % COMMENTS: 24 | % 25 | % Copyright (c) Pierre Bellec, Centre de recherche de l'institut de 26 | % Gériatrie de Montréal, Département d'informatique et de recherche 27 | % opérationnelle, Université de Montréal, 2010-2011. 28 | % Maintainer : pierre.bellec@criugm.qc.ca 29 | % See licensing information in the code. 30 | % Keywords : statistics, correlation, Fisher 31 | 32 | % Permission is hereby granted, free of charge, to any person obtaining a copy 33 | % of this software and associated documentation files (the "Software"), to deal 34 | % in the Software without restriction, including without limitation the rights 35 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36 | % copies of the Software, and to permit persons to whom the Software is 37 | % furnished to do so, subject to the following conditions: 38 | % 39 | % The above copyright notice and this permission notice shall be included in 40 | % all copies or substantial portions of the Software. 41 | % 42 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | % THE SOFTWARE. 49 | 50 | z = 0.5 * log( (1+r)./(1-r) ); -------------------------------------------------------------------------------- /niak/commands/SI_processing/niak_gaussian_fit.m: -------------------------------------------------------------------------------- 1 | function [y,Ybis] = niak_gaussian_fit(par) 2 | % This function is used by NIAK_CORRECT_VOL, and is not supposed to be used 3 | % independently. 4 | % 5 | % _________________________________________________________________________ 6 | % COMMENTS: 7 | % 8 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, 9 | % Montreal Neurological Institute, McGill University, 2008. 10 | % Maintainer : pbellec@bic.mni.mcgill.ca 11 | % See licensing information in the code. 12 | % Keywords : medical imaging 13 | 14 | % Permission is hereby granted, free of charge, to any person obtaining a copy 15 | % of this software and associated documentation files (the "Software"), to deal 16 | % in the Software without restriction, including without limitation the rights 17 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 18 | % copies of the Software, and to permit persons to whom the Software is 19 | % furnished to do so, subject to the following conditions: 20 | % 21 | % The above copyright notice and this permission notice shall be included in 22 | % all copies or substantial portions of the Software. 23 | % 24 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 25 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 26 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 27 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 28 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 29 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 30 | % THE SOFTWARE. 31 | 32 | % INPUT 33 | % par par(1) is the mean of the gaussian function 34 | % par(2) is the standard deviation of the gaussian function 35 | % 36 | % OUTPUTS 37 | % Ybis value of the gaussian function with parameters par at X (global) 38 | % y quadratic error between Ybis and Y (global) 39 | % 40 | % COMMENTS 41 | % Vincent Perlbarg 11/04/06 42 | 43 | global niak_gb_X niak_gb_Y 44 | mu = par(1); 45 | sig = par(2); 46 | 47 | Ybis = 1/(sqrt(2*pi)*sig)*exp(-0.5*((niak_gb_X-mu)/sig).^2); 48 | 49 | y = sum((niak_gb_Y-Ybis).^2); 50 | return -------------------------------------------------------------------------------- /niak/commands/formats/niak_full_file.m: -------------------------------------------------------------------------------- 1 | function file_name_f = niak_full_file(file_name) 2 | % convert a file name (either relative or absolute) into a full file name 3 | % 4 | % SYNTAX: 5 | % PATH_NAME_F = NIAK_FULL_FILE(PATH_NAME) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % FILE_NAME 11 | % (string) a file name with a relative or absolute path name. 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS: 15 | % 16 | % FILE_NAME_F 17 | % (string) same as FILE_NAME, but in a absolute path. 18 | % 19 | % _________________________________________________________________________ 20 | % COMMENTS: 21 | % 22 | % Copyright (c) Pierre Bellec, 23 | % Centre de recherche de l'institut de Gériatrie de Montréal, 24 | % Département d'informatique et de recherche opérationnelle, 25 | % Université de Montréal, 2012. 26 | % Maintainer : pierre.bellec@criugm.qc.ca 27 | % See licensing information in the code. 28 | % Keywords : 29 | 30 | % Permission is hereby granted, free of charge, to any person obtaining a copy 31 | % of this software and associated documentation files (the "Software"), to deal 32 | % in the Software without restriction, including without limitation the rights 33 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 34 | % copies of the Software, and to permit persons to whom the Software is 35 | % furnished to do so, subject to the following conditions: 36 | % 37 | % The above copyright notice and this permission notice shall be included in 38 | % all copies or substantial portions of the Software. 39 | % 40 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 41 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 42 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 43 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 44 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 45 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 46 | % THE SOFTWARE. 47 | 48 | [path_f,name_f,ext_f] = niak_fileparts(file_name); 49 | path_f = niak_full_path(path_f); 50 | file_name_f = [path_f name_f ext_f]; 51 | 52 | -------------------------------------------------------------------------------- /niak/commands/formats/niak_cmp_str_cell.m: -------------------------------------------------------------------------------- 1 | function mask_f = niak_cmp_str_cell(cell_str1,cell_str2) 2 | 3 | % Test if one of many strings exist in another list of strings 4 | % 5 | % SYNTAX: 6 | % MASK_F = niak_cmp_str_cell(CELL_STR1,CELL_STR2) 7 | % 8 | % INPUTS: 9 | % CELL_STR1 (string or cell of strings) 10 | % CELL_STR2 (string or cell of strings) 11 | % 12 | % OUTPUTS: 13 | % MASK_F (vector) MASK_F(i) equals 1 if CELL_STR{i} is identical to 14 | % CELL_STR2{j} for any j, 0 otherwise. If one argument is a 15 | % simple string, it is converted into a cell of string with 16 | % one element. 17 | % 18 | % SEE ALSO: 19 | % NIAK_FIND_STR_CELL 20 | % 21 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 22 | % Maintainer : pbellec@bic.mni.mcgill.ca 23 | % See licensing information in the code. 24 | % Keywords : string 25 | 26 | 27 | % Permission is hereby granted, free of charge, to any person obtaining a copy 28 | % of this software and associated documentation files (the "Software"), to deal 29 | % in the Software without restriction, including without limitation the rights 30 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 31 | % copies of the Software, and to permit persons to whom the Software is 32 | % furnished to do so, subject to the following conditions: 33 | % 34 | % The above copyright notice and this permission notice shall be included in 35 | % all copies or substantial portions of the Software. 36 | % 37 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 38 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 39 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 40 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 41 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 42 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 43 | % THE SOFTWARE. 44 | 45 | if ischar(cell_str1) 46 | str1{1} = cell_str1; 47 | cell_str = str1; 48 | clear str1 49 | end 50 | 51 | if ischar(cell_str2) 52 | str2{1} = cell_str2; 53 | cell_str2 = str2; 54 | clear str2 55 | end 56 | 57 | mask_f = ismember(cell_str1,cell_str2)'; -------------------------------------------------------------------------------- /niak/commands/statistics/niak_build_rmap.m: -------------------------------------------------------------------------------- 1 | function rmap = niak_build_rmap(vol,seed,mask); 2 | % Compute a functional connectivity map from a seed 3 | % 4 | % SYNTAX: 5 | % R = NIAK_BUILD_RMAP(VOL,SEED,MASK) 6 | % 7 | % INPUTS: 8 | % VOL (3D+t array) an fMRI dataset 9 | % SEED (3D array, same size as VOL(:,:,:,1) ) a binary mask of the seed 10 | % MASK (3D array, default every voxels) a binary mask where computation is restricted 11 | % 12 | % OUTPUTS 13 | % RMAP (3D array) the functional connectivity map, starting from the seed 14 | % 15 | % Copyright (c) Pierre Bellec, 16 | % Centre de recherche de l'institut de 17 | % Gériatrie de Montréal, Département d'informatique et de recherche 18 | % opérationnelle, Université de Montréal, 2013 19 | % Maintainer : pierre.bellec@criugm.qc.ca 20 | % See licensing information in the code. 21 | % Keywords : functional connectivity map, fMRI 22 | 23 | % Permission is hereby granted, free of charge, to any person obtaining a copy 24 | % of this software and associated documentation files (the "Software"), to deal 25 | % in the Software without restriction, including without limitation the rights 26 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 27 | % copies of the Software, and to permit persons to whom the Software is 28 | % furnished to do so, subject to the following conditions: 29 | % 30 | % The above copyright notice and this permission notice shall be included in 31 | % all copies or substantial portions of the Software. 32 | % 33 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 38 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 39 | % THE SOFTWARE. 40 | 41 | [nx,ny,nz,nt] = size(vol); 42 | if nargin < 3 43 | mask = true(nx,ny,nz); 44 | end 45 | y = niak_normalize_tseries(niak_vol2tseries(vol,mask)); 46 | x = niak_normalize_tseries(mean(y(:,seed(:)),2)); 47 | rmap = sum(y.*repmat(x,[1 size(y,2)]),1)/(nt-1); 48 | rmap = niak_tseries2vol (rmap,mask); -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_char2cell.m: -------------------------------------------------------------------------------- 1 | function cellstr = psom_char2cell(char_array) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY PSOM_CHAR2CELL 5 | % 6 | % Convert a char array into a cell of strings 7 | % 8 | % SYNTAX : 9 | % CELLSTR = PSOM_CHAR2CELL(CHAR_ARRAY) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS : 13 | % 14 | % CHAR_ARRAY 15 | % (string array) the rows of CHAR_ARRAY are the strings of interest 16 | % 17 | % _________________________________________________________________________ 18 | % OUTPUTS : 19 | % 20 | % CELLSTR 21 | % (cell of strings) CELLSTR{I} is a deblanked version of 22 | % CHAR_ARRAY(I,:). 23 | % 24 | % _________________________________________________________________________ 25 | % COMMENTS : 26 | % 27 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 28 | % Maintainer : pbellec@bic.mni.mcgill.ca 29 | % See licensing information in the code. 30 | % Keywords : string 31 | 32 | % Permission is hereby granted, free of charge, to any person obtaining a copy 33 | % of this software and associated documentation files (the "Software"), to deal 34 | % in the Software without restriction, including without limitation the rights 35 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36 | % copies of the Software, and to permit persons to whom the Software is 37 | % furnished to do so, subject to the following conditions: 38 | % 39 | % The above copyright notice and this permission notice shall be included in 40 | % all copies or substantial portions of the Software. 41 | % 42 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | % THE SOFTWARE. 49 | 50 | cellstr = cell([size(char_array,1) 1]); 51 | 52 | for num_e = 1:length(cellstr) 53 | cellstr{num_e} = deblank(char_array(num_e,:)); 54 | end -------------------------------------------------------------------------------- /niak/commands/formats/niak_mat2vec.m: -------------------------------------------------------------------------------- 1 | function vec = niak_mat2vec(mat); 2 | % Convert a symmetric matrix into a vector (the diagonal elements are lost) 3 | % 4 | % SYNTAX: 5 | % VEC = NIAK_MAT2VEC(MAT) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % MAT 11 | % (array) a square matrix. MAT should be symmetric. Diagonal elements 12 | % will be lost. 13 | % 14 | % _________________________________________________________________________ 15 | % OUTPUTS: 16 | % 17 | % VEC 18 | % (vector) a vectorized version of mat. Only off-diagonal 19 | % low-triangular values are kept. 20 | % 21 | % _________________________________________________________________________ 22 | % SEE ALSO: 23 | % NIAK_VEC2MAT 24 | % 25 | % _________________________________________________________________________ 26 | % COMMENTS: 27 | % 28 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 29 | % Neurological Institute, McGill University, 2007. 30 | % Maintainer : pbellec@bic.mni.mcgill.ca 31 | % See licensing information in the code. 32 | % Keywords : 33 | 34 | % Permission is hereby granted, free of charge, to any person obtaining a copy 35 | % of this software and associated documentation files (the "Software"), to deal 36 | % in the Software without restriction, including without limitation the rights 37 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 38 | % copies of the Software, and to permit persons to whom the Software is 39 | % furnished to do so, subject to the following conditions: 40 | % 41 | % The above copyright notice and this permission notice shall be included in 42 | % all copies or substantial portions of the Software. 43 | % 44 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 48 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 49 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 50 | % THE SOFTWARE. 51 | 52 | N = size(mat,1); 53 | vec = mat(tril(true(N),-1)); -------------------------------------------------------------------------------- /niak/commands/formats/niak_mat2lvec.m: -------------------------------------------------------------------------------- 1 | function vec = niak_mat2lvec(mat); 2 | % Convert a symmetric matrix into a vector (diagonal elements included) 3 | % 4 | % SYNTAX: 5 | % VEC = NIAK_MAT2LVEC(MAT) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % MAT 11 | % (array) a square matrix. MAT should be symmetric. Diagonal elements 12 | % will be included. 13 | % 14 | % _________________________________________________________________________ 15 | % OUTPUTS: 16 | % 17 | % LVEC 18 | % (vector) a vectorized version of mat. Low-triangular and diagonal 19 | % values are kept. 20 | % 21 | % _________________________________________________________________________ 22 | % SEE ALSO: 23 | % NIAK_LVEC2MAT 24 | % 25 | % _________________________________________________________________________ 26 | % COMMENTS: 27 | % 28 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 29 | % Neurological Institute, McGill University, 2007. 30 | % Maintainer : pbellec@bic.mni.mcgill.ca 31 | % See licensing information in the code. 32 | % Keywords : 33 | 34 | % Permission is hereby granted, free of charge, to any person obtaining a copy 35 | % of this software and associated documentation files (the "Software"), to deal 36 | % in the Software without restriction, including without limitation the rights 37 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 38 | % copies of the Software, and to permit persons to whom the Software is 39 | % furnished to do so, subject to the following conditions: 40 | % 41 | % The above copyright notice and this permission notice shall be included in 42 | % all copies or substantial portions of the Software. 43 | % 44 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 48 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 49 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 50 | % THE SOFTWARE. 51 | 52 | N = size(mat,1); 53 | 54 | mask_l = tril(ones(N)); 55 | mask_l = mask_l>0; 56 | 57 | vec = mat(mask_l); -------------------------------------------------------------------------------- /niak/commands/formats/niak_files2str.m: -------------------------------------------------------------------------------- 1 | function str_files = niak_files2str(files,pref) 2 | 3 | % Convert a string, cell of strings or a structure where each field is a 4 | % string into one single string, where each string is between " " and 5 | % multiple strings are separated by a ,. 6 | % 7 | % SYNTAX : 8 | % STR_FILES = NIAK_FILES2STR(FILES) 9 | % 10 | % INPUTS : 11 | % FILES (string, cell of strings or a structure where each field is a 12 | % string or a cell of strings) All those strings are file 13 | % names. 14 | % 15 | % PREF (string) 16 | % 17 | % OUTPUTS : 18 | % STR_FILES (string) all file names in FILES are concatenated in a 19 | % string of the form '[PREFfilename1]', '[PREFfilename2]' ... 20 | % 21 | % COMMENTS : 22 | % Copyright (c) Pierre Bellec 01/2008 23 | 24 | % Permission is hereby granted, free of charge, to any person obtaining a copy 25 | % of this software and associated documentation files (the "Software"), to deal 26 | % in the Software without restriction, including without limitation the rights 27 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | % copies of the Software, and to permit persons to whom the Software is 29 | % furnished to do so, subject to the following conditions: 30 | % 31 | % The above copyright notice and this permission notice shall be included in 32 | % all copies or substantial portions of the Software. 33 | % 34 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 40 | % THE SOFTWARE. 41 | 42 | if nargin < 2 43 | pref = ''; 44 | end 45 | 46 | cell_files = niak_files2cell(files); 47 | 48 | str_files = ''; 49 | 50 | for num_f = 1:length(cell_files); 51 | if ~strcmp(cell_files{num_f},'gb_niak_omitted') 52 | if isempty(str_files) 53 | str_files = [str_files '"' pref cell_files{num_f} '"']; 54 | else 55 | str_files = [str_files ', "' pref cell_files{num_f} '"']; 56 | end 57 | end 58 | end -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_rm_blank.m: -------------------------------------------------------------------------------- 1 | function str_b = psom_rm_blank(str,list_blanks) 2 | % Remove leading and trailing blanks from str, and suppress blanks 3 | % following a blank. 4 | % 5 | % SYNTAX 6 | % STR_B = NIAK_RM_BLANK(STR,LIST_BLANKS) 7 | % 8 | % INPUT 9 | % STR (vector of strings) 10 | % LIST_BLANKS (cell of string, default {}) a list of characters that 11 | % will be considered as blanks 12 | % 13 | % OUTPUT 14 | % STR_B (vector of strings) a "deblanked" version of str 15 | % 16 | % COMMENTS 17 | % 18 | % Copyright (c) Pierre Bellec 01/2008 19 | % 20 | % Permission is hereby granted, free of charge, to any person obtaining a copy 21 | % of this software and associated documentation files (the "Software"), to deal 22 | % in the Software without restriction, including without limitation the rights 23 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | % copies of the Software, and to permit persons to whom the Software is 25 | % furnished to do so, subject to the following conditions: 26 | % 27 | % The above copyright notice and this permission notice shall be included in 28 | % all copies or substantial portions of the Software. 29 | % 30 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | % THE SOFTWARE. 37 | 38 | % Setting up default 39 | if nargin < 2 40 | list_blanks = {}; 41 | end 42 | 43 | str_b = str; 44 | for num_e = 1:length(list_blanks) 45 | str_b = strrep(str_b,list_blanks{num_e},' '); 46 | end 47 | 48 | ind = 1:length(str); 49 | 50 | pos = findstr(str_b,' '); 51 | if length(pos)>1 52 | to_trash = find(pos(2:end)-pos(1:end-1)==1); 53 | if ~isempty(to_trash) 54 | str_b = str_b(~ismember(ind,pos(to_trash))); 55 | end 56 | end 57 | 58 | if ~isempty(str_b) 59 | if strcmp(str_b(1),' ') 60 | str_b = str_b(2:end); 61 | end 62 | end 63 | 64 | if ~isempty(str_b) 65 | if strcmp(str_b(end),' ') 66 | str_b = str_b(1:end-1); 67 | end 68 | end -------------------------------------------------------------------------------- /niak/commands/misc/niak_progress.m: -------------------------------------------------------------------------------- 1 | function [] = niak_progress(num_i,nb_it,perc) 2 | % Print percentage of progress in a loop 3 | % 4 | % SYNTAX: 5 | % NIAK_PROGRESS( NUM_I , NB_IT , [PERC] ) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % NUM_I 11 | % (integer) the current number of the iteration 12 | % 13 | % NB_IT 14 | % (integer) the total number of iteration 15 | % 16 | % PERC 17 | % (optional, default 5) a new message will be issued every PERC. 18 | % 19 | % _________________________________________________________________________ 20 | % COMMENTS: 21 | % 22 | % Copyright (c) Pierre Bellec, 23 | % Research Centre of the Montreal Geriatric Institute 24 | % & Department of Computer Science and Operations Research 25 | % University of Montreal, Québec, Canada, 2012 26 | % Maintainer : pierre.bellec@criugm.qc.ca 27 | % See licensing information in the code. 28 | % Keywords : 29 | 30 | % Permission is hereby granted, free of charge, to any person obtaining a copy 31 | % of this software and associated documentation files (the "Software"), to deal 32 | % in the Software without restriction, including without limitation the rights 33 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 34 | % copies of the Software, and to permit persons to whom the Software is 35 | % furnished to do so, subject to the following conditions: 36 | % 37 | % The above copyright notice and this permission notice shall be included in 38 | % all copies or substantial portions of the Software. 39 | % 40 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 41 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 42 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 43 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 44 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 45 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 46 | % THE SOFTWARE. 47 | 48 | if nargin<3 49 | perc = 5; 50 | end 51 | 52 | if num_i == 1 53 | fprintf(' Percentage done:') 54 | return 55 | end 56 | 57 | old_perc = perc*floor((100/perc)*(num_i-1)/nb_it); 58 | new_perc = perc*floor((100/perc)*num_i/nb_it); 59 | if old_perc~=new_perc 60 | fprintf(' %1.0f',new_perc); 61 | end 62 | if num_i == nb_it 63 | fprintf('\n') 64 | end -------------------------------------------------------------------------------- /pipeSetup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ============================================================================= 3 | # Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 4 | # BrainModes Research Group (head: P. Ritter) 5 | # Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 6 | # Correspondence: petra.ritter@charite.de 7 | # 8 | # When using this code please cite as follows: 9 | # Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P (in prep) 10 | # Constructing subject-specific Virtual Brains from multimodal neuroimaging 11 | # 12 | # This software is distributed under the terms of the GNU General Public License 13 | # as published by the Free Software Foundation. Further details on the GPL 14 | # license can be found at http://www.gnu.org/copyleft/gpl.html. 15 | # ============================================================================= 16 | 17 | #This file holds the paths to the local installations of the Toolboxes required to execute the Pipeline 18 | # 19 | #Set the rootPath i.e. the folder holding the shell scripts for the pipeline 20 | export rootPath=/home1/03510/srothmei/tvbPipe 21 | 22 | #Set the path to the folder holding the subject files 23 | export subFolder=/work/03510/srothmei/subjects 24 | 25 | #Define the folder for the logfiles 26 | export logFolder=${subFolder}/${subID}/logfiles 27 | 28 | #Set Paths FREESUFER 29 | #FREESURFER_HOME=/home/petra/freesurfer/freesurfer 30 | module load freesurfer 31 | 32 | #Set Paths for FSL 33 | FSLDIR=/home1/03510/srothmei/bin/fsl 34 | 35 | #Set Paths for MRTrix 36 | MRTrixDIR=/home1/03510/srothmei/bin/mrtrix-0.2 37 | 38 | 39 | ################################################################### 40 | # Additional stuff required to be executed for using the toolboxes. 41 | # Edit on own risk from here 42 | ################################################################### 43 | #SUBJECTS_DIR=${FREESURFER_HOME}/subjects 44 | #FUNCTIONALS_DIR=${FREESURFER_HOME}/sessions 45 | #PATH=${PATH}:${FREESURFER_HOME}/bin 46 | #export FREESURFER_HOME SUBJECTS_DIR FUNCTIONALS_DIR PATH 47 | #source ${FREESURFER_HOME}/FreeSurferEnv.sh 48 | #source ${FREESURFER_HOME}/SetUpFreeSurfer.sh 49 | 50 | . ${FSLDIR}/etc/fslconf/fsl.sh 51 | PATH=${FSLDIR}/bin:${PATH} 52 | export FSLDIR PATH 53 | 54 | LD_LIBRARY_PATH=${MRTrixDIR}/lib/ 55 | export LD_LIBRARY_PATH 56 | PATH=${MRTrixDIR}/bin:${PATH} 57 | export PATH 58 | 59 | #Include GNU parallel 60 | PATH=/home1/03510/srothmei/bin:${PATH} 61 | -------------------------------------------------------------------------------- /niak/commands/SI_processing/niak_unpad_vol.m: -------------------------------------------------------------------------------- 1 | function vol = niak_unpad_vol(vol_m,pad_size); 2 | % Pad a 3D volume with a single value or copies of extreme slices. 3 | % 4 | % SYNTAX : 5 | % VOL = NIAK_UNPAD_VOL(VOL_P,PAD_SIZE) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS : 9 | % 10 | % VOL 11 | % (3D array) a 3D volume. 12 | % 13 | % PAD_SIZE 14 | % (integer) remove PAD_SIZE elements at the begining/end of each 15 | % dimension of the volume. 16 | % 17 | % _________________________________________________________________________ 18 | % OUTPUTS : 19 | % 20 | % VOL 21 | % (3D array) same as VOL_M, but unpadded. 22 | % 23 | % _________________________________________________________________________ 24 | % SEE ALSO: 25 | % NIAK_PAD_VOL 26 | % 27 | % _________________________________________________________________________ 28 | % COMMENTS : 29 | % 30 | % Copyright (c) Pierre Bellec, Centre de Recherche de l'institut de 31 | % geriatrie de Montreal, Universite de Montreal, Montreal, Canada, 2010. 32 | % Maintainer : pbellec@bic.mni.mcgill.ca 33 | % See licensing information in the code. 34 | % Keywords : volume, padding 35 | 36 | % Permission is hereby granted, free of charge, to any person obtaining a copy 37 | % of this software and associated documentation files (the "Software"), to deal 38 | % in the Software without restriction, including without limitation the rights 39 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 40 | % copies of the Software, and to permit persons to whom the Software is 41 | % furnished to do so, subject to the following conditions: 42 | % 43 | % The above copyright notice and this permission notice shall be included 44 | % in all copies or substantial portions of the Software. 45 | % 46 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 49 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 52 | % THE SOFTWARE. 53 | % Setting up default 54 | 55 | siz_vol = size(vol_m)-2*pad_size; 56 | vol = vol_m(pad_size+1:pad_size+siz_vol(1),pad_size+1:pad_size+siz_vol(2),pad_size+1:pad_size+siz_vol(3)); 57 | -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_read_xml.m: -------------------------------------------------------------------------------- 1 | function [xml_struct] = psom_read_xml(xml_file) 2 | % Reads an XML file to a matlab structure. 3 | % 4 | % SYNTAX: 5 | % [XML_STRUCT] = PSOM_READ_XML(XML_FILE) 6 | % 7 | % ___________________________________________________________________________ 8 | % INPUTS 9 | % 10 | % XML_FILE 11 | % 12 | % A standard XML file. 13 | % 14 | % ___________________________________________________________________________ 15 | % OUTPUTS 16 | % 17 | % XML_STRUCT 18 | % 19 | % A standard matlab/octave structure containing the fields of the xml file. 20 | % _________________________________________________________________________ 21 | % COMMENTS: 22 | % 23 | % Copyright (c) Sebastien Lavoie-Courchesne, 24 | % Centre de recherche de l'institut de Gériatrie de Montréal 25 | % Département d'informatique et de recherche opérationnelle 26 | % Université de Montréal, 2011. 27 | % 28 | % Maintainer : pierre.bellec@criugm.qc.ca 29 | % See licensing information in the code. 30 | % Keywords : xml, structure 31 | 32 | % Permission is hereby granted, free of charge, to any person obtaining a copy 33 | % of this software and associated documentation files (the "Software"), to deal 34 | % in the Software without restriction, including without limitation the rights 35 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36 | % copies of the Software, and to permit persons to whom the Software is 37 | % furnished to do so, subject to the following conditions: 38 | % 39 | % The above copyright notice and this permission notice shall be included in 40 | % all copies or substantial portions of the Software. 41 | % 42 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | % THE SOFTWARE. 49 | 50 | 51 | [fid,msg] = fopen(xml_file,'r'); 52 | if(fid == -1) 53 | error(msg); 54 | end 55 | 56 | xml_text = char(fread(fid,[1,Inf],'char')); 57 | xml_uncommented = psom_string_remove(xml_text,''); 58 | xml_uncommented = psom_string_remove(xml_uncommented,''); 59 | xml_struct = psom_xml2struct(xml_uncommented); 60 | fclose(fid); 61 | endfunction -------------------------------------------------------------------------------- /niak/commands/formats/niak_rm_blank.m: -------------------------------------------------------------------------------- 1 | function str_b = niak_rm_blank(str,list_blanks) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_RM_BLANK 5 | % 6 | % Remove leading and trailing blanks from str, and suppress blanks 7 | % following a blank. 8 | % 9 | % SYNTAX 10 | % STR_B = NIAK_RM_BLANK(STR,LIST_BLANKS) 11 | % 12 | % INPUT 13 | % STR (vector of strings) 14 | % LIST_BLANKS (cell of string, default {}) a list of characters that 15 | % will be considered as blanks 16 | % 17 | % OUTPUT 18 | % STR_B (vector of strings) a "deblanked" version of str 19 | % 20 | % COMMENTS 21 | % 22 | % Copyright (c) Pierre Bellec 01/2008 23 | % 24 | % Permission is hereby granted, free of charge, to any person obtaining a copy 25 | % of this software and associated documentation files (the "Software"), to deal 26 | % in the Software without restriction, including without limitation the rights 27 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 28 | % copies of the Software, and to permit persons to whom the Software is 29 | % furnished to do so, subject to the following conditions: 30 | % 31 | % The above copyright notice and this permission notice shall be included in 32 | % all copies or substantial portions of the Software. 33 | % 34 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 35 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 36 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 37 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 38 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 39 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 40 | % THE SOFTWARE. 41 | 42 | % Setting up default 43 | if nargin < 2 44 | list_blanks = {}; 45 | end 46 | 47 | str_b = str; 48 | for num_e = 1:length(list_blanks) 49 | str_b = strrep(str_b,list_blanks{num_e},' '); 50 | end 51 | 52 | ind = 1:length(str); 53 | 54 | pos = findstr(str_b,' '); 55 | if length(pos)>1 56 | to_trash = find(pos(2:end)-pos(1:end-1)==1); 57 | if ~isempty(to_trash) 58 | str_b = str_b(~ismember(ind,pos(to_trash))); 59 | end 60 | end 61 | 62 | if ~isempty(str_b) 63 | if strcmp(str_b(1),' ') 64 | str_b = str_b(2:end); 65 | end 66 | end 67 | 68 | if ~isempty(str_b) 69 | if strcmp(str_b(end),' ') 70 | str_b = str_b(1:end-1); 71 | end 72 | end -------------------------------------------------------------------------------- /niak/commands/formats/niak_lvec2mat.m: -------------------------------------------------------------------------------- 1 | function mat = niak_lvec2mat(vec); 2 | % Convert a vector into a symmetric matrix. 3 | % 4 | % SYNTAX: 5 | % MAT = NIAK_LVEC2MAT(VEC) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % LVEC 11 | % (vector) a vectorized version of mat. Low-triangular and diagonal 12 | % values are kept. 13 | % 14 | % _________________________________________________________________________ 15 | % OUTPUTS: 16 | % 17 | % MAT 18 | % (array) a square matrix. MAT is symmetric. Diagonal elements are also 19 | % specified in VEC. 20 | % 21 | % _________________________________________________________________________ 22 | % SEE ALSO: 23 | % NIAK_MAT2LVEC 24 | % 25 | % _________________________________________________________________________ 26 | % COMMENTS: 27 | % 28 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 29 | % Neurological Institute, McGill University, 2007. 30 | % Maintainer : pbellec@bic.mni.mcgill.ca 31 | % See licensing information in the code. 32 | % Keywords : 33 | 34 | % Permission is hereby granted, free of charge, to any person obtaining a copy 35 | % of this software and associated documentation files (the "Software"), to deal 36 | % in the Software without restriction, including without limitation the rights 37 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 38 | % copies of the Software, and to permit persons to whom the Software is 39 | % furnished to do so, subject to the following conditions: 40 | % 41 | % The above copyright notice and this permission notice shall be included in 42 | % all copies or substantial portions of the Software. 43 | % 44 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 48 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 49 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 50 | % THE SOFTWARE. 51 | 52 | M = length(vec); 53 | N = round((-1+sqrt(1+8*M))/2); 54 | 55 | mat = zeros([N N]); 56 | 57 | mask_l = tril(ones(N)); 58 | mask_l = mask_l>0; 59 | 60 | mat(mask_l) = vec; 61 | mask_l = mask_l'; 62 | mask_l(eye(size(mask_l))>0) = 0; 63 | mat2 = mat'; 64 | mat(mask_l) = mat2(mask_l); 65 | 66 | -------------------------------------------------------------------------------- /aggregateSC.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script performs the final steps of the pipeline: 4 | # + Aggregate the SC matrix 5 | # + Convert the data into TVB format 6 | # + put all the resulting data (e.g. SC/FC matrices) into a single results-folder 7 | # + Delte the fiber tracks and put the whole folder into a compressed tarball 8 | # 9 | # ============================================================================= 10 | # Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 11 | # BrainModes Research Group (head: P. Ritter) 12 | # Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 13 | # Correspondence: petra.ritter@charite.de 14 | # 15 | # When using this code please cite as follows: 16 | # Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P (in prep) 17 | # Constructing subject-specific Virtual Brains from multimodal neuroimaging 18 | # 19 | # This software is distributed under the terms of the GNU General Public License 20 | # as published by the Free Software Foundation. Further details on the GPL 21 | # license can be found at http://www.gnu.org/copyleft/gpl.html. 22 | # ============================================================================= 23 | # 24 | 25 | #Init 26 | subID=$1 27 | subFolder=$2 28 | 29 | # Start with the aggregation 30 | ./runOctave.sh "aggregateSC_clusterDK('${subID}_SC.mat','${subFolder}/${subID}/mrtrix_68/masks_68/wmborder.mat','${subID}')" 31 | 32 | #Now convert the results into tvb format 33 | ./runOctave.sh "connectivity2TVBFS('${subID}','${subFolder}/${subID}','${subID}_SC.mat','recon_all')" 34 | 35 | #Gather all the results in a single folder 36 | resultFolder=${subFolder}/${subID}/results 37 | #SC Matrices 38 | cp ${subFolder}/${subID}/mrtrix_68/tracks_68/${subID}_SC.mat ${resultFolder}/${subID}_SC.mat 39 | #FC matrices 40 | if [ -d "$subFolder/$subID/RAWDATA/BOLD-EPI" ]; then 41 | cp ${subFolder}/${subID}/bold/${subID}_fMRI_new.mat ${resultFolder}/${subID}_fMRI_new.mat 42 | fi 43 | 44 | #Clean the results 45 | rm ${subFolder}/${subID}/mrtrix_68/tracks_68/*.tck 46 | 47 | #Remove the RAWDATA since the user has it anyway because he uploaded it... 48 | rm -R ${subFolder}/${subID}/RAWDATA 49 | 50 | #Remove some residual mrtrix-data, just in case there where some minor errors which might lead to a huge bloat of the folder size by not deleting 51 | #tmp-files correctly... 52 | rm -f ${subFolder}/${subID}/mrtrix_68/masks_68/mrtrix-*.nii 53 | 54 | #Tie up the download package... 55 | cd ${subFolder} 56 | tar -zcvf ${subID}_downloadData.tar.gz ${subID}/ && rm -R ${subID}/ 57 | -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_subset_pipeline.m: -------------------------------------------------------------------------------- 1 | function pipeline2 = psom_subset_pipeline(pipeline,list_jobs) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY PSOM_SUBSET_PIPELINE 5 | % 6 | % Extract a subset of a pipeline 7 | % 8 | % SYNTAX 9 | % PIPELINE2 = PSOM_SUBSET_PIPELINE(PIPELINE,LIST_JOBS) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUT 13 | % 14 | % PIPELINE 15 | % (structure) a pipeline (see PSOM_RUN_PIPELINE) 16 | % 17 | % LIST_JOBS 18 | % (string or cell of strings) a list of job names. 19 | % 20 | % _________________________________________________________________________ 21 | % OUTPUT 22 | % 23 | % PIPELINE2 24 | % (structure) all the jobs whose name contains one string from 25 | % LIST_JOBS is included in PIPELINE2 26 | % 27 | % _________________________________________________________________________ 28 | % COMMENTS 29 | % 30 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 31 | % Maintainer : pbellec@bic.mni.mcgill.ca 32 | % See licensing information in the code. 33 | % keywords : pipeline 34 | 35 | % Permission is hereby granted, free of charge, to any person obtaining a copy 36 | % of this software and associated documentation files (the "Software"), to deal 37 | % in the Software without restriction, including without limitation the rights 38 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | % copies of the Software, and to permit persons to whom the Software is 40 | % furnished to do so, subject to the following conditions: 41 | % 42 | % The above copyright notice and this permission notice shall be included in 43 | % all copies or substantial portions of the Software. 44 | % 45 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | % THE SOFTWARE. 52 | 53 | list_jobs_all = fieldnames(pipeline); 54 | mask_job = psom_find_str_cell(list_jobs_all,list_jobs); 55 | list_job2 = list_jobs_all(mask_job); 56 | 57 | for num_j = 1:length(list_job2) 58 | name_job = list_job2{num_j}; 59 | pipeline2.(name_job) = pipeline.(name_job); 60 | end -------------------------------------------------------------------------------- /niak/commands/formats/niak_merge_structs.m: -------------------------------------------------------------------------------- 1 | function struct12 = niak_merge_structs(struct1,struct2) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_MERGE_STRUCTS 5 | % 6 | % Merge two structures. 7 | % 8 | % SYNTAX: 9 | % STRUCT12 = NIAK_MERGE_STRUCTS(STRUCT1,STRUCT2) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS: 13 | % 14 | % STRUCT1 15 | % (structure) 16 | % 17 | % STRUCT2 18 | % (structure) 19 | % 20 | % _________________________________________________________________________ 21 | % OUTPUTS: 22 | % 23 | % STRUCT12 24 | % (structure) combines the fields of STRUCT1 and STRUCT2. 25 | % 26 | % _________________________________________________________________________ 27 | % COMMENTS: 28 | % 29 | % If structures have fields in common, the fields of STRUCT2 override the 30 | % ones of STRUCT1. 31 | % 32 | % For speed optimization, the smallest structure should be passed as 33 | % STRUCT2. 34 | % 35 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 36 | % Maintainer : pbellec@bic.mni.mcgill.ca 37 | % See licensing information in the code. 38 | % Keywords : structure 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | 58 | list_fields = fieldnames(struct2); 59 | struct12 = struct1; 60 | 61 | for num_f = 1:length(list_fields) 62 | 63 | struct12 = setfield(struct12,list_fields{num_f},getfield(struct2,list_fields{num_f})); 64 | 65 | end -------------------------------------------------------------------------------- /niak/commands/read_write/niak_read_transf.m: -------------------------------------------------------------------------------- 1 | function transf = niak_read_transf(file_name) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_READ_TRANSF 5 | % 6 | % Read a lsq12 transformation matrix from an xfm file 7 | % 8 | % SYNTAX: 9 | % TRANSF = NIAK_READ_TRANSF(FILE_NAME) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS: 13 | % 14 | % FILE_NAME 15 | % (string) the name of the xfm file (usually ends in .xfm) 16 | % 17 | % _________________________________________________________________________ 18 | % OUTPUTS: 19 | % 20 | % TRANSF 21 | % (matrix 4*4) a classical matrix representation of an lsq12 22 | % transformation. 23 | % 24 | % _________________________________________________________________________ 25 | % SEE ALSO: 26 | % 27 | % _________________________________________________________________________ 28 | % COMMENTS: 29 | % 30 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 31 | % Maintainer : pbellec@bic.mni.mcgill.ca 32 | % See licensing information in the code. 33 | % Keywords : xfm, minc 34 | 35 | 36 | % Permission is hereby granted, free of charge, to any person obtaining a copy 37 | % of this software and associated documentation files (the "Software"), to deal 38 | % in the Software without restriction, including without limitation the rights 39 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 40 | % copies of the Software, and to permit persons to whom the Software is 41 | % furnished to do so, subject to the following conditions: 42 | % 43 | % The above copyright notice and this permission notice shall be included in 44 | % all copies or substantial portions of the Software. 45 | % 46 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 49 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 52 | % THE SOFTWARE. 53 | 54 | hf = fopen(file_name); 55 | xfm_info = fread(hf,Inf,'uint8=>char')'; 56 | cell_info = niak_string2lines(xfm_info); 57 | transf = eye(4); 58 | transf(1,:) = str2num(cell_info{end-2}); 59 | transf(2,:) = str2num(cell_info{end-1}); 60 | transf(3,:) = str2num(cell_info{end}(1:end-1)); 61 | fclose(hf); -------------------------------------------------------------------------------- /niak/commands/clustering/niak_hier2order.m: -------------------------------------------------------------------------------- 1 | function order = niak_hier2order(hier); 2 | % Order objects based on a hierarchy. 3 | % 4 | % SYNTAX : 5 | % ORDER = NIAK_HIER2ORDER(HIER) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS : 9 | % 10 | % HIER 11 | % (2D array) defines a hierarchy (see NIAK_HIERARCHICAL_CLUSTERING) 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS : 15 | % 16 | % ORDER 17 | % (vector) defines a permutation on the objects as defined by HIER 18 | % when splitting the objects backward. 19 | % 20 | % _________________________________________________________________________ 21 | % COMMENTS : 22 | % 23 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 24 | % Maintainer : pbellec@bic.mni.mcgill.ca 25 | % See licensing information in the code. 26 | % Keywords : hierarchical clustering 27 | 28 | % Permission is hereby granted, free of charge, to any person obtaining a copy 29 | % of this software and associated documentation files (the "Software"), to deal 30 | % in the Software without restriction, including without limitation the rights 31 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 32 | % copies of the Software, and to permit persons to whom the Software is 33 | % furnished to do so, subject to the following conditions: 34 | % 35 | % The above copyright notice and this permission notice shall be included in 36 | % all copies or substantial portions of the Software. 37 | % 38 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 39 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 40 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 41 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 42 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 43 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 44 | % THE SOFTWARE. 45 | 46 | n = size(hier,1); 47 | if size(hier,2) == 3 48 | hier = [hier(:,3) hier(:,1) hier(:,2) ((n+2):(2*n+1))']; 49 | end 50 | 51 | order = hier(n,4); 52 | 53 | i = n; 54 | for i = n:-1:1 55 | ind = find(order==hier(i,4)); 56 | order2 = []; 57 | if ind > 1 58 | order2 = order(1:ind-1); 59 | end 60 | order2 = [order2 ; hier(i,2:3)']; 61 | if ind ') 18 | % 19 | % ___________________________________________________________________________ 20 | % OUTPUTS 21 | % 22 | % STRING_REMOVED 23 | % String with the substrings removed. 24 | % 25 | % _________________________________________________________________________ 26 | % COMMENTS: 27 | % 28 | % Copyright (c) Sebastien Lavoie-Courchesne, 29 | % Centre de recherche de l'institut de Gériatrie de Montréal 30 | % Département d'informatique et de recherche opérationnelle 31 | % Université de Montréal, 2011. 32 | % 33 | % Maintainer : pierre.bellec@criugm.qc.ca 34 | % See licensing information in the code. 35 | % Keywords : string, remove 36 | 37 | % Permission is hereby granted, free of charge, to any person obtaining a copy 38 | % of this software and associated documentation files (the "Software"), to deal 39 | % in the Software without restriction, including without limitation the rights 40 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 41 | % copies of the Software, and to permit persons to whom the Software is 42 | % furnished to do so, subject to the following conditions: 43 | % 44 | % The above copyright notice and this permission notice shall be included in 45 | % all copies or substantial portions of the Software. 46 | % 47 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 51 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 52 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 53 | % THE SOFTWARE. 54 | 55 | 56 | a = strfind(string,remove_start); 57 | string_removed = string; 58 | 59 | if(length(a) == 0) 60 | return 61 | end 62 | 63 | for num_c=1:length(a) 64 | b = strfind(string(a(num_c):end),remove_end); 65 | comment = string(a(num_c):a(num_c)+b(1)); 66 | string_removed = strrep(string_removed,comment,''); 67 | end 68 | endfunction 69 | -------------------------------------------------------------------------------- /niak/commands/read_write/niak_path_tmp.m: -------------------------------------------------------------------------------- 1 | function path_name = niak_path_tmp(ext) 2 | % Suggest a name for a temporary folder. 3 | % 4 | % SYNTAX: 5 | % PATH_NAME = NIAK_PATH_TMP(EXT) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % EXT 11 | % (string) An extension for the path name 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS: 15 | % 16 | % PATH_NAME 17 | % (string) A (full path) name for a temporary file. 18 | % 19 | % _________________________________________________________________________ 20 | % COMMENTS: 21 | % 22 | % The directory is created. 23 | % 24 | % The temporary paths live in the temporary directory. This directory is by 25 | % default '/tmp/', but this can be changed using the variable GB_NIAK_TMP 26 | % in the file NIAK_GB_VARS. 27 | % 28 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 29 | % Maintainer : pbellec@bic.mni.mcgill.ca 30 | % See licensing information in the code. 31 | % Keywords : 32 | 33 | % Permission is hereby granted, free of charge, to any person obtaining a copy 34 | % of this software and associated documentation files (the "Software"), to deal 35 | % in the Software without restriction, including without limitation the rights 36 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | % copies of the Software, and to permit persons to whom the Software is 38 | % furnished to do so, subject to the following conditions: 39 | % 40 | % The above copyright notice and this permission notice shall be included in 41 | % all copies or substantial portions of the Software. 42 | % 43 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | % THE SOFTWARE. 50 | global gb_psom_name_job 51 | niak_gb_vars 52 | flag_tmp = 1; 53 | 54 | while flag_tmp == 1 55 | if ~isempty(gb_psom_name_job) 56 | path_name = sprintf('%sniak_tmp_%s_%i%s%s',gb_niak_tmp,gb_psom_name_job,floor(1000000000*rand(1)),ext,filesep); 57 | else 58 | path_name = sprintf('%sniak_tmp_%i%s%s',gb_niak_tmp,floor(1000000000*rand(1)),ext,filesep); 59 | end 60 | flag_tmp = exist(path_name)>0; 61 | end 62 | 63 | niak_mkdir(path_name); -------------------------------------------------------------------------------- /niak/commands/formats/niak_neig2mat.m: -------------------------------------------------------------------------------- 1 | function mat = niak_neig2mat(neig); 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY OF NIAK_NEIG2MAT 5 | % 6 | % Convert a table of spatial neighbours into an adjacency matrix 7 | % representation. 8 | % 9 | % SYNTAX: 10 | % MAT = NIAK_NEIG2MAT(NEIG) 11 | % 12 | % _________________________________________________________________________ 13 | % INPUTS: 14 | % 15 | % (2D array) NEIG(i,:) is the list of neighbours of voxel i. All 16 | % numbers refer to a rwo of NEIG. Because all voxels 17 | % do not necessarily have the same number of neighbours, 0 are 18 | % used to pad each line. 19 | % 20 | % _________________________________________________________________________ 21 | % OUTPUTS: 22 | % 23 | % MAT 24 | % (sparse matrix) MAT(I,J) equals 1 is J is in the list of neighbours 25 | % of row I. 26 | % 27 | % _________________________________________________________________________ 28 | % SEE ALSO: 29 | % 30 | % NIAK_BUILD_NEIGHBOUR 31 | % 32 | % _________________________________________________________________________ 33 | % COMMENTS: 34 | % 35 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 36 | % Neurological Institute, McGill University, 2007. 37 | % Maintainer : pbellec@bic.mni.mcgill.ca 38 | % See licensing information in the code. 39 | % Keywords : 40 | 41 | % Permission is hereby granted, free of charge, to any person obtaining a copy 42 | % of this software and associated documentation files (the "Software"), to deal 43 | % in the Software without restriction, including without limitation the rights 44 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 45 | % copies of the Software, and to permit persons to whom the Software is 46 | % furnished to do so, subject to the following conditions: 47 | % 48 | % The above copyright notice and this permission notice shall be included in 49 | % all copies or substantial portions of the Software. 50 | % 51 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 52 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 53 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 54 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 55 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 56 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 57 | % THE SOFTWARE. 58 | 59 | N = size(neig,1); 60 | ind = find(neig); 61 | [x,y] = ind2sub(size(neig),ind); 62 | mat = sparse(x,neig(ind),ones([length(x) 1]),N,N); -------------------------------------------------------------------------------- /niak/commands/formats/niak_scales2cell.m: -------------------------------------------------------------------------------- 1 | function [scales1,scales2] = niak_scales2cell(scales_mat); 2 | % convert pairs of integer into non-redundant lists. 3 | % 4 | % SYNTAX: 5 | % [SCALES1,SCALES2] = NIAK_SCALES2CELL(SCALES_MAT) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % SCALES_MAT 11 | % (array N*2) each row is a pair of integers 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS: 15 | % 16 | % SCALES1 17 | % (vector) An ordered list of unique values found in SCALES_MAT(:,1) 18 | % 19 | % SCALES2 20 | % (cell) SCALES2{I} is an ordered list of unique integers found in 21 | % SCALES_MAT(:,2) such that SCALES_MAT(:,1) is equal to SCALES1(I). 22 | % 23 | % _________________________________________________________________________ 24 | % SEE ALSO: 25 | % NIAK_SCALES2MAT 26 | % 27 | % _________________________________________________________________________ 28 | % COMMENTS: 29 | % 30 | % Copyright (c) Pierre Bellec 31 | % Centre de recherche de l'institut de Gériatrie de Montréal 32 | % Département d'informatique et de recherche opérationnelle 33 | % Université de Montréal, 2010 34 | % Maintainer : pbellec@criugm.qc.ca 35 | % See licensing information in the code. 36 | % Keywords : 37 | 38 | % Permission is hereby granted, free of charge, to any person obtaining a copy 39 | % of this software and associated documentation files (the "Software"), to deal 40 | % in the Software without restriction, including without limitation the rights 41 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 42 | % copies of the Software, and to permit persons to whom the Software is 43 | % furnished to do so, subject to the following conditions: 44 | % 45 | % The above copyright notice and this permission notice shall be included in 46 | % all copies or substantial portions of the Software. 47 | % 48 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 54 | % THE SOFTWARE. 55 | 56 | scales1 = unique(scales_mat(:,1)); 57 | scales2 = cell([length(scales1) 1]); 58 | tmp1 = scales_mat(:,1); 59 | tmp2 = scales_mat(:,2); 60 | for num_x = 1:length(scales1) 61 | scales2{num_x} = unique(tmp2(tmp1==scales1(num_x))); 62 | end -------------------------------------------------------------------------------- /niak/commands/formats/niak_string2words.m: -------------------------------------------------------------------------------- 1 | function cell_words = niak_string2words(vec_string,list_blanks) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_STRING2WORDS 5 | % 6 | % Converts a strings into a cell of strings with individual words 7 | % 8 | % SYNTAX 9 | % cell_words = NIAK_STRING2WORDS(VEC_STRING,LIST_BLANKS) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUT 13 | % 14 | % VEC_STRING 15 | % (vector of strings) containing words separated by blanks 16 | % 17 | % LIST_BLANKS 18 | % (cell of string, default {}) a list of characters that 19 | % will be considered as blanks in addition to ' '. 20 | % 21 | % _________________________________________________________________________ 22 | % OUTPUT 23 | % 24 | % CELL_WORDS 25 | % (cell of string) cell_words{n} is the nth word in VEC_STRING 26 | % 27 | % _________________________________________________________________________ 28 | % COMMENTS 29 | % 30 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 31 | % Maintainer : pbellec@bic.mni.mcgill.ca 32 | % See licensing information in the code. 33 | % keywords : string 34 | 35 | % Permission is hereby granted, free of charge, to any person obtaining a copy 36 | % of this software and associated documentation files (the "Software"), to deal 37 | % in the Software without restriction, including without limitation the rights 38 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | % copies of the Software, and to permit persons to whom the Software is 40 | % furnished to do so, subject to the following conditions: 41 | % 42 | % The above copyright notice and this permission notice shall be included in 43 | % all copies or substantial portions of the Software. 44 | % 45 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | % THE SOFTWARE. 52 | 53 | % Setting up default 54 | if nargin < 2 55 | list_blanks = {}; 56 | end 57 | 58 | vec_string = niak_rm_blank(vec_string,list_blanks); 59 | 60 | if ~isempty(vec_string) 61 | ind = findstr([' ' vec_string ' '],' '); 62 | 63 | for num_i = 1:length(ind)-1 64 | cell_words{num_i} = vec_string(ind(num_i):ind(num_i+1)-2); 65 | end 66 | else 67 | cell_words = cell(0); 68 | end 69 | 70 | -------------------------------------------------------------------------------- /niak/commands/statistics/niak_build_covariance.m: -------------------------------------------------------------------------------- 1 | function S = niak_build_covariance(tseries,flag_vec); 2 | % Compute the covariance matrix from regional time series. 3 | % 4 | % SYNTAX: 5 | % S = NIAK_BUILD_COVARIANCE(TSERIES,FLAG_VEC) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % TSERIES 11 | % (array) time series. First dimension is time. 12 | % 13 | % FLAG_VEC 14 | % (boolean, default false) if FLAG_VEC == true, the matrix is 15 | % "vectorized" and the redundant elements are suppressed. Use 16 | % NIAK_LVEC2MAT to unvectorize it. 17 | % 18 | % _________________________________________________________________________ 19 | % OUTPUTS: 20 | % 21 | % S 22 | % (square matrix or vector) Empirical covariance matrix. S is 23 | % symmetrical. 24 | % 25 | % _________________________________________________________________________ 26 | % SEE ALSO: 27 | % NIAK_BUILD_MEASURE, NIAK_MAT2VEC, NIAK_MAT2LVEC, NIAK_VEC2MAT, 28 | % NIAK_LVEC2MAT, NIAK_BUILD_COVARIANCE, NIAK_BUILD_CORRELATION, 29 | % NIAK_BUILD_CONCENTRATION, NIAK_BUILD_PARTIAL_CORRELATION. 30 | % 31 | % _________________________________________________________________________ 32 | % COMMENTS: 33 | % 34 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 35 | % Neurological Institute, McGill University, 2007. 36 | % Maintainer : pbellec@bic.mni.mcgill.ca 37 | % See licensing information in the code. 38 | % Keywords : statistics, covariance 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | if nargin < 2 58 | flag_vec = false; 59 | end 60 | S = niak_build_srup(tseries,flag_vec); -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_string2words.m: -------------------------------------------------------------------------------- 1 | function cell_words = psom_string2words(vec_string,list_blanks) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY PSOM_STRING2WORDS 5 | % 6 | % Converts a strings into a cell of strings with individual words 7 | % 8 | % SYNTAX 9 | % cell_words = PSOM_STRING2WORDS(VEC_STRING,LIST_BLANKS) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUT 13 | % 14 | % VEC_STRING 15 | % (vector of strings) containing words separated by blanks 16 | % 17 | % LIST_BLANKS 18 | % (cell of string, default {}) a list of characters that 19 | % will be considered as blanks in addition to ' '. 20 | % 21 | % _________________________________________________________________________ 22 | % OUTPUT 23 | % 24 | % CELL_WORDS 25 | % (cell of string) cell_words{n} is the nth word in VEC_STRING 26 | % 27 | % _________________________________________________________________________ 28 | % COMMENTS 29 | % 30 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 31 | % Maintainer : pbellec@bic.mni.mcgill.ca 32 | % See licensing information in the code. 33 | % keywords : string 34 | 35 | % Permission is hereby granted, free of charge, to any person obtaining a copy 36 | % of this software and associated documentation files (the "Software"), to deal 37 | % in the Software without restriction, including without limitation the rights 38 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | % copies of the Software, and to permit persons to whom the Software is 40 | % furnished to do so, subject to the following conditions: 41 | % 42 | % The above copyright notice and this permission notice shall be included in 43 | % all copies or substantial portions of the Software. 44 | % 45 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | % THE SOFTWARE. 52 | 53 | % Setting up default 54 | if nargin < 2 55 | list_blanks = {}; 56 | end 57 | 58 | vec_string = psom_rm_blank(vec_string,list_blanks); 59 | 60 | if ~isempty(vec_string) 61 | ind = findstr([' ' vec_string ' '],' '); 62 | 63 | for num_i = 1:length(ind)-1 64 | cell_words{num_i} = vec_string(ind(num_i):ind(num_i+1)-2); 65 | end 66 | else 67 | cell_words = cell(0); 68 | end 69 | 70 | -------------------------------------------------------------------------------- /matlab_scripts/read_mrtrix_tracks.m: -------------------------------------------------------------------------------- 1 | function tracks = read_mrtrix_tracks (filename) 2 | 3 | % function: tracks = read_mrtrix_tracks (filename) 4 | % 5 | % returns a structure containing the header information and data for the MRtrix 6 | % format track file 'filename' (i.e. files with the extension '.tck'). 7 | % The track data will be stored as a cell array in the 'data' field of the 8 | % return variable. 9 | % 10 | % Source: MRTrix (http://www.brain.org.au/software/mrtrix/) 11 | 12 | image.comments = {}; 13 | 14 | f = fopen (filename, 'r'); 15 | if (f<1) 16 | disp (['error opening ' filename ]); 17 | return 18 | end 19 | L = fgetl(f); 20 | if ~strncmp(L, 'mrtrix tracks', 13) 21 | fclose(f); 22 | disp ([filename ' is not in MRtrix format']); 23 | return 24 | end 25 | 26 | tracks = struct(); 27 | 28 | while 1 29 | L = fgetl(f); 30 | if ~ischar(L), break, end; 31 | L = strtrim(L); 32 | if strcmp(L, 'END'), break, end; 33 | d = strfind (L,':'); 34 | if isempty(d) 35 | disp (['invalid line in header: ''' L ''' - ignored']); 36 | else 37 | key = lower(strtrim(L(1:d(1)-1))); 38 | value = strtrim(L(d(1)+1:end)); 39 | if strcmp(key, 'file') 40 | file = value; 41 | elseif strcmp(key, 'datatype') 42 | tracks.datatype = value; 43 | else 44 | tracks = setfield (tracks, key, value); 45 | end 46 | end 47 | end 48 | fclose(f); 49 | 50 | if ~exist ('file') || ~isfield (tracks, 'datatype') 51 | disp ('critical entries missing in header - aborting') 52 | return 53 | end 54 | 55 | [ file, offset ] = strtok(file); 56 | if ~strcmp(file,'.') 57 | disp ('unexpected file entry (should be set to current ''.'') - aborting') 58 | return; 59 | end 60 | 61 | if isempty(offset) 62 | disp ('no offset specified - aborting') 63 | return; 64 | end 65 | offset = str2num(char(offset)); 66 | 67 | datatype = lower(tracks.datatype); 68 | byteorder = datatype(end-1:end); 69 | 70 | if strcmp(byteorder, 'le') 71 | f = fopen (filename, 'r', 'l'); 72 | datatype = datatype(1:end-2); 73 | elseif strcmp(byteorder, 'be') 74 | f = fopen (filename, 'r', 'b'); 75 | datatype = datatype(1:end-2); 76 | else 77 | disp ('unexpected data type - aborting') 78 | return; 79 | end 80 | 81 | if (f<1) 82 | disp (['error opening ' filename ]); 83 | return 84 | end 85 | 86 | fseek (f, offset, -1); 87 | data = fread(f, inf, datatype); 88 | fclose (f); 89 | 90 | N = floor(prod(size(data))/3); 91 | data = reshape (data, 3, N)'; 92 | k = find (~isfinite(data(:,1))); 93 | 94 | tracks.data = {}; 95 | pk = 1; 96 | for n = 1:(prod(size(k))-1) 97 | tracks.data{end+1} = data(pk:(k(n)-1),:); 98 | pk = k(n)+1; 99 | end 100 | 101 | 102 | -------------------------------------------------------------------------------- /niak/commands/statistics/niak_build_concentration.m: -------------------------------------------------------------------------------- 1 | function U = niak_build_concentration(tseries,flag_vec); 2 | % Compute the concentration matrix from regional time series. 3 | % 4 | % SYNTAX: 5 | % U = NIAK_BUILD_CONCENTRATION(TSERIES,FLAG_VEC) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % TSERIES 11 | % (array) time series. First dimension is time. 12 | % 13 | % FLAG_VEC 14 | % (boolean, default false) if FLAG_VEC == true, the matrix is 15 | % "vectorized" and the redundant elements are suppressed. Use 16 | % NIAK_LVEC2MAT to unvectorize it. 17 | % 18 | % _________________________________________________________________________ 19 | % OUTPUTS: 20 | % 21 | % U 22 | % (square matrix or vector) Empirical concentration matrix. S is 23 | % symmetrical. 24 | % 25 | % _________________________________________________________________________ 26 | % SEE ALSO: 27 | % NIAK_BUILD_MEASURE, NIAK_MAT2VEC, NIAK_MAT2LVEC, NIAK_VEC2MAT, 28 | % NIAK_LVEC2MAT, NIAK_BUILD_COVARIANCE, NIAK_BUILD_CORRELATION, 29 | % NIAK_BUILD_CONCENTRATION, NIAK_BUILD_PARTIAL_CORRELATION. 30 | % 31 | % _________________________________________________________________________ 32 | % COMMENTS: 33 | % 34 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 35 | % Neurological Institute, McGill University, 2007. 36 | % Maintainer : pbellec@bic.mni.mcgill.ca 37 | % See licensing information in the code. 38 | % Keywords : statistics, concentration 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | if nargin < 2 58 | flag_vec = false; 59 | end 60 | [S,R,U] = niak_build_srup(tseries,flag_vec); -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_run_job.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env octave 2 | % Executes a .mat job. 3 | % 4 | % SYNTAX: 5 | % psom_run_job 6 | % 7 | % ___________________________________________________________________________ 8 | % INPUTS 9 | % 10 | % job.mat 11 | % .mat job to execute. 12 | % 13 | % ___________________________________________________________________________ 14 | % OUTPUTS 15 | % 16 | % The outputs depend on the given job. 17 | % 18 | % _________________________________________________________________________ 19 | % COMMENTS: 20 | % 21 | % Copyright (c) Sebastien Lavoie-Courchesne, 22 | % Centre de recherche de l'institut de Gériatrie de Montréal 23 | % Département d'informatique et de recherche opérationnelle 24 | % Université de Montréal, 2011. 25 | % 26 | % Maintainer : pierre.bellec@criugm.qc.ca 27 | % See licensing information in the code. 28 | % Keywords : job, execute, run 29 | 30 | % Permission is hereby granted, free of charge, to any person obtaining a copy 31 | % of this software and associated documentation files (the "Software"), to deal 32 | % in the Software without restriction, including without limitation the rights 33 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 34 | % copies of the Software, and to permit persons to whom the Software is 35 | % furnished to do so, subject to the following conditions: 36 | % 37 | % The above copyright notice and this permission notice shall be included in 38 | % all copies or substantial portions of the Software. 39 | % 40 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 41 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 42 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 43 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 44 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 45 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 46 | % THE SOFTWARE. 47 | 48 | if(nargin != 1 && nargin != 2) 49 | error("USAGE: psom_run_job or psom_run_job \n"); 50 | end 51 | 52 | args = argv(); 53 | job = load(args{1}); 54 | if isfield(job,'files_out') 55 | files_out = job.files_out; 56 | path_all = psom_files2cell(files_out); 57 | path_all = cellfun (@fileparts,path_all,'UniformOutput',false); 58 | path_all = unique(path_all); 59 | for num_p = 1:length(path_all) 60 | path_f = path_all{num_p}; 61 | [succ,messg,messgid] = psom_mkdir(path_f); 62 | if succ == 0 63 | warning(messgid,messg); 64 | end 65 | end 66 | end 67 | failed = psom_run_job(args{1}); 68 | if(~failed) 69 | printf('***Success***\n'); 70 | else 71 | printf('***Failure***\n'); 72 | end -------------------------------------------------------------------------------- /niak/commands/formats/niak_sub2ind_2d.m: -------------------------------------------------------------------------------- 1 | function ind = niak_sub2ind_2d(siz,subx,suby) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_SUB2IND_2D 5 | % 6 | % Convert 2D coordinates into linear indices 7 | % 8 | % SYNTAX : 9 | % IND = NIAK_SUB2IND_2D(SIZ,SUB) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS : 13 | % 14 | % SIZ 15 | % (vector 1*2) the size of the 2D array 16 | % 17 | % SUBX 18 | % (vector N*1) SUBX(M) is the X coordinate of the Mth element 19 | % 20 | % SUBY 21 | % (vector N*1) SUBY(M) is the Y coordinate of the Mth element 22 | % 23 | % _________________________________________________________________________ 24 | % OUTPUTS : 25 | % 26 | % IND 27 | % (vector N*1) IND(M) is the linear index corresponding to 28 | % [SUBX(M) SUBY(M)]. 29 | % 30 | % _________________________________________________________________________ 31 | % COMMENTS : 32 | % 33 | % This implementation of the classic matlab SUB2IND is markedly faster 34 | % because it notably avoids to check that the coordinates are valid (i.e. 35 | % within bounds). At least it used to be the case on Matlab 6.5. 36 | % 37 | % SUBX can also be a M*2 array. In that case, the first column corresponds 38 | % to SUBX and the second to SUBY. 39 | % 40 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 41 | % Maintainer : pbellec@bic.mni.mcgill.ca 42 | % See licensing information in the code. 43 | % Keywords : indices, matlab 44 | 45 | % Permission is hereby granted, free of charge, to any person obtaining a copy 46 | % of this software and associated documentation files (the "Software"), to deal 47 | % in the Software without restriction, including without limitation the rights 48 | % to use, copy, modify, merge, publish, distribute, subxlicense, and/or sell 49 | % copies of the Software, and to permit persons to whom the Software is 50 | % furnished to do so, subxject to the following conditions: 51 | % 52 | % The above copyright notice and this permission notice shall be included in 53 | % all copies or subxstantial portions of the Software. 54 | % 55 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 56 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 57 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 58 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 59 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 60 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 61 | % THE SOFTWARE. 62 | if nargin == 2 63 | ind = subx(:,1) + (subx(:,2)-1)*siz(1); 64 | else 65 | ind = subx + (suby-1)*siz(1); 66 | end -------------------------------------------------------------------------------- /niak/commands/statistics/niak_build_correlation.m: -------------------------------------------------------------------------------- 1 | function R = niak_build_correlation(tseries,flag_vec); 2 | % Compute the correlation matrix from regional time series. 3 | % 4 | % SYNTAX: 5 | % R = NIAK_BUILD_CORRELATION(TSERIES,FLAG_VEC) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % TSERIES 11 | % (array) time series. First dimension is time. 12 | % 13 | % FLAG_VEC 14 | % (boolean, default false) if FLAG_VEC == true, the matrix is 15 | % "vectorized" and the redundant elements are suppressed. Use 16 | % NIAK_VEC2MAT to unvectorize it. 17 | % 18 | % _________________________________________________________________________ 19 | % OUTPUTS: 20 | % 21 | % R 22 | % (square matrix or vector) Empirical correlation matrix. R is 23 | % symmetrical with ones on the diagonal. 24 | % 25 | % _________________________________________________________________________ 26 | % SEE ALSO: 27 | % NIAK_BUILD_MEASURE, NIAK_MAT2VEC, NIAK_MAT2LVEC, NIAK_VEC2MAT, 28 | % NIAK_LVEC2MAT, NIAK_BUILD_COVARIANCE, NIAK_BUILD_CORRELATION, 29 | % NIAK_BUILD_CONCENTRATION, NIAK_BUILD_PARTIAL_CORRELATION. 30 | % 31 | % _________________________________________________________________________ 32 | % COMMENTS: 33 | % 34 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 35 | % Neurological Institute, McGill University, 2007. 36 | % Maintainer : pbellec@bic.mni.mcgill.ca 37 | % See licensing information in the code. 38 | % Keywords : statistics, correlation 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | if nargin < 2 58 | flag_vec = false; 59 | end 60 | [S,R] = niak_build_srup(tseries,flag_vec); -------------------------------------------------------------------------------- /niak/commands/formats/niak_replace_str.m: -------------------------------------------------------------------------------- 1 | function str2 = niak_replace_str(str1,str_find,str_replace) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_REPLACE_STR 5 | % 6 | % Replace all occurences of one string by another in a string. 7 | % 8 | % SYNTAX: 9 | % STR = NIAK_REPLACE_STR(STR1,STR2) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS: 13 | % 14 | % STR1 15 | % (string) an arbitrary string. 16 | % 17 | % STR_FIND 18 | % (string) the string that needs to be replaced 19 | % 20 | % STR_REPLACE 21 | % (string) the "replace by" string 22 | % 23 | % _________________________________________________________________________ 24 | % OUTPUTS: 25 | % 26 | % STR2 27 | % (string) same as STR1, except all occurences of STR_FIND have 28 | % been replaced by STR_REPLACE. 29 | % 30 | % _________________________________________________________________________ 31 | % COMMENTS 32 | % 33 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 34 | % Maintainer : pbellec@bic.mni.mcgill.ca 35 | % See licensing information in the code. 36 | % Keywords : niak, string 37 | 38 | % Permission is hereby granted, free of charge, to any person obtaining a copy 39 | % of this software and associated documentation files (the "Software"), to deal 40 | % in the Software without restriction, including without limitation the rights 41 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 42 | % copies of the Software, and to permit persons to whom the Software is 43 | % furnished to do so, subject to the following conditions: 44 | % 45 | % The above copyright notice and this permission notice shall be included in 46 | % all copies or substantial portions of the Software. 47 | % 48 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 54 | % THE SOFTWARE. 55 | 56 | pos = findstr(str1,str_find); 57 | if isempty(pos) 58 | 59 | str2 = str1; 60 | 61 | else 62 | str2 = []; 63 | 64 | num_p = 1; 65 | while num_p <= length(str1) 66 | 67 | if ismember(num_p,pos) 68 | str2 = [str2 str_replace]; 69 | num_p = num_p + length(str_find); 70 | else 71 | str2 = [str2 str1(num_p)]; 72 | num_p = num_p+1; 73 | end 74 | end 75 | end -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_file_tmp.m: -------------------------------------------------------------------------------- 1 | function file_name = psom_file_tmp(ext) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY PSOM_FILE_TMP 5 | % 6 | % Suggest a name of temporary file 7 | % 8 | % SYNTAX: 9 | % FILE_NAME = PSOM_FILE_TMP(EXT) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS: 13 | % 14 | % EXT (string) An extension for the file name 15 | % 16 | % OUTPUTS: 17 | % 18 | % A (full path) name for a temporary file. 19 | % 20 | % _________________________________________________________________________ 21 | % COMMENTS: 22 | % 23 | % The temporary files live in the temporary directory. This directory is by 24 | % default '/tmp/', but this can be changed using the variable GB_PSOM_TMP 25 | % in the file PSOM_GB_VARS. 26 | % 27 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 28 | % Maintainer : pbellec@bic.mni.mcgill.ca 29 | % See licensing information in the code. 30 | % Keywords : 31 | 32 | % Permission is hereby granted, free of charge, to any person obtaining a copy 33 | % of this software and associated documentation files (the "Software"), to deal 34 | % in the Software without restriction, including without limitation the rights 35 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36 | % copies of the Software, and to permit persons to whom the Software is 37 | % furnished to do so, subject to the following conditions: 38 | % 39 | % The above copyright notice and this permission notice shall be included in 40 | % all copies or substantial portions of the Software. 41 | % 42 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | % THE SOFTWARE. 49 | 50 | global gb_psom_name_job 51 | flag_gb_psom_fast_gb = 1; %% the initialization of global variables will be as fast as possible 52 | psom_gb_vars 53 | if nargin == 0 54 | ext = '.tmp'; 55 | end 56 | flag_tmp = 1; 57 | while flag_tmp == 1 58 | label = clock; 59 | label(end) = 10000*label(end); 60 | label = round(sum(label)); 61 | if ~isempty(gb_psom_name_job) 62 | file_name = sprintf('%spsom_tmp_%s_%i%s',gb_psom_tmp,gb_psom_name_job,label,ext); 63 | else 64 | file_name = sprintf('%spsom_tmp_%i%s',gb_psom_tmp,label,ext); 65 | end 66 | flag_tmp = psom_exist(file_name); 67 | end 68 | 69 | save(file_name,'flag_tmp') -------------------------------------------------------------------------------- /niak/commands/formats/niak_sub2ind_3d.m: -------------------------------------------------------------------------------- 1 | function ind = niak_sub2ind_3d(siz,subx,suby,subz) 2 | % Convert 3D coordinates into linear indices 3 | % 4 | % SYNTAX : 5 | % IND = NIAK_SUB2IND_3D(SIZ,SUB) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS : 9 | % 10 | % SIZ 11 | % (vector 1*3) the size of the 3D array 12 | % 13 | % SUBX 14 | % (vector N*1) SUBX(M) is the X coordinate of the Mth element 15 | % 16 | % SUBY 17 | % (vector N*1) SUBY(M) is the Y coordinate of the Mth element 18 | % 19 | % SUBZ 20 | % (vector N*1) SUBZ(M) is the Z coordinate of the Mth element 21 | % 22 | % _________________________________________________________________________ 23 | % OUTPUTS : 24 | % 25 | % IND 26 | % (vector N*1) IND(M) is the linear index corresponding to 27 | % [SUBX(M) SUBY(M) SUBZ(M)] 28 | % 29 | % _________________________________________________________________________ 30 | % COMMENTS : 31 | % 32 | % This implementation of the classic matlab SUB2IND is markedly faster 33 | % because it notably avoids to check that the coordinates are valid (i.e. 34 | % within bounds). At least it used to be the case on Matlab 6.5. 35 | % 36 | % SUBX can also be a M*3 array. In that case, the first column corresponds 37 | % to SUBX, the second to SUBY and the third to SUBZ. 38 | % 39 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 40 | % Maintainer : pbellec@bic.mni.mcgill.ca 41 | % See licensing information in the code. 42 | % Keywords : indices, matlab 43 | 44 | % Permission is hereby granted, free of charge, to any person obtaining a copy 45 | % of this software and associated documentation files (the "Software"), to deal 46 | % in the Software without restriction, including without limitation the rights 47 | % to use, copy, modify, merge, publish, distribute, subxlicense, and/or sell 48 | % copies of the Software, and to permit persons to whom the Software is 49 | % furnished to do so, subxject to the following conditions: 50 | % 51 | % The above copyright notice and this permission notice shall be included in 52 | % all copies or subxstantial portions of the Software. 53 | % 54 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 55 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 56 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 57 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 58 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 59 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 60 | % THE SOFTWARE. 61 | if nargin == 2 62 | ind = subx(:,1) + (subx(:,2)-1)*siz(1) + (subx(:,3)-1)*siz(1)*siz(2); 63 | else 64 | ind = subx + (suby-1)*siz(1) + (subz-1)*siz(1)*siz(2); 65 | end -------------------------------------------------------------------------------- /niak/commands/statistics/niak_build_partial_correlation.m: -------------------------------------------------------------------------------- 1 | function P = niak_build_partial_correlation(tseries,flag_vec); 2 | % Compute the partial correlation matrix from regional time series. 3 | % 4 | % SYNTAX: 5 | % P = NIAK_BUILD_PARTIAL_CORRELATION(TSERIES,FLAG_VEC) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % TSERIES 11 | % (array) time series. First dimension is time. 12 | % 13 | % FLAG_VEC 14 | % (boolean, default false) if FLAG_VEC == true, the matrix is 15 | % "vectorized" and the redundant elements are suppressed. Use 16 | % NIAK_VEC2MAT to unvectorize it. 17 | % 18 | % _________________________________________________________________________ 19 | % OUTPUTS: 20 | % 21 | % P 22 | % (square matrix or vector) Empirical partial correlation matrix. P 23 | % is symmetrical with ones on the diagonal. 24 | % 25 | % _________________________________________________________________________ 26 | % SEE ALSO: 27 | % NIAK_BUILD_MEASURE, NIAK_MAT2VEC, NIAK_MAT2LVEC, NIAK_VEC2MAT, 28 | % NIAK_LVEC2MAT, NIAK_BUILD_COVARIANCE, NIAK_BUILD_CORRELATION, 29 | % NIAK_BUILD_CONCENTRATION, NIAK_BUILD_PARTIAL_CORRELATION. 30 | % 31 | % _________________________________________________________________________ 32 | % COMMENTS: 33 | % 34 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 35 | % Neurological Institute, McGill University, 2007. 36 | % Maintainer : pbellec@bic.mni.mcgill.ca 37 | % See licensing information in the code. 38 | % Keywords : statistics, correlation 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | if nargin < 2 58 | flag_vec = false; 59 | end 60 | [S,R,U,P] = niak_build_srup(tseries,flag_vec); -------------------------------------------------------------------------------- /niak/commands/formats/niak_vol2tseries.m: -------------------------------------------------------------------------------- 1 | function tseries = niak_vol2tseries(vol,mask) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_VOL2TSERIES 5 | % 6 | % Convert a 3D+t dataset into a time*space array. 7 | % 8 | % SYNTAX : 9 | % TSERIES = NIAK_VOL2TSERIES(VOL,MASK) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS : 13 | % 14 | % VOL 15 | % (4D array) A 3D+t dataset. 16 | % 17 | % MASK 18 | % (3D volume, default all voxels) a binary mask of the voxels that 19 | % will be included in the time*space array. 20 | % 21 | % _________________________________________________________________________ 22 | % OUTPUTS : 23 | % 24 | % TSERIES 25 | % (2D array) a time*space array with the time series of the voxel in 26 | % MASK (in the same order as in find(MASK)). 27 | % 28 | % _________________________________________________________________________ 29 | % COMMENTS : 30 | % 31 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 32 | % Maintainer : pbellec@bic.mni.mcgill.ca 33 | % See licensing information in the code. 34 | % Keywords : 35 | 36 | % Permission is hereby granted, free of charge, to any person obtaining a copy 37 | % of this software and associated documentation files (the "Software"), to deal 38 | % in the Software without restriction, including without limitation the rights 39 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 40 | % copies of the Software, and to permit persons to whom the Software is 41 | % furnished to do so, subject to the following conditions: 42 | % 43 | % The above copyright notice and this permission notice shall be included in 44 | % all copies or substantial portions of the Software. 45 | % 46 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 49 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 52 | % THE SOFTWARE. 53 | 54 | if ~exist('vol','var') 55 | error('Syntax : TSERIES = NIAK_VOL2TSERIES(VOL,MASK) . Type ''help niak_vol2tseries'' for more info'); 56 | end 57 | 58 | [nx,ny,nz,nt] = size(vol); 59 | 60 | if ~exist('mask','var') 61 | mask = ones([nx,ny,nz]); 62 | end 63 | mask = mask > 0; 64 | [nx2,ny2,nz2] = size(mask); 65 | if (nx~=nx2)||(ny~=ny2)||(nz~=nz2) 66 | error('The mask should have the same spatial dimensions as the space-time dataset'); 67 | end 68 | tseries = reshape(vol,[nx*ny*nz nt]); 69 | tseries = tseries(mask,:)'; 70 | -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_merge_pipeline.m: -------------------------------------------------------------------------------- 1 | function struct12 = psom_merge_pipeline(struct1,struct2,prefix) 2 | % Merge two pipelines (or any two arbitrary structures with one entry). 3 | % 4 | % SYNTAX: 5 | % PIPE12 = PSOM_MERGE_PIPELINE(PIPE1,PIPE2,PREFIX) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % PIPE1 11 | % (structure) with one entry. 12 | % 13 | % PIPE2 14 | % (structure) with one entry. 15 | % 16 | % PREFIX 17 | % (string, default '') a prefix added to all field names in PIPE2 before 18 | % merging. 19 | % 20 | % _________________________________________________________________________ 21 | % OUTPUTS: 22 | % 23 | % PIPE12 24 | % (structure) combines the fields of PIPE1 and PIPE2. 25 | % 26 | % _________________________________________________________________________ 27 | % COMMENTS: 28 | % 29 | % If structures have fields in common, the fields of PIPE2 override the 30 | % ones of PIPE1. 31 | % 32 | % For speed optimization, the smallest structure should be passed as 33 | % PIPE2. 34 | % 35 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 36 | % Maintainer : pbellec@bic.mni.mcgill.ca 37 | % See licensing information in the code. 38 | % Keywords : structure 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | 58 | if nargin < 3 59 | prefix = ''; 60 | end 61 | 62 | list_fields = fieldnames(struct2); 63 | struct12 = struct1; 64 | 65 | for num_f = 1:length(list_fields) 66 | if ~isempty(prefix)&&isfield(struct2.(list_fields{num_f}),'dep') 67 | struct2.(list_fields{num_f}).dep = strcat(prefix,struct2.(list_fields{num_f}).dep); 68 | end 69 | struct12.([prefix list_fields{num_f}]) = struct2.(list_fields{num_f}); 70 | end -------------------------------------------------------------------------------- /niak/commands/read_write/niak_file_tmp.m: -------------------------------------------------------------------------------- 1 | function file_name = niak_file_tmp(ext) 2 | % Suggest a name of temporary file 3 | % 4 | % SYNTAX: 5 | % FILE_NAME = NIAK_FILE_TMP(EXT) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % EXT 11 | % (string) An extension for the file name 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS: 15 | % 16 | % FILE_NAME 17 | % (string) A (full path) name for a temporary file. 18 | % 19 | % _________________________________________________________________________ 20 | % COMMENTS: 21 | % 22 | % The temporary files live in the temporary directory. This directory is by 23 | % default '/tmp/', but this can be changed using the variable GB_NIAK_TMP 24 | % in the file NIAK_GB_VARS. 25 | % 26 | % If this function is called using the pipeline system for Octave and Matlab, 27 | % it will use the job name as part of the temporary file name. 28 | % 29 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 30 | % Maintainer : pbellec@bic.mni.mcgill.ca 31 | % See licensing information in the code. 32 | % Keywords : 33 | 34 | % Permission is hereby granted, free of charge, to any person obtaining a copy 35 | % of this software and associated documentation files (the "Software"), to deal 36 | % in the Software without restriction, including without limitation the rights 37 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 38 | % copies of the Software, and to permit persons to whom the Software is 39 | % furnished to do so, subject to the following conditions: 40 | % 41 | % The above copyright notice and this permission notice shall be included in 42 | % all copies or substantial portions of the Software. 43 | % 44 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 48 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 49 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 50 | % THE SOFTWARE. 51 | 52 | global gb_psom_name_job 53 | flag_gb_niak_fast_gb = 1; %% the initialization of global variables will be as fast as possible 54 | niak_gb_vars 55 | flag_tmp = 1; 56 | 57 | while flag_tmp == 1; 58 | if ~isempty(gb_psom_name_job) 59 | file_name = sprintf('%s_niak_tmp_%s_%i%s',gb_niak_tmp,gb_psom_name_job,floor(1000000000*rand(1)),ext); 60 | else 61 | file_name = sprintf('%sniak_tmp_%i%s',gb_niak_tmp,floor(1000000000*rand(1)),ext); 62 | end 63 | flag_tmp = exist(file_name,'file')>0; 64 | end 65 | save(file_name,'flag_tmp') -------------------------------------------------------------------------------- /niak/commands/formats/niak_tseries2vol.m: -------------------------------------------------------------------------------- 1 | function vol = niak_tseries2vol(tseries,mask) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_TSERIES2VOL 5 | % 6 | % Convert a time*space array along with a binary mask of voxels into a 3D+t 7 | % dataset. 8 | % 9 | % SYNTAX : 10 | % VOL = NIAK_TSERIES2VOL(TSERIES,MASK) 11 | % 12 | % _________________________________________________________________________ 13 | % INPUTS : 14 | % 15 | % TSERIES 16 | % (2D array) a time*space array with the time series of the voxel in 17 | % MASK (in the same order as in find(MASK)). 18 | % 19 | % MASK 20 | % (3D volume, default all voxels) a binary mask of the voxels that 21 | % are included in the time*space array. 22 | % 23 | % _________________________________________________________________________ 24 | % OUTPUTS : 25 | % 26 | % VOL 27 | % (4D array) A 3D+t dataset. 28 | % 29 | % _________________________________________________________________________ 30 | % COMMENTS : 31 | % 32 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 33 | % Maintainer : pbellec@bic.mni.mcgill.ca 34 | % See licensing information in the code. 35 | % Keywords : 36 | 37 | % Permission is hereby granted, free of charge, to any person obtaining a copy 38 | % of this software and associated documentation files (the "Software"), to deal 39 | % in the Software without restriction, including without limitation the rights 40 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 41 | % copies of the Software, and to permit persons to whom the Software is 42 | % furnished to do so, subject to the following conditions: 43 | % 44 | % The above copyright notice and this permission notice shall be included in 45 | % all copies or substantial portions of the Software. 46 | % 47 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 51 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 52 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 53 | % THE SOFTWARE. 54 | 55 | if ~exist('tseries','var')||~exist('mask','var') 56 | error('Syntax : VOL = NIAK_TSERIES2VOL(TSERIES,MASK) . Type ''help niak_tseries2vol'' for more info'); 57 | end 58 | 59 | [nx,ny,nz] = size(mask); 60 | 61 | mask = mask>0; 62 | 63 | nt = size(tseries,1); 64 | 65 | if sum(mask(:))~= size(tseries,2) 66 | error('the space dimension in TSERIES should have the same size as the number of voxels in mask !'); 67 | end 68 | 69 | vol = zeros([nx*ny*nz nt]); 70 | vol(mask,:) = tseries'; 71 | vol = reshape(vol,[nx ny nz nt]); -------------------------------------------------------------------------------- /niak/commands/statistics/niak_gen_connectome.m: -------------------------------------------------------------------------------- 1 | function [R_ind]=niak_gen_connectome(vol,brain_rois,order) 2 | % Extract the connectome from a 3D+t dataset. 3 | % 4 | % [R_IND] = NIAK_GEN_CONNECTOME(VOL,BRAIN_ROIS,ORDER) 5 | % 6 | % _________________________________________________________________________ 7 | % INPUTS: 8 | % 9 | % VOL 10 | % (3D+t array) the fMRI data. 11 | % 12 | % BRAIN_ROIS 13 | % (3D volume) mask or ROI coded with integers. ROI #I is defined by 14 | % MASK==I 15 | % 16 | % ORDER 17 | % (optional) the order of eahc index of the connectome index 18 | % 19 | % _________________________________________________________________________ 20 | % OUTPUTS: 21 | % 22 | % R_IND 23 | % (array) The connectome of the 3D+t dataset 24 | % 25 | % _________________________________________________________________________ 26 | % COMMENTS: 27 | % 28 | % Copyright (c) Christian L. Dansereau, 29 | % Centre de recherche de l'Institut universitaire de gériatrie de Montréal, 30 | % 2012. 31 | % Maintainer : pierre.bellec@criugm.qc.ca 32 | % See licensing information in the code. 33 | % Keywords : connectome, fMRI 34 | 35 | % Permission is hereby granted, free of charge, to any person obtaining a copy 36 | % of this software and associated documentation files (the "Software"), to deal 37 | % in the Software without restriction, including without limitation the rights 38 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 39 | % copies of the Software, and to permit persons to whom the Software is 40 | % furnished to do so, subject to the following conditions: 41 | % 42 | % The above copyright notice and this permission notice shall be included in 43 | % all copies or substantial portions of the Software. 44 | % 45 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 46 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 47 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 48 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 49 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 50 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 51 | % THE SOFTWARE. 52 | 53 | [tseries_rois,std_tseries_rois] = niak_build_tseries(vol,brain_rois); 54 | 55 | %% Correcting the mean of the time series 56 | 57 | fprintf('Correction of the mean of time series ...\n'); 58 | opt_norm.type = 'mean_var'; 59 | tseries_rois = niak_normalize_tseries(tseries_rois,opt_norm); 60 | 61 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 62 | %% connectome computation %% 63 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 64 | 65 | fprintf('Computing the connectome from the time series ...\n'); 66 | R_ind = corrcoef(tseries_rois); 67 | 68 | % If order is specified 69 | if exist('order') 70 | R_ind = R_ind(order,order); 71 | end 72 | 73 | -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_path_tmp.m: -------------------------------------------------------------------------------- 1 | function path_name = psom_path_tmp(ext) 2 | % Suggest a name for a temporary folder. 3 | % 4 | % SYNTAX: 5 | % PATH_NAME = PSOM_PATH_TMP(EXT) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % EXT 11 | % (string) An extension for the path name 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS: 15 | % 16 | % PATH_NAME 17 | % (string) A (full path) name for a temporary file. 18 | % 19 | % _________________________________________________________________________ 20 | % COMMENTS: 21 | % 22 | % The directory is created. 23 | % 24 | % The temporary paths live in the temporary directory. This directory is by 25 | % default '/tmp/', but this can be changed using the variable GB_PSOM_TMP 26 | % in the file PSOM_GB_VARS. 27 | % 28 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 29 | % Maintainer : pbellec@bic.mni.mcgill.ca 30 | % See licensing information in the code. 31 | % Keywords : 32 | 33 | % Permission is hereby granted, free of charge, to any person obtaining a copy 34 | % of this software and associated documentation files (the "Software"), to deal 35 | % in the Software without restriction, including without limitation the rights 36 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | % copies of the Software, and to permit persons to whom the Software is 38 | % furnished to do so, subject to the following conditions: 39 | % 40 | % The above copyright notice and this permission notice shall be included in 41 | % all copies or substantial portions of the Software. 42 | % 43 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 49 | % THE SOFTWARE. 50 | global gb_psom_name_job 51 | flag_gb_psom_fast_gb = 1; %% the initialization of global variables will be as fast as possible 52 | psom_gb_vars 53 | flag_tmp = 1; 54 | if nargin == 0 55 | ext = ''; 56 | end 57 | 58 | while flag_tmp == 1 59 | label = clock; 60 | label(end) = 10000*label(end); 61 | label = round(sum(label)); 62 | if ~isempty(gb_psom_name_job) 63 | path_name = sprintf('%spsom_tmp_%s_%i%s%s',gb_psom_tmp,gb_psom_name_job,label,ext,filesep); 64 | else 65 | path_name = sprintf('%spsom_tmp_%i%s%s',gb_psom_tmp,label,ext,filesep); 66 | end 67 | flag_tmp = exist(path_name,'dir')>0; 68 | end 69 | 70 | psom_mkdir(path_name); -------------------------------------------------------------------------------- /niak/commands/read_write/niak_resample_to_self.m: -------------------------------------------------------------------------------- 1 | function [] = niak_resample_to_self(file_name,opt) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_RESAMPLE_TO_SELF 5 | % 6 | % Apply MINCRESAMPLE to resample a volume in its own space, i.e. such that 7 | % the direction cosines are x, y and z 8 | % 9 | % SYNTAX: 10 | % [] = NIAK_BRICK_RESAMPLE_TO_SELF(FILE_NAME) 11 | % 12 | % _________________________________________________________________________ 13 | % INPUTS: 14 | % 15 | % FILE_NAME 16 | % (string) name of the file to resample (can be 3D+t). 17 | % 18 | % OPT 19 | % (structure) same as in NIAK_BRICK_RESAMPLE_VOL 20 | % 21 | % _________________________________________________________________________ 22 | % OUTPUTS: 23 | % 24 | % Overwrites the file with its resampled version. 25 | % 26 | % _________________________________________________________________________ 27 | % COMMENTS: 28 | % 29 | % This is a simple wrapper of MINCRESAMPLE and NIAK_BRICK_RESAMPLE_VOL. 30 | % 31 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, 32 | % Montreal Neurological Institute, McGill University, 2008. 33 | % Maintainer : pbellec@bic.mni.mcgill.ca 34 | % See licensing information in the code. 35 | % Keywords : medical imaging, minc 36 | 37 | % Permission is hereby granted, free of charge, to any person obtaining a copy 38 | % of this software and associated documentation files (the "Software"), to deal 39 | % in the Software without restriction, including without limitation the rights 40 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 41 | % copies of the Software, and to permit persons to whom the Software is 42 | % furnished to do so, subject to the following conditions: 43 | % 44 | % The above copyright notice and this permission notice shall be included in 45 | % all copies or substantial portions of the Software. 46 | % 47 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 51 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 52 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 53 | % THE SOFTWARE. 54 | 55 | if ~exist(file_name,'file') 56 | error(sprintf('I can''t find file %s',file_name)); 57 | end 58 | 59 | file_tmp = niak_file_tmp('_res.mnc'); 60 | files_in.source = file_name; 61 | files_in.target = file_name; 62 | files_out = file_tmp; 63 | 64 | opt.flag_tfm_space = 1; 65 | 66 | niak_brick_resample_vol(files_in,files_out,opt); 67 | [succ,msg] = system(cat(2,'mv ',file_tmp,' ',file_name)); 68 | if ~(succ==0) 69 | error(msg); 70 | end 71 | -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_exist.m: -------------------------------------------------------------------------------- 1 | function flag_exist = psom_exist(file_name) 2 | % A fast version of "exist" specific of files with full path names. 3 | % 4 | % SYNTAX: 5 | % FLAG_EXIST = PSOM_EXIST(FILE_NAME) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % FILE_NAME 11 | % (string) a file name with full path 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS: 15 | % 16 | % FLAG_EXIST 17 | % (integer) 1 if FILE_NAME is a file, 7 if it is a folder, 0 otherwise. 18 | % 19 | % _________________________________________________________________________ 20 | % COMMENTS: 21 | % 22 | % This is essentially the same as exist(FILE_NAME), restricted to files and 23 | % directories, but it is much faster when the search path is large. It will 24 | % only work for file names/folder names with full path though. 25 | % 26 | % _________________________________________________________________________ 27 | % Copyright (c) Pierre Bellec, Centre de recherche de l'institut de 28 | % geriatrie de Montreal, Departement d'informatique et recherche 29 | % operationnelle, Universite de Montreal, 2010. 30 | % Maintainer : pbellec@criugm.qc.ca 31 | % See licensing information in the code. 32 | % Keywords : pipeline, niak, preprocessing, fMRI, psom 33 | 34 | % Permission is hereby granted, free of charge, to any person obtaining a copy 35 | % of this software and associated documentation files (the "Software"), to deal 36 | % in the Software without restriction, including without limitation the rights 37 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 38 | % copies of the Software, and to permit persons to whom the Software is 39 | % furnished to do so, subject to the following conditions: 40 | % 41 | % The above copyright notice and this permission notice shall be included in 42 | % all copies or substantial portions of the Software. 43 | % 44 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 48 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 49 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 50 | % THE SOFTWARE. 51 | 52 | if size(file_name,1)>1 53 | flag_exist = true; 54 | for num_f = 1:size(file_name,1) 55 | flag_exist = flag_exist && psom_exist(deblank(file_name(num_f,:))); 56 | end 57 | return 58 | end 59 | 60 | hf = fopen(file_name,'r'); 61 | if hf == -1 62 | flag_exist = false; 63 | else 64 | fclose(hf); 65 | flag_exist = true; 66 | end 67 | if ~flag_exist 68 | flag_exist = exist(file_name,'dir'); 69 | end -------------------------------------------------------------------------------- /niak/commands/formats/niak_vec2mat.m: -------------------------------------------------------------------------------- 1 | function mat = niak_vec2mat(vec,val_diag); 2 | % Convert a vectorized symmetric matrix back into matrix form. 3 | % 4 | % SYNTAX: 5 | % MAT = NIAK_VEC2MAT(VEC,VAL_DIAG) 6 | % 7 | % _________________________________________________________________________ 8 | % 9 | % INPUTS: 10 | % 11 | % VEC 12 | % (vector) a vectorized version of a symmetric matrix (without 13 | % diagonal elements). 14 | % 15 | % VAL_DIAG 16 | % (scalar or vector, default 1) the value(s) to put on the diagonal. 17 | % 18 | % _________________________________________________________________________ 19 | % OUTPUTS: 20 | % 21 | % MAT 22 | % (array) a square matrix. MAT is symmetric. Diagonal elements are 23 | % one. 24 | % 25 | % _________________________________________________________________________ 26 | % SEE ALSO: 27 | % NIAK_MAT2VEC 28 | % 29 | % _________________________________________________________________________ 30 | % COMMENTS: 31 | % 32 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 33 | % Neurological Institute, McGill University, 2007. 34 | % Maintainer : pbellec@bic.mni.mcgill.ca 35 | % See licensing information in the code. 36 | % Keywords : 37 | 38 | % Permission is hereby granted, free of charge, to any person obtaining a copy 39 | % of this software and associated documentation files (the "Software"), to deal 40 | % in the Software without restriction, including without limitation the rights 41 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 42 | % copies of the Software, and to permit persons to whom the Software is 43 | % furnished to do so, subject to the following conditions: 44 | % 45 | % The above copyright notice and this permission notice shall be included in 46 | % all copies or substantial portions of the Software. 47 | % 48 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 54 | % THE SOFTWARE. 55 | if (size(vec,1)>1) && (size(vec,2)>1) 56 | nb_m = size(vec,2); 57 | for num_m = 1:nb_m 58 | mat_tmp = niak_vec2mat(vec(:,num_m)); 59 | if num_m == 1 60 | mat = zeros([size(mat_tmp) nb_m]); 61 | end 62 | mat(:,:,num_m) = mat_tmp; 63 | end 64 | return 65 | end 66 | 67 | if nargin < 2 68 | val_diag = 1; 69 | end 70 | 71 | M = length(vec); 72 | N = round((1+sqrt(1+8*M))/2); 73 | 74 | mat = zeros([N N]); 75 | mat(tril(true(N),-1)) = vec; 76 | mat = mat'; 77 | mat(tril(true(N),-1)) = vec; 78 | mat(eye(N)==1) = val_diag; 79 | -------------------------------------------------------------------------------- /niak/commands/formats/niak_hdr_minc2mat.m: -------------------------------------------------------------------------------- 1 | function [mat] = niak_hdr_minc2mat(direction_cosine,step,start) 2 | % Convert MINC cosines/start/step into an affine transformation. 3 | % 4 | % SYNTAX: 5 | % MAT = NIAK_HDR_MINC2MAT(DIRECTION_COSINE,STEP,START) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % DIRECTION_COSINES (array 3*3) gives you the direction assigned to the 11 | % respective dimensions of the voxel array. 12 | % 13 | % STEP (vector 3*1) the step made at each voxel dimension along the 14 | % DIRECTION_COSINES vector. 15 | % 16 | % START (vector 3*1) the starting value of each voxel dimension along the 17 | % DIRECTION_COSINES vector. 18 | % 19 | % _________________________________________________________________________ 20 | % OUTPUTS: 21 | % 22 | % MAT (4*4 array) An affine transformation, usually seen as a 23 | % "voxel-to-world" space transform. 24 | % 25 | % _________________________________________________________________________ 26 | % COMMENTS: 27 | % 28 | % This function is based on the description of MINC2 system of coordinates 29 | % that can be found at : 30 | % http://en.wikibooks.org/wiki/MINC/Reference/MINC2.0_File_Format_Reference#MINC_2.0_coordinate_system 31 | % 32 | % _________________________________________________________________________ 33 | % SEE ALSO: 34 | % NIAK_READ_HDR_MINC, NIAK_WRITE_MINC, NIAK_HDR_MAT2MINC 35 | % 36 | % Copyright (c) Pierre Bellec, McConnel Brain Imaging Center, Montreal 37 | % Neurological Institute, McGill University, Montreal, Canada. 38 | % Maintainer : pierre.bellec@criugm.qc.ca 39 | % See licensing information in the code. 40 | % Keywords : medical imaging, I/O, affine transformation, minc 41 | 42 | % Permission is hereby granted, free of charge, to any person obtaining a copy 43 | % of this software and associated documentation files (the "Software"), to deal 44 | % in the Software without restriction, including without limitation the rights 45 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 46 | % copies of the Software, and to permit persons to whom the Software is 47 | % furnished to do so, subject to the following conditions: 48 | % 49 | % The above copyright notice and this permission notice shall be included in 50 | % all copies or substantial portions of the Software. 51 | % 52 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 53 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 54 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 55 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 56 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 57 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 58 | % THE SOFTWARE. 59 | 60 | mat = eye(4); 61 | mat(1:3,1:3) = direction_cosine * (diag(step)); 62 | mat(1:3,4) = direction_cosine * start; -------------------------------------------------------------------------------- /niak/commands/formats/niak_find_str_cell.m: -------------------------------------------------------------------------------- 1 | function mask_f = niak_find_str_cell(cell_str,cell_str2) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_FIND_STR_CELL 5 | % 6 | % Test if one of many strings are substrings of another list of strings 7 | % 8 | % SYNTAX: 9 | % MASK_F = NIAK_FIND_STR_CELL(CELL_STR,CELL_STR2) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS: 13 | % 14 | % CELL_STR 15 | % (string or cell of strings) 16 | % 17 | % CELL_STR2 18 | % (string or cell of strings) 19 | % 20 | % _________________________________________________________________________ 21 | % OUTPUTS: 22 | % 23 | % MASK_F 24 | % (vector) MASK_F(i) equals 1 if CELL_STR{i} contains CELL_STR2{j} 25 | % for any j, 0 otherwise. If one argument is a simple string, it is 26 | % converted into a cell of string with one element. 27 | % 28 | % _________________________________________________________________________ 29 | % 30 | % SEE ALSO: 31 | % 32 | % NIAK_CMP_STR_CELL 33 | % 34 | % _________________________________________________________________________ 35 | % COMMENTS : 36 | % 37 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 38 | % Maintainer : pbellec@bic.mni.mcgill.ca 39 | % See licensing information in the code. 40 | % Keywords : string 41 | 42 | 43 | % Permission is hereby granted, free of charge, to any person obtaining a copy 44 | % of this software and associated documentation files (the "Software"), to deal 45 | % in the Software without restriction, including without limitation the rights 46 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 47 | % copies of the Software, and to permit persons to whom the Software is 48 | % furnished to do so, subject to the following conditions: 49 | % 50 | % The above copyright notice and this permission notice shall be included in 51 | % all copies or substantial portions of the Software. 52 | % 53 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 54 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 55 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 56 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 57 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 58 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 59 | % THE SOFTWARE. 60 | 61 | if ischar(cell_str) 62 | str2{1} = cell_str; 63 | cell_str = str2; 64 | clear str2 65 | end 66 | 67 | if ischar(cell_str2) 68 | str2{1} = cell_str2; 69 | cell_str2 = str2; 70 | clear str2 71 | end 72 | 73 | nb_e = length(cell_str); 74 | nb_f = length(cell_str2); 75 | mask_f = zeros([nb_e 1]); 76 | 77 | for num_e = 1:nb_e 78 | for num_f = 1:nb_f 79 | mask_f(num_e) = mask_f(num_e)|~isempty(findstr(cell_str{num_e},cell_str2{num_f})); 80 | end 81 | end 82 | 83 | mask_f = mask_f>0; -------------------------------------------------------------------------------- /niak/commands/formats/niak_get_minc_att.m: -------------------------------------------------------------------------------- 1 | function val = niak_get_minc_att(hdr,var_name,att_name); 2 | % Get the value of a the attribute of a minc variable from a minc header. 3 | % 4 | % SYNTAX: 5 | % VAL = NIAK_GET_MINC_ATT(HDR,VAR_NAME,ATT_NAME) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % HDR 11 | % (structure) a minc header (see NIAK_READ_HDR_MINC). 12 | % 13 | % VAR_NAME 14 | % (string) the name of a variable in the minc file. 15 | % 16 | % ATT_NAME 17 | % (string) the name of an attribute of the variable. 18 | % 19 | % _________________________________________________________________________ 20 | % OUTPUTS: 21 | % 22 | % VAL 23 | % The value of the selected attribute of the selected variable. 24 | % 25 | % _________________________________________________________________________ 26 | % SEE ALSO: 27 | % 28 | % _________________________________________________________________________ 29 | % COMMENTS: 30 | % 31 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 32 | % Neurological Institute, McGill University, 2007. 33 | % Maintainer : pbellec@bic.mni.mcgill.ca 34 | % See licensing information in the code. 35 | % Keywords : 36 | 37 | % Permission is hereby granted, free of charge, to any person obtaining a copy 38 | % of this software and associated documentation files (the "Software"), to deal 39 | % in the Software without restriction, including without limitation the rights 40 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 41 | % copies of the Software, and to permit persons to whom the Software is 42 | % furnished to do so, subject to the following conditions: 43 | % 44 | % The above copyright notice and this permission notice shall be included in 45 | % all copies or substantial portions of the Software. 46 | % 47 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 51 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 52 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 53 | % THE SOFTWARE. 54 | 55 | if ~exist('hdr','var')|~exist('var_name','var')|~exist('att_name','var') 56 | error('niak:commands','syntax: VAL = NIAK_GET_MINC_ATT(HDR,VAR_NAME,ATT_NAME).\n Type ''help niak_get_minc_att'' for more info.') 57 | end 58 | 59 | if ~isstruct(hdr) 60 | error('HDR should be a structure'); 61 | end 62 | 63 | try 64 | var_data = hdr.details.(var_name); 65 | catch 66 | error('I could not find the variable %s in HDR',var_name); 67 | end 68 | 69 | ind = find(ismember(var_data.varatts,att_name),1); 70 | 71 | if isempty(ind) 72 | error('I could not find the attribute %s in the variable %s',att_name,var_name); 73 | end 74 | 75 | val = var_data.attvalue{ind}; -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_find_str_cell.m: -------------------------------------------------------------------------------- 1 | function mask_f = psom_find_str_cell(cell_str,cell_str2) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY PSOM_FIND_STR_CELL 5 | % 6 | % Test if one of many strings are substrings of another list of strings 7 | % 8 | % SYNTAX: 9 | % MASK_F = PSOM_FIND_STR_CELL(CELL_STR,CELL_STR2) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS: 13 | % 14 | % CELL_STR 15 | % (string or cell of strings) 16 | % 17 | % CELL_STR2 18 | % (string or cell of strings) 19 | % 20 | % _________________________________________________________________________ 21 | % OUTPUTS: 22 | % 23 | % MASK_F 24 | % (vector) MASK_F(i) equals 1 if CELL_STR{i} contains CELL_STR2{j} 25 | % for any j, 0 otherwise. If one argument is a simple string, it is 26 | % converted into a cell of string with one element. 27 | % 28 | % _________________________________________________________________________ 29 | % 30 | % SEE ALSO: 31 | % 32 | % PSOM_CMP_STR_CELL 33 | % 34 | % _________________________________________________________________________ 35 | % COMMENTS : 36 | % 37 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 38 | % Maintainer : pbellec@bic.mni.mcgill.ca 39 | % See licensing information in the code. 40 | % Keywords : string 41 | 42 | 43 | % Permission is hereby granted, free of charge, to any person obtaining a copy 44 | % of this software and associated documentation files (the "Software"), to deal 45 | % in the Software without restriction, including without limitation the rights 46 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 47 | % copies of the Software, and to permit persons to whom the Software is 48 | % furnished to do so, subject to the following conditions: 49 | % 50 | % The above copyright notice and this permission notice shall be included in 51 | % all copies or substantial portions of the Software. 52 | % 53 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 54 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 55 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 56 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 57 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 58 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 59 | % THE SOFTWARE. 60 | 61 | if ischar(cell_str) 62 | str2{1} = cell_str; 63 | cell_str = str2; 64 | clear str2 65 | end 66 | 67 | if ischar(cell_str2) 68 | str2{1} = cell_str2; 69 | cell_str2 = str2; 70 | clear str2 71 | end 72 | 73 | nb_e = length(cell_str); 74 | nb_f = length(cell_str2); 75 | mask_f = zeros([nb_e 1]); 76 | 77 | for num_e = 1:nb_e 78 | for num_f = 1:nb_f 79 | mask_f(num_e) = mask_f(num_e)|~isempty(findstr(cell_str{num_e},cell_str2{num_f})); 80 | end 81 | end 82 | 83 | mask_f = mask_f>0; -------------------------------------------------------------------------------- /niak/commands/misc/niak_version.m: -------------------------------------------------------------------------------- 1 | function versions = niak_version() 2 | % Is a wraper of psom_version_svn and provide release number of psom and niak. 3 | % 4 | % SYNTAX : 5 | % VERSIONS = NIAK_VERSION() 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS : 9 | % 10 | % 11 | % _________________________________________________________________________ 12 | % OUTPUTS: 13 | % 14 | % VERSIONS 15 | % (structure) SVN.NAME Name of the svn lib. 16 | % SVN.VERSION version number of the lib. 17 | % SVN.PATH path of the svn root lib. 18 | % SVN.INFO information from the function svnversion. 19 | % 20 | % RELEASE.NAME name of the lib. 21 | % RELEASE.RELEASE release number. 22 | % 23 | % _________________________________________________________________________ 24 | % COMMENTS : 25 | % 26 | % 27 | % Copyright (c) Christian L. Dansereau, Centre de recherche de l'Institut universitaire de gériatrie de Montréal, 2011. 28 | % Maintainer : pbellec@bic.mni.mcgill.ca 29 | % See licensing information in the code. 30 | % Keywords : svn,release,version 31 | 32 | % Permission is hereby granted, free of charge, to any person obtaining a copy 33 | % of this software and associated documentation files (the "Software"), to deal 34 | % in the Software without restriction, including without limitation the rights 35 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 36 | % copies of the Software, and to permit persons to whom the Software is 37 | % furnished to do so, subject to the following conditions: 38 | % 39 | % The above copyright notice and this permission notice shall be included in 40 | % all copies or substantial portions of the Software. 41 | % 42 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 43 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 44 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 45 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 46 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 47 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 48 | % THE SOFTWARE. 49 | 50 | 51 | %%%%%%%%%%%%%%%%% 52 | %% SVN %% 53 | %%%%%%%%%%%%%%%%% 54 | 55 | versions.svn = psom_version_svn(); 56 | 57 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 58 | %% Release number %% 59 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% 60 | 61 | k=0; 62 | % Look for the PSOM version release 63 | if exist('psom_gb_vars') == 2 64 | k=k+1; 65 | psom_gb_vars; 66 | versions.release(k).name = 'psom'; 67 | versions.release(k).release = gb_psom_version; 68 | end 69 | 70 | % Look for the NIAK version release 71 | if exist('niak_gb_vars') == 2 72 | k=k+1; 73 | niak_gb_vars; 74 | versions.release(k).name = 'niak'; 75 | versions.release(k).release = gb_niak_version; 76 | end 77 | 78 | 79 | end 80 | -------------------------------------------------------------------------------- /niak/commands/formats/niak_part2mat.m: -------------------------------------------------------------------------------- 1 | function mat = niak_part2mat(part,flag_binary); 2 | % Convert a vector partition of integer lables into an adjacency matrix. 3 | % 4 | % SYNTAX: 5 | % MAT = NIAK_PART2MAT(PART,FLAG_BINARY) 6 | % 7 | % _________________________________________________________________________ 8 | % 9 | % INPUTS: 10 | % 11 | % PART 12 | % (vector) PART(i) is the number of the cluster of region i. 13 | % 14 | % FLAG_BINARY 15 | % (boolean, default false) if FLAG_BINARY is true, the output will be a 16 | % binary matrix. 17 | % 18 | % _________________________________________________________________________ 19 | % OUTPUTS: 20 | % 21 | % MAT 22 | % (array) a square matrix. MAT(I,J) equals K (or 1 if FLAG_BINARY) 23 | % if regions I and J are together in cluster K, and zero otherwise. 24 | % 25 | % _________________________________________________________________________ 26 | % SEE ALSO: 27 | % 28 | % _________________________________________________________________________ 29 | % COMMENTS: 30 | % 31 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, Montreal 32 | % Neurological Institute, McGill University, 2007-2010. 33 | % Centre de recherche de l'institut de gériatrie de Montréal, 34 | % Département d'informatique et de recherches opérationnelles, 35 | % Université de Montréal, 2010. 36 | % Maintainer : pbellec@bic.mni.mcgill.ca 37 | % See licensing information in the code. 38 | % Keywords : partition, adjacency 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | 58 | if nargin<2 59 | flag_binary = false; 60 | end 61 | nb_rois = length(part); 62 | mat = zeros([nb_rois nb_rois]); 63 | list_clusters = unique(part); 64 | list_clusters = list_clusters(list_clusters~=0); 65 | list_clusters = list_clusters(:)'; 66 | 67 | for num_c = list_clusters 68 | if flag_binary 69 | mat(part==num_c,part==num_c) = 1; 70 | else 71 | mat(part==num_c,part==num_c) = num_c; 72 | end 73 | end -------------------------------------------------------------------------------- /niak/commands/read_write/niak_write_transf.m: -------------------------------------------------------------------------------- 1 | function flag = niak_write_transf(transf,file_name) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_WRITE_TRANSF 5 | % 6 | % Save a lsq12 transformation matrix into an xfm file 7 | % 8 | % _________________________________________________________________________ 9 | % SYNTAX 10 | % 11 | % [FLAG,MSG] = NIAK_WRITE_TRANSF(TRANSF,FILE_NAME) 12 | % 13 | % _________________________________________________________________________ 14 | % INPUTS 15 | % 16 | % TRANSF 17 | % (matrix 4*4) a classical matrix representation of an lsq12 18 | % transformation. 19 | % 20 | % FILE_NAME 21 | % (string) the name of the xfm file (usually ends in .xfm) 22 | % 23 | % _________________________________________________________________________ 24 | % OUTPUTS 25 | % 26 | % FLAG 27 | % (real number) if FLAG == -1, an error occured 28 | % 29 | % _________________________________________________________________________ 30 | % SEE ALSO 31 | % NIAK_PARAM2TRANSF, NIAK_TRANSF2PARAM, NIAK_READ_TRANSF 32 | % 33 | % _________________________________________________________________________ 34 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 35 | % Maintainer : pbellec@bic.mni.mcgill.ca 36 | % See licensing information in the code. 37 | % Keywords : xfm, minc 38 | 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | 58 | niak_gb_vars 59 | 60 | hf = fopen(file_name,'w'); 61 | if hf == -1 62 | flag = -1; 63 | error('could not create file %s',file_name) 64 | else 65 | flag = 1; 66 | end 67 | 68 | fprintf(hf,'MNI Transform File\n'); 69 | fprintf(hf,'%%Created using NIAK v.%s, %s, by %s\n',gb_niak_version,datestr(now),gb_niak_user) ; 70 | fprintf(hf,'\nTransform_Type = Linear;\nLinear_Transform =\n'); 71 | fprintf(hf,'%s\n',num2str(transf(1,:),15)); 72 | fprintf(hf,'%s\n',num2str(transf(2,:),15)); 73 | fprintf(hf,'%s;\n',num2str(transf(3,:),15)); 74 | 75 | fclose(hf); 76 | -------------------------------------------------------------------------------- /niak/commands/read_write/niak_read_tags.m: -------------------------------------------------------------------------------- 1 | function [coord,labels] = niak_read_tags(file_name) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY NIAK_READ_TAGS 5 | % 6 | % Read coordinates in a tag file. 7 | % 8 | % SYNTAX: 9 | % [COORD,LABELS] = NIAK_READ_TAB(FILE_NAME) 10 | % 11 | % _________________________________________________________________________ 12 | % INPUTS: 13 | % 14 | % FILE_NAME 15 | % (string) the name of a (text) tag file. 16 | % 17 | % _________________________________________________________________________ 18 | % OUTPUTS: 19 | % 20 | % COORD 21 | % (matrix N*3) COORD(I,:) is the 3D-coordinates of the I point in the 22 | % tag file. 23 | % 24 | % LABELS 25 | % (cell of string) LABELS{I} is the label of the Ith tag. 26 | % 27 | % _________________________________________________________________________ 28 | % SEE ALSO: 29 | % 30 | % _________________________________________________________________________ 31 | % COMMENTS: 32 | % 33 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 34 | % Maintainer : pbellec@bic.mni.mcgill.ca 35 | % See licensing information in the code. 36 | % Keywords : xfm, minc 37 | 38 | 39 | % Permission is hereby granted, free of charge, to any person obtaining a copy 40 | % of this software and associated documentation files (the "Software"), to deal 41 | % in the Software without restriction, including without limitation the rights 42 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 43 | % copies of the Software, and to permit persons to whom the Software is 44 | % furnished to do so, subject to the following conditions: 45 | % 46 | % The above copyright notice and this permission notice shall be included in 47 | % all copies or substantial portions of the Software. 48 | % 49 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 50 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 51 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 52 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 53 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 54 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 55 | % THE SOFTWARE. 56 | 57 | if ~exist('file_name','var') 58 | error('Syntax : [COORD,LABELS] = NIAK_READ_TAB(FILE_NAME). Type ''help niak_read_tags'' for more infos.') 59 | end 60 | 61 | if ~exist(file_name,'file') 62 | error(cat(2,'Could not find any file matching the description ',file_name)); 63 | end 64 | 65 | hf = fopen(file_name); 66 | tab = fread(hf, Inf, 'uint8=>char')'; 67 | fclose(hf); 68 | 69 | tab = niak_string2lines(tab); 70 | tab = tab(5:end); 71 | 72 | coord = zeros([length(tab) 3]); 73 | labels = cell([length(tab) 1]); 74 | 75 | for num_l = 1:length(tab) 76 | line_tab = niak_string2words(tab{num_l}); 77 | coord(num_l,:) = str2num(char(line_tab(1:3))); 78 | ind_num = findstr(tab{num_l},'"'); 79 | labels{num_l} = tab{num_l}(ind_num(1)+1:ind_num(2)-1); 80 | end -------------------------------------------------------------------------------- /niak/commands/formats/niak_part2vol.m: -------------------------------------------------------------------------------- 1 | function vol = niak_part2vol(part,mask); 2 | % Convert a partition of N individual regions into 3D maps of clusters. 3 | % 4 | % SYNTAX: 5 | % VOL = NIAK_PART2VOL(PART,MASK) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % PART 11 | % (vector) PART(I) is the number of the cluster of region I. 12 | % 13 | % MASK 14 | % (3D volume) MASK==I is a binary mask of region I. 15 | % 16 | % _________________________________________________________________________ 17 | % OUTPUTS: 18 | % 19 | % VOL 20 | % (3D volume) VOL==K is a binary mask of the Kth cluster. 21 | % 22 | % _________________________________________________________________________ 23 | % COMMENTS: 24 | % 25 | % This function will work with any vector of scalar values PART. This means 26 | % that in MASK, region K will be replaced by the values found in PART(K) 27 | % whatever that value is, integer or scalar. 28 | % 29 | % PART have multiple rows and columns. In this case, VOL will be a 4D array 30 | % where each volume will correspond to one row of PART. (Think as colums of 31 | % PART as time series and VOL as a 3D+t dataset). 32 | % 33 | % Copyright (c) Pierre Bellec 34 | % McConnell Brain Imaging Center, Montreal 35 | % Neurological Institute, McGill University, 2007-2011. 36 | % Centre de recherche de l'institut de Gériatrie de Montréal, 37 | % Département d'informatique et de recherche opérationnelle, 38 | % Université de Montréal, 2011-2012. 39 | % Maintainer : pierre.bellec@criugm.qc.ca 40 | % See licensing information in the code. 41 | % Keywords : partition, roi 42 | 43 | % Permission is hereby granted, free of charge, to any person obtaining a copy 44 | % of this software and associated documentation files (the "Software"), to deal 45 | % in the Software without restriction, including without limitation the rights 46 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 47 | % copies of the Software, and to permit persons to whom the Software is 48 | % furnished to do so, subject to the following conditions: 49 | % 50 | % The above copyright notice and this permission notice shall be included in 51 | % all copies or substantial portions of the Software. 52 | % 53 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 54 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 55 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 56 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 57 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 58 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 59 | % THE SOFTWARE. 60 | if size(part,1)>1 && size(part,2)>1 61 | vol = zeros([size(mask) size(part,1)]); 62 | for num_v = 1:size(part,1) 63 | vol_tmp = zeros(size(mask)); 64 | vol_tmp(mask>0) = part(num_v,mask(mask>0)); 65 | vol(:,:,:,num_v) = vol_tmp; 66 | end 67 | else 68 | vol = zeros(size(mask)); 69 | vol(mask>0) = part(mask(mask>0)); 70 | end 71 | -------------------------------------------------------------------------------- /niak/commands/SI_processing/niak_compcor_mask.m: -------------------------------------------------------------------------------- 1 | function mask = niak_compcor_mask(vol,perc,method); 2 | % Compute the 't' mask of the compcor method (based on temporal standard deviation) 3 | % 4 | % SYNTAX: 5 | % MASK = NIAK_COMPCOR_MASK( VOL , [PERC] , [METHOD] ) 6 | % 7 | % INPUTS: 8 | % VOL (3D+t array) an fMRI dataset 9 | % PERC (scalar, default 0.02) the proportion of voxels considered to have a 10 | % "high" standard deviation (in time). 11 | % METHOD (string, default 'slice') how to define "high" standard deviation. 12 | % 'slice': top PERC of voxels per slice 13 | % 'global': top PERC of voxels globally 14 | % 15 | % OUTPUTS 16 | % MASK (3D array) a binary mask of high standard deviation voxels 17 | % 18 | % REFERENCE 19 | % Behzadi, Y., Restom, K., Liau, J., Liu, T. T., Aug. 2007. A component based 20 | % noise correction method (CompCor) for BOLD and perfusion based fMRI. 21 | % NeuroImage 37 (1), 90-101. http://dx.doi.org/10.1016/j.neuroimage.2007.04.042 22 | % 23 | % Copyright (c) Pierre Bellec, 24 | % Centre de recherche de l'institut de 25 | % Gériatrie de Montréal, Département d'informatique et de recherche 26 | % opérationnelle, Université de Montréal, 2013 27 | % Maintainer : pierre.bellec@criugm.qc.ca 28 | % See licensing information in the code. 29 | % Keywords : fMRI, noise, compcor 30 | 31 | % Permission is hereby granted, free of charge, to any person obtaining a copy 32 | % of this software and associated documentation files (the "Software"), to deal 33 | % in the Software without restriction, including without limitation the rights 34 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 35 | % copies of the Software, and to permit persons to whom the Software is 36 | % furnished to do so, subject to the following conditions: 37 | % 38 | % The above copyright notice and this permission notice shall be included in 39 | % all copies or substantial portions of the Software. 40 | % 41 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 46 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 47 | % THE SOFTWARE. 48 | if nargin < 2 49 | perc = 0.02; 50 | end 51 | if nargin < 3 52 | method = 'slice'; 53 | end 54 | std_vol = std(vol,[],4); 55 | [nx,ny,nz,nt] = size(vol); 56 | switch method 57 | case 'slice' 58 | mask = false([nx ny nz]); 59 | for iz = 1:nz % loop over slices 60 | slice = std_vol(:,:,iz); 61 | val = sort(slice(:),'descend'); 62 | mask(:,:,iz) = std_vol(:,:,iz)>= val(floor(perc*length(val))); 63 | end 64 | case 'global' 65 | val = sort(std_vol(:),'descend'); 66 | mask = std_vol >= val(floor(perc*length(val))); 67 | otherwise 68 | error('%s is an unknown method',method) 69 | end -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_struct_cell_string2char.m: -------------------------------------------------------------------------------- 1 | function [char_array,ind_fields] = psom_struct_cell_string2char(scs) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY PSOM_STRUCT_CELL_STRING2CHAR 5 | % 6 | % Convert a structure where each field is a cell of strings into a char 7 | % array and an index making the correspondance between each entry of the 8 | % array and a field of the structure. 9 | % 10 | % SYNTAX : 11 | % [CHAR_ARRAY,IND_FIELDS] = PSOM_STRUCT_CELL_STRING2CHAR(SCS) 12 | % 13 | % _________________________________________________________________________ 14 | % INPUTS : 15 | % 16 | % SCS 17 | % (structure) all fields are cell of strings. 18 | % 19 | % _________________________________________________________________________ 20 | % OUTPUTS : 21 | % 22 | % CHAR_ARRAY 23 | % (string array) CHAR_ARRAY(I,:) is one of the string in SCS, padded 24 | % with spaces to reach the length of the longest string. 25 | % 26 | % IND_FIELDS 27 | % (vector) if FIELDS is the list of field names in SCS, 28 | % CHAR_ARRAY(I,:) comes from the field FIELDS{IND_FIELDS(I)}. 29 | % 30 | % _________________________________________________________________________ 31 | % COMMENTS : 32 | % 33 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 34 | % Maintainer : pbellec@bic.mni.mcgill.ca 35 | % See licensing information in the code. 36 | % Keywords : string 37 | 38 | % Permission is hereby granted, free of charge, to any person obtaining a copy 39 | % of this software and associated documentation files (the "Software"), to deal 40 | % in the Software without restriction, including without limitation the rights 41 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 42 | % copies of the Software, and to permit persons to whom the Software is 43 | % furnished to do so, subject to the following conditions: 44 | % 45 | % The above copyright notice and this permission notice shall be included in 46 | % all copies or substantial portions of the Software. 47 | % 48 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 49 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 50 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 51 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 52 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 53 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 54 | % THE SOFTWARE. 55 | 56 | list_fields = fieldnames(scs); 57 | 58 | nb_str = 0; 59 | 60 | for num_f = 1:length(list_fields) 61 | nb_str = nb_str + length(scs.(list_fields{num_f})); 62 | end 63 | 64 | ind_fields = zeros([nb_str 1]); 65 | char_array = cell([nb_str 1]); 66 | num_e = 1; 67 | 68 | for num_f = 1:length(list_fields) 69 | ind_fields(num_e:(length(scs.(list_fields{num_f}))+num_e-1)) = num_f; 70 | 71 | for num_s = 1:length(scs.(list_fields{num_f})) 72 | char_array{num_e} = scs.(list_fields{num_f}){num_s}; 73 | num_e = num_e + 1; 74 | end 75 | 76 | end 77 | char_array = char(char_array); -------------------------------------------------------------------------------- /niak/commands/formats/niak_scales2mat.m: -------------------------------------------------------------------------------- 1 | function scales_mat = niak_scales2mat(scales,neigh); 2 | % Convert a list of scales into an array scales*(neighbourhood of scales) 3 | % 4 | % SYNTAX: 5 | % SCALES_MAT = NIAK_SCALES2MAT(SCALES,NEIGH) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % SCALES 11 | % (vector) a list of integers 12 | % 13 | % NEIGH 14 | % (vector 1*3, default [0.7 0.1 1.3] percentage that define the 15 | % neighbourhood of a scale. 16 | % 17 | % _________________________________________________________________________ 18 | % OUTPUTS: 19 | % 20 | % SCALES_MAT 21 | % (array) For each row, SCALES_MAT(I,2) is a scale and SCALES_MAT(I,1) a 22 | % neighbour of this scale. All possible pairs of scales/neighbours are 23 | % listed. 24 | % 25 | % _________________________________________________________________________ 26 | % SEE ALSO: 27 | % NIAK_SCALES2CELL 28 | % 29 | % _________________________________________________________________________ 30 | % COMMENTS: 31 | % 32 | % Copyright (c) Pierre Bellec 33 | % Centre de recherche de l'institut de Gériatrie de Montréal 34 | % Département d'informatique et de recherche opérationnelle 35 | % Université de Montréal, 2010 36 | % Maintainer : pbellec@criugm.qc.ca 37 | % See licensing information in the code. 38 | % Keywords : 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | 58 | if nargin < 2 59 | neigh = [0.7 0.1 1.3]; 60 | end 61 | nb_points = 0; 62 | scales2 = cell([length(scales) 1]); 63 | for num_s = 1:length(scales) 64 | scales2{num_s} = unique(ceil(scales(num_s)*(neigh(1):neigh(2):neigh(3)))); 65 | nb_points = nb_points + length(scales2{num_s}); 66 | end 67 | 68 | num_p = 0; 69 | scales_mat = zeros([nb_points 2]); 70 | for num_s = 1:length(scales) 71 | for num_g = 1:length(scales2{num_s}) 72 | scales_mat(num_p+1:num_p+length(scales2{num_s}),1) = scales(num_s); 73 | scales_mat(num_p+1:num_p+length(scales2{num_s}),2) = scales2{num_s}; 74 | end 75 | num_p = num_p+length(scales2{num_s}); 76 | end 77 | -------------------------------------------------------------------------------- /niak/commands/SI_processing/niak_find_local_max_1d.m: -------------------------------------------------------------------------------- 1 | function [val,ind] = niak_find_local_max_1d(x,sig,neigh) 2 | % Find local max in a 1D signal. 3 | % Temporal neighbourhood is defined through a symmetric time window. 4 | % 5 | % SYNTAX: 6 | % [VAL,IND] = NIAK_FIND_LOCAL_MAX_1D(X,SIG,NEIGH) 7 | % 8 | % _________________________________________________________________________ 9 | % INPUTS: 10 | % 11 | % X 12 | % (vector) measure SIG(N) corresponds to absciss X(N). 13 | % 14 | % SIG 15 | % (vector, size T*1) a time series, or at least a series of 16 | % observation where proximity in the order list makes sense to define 17 | % a neighbourhood 18 | % 19 | % NEIGH 20 | % (vector, default [0.7 1.3]) defines the local neighbourhood of 21 | % a number of clusters. 22 | % 23 | % _________________________________________________________________________ 24 | % OUTPUTS : 25 | % 26 | % VAL 27 | % (vector) The values of the local max. 28 | % 29 | % IND 30 | % (vector) the index of the local max in SIG. 31 | % 32 | % _________________________________________________________________________ 33 | % SEE ALSO: 34 | % 35 | % _________________________________________________________________________ 36 | % COMMENTS: 37 | % 38 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center,Montreal 39 | % Neurological Institute, McGill University, 2008. 40 | % Maintainer : pbellec@bic.mni.mcgill.ca 41 | % See licensing information in the code. 42 | % Keywords : clustering, stability, bootstrap 43 | 44 | % Permission is hereby granted, free of charge, to any person obtaining a copy 45 | % of this software and associated documentation files (the "Software"), to deal 46 | % in the Software without restriction, including without limitation the rights 47 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 48 | % copies of the Software, and to permit persons to whom the Software is 49 | % furnished to do so, subject to the following conditions: 50 | % 51 | % The above copyright notice and this permission notice shall be included in 52 | % all copies or substantial portions of the Software. 53 | % 54 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 55 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 56 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 57 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 58 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 59 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 60 | % THE SOFTWARE. 61 | 62 | if nargin < 3 63 | neigh = [0.7,1.3]; 64 | end 65 | 66 | if length(neigh)>1 67 | neigh = neigh([1 end]); 68 | end 69 | nt = length(sig); 70 | 71 | val = []; 72 | ind = []; 73 | 74 | for num_t = 1:length(sig) 75 | mask_low = x >= floor(neigh(1)*x(num_t)); 76 | mask_up = x <= ceil(neigh(2)*x(num_t)); 77 | mask = mask_low & mask_up; 78 | mask(num_t) = false; 79 | if any(mask)&&(~any(sig(num_t) < sig(mask))) 80 | 81 | val = [val ; sig(num_t)]; 82 | ind = [ind ; num_t]; 83 | 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /niak/commands/formats/niak_param2transf.m: -------------------------------------------------------------------------------- 1 | function transf = niak_param2transf(rot,tsl) 2 | % Convert rotation and translation parameters to a standard 3 | % 4*4 matrix array (y=M*x+T). 4 | % 5 | % SYNTAX: 6 | % TRANSF = NIAK_PARAM2TRANSF(ROT,TSL) 7 | % 8 | % _________________________________________________________________________ 9 | % INPUTS: 10 | % 11 | % ROT 12 | % (array 3*1) the rotation parameters (in x, y and z planes). 13 | % Unit is degrees. 14 | % 15 | % TSL 16 | % (array 3*1) the translation parameters. 17 | % 18 | % _________________________________________________________________________ 19 | % OUTPUTS: 20 | % 21 | % TRANSF (4*4 array) An lsq6 transformation, usually seen as a 22 | % "voxel-to-world" space transform. 23 | % 24 | % _________________________________________________________________________ 25 | % COMMENTS: 26 | % 27 | % This code was written by Giampiero Campa, 28 | % PhD, Research Assistant Professor 29 | % West Virginia University, Aerospace Engineering Dept. 30 | % Morgantown, WV, 26506-6106, USA, Copyright 1/11/96 31 | % See 32 | % http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=956&objectType=File 33 | % 34 | % Modified by Pierre Bellec, McConnel Brain Imaging Center, Montreal 35 | % Neurological Institute, McGill University, Montreal, Canada, 2008. 36 | % Changing inputs/outputs formats. 37 | % Maintainer : pbellec@bic.mni.mcgill.ca 38 | % See licensing information in the code. 39 | % Keywords : rigid-body transformation, rotation, Euler angles 40 | % 41 | % See licensing information in the code 42 | 43 | % Permission is hereby granted, free of charge, to any person obtaining a copy 44 | % of this software and associated documentation files (the "Software"), to deal 45 | % in the Software without restriction, including without limitation the rights 46 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 47 | % copies of the Software, and to permit persons to whom the Software is 48 | % furnished to do so, subject to the following conditions: 49 | % 50 | % The above copyright notice and this permission notice shall be included in 51 | % all copies or substantial portions of the Software. 52 | % 53 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 54 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 55 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 56 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 57 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 58 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 59 | % THE SOFTWARE. 60 | 61 | O=tsl; 62 | r=(rot(1)/180)*pi; 63 | p=(rot(2)/180)*pi; 64 | y=(rot(3)/180)*pi; 65 | 66 | R=expm(vp([0 0 1]',y))*expm(vp([0 1 0]',p))*expm(vp([1 0 0]',r)); 67 | 68 | transf=[ R, O(:); 0 0 0 1 ]; 69 | 70 | function z=vp(x,y) 71 | 72 | % z=vp(x,y); z = 3d cross product of x and y 73 | % vp(x) is the 3d cross product matrix : vp(x)*y=vp(x,y). 74 | % 75 | % by Giampiero Campa. 76 | 77 | z=[ 0 -x(3) x(2); 78 | x(3) 0 -x(1); 79 | -x(2) x(1) 0 ]; 80 | 81 | if nargin>1, z=z*y; end 82 | -------------------------------------------------------------------------------- /niak/commands/SI_processing/niak_build_adjacency.m: -------------------------------------------------------------------------------- 1 | function adj = niak_build_adjacency(mask,neig) 2 | % Compute the adjacency matrix of voxels within a region of interest in a 3 | % 3D volume. 4 | % 5 | % SYNTAX : 6 | % ADJ = NIAK_BUILD_ADJACENCY(MASK,NEIG) 7 | % 8 | % _________________________________________________________________________ 9 | % INPUTS : 10 | % 11 | % MASK 12 | % (3D array) binary mask of one 3D-region of interest (1s inside, 13 | % 0s outside) 14 | % 15 | % NEIG 16 | % (integer value, default 26) definition of 3D-connexity (possible 17 | % value 6,26) 18 | % 19 | % _________________________________________________________________________ 20 | % OUTPUTS : 21 | % 22 | % ADJ 23 | % (2D array) adjacency matrix of voxels inside the mask. Order of the 24 | % voxels is given by FIND(MASK(:)) 25 | % 26 | % _________________________________________________________________________ 27 | % COMMENTS : 28 | % 29 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center,Montreal 30 | % Neurological Institute, McGill University, 2008. 31 | % Maintainer : pbellec@bic.mni.mcgill.ca 32 | % See licensing information in the code. 33 | % Keywords : adjacency matrix, connexity,graph 34 | 35 | nb_regions = max(mask(:)); % Number of regions 36 | 37 | %% Default inputs 38 | if nargin < 2 39 | neig = 26; 40 | end 41 | 42 | %% Find linear indices and 3D coordinates of voxels in the mask 43 | I = find(mask(:)); 44 | N = length(I); 45 | [nx,ny,nz] = size(mask); 46 | [coordx,coordy,coordz] = ind2sub(size(mask),I); 47 | coord = [coordx,coordy,coordz]; 48 | 49 | %% Generation of the neighborhood matrix 50 | if neig == 26 51 | dec = [0,1,-1]; 52 | num = 1; 53 | for i = 1:3 54 | for j = 1:3 55 | for k = 1:3 56 | decxyz(num,:) = [dec(i),dec(j),dec(k)]; 57 | num = num + 1; 58 | end 59 | end 60 | end 61 | decxyz = decxyz(2:27,:); 62 | elseif neig == 6 63 | decxyz = [1 0 0;-1 0 0; 0 1 0; 0 -1 0; 0 0 1; 0 0 -1]; 64 | end 65 | 66 | long_neig = length(decxyz); 67 | 68 | %% V is a vector with N 1, then N 2, ..., N N 69 | v = 1/length(decxyz):1/length(decxyz):N; 70 | v = ceil(v); 71 | 72 | %% Generating the matrix of neighbors 73 | neigx = ones([long_neig 1])*coord(:,1)' + decxyz(:,1)*ones([1 N]); 74 | neigy = ones([long_neig 1])*coord(:,2)' + decxyz(:,2)*ones([1 N]); 75 | neigz = ones([long_neig 1])*coord(:,3)' + decxyz(:,3)*ones([1 N]); 76 | neig = [neigx(:) neigy(:) neigz(:)]; 77 | 78 | %% Get rid of the neighbors outside the volume 79 | in_vol = (neigx(:)>0)&(neigx(:)<=nx)&(neigy(:)>0)&(neigy(:)<=ny)&(neigz(:)>0)&(neigz(:)<=nz); 80 | garde = in_vol; 81 | garde(in_vol) = mask(sub2ind(size(mask),neigx(in_vol),neigy(in_vol),neigz(in_vol))); 82 | 83 | % Generation of the adjacency matrix 84 | I1 = I(v); 85 | I2 = sub2ind(size(mask),neig(garde,1),neig(garde,2),neig(garde,3)); 86 | I1 = I1(garde); 87 | diagx = (1:nx*ny*nz)'; 88 | I1 = [diagx;I1]; 89 | if ~isempty(I2) 90 | I2 = [diagx;I2]; 91 | adj = sparse(I1,I2,ones(size(I1)),nx*ny*nz,nx*ny*nz); 92 | adj = logical(adj); 93 | adj = adj(I,I); 94 | else 95 | adj = sparse(length(I),length(I)); 96 | adj = logical(adj); 97 | end -------------------------------------------------------------------------------- /niak/commands/formats/niak_full_path.m: -------------------------------------------------------------------------------- 1 | function path_name_f = niak_full_path(path_name) 2 | % convert a path name (either relative or absolute) into a full path name 3 | % 4 | % SYNTAX: 5 | % PATH_NAME_F = NIAK_FULL_PATH(PATH_NAME) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % PATH_NAME 11 | % (string, default pwd) a relative or absolute path name. 12 | % 13 | % _________________________________________________________________________ 14 | % OUTPUTS: 15 | % 16 | % PATH_NAME_F 17 | % (string) same as PATH_NAME, but in a absolute form and with a 18 | % filesep appended at the end. 19 | % 20 | % _________________________________________________________________________ 21 | % COMMENTS: 22 | % 23 | % Copyright (c) Pierre Bellec, 24 | % Centre de recherche de l'institut de Gériatrie de Montréal, 25 | % Département d'informatique et de recherche opérationnelle, 26 | % Université de Montréal, 2012. 27 | % Maintainer : pierre.bellec@criugm.qc.ca 28 | % See licensing information in the code. 29 | % Keywords : 30 | 31 | % Permission is hereby granted, free of charge, to any person obtaining a copy 32 | % of this software and associated documentation files (the "Software"), to deal 33 | % in the Software without restriction, including without limitation the rights 34 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 35 | % copies of the Software, and to permit persons to whom the Software is 36 | % furnished to do so, subject to the following conditions: 37 | % 38 | % The above copyright notice and this permission notice shall be included in 39 | % all copies or substantial portions of the Software. 40 | % 41 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 42 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 43 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 44 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 45 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 46 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 47 | % THE SOFTWARE. 48 | 49 | if nargin == 0 50 | path_name = pwd; 51 | end 52 | 53 | %% convert relative into full path 54 | path_name = strrep(path_name,[filesep filesep],filesep); 55 | if isempty(strfind(path_name,[':' filesep]))&&~strcmp(path_name(1),filesep)&&~strcmp(path_name(1:min(2,length(path_name))),['.' filesep])&&~strcmp(path_name(1:min(3,length(path_name))),['..' filesep]) 56 | path_name_f = [ pwd filesep path_name ] ; 57 | elseif strcmp(path_name(1:min(2,length(path_name))),['.' filesep]) 58 | path_name_f = [pwd filesep path_name(3:end)]; 59 | elseif strcmp(path_name(1:min(3,length(path_name))),['..' filesep]) 60 | path_name_f = pwd; 61 | ind = strfind(path_name_f,filesep); 62 | if ~isempty(ind)&&(ind(end)>1) 63 | path_name_f = path_name_f(1:(ind(end)-1)); 64 | end 65 | path_name_f = [path_name_f filesep path_name(4:end)]; 66 | else 67 | path_name_f = path_name; 68 | end 69 | 70 | %% Append filesep at the end 71 | if ~strcmp(path_name_f(end),filesep) 72 | path_name_f = [path_name_f filesep]; 73 | end 74 | 75 | -------------------------------------------------------------------------------- /niak/commands/read_write/niak_cp_fmri.m: -------------------------------------------------------------------------------- 1 | function [flag_error,message] = niak_cp_fmri(source,target) 2 | % Copy an fMRI volume under a different name. 3 | % 4 | % SYNTAX: 5 | % [FLAG_ERROR,MESSAGE] = NIAK_CP_FMRI(SOURCE,TARGET) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS: 9 | % 10 | % SOURCE 11 | % (string) the name of an fMRI dataset (extension .mnc or .nii with or 12 | % wihtout .gz). 13 | % 14 | % TARGET 15 | % (string) the name of an fMRI dataset (extension .mnc or .nii with or 16 | % wihtout .gz). 17 | % 18 | % _________________________________________________________________________ 19 | % OUTPUTS: 20 | % 21 | % FLAG_ERROR 22 | % (boolean) If the flag is non-zero, an error has occured. 23 | % 24 | % MESSAGE 25 | % (string) the message generated by the copy command. 26 | % 27 | % _________________________________________________________________________ 28 | % COMMENTS: 29 | % 30 | % The difference between that command and a simple cp is that any file 31 | % of the type _extra.mat will be copied under the name 32 | % _extra.mat. 33 | % 34 | % Copyright (c) Pierre Bellec, 35 | % Research Centre of the Montreal Geriatric Institute 36 | % & Department of Computer Science and Operations Research 37 | % University of Montreal, Québec, Canada, 2012. 38 | % Maintainer : pierre.bellec@criugm.qc.ca 39 | % See licensing information in the code. 40 | % Keywords : fMRI 41 | 42 | % Permission is hereby granted, free of charge, to any person obtaining a copy 43 | % of this software and associated documentation files (the "Software"), to deal 44 | % in the Software without restriction, including without limitation the rights 45 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 46 | % copies of the Software, and to permit persons to whom the Software is 47 | % furnished to do so, subject to the following conditions: 48 | % 49 | % The above copyright notice and this permission notice shall be included in 50 | % all copies or substantial portions of the Software. 51 | % 52 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 53 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 54 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 55 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 56 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 57 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 58 | % THE SOFTWARE. 59 | source = niak_full_file(source); 60 | target = niak_full_file(target); 61 | 62 | instr_copy = cat(2,'cp ',source,' ',target); 63 | 64 | [status,msg] = system(instr_copy); 65 | if status~=0 66 | error(msg) 67 | end 68 | 69 | % Copy the "extra" file, if present 70 | [path_s,name_s,ext_s] = niak_fileparts(source); 71 | [path_t,name_t,ext_t] = niak_fileparts(target); 72 | file_extra_s = [path_s filesep name_s '_extra.mat']; 73 | file_extra_t = [path_t filesep name_t '_extra.mat']; 74 | if psom_exist(file_extra_s) 75 | instr_copy = cat(2,'cp -f ',file_extra_s,' ',file_extra_t); 76 | [status,msg] = system(instr_copy); 77 | if status~=0 78 | error(msg) 79 | end 80 | end -------------------------------------------------------------------------------- /niak/extensions/psom-1.0.2/psom_is_dag.m: -------------------------------------------------------------------------------- 1 | function [flag_dag,list_vert_cycle] = psom_is_dag(adj) 2 | % 3 | % _________________________________________________________________________ 4 | % SUMMARY PSOM_IS_DAG 5 | % 6 | % Test if a sparse binary matrix is the adjacency matrix of a directed 7 | % acyclic graph 8 | % 9 | % SYNTAX : 10 | % [FLAG_DAG,LIST_VERT_CYCLE] = PSOM_IS_DAG(ADJ) 11 | % 12 | % _________________________________________________________________________ 13 | % INPUTS : 14 | % 15 | % ADJ 16 | % (sparse binary matris) ADJ(I,J) == 1 only if there is an edge from 17 | % J to I. 18 | % 19 | % _________________________________________________________________________ 20 | % OUTPUTS : 21 | % 22 | % FLAG_DAG 23 | % (boolean) FLAG_DAG == 1 only if ADJ is the adjacency matrix of an 24 | % acyclic directed graph. 25 | % 26 | % LIST_VERT_CYCLE 27 | % (vector) the list of vertices number which are involved in cycles. 28 | % 29 | % _________________________________________________________________________ 30 | % COMMENTS : 31 | % 32 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 33 | % Maintainer : pbellec@bic.mni.mcgill.ca 34 | % See licensing information in the code. 35 | % Keywords : string 36 | 37 | % Permission is hereby granted, free of charge, to any person obtaining a copy 38 | % of this software and associated documentation files (the "Software"), to deal 39 | % in the Software without restriction, including without limitation the rights 40 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 41 | % copies of the Software, and to permit persons to whom the Software is 42 | % furnished to do so, subject to the following conditions: 43 | % 44 | % The above copyright notice and this permission notice shall be included in 45 | % all copies or substantial portions of the Software. 46 | % 47 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 48 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 49 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 50 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 51 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 52 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 53 | % THE SOFTWARE. 54 | 55 | %% SYNTAX 56 | if ~exist('adj','var') 57 | error('SYNTAX: [FLAG_DAG,LIST_VERT_CYCLE] = PSOM_IS_DAG(ADJ). Type ''help psom_is_dag'' for more info.') 58 | end 59 | 60 | flag_dag = true; 61 | nb_vertices = size(adj,1); 62 | list_vert_cycle = []; 63 | lab_vertices = 1:nb_vertices; 64 | 65 | while ~isempty(adj) && flag_dag 66 | 67 | mask_term = max(adj,[],1) == 0; % find terminal nodes 68 | 69 | if max(double(mask_term))==0 % The doubel conversion is there for compatibility with Octave 3.0.4 70 | %% There is no terminal node, but the matrix is not empty, 71 | %% there must be a cycle 72 | flag_dag = false; 73 | list_vert_cycle = lab_vertices; 74 | else 75 | %% Get rid of terminal nodes and start again 76 | adj = adj(~mask_term,~mask_term); 77 | lab_vertices = lab_vertices(~mask_term); 78 | end 79 | 80 | end -------------------------------------------------------------------------------- /checkArchive.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Automated checking of archive files to see if the folder structure inside 3 | # mathes the requirements of the pipeline 4 | # 5 | # Currently supported file-formats: .tar.gz; .zip 6 | # 7 | # Usage ./checkArchive.sh fileName.format 8 | # 9 | # ============================================================================= 10 | # The folder structure must match the following pattern: 11 | # 12 | # +--RAWDATA 13 | # +--BOLD-EPI 14 | # +--IM-0001-0001.dcm 15 | # +-- ... 16 | # +--DTI 17 | # +--IM-0001-0001.dcm 18 | # +-- ... 19 | # +--MPRAGE 20 | # +--IM-0001-0001.dcm 21 | # +-- ... 22 | # ============================================================================= 23 | # 24 | # ============================================================================= 25 | # Authors: Michael Schirner, Simon Rothmeier, Petra Ritter 26 | # BrainModes Research Group (head: P. Ritter) 27 | # Charité University Medicine Berlin & Max Planck Institute Leipzig, Germany 28 | # Correspondence: petra.ritter@charite.de 29 | # 30 | # When using this code please cite as follows: 31 | # Schirner M, Rothmeier S, Jirsa V, McIntosh AR, Ritter P 32 | # Constructing subject-specific Virtual Brains from multimodal neuroimaging 33 | # 34 | # This software is distributed under the terms of the GNU General Public License 35 | # as published by the Free Software Foundation. Further details on the GPL 36 | # license can be found at http://www.gnu.org/copyleft/gpl.html. 37 | # ============================================================================= 38 | # 39 | 40 | # Init 41 | theFile=$1 42 | retVal=0 43 | 44 | #Define functions 45 | checkFolderStructure() { 46 | inputString=$1 47 | retVal=0 48 | 49 | #Check for faulty structure 50 | if [[ $inputString != *"RAWDATA/"* ]]; then retVal=1; fi #Mainfolder must be namen RAWDATA 51 | if [[ $inputString != *"RAWDATA/MPRAGE/"* ]]; then retVal=1; fi #Check for anatomical data folder with subID folder inside 52 | if [[ $inputString != *"RAWDATA/DTI/"* ]]; then retVal=1; fi #Check for DTI folder with subID folder inside 53 | 54 | #Optional: If BOLD data is include check if the data is formatted appropriate 55 | #if [[ $inputString == *"RAWDATA/BOLD-EPI/"* ]] 56 | # then 57 | # if [[ $inputString != *"RAWDATA/BOLD-EPI/"*"/"* ]]; then retVal=4; fi 58 | #fi 59 | 60 | return $retVal 61 | } 62 | 63 | # First determine if the file format is valid i.e. supported by this script 64 | if [[ $theFile == *.zip ]]; then 65 | #List the folders inside the zip archive but remove MACOSX control files. Afterwards reduce the lines to just the folder names 66 | theString=$(zipinfo $theFile | grep '^d' | grep -v "MACOSX" | awk 'NF>1{print $NF}') 67 | elif [[ $theFile == *.tar.gz ]]; then 68 | #List folder in the archive 69 | theString=$(tar -ztvf $theFile | grep '^d' | awk 'NF>1{print $NF}') 70 | else 71 | #Error message + exit code 1 72 | echo "Error! Unsupported file-format for $theFile" 73 | exit 1 74 | fi 75 | 76 | #Check if the structure is valid 77 | checkFolderStructure "$theString" 78 | retVal=$? 79 | 80 | #Check the return Value of the folder structure checking method 81 | if [ $retVal == 0 ]; then 82 | exit 0 83 | else 84 | exit 1 85 | fi 86 | -------------------------------------------------------------------------------- /niak/commands/SI_processing/niak_build_density_mask.m: -------------------------------------------------------------------------------- 1 | function vec_dense = niak_build_density_mask(mask,type_neig) 2 | % Derive a map of spatial density for a binary volume. 3 | % 4 | % SYNTAX: 5 | % VEC_DENSE = NIAK_BUILD_DENSITY_MASK(MASK,TYPE_NEIG) 6 | % 7 | % _________________________________________________________________________ 8 | % INPUTS : 9 | % 10 | % MASK 11 | % (3D volume) a binary volume. 12 | % 13 | % TYPE_NEIG 14 | % (integer, default 26) the type of spatial connexity. See 15 | % NIAK_BUILD_NEIGHBOUR_MAT. 16 | % 17 | % _________________________________________________________________________ 18 | % OUTPUTS : 19 | % 20 | % VEC_DENSE 21 | % (vector) VEC_DENSE(I) is the spatial density at voxel I in MASK, as 22 | % numbered using FIND(MASK). 23 | % 24 | % _________________________________________________________________________ 25 | % SEE ALSO : 26 | % NIAK_BUILD_NEIGHBOUR_MAT, NIAK_CLUSTERING_SPACE_DENSITY 27 | % 28 | % _________________________________________________________________________ 29 | % COMMENTS 30 | % 31 | % Spatial density at each voxel is defined as the proportion of spatial 32 | % neighbours that fall within the mask. 33 | % 34 | % _________________________________________________________________________ 35 | % Copyright (c) Pierre Bellec, Montreal Neurological Institute, 2008. 36 | % Maintainer : pbellec@bic.mni.mcgill.ca 37 | % See licensing information in the code. 38 | % Keywords : medical imaging, t1, mask, segmentation 39 | 40 | % Permission is hereby granted, free of charge, to any person obtaining a copy 41 | % of this software and associated documentation files (the "Software"), to deal 42 | % in the Software without restriction, including without limitation the rights 43 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 44 | % copies of the Software, and to permit persons to whom the Software is 45 | % furnished to do so, subject to the following conditions: 46 | % 47 | % The above copyright notice and this permission notice shall be included in 48 | % all copies or substantial portions of the Software. 49 | % 50 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 53 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 55 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 56 | % THE SOFTWARE. 57 | 58 | decxyz = niak_build_neighbour_mat(type_neig); 59 | nb_n = size(decxyz,1); 60 | opt_neig.ind = find(mask); 61 | [coordx,coordy,coordz] = ind2sub(size(mask),opt_neig.ind); 62 | opt_neig.coord = [coordx,coordy,coordz]; 63 | clear coordx coordy coordz 64 | opt_neig.type_neig = type_neig; 65 | opt_neig.flag_position = true; 66 | opt_neig.flag_within_mask = true; 67 | 68 | for num_n = 1:nb_n 69 | opt_neig.decxyz = decxyz(num_n,:); 70 | neig = niak_build_neighbour(mask,opt_neig); 71 | if num_n == 1 72 | vec_dense = double(neig>0)+1; 73 | else 74 | vec_dense = vec_dense + (neig>0); 75 | end 76 | end 77 | vec_dense = vec_dense/(nb_n+1); -------------------------------------------------------------------------------- /niak/commands/statistics/niak_correct_vol.m: -------------------------------------------------------------------------------- 1 | function vol_c = niak_correct_vol(vol,mask) 2 | % Correct the distribution of a 3D random field to zero mean/unit variance 3 | % The function fits a Gaussian distribution on the histogram of the volume 4 | % insie a mask, with parameters initialized by the median and the median 5 | % absolute deviation to the median. 6 | % 7 | % SYNTAX: 8 | % VOL_C = NIAK_CORRECT_VOL(VOL,MASK) 9 | % 10 | % _________________________________________________________________________ 11 | % INPUTS: 12 | % 13 | % VOL 14 | % (3D array) 15 | % 16 | % MASK 17 | % (binary 3D array) 18 | % 19 | % _________________________________________________________________________ 20 | % OUTPUTS: 21 | % 22 | % VOL_C 23 | % (3D array) same as VOL, with corrected distribution. 24 | % 25 | % _________________________________________________________________________ 26 | % COMMENTS: 27 | % 28 | % Copyright (c) Pierre Bellec, McConnell Brain Imaging Center, 29 | % Montreal Neurological Institute, McGill University, 2008. 30 | % Maintainer : pbellec@bic.mni.mcgill.ca 31 | % See licensing information in the code. 32 | % Keywords : medical imaging 33 | 34 | % Permission is hereby granted, free of charge, to any person obtaining a copy 35 | % of this software and associated documentation files (the "Software"), to deal 36 | % in the Software without restriction, including without limitation the rights 37 | % to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 38 | % copies of the Software, and to permit persons to whom the Software is 39 | % furnished to do so, subject to the following conditions: 40 | % 41 | % The above copyright notice and this permission notice shall be included in 42 | % all copies or substantial portions of the Software. 43 | % 44 | % THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 45 | % IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 46 | % FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 47 | % AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 48 | % LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 49 | % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 50 | % THE SOFTWARE. 51 | 52 | flag_visu = 0; 53 | 54 | global niak_gb_X niak_gb_Y 55 | 56 | if nargin < 3 57 | p = 0.05; 58 | end 59 | 60 | % Histogram computation and normalization 61 | M = vol(mask); 62 | M = M(:); 63 | M = double(M); 64 | [niak_gb_Y,niak_gb_X] = hist(M,length(M)/100); 65 | niak_gb_Y = niak_gb_Y/(length(M)*(max(niak_gb_X)-min(niak_gb_X)))*length(niak_gb_X); 66 | 67 | % Gaussian parameters fitting. 68 | if exist('fminsearch','file') 69 | par = fminsearch('niak_gaussian_fit',[median(M);1.4826*median(abs(M-median(M)))]); 70 | else 71 | par = [median(M);1.4826*median(abs(M-median(M)))]; 72 | end 73 | 74 | if flag_visu 75 | [err,val] = niak_gaussian_fit(par); 76 | figure 77 | bar(niak_gb_X,niak_gb_Y); hold on; plot(niak_gb_X,val,'r'); 78 | title(sprintf('Empirical distribution and fitted gaussian function mean %1.3s std %1.3s',par(1),par(2))); 79 | end 80 | 81 | % Volume correction 82 | vol_c = zeros(size(vol)); 83 | vol_c(mask) = (vol(mask) - par(1))/par(2); --------------------------------------------------------------------------------