Pattern-based permutation statistics and code transforms