a complete script for subsampling