|
6 | 6 | import pandas as pd
|
7 | 7 | import zarr
|
8 | 8 |
|
9 |
| -from vcztools import _vcztools |
| 9 | +from . import _vcztools, retrieval |
10 | 10 |
|
11 | 11 |
|
12 | 12 | def encode_genotypes(genotypes, a12_allele=None):
|
@@ -62,6 +62,7 @@ def generate_bim(root, a12_allele):
|
62 | 62 | class Writer:
|
63 | 63 | def __init__(self, vcz_path, bed_path, fam_path, bim_path):
|
64 | 64 | self.root = zarr.open(vcz_path, mode="r")
|
| 65 | + |
65 | 66 | self.bim_path = bim_path
|
66 | 67 | self.fam_path = fam_path
|
67 | 68 | self.bed_path = bed_path
|
@@ -109,28 +110,22 @@ def _compute_alleles(self, G, alleles):
|
109 | 110 | return a12_allele
|
110 | 111 |
|
111 | 112 | def _write_genotypes(self):
|
| 113 | + ci = retrieval.variant_chunk_iter( |
| 114 | + self.root, fields=["call_genotype", "variant_allele"] |
| 115 | + ) |
112 | 116 | call_genotype = self.root["call_genotype"]
|
113 |
| - variant_allele = self.root["variant_allele"] |
114 | 117 | a12_allele = zarr.zeros(
|
115 | 118 | (call_genotype.shape[0], 2), chunks=call_genotype.chunks[0], dtype=int
|
116 | 119 | )
|
117 | 120 | with open(self.bed_path, "wb") as bed_file:
|
118 | 121 | bed_file.write(bytes([0x6C, 0x1B, 0x01]))
|
119 |
| - for v_chunk in range(call_genotype.cdata_shape[0]): |
120 |
| - # before = time.perf_counter() |
121 |
| - G = call_genotype.blocks[v_chunk] |
122 |
| - # duration = time.perf_counter() - before |
123 | 122 |
|
124 |
| - # before = time.perf_counter() |
125 |
| - a12 = self._compute_alleles(G, variant_allele.blocks[v_chunk]) |
126 |
| - # duration = time.perf_counter() - before |
127 |
| - |
128 |
| - # before = time.perf_counter() |
| 123 | + for j, chunk in enumerate(ci): |
| 124 | + G = chunk["call_genotype"] |
| 125 | + a12 = self._compute_alleles(G, chunk["variant_allele"]) |
129 | 126 | buff = encode_genotypes(G, a12)
|
130 |
| - # duration = time.perf_counter() - before |
131 |
| - |
132 | 127 | bed_file.write(buff)
|
133 |
| - a12_allele.blocks[v_chunk] = a12 |
| 128 | + a12_allele.blocks[j] = a12 |
134 | 129 | return a12_allele[:]
|
135 | 130 |
|
136 | 131 | def run(self):
|
|
0 commit comments