Main analysis and plotting script