A permutation test for determining significance of clusters with applications to spatial and gene expression data