Problems with connectomics

Hi everyone, I am doing my final project in the university about connectomics and for that I am using a lot of commands of MRtrix, but i can’t get a good connectome. I show you the commands i am using, and the final error I am getting. I will appreciate any help you could provide to me.
I use 61 gradients and b=1000. Then I use T1 and DWI files, which they have a format .nii at the begin.

To get the connectome matrix, I use a mix of the HCP tutorial and instructions of my teacher in the University.

T1 PROCESS

Cortical segmentation(Freesurfer)

recon-all -s caso002 -i /datos/pruebas_daniel/estructural/T1s/caso002/caso002_T1.nii
recon-all -s caso002 -all

I move and change the name of the file apar+aseg.

cp /datos/pruebas_daniel/estructural/Freesurfer_cortical_parcelation/caso002/mri/aparc+aseg.mgz /datos/pruebas_daniel/estructural/Freesurfer_segmentacion_cortical_resultado/caso002/caso002_cortical_seg.mgz

I change the format nii to mgz.(Freesurfer)

mri_convert /datos/pruebas_daniel/estructural/Freesurfer_segmentacion_cortical_resultado/caso002/caso002_cortical_seg.mgz /datos/pruebas_daniel/estructural/Freesurfer_segmentacion_cortical_resultado/caso002/caso002_cortical_seg.nii

I change the real volume to a volume 256x256x256 so later I can calculate a deformation.(Freesurfer)

mri_convert -c /datos/pruebas_daniel/estructural/T1s/caso002/caso002_T1.nii /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_T1_256.nii.gz

I extract the brain because the skull can cause problems(FSL)

bet /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_T1_256.nii.gz /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_T1_256_masked.nii.gz -R

DWI PROCESS

I obtain a mask for future propose(MRtrix)

dwi2mask /datos/pruebas_daniel/difusion/DWIs/caso002/caso002_dwi.nii /datos/pruebas_daniel/difusion/MRTRIX_brain_mask/caso002/caso002_MRTRIX_brain_mask.nii -fslgrad /datos/pruebas_daniel//difusion/b_values_61_direcciones.bvec /datos/pruebas_daniel//difusion/b_values_61_direcciones.bval

I obtain a 5tt format so i can do the tractography with the option act(MRtrix)

5ttgen fsl /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_ T1_256.nii.gz /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_5tt.nii.gz

I obtain the response function (MRtrix)

dwi2response tournier -fslgrad /datos/pruebas_daniel/difusion/b_values_61_direcciones.bvec /datos/pruebas_daniel/difusion/b_values_61_direcciones.bval /datos/pruebas_daniel/difusion/DWIs/caso002/caso002_dwi.nii /datos/pruebas_daniel/difusion/MRTRIX_spherical_deconvolution/caso002/caso002_sph_dec_response -mask /datos/pruebas_daniel/difusion/MRTRIX_brain_mask/caso002/caso002_MRTRIX_brain_mask.nii

I obtain the Fiber orientation distribution(MRtrix)

dwi2fod csd -fslgrad /datos/pruebas_daniel/difusion/b_values_61_direcciones.bvec /datos/pruebas_daniel/difusion/b_values_61_direcciones.bval /datos/pruebas_daniel/difusion/DWIs/caso002/caso002_dwi.nii /datos/pruebas_daniel/difusion/MRTRIX_spherical_deconvolution/caso002/caso002_sph_dec_response /datos/pruebas_daniel/difusion/MRTRIX_spherical_deconvolution/caso002/caso002_sph_dec_output_fod.nii -mask /datos/pruebas_daniel/difusion/MRTRIX_brain_mask/caso002/caso002_MRTRIX_brain_mask.nii

I obtain a lot of parameters(tensors), including the FA. (MRtrix)

dtifit -k /datos/pruebas_daniel/difusion/DWIs/caso002/caso002_dwi.nii -o /datos/pruebas_daniel/difusion/tensores_con_FSL/caso002/caso002 -m /datos/pruebas_daniel/difusion/MRTRIX_brain_mask/caso002/caso002_MRTRIX_brain_mask.nii -r /datos/pruebas_daniel/difusion/b_values_61_direcciones.bvec -b /datos/pruebas_daniel/difusion/b_values_61_direcciones.bval

I do the parcellation.(MRtrix)

