@@ -96,28 +96,14 @@ def write_multi_read_wig(wig_file: BinaryIO,
96
96
wig_file .write (WIG_FIXED_STEP_DECLARATION_FORMAT
97
97
.format (chr_name , 1 )
98
98
.encode ())
99
- write_floats_buffered (multi_read_mappability , wig_file ,
100
- MULTREAD_WRITE_BUFFER_SIZE )
101
99
100
+ for mappability_chunk in np .nditer (multi_read_mappability ,
101
+ flags = ['external_loop' , 'buffered' ]):
102
+ wig_file .writelines (f"{ value } \n " .encode ()
103
+ for value in mappability_chunk )
102
104
103
- def write_floats_buffered (float_array : npt .NDArray [np .float64 ],
104
- file : BinaryIO ,
105
- buffer_size : int ):
106
- # Split the array into buffer_size chunks.
107
- # NB: Ideally this would be based on a byte count but it depends on how the
108
- # floats are converted and formatted
109
105
110
- # To estimate the number of splits, take the array size, divide by the
111
- # buffer size (floored) and add 1
112
-
113
- num_splits = (float_array .size // buffer_size ) + 1
114
- file .writelines (
115
- float_buffer .astype (bytes ) + b'\n '
116
- for float_buffer in np .array_split (float_array , num_splits )
117
- )
118
-
119
-
120
- def save_remove (filename : str ):
106
+ def safe_remove (filename : str ):
121
107
if (filename and
122
108
filename != STDOUT_FILENAME and
123
109
Path (filename ).exists ()):
@@ -141,8 +127,8 @@ def write_mappability_files(unique_count_filenames: list[Path],
141
127
raise ValueError ("Must specify at least one output file" )
142
128
143
129
# Delete any existing mappability files if they exist
144
- save_remove (single_read_bed_filename )
145
- save_remove (multi_read_wig_filename )
130
+ safe_remove (single_read_bed_filename )
131
+ safe_remove (multi_read_wig_filename )
146
132
147
133
# For every unique length file specified
148
134
for unique_count_filename in unique_count_filenames :
0 commit comments