import os
import json
import sys

path = sys.argv[1]
suffix = sys.argv[2]

file_list = [e for e in os.listdir(path) if e.endswith(suffix)]

summary = []

for each in file_list:
    each_dict = {}
    each_dict["type"] = "bed"
    each_dict["url"] = "https://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/" + path + each
    
    each_dict["name"] = each.split('_merge')[0]
    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)
