|
1 | 1 | from pathlib import Path
|
2 | 2 | import sys
|
3 |
| -from typing import TextIO, Union |
| 3 | +from typing import BinaryIO, Union |
4 | 4 |
|
5 | 5 | from newmap.util import verbose_print
|
6 | 6 |
|
@@ -87,14 +87,16 @@ def write_single_read_bed(bed_file: TextIO,
|
87 | 87 | current_value))
|
88 | 88 |
|
89 | 89 |
|
90 |
| -def write_multi_read_wig(wig_file: TextIO, |
| 90 | +def write_multi_read_wig(wig_file: BinaryIO, |
91 | 91 | multi_read_mappability: npt.NDArray[np.float64],
|
92 | 92 | chr_name: str):
|
93 | 93 |
|
94 | 94 | # Write out the fixedStep declaration
|
95 |
| - wig_file.write(WIG_FIXED_STEP_DECLARATION_FORMAT.format(chr_name, 1)) |
96 |
| - for value in multi_read_mappability: |
97 |
| - wig_file.write("{}\n".format(value)) |
| 95 | + wig_file.write(WIG_FIXED_STEP_DECLARATION_FORMAT |
| 96 | + .format(chr_name, 1) |
| 97 | + .encode()) |
| 98 | + wig_file.write(b''.join(multi_read_mappability.astype(bytes) + b'\n')) |
| 99 | + wig_file.flush() |
98 | 100 |
|
99 | 101 |
|
100 | 102 | def write_mappability_files(unique_count_filenames: list[Path],
|
@@ -178,11 +180,12 @@ def write_mappability_files(unique_count_filenames: list[Path],
|
178 | 180 | f" to {multi_read_wig_filename}")
|
179 | 181 |
|
180 | 182 | if multi_read_wig_filename == STDOUT_FILENAME:
|
181 |
| - write_multi_read_wig(sys.stdout, |
| 183 | + write_multi_read_wig(sys.stdout.buffer, |
182 | 184 | multi_read_mappability,
|
183 | 185 | chr_name)
|
184 | 186 | else:
|
185 |
| - with open(multi_read_wig_filename, "a") as multi_read_wig_file: |
| 187 | + with open(multi_read_wig_filename, "ab") as \ |
| 188 | + multi_read_wig_file: |
186 | 189 | write_multi_read_wig(multi_read_wig_file,
|
187 | 190 | multi_read_mappability,
|
188 | 191 | chr_name)
|
|
0 commit comments