SHEAR: sample heterogeneity estimation and assembly by reference