Despite persistent efforts over the last century, a theory for predicting the effects of surface roughness on the mean flow is still missing. Here, we extend a recently proposed multi-state theory to incorporate roughness effects. A formula for the roughness function is constructed by applying the Lie-group invariance theory, giving excellent agreement with the fully collapsed data of both the Nikuradze sand-coated and Princeton honed pipes. A major advantage of the theory is its ability to successfully describe the non-universality-either inflectional or monotonic variations-in a transitionally rough regime with a single sharpness parameter. This model then yields an analytic prediction for the friction factor and mean velocity profiles in rough pipes, agreeing with the empirical data. Consistent with classical understanding (e.g. Townsend's similarity hypothesis), our results confirm the multi-layer theory of wall turbulence, regardless of smooth or rough surfaces.