demianw / tract_querier

Implementation of the White Matter Query Language and associated tools for dMRI white matter tract extraction and analysis
Other
27 stars 27 forks source link

Avoid writing to file when filtering short streamlines #47

Open jhlegarreta opened 5 years ago

jhlegarreta commented 5 years ago

Description

tract_querier offers tools to perform streamline filtering. However, their behavior may offer room for improvement (if I am not missing anything).

If I am not mistaken tract_querier's tract_math tools require their output to be written to disk. I'd dare to say it may be worthwhile exploring the possibility of returning the filtered tractogram instead of writing it to disk.

Expected behavior

Using the tract_remove_short_tracts operation of tract_querier's tract_math tools like:

tract_math.operations['tract_remove_short_tracts'](
                my_unfiltered_tractogram, length_threshold,
                filtered_tractogram_filename)

This seems to require a filename so that the filtered tractogram is written to disk. Then users would be reading it back with

 filtered_tractogram = \
                tract_querier.tractography.tractography_from_file(
                    filtered_tractogram_filename)

I would have expected the tract_math tools to return a tractogram so that a file I/O operation is avoided.

Actual behavior

Using the tract_math tools requires writing/reading the files to/from disk.

Steps to Reproduce

Use any input tractogram and filter streamlines less than a given length using the tract_math. The tract_querier/scripts/tract_querier could be used, modifying it to call

tract_math.operations['tract_remove_short_tracts'](
                my_input_tractogram, length_threshold,
                filtered_tractogram_filename)

Reproducibility

%100

Versions

master

Environment

Ubuntu 16.04 LTS, Python 3.6.5

nibabel==2.5.1
numpy==1.17.3
scipy==1.3.2
six==1.13.0
tract-querier==0.1

Additional Information

Related to #46: to circumvent "single-point streamlines" one could think of using tract_querier's tract_math tract_remove_short_tracts operation.

demianw commented 4 years ago

Hello @jhlegarreta! Thanks for the detailed input.

Tract-math has been thought as a command-line, following after fslmath, tool and not as an API to perform python scripting hence the write-to-disk behaviour. I think that changing this will require an in-depth refactoring which is not priority with our given resources now.

I've been thinking on using click for a refactoring that would agree with what you are saying but our priority now is on improving the language core.

Pull requests are more than welcomed though, and I will be happy to work with you on it.

jhlegarreta commented 4 years ago

@demianw I see. Improving the language core will also be welcome by users :100: !

As time permits I'd love to contribute to tract_querier. I am running into a heavy workload, but at some point I'd like to give a go at some aspects that allow for improvement in this nice endeavor !