def wcs_axis_to_data_axis(wcs_axis, missing_axes):
    """
    Converts a wcs axis number to the corresponding data axis number.
    """
    if wcs_axis is None:
        result = None
    else:
        if wcs_axis < 0:
            wcs_axis = len(missing_axes) + wcs_axis
        if wcs_axis > len(missing_axes) - 1 or wcs_axis < 0:
            raise IndexError('WCS axis out of range.  Number WCS axes = {}'
                .format(len(missing_axes)))
        if missing_axes[wcs_axis]:
            result = None
        else:
            data_ordered_wcs_axis = len(missing_axes) - wcs_axis - 1
            result = data_ordered_wcs_axis - sum(missing_axes[::-1][:
                data_ordered_wcs_axis])
    return result
