daducci / COMMIT

Linear framework to combine tractography and tissue micro-structure estimation with diffusion MRI
Other
43 stars 33 forks source link

[fix] tckedit command in Wiki is too long #109

Closed smeisler closed 2 years ago

smeisler commented 2 years ago

Hi,

In the COMMIT 2 wiki when one is getting the tractogram that only has connecting fibers in the connectome, the tckedit command string is very long when using an atlas with a large amount of nodes (number of inputs is scaled by n^2). Many terminals will not be able to handle a string that large.

However, tckedit accepts wildcard operators, so the code block that looks like:

CMD = 'tckedit -force -nthreads 0'
for i in range(C.shape[0]):
    for j in range(i,C.shape[0]):
        if C[i,j] > 0 :
            CMD += ' bundles/bundle_%d-%d.tck' %(i+1,j+1)
os.system( CMD + ' demo01_fibers_connecting.tck' )

can simply be changed to:

os.system('tckedit -force -nthreads 0 bundles/bundle*.tck demo01_fibers_connecting.tck' )

Hopefully this helps, Steven

daducci commented 2 years ago

Hi @smeisler ,

the code in the tutorial is just one way of achieving the grouping needed by COMMIT2, and we opted for this solution as it uses MRtrix which is widely used. I a not sure if your fix works as it is, because we need to group the streamlines in a given order and I am not sure what is the actual ordering when using the wildcards. But thanks for the solution, we will investigate it and run some tests! Stay tuned and thanks again :-)

smeisler commented 2 years ago

Ah I see. Upon further inspection, indeed just using a single wildcard will result in the order not being correct. However, perhaps looping over just the i elements and using a wildcard for j will work? E.g.:

CMD = 'tckedit -force -nthreads 0'
for i in range(C.shape[0]):
    if C[i,j] > 0 :
        CMD += ' bundles/bundle_%d-*.tck' %(i+1)
os.system( CMD + ' demo01_fibers_connecting.tck' )

At least in this way, fibers will be grouped by their node1 assignment.

Appending 0s to node numbers would also help the wildcard approach (e.g. bundles_001-020 instead of bundles_1-20 but this was a MRtrix command so I am not sure it would be possible to change that or if it would have bad downstream effects.

MarioOcampo commented 2 years ago

Hello, Using a wildcard for j may also create tractograms with an incorrect order. But, using a similar approach, a solution can be to create the tractogram in two steps.

  1. Creating a tractogram_i for each row i
  2. Merge all tractogram_i
CMD = 'tckedit -force -nthreads 0'
for i in range(C.shape[0]):
    CMD_i = 'tckedit -force -nthreads 0'
    for j in range(i,C.shape[0]):
        if C[i,j] > 0 :
            CMD_i += ' bundles/bundle_%d-%d.tck' %(i+1,j+1)
    os.system( CMD_i + ' bundles/demo01_fibers_connecting_%d.tck' % (i+1) )
    CMD += ' bundles/demo01_fibers_connecting_%d.tck' %(i+1)
os.system( CMD + ' demo01_fibers_connecting.tck' )

Let us know if this avoid the problems with the terminal.

Best Mario