import os
import json

file_list1 = [each for each in os.listdir('/home/yuz/Public_html/chen/h3k27ac_chrhmm_peak_calling') if each.endswith("bed.sorted.gz")]
summary = []

for each in file_list1:
    each_dict = {}
    each_dict["type"] = "bed"
    each_dict["url"] = "http://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/chen/h3k27ac_chrhmm_peak_calling/" + each
    each_dict["name"] = '_'.join(each.split(".")[0].split('_')[:3])+'_peak'
    each_dict["options"] = {"color": "red", "background":"#C0E3CC"}
    each_dict["metadata"] = {"sample": each.split("_")[1]}
    summary.append(each_dict)

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

