import os
import json

conditions = {"TH779_CKDL230030157-1A_HJLFCCCX2_L8_mm10":"TH779_WT-H3K9me3",
        "TH780_CKDL230030157-1A_HJLFCCCX2_L8_mm10":"TH780_Dnmt-TKO-H3K9me3",
        "TH781_CKDL230030157-1A_HJLFCCCX2_L8_mm10":"TH781_Tet-TKO-H3K9me3",
        "TH782_CKDL230030157-1A_HJLFCCCX2_L8_mm10":"TH782_Dnmt-TKO_and_Tet-TKO_C5",
        "TH783_CKDL230030157-1A_HJLFCCCX2_L8_mm10":"TH783_Dnmt-TKO_and_Tet-TKO_A5-2"
        }
peak_loop = os.listdir('loops_bin5k_dist1k')
bw1 = os.listdir('hichip_bw') 
bw2 = os.listdir('chipseq_bw')
hic = os.listdir('hic')
#new_loop = os.listdir('loops_bin5k_dist1k')
summary = []
for f in peak_loop:
    if f.endswith('peak.sorted.gz'):
        each_dict = {}
        each_dict["type"] = "bed"
        each_dict["url"] = "http://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/loops_bin5k_dist1k/"+f
        each_dict["name"] = f
        each_dict['metadata'] = {'data':'chipseqPeak'}
        summary.append(each_dict)
    elif f.endswith('txt.sorted.gz'):
        each_dict={}
        each_dict["type"] = "longrange"
        each_dict["url"] = "http://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/loops_bin5k_dist1k/"+f
        each_dict["name"] = f.split('.')[0][3:]
        each_dict["showOnHubLoad"] = True
        each_dict["options"] = {"displayMode": "arc","height": 100}
        each_dict['metadata'] = {'data':'significantLoop'}
        summary.append(each_dict)

for f in bw1:
    each_dict = {}
    each_dict["type"] = "bigwig"
    each_dict["url"] = "http://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/hichip_bw/"+f
    each_dict["name"] = conditions[f.split('.')[0]]
    each_dict['metadata'] = {'data':'hichip'}
    summary.append(each_dict)

for f in bw2:
    each_dict = {}
    each_dict["type"] = "bigwig"
    each_dict["url"] = "http://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/chipseq_bw/"+f
    each_dict["name"] = f.split('.')[0]
    each_dict['metadata'] = {'data':'chipseq'}
    summary.append(each_dict)

for f in hic:
    each_dict = {}
    each_dict['type'] = 'hic'
    each_dict['name'] = f
    each_dict['url'] = 'http://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/hic/'+f
    each_dict['options'] = {'displayMode':'arc'}
    each_dict['metadata'] = {'allValidPairs'}
    summary.append(each_dict)

summary = sorted(summary, key=lambda x: x['name'])
with open("format4.json", "w") as write_file:
    json.dump(summary, write_file, indent=6) 

