import os
import json

#file_list = os.listdir("/home/yuz/Public_html/chen/cutrun_2023")
file_list1 = [each for each in os.listdir('/home/yuz/Public_html/chen/chip_2023') if each.endswith("gz")]
file_list2 = [each for each in os.listdir('/home/yuz/Public_html/chen/chip_2023') 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/chip_2023/" + each
    each_dict["name"] = each.split(".")[1][11:]
    each_dict["options"] = {"color": "red", "background":"#C0E3CC"}
    each_dict["metadata"] = {"sample": each.split("_")[5], "age": each.split("_")[2], "genotype": each.split("_")[3]}
    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/chip_2023/" + each
    each_dict["name"] = each.split(".")[1][11:]
    each_dict["options"] = {"color": "blue", "background":"#C0E3CC"}
    each_dict["metadata"] = {"sample": each.split("_")[5], "age": each.split("_")[2], "genotype": each.split("_")[3]}
    summary.append(each_dict)
summary = sorted(summary,key=lambda x: x['name'])
with open("chip_2023_with_meta.json", "w") as write_file:
    json.dump(summary, write_file, indent=6) 
