Deep-MI / fsqc

A set of quality control scripts for FreeSurfer- and FastSurfer-processed structural MRI data

Home Page:https://deep-mi.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unbuntu terminal frozen while encounter issue with surface overlaid

XinQi7788 opened this issue · comments

Hi Kersten:

I am using the latest updated qatools-python, but encountered the same “a problem occurred with the surface overlays” issue while running some ANDI T1w images on a ubuntu machine.

When I noticed the “A problem occurred with the surface overlays” message, I clicked Control + C, then clicked Enter, the program kept running the rest of list of images.

Here are examples of image lists make the Linux terminal froze while running qatools-python.
ADNI_011_S_0022_I32389
ADNI_033_S_0739_I119135
ADNI_035_S_4082_I296308

Can you please share a link that I can upload FreeSurfer results of those images?

Looking forward to your reply

Xin

Hi, I think that the previous upload link should still work; let me know if I should send it again. Thanks, Kersten

Hi Xin,

thanks for the upload! I ran these files, and have to admit that I could not see any problem with them. So the issue remains a mystery to some extent.

But maybe your Docker suggestion could also help with that: it's not only nice for parallelization, but also provides a more controlled environment with regard to other libraries etc., which may be a source of this error.

So it should be worth giving it a try. I still need to create a DockerFile / image; this could be done until the end of the week, I suppose.

Best, Kersten

Hi Xin,

thanks for the info and for uploading the output - that was indeed helpful!

