code for manipulating mapping files and distance matrices