biostrings package

Submodules

biostrings.dnastring module

class biostrings.dnastring.DNAString(sequence, metadata=None, _validate=True)[source]

Bases: BiocObject

A string container for a DNA sequence, similar to Bioconductor’s DNAString.

This class stores the sequence internally as bytes, enforcing the DNA alphabet.

__copy__()[source]

Shallow copy of the object.

Return type:

DNAString

Returns:

Same type as the caller, a shallow copy of this object.

__deepcopy__(memo)[source]

Deep copy of the object.

Parameters:

memo – Passed to internal deepcopy() calls.

Return type:

DNAString

Returns:

Same type as the caller, a deep copy of this object.

__eq__(other)[source]

Check for equality with another DNAString or str.

Return type:

bool

__getitem__(key)[source]

Extract a subsequence (slicing).

Parameters:

key (Union[int, slice]) – An integer or slice.

Return type:

DNAString

Returns:

A new DNAString object representing the subsequence.

__hash__ = None
__init__(sequence, metadata=None, _validate=True)[source]

Create a DNAString.

Parameters:
  • sequence (Union[str, bytes]) – A string or bytes object representing a DNA sequence.

  • metadata (Union[Dict[str, Any], NamedList, None]) – Additional metadata. If None, defaults to an empty dictionary.

  • _validate (bool) – Whether to validate the arguments, internal use only.

__len__()[source]

Return the length of the sequence.

Return type:

int

__repr__()[source]

Return a string representation.

Return type:

str

get_sequence()[source]

Get the sequence.

Return type:

str

Returns:

The sequence string.

reverse_complement()[source]

Compute the reverse complement of the sequence.

Return type:

DNAString

Returns:

A new DNAString with the reverse complement.

to_bytes()[source]

Get the underlying byte representation.

Return type:

bytes

biostrings.dnastringset module

class biostrings.dnastringset.DNAStringSet(sequences=None, names=None, _pool=None, _ranges=None, metadata=None, _validate=True)[source]

Bases: BiocObject

A collection of DNA sequences, similar to Bioconductor’s DNAStringSet.

This class follows the “pool and ranges” model for high memory efficiency. All sequences are stored in a single concatenated ‘bytes’ object (the pool).

An ‘IRanges’ object tracks the start and width of each sequence in the pool.

__annotations__ = {}
__copy__()[source]

Shallow copy of the object.

Return type:

DNAStringSet

Returns:

Same type as the caller, a shallow copy of this object.

__deepcopy__(memo)[source]

Deep copy of the object.

Parameters:

memo – Passed to internal deepcopy() calls.

Return type:

DNAStringSet

Returns:

Same type as the caller, a deep copy of this object.

__getitem__(key)[source]

Extract one or more sequences.

Parameters:

key (Union[int, slice, List[int], ndarray]) –

  • If key is int: Returns a DNAString object (a copy).

  • If key is slice or list: Returns a new DNAStringSet (a view).

Return type:

Union[DNAString, DNAStringSet]

Returns:

A DNAString or DNAStringSet object representing the slice.

__init__(sequences=None, names=None, _pool=None, _ranges=None, metadata=None, _validate=True)[source]

Create a DNAStringSet.

Parameters:
  • sequences (Optional[List[str]]) – A list of Python strings to initialize the set.

  • names (Union[List[str], Names, None]) – An optional list of names for the sequences.

  • _pool (internal) – Used by methods like __getitem__ to create new sets without copying data.

  • _ranges (internal) – Used by methods like __getitem__.

  • metadata (Union[Dict[str, Any], NamedList, None]) – Additional metadata. If None, defaults to an empty dictionary.

  • validate – Whether to validate the arguments, internal use only.

__len__()[source]

Return the number of sequences in the set.

Return type:

int

__repr__()[source]

Return a compact representation.

Return type:

str

get_names()[source]

Get range names.

Return type:

Optional[Names]

Returns:

List containing the names for all ranges, or None if no names are present.

get_width()[source]

Return an array of lengths for all sequences.

Return type:

ndarray

property names: Names | None

Return the names of the sequences.

set_names(names, in_place=False)[source]
Parameters:
  • names (Optional[List[str]]) – Sequence of names or None, see the constructor for details.

  • in_place (bool) – Whether to modify the object in place.

Return type:

DNAStringSet

Returns:

If in_place = False, a new DNAStringSet is returned with the modified names. Otherwise, the current object is directly modified and a reference to it is returned.

to_list()[source]

Convert the set to a list of Python strings.

Return type:

List[str]

unlist()[source]

Concatenate all sequences in the set into one DNAString.

Return type:

DNAString

width()[source]

Alias to get_width().

Return type:

ndarray

biostrings.lib_biostrings module

biostrings.utils module

Module contents