I have to admit that I was looking in the wrong place at the first, i.e. the screenshots and surface overlays within the 'screenshots' module. However, this module is also called from the 'fornix' module for visualization, and this is where the error occurs. I.e. I now could replicate the problem (we're entering an infinite loop); fixing it, as far as I can tell at the moment, will be straightforward.

Will upload a fix until Monday.

Best,

Kersten

Hi, the infinite-loop issue is hopefully fixed now; I am leaving the issue open, though, for the docker file, which is in the works. Will update soon.

Best, Kersten

Hi, I've added a Dockerfile including a new page for documenation.

Best, Kersten

Hi Xin,

there are some "expert options" within the script, which are a little bit hidden at the moment, and the "--screenshots_views" option may provide what you are looking for. Coordinates should be in FreeSurfer's RAS system.

Therefore, before making changes to the code, my suggestion is to give it a try and see if and how it works. If this is not what you are looking for, let me know.

Take a look at the help section in the qatoolspython/qatoolspython.py script, around lines 163 ff. currently, for some details.

Best regards,

Kersten

Hi Kersten:

Happy New Year of 2022!

I tried the --screenshots_views with different x, y, z locations that works well. Thank you so much!

However, if I would like to change the --screenshots_base to some image, such as hypothalamic_subunits_seg.v1.mgz, how to make it for a list of subjects, not just a single one.
Here is the ERROR if using –subjects-file flag along with –screenshot_base.

ERROR: can only use the --screenshots_base argument for a single subject, which must be specified using –subject

Looking forward to your reply.

Best Regards
Xin

Can we create screenshots with a html file of hypothalamic subunits for a list of subjects? Just similar like for fornix by adding flag as --fornix --fornix-html?

Thank you very much.
Xin

Happy New Year to you, too!

I have to admit that the current behavior of --screenshots_base when processing multiple subjects is to some extent the expected behavior; this argument was intended to allow for greater customization of the screenshots module when used as a stand-alone tool, and initially I did not want to make the assumption of identical filenames and identical (relative) path names of custom base images for multiple subjects. Without identical file and path names, specification of these images on the command line would require a long list of inputs and this would be rather cumbersome. The same logic applies to the --screenshots_surf and --screenshots_overlay arguments.

The workaround at the moment is of course to use the tool in single-subject mode, but I see that this may not be ideal either. And I see that in some scenarios the assumption of identical file / path names across subjects may be justified, and in the end I can still check for presence of the given file.

If I understand correctly, your idea is to create semi-transparent, colored masks of the hypothalamic subunits, possibly with a contour, and overlay them onto (a part of) the anatomical image, is it? I guess it would also make sense for the subfields of hippocampus and amygdala, for which dedicated toolboxes also exist. In principle this can be done, but as far as I can see at the moment, it is slightly more complicated than the CC / fornix module, because we need a heuristic to find good coordinates where to do the screenshots, for example.

Let me give it a try for both 1. and 2., I'll see if it's feasible and get back on the issue. WIll take ~ 1-2 weeks, I guess.

Best regards, Kersten

Thanks, Kersten for such a quick reply!

Yes, all your understandings are correct!

For no. 2 request, to find a good coordinates, just like the current version, to give a --screenshots_views with x, y, z coordinates that could be customized by user along with corresponding --screenshots_layout, that would be useful.

It would be great that such screenshots with a html file functionalities for the subfields of hippocampus, amygdala, thalamus and hypothalamus exist in the toolbox.

Best Regards
Xin

Hi Xin,

I've uploaded a new version with some modifications for requests 1. and 2.

The --screenshots_base argument offers more flexibility now, i.e. can use any volume file within the <SUBJECTS_DIR>//mri directory; must have the same name across subjects. If files have different names across subjects or are not stored within each subject's mri subdirectory, then the program must be used in single-subject mode. I've written an explanation in the qatoolspython.py help section, but would like to keep them as 'expert' options for a while before fully documenting them (e.g. in the README.md).

Also, I've added --hypothalamus / --hypothalamus-html options. They work just like the fornix module. Coordinates for display are not required, but chosen based on the centroids of the subregions. Similiar to the above, I would like to keep them as 'expert' options for a while before fully documenting them (e.g. in the README.md); they should not interfere with other processing. Maybe try it out, and if you have any suggestions, let me know. For example, maybe croppping of the images might make sense.

Similar modules for the hippocampus and thalamus will likely be added within approx. 2 weeks.

Best, Kersten

Hi Kersten:

Thank you so much for improving the tools with our requests. Very appreciate!
I will test the new functions soon and let you know.

Best, Xin

Hi Kersten:

The outlier module is to detect extreme values among the subcortical ('aseg') segmentations. Is it possible to include another outlier modules to detect extreme values of hypothalmus, fornix, hippocampus and thalamus segmentations?

Thank you very much.

Best, Xin

  1. The screenshots on hypothalamus.png are too small to visualize. I agree that maybe cropping of the images might make sense. The size of screenshot on fornix looks good.
  2. Only the first screenshot has the hypothalamus overlay. Can we have different cuts/orientation views only focused on hypothalamus region?
  3. New modules of large ROIs with different cuts / views on hypothalamus, thalamus, hippocampus, amygdala?

Thank you very much.

Best, Xin

Hi Xin, thanks for your helpful feedback. I'll push some updates during the next days:

  1. I agree that using a cut-out is a better idea than using the full image. Will implement this.
  2. Just to confirm, because I didn't see this during testing: only the first image shows the hypothalamus labels, the others just show the background image, even if enlarged? Will also check this.
  3. Yes, new modules for hippocampus/amygdala and thalamus are also planned. Will take around 1 week per module.
  4. Including the ROI segmentation stats in the outlier module is also a good idea. I'll put that on the list.

Best, Kersten

Hi Xin,

I've made some changes and additions to the toolbox as discussed before. Specifically, I've addressed issues 1, 2, and partially 3 (only the hippocampus module) from the above list. Looking forward to your feedback (for example, do the views / sections of the hypothalamus and hippocampus/amygdala make sense, or should we add additional ones, or change the cut-out, etc.).

Please note that I've created and made the additions to a new freesurfer-module-dev branch (as opposed to the default freesurfer-module-releases branch), since there may be more additions and revisions in the future.

Eventually I will merge new content from freesurfer-module-dev branch to freesurfer-module-releases, but until then, please take care to download / checkout the freesurfer-module-dev branch for testing purposes.

Best,

Kersten

Hi Kersten:

Thank you for updates!
I cloned the freesurfer-module-dev branch for testing now and will let you know how the screenshots looks like later.

After adding flags of --hippocampus --hippocampus-html --hippocampus-label, the error shows as below.
qatools.py: error: unrecognized arguments: --hippocampus --hippocampus-html --hippocampus-label

Best
Xin

Hi,

just to make sure: does a git status command show that you are on the dev branch? If not, please use git checkout freesurfer-module-dev to switch to that branch.

Thanks, Kersten

Sorry, my mistake! I am testing using the freesurfer-module-dev now... so far looks fine. I will share more feedback later.

Thank you very much.
Xin

Hi Kersten:

The screenshots of subfields of hypothalamus, hippocampus/amygdala look very nice. After my consulting with my colleague, if any additional cut-outs are suggested, I will let you know. Thank you so much for implementing it.

Best
Xin

Hi Kersten:

Below are some questions and Error message encountered while testing on the hypothalamus screenshot module.

  1. For the screenshots of hippocampus/amygdala, hypothalamus, et al, are those cuts at the same location? (Is this standard MNI space or subject space?).

  2. When only use --hypothalamus --hypothalamus-html, such as for ~1700 subjects's IDs are listed inside the subjects-file, but only 8 subjects' screenshots are created inside the html file although the hypothalamus.png of each subject is created inside the hypothalamus folder.

  3. After the last subject's processing is done, got TypeError is shown as below. I guess it is maybe because there are some empty space at the bottom of the list of subjects-file, such as subjectID.txt.
    Traceback (most recent call last):
    File "qatools.py", line 7, in
    _qatools()
    File "/home/Xin/qatools-python-freesurfer-module-dev/qatoolspython/qatools_cmd.py", line 17, in _qatools
    qatoolspython.run_qatools(subjects_dir, output_dir, subjects, subjects_file, shape, screenshots, screenshots_html, screenshots_base, screenshots_overlay, screenshots_surf, screenshots_views, screenshots_layout, fornix, fornix_html, hypothalamus, hypothalamus_html, hippocampus, hippocampus_html, hippocampus_label, outlier, outlier_table, fastsurfer)
    File "/home/Xin/qatools-python-freesurfer-module-dev/qatoolspython/qatoolspython.py", line 1457, in run_qatools
    _do_qatools(subjects_dir, output_dir, subjects, shape, screenshots, screenshots_html, screenshots_base, screenshots_overlay, screenshots_surf, screenshots_views, screenshots_layout, fornix, fornix_html, hypothalamus, hypothalamus_html, hippocampus, hippocampus_html, hippocampus_label, outlier, outlier_table, fastsurfer)
    File "/home/Xin/qatools-python-freesurfer-module-dev/qatoolspython/qatoolspython.py", line 1418, in _do_qatools
    print("

    <a href=""+os.path.join('hypothalamus', subject, os.path.basename(imagesHypothalamusDict[subject]))+"">"
    File "/home/Xin/miniconda3/lib/python3.8/posixpath.py", line 142, in basename
    p = os.fspath(p)
    TypeError: expected str, bytes or os.PathLike object, not list

Best Regards.
Xin

Hi Kersten:

To following the above item 2 and 3.

For 2, I tested again, got the same result, only 8 subjects screenshots are shown inside the hypothalamus html file
For 3, the empty space at the bottom of the subject-file are moved, so the last line of the list is a subject ID, but still received the same error as above.

Looking forward to your reply.

Best
Xin

Hi Xin,

thanks for your message. Some external, large-scale testing is really helpful, because I do not necessarily see all issues with my tests.

Re 1: The screenshots for Amygdala/Hippocampus and Hypothalamus are roughly the same (=equivalent) location. I am using the centroids of (a selection of) subfields / subregions to define the views. In that sense, I believe they are roughly comparable across cases, eventhough everything still remains in native space.

Re 2&3: I believe those issues are related. I speculate that the hypothalamic module for your subject no. 9 failed for some unknown reason (why would be interesting to know), and I did not catch this properly for the creation of the html overview. I have uploaded a fix to the dev branch, and hope it's working now.

Thanks, Kersten

Hi Kersten:

Thank you so much for a quick reply and update!

I started to test the new uploaded dev branch and will let you know how it goes sometime later tomorrow.

BTW, for the subject no. 9, how did you know it is no. 9 and what is its ID if you can tell? The no. 9 subject on the list, its hypothalamus screenshot looks fine to me.

Best, Xin

Great, thanks.

I am speculating it's subject no. 9 because apparently the preceding 8 cases went through properly. And I could reproduce the reported error by making one of my test cases failing the hypothalamus module, which later caused the html generation to terminate while processing this particular case. There might still be another reason, but at least that's my current hypothesis. Note that in the html output the subjects are sorted alphanumerically, so if your list isn't sorted or sorted differently, this might explain why your no. 9 (from the list) appears to be OK. The ID I can't tell, sorry.

Best, Kersten

Hi Kersten:
The failed hypothalamus screenshot case is identified. Here its result is attached. Maybe you can figure out why :).

The new version works well. On the html file, the failed case only shows the subject ID without breaking the processing keeping going. Thank you very much!.

Best, Xin
Hypothalamas_screenshots_Failed.zip

Hi Kersten:

So far, the qatools-python works well in processing the subjects sequentially. Each subject takes about 7-14 mins according to different computer configs ( I am using 4-core CPU now), but to process thousands of subjects, it takes many days or weeks to get it done. Especially the outliers, html files to make the final processing above the all subjects' processing are done. If we would like to to conduct parallel computing on each subject, then integrate all the subjects results to get outliers, html files et al, do you have suggestion on how to use the toolkit?

Looking forward to your reply and thank you very much!

Best, Xin

Hi Xin,

thanks, and good point; I think there are two potential solutions: one would be to selectively switch off (parts of) components that are not strictly necessary, but take a lot of time. Generally, screenshots do take some time, and also the surface / contour overlays need some time to be computed. I would need to take a closer look in the next days how much time actually, and if there is potential for saving time without sacrificing too much information. The other potential solution of course is parallelization; here, the easy-to-implement solution would be to start multiple instances of the program at the same time, and in the end have another single run to integrate all existing results. In contrast, full parallelization within a single run of the program might take some more implementation effort. I will think about during the next days, and get back to you.

Best, Kersten

Hi Kersten:

Thank you so much for the update. The other potential solution sounds good to me.

Also, Can qatools-python provide cortical parcellation screening shots and numerical outliers of the cortical parcellations as well? This is more important than parallelization requests currently :).

