Sex is a biological term and gender is depended on the roles performed by an individual. In our society it is mandatory for a man or woman to behave and develop sexual preference for its opposite gender and this conservative thought process had strongly held the base of defining a sexual acts which is intended to happen between a male and female only.
However, this is not something defined by nature but by individual likeliness. This is the reason why even after being a male by sex, a male by gender can have likeliness for another male. This is something which cannot be bounded by social and cultural belief even after being into it for years.