from unittest.mock import call


def fsl_cluster(finput, findex, thresh=0.9, fosize=None, fothresh=None, **kwargs):
    """
    Run FSL Cluster command (https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Cluster)
    :param str finput: Input filename, image to be thresholded
    :param float thresh: Chosen threshold; default = 0.9
    :param str findex: Output file with each cluster assigned an integer from 1 to N
    :param str fosize: Output file with each cluster voxel assigned an integer equivalent to its cluster size
    :param str fothresh: Output file with clusters assigned the original values (only > threshold remain)
    :return:
    """
    # First try to run standard spherical project
    osize = "--osize={}".format(fosize) if fosize is not None else ""
    othresh = "--othresh={}".format(fothresh) if fothresh is not None else ""
    fsl = "cluster --in={} --thresh={} --oindex={} {} {}".format(finput, thresh, findex, osize, othresh)
    print("Running command: {}".format(fsl))
    code_1 = call(fsl, **kwargs)
    return code_1