Nipythonic way to use text file (waytotal) as input for fslmaths

I wanted to use one of the output files from probtrackx ( waytotal ) to threshold the fdt_paths.nii.gz

What’s the cleanest way to read the output of the waytotal file and then make it an input for fslmaths…

myworkflow.connect( ‘pbx’,‘waytotal’, ‘fslmaths’,‘Threshold’,‘thresh’)

but in this case, the output from pbx is a file (waytotal) and not a float, which is what the fslmaths–>Threshold wrapper wants.

Is there already a built-in helper function that will take as an input a single one line text file and output the value as a float or do I have to roll my own?

Hi @dagutman, I’m not aware of such a function. But you can create a simple function like:

def reader(file):
    with open(file) as f:
        text = f.read()
    return float(text)

or similar. And use the nipype Function interface to create an extra node, here you can find some examples.