Best Regards
Xin

Hi Xin,

I've adapted the outlier module to include cortical, hippocampal/amygdalar, and hypothalamic values, and have uploaded a new version to the dev branch for evaluation purposes. The parallelization enhancement remains on the TODO list, and so do the brainstem and thalamus extensions. Cortical screenshots will require some time, because there is little existing to code to build upon at the moment.

Best,
Kersten

Hi Kersten:

Thank you for your so quick feedback. I have started to test the updated outlier module and will let you know how it goes.

Best,
Xin

Kersten:

For the normative values taken from the literature (see References) when calculating normative values of outliers, can you please tell which references from the citations are? Thanks a lot.

The normative values are derived from:

Potvin O, Mouiha A, Dieumegarde L, Duchesne S, & Alzheimer's Disease Neuroimaging Initiative; 2016; Normative data for subcortical regional volumes over the lifetime of the adult human brain; Neuroimage: 137, 9-20; doi.org/10.1016/j.neuroimage.2016.05.016

The normative values are derived from:

Potvin O, Mouiha A, Dieumegarde L, Duchesne S, & Alzheimer's Disease Neuroimaging Initiative; 2016; Normative data for subcortical regional volumes over the lifetime of the adult human brain; Neuroimage: 137, 9-20; doi.org/10.1016/j.neuroimage.2016.05.016

