German pharmaceutical giant Bayer said it will buy the US-based biotech firm for as much as $4 billion as it aims to get a foothold in the rapidly growing gene-therapy market.