finished function to compute the affinity matrix
cleaning the working directory