Thanks, Kersten!
From the outlier results, it is easy to get more false-positive outliers compared to a visual read from our experience so far.

Best, Xin

Hi Kersten:

For different surfaces views, there are no --surfaces_views and --surfaces_layout flags.

There are only 4 views of surfaces in the html file. Can we have different views of surfaces like the screenshots_view as below ? Thank you very much.

This is only for different screenshots views as below.
--screenshots_views x=-30 x=-20 x=20 x=30 y=-30 y=-20 y=-10 y=0 z=10 z=30 --screenshots_layout 2 5

Best regards
Xin

Hi Xin,

thanks for your message. I am not sure that a --surface_views argument is really meaningful, since we are looking onto a 2D surface, as opposed to slices through a volume. In particular, slicing through the surface might just give its boundary contours. So I am a bit hesitating to implement a solution with arbitrary coordinates. But I am happy to discuss.

One potential improvement, however, could be (optional) views from top and bottom, and front and back - i.e. to add more fixed viewing positions.

Best regards, Kersten

Hi Kersten:

For the surface views, can we have 6 views of left_lateral, left_medial, left_transverse, right_lateral, right_medial, and right_transverse? And I am not sure inflated view are useful for us.

Here is an example created by using another tool for your reference, but we would like to use qatools-python alone to get surface and volume screenshots with a html file.

Looking forward to your reply and thank you very much for your always help!
surface_views_example.zip

Best Regards, Xin

Hi Kersten:

No need to spend time revising the surfaces screenshots. The current version is fine. Thank you so much!

Best, Xin