#!python

import subprocess, os, eaglec, zipfile, sys

def download_and_unzip(subfolder, link):

    root_folder = os.path.join(os.path.split(eaglec.__file__)[0], 'data')
    if not os.path.exists(root_folder):
        os.mkdir(root_folder)
        
    outzip = os.path.join(root_folder, '{0}.zip'.format(subfolder))
    command = ['wget', '-O', outzip, '-L', link]
    subprocess.check_call(' '.join(command), shell=True)
    with zipfile.ZipFile(outzip, 'r') as zip_ref:
        zip_ref.extractall(root_folder)
    
    os.remove(outzip)

weblinks = {
    'bulk': 'http://3dgenome.fsm.northwestern.edu/eagleC/model/bulk.zip',
    'single-cells': 'http://3dgenome.fsm.northwestern.edu/eagleC/model/single-cells.zip'
}

for subfolder in weblinks:
    download_and_unzip(subfolder, weblinks[subfolder])