Saturday 14 July 2012

Transferring MRI data

1) Transferring from the scanner

On the scanner console, when all images in an exam have been collected and you are removing the participant from the scanner, make sure you press the "End Exam" button. This guarantees that all the images you require have been finally written to the internal GE database. Then, from a terminal window in the console, type; copydicom The copydicom script will get run overnight by the scanner, but it is good practice to transfer the data as soon as the exam is finished.
 The script will identify any MRI exams that have not previously been transferred to the CUBRIC cluster file-system (such as the one you have just collected). Note that the exam must be finished before you press this button. Otherwise, additional copies of the exam will end up in the database - which can cause confusion (but will only lead to duplication, rather than a loss of data).
When the command has finished, your images have been packaged up and transferred to the CUBRIC cluster file-system. Note: A typical fMRI experiment may consist of several tens of thousands of images. In the standard DICOM database, each of these images are stored in a separate file. This can be very inefficient, both in terms of file transfers and load on the linux file-system. So, we have taken the decision to package up all the images from an Exam in a single archive file, which is also compressed.  In CUBRIC parlance, this is known as a dicball/tarball.

2) Unpacking Scanner DICOM data

(Note, steps 2 and 3 can be done using the Studies database https://studies.cubric.cf.ac.uk).

Log in to your normal user account on the CUBRIC  system. All dicballs are transferred to the same location, namely: /cubric/mri/direct_transfer/YYYY
where YYYY represents the year of the scan. Dicballs have fairly obscure names, which contain the name and time that the exam started. If you type the following command you will see all the  dicballs currently in the database, sorted so that the last file listed is the last one to be transferred. ls -lrt /cubric/mri/direct_transfer/2012
Here is a typical listing from our database:

2012-07-19-16-35-54-e2357712.tgz
2012-07-19-18-21-53-e2390174.tgz
2012-07-20-08-02-36-e2404155.tgz
2012-07-20-08-08-30-e2404166.tgz
2012-07-20-09-04-34-e2404178.tgz
2012-07-20-10-02-49-e2404274.tgz

To locate a dicball based on the Exam number, use  seriesinfo
e.g.
sapje1@daws15:/cubric/users/sapje1$ seriesinfo 9319
------------------------------------------------------------------

                   REL Study ID//9319 (Exam No)
             DICOM Data Tarball//2013-07-22-08-13-44-e4568456.tgz
               PAT Patient Name//dailyqa 
          PAT Patient Birthdate//
            ID Acquisition Date//20130722
            ID Acquisition Time//075619
              ACQ Protocol Name//dailyQA_2012b/1 
1 // fgre // loc
2 // fgre // ASSET cal
3 // epiRT // EPI TR=3 64x64, 360FOV,no ASSET, no FATSAT
4 // epiRT // EPI QA 10min
------------------------------------------------------------------
This lists the tarball name, time, date and participant ID, and limited information about the series run during the acquisition (pulse sequence name and series description).

3) Unpacking a dicball
 Once you have found the you file you need to unpack, you next have to decide where you want to put the unpacked and processed data. Let's suppose you are doing a project on Widget Perception and the dicball contains data from your subject 23. In your home directory, you probably want to create a directory called Widget, and then sub-directories called Subject23 etc. i.e.:
mkdir Widget
cd Widget
mkdir Subject23
cd Subject23

Now you are in the new directory, you can unpack the dicball using the sortdicomball command. sortdicomball  e.g.
sortdicomball /gpfs/mri/direct_transfer/2007/2007-12-11-10-38-33-e99743.tgz .  
(don't forget the trailing full stop)

This will unpack the selected dicball archive into the current directory. It will create a new sub-directory based on the patient and exam id. If you cd into this, you will see a set of subdirectories e.g.: Series_00001    
Series_00002    
Series_00003 .......

Remember : you need to give the full path to the location of the dicball! 

Alternatively, you can use  tarball.unpackdicom
e.g.
tarball.unpackdicom /cubric/mri/direct_transfer/2013/2013-07-29-15-54-26-e5048388.tgz
(note this unpacks to current directory, and no trailing full stop)
This names the series directory according to the series number + pulse sequence.
e.g. 
1_fgre
2_fgre
3_efgre3d
403_epi2cje032
4_epi2cje032

 4) Converting Dicom data to NIFTI/Analyze format

Each of the above sub-directories contains the Dicom files for one of your series, which you now need to convert into NIFTI files for analysis. Let's suppose Series_00003 contains the data for a functional experiment in which there are 37 anatomical slices collected every TR for 200 volumes.
Here's how you would convert the data using the command geprepfunct:
cd Series_00003
geprepfunct 37 200 widget_sub23_run1
This will create a 4D NIFTI file, called widget_sub23_run1.nii.gz , suitable for analysis with FSL or CUBRIC's other software packages.
You need to change the 3 parameters on the geprepfunct command line to match your data. 
Alternatively, if you can't do the sums to work out number of slices/volumes, use dcm.geprepauto which gets the number of slices from the dicom header, and calculates the number of volumes based on the total number of images in the directory.
e.g.
dcm.geprepauto widget_sub23_run1

5) Converting Structural (FSPGR) data for MEG or FreeSurfer 

Note that, for the analysis of anatomical data to be used for MEG or , we no longer recommend the use of geprepfunct. If your data is a MEG anatomical scan (i.e. one volume) you should instead use the dic2mri command. Note that the dicom files for the series will be packed up into an archive called sorted.tar.gz in the Series_XXXXX sub-directory. Note that these are a copy of the original dicom files stored in the dicball. As such you can go ahead and delete sorted.tar.gz, when you feel ready and comfortable!
One data management strategy that seems to work well is to create a directory, at the same level as the Series_XXXX directories, to hold all your NIFTI files. You can then move all the NIFTIs to this subdirectory using the following:
mkdir NIFTI
mv Series_*/*.nii.gz NIFTI/
Importantly, the NIFTI files must all have different filenames, or they will overwrite each other. Now you are ready to do your analysis...
Note: geprepfunct only generates NIFTI files if this is the default output type for FSL. If the FSLOUTPUTTYPE environment variable is set to ANALYZE, then this is the type of file that will be created. CUBRIC users have NIFTI set to be the default. Converting to Anatomical scans for MEG Follow the Instructions above on using sortdicomball/whodicball Find the dicom series with about 170 .dcm files..this is probably the anatomical scan.
Then run the dic2mri command in that directory. If you have queries about the commands mentioned here, you should contact the authors: copydicom.sh : Spiro lastdicball: Krish whodicball: Krish sortdicomball: Krish geprepfunct: Krish dic2mri: Krish