The adjacency matrix is missing a row (connectome)

Can someone HELP ME, I was generating connectome from diffusion mri, and It’s really strange that the shape adjacency matrix is (163*164).

I’ve tagged my code below:


cd $baseDir
patList=$(ls $baseDir)
for patID in $patList
         echo "Patient ID: $patID"
         timepointlist=$(ls -d $baseDir/$patID/*/)
         for timepoint in $timepointlist
                echo "Target directory: $targetDir"
                if [ -d "$targetDir" ]; then
                cd $targetDir
                echo "Directory does not exist: $targetDir"

                mrconvert -fslgrad *.bvec *.bval *.nii.gz dwi.mif -force
                dwidenoise dwi.mif denoise.mif -force
                mrdegibbs denoise.mif degibbs.mif -force
                dwiextract degibbs.mif -bzero - | mrmath -axis 3 - mean b0.nii -force

                flirt.fsl -dof 6 -cost normmi -ref $baseDir/T1.nii.gz -in b0.nii -omat T_fsl.txt

                echo "fishish flirt"
                transformconvert T_fsl.txt b0.nii $baseDir/T1.mgz flirt_import T_DWItoT1.txt -force        
                mrtransform -linear T_DWItoT1.txt degibbs.mif align.mif -force  # apply alignment
                echo "fishish alignment"
                mrconvert /home/cmet-standard/application/freesurfer/subjects/fsaverage/mri/aparc.a2009s+aseg.mgz aparc2009aseg.nii.gz -force              # readable for MRtrix
                5ttgen freesurfer aparc2009aseg.nii.gz 5ttseg.mif -force
                # 5tt2gmwmi 5ttseg.mif 5tt_gmwmi.mif
                echo "fishish segmentation"

                ## single shell(only one b value)
                # estimate response function for wm only for single shell        
                dwi2response tournier align.mif wm_ss.txt -force
                dwi2fod csd align.mif wm_ss.txt dwi_wmCsd.mif -force

                ### diffusion tensor imagine ###
                # create a mask 
                dwi2mask align.mif - | maskfilter - dilate dwi_mask.mif -force

                # creatediffusion tensor
                dwi2tensor -mask dwi_mask.mif align.mif dt.mif -force

                # calculate eigenvectors and scalar metrics from tensor
                tensor2metric dt.mif -fa dt_fa.mif -adc dt_adc.mif -force

                #create ROIs
                mrthreshold -abs 0.2 dt_fa.mif - | mrcalc - dwi_mask.mif -mult dwi_wmMask.mif
                #whole brain tractography
                tckgen -algo iFOD2 -act 5ttseg.mif -backtrack -crop_at_gmwmi \
                        -cutoff 0.03 -angle 60 -minlength 15 -maxlength 230 \
                        -seed_image dwi_wmMask.mif -select 200k \
                        fibs_200k_angles45_maxlength200_act.tck -force
                echo "fishish tractography"
                # connectome
                # relabel the parcellation order
                labelconvert aparc2009aseg.nii.gz $FREESURFER_HOME/FreeSurferColorLUT.txt \
                /home/cmet-standard/anaconda3/share/mrtrix3/labelconvert/fs_a2009s.txt \
                aparc+aseg_relabl.nii.gz -force

                # generate connectome

                tck2connectome -symmetric -zero_diagonal -scale_invnodevol \
                        fibs_200k_angles45_maxlength200_act.tck \
                        aparc+aseg_relabl.nii.gz \
                        connectome.csv \
                        -out_assignment assignments.csv -force


Hi @Ning,

That is very strange, does your parcellation have 164 Rois? To be sure that is one column missing and not anything added.

Best regards,


1 Like

Hi,thanks for replying. @mblesac

It does have 164 rois, according to the mrtrix3/labelconvert/fs_a2009s.txt

And during progression it shows warning:
tck2connectome: [WARNING] The following nodes do not have any streamlines assigned:
tck2connectome: [WARNING] 1, 5, 31, 32, 43, 50, 70, 102, 120, 121, 132, 152, 159
tck2connectome: [WARNING] (This may indicate a poor registration)
Maybe that’s the cause?

Btw I changed another atlas fs_default.txt with 84 rois, the connectome is (83*84),also a row missing.

Best regards,

Hi @mblesac lesac
By defaut,the “read_csv” method in pandas and libre office both treat the first row as the column header, that’s why there’s a row missing. problem solved, can’t believe I’ve waste one day on this! :upside_down_face: