| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | """ |
|---|
| 4 | Adds Manually created builds and chrom info to Galaxy's info tables |
|---|
| 5 | |
|---|
| 6 | Usage: |
|---|
| 7 | python add_manual_builds.py input_file builds.txt chrom_length_dir |
|---|
| 8 | """ |
|---|
| 9 | |
|---|
| 10 | import sys,os |
|---|
| 11 | |
|---|
| 12 | def add_manual_builds(input_file, build_file, chr_dir): |
|---|
| 13 | #determine existing builds, so as to not overwrite |
|---|
| 14 | existing_builds = [] |
|---|
| 15 | for line in open(build_file): |
|---|
| 16 | try: |
|---|
| 17 | if line.startswith("#"): continue |
|---|
| 18 | existing_builds.append(line.replace("\n","").replace("\r","").split("\t")[0]) |
|---|
| 19 | except: |
|---|
| 20 | continue |
|---|
| 21 | build_file_out = open(build_file,'a') |
|---|
| 22 | for line in open(input_file): |
|---|
| 23 | try: |
|---|
| 24 | fields = line.split("\t") |
|---|
| 25 | build = fields.pop(0) |
|---|
| 26 | if build in existing_builds: continue # if build exists, leave alone |
|---|
| 27 | name = fields.pop(0) |
|---|
| 28 | chrs = fields.pop(0).replace("\n","").replace("\r","").split(",") |
|---|
| 29 | print>>build_file_out, build+"\t"+name+" ("+build+")" |
|---|
| 30 | chr_len_out=open( os.path.join(chr_dir,build+".len"),'w') |
|---|
| 31 | for chr in chrs: |
|---|
| 32 | print>>chr_len_out, chr.replace("=","\t") |
|---|
| 33 | chr_len_out.close() |
|---|
| 34 | except: |
|---|
| 35 | continue |
|---|
| 36 | build_file_out.close() |
|---|
| 37 | |
|---|
| 38 | if __name__ == "__main__": |
|---|
| 39 | if len(sys.argv) < 4: |
|---|
| 40 | print "USAGE: python add_manual_builds.py input_file builds.txt chrom_length_dir" |
|---|
| 41 | sys.exit(1) |
|---|
| 42 | input_file = sys.argv[1] |
|---|
| 43 | build_file = sys.argv[2] |
|---|
| 44 | chr_dir = sys.argv[3] |
|---|
| 45 | add_manual_builds(input_file,build_file,chr_dir) |
|---|