@@ -451,30 +451,30 @@ def read_VisiumHD(
451451# Vizgen
452452
453453_VIZGEN_COLUMNS = {"gene" : "gene" , "global_x" : "x" , "global_y" : "y" }
454- VIZGEN_CTRLS = ["^Blank" ]
455- """Patterns for Vizgen controls"""
454+ MERSCOPE_CTRLS = ["^Blank" ]
455+ """Patterns for MERSCOPE controls"""
456456
457457
458458@validate_threads
459- def read_Vizgen (
459+ def read_MERSCOPE (
460460 filepath : _PathLike ,
461461 * ,
462462 binsize : float = 0.5 ,
463- remove_genes : Collection [str ] = VIZGEN_CTRLS ,
463+ remove_genes : Collection [str ] = MERSCOPE_CTRLS ,
464464 n_threads : int | None = None ,
465465) -> LazyKDE :
466466 """
467- Read a Vizgen transcripts file.
467+ Read a MERSCOPE transcripts file.
468468
469469 Parameters
470470 ----------
471471 filepath : os.PathLike or str
472- Path to the Vizgen transcripts file.
472+ Path to the MERSCOPE transcripts file.
473473 binsize : float, optional
474474 Size of each bin in um.
475475 remove_genes : collections.abc.Collection[str], optional
476476 List of regex patterns to filter the 'gene' column,
477- :py:attr:`sainsc.io.VIZGEN_CTRLS ` by default.
477+ :py:attr:`sainsc.io.MERSCOPE_CTRLS ` by default.
478478 n_threads : int | None, optional
479479 Number of threads used for reading file and processing. If `None` or 0 this will
480480 default to the number of available CPUs.
@@ -483,15 +483,28 @@ def read_Vizgen(
483483 -------
484484 sainsc.LazyKDE
485485 """
486+ filepath = Path (filepath )
487+ columns = list (_VIZGEN_COLUMNS .keys ())
486488
487- transcripts = pl .read_csv (
488- Path (filepath ),
489- columns = list (_VIZGEN_COLUMNS .keys ()),
490- schema_overrides = {"gene" : pl .Categorical },
491- n_threads = n_threads ,
492- ).rename (_VIZGEN_COLUMNS )
489+ if filepath .suffix == ".csv" :
490+ transcripts = pl .read_csv (
491+ filepath ,
492+ columns = columns ,
493+ schema_overrides = {"gene" : pl .Categorical },
494+ n_threads = n_threads ,
495+ )
496+ elif filepath .suffix == ".parquet" :
497+ # what about transcript_score (no documentation?)
498+ transcripts = (
499+ pl .scan_parquet (filepath )
500+ .select (columns )
501+ .with_columns (pl .col ("gene" ).cast (pl .Categorical ))
502+ .collect ()
503+ )
504+ else :
505+ raise ValueError ("Unexpected file format. Only .csv or .parquet are supported." )
493506
494- transcripts = _filter_genes (transcripts , remove_genes )
507+ transcripts = _filter_genes (transcripts . rename ( _VIZGEN_COLUMNS ) , remove_genes )
495508
496509 return LazyKDE .from_dataframe (
497510 transcripts , binsize = binsize , resolution = 1_000 , n_threads = n_threads
0 commit comments