11import pathlib
2- import flatgfa
32from itertools import islice
3+
4+ import flatgfa
5+
6+
47def iter_bits_ones_dash (path , chunk_bytes : int = 64 * 1024 ):
58 ws = b" \t \r \n \v \f "
69 with open (path , "rb" ) as f :
@@ -11,12 +14,15 @@ def iter_bits_ones_dash(path, chunk_bytes: int = 64 * 1024):
1114 for b in chunk :
1215 if b in ws :
1316 continue
14- if b == ord ('1' ):
17+ if b == ord ("1" ):
1518 yield True
16- elif b == ord ('0' ):
19+ elif b == ord ("0" ):
1720 yield False
1821 else :
19- raise ValueError (f"Invalid character in file: { chr (b )!r} (expected '1' or '0')" )
22+ raise ValueError (
23+ f"Invalid character in file: { chr (b )!r} (expected '1' or '0')"
24+ )
25+
2026
2127def compare_row_to_file (row_bits , path ) -> tuple [bool , int | None ]:
2228 n = len (row_bits )
@@ -34,6 +40,7 @@ def compare_row_to_file(row_bits, path) -> tuple[bool, int | None]:
3440 raise ValueError (f"File ended early: got { i } bits, expected { n } ." )
3541 return True , None
3642
43+
3744TEST_DIR = pathlib .Path (__file__ ).parent
3845TEST_GFA = TEST_DIR / "./matrix_gaf_folder/Chr3.gfa"
3946GAF_DIR = (TEST_DIR / "./matrix_gaf_folder" ).resolve ()
@@ -48,7 +55,7 @@ def compare_row_to_file(row_bits, path) -> tuple[bool, int | None]:
4855# print("OK (all columns match)" if ok else f"Mismatch at column {where}")
4956FIRST_N = 100
5057for gaf_path , row in zip (gaf , pangenotype_matrix ):
51- row01 = [int (b ) for b in row ]
58+ row01 = [int (b ) for b in row ]
5259 # print(pathlib.Path(gaf_path).name, *row01)
5360 first_bits = islice (row , FIRST_N )
54- print (pathlib .Path (gaf_path ).name , * map (int , first_bits ))
61+ print (pathlib .Path (gaf_path ).name , * map (int , first_bits ))
0 commit comments