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('peak_loop2')
bw1 = os.listdir('hichip_bw') 
bw2 = os.listdir('chipseq_bw')
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/peak_loop2/"+f
        each_dict["name"] = f
        summary.append(each_dict)
    elif f.endswith('_WashU.bed.gz'):
        each_dict={}
        each_dict["type"] = "longrange"
        each_dict["url"] = "http://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/peak_loop2/"+f
        each_dict["name"] = f.split('.')[0]
        each_dict["showOnHubLoad"] = True
        each_dict["options"] = {"displayMode": "arc","height": 100}
        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]]
    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]
    summary.append(each_dict)

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

