segger.data.io¶
MerscopeKeys ¶
Bases: Enum
Keys for MERSCOPE data (Vizgen platform).
MerscopeSample ¶
MerscopeSample(transcripts_df=None, transcripts_radius=10, boundaries_graph=False, embedding_df=None, verbose=True)
Bases: SpatialTranscriptomicsSample
Source code in src/segger/data/io.py
1115 1116 1117 1118 1119 1120 1121 1122 1123 |
|
filter_transcripts ¶
filter_transcripts(transcripts_df, min_qv=20.0)
Filters transcripts based on specific criteria for Merscope using Dask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcripts_df
|
dd.DataFrame The Dask DataFrame containing transcript data. |
required | |
min_qv
|
float, optional The minimum quality value threshold for filtering transcripts. |
20.0
|
Returns:
Type | Description |
---|---|
DataFrame
|
dd.DataFrame The filtered Dask DataFrame. |
Source code in src/segger/data/io.py
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 |
|
SpatialDataKeys ¶
Bases: Enum
Keys for MERSCOPE data (Vizgen platform).
SpatialDataSample ¶
SpatialDataSample(transcripts_df=None, transcripts_radius=10, boundaries_graph=False, embedding_df=None, feature_name=None, verbose=True)
Bases: SpatialTranscriptomicsSample
Source code in src/segger/data/io.py
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 |
|
filter_transcripts ¶
filter_transcripts(transcripts_df, min_qv=20.0)
Filters transcripts based on quality value and removes unwanted transcripts for Xenium using Dask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcripts_df
|
DataFrame
|
The Dask DataFrame containing transcript data. |
required |
min_qv
|
float
|
The minimum quality value threshold for filtering transcripts. |
20.0
|
Returns:
Type | Description |
---|---|
DataFrame
|
dd.DataFrame: The filtered Dask DataFrame. |
Source code in src/segger/data/io.py
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 |
|
SpatialTranscriptomicsDataset ¶
SpatialTranscriptomicsDataset(root, transform=None, pre_transform=None, pre_filter=None)
Bases: InMemoryDataset
A dataset class for handling SpatialTranscriptomics spatial transcriptomics data.
Attributes:
Name | Type | Description |
---|---|---|
root |
str
|
The root directory where the dataset is stored. |
transform |
callable
|
A function/transform that takes in a Data object and returns a transformed version. |
pre_transform |
callable
|
A function/transform that takes in a Data object and returns a transformed version. |
pre_filter |
callable
|
A function that takes in a Data object and returns a boolean indicating whether to keep it. |
Initialize the SpatialTranscriptomicsDataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root
|
str
|
Root directory where the dataset is stored. |
required |
transform
|
callable
|
A function/transform that takes in a Data object and returns a transformed version. Defaults to None. |
None
|
pre_transform
|
callable
|
A function/transform that takes in a Data object and returns a transformed version. Defaults to None. |
None
|
pre_filter
|
callable
|
A function that takes in a Data object and returns a boolean indicating whether to keep it. Defaults to None. |
None
|
Source code in src/segger/data/utils.py
441 442 443 444 445 446 447 448 449 450 451 452 |
|
processed_file_names
property
¶
processed_file_names
Return a list of processed file names in the processed directory.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of processed file names. |
raw_file_names
property
¶
raw_file_names
Return a list of raw file names in the raw directory.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: List of raw file names. |
download ¶
download()
Download the raw data. This method should be overridden if you need to download the data.
Source code in src/segger/data/utils.py
472 473 474 |
|
get ¶
get(idx)
Get a processed data object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx
|
int
|
Index of the data object to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
Data |
Data
|
The processed data object. |
Source code in src/segger/data/utils.py
488 489 490 491 492 493 494 495 496 497 498 499 |
|
len ¶
len()
Return the number of processed files.
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Number of processed files. |
Source code in src/segger/data/utils.py
480 481 482 483 484 485 486 |
|
process ¶
process()
Process the raw data and save it to the processed directory. This method should be overridden if you need to process the data.
Source code in src/segger/data/utils.py
476 477 478 |
|
SpatialTranscriptomicsKeys ¶
Bases: Enum
Unified keys for spatial transcriptomics data, supporting multiple platforms.
SpatialTranscriptomicsSample ¶
SpatialTranscriptomicsSample(transcripts_df=None, transcripts_radius=10, boundaries_graph=False, embedding_df=None, keys=None, verbose=True)
Bases: ABC
Initialize the SpatialTranscriptomicsSample class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcripts_df
|
DataFrame
|
A DataFrame containing transcript data. |
None
|
transcripts_radius
|
int
|
Radius for transcripts in the analysis. |
10
|
boundaries_graph
|
bool
|
Whether to include boundaries (e.g., nucleus, cell) graph information. |
False
|
keys
|
Dict
|
The enum class containing key mappings specific to the dataset. |
None
|
Source code in src/segger/data/io.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
build_pyg_data_from_tile ¶
build_pyg_data_from_tile(boundaries_df, transcripts_df, r_tx=5.0, k_tx=3, method='kd_tree', gpu=False, workers=1, scale_boundaries=1.0)
Builds PyG data from a tile of boundaries and transcripts data using Dask utilities for efficient processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boundaries_df
|
DataFrame
|
Dask DataFrame containing boundaries data (e.g., nucleus, cell). |
required |
transcripts_df
|
DataFrame
|
Dask DataFrame containing transcripts data. |
required |
r_tx
|
float
|
Radius for building the transcript-to-transcript graph. |
5.0
|
k_tx
|
int
|
Number of nearest neighbors for the tx-tx graph. |
3
|
method
|
str
|
Method for computing edge indices (e.g., 'kd_tree', 'faiss'). |
'kd_tree'
|
gpu
|
bool
|
Whether to use GPU acceleration for edge index computation. |
False
|
workers
|
int
|
Number of workers to use for parallel processing. |
1
|
scale_boundaries
|
float
|
The factor by which to scale the boundary polygons. Default is 1.0. |
1.0
|
Returns:
Name | Type | Description |
---|---|---|
HeteroData |
HeteroData
|
PyG Heterogeneous Data object. |
Source code in src/segger/data/io.py
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 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
|
compute_boundaries_geometries ¶
compute_boundaries_geometries(boundaries_df=None, polygons_gdf=None, scale_factor=1.0, area=True, convexity=True, elongation=True, circularity=True)
Computes geometries for boundaries (e.g., nuclei, cells) from the dataframe using Dask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boundaries_df
|
DataFrame
|
The dataframe containing boundaries data. Required if polygons_gdf is not provided. |
None
|
polygons_gdf
|
GeoDataFrame
|
Precomputed Dask GeoDataFrame containing boundary polygons. If None, will compute from boundaries_df. |
None
|
scale_factor
|
float
|
The factor by which to scale the polygons (default is 1.0). |
1.0
|
area
|
bool
|
Whether to compute area. |
True
|
convexity
|
bool
|
Whether to compute convexity. |
True
|
elongation
|
bool
|
Whether to compute elongation. |
True
|
circularity
|
bool
|
Whether to compute circularity. |
True
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
dgpd.GeoDataFrame: A GeoDataFrame containing computed geometries. |
Source code in src/segger/data/io.py
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
|
compute_transcript_overlap_with_boundaries ¶
compute_transcript_overlap_with_boundaries(transcripts_df, boundaries_df=None, polygons_gdf=None, scale_factor=1.0)
Computes the overlap of transcript locations with scaled boundary polygons and assigns corresponding cell IDs to the transcripts using Dask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcripts_df
|
DataFrame
|
Dask DataFrame containing transcript data. |
required |
boundaries_df
|
DataFrame
|
Dask DataFrame containing boundary data. Required if polygons_gdf is not provided. |
None
|
polygons_gdf
|
GeoDataFrame
|
Precomputed Dask GeoDataFrame containing boundary polygons. If None, will compute from boundaries_df. |
None
|
scale_factor
|
float
|
The factor by which to scale the boundary polygons. Default is 1.0. |
1.0
|
Returns:
Type | Description |
---|---|
DataFrame
|
dd.DataFrame: The updated DataFrame with overlap information and assigned cell IDs. |
Source code in src/segger/data/io.py
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 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
|
create_scaled_polygon
staticmethod
¶
create_scaled_polygon(group, scale_factor, keys)
Static method to create and scale a polygon from boundary vertices and return a GeoDataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group
|
DataFrame
|
Group of boundary coordinates (for a specific cell). |
required |
scale_factor
|
float
|
The factor by which to scale the polygons. |
required |
keys
|
Dict or Enum
|
A collection of keys to access column names for 'cell_id', 'vertex_x', and 'vertex_y'. |
required |
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: A GeoDataFrame containing the scaled Polygon and cell_id. |
Source code in src/segger/data/io.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
|
filter_transcripts
abstractmethod
¶
filter_transcripts(transcripts_df, min_qv=20.0)
Abstract method to filter transcripts based on dataset-specific criteria.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcripts_df
|
DataFrame
|
The dataframe containing transcript data. |
required |
min_qv
|
float
|
The minimum quality value threshold for filtering transcripts. |
20.0
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The filtered dataframe. |
Source code in src/segger/data/io.py
63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
generate_and_scale_polygons ¶
generate_and_scale_polygons(boundaries_df, scale_factor=1.0)
Generate and scale polygons from boundary coordinates using Dask. Keeps class structure intact by using static method for the core polygon generation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
boundaries_df
|
DataFrame
|
DataFrame containing boundary coordinates. |
required |
scale_factor
|
float
|
The factor by which to scale the polygons (default is 1.0). |
1.0
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
dgpd.GeoDataFrame: A GeoDataFrame containing scaled Polygon objects and their centroids. |
Source code in src/segger/data/io.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 |
|
load_boundaries ¶
load_boundaries(path, file_format='parquet', x_min=None, x_max=None, y_min=None, y_max=None)
Load boundaries data lazily using Dask, filtering by the specified bounding box.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
Path
|
Path to the boundaries file. |
required |
file_format
|
str
|
Format of the file to load. Only 'parquet' is supported in this refactor. |
'parquet'
|
x_min
|
float
|
Minimum X-coordinate for the bounding box. |
None
|
x_max
|
float
|
Maximum X-coordinate for the bounding box. |
None
|
y_min
|
float
|
Minimum Y-coordinate for the bounding box. |
None
|
y_max
|
float
|
Maximum Y-coordinate for the bounding box. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
dd.DataFrame: The filtered boundaries DataFrame. |
Source code in src/segger/data/io.py
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 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 |
|
load_transcripts ¶
load_transcripts(base_path=None, sample=None, transcripts_filename=None, path=None, file_format='parquet', x_min=None, x_max=None, y_min=None, y_max=None)
Load transcripts from a Parquet file using Dask for efficient chunked processing, only within the specified bounding box, and return the filtered DataFrame with integer token embeddings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_path
|
Path
|
The base directory path where samples are stored. |
None
|
sample
|
str
|
The sample name or identifier. |
None
|
transcripts_filename
|
str
|
The filename of the transcripts file (default is derived from the dataset keys). |
None
|
path
|
Path
|
Specific path to the transcripts file. |
None
|
file_format
|
str
|
Format of the file to load (default is 'parquet'). |
'parquet'
|
x_min
|
float
|
Minimum X-coordinate for the bounding box. |
None
|
x_max
|
float
|
Maximum X-coordinate for the bounding box. |
None
|
y_min
|
float
|
Minimum Y-coordinate for the bounding box. |
None
|
y_max
|
float
|
Maximum Y-coordinate for the bounding box. |
None
|
Returns:
Type | Description |
---|---|
DataFrame
|
dd.DataFrame: The filtered transcripts DataFrame. |
Source code in src/segger/data/io.py
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 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 |
|
save_dataset_for_segger ¶
save_dataset_for_segger(processed_dir, x_size=1000, y_size=1000, d_x=900, d_y=900, margin_x=None, margin_y=None, compute_labels=True, r_tx=5, k_tx=3, val_prob=0.1, test_prob=0.2, neg_sampling_ratio_approx=5, sampling_rate=1, num_workers=1, scale_boundaries=1.0, method='kd_tree', gpu=False, workers=1)
Saves the dataset for Segger in a processed format using Dask for parallel and lazy processing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
processed_dir
|
Path
|
Directory to save the processed dataset. |
required |
x_size
|
float
|
Width of each tile. |
1000
|
y_size
|
float
|
Height of each tile. |
1000
|
d_x
|
float
|
Step size in the x direction for tiles. |
900
|
d_y
|
float
|
Step size in the y direction for tiles. |
900
|
margin_x
|
float
|
Margin in the x direction to include transcripts. |
None
|
margin_y
|
float
|
Margin in the y direction to include transcripts. |
None
|
compute_labels
|
bool
|
Whether to compute edge labels for tx_belongs_bd edges. |
True
|
r_tx
|
float
|
Radius for building the transcript-to-transcript graph. |
5
|
k_tx
|
int
|
Number of nearest neighbors for the tx-tx graph. |
3
|
val_prob
|
float
|
Probability of assigning a tile to the validation set. |
0.1
|
test_prob
|
float
|
Probability of assigning a tile to the test set. |
0.2
|
neg_sampling_ratio_approx
|
float
|
Approximate ratio of negative samples. |
5
|
sampling_rate
|
float
|
Rate of sampling tiles. |
1
|
num_workers
|
int
|
Number of workers to use for parallel processing. |
1
|
scale_boundaries
|
float
|
The factor by which to scale the boundary polygons. Default is 1.0. |
1.0
|
method
|
str
|
Method for computing edge indices (e.g., 'kd_tree', 'faiss'). |
'kd_tree'
|
gpu
|
bool
|
Whether to use GPU acceleration for edge index computation. |
False
|
workers
|
int
|
Number of workers to use to compute the neighborhood graph (per tile). |
1
|
Source code in src/segger/data/io.py
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 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 |
|
set_embedding ¶
set_embedding(embedding_name)
Set the current embedding type for the transcripts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding_name
|
str The name of the embedding to use. |
required |
Source code in src/segger/data/io.py
402 403 404 405 406 407 408 409 410 411 412 413 414 |
|
set_file_paths ¶
set_file_paths(transcripts_path, boundaries_path)
Set the paths for the transcript and boundary files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcripts_path
|
Path
|
Path to the Parquet file containing transcripts data. |
required |
boundaries_path
|
Path
|
Path to the Parquet file containing boundaries data. |
required |
Source code in src/segger/data/io.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
set_metadata ¶
set_metadata()
Set metadata for the transcript dataset, including bounding box limits and unique gene names, without reading the entire Parquet file. Additionally, return integer tokens for unique gene names instead of one-hot encodings and store the lookup table for later mapping.
Source code in src/segger/data/io.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 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 399 400 |
|
XeniumKeys ¶
Bases: Enum
Keys for 10X Genomics Xenium formatted dataset.
XeniumSample ¶
XeniumSample(transcripts_df=None, transcripts_radius=10, boundaries_graph=False, embedding_df=None, verbose=True)
Bases: SpatialTranscriptomicsSample
Source code in src/segger/data/io.py
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 |
|
filter_transcripts ¶
filter_transcripts(transcripts_df, min_qv=20.0)
Filters transcripts based on quality value and removes unwanted transcripts for Xenium using Dask.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcripts_df
|
DataFrame
|
The Dask DataFrame containing transcript data. |
required |
min_qv
|
float
|
The minimum quality value threshold for filtering transcripts. |
20.0
|
Returns:
Type | Description |
---|---|
DataFrame
|
dd.DataFrame: The filtered Dask DataFrame. |
Source code in src/segger/data/io.py
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 |
|
calculate_gene_celltype_abundance_embedding ¶
calculate_gene_celltype_abundance_embedding(adata, celltype_column)
Calculate the cell type abundance embedding for each gene based on the percentage of cells in each cell type that express the gene (non-zero expression).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
adata
|
AnnData
|
An AnnData object containing gene expression data and cell type information. |
required |
celltype_column
|
str
|
The column name in |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: A DataFrame where rows are genes and columns are cell types, with each value representing the percentage of cells in that cell type expressing the gene. |
Example
adata = AnnData(...) # Load your scRNA-seq AnnData object celltype_column = 'celltype_major' abundance_df = calculate_gene_celltype_abundance_embedding(adata, celltype_column) abundance_df.head()
Source code in src/segger/data/utils.py
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 261 262 263 264 |
|
compute_transcript_metrics ¶
compute_transcript_metrics(df, qv_threshold=30, cell_id_col='cell_id')
Computes various metrics for a given dataframe of transcript data filtered by quality value threshold.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The dataframe containing transcript data. |
required |
qv_threshold
|
float
|
The quality value threshold for filtering transcripts. |
30
|
cell_id_col
|
str
|
The name of the column representing the cell ID. |
'cell_id'
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: A dictionary containing various transcript metrics: - 'percent_assigned' (float): The percentage of assigned transcripts. - 'percent_cytoplasmic' (float): The percentage of cytoplasmic transcripts among assigned transcripts. - 'percent_nucleus' (float): The percentage of nucleus transcripts among assigned transcripts. - 'percent_non_assigned_cytoplasmic' (float): The percentage of non-assigned cytoplasmic transcripts. - 'gene_metrics' (pd.DataFrame): A dataframe containing gene-level metrics. |
Source code in src/segger/data/utils.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 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 |
|
create_anndata ¶
create_anndata(df, panel_df=None, min_transcripts=5, cell_id_col='cell_id', qv_threshold=30, min_cell_area=10.0, max_cell_area=1000.0)
Generates an AnnData object from a dataframe of segmented transcriptomics data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df
|
DataFrame
|
The dataframe containing segmented transcriptomics data. |
required |
panel_df
|
Optional[DataFrame]
|
The dataframe containing panel information. |
None
|
min_transcripts
|
int
|
The minimum number of transcripts required for a cell to be included. |
5
|
cell_id_col
|
str
|
The column name representing the cell ID in the input dataframe. |
'cell_id'
|
qv_threshold
|
float
|
The quality value threshold for filtering transcripts. |
30
|
min_cell_area
|
float
|
The minimum cell area to include a cell. |
10.0
|
max_cell_area
|
float
|
The maximum cell area to include a cell. |
1000.0
|
Returns:
Type | Description |
---|---|
AnnData
|
ad.AnnData: The generated AnnData object containing the transcriptomics data and metadata. |
Source code in src/segger/data/utils.py
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 |
|
filter_transcripts ¶
filter_transcripts(transcripts_df, min_qv=20.0)
Filters transcripts based on quality value and removes unwanted transcripts.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
transcripts_df
|
DataFrame
|
The dataframe containing transcript data. |
required |
min_qv
|
float
|
The minimum quality value threshold for filtering transcripts. |
20.0
|
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame: The filtered dataframe. |
Source code in src/segger/data/utils.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
format_time ¶
format_time(elapsed)
Format elapsed time to hs.
Parameters:¶
elapsed : float Elapsed time in seconds.
Returns:¶
str Formatted time in hs.
Source code in src/segger/data/utils.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 |
|
get_edge_index ¶
get_edge_index(coords_1, coords_2, k=5, dist=10, method='kd_tree', gpu=False, workers=1)
Computes edge indices using various methods (KD-Tree, FAISS, RAPIDS::cuvs+cupy (cuda)).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coords_1
|
ndarray
|
First set of coordinates. |
required |
coords_2
|
ndarray
|
Second set of coordinates. |
required |
k
|
int
|
Number of nearest neighbors. |
5
|
dist
|
int
|
Distance threshold. |
10
|
method
|
str
|
The method to use ('kd_tree', 'faiss', 'cuda'). |
'kd_tree'
|
gpu
|
bool
|
Whether to use GPU acceleration (applicable for FAISS). |
False
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Edge indices. |
Source code in src/segger/data/utils.py
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 |
|
get_edge_index_cuda ¶
get_edge_index_cuda(coords_1, coords_2, k=10, dist=10.0, metric='sqeuclidean', nn_descent_niter=100)
Computes edge indices using RAPIDS cuVS with cagra for vector similarity search, with input coordinates as PyTorch tensors on CUDA, using DLPack for conversion.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coords_1
|
Tensor
|
First set of coordinates (query vectors) on CUDA. |
required |
coords_2
|
Tensor
|
Second set of coordinates (index vectors) on CUDA. |
required |
k
|
int
|
Number of nearest neighbors. |
10
|
dist
|
float
|
Distance threshold. |
10.0
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Edge indices as a PyTorch tensor on CUDA. |
Source code in src/segger/data/utils.py
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 399 400 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 |
|
get_edge_index_faiss ¶
get_edge_index_faiss(coords_1, coords_2, k=5, dist=10, gpu=False)
Computes edge indices using FAISS.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coords_1
|
ndarray
|
First set of coordinates. |
required |
coords_2
|
ndarray
|
Second set of coordinates. |
required |
k
|
int
|
Number of nearest neighbors. |
5
|
dist
|
int
|
Distance threshold. |
10
|
gpu
|
bool
|
Whether to use GPU acceleration. |
False
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Edge indices. |
Source code in src/segger/data/utils.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
get_edge_index_kdtree ¶
get_edge_index_kdtree(coords_1, coords_2, k=5, dist=10, workers=1)
Computes edge indices using KDTree.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coords_1
|
ndarray
|
First set of coordinates. |
required |
coords_2
|
ndarray
|
Second set of coordinates. |
required |
k
|
int
|
Number of nearest neighbors. |
5
|
dist
|
int
|
Distance threshold. |
10
|
Returns:
Type | Description |
---|---|
Tensor
|
torch.Tensor: Edge indices. |
Source code in src/segger/data/utils.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
|
get_xy_extents ¶
get_xy_extents(filepath, x, y)
Get the bounding box of the x and y coordinates from a Parquet file.
Parameters¶
filepath : str The path to the Parquet file. x : str The name of the column representing the x-coordinate. y : str The name of the column representing the y-coordinate.
Returns¶
shapely.Polygon A polygon representing the bounding box of the x and y coordinates.
Source code in src/segger/data/utils.py
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 538 539 |
|