Matteo Trentin took victory on an incident-packed stage seven of the Tour de France, as Vincenzo Nibali retained his overall lead in the general classification.