Kernels and ranks of cyclic and negacyclic quaternary codes