gctree.isotyping

A module for incorporating isotype information in gctree inference.

Functions

explode_idmap

Uses provided mapping of original sequence IDs to observed isotypes to 'explode' the provided mapping of unique sequence IDs to original sequence IDs.

isotype_distance

Returns the weight of the transition from isotype t1 to isotype t2.

isotype_parsimony

Computes the sum of isotype_distance() along each edge in an isotyped tree.

isotype_tree

Method adds isotypes to tree, minimizing isotype switching and obeying switching order.

Classes

Isotype

An isotype, and associated information about class switching order and transition weights.

IsotypeTemplate

A template constructor class for Isotype()

class gctree.isotyping.IsotypeTemplate(isotype_order, weight_matrix=None)[source]

A template constructor class for Isotype()

Parameters:
  • isotype_order (Sequence[str]) – A list or other Sequence of isotype names, in the allowed class switching order

  • weight_matrix (Optional[Sequence[Sequence[float]]]) – An optional matrix containing transition weights between isotypes. Default weight is 1 for all allowed isotype transitions.

__init__(isotype_order, weight_matrix=None)[source]
new(isotype_name)[source]

Return an Isotype() object with the isotype order and weight matrix provided to this class’s constructor.

class gctree.isotyping.Isotype(order, weight_matrix, isotype_name)[source]

An isotype, and associated information about class switching order and transition weights.

order

A list or other sequence of isotype names, in their allowed class switching order

weight_matrix

Transition weights between isotypes, with first index the original isotype index, and second index the new isotype index.

isotype

Index of isotype name in self.order

Objects of this class shall be instantiated using IsotypeTemplate.new().

__init__(order, weight_matrix, isotype_name)[source]
resolutions()[source]

Returns list of all possible isotypes if passed an ambiguous isotype.

Otherwise, returns a list containing a copy of the passed isotype.

Return type:

Sequence[Isotype]

gctree.isotyping.isotype_tree(tree, newidmap, isotype_names, weight_matrix=None)[source]

Method adds isotypes to tree, minimizing isotype switching and obeying switching order.

  • Adds observed isotypes to each observed node in the collapsed trees output by gctree inference. If cells with the same sequence but different isotypes are observed, then collapsed tree nodes must be ‘exploded’ into new nodes with the appropriate isotypes and abundances. Each unique sequence ID generated by gctree is prepended to its observed isotype, and a new isotyped.idmap mapping these new sequence IDs to original sequence IDs is written in the output directory.

  • Resolves isotypes of unobserved ancestral genotypes in a way that minimizes isotype switching and obeys isotype switching order. If observed isotypes of an observed internal node and its children violate switching order, then the observed internal node is replaced with an unobserved node with the same sequence, and the observed internal node is placed as a child leaf. This procedure always allows switching order conflicts to be resolved, and should usually increase isotype transitions required in the resulting tree.

Parameters:
  • tree (TreeNode) – ete3 Tree

  • newidmap (Dict[str, Dict[str, str]]) – mapping of sequence IDs to isotypes, such as that output by utils.explode_idmap().

  • isotype_names (Sequence[str]) – list or other sequence of isotype names observed, in correct switching order.

Return type:

TreeNode

Returns:

A new ete3 Tree whose nodes have isotype annotations in the attribute isotype. Node names in this tree also contain isotype names.

gctree.isotyping.isotype_distance(t1, t2)[source]

Returns the weight of the transition from isotype t1 to isotype t2.

This function is not symmetric on its arguments, so isn’t a true distance.

Return type:

float

gctree.isotyping.isotype_parsimony(tree)[source]

Computes the sum of isotype_distance() along each edge in an isotyped tree.

If no weight matrix was provided during isotyping of the tree, then the return value of this function is the number of isotype transitions along edges in the tree.

Return type:

float

gctree.isotyping.explode_idmap(idmap, isotype_map)[source]

Uses provided mapping of original sequence IDs to observed isotypes to ‘explode’ the provided mapping of unique sequence IDs to original sequence IDs.

Parameters:
  • idmap (Dict[str, Set[str]]) – A dictionary mapping unique sequence IDs to sets of original IDs of observed sequences

  • isotype_map (Dict[str, str]) – A dictionary mapping original IDs to observed isotype names

Return type:

Dict[str, Dict[str, Set[str]]]

Returns:

A dictionary mapping unique sequence IDs to dictionaries, mapping isotype names to sets of original sequence IDs.