Porting the original shell script pipeline to python