labelconvert /datos/pruebas_daniel/estructural/Freesurfer_segmentacion_cortical_resultado/caso002/caso002_cortical_seg.nii  $FREESURFER_HOME/FreeSurferColorLUT.txt  /opt/shared/MRtrix/mrtrix3/src/connectome/tables/fs_default.txt /datos/pruebas_daniel/estructural/Freesurfer_segmentacion_cortical_resultado/caso002/caso002_cortical_seg_lut.nii  

Now, i realize the orientation of the T1 and FA are different of the DWI, so i use the next comands(FSL)

flirt -in /datos/pruebas_daniel/difusion/tensores_con_FSL/caso002/caso002_FA -ref /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_T1_256_masked -out /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_FA_over_T1 -omat /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_transf_FA_over_T1.mat -dof 12 -searchrx -180 180 -searchry -180 180 -searchrz -180 180 
convert_xfm -omat /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_transf_inv_FA_over_T1.mat -inverse /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_transf_FA_over_T1.mat
flirt -in /datos/pruebas_daniel/estructural/Freesurfer_segmentacion_cortical_resultado/caso002/caso002_cortical_seg_lut.nii -ref /datos/pruebas_daniel/difusion/tensores_con_FSL/caso002/caso002_FA -out /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_cortical_seg_lut_warped -init /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_transf_inv_FA_over_T1.mat -interp nearestneighbour -applyxfm
flirt -in /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_5tt.nii.gz -ref /datos/pruebas_daniel/difusion/tensores_con_FSL/caso002/caso002_FA -out /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_5tt_warped -init /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_transf_inv_FA_over_T1.mat -interp nearestneighbour -applyxfm

Tractography(MRtrix)

tckgen -act /datos/pruebas_daniel/estructural/T1s_256x256x256/caso002/caso002_5tt_warped.nii.gz /datos/pruebas_daniel/difusion/MRTRIX_spherical_deconvolution/caso002/caso002_sph_dec_output_fod.nii /datos/pruebas_daniel/difusion/MRTRIX_whole_brain_tractography/caso002/caso002_act_2000000_fibras.tck -seed_image /datos/pruebas_daniel/difusion/MRTRIX_brain_mask/caso002/caso002_MRTRIX_brain_mask.nii -number  2000000

Connectome Matrix (MRtrix)

tck2connectome /datos/pruebas_daniel/difusion/MRTRIX_whole_brain_tractography/caso002/caso002_act_2000000_fibras.tck /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_cortical_seg_lut_warped.nii.gz /datos/pruebas_daniel/difusion/MRTRIX_conectomica/caso002/caso002_conectomica_fiber_count.csv

And after executing tck2connectome command, i get this error:

tck2connectome: [WARNING] The following nodes do not have any streamlines assigned: 
tck2connectome: [WARNING] 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 24, 25, 26, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 49, 53, 54, 60, 62, 67, 69, 74, 80, 81 
tck2connectome: [WARNING] (This may indicate a poor registration)

Can anyone help me to find where is my mistake?

Thanks a lot!

