Skip to content

Commit

Permalink
fix buggy example in api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
aryarm authored Jan 12, 2024
1 parent 7963267 commit d06d50a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions docs/api/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ As an example, let's say we would like to convert `the following .blocks.det fil
# iterate through lines of the .blocks.det file
with open("tests/data/simple.blocks.det") as blocks_file:
for idx, line in enumerate(blocks_file.readlines()):
for idx, line in enumerate(blocks_file.read().splitlines()[1:]):
# initialize variables and parse line from the blocks file
hap_id = f"H{idx}"
chrom, bp1, bp2, kb, nsnps, snps = line.split("\t")
# create a haplotype line in the .hap file
hp.data[hap_id] = data.Haplotype(chrom=chrom, start=bp1, end=bp2, id=hap_id)
hp.data[hap_id] = data.Haplotype(
chrom=chrom, start=int(bp1), end=int(bp2), id=hap_id
)
# fetch alleles from the genotypes file
snp_gts = gt.subset(variants=tuple(snps.split("|")))
Expand Down
6 changes: 4 additions & 2 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2073,13 +2073,15 @@ def test_blocks2hap(self):

# iterate through lines of the .blocks.det file
with open(DATADIR / "simple.blocks.det") as blocks_file:
for idx, line in enumerate(blocks_file.readlines()):
for idx, line in enumerate(blocks_file.read().splitlines()[1:]):
# initialize variables and parse line from the blocks file
hap_id = f"H{idx}"
chrom, bp1, bp2, kb, nsnps, snps = line.split("\t")

# create a haplotype line in the .hap file
hp.data[hap_id] = Haplotype(chrom=chrom, start=bp1, end=bp2, id=hap_id)
hp.data[hap_id] = Haplotype(
chrom=chrom, start=int(bp1), end=int(bp2), id=hap_id
)

# fetch alleles from the genotypes file
snp_gts = gt.subset(variants=tuple(snps.split("|")))
Expand Down

0 comments on commit d06d50a

Please sign in to comment.