counting adapted fom rnacounter.cc