Friday, 21 August 2015

Unix commands

Queue commands

echo 'command1 --option arg1 arg2' | at -q b -m now
echo 'command2 ...' | at -q b -m now

Tuesday, 14 April 2015

TBSS preparation

ExploreDTI to set up files for RA/AD

Open matlab by typing matlab into terminal

Go up in current directory to find the folder ‘exploredti’ then go into it and drag and drop ‘source’ and ‘MainExploreDTI’ into terminal.

Type MainExploreDTI

-          ‘plugins’ – ‘export stuff to *.nii files’ – select ‘multiple’- select ‘FA/largest eigenvalue’-  select ‘MD/Radial/transverse diffusivity’ – ‘ok’
S    Select file containing mat files and then select files to save the files in.


- - This will produce nifti files for the measures that you have selected.

     TBSS


      http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/TBSS/UserGuide


All data should be in NIFTI format and corrected for the effects of eddy current distortions and head motion.

Make directories called 'TBSSmain' and inside that 'mytbss'
Copy FA nifti files into mytbss
Navigate into 'mytbss'

Preprocessing


-    %tbss_1_preproc *.nii
-         % tbss_2_reg -T 
-         %  tbss_3_postreg –S

-          %  tbss_4_prestats 0.2

n    These commands perform a non-linear registration and affine transformation into MNI space using the non-linear registration tool. This creates mean FA and skeletonised images.
S   See TBSS UserGuide for other options.

Freesurfer longitudinal processing stream

https://surfer.nmr.mgh.harvard.edu/fswiki/LongitudinalProcessing

https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/LongitudinalTutorial

1. Cross-sectionally process your data (recon-all)

2. Create template for all timepoints for each subject.

recon-all -base <templateid> -tp <tp1id> -tp <tp2id> ... -all

3. Longitudinally process all timepoints

  recon-all -long <tpNid> <templateid> -all

4. Inspect the base and longitudinal data




Wednesday, 25 March 2015

DTI preparation for TBSS analysis

Before anything else you need to be sure that the data you need (diffusion and T1 images) have all been retrieved from Dougal into /data/blinded and contain no duplicates.
1) LOGIN IN TO ONE OF THE LINUX SERVERS (nanlnx1, nanlnx2,...)
% ssh kxxxxxxx@nanlnx1.iop.kcl.ac.uk
2) ADD THE NBL MODULE (THIS WILL SET UP YOU ENVIRONMENT SO YOU CAN RUN THE PIPELINE COMMANDS)
%  module add /home/k1339392/software/nbl /etc/nblmodule
3) CREATE THE FOLDERS FOR YOUR PROJECT (i.e. DRUM_PROJECT)
% mkdir ~/DRUM_PROJECT
% mkdir ~/DRUM_PROJECT/nandata
% mkdir ~/DRUM_PROJECT/dtidata
% mkdir ~/DRUM_PROJECT/expdtidata
% cd ~/DRUM_PROJECT
% ls
4) GET THE DATA FROM DOUGAL (add new folders with NIFTI data to ./nandata with NIFTI data)
% getnandata /data/blinded/CNSCNSD ./nandata DRUMPILOT01
% ls ./nandata
5) PREPARE DTI DATA FOR PREPROCESSING ( adds *.nii.gz *.bvec *.bval _mask.nii.gz files to ./dtidata). Use -C option if your data was acquired in the old CNS scanner using the 32 directions pulse sequence (i.e. BRCATLAS and MIAMRC projects).
% prepdti -C  ./nandata ./dtidata DRUMPILOT01 DTI_2mm_60B1500_FDA
% ls ./dtidata
6) PREPARE T1 DATA REQUIRED FOR EPI CORRECTION (adds new _T1.nii.gz _T1_mask.nii.gz files to ./dtidata)
% prept  ./nandata ./dtidata DRUMPILOT01 MPRAGE
7) RUN EXPLORE DTI PREPROCESSING SCRIPT (creates new *.mat *_EPI.mat files in ./expdtidata )
SM/EC CORRECTION ONLY
% expdticorr -R  ./dtidata ./expdtidata DRUMPILOT01 _SMEC
% ls ./expdtidata
SM/EC/EPI CORRECTION
% expdticorr -E  -R  ./dtidata ./expdtidata DRUMPILOT01 _EPI
% ls ./expdtidata

The final result will be a new file in ./expdtidata called DRUMPILOT01_[EPI/SMEC].mat. This file can only be opened with ExploreDTI. Using Explore DTI you will be able to generate any kind of diffusion images/maps you need, including of course tractography datasets.


See DTI pipeline document for more detail

Thursday, 5 March 2015

Random freesurfer commands and links

Table of surface areas (Desikan atlas)

aparc2statstable --hemi lh --subjects <list subjects> --tablefile lh.aparc.area.table

Table of thickness values (Desikan Atlas)

aparcstats2table --hemi lh --subjects <list subjects> -meas thickness --parc aparc --tablefile  lh.aparc.stats.thickness.table

Table of cortical volumes (Desikan Atlas)

aparcstats2table --subjects bert ernie fred margaret --parc aparc.a2005s --hemi rh --meas volume --tablefile aparc_stats_rh.txt

Table of subcortical volumes
asegstats2table --subjects bert ernie fred --meas volume --tablefile aseg_stats.txt

or create text file with path of all subjects and 

asegstats2table --subjectsfile=subject_to_write --meas volume --tablefile aseg_stats.txt

Change background of figure to white:
convert -fill white -opaque black <tksurfer_image_black_background>
<new_image_with_white_background>

