Pre Module API Reference
Module for pre-processing to generate LandscapeFiles from ST data.
add_custom_segmentation(path_landscape_files, path_segmentation_files, image_scale=1, tile_size=250)
Add custom segmentation to existing landscape files.
Parameters: - path_landscape_files: Path to landscape files - path_segmentation_files: Path to segmentation files - image_scale: Image scale factor - tile_size: Tile size for processing
Source code in src/celldega/pre/__init__.py
921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
|
cluster_gene_expression(technology, path_landscape_files, cbg, data_dir=None, segmentation_approach='default')
Calculates cluster-specific gene expression signatures for Xenium data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
technology
|
str
|
The technology used (e.g., "Xenium" or "MERSCOPE"). Currently, only "Xenium" is supported. |
required |
data_dir
|
str
|
Path to the directory containing the Xenium data. |
None
|
path_landscape_files
|
str
|
Path to the directory where the gene expression signature file will be saved. |
required |
cbg
|
DataFrame
|
A cell-by-gene matrix where rows represent cells and columns represent genes. The index of the DataFrame should match the cell IDs in the Xenium metadata. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified technology is not supported. |
FileNotFoundError
|
If the required input files are not found. |
Source code in src/celldega/pre/__init__.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|
create_cluster_and_meta_cluster(technology, path_landscape_files, data_dir=None, segmentation_approach='default')
Creates cell clusters and meta cluster files for visualization. Currently supports only Xenium.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
technology
|
str
|
The technology used (e.g., "Xenium" or "MERSCOPE"). Currently, only "Xenium" is supported. |
required |
data_dir
|
str
|
Path to the directory containing the Xenium data. |
None
|
path_landscape_files
|
str
|
Path to the directory where the cluster and meta cluster files will be saved. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified technology is not supported. |
FileNotFoundError
|
If the required input files are not found. |
Source code in src/celldega/pre/__init__.py
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
create_image_tiles(technology, data_dir, path_landscape_files, image_tile_layer='dapi')
Creates image tiles for visualization from the Xenium morphology image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
technology
|
str
|
The technology used (e.g., "Xenium", "MERSCOPE", "VisiumHD", "H&E"). |
required |
data_dir
|
str
|
Path to the directory containing the data (e.g., morphology_focus_0000.ome.tif). |
required |
path_landscape_files
|
str
|
Path to the directory where the image tiles and pyramid will be saved. |
required |
image_tile_layer
|
str
|
Specifies which image layers to process. Options for Xenium are |
'dapi'
|
Raises:
Type | Description |
---|---|
ValueError
|
If the specified technology is not supported or if the image_tile_layer is invalid. |
FileNotFoundError
|
If the required input image file is not found. |
Source code in src/celldega/pre/__init__.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
create_image_tiles_h_and_e(data_dir, path_landscape_files, image_tile_layer)
Creates image tiles for visualization from the H&E image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir
|
str
|
Path to the directory containing the data (e.g., morphology_focus_0000.ome.tif). |
required |
path_landscape_files
|
str
|
Path to the directory where the image tiles and pyramid will be saved. |
required |
image_tile_layer
|
str
|
Specifies the name of the h&e image to process. |
required |
Raises: FileNotFoundError: If the required input image file is not found.
Source code in src/celldega/pre/__init__.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
|
create_image_tiles_merscope(data_dir, path_landscape_files, image_tile_layer='dapi')
Creates image tiles for visualization from the Xenium morphology image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir
|
str
|
Path to the directory containing the data (e.g., morphology_focus_0000.ome.tif). |
required |
path_landscape_files
|
str
|
Path to the directory where the image tiles and pyramid will be saved. |
required |
image_tile_layer
|
str
|
Specifies which image layers to process. Options are 'dapi' (default) or 'all'. |
'dapi'
|
Raises: FileNotFoundError: If the required input image file is not found.
Source code in src/celldega/pre/__init__.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 |
|
create_image_tiles_xenium(data_dir, path_landscape_files, image_tile_layer='dapi')
Creates image tiles for visualization from the Xenium morphology image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir
|
str
|
Path to the directory containing the data (e.g., morphology_focus_0000.ome.tif). |
required |
path_landscape_files
|
str
|
Path to the directory where the image tiles and pyramid will be saved. |
required |
image_tile_layer
|
str
|
Specifies which image layers to process. Options are 'dapi' (default) or 'all'. |
'dapi'
|
Raises: FileNotFoundError: If the required input image file is not found.
Source code in src/celldega/pre/__init__.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
get_image_info(technology, image_tile_layer='dapi')
Retrieve image information for a given technology and image tile layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
technology
|
str
|
The technology for which image information is requested. Currently supports 'Xenium' and 'MERSCOPE'. |
required |
image_tile_layer
|
str
|
The type of image tile layer to retrieve information for. Options are 'dapi' or 'all'. Defaults to 'dapi'. |
'dapi'
|
Returns:
Type | Description |
---|---|
list[dict]
|
A list of dictionaries containing image information, including name, |
list[dict]
|
button name, and color. |
Raises:
Type | Description |
---|---|
ValueError
|
If the technology is not supported or the image_tile_layer is invalid. |
Source code in src/celldega/pre/image_info.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
get_max_zoom_level(path_image_pyramid)
Returns the maximum zoom level based on the highest-numbered directory in the specified path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_image_pyramid
|
str
|
Path to the directory containing zoom level directories. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
The maximum zoom level. |
Source code in src/celldega/pre/__init__.py
835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
|
main(sample, data_root_dir, tile_size, image_tile_layer='all', path_landscape_files='', use_int_index=True, max_workers=1)
Main function to preprocess Xenium or MERSCOPE data and generate landscape files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample
|
str
|
Name of the sample (e.g., 'Xenium_V1_human_Pancreas_FFPE_outs'). |
required |
data_root_dir
|
str
|
Root directory containing all sample data. The
|
required |
tile_size
|
int
|
Size of the tiles for transcript and boundary tiles. |
required |
image_tile_layer
|
str
|
Image layers to be tiled. 'dapi' or 'all'. |
'all'
|
path_landscape_files
|
str
|
Directory to save the landscape files. |
''
|
use_int_index
|
bool
|
Use integer index for smaller files and faster rendering. |
True
|
Example
change directory to celldega, and run:
python run_pre_processing.py --sample Xenium_V1_human_Pancreas_FFPE_outs --data_root_dir data --tile_size 250 --image_tile_layer 'dapi' --path_landscape_files notebooks/Xenium_V1_human_Pancreas_FFPE_outs
Source code in src/celldega/pre/run_pre_processing.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
make_chromium_from_anndata(adata, path_landscape_files)
Generate minimal LandscapeFiles from a Chromium AnnData object.
Parameters
adata : anndata.AnnData AnnData object containing scRNA-seq count data. path_landscape_files : str or Path Directory where LandscapeFiles will be written.
Raises
ValueError If the expression matrix contains non-integer values.
Source code in src/celldega/pre/__init__.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 |
|
make_deepzoom_pyramid(image_path, output_path, pyramid_name, tile_size=512, overlap=0, suffix='.jpeg')
Creates a DeepZoom image pyramid from a JPEG image.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image_path
|
str
|
Path to the JPEG image file. |
required |
output_path
|
str
|
Directory to save the DeepZoom pyramid. |
required |
pyramid_name
|
str
|
Name of the pyramid directory. |
required |
tile_size
|
int
|
Tile size for the DeepZoom pyramid. Defaults to 512. |
512
|
overlap
|
int
|
Overlap size for the DeepZoom pyramid. Defaults to 0. |
0
|
suffix
|
str
|
Suffix for the DeepZoom pyramid tiles. Defaults to ".jpeg". |
'.jpeg'
|
Returns:
Type | Description |
---|---|
None |
Source code in src/celldega/pre/__init__.py
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
|
make_meta_cell_image_coord(technology, path_transformation_matrix, path_meta_cell_micron, path_meta_cell_image, image_scale=1)
Applies an affine transformation to cell coordinates in microns and saves the transformed coordinates in pixels.
Parameters
technology : str The technology used to generate the data, Xenium and MERSCOPE are supported. path_transformation_matrix : str Path to the transformation matrix file path_meta_cell_micron : str Path to the meta cell file with coordinates in microns path_meta_cell_image : str Path to save the meta cell file with coordinates in pixels
Returns
None
Examples
make_meta_cell_image_coord( ... technology='Xenium', ... path_transformation_matrix='data/transformation_matrix.csv', ... path_meta_cell_micron='data/meta_cell_micron.csv', ... path_meta_cell_image='data/meta_cell_image.parquet' ... ) Args: technology (str): The technology used to generate the data (e.g., "Xenium" or "MERSCOPE"). path_transformation_matrix (str): Path to the transformation matrix file. path_meta_cell_micron (str): Path to the meta cell file with coordinates in microns. path_meta_cell_image (str): Path to save the meta cell file with coordinates in pixels. image_scale (float): Scaling factor to convert micron coordinates to pixel coordinates.
Returns:
Type | Description |
---|---|
None |
Source code in src/celldega/pre/__init__.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 |
|
make_meta_gene(cbg, path_output)
Creates a DataFrame with genes and their assigned colors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cbg
|
DataFrame
|
A sparse DataFrame with genes as columns and barcodes as rows.. |
required |
path_output
|
str
|
Path to save the meta gene file. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in src/celldega/pre/__init__.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 |
|
make_trx_tiles(technology, path_trx, path_transformation_matrix=None, path_trx_tiles=None, coarse_tile_factor=10, tile_size=250, chunk_size=1000000, verbose=False, image_scale=1, max_workers=1)
Processes transcript data by dividing it into coarse-grain and fine-grain tiles, applying transformations, and saving the results in a parallelized manner.
Parameters
technology : str The technology used for generating the transcript data (e.g., "MERSCOPE" or "Xenium"). path_trx : str Path to the file containing the transcript data. path_transformation_matrix : str Path to the file containing the transformation matrix (CSV file). path_trx_tiles : str Directory path where the output files (Parquet files) for each tile will be saved. coarse_tile_factor : int, optional Scaling factor of each coarse-grain tile comparing to the fine tile size. tile_size : int, optional Size of each fine-grain tile in microns (default is 250). chunk_size : int, optional Number of rows to process per chunk for memory efficiency (default is 1000000). verbose : bool, optional Flag to enable verbose output (default is False). image_scale : float, optional Scale factor to apply to the transcript coordinates (default is 0.5). max_workers : int, optional Maximum number of parallel workers for processing tiles (default is 1).
Returns
dict A dictionary containing the bounds of the processed data in both x and y directions.
Source code in src/celldega/pre/trx_tile.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
|
read_cbg_mtx(base_path)
Read the cell-by-gene matrix from the mtx files.
Parameters
base_path : str The base path to the directory containing the mtx files.
Returns
cbg : pandas.DataFrame A sparse DataFrame with genes as columns and barcodes as rows.
Source code in src/celldega/pre/landscape.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
remove_intermediate_files(path_landscape_files)
Remove intermediate image files.
Parameters: - path_landscape_files: Path to landscape files directory
Source code in src/celldega/pre/__init__.py
437 438 439 440 441 442 443 444 445 446 447 |
|
save_landscape_parameters(technology, path_landscape_files, image_name='dapi_files', tile_size=1000, image_info=None, image_format='.webp', use_int_index=True, segmentation_approach='default')
Saves the landscape parameters to a JSON file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
technology
|
str
|
The technology used to generate the data. |
required |
path_landscape_files
|
str
|
Path to the directory where landscape files are stored. |
required |
image_name
|
str
|
Name of the image directory. Defaults to "dapi_files". |
'dapi_files'
|
tile_size
|
int
|
Tile size for the image pyramid. Defaults to 1000. |
1000
|
image_info
|
dict
|
Additional image metadata. Defaults to None. |
None
|
image_format
|
str
|
Format of the image files. Defaults to ".webp". |
'.webp'
|
use_int_index
|
bool
|
Use integer name for cell_tile and trx_tile. |
True
|
Returns:
Type | Description |
---|---|
None |
Source code in src/celldega/pre/__init__.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 |
|
write_xenium_transform(data_dir, path_landscape_files, transform_fname='micron_to_image_transform.csv')
Extracts the transformation matrix from the Xenium cells.zarr.zip file and saves it as a CSV file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir
|
str
|
Path to the directory containing the Xenium data (e.g., cells.zarr.zip). |
required |
path_landscape_files
|
str
|
Path to the directory where the transformation matrix CSV will be saved. |
required |
transform_fname
|
str
|
Name of the output CSV file. Defaults to "micron_to_image_transform.csv". |
'micron_to_image_transform.csv'
|
Returns:
Type | Description |
---|---|
numpy.ndarray: The full transformation matrix extracted from the Xenium cells.zarr.zip file. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the cells.zarr.zip file does not exist in the specified |
KeyError
|
If the transformation matrix is not found in the Zarr file under the expected path. |
Exception
|
If an unexpected error occurs while processing the Zarr file. |
Source code in src/celldega/pre/__init__.py
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 |
|