Skip to content

Commit

Permalink
resolve second failing transform test
Browse files Browse the repository at this point in the history
  • Loading branch information
aryarm authored Nov 27, 2024
1 parent b86ee57 commit 9f7ded2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion haptools/data/genotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@ def write(self):
record.samples[sample].phased = self.data[samp_idx, var_idx, 2]
# write the record to a file
vcf.write(record)
vcf.close()
try:
vcf.close()
except OSError as e:
if e.errno == 9 and len(self.variants) == 0:
self.log.warning("No variants to write to VCF")
else:
raise e


class TRRecordHarmonizerRegion(trh.TRRecordHarmonizer):
Expand Down
6 changes: 5 additions & 1 deletion haptools/data/haplotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,9 +1198,13 @@ def __iter__(
indexed = True
try:
haps_file = TabixFile(str(self.fname))
if region is not None:
haps_file.fetch(region=region, multiple_iterators=True)
except OSError:
indexed = False
# if the user requested a specific region or subset of haplotypes and the file
except ValueError:
indexed = False
# If the user requested a specific region or subset of haplotypes and the file
# is indexed, then we should handle it using tabix
# else, we use a regular text opener - b/c there's no benefit to using tabix
if (region or haplotypes) and indexed:
Expand Down

0 comments on commit 9f7ded2

Please sign in to comment.