#!/home/bol7asan/anaconda3/envs/bokeh/bin/python import glob import os from bokeh.palettes import Category20_20 as colors from datetime import date today = date.today() def hex_to_rgb(hexcode, alpha=0.1): hexcode = hexcode.lstrip('#') rgbcode = ','.join([str(int(hexcode[i:i+2], 16)) for i in (0, 2, 4)]) return str(rgbcode) # Set directories bw_dir = os.getcwd() # Use current directory output_dir = os.path.join(bw_dir, "track_hub") # Create the output directory if it doesn't exist if not os.path.exists(output_dir): os.makedirs(output_dir) # Get list of BigWig files in the directory bwfiles = sorted([os.path.basename(x) for x in glob.glob(bw_dir + '/*.bw')]) # Check if any .bw files were found if not bwfiles: print("No .bw files found in the directory!") exit(1) # Create trackDb.txt with open(os.path.join(output_dir, 'trackDb.txt'), 'w') as fp: for _nn, bwfile in enumerate(bwfiles): color_index = _nn % len(colors) # Cycle through colors if more than 20 files fp.write(f'track {bwfile.split(".bw")[0]}\n') fp.write(f'bigDataUrl {bwfile}\n') fp.write(f'shortLabel {bwfile}\n') fp.write(f'longLabel {bwfile}\n') fp.write('autoScale on\n') fp.write('type bigWig\n') fp.write('windowingFunction mean\n') fp.write('smoothingWindow 5\n') fp.write('visibility full\n') fp.write(f'color {hex_to_rgb(colors[color_index])}\n\n') # Create hub.txt with open(os.path.join(output_dir, 'hub.txt'), 'w') as fp: fp.write(f'hub MixedTracks_{today}\n') fp.write('shortLabel MixedTracks hub\n') fp.write('longLabel MixedTracks hub\n') fp.write('genomesFile genomes.txt\n') fp.write('email mohammed.alhusayan@pennmedicine.upenn.edu\n') fp.write('descriptionUrl none\n') # Create genomes.txt genome_build = 'hg38' # You can modify this if you're using a different genome build with open(os.path.join(output_dir, 'genomes.txt'), 'w') as fp: fp.write(f'genome {genome_build}\n') fp.write(f'trackDb {genome_build}/trackDb.txt\n') print(f"Track hub files created in {output_dir}")