Hacked your post to make it a bit more readable, hope you don’t mind! (Adding three ‘```’ marks above and below each command makes them appear as code snippets; the fixed-width font really helps :+1:)

Also quick note: dtifit is an FSL command, not MRtrix3.

So the reason I added that note at the end of the warning message is that in my experience this issue arises most commonly due to registration errors; and I’d say that’s the most likely issue in your case as well. I’m not as experienced with flirt as some other people here will be, but I would suggest the following:

  1. Immediately check the outcome of flirt in mrview: Make sure you load one image as the main image being viewed, and the other image using the ‘Overlay’ tool. Make sure the two volumes align in space, regardless of whether or not they are actually sampled on the same voxel grid. Until you can verify that this step is working as it should, debugging any subsequent steps is meaningless.

  2. If the above is correct, try using transformconvert and mrtransform to apply the estimated transformation. You may also need a transformcalc inverse in there if you’re registering FA to T1 rather than the other way around (or you could just register T1 to FA to avoid that inversion).

  3. If the registration isn’t correct, maybe try 6 degrees of freedom rather than 12. In fact, if you have corrected for EPI susceptibility distortions (which I hope you have, given you are attempting to use ACT and a FreeSurfer-based parcellation), you shouldn’t be using 12 degrees of freedom anyway, since it’s intra-subject registration.

  4. Regridding the 5TT image should use linear interpolation rather than nearest neighbour. This will give a smoother result, but still ensure that the sum of partial volume fractions remains 1.0 for all voxels.

Let us know if that gets you anywhere; otherwise we’ll see if any more regular flirt users spot an issue.
Rob

Hi, first of all, thank you for answering my doubts and sorry for the little mistakes but i am starting with connectomics.

I check the 5tt image before i use flirt and this is the outcome:

You can see that it appears that everything is okay.

But when i use flirt with my 5tt image so i can do the tractography properly, this is the outcome:

As you can see, the image is not aligned with the main 5tt image, so I wonder if you think I should use the other commands you told me to check(transformconvert, etc)

The other outcomes of flirt it appears that the volumes are aligned in space, so think the problem is with 5tt image.
And, finally I want to emphasize that I try to use flirt with 6 degrees and linear interpolation and the outcome was very similar.

Thank you for your time, Daniel.

OK, I’m not sure if you’re still using the same sequence of commands as you had described earlier, but this introduced doubts:

But when i use flirt with my 5tt image …

As you can see, the image is not aligned with the main 5tt image

Typically in this sort of use case, the ‘main’ image would be the FA image, and the 5TT image would be the ‘moving’ / ‘overlay’ image. Not sure if this was simply a typo.


Otherwise, one thing I would consider may be having an influence is the fact that 5ttgen by default will crop the resulting image field of view to save memory and improve tracking performance. This may be influencing how the transformation calculated by flirt based on a T1 image is being applied to the 5TT image / how fslview is displaying it. Has anybody else had any experience with this?

Unfortunately this sort of thing can be difficult to diagnose (even more so when you have only a couple of screenshots to work with). My advice would be:

  • When assessing image alignment following registration, use mrview’s Overlay tool. fslview I believe performs its visual alignment based on the [0, 0, 0] corner voxel of each image, the position of which will vary considerably between the T1 and 5TT image. By using mrview’s Overlay tool, you will be assessing the image alignment using the same ‘interpretation’ of image alignment in scanner space that will be applied during tractography.

  • If the images are in fact not aligned, there’s a couple of options:

    • Try using transformconvert to convert the linear transform to MRtrix3 convention (make sure you provide the same images to transformconvert as were used in flirt), then apply it to the 5TT image using mrtransform.

    • Try re-running 5ttgen with the -nocrop option. That will remove the confound of image FoV cropping, which may simplify your application / assessment of registration.

Good luck!
Rob

HI, I ran this commands:

flirt -in caso002_FA -ref caso002_T1_256_masked -out caso002_FA_over_T1 -omat caso002_transf_FA_over_T1.mat -dof 12 -searchrx -180 180 -searchry -180 180 -searchrz -180 180 

transformconvert caso002_transf_FA_over_T1.mat caso002_FA.nii.gz caso002_T1_256_masked.nii.gz flirt_import caso002_transf_FA_over_T1_MRtrix.mat

transformcalc caso002_transf_FA_over_T1_MRtrix.mat invert caso002_transf_inv_FA_over_T1_MRtrix.mat

mrtransform -linear caso002_transf_inv_FA_over_T1_MRtrix.mat caso002_5tt.nii.gz caso002_5tt_warped_MRtrix.nii.gz

And there is a warning when i use mrtransform:

mrtransform -linear caso002_transf_inv_FA_over_T1_MRtrix.mat caso002_5tt.nii.gz caso002_5tt_warped_MRtrix.nii.gz

Although I out the option -template, the first warning still appears. Do you know if I am using this commands well?

I’m guessing that the warning produced by mrtransform was related to the transform not being orthonormal? (Best to include the terminal output in your post.) This is due to specifying -dof 12 to flirt, which tells flirt to optimise a linear transform that includes 3 scaling and 3 shearing components on top of translations and rotations. When two images are of the same subject, only 6 degrees of freedom should be used, in order to correct translations and rotations between the images only.

Otherwise, I don’t spot any issues with the command chain. Fix the degrees of freedom, and make sure you check the final result in mrview using the Overlay tool. You can either open the FA image and then load the 5TT image in the Overlay tool, or open the 5TT image then load the FA image in the Overlay tool; either is valid.

Rob

Hi, finally I change the command 5tt fsl for the command 5tt freesurfer with the option -nocrop and I didn´t get any bugs. Thank you @rsmith for your answers!