import os
import json

file_list = [e for e in os.listdir('../../chipseq2025_bw') if e.endswith('bigWig') and 'CKDL' in e]

summary = []

for each in file_list:
    print(each)
    each_dict = {}
    each_dict["type"] = "bigwig"
    each_dict["url"] = "https://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/chipseq2025_bw/" + each

    #each_dict["name"] = each.split('_chip')[0].split('methylQA_')[1]
    each_dict["options"] = {"color": "blue", "background":"#C0E3CC"}
    #if 'mesc' not in each and "INPUT" not in each:
    each_dict["metadata"] = {"sample": each[each.index('H'):].split('_')[0], "genotype": each.split('_')[2]}
    each_dict["name"] = each.split('_CKDL')[0].split('lQA_')[1]
    #else:
        #each_dict["metadata"] = {"sample": "H3K27me3", "genotype": "WT"}
        #each_dict["name"] = each.split('lQA_')[1].split('.')[0]
    summary.append(each_dict)

file_list = [e for e in os.listdir('.') if e.endswith('gz')]
for each in file_list:
    each_dict = {}
    each_dict["type"] = "bed"
    each_dict["url"] = "https://regmedsrv1.wustl.edu/Public_SPACE/yuz/Public_html/hichip/chipseq2025_peakChrhmm/wo_input/" + each
    name = each.split('BED3_')[1].split('.')[0]
    #each_dict["name"] = name
    each_dict["options"] = {"color": "blue", "background":"#C0E3CC", "displayMode":"density"}
    if 'mesc' not in each:
        #name = each.split('BED3_')[1].split('.')[0]
        each_dict["name"] = name
        each_dict["metadata"] = {"sample": each.split('_')[4], "genotype": each.split('_')[3]}
    #else:
    #    each_dict["name"] = name+'_H3K27me3_peak'
    #    each_dict["metadata"] = {"sample":"H3K27me3", "genotype": "WT"}

    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)
