import os
import json

file_list = [e for e in os.listdir('bigwigs') if e.endswith('bigWig')]
file_list1 = [e for e in os.listdir('peaks_from_chrhmm') if e.endswith('gz')]

summary = []

for each in file_list:
    each_dict = {}
    each_dict["type"] = "bigwig"
    each_dict["url"] = "https://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/cuttag/bigwigs/" + each
    
    each_dict["name"] = each.split('_normalized')[0]
    each_dict["options"] = {"color": "blue", "background":"#C0E3CC"}
    summary.append(each_dict)

for each in file_list1:
    each_dict = {}
    each_dict["type"] = "bed"
    each_dict["url"] = "https://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/cuttag/peaks_from_chrhmm/" + each
    
    each_dict["name"] = each.split('.')[0].split('HMM_')[1]+'_chromHMM'
    each_dict["options"] = {"color": "blue", "background":"#C0E3CC"}
    summary.append(each_dict)

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