Python API
lanctools exports two classes for working with local ancestry data. LancData contains the genotype and local ancestry data for a set of plink2 .pgen and .lanc files, together with efficient methods for querying this data. FlatLanc is the core data structure which stores local ancestry data in a flattened structure.
lanctools.LancData
The genotype and local ancestry data for a single chromosome/dataset.
Attributes:
| Name | Type | Description |
|---|---|---|
pgen |
PgenReader
|
A pgenlib PgenReader object. |
pvar |
PvarReader
|
A pgenlib PVarReader object. |
lanc |
FlatLanc
|
A FlatLanc object with local ancestry data. |
ancestries |
list[str]
|
An ordered list of ancestry names. The integer codes in
the .lanc file and |
plink_prefix |
str
|
The prefix for the corresponding plink2 fileset. |
Source code in src/lanctools/core.py
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 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 401 | |
__init__(plink_prefix, lanc_file, ancestries=None)
Constructs a LancData from plink2 files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plink_prefix
|
str
|
The prefix for a plink2 fileset. |
required |
lanc_file
|
str
|
The path to a .lanc file. |
required |
ancestries
|
Optional[list[str]
|
An optional list of ordered ancestry names corresponding to the .lanc file. |
None
|
Source code in src/lanctools/core.py
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 | |
get_geno(indices)
Query phased genotypes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
NDArray[uint32]
|
An array of variant indices in pvar order (0-based), shape (V,) |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
An array of phased genotypes, shape (N, V, 2) |
Source code in src/lanctools/core.py
370 371 372 373 374 375 376 377 378 379 380 | |
get_info(indices)
Query info for a set of variants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
NDArray[uint32]
|
The variant indices in pvar order (0-based), shape (V,) |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pandas.DataFrame: One row per variant with the following columns:
|
Source code in src/lanctools/core.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
get_lanc(indices)
Query phased local ancestry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
NDArray[unsignedinteger]
|
The variant indices in pvar order (0-based), shape (V,) |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
An array of ancestries, shape (N, V, 2) |
Source code in src/lanctools/core.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
get_lanc_dosage(indices)
Query local ancestry dosage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
NDArray[uint32]
|
An array of variant indices in pvar order (0-based), shape (V,) |
required |
Returns:
| Type | Description |
|---|---|
NDArray[uint8]
|
An array of local ancestry dosages, shape (N, V, K) (where K is the number of ancestries) |
Source code in src/lanctools/core.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
get_lanc_geno(indices)
Query genotypes deconvoluted/masked by ancestry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indices
|
NDArray[unsignedinteger]
|
An array of variant indices in pvar order (0-based), shape (V,) |
required |
Returns:
| Type | Description |
|---|---|
NDArray[int32]
|
An array of genotypes masked by ancestry, shape (N, V, 2) |
Source code in src/lanctools/core.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | |
lanctools.FlatLanc
Stores .lanc file ancestry data in a flattened structure for fast querying.
Attributes:
| Name | Type | Description |
|---|---|---|
right_haps |
NDArray[uint8]
|
Concatenated right haplotypes for all samples, shape (H,) |
left_haps |
NDArray[uint8]
|
Concatenated left haplotypes for all samples, shape (H,) |
breakpoints |
NDArray[uint32]
|
Concatenated breakpoints for all samples, shape (H,) |
offsets |
NDArray[uint32]
|
Cumulative end indices separating samples, shape (N,) |
Source code in src/lanctools/core.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |