Obama says transgender bathroom directive based on law