Robust comparative analysis and contamination removal for metagenomics