tracts.haploid.Haploid#
- class Haploid(Ls=None, lschroms=None, fname=None, selectchrom=None, labs=None, name=None, allosomes=None)#
Bases:
objectA class representing a haploid genome, composed of a set of chromosomes, each of which consists of a list of tracts.
- Ls#
The lengths of the chromosomes.
- Type:
list of float
- chroms#
The chromosome objects.
- Type:
list of
tracts.chromosome.Chrom
- labs#
Labels identifying the chromosomes.
- Type:
list of str
- name#
An optional name for the haploid.
- Type:
str
- allosomes#
A dictionary mapping chromosome labels to chromosome objects, for chromosomes that are treated as allosomes.
- Type:
dict
- __init__(Ls=None, lschroms=None, fname=None, selectchrom=None, labs=None, name=None, allosomes=None)#
Initialize a Haploid object.
- Parameters:
Ls (
list) – The lengths of the chromosomes. If not provided, the lengths will be inferred from the chromosome objects provided in lschroms. If neither Ls nor lschroms are provided, an error will be raised.lschroms (
list) – The chromosome objects. If not provided, the chromosome objects will be loaded from the file specified by fname. If neither lschroms nor fname are provided, an error will be raised.fname (
str) – The path to the file containing the haploid genome data. If not provided, the chromosome objects will be provided directly in lschroms. If neither fname nor lschroms are provided, an error will be raised. The file should be a tab-delimited text file with columns: chrom, start, end, label, and optionally others. The first line may be a header, which will be automatically skipped if it contains the expected column names.selectchrom (
list[int|str] |None) – An optional list of chromosome identifiers specifying which chromosomes to select from the file. If not provided, all chromosomes will be selected. The list should contain chromosome identifiers as strings or integers corresponding to the chromosome numbers in the file (e.g., [“1”, “2”, “3”]). Chromosome identifiers that cannot be converted to integers will be ignored, and the corresponding chromosomes will not be selected.labs (
list) – A list of labels for the chromosomes. If not provided, no labels will be assigned.name (
str) – An optional name for the haploid genome. If not provided, the name will be set to None.allosomes (
dict[Any,Chrom]) – An optional dictionary mapping chromosome labels to chromosome objects, for chromosomes that are treated as allosomes. If not provided, no chromosomes will be treated as allosomes. Chromosome labels should be strings corresponding to the chromosome identifiers in the file (e.g., “X” for the X chromosome). Chromosome labels that are not present in the file will be ignored, and no chromosomes will be treated as allosomes.
- static from_file(path, name=None, selectchrom=None, allosome_labels=None)#
Load a haploid genome from a file.
- Parameters:
path (
str) – The path to the file containing the haploid genome data. The file should be a tab-delimited text file with columns: chrom, start, end, label, and optionally others. The first line may be a header, which will be automatically skipped if it contains the expected column names.name (
str) – An optional name for the haploid genome. If not provided, the name will be set to None.selectchrom (
list[int|str] |None) – An optional list of chromosome identifiers specifying which chromosomes to select from the file. If not provided, all chromosomes will be selected. Elements are converted to integers when possible. Non-numeric values are ignored with a warning.allosome_labels (
set|None) – An optional set of chromosome labels that should be treated as allosomes. If not provided, no chromosomes will be treated as allosomes. Chromosome labels should be strings corresponding to the chromosome identifiers in the file (e.g., “X” for the X chromosome). Chromosome labels that are not present in the file will be ignored, and no chromosomes will be treated as allosomes.
- Returns:
A Haploid object representing the loaded haploid genome.
- Return type: