def get_idx(in_files, stop_idx=None, start_idx=None):
    """
    Method to get the first and the last slice for
    the functional run. It verifies the user specified
    first and last slice. If the values are not valid, it
    calculates and returns the very first and the last slice

    Parameters
    ----------
    in_file : string (nifti file)
       Path to input functional run

    stop_idx : int
        Last volume to be considered, specified by user
        in the configuration file

    stop_idx : int
        First volume to be considered, specified by user
        in the configuration file

    Returns
    -------
    stop_idx :  int
        Value of first slice to consider for the functional run

    start_idx : int
        Value of last slice to consider for the functional run

    """
    from nibabel import load
    img = load(in_files)
    hdr = img.get_header()
    shape = hdr.get_data_shape()
    if len(shape) != 4:
        raise TypeError('Input nifti file: %s is not a 4D file' % in_files)
    nvols = int(hdr.get_data_shape()[3])
    if start_idx == None or start_idx < 0 or start_idx > nvols - 1:
        startidx = 0
    else:
        startidx = start_idx
    if stop_idx == None or stop_idx > nvols - 1:
        stopidx = nvols - 1
    else:
        stopidx = stop_idx
    return stopidx, startidx
