We develop a ’higher genus‘ analogue of operads, which we call modular operads, in which graphs replace trees in the definition. We study a functor $F$ on the category of modular operads, the Feynman transform, which generalizes Kontsevich‘s graph complexes and also the bar construction for operads. We calculate the Euler characteristic of the Feynman transform, using the theory of symmetric functions: our formula is modelled on Wick‘s theorem. We give applications to the theory of moduli spaces of pointed algebraic curves.