Analysis scripts for figures 1ab 2ab