Skip to content

Best Templates for MAGeT

Eduardo Garza edited this page Feb 5, 2016 · 22 revisions

Until there is a simpler solution, this is a good way of finding the best template brains for your sample. This tutorial was made from pieces of emails and chats with Matt Park, Raihaan Patel and Gabriel Devenyi.

A summary of the steps required:

  1. Label ~100-200 possible template brains using the 1st stage in MAGeT brain (simplified or morpho branches). It will do 1_register & 2a_resample labels which are simply atlas-to-template registrations.
  2. Make QC images for each atlas to template combination, resulting in ~500 QC images, ~100 per atlas (if you have 100 template brains).
  3. Quality control the templates for each atlas registration.
  4. Choose the best atlas to template registrations, and use them as template brains.

Now here it is step by step:

STEP 1 > Atlas-to-template registrations

Make sure you are in a node $ gpcdev and that you have loaded the scinet module $ module load scinet.

Create a new directory wherever you want. Let's call it best_template

mkdir best_template

Create the MAGeT structure inside the folder input as if you were performing MAGeTbrain or MAGeTmorph.

This step involves changing the mb script structure, therefore, you need to be careful not to change anything else.

Go to your MAGeTbrain directory and inside the folder bin you will find the script mb. Make sure you decide on either the simplified or the morpho branch, because the paths are slightly different. I suggest using the simplified branch.

There are many ways to edit the mb script, I use nano. Write nano mb and click Enter. Once you are editing the file, click ctrl + w to find a text line (2 text lines if you are using the morpho branch), and comment them out (add # at the beginning):

p.queue.append_commands(STAGE_VOTE, [commandline]) (only simplified)

and

p.queue.append_commands(STAGE_MORPHO, [commandline]) (only for morpho)

Example (in simplified):

# p.queue.append_commands(STAGE_VOTE, [commandline])

Click ctrl + x to exit, then you will be asked if you want to save, click Y for yes and enter the same name.

Go back to your best_template directory and run $ mb run as normal. It will take about ~12 hours to run (I haven't checked exactly).

In your best_template directory, there will be the logs and output directories.

STEP 2 > Create the QC images

Check inside output that you have the folder registrations with one folder per atlas (i.e. brain1_t1) and inside one folder per template (subject1, subject2, etc.). Inside each template folder you will find several xfm and mnc files.

To create the QC images, copy either one script inside the best_template folder:

If used simplified: cp -v /scratch/m/mchakrav/patelmo6/generate-template-label-jobs-simple.sh .

if morph: cp -v /scratch/m/mchakrav/patelmo6/generate-template-label-jobs-morph.sh .

Run the script ./generate-template-label-jobs-simple.sh. (make sure you run it inside the best_template folder).

This will create a file 2a_template_labels_jobs. Check it with nano and make sure it is a set of mincresample jobs on your data.

Run the jobs qbatch 2a_template_labels_jobs 100 2:00:00

STEP 3 > Check the QC of the images

You will find the QC images in /output/labels/brain1/template1/labels.mnc. Download them and check them using Display or Register.

STEP 4 > Choose the best templates

Here is the tricky thing. The goal is to find images from your dataset that had good labels from each of the 5 brains, or as many as possible.

Example:

You are using the Hippocampus atlas brains and labels (5). Check each label file (registration) starting with brain1, then eliminating "bad" templates sequentially:

brain1: 30 fails -> 70 remaining

brain2: 20 fails -> 50 remaining

brain3: 15 fails -> 35 remaining

brain4: 10 fails -> 25 remaining

brain5: 3 fails -> 22 remaining -> take 21 from here, use as final template library.

Some TIPS from the CobraLab Crew.

These tips may help you decide which are the best templates. It is not a standardised method yet, but it will make your labelling for MAGeT much better.

Here is a quote from Matt himself:

"I've found this approach works very well with datasets that don't match/register very well to our atlases & significantly improves overall segmentation accuracy. I don't even check the demographic/DX spread of the resulting template library, but in cases where there is significant degen. (i.e. large ventricles)- I try to choose "intermediate"-anatomy subjects (as in intermediate anatomy/ventricle size between our atlases & heavily degen. subjects) that pass template QC. This approach was especially effective for ADNI1/ADNI2GO- I specifically chose ~200 candidate subjects, that were either MCI or AD within ADNI1/ADNI2GO- only ~25-30 from the initial 200 passed all pairwise atlas-to-template QC (just out of pure chance, really). Chose the final 21 from these, and the final subject labels were freakin excellent, to the point that they almost did not need QC-ing for the hippocampus.

For example, let's say (after template QC) you end up with the following template candidates:

20 subjects with small ventricles: pass 10 patients with medium-sized ventricles: pass 3 patients (out of maybe ~20) with large ventricles: pas

Here, I would try to choose subjects from the latter two (10 + 3) and 8 from the small ventricle group- that way, you get optimal "matching" between templates and subjects, pairwise amongst all "subtypes" of anatomy present in the dataset. It's difficult to do in small samples (limited N), but I find that even proceeding with simply controls (small ventricles) that pass QC still works reasonably well, as you're still minimizing error at the template stage & templates generally register quite well to subjects since they're usually from the same acquisition."

Here is a quote from Raihaan:

"One thing to note is that these are labels produced from a single atlas registration, so the overall quality will be noticeably poorer than final maget output. So your definition of 'good' will likley be more lenient than if you were qcing final maget output. I usually find a distribution in quality when I do this, and I just try to take the nicest ones. Sometimes the nicest ones are great, and sometimes the nicest ones are not so great but they are the best I have."

Clone this wiki locally