scirpy.io.AirrCell#

class scirpy.io.AirrCell(cell_id, cell_attribute_fields=(), *, logger=<module 'scanpy.logging' from '/home/docs/checkouts/readthedocs.org/user_builds/scirpy/envs/v0.17.2/lib/python3.10/site-packages/scanpy/logging.py'>)#

Data structure for a Cell with immune receptors. Represents one row of adata.obsm["airr"].

This data structure is compliant with the AIRR rearrangement schema v1.0. An AirrCell can hold multiple chains (i.e. rows from the rearrangement TSV) which belong to the same cell. A chain is represented as a dictionary, where the keys are AIRR-rearrangement fields.

The AirrCell can, additionally, hold cell-level attributes which can be set in a dict-like fashion. Keys marked as “cell-level” via cell_attribute_fields will be automatically transferred to the cell-level when added through a chain. They are required to have the same value for all chains.

Parameters:
  • cell_id (str) – cell id or barcode. Needs to match the cell id used for transcriptomics data, if any.

  • cell_attribute_fields (Collection[str] (default: ())) – List of field-names which are supposed to be stored at the cell-level rather than the chain level. If a chain with these fields is added to the cell, they are set on the cell-level instead. If the values already exist on the cell-level, a ValueError is raised, if they differ from the values that are already present.

  • logger (Any (default: <module 'scanpy.logging' from '/home/docs/checkouts/readthedocs.org/user_builds/scirpy/envs/v0.17.2/lib/python3.10/site-packages/scanpy/logging.py'>)) – A logger to write messages to. If not specified, use scanpy’s default logger.

Attributes table#

VALID_LOCI

Valid chains are IMGT locus names see https://docs.airr-community.org/en/latest/datarep/rearrangements.html#locus-names

VDJ_LOCI

Identifiers of loci with a V-D-J junction

VJ_LOCI

Identifiers of loci with a V-J junction

cell_id

Unique identifier (barcode) of the cell.

chains

List of chain-dictionaries added to the cell.

fields

Return a list of all fields (chain-level and cell-level)

Methods table#

add_chain(chain)

Add a chain to the cell.

add_serialized_chains(serialized_chains)

Add chains serialized as JSON.

clear()

empty_chain_dict()

Generate an empty chain dictionary, containing all required AIRR columns, but set to None

get(k[,d])

items()

keys()

pop(k[,d])

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem()

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[,d])

to_airr_records()

Iterate over chains as AIRR-Rearrangent compliant dictonaries.

update([E, ]**F)

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values()

Attributes#

AirrCell.VALID_LOCI = ('TRA', 'TRG', 'IGK', 'IGL', 'TRB', 'TRD', 'IGH')#

Valid chains are IMGT locus names see https://docs.airr-community.org/en/latest/datarep/rearrangements.html#locus-names

AirrCell.VDJ_LOCI = ('TRB', 'TRD', 'IGH')#

Identifiers of loci with a V-D-J junction

AirrCell.VJ_LOCI = ('TRA', 'TRG', 'IGK', 'IGL')#

Identifiers of loci with a V-J junction

AirrCell.cell_id#

Unique identifier (barcode) of the cell.

AirrCell.chains#

List of chain-dictionaries added to the cell.

AirrCell.fields#

Return a list of all fields (chain-level and cell-level)

Methods#

AirrCell.add_chain(chain)#

Add a chain to the cell.

A chain is a dictionary following the AIRR Rearrangement Schema.

Return type:

None

AirrCell.add_serialized_chains(serialized_chains)#

Add chains serialized as JSON.

The JSON object needs to be a list of dicts. If serialized_chains is a value interpreted as NA, the function passes silently and does nothing.

Return type:

None

AirrCell.clear() None.  Remove all items from D.#
static AirrCell.empty_chain_dict()#

Generate an empty chain dictionary, containing all required AIRR columns, but set to None

Return type:

dict

AirrCell.get(k[, d]) D[k] if k in D, else d.  d defaults to None.#
AirrCell.items() a set-like object providing a view on D's items#
AirrCell.keys() a set-like object providing a view on D's keys#
AirrCell.pop(k[, d]) v, remove specified key and return the corresponding value.#

If key is not found, d is returned if given, otherwise KeyError is raised.

AirrCell.popitem() (k, v), remove and return some (key, value) pair#

as a 2-tuple; but raise KeyError if D is empty.

AirrCell.setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D#
AirrCell.to_airr_records()#

Iterate over chains as AIRR-Rearrangent compliant dictonaries. Each dictionary will also include the cell-level information.

Yields:

Dictionary representing one row of a AIRR rearrangement table

Return type:

Iterable[dict]

AirrCell.update([E, ]**F) None.  Update D from mapping/iterable E and F.#

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

AirrCell.values() an object providing a view on D's values#