From c2897b088827e24b8806de5cc06baa33dd59b773 Mon Sep 17 00:00:00 2001 From: Readman Chiu Date: Fri, 19 Jul 2024 13:35:59 -0700 Subject: [PATCH] add extensions to tmp files --- CHANGES.md | 1 + src/ins.py | 6 +++--- src/utils.py | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bb983c0..b60dbf8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -70,4 +70,5 @@ v1.5.1 - bugfix: size and copy range of alleles only include "full" supporting reads even if partials were included, but "partial" reads will be reported in support counts - bugfix: allele motif equivalence checked to perform proper tallying for determining consensus motif in variant - used read name as tiebreaker for choosing support read sequence as ALT +- add extensions (`.fa`, `.blastn`, `.bed`) to temporary files to help debugging - `MOTIF` renamed to `RU`, `COPIES` to `REF` in VCF fields diff --git a/src/ins.py b/src/ins.py index c394df4..6388d83 100644 --- a/src/ins.py +++ b/src/ins.py @@ -456,7 +456,7 @@ def create_tmp_bed(self, ins_list, include_read=False): for ins in ins_list: ins_bed += '{}\n'.format(INS.to_bed(ins, include_read=include_read)) - ins_bed_file = create_tmp_file(ins_bed) + ins_bed_file = create_tmp_file(ins_bed, '.bed') self.tmp_files.add(ins_bed_file) return ins_bed_file @@ -469,7 +469,7 @@ def merge(self, ins_list, d=50): ins_all = BedTool(ins_bed_file) ins_merged = ins_all.sort().merge(d=d, c='4,5', o='distinct,count_distinct') if self.debug: - ins_merged_file = create_tmp_file('') + ins_merged_file = create_tmp_file('', '.bed') ins_merged.saveas(ins_merged_file) print('ins merged {}'.format(ins_merged_file)) @@ -516,7 +516,7 @@ def get_examine_regions(self, bam, chroms, chunk_size=1000000, regions_bed_file= chrom_spans = '' for chrom in sorted(chroms): chrom_spans += '{}\n'.format('\t'.join(map(str, [chrom, 0, chrom_lens[chrom]]))) - chrom_bed_file = create_tmp_file(chrom_spans) + chrom_bed_file = create_tmp_file(chrom_spans, '.bed') self.tmp_files.add(chrom_bed_file) chrom_bed = BedTool(chrom_bed_file) diff --git a/src/utils.py b/src/utils.py index 8531549..1e8ffed 100644 --- a/src/utils.py +++ b/src/utils.py @@ -35,8 +35,8 @@ def combine_batch_results(batch_results, data_type): return all_results -def create_tmp_file(content): - fd, path = tempfile.mkstemp() +def create_tmp_file(content, ext=None): + fd, path = tempfile.mkstemp(suffix=ext) try: with os.fdopen(fd, 'w') as out: out.write(content)