Revision 6740d3ab73923164703a0ba2b11fc0294e8ea12e authored by John Chilton on 04 July 2020, 14:16:28 UTC, committed by John Chilton on 04 July 2020, 14:16:28 UTC
1 parent 78273d2
add_manual_builds.py
#!/usr/bin/env python
"""
Adds Manually created builds and chrom info to Galaxy's info tables
Usage:
python add_manual_builds.py input_file builds.txt chrom_length_dir
"""
from __future__ import print_function
import os
import sys
def add_manual_builds(input_file, build_file, chr_dir):
# determine existing builds, so as to not overwrite
existing_builds = []
for line in open(build_file):
try:
if line.startswith("#"):
continue
existing_builds.append(line.replace("\n", "").replace("\r", "").split("\t")[0])
except Exception:
continue
build_file_out = open(build_file, 'a')
for line in open(input_file):
try:
fields = line.replace("\n", "").replace("\r", "").split("\t")
build = fields.pop(0)
if build in existing_builds:
continue # if build exists, leave alone
name = fields.pop(0)
try: # get chrom lens if included in file, otherwise still add build
chrs = fields.pop(0).split(",")
except Exception:
chrs = []
print(build + "\t" + name + " (" + build + ")", file=build_file_out)
if chrs: # create len file if provided chrom lens
chr_len_out = open(os.path.join(chr_dir, build + ".len"), 'w')
for chr in chrs:
print(chr.replace("=", "\t"), file=chr_len_out)
chr_len_out.close()
except Exception:
continue
build_file_out.close()
if __name__ == "__main__":
if len(sys.argv) < 4:
sys.exit("USAGE: python add_manual_builds.py input_file builds.txt chrom_length_dir")
input_file = sys.argv[1]
build_file = sys.argv[2]
chr_dir = sys.argv[3]
add_manual_builds(input_file, build_file, chr_dir)
Computing file changes ...