http://ftp.nmr.mgh.harvard.edu/fswiki/FsTutorial/MorphAndRecon

Command line Group Analysis
https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/GroupAnalysis

Smoothing/qcache command
http://freesurfer.net/fswiki/FsTutorial/QdecGroupAnalysis_freeview

Methods citation
https://surfer.nmr.mgh.harvard.edu/fswiki/FreeSurferMethodsCitation

Check surfaces
tkmedit your_subject_name wm.mgz rh.white -aux brain.mgz \
tkmedit your_subject_name wm.mgz lh.white -aux brain.mgz
https://surfer.nmr.mgh.harvard.edu/fswiki/BasicReconstruction

Check subcortical segmentation
tkmedit SUBJECT orig.mgz -aux-segmentation aseg.mgz

Explanation of steps of reconstruction
http://ftp.nmr.mgh.harvard.edu/fswiki/FsTutorial/MorphAndRecon


Recon-all descriptions
https://surfer.nmr.mgh.harvard.edu/fswiki/recon-all







Friday, 13 February 2015

TRACULA preprocessing

Step 1 (preprocessing)- 
  • Eddy-current compensation
  • Computing measures of head motion during the DWI scan
  • Intra-subject registration (individual DWI to individual T1)
  • Inter-subject registration (individual T1 to a common template space)
  • Creation of cortical and white-matter masks from FreeSurfer reconstructions
  • Tensor fitting for extract of tensor-based measures (FA, MD, etc)
  • Computing anatomical priors for white-matter pathways from the TRACULA atlas
Command is:

% trac-all -prep -c /home/.../config.file

Errors:
  • May get errors when trying to include all subjects in config file, couldn't figure out why so I created several config files splitting the subjects into smaller groups.
  • There may be issues with registration of the T1 to DTI data. You can check this by either overlaying the dmri/dtifit_FA.nii.gz and dlabel/aparc+aseg.bbr.nii files is fslview or freeview. Alternatively you can check the registration specifically using the command:
% tkregister2 --mov /home/.../dmri/dwi.nii.gz \
--reg /home/../dmir/xfms/anatorig2diff.bbr.dat --surf

  • There are several options for correcting a bad registration. Go into the TRACULA_OUTPUT/subject/scripts and open the trac-all.log. In there search for bbregister, keep searching until you find the bbregister command line and copy this into the command line to test on one subject only. You can substitute '--init-fsl' for '--init-header', '--init-spm' or --init-rr' (if don't have spm). I tried several options and in the end it was --init-spm that worked the best. - The command should be something like
% bbregister --s PDPLUS010 --init-header --dti --mov /home/.../dmri/dwi.nii.gz --reg /home/../dmri/xfms/anatorig2diff.bbr.dat --fslmat /home/../dmri/xfms/diff2anatorig.bbr.mat

use the command bbregister prints out to check the registration.

  • If this works and you now need to run all of the registrations again with the new option you will need to edit the trac-preproc script. Find $FREESURFER_HOME/bin/trac-preproc and copy it to your account. There you can search for '--init-header' and change this to '--init-spm'. You will also need a system administrator to copy the main trac-all script and edit this to specify that the new trac-preproc script is to be used. These edits mean that the one directory where this has been done will need to be used for all analysis, and for each command you will need to specify ./trac-all (whilst in the directory) for each command e.g.:
% ls /home/.../bbreg_TRAC
% ./trac-all -prep -c /home/config.file

  • You can now rerun the whole of the first preprocessing step again on all subjects. Check using fslview.
Step 2 (Ball and Stick model fit):
  • TRACULA uses the ball-and-stick model of diffusion to reconstruct the pathways from the DWI data. FSL's bedpostX fits the ball-and-stick model to the DWI data, estimating probability distributions of the parameters of this model at every voxel. This command will run bedpostX on the pre-processed data of all the subjects specified in the configuration file.
% ./trac-all -bedp -c /home/.../config.file
  • I did get some errors at this stage, system administrator fixed this (not sure what it was)
Step 3 (Reconstructing white matter pathways)

The final step is to generate the probability distributions for each white-matter bundles you specified in the configuration file. This is done by simultaneously fitting the shape of each pathway to the results of the ball-and-stick model of diffusion from above and to the prior knowledge of the pathway anatomy given by the set of manually labeled training subjects in the TRACULA atlas. The following command will reconstruct the probabilistic distribution of the pathways. 

% ./trac-all -path -c /home/.../config.file

  • you can check the output of the tract reconstruction either individual tracts:
freeview -v $TUTORIAL_DATA/diffusion_tutorial/elmo.2012/dmri/dtifit_FA.nii.gz \
            $TUTORIAL_DATA/diffusion_tutorial/elmo.2012/dpath/rh.ilf_AS_avg33_mni_bbr/path.pd.nii.gz:colormap=jet:isosurface=0,0:color='Red':name=rh.ilf \
            $TUTORIAL_DATA/diffusion_tutorial/elmo.2012/dpath/lh.ilf_AS_avg33_mni_bbr/path.pd.nii.gz:colormap=jet:isosurface=0,0:color='Red':name=lh.ilf
  • Or all together:
freeview -tv $TUTORIAL_DATA/diffusion_tutorial/elmo.2012/dpath/merged_avg33_mni_bbr.mgz \
         -v $TUTORIAL_DATA/diffusion_tutorial/elmo.2012/dmri/dtifit_FA.nii.gz &


  • Errors: you may find that some tracts are not reconstructed and do not show in the 3D view. I have created a separate page on how to fix this.