Clustering with flexible constraints and application to disease subtyping