torchcell.sequence.get_chr_from_description

get_chr_from_description(description: str) → int[source]

Extracts the chromosome number from a given description string.

Processes a description string containing either a chromosome in Roman numeral (e.g., “[chromosome=IX]”). Or a location (e.g., “[location=mitochondrion]”). If a chromosome is found, it converts the Roman numeral to an integer. If the location is a mitochondrion, it returns 0. Handles descriptions containing chromosome information in a predefined format.

Parameters:

description (str) – Description string containing chromosome number

Returns:

Chromosome number. Returns 0 if the location is mitochondrion.

Return type:

int

Raises:
  • ValueError – If the description carries neither a [chromosome=...] tag nor a [location=mitochondrion] tag.

  • KeyError – If the chromosome tag is not a Roman numeral.

Example

>>> get_chr_from_description("[chromosome=IX] some other info")
9
>>> get_chr_from_description("[location=mitochondrion] some other info")
0