import os
import json

file_list1 = [each for each in os.listdir('/home/yuz/Public_html/chen/encode_forebrain') if each.endswith("bed.sorted.gz")]
file_list2 = [each for each in os.listdir('/home/yuz/Public_html/chen/encode_forebrain') if each.endswith("bigWig")]
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/encode_forebrain/" + each
    each_dict["name"] = '_'.join(each.split(".")[0].split('_')[:2])+'_peak'
    each_dict["options"] = {"color": "red", "background":"#C0E3CC"}
    each_dict["metadata"] = {"sample": each.split("_")[1]}
    summary.append(each_dict)

for each in file_list2:
    each_dict = {}
    each_dict["type"] = "bigwig"
    each_dict["url"] = "http://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/chen/encode_forebrain/" + each
    each_dict["name"] = '_'.join(each.split('.')[0].split('_')[:2])
    each_dict["options"] = {"color": "blue", "background":"#C0E3CC"}
    each_dict["metadata"] = {"sample": each.split("_")[1]}
    summary.append(each_dict)

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