dasi.models.alignment_container

Alignment container.

Functions

blast_to_region(query_or_subject, seqdb)

Converts a blast data result to a Region.

Classes

AlignmentContainer(seqdb[, alignments])

Container for a set of query-to-subject alignments for a single query.

AlignmentContainerFactory(seqdb)

Class that maintains a shared list of alignments and shared sequence database.

Classes

AlignmentContainer(seqdb[, alignments])

Container for a set of query-to-subject alignments for a single query.

AlignmentContainerFactory(seqdb)

Class that maintains a shared list of alignments and shared sequence database.

Functions

blast_to_region(query_or_subject, seqdb)

Converts a blast data result to a Region.

class dasi.models.alignment_container.AlignmentContainer(seqdb, alignments=None)[source]

Bases: collections.abc.Sized

Container for a set of query-to-subject alignments for a single query.

Instance Attributes/Properties:
alignments list of alignments for the container

List[Alignment]

seqdb key to SeqRecord dictionary

Dict[str, SeqRecord]

logger the instance’s logger

Loggable

This class contains:
  1. Methods grouping alignments together according to those

alignments that share the same starting and ending points.
  1. Methods for ‘expanding’ alignments

Methods

_alignment_hash(a)

A hashable representation of an alignment for grouping.

_create_pcr_product_alignment(…)

Create a new alignment group for a PCR product.

_make_subgroup(group, a, b, atype)

Make a subgroup at the specified indices.

clean_alignments()

Remove redundant alignments.

copy_groups(alignment_groups, atype)

Copy alignments from the list of groups to a new alignment type.

expand([expand_overlaps, expand_primers, …])

Alignment expansion algorithm.

expand_overlaps(alignment_groups[, atype, …])

Expand the list of alignments from existing regions.

expand_primer_pairs(alignment_groups[, lim_size])

Creates new alignments for all possible primer pairs.

find_groups_by_pos(a, b, group_type[, groups])

Return a list of groups that have the same positions (a, b) and same group_type.

freeze()

Freeze the container, disallowing further modifications to alignments.

get_groups_by_types(types)

Return AlignmentGroups by fragment type.

groups_by_type()

Return alignment groups according to their alignment ‘type’.

redundent_alignment_groups(alignments)

Return AlignmentGroups that have been grouped by alignment_hash.

unfreeze()

Unfreeze the container, allowing modifications to alignments.

Attributes

types

Return all valid types.

static _alignment_hash(a)[source]

A hashable representation of an alignment for grouping.

_create_pcr_product_alignment(template_group, fwd, rev, alignment_type, lim_size)[source]

Create a new alignment group for a PCR product.

Situations the PCRProductAlignmentGroup represents:

            <--------
------------------
---->

               <--------
   ------------------
-------->


        <-----
   ------------------
-------->


              <------
   ------------------
-------->
Parameters
  • template_group (AlignmentGroup) –

  • fwd (Optional[Alignment]) –

  • rev (Optional[Alignment]) –

  • alignment_type (str) –

Returns

_make_subgroup(group, a, b, atype)[source]

Make a subgroup at the specified indices.

Returns None if a, b and the indices of the group.query_region or if a == b

Return type

Optional[AlignmentGroup]

clean_alignments()[source]

Remove redundant alignments.

copy_groups(alignment_groups, atype)[source]

Copy alignments from the list of groups to a new alignment type.

expand(expand_overlaps=True, expand_primers=True, expand_primer_dimers=False, lim_size=True)[source]

Alignment expansion algorithm.

Parameters
  • expand_overlaps – if True, expand overlaps

  • expand_primers – if True, expand primer pairs

  • expand_primer_dimers – if True, expand primer dimer pairs

  • lim_size (bool) – if True, limit the size of the alignment according to theri Molecule definitions

Returns

None

expand_overlaps(alignment_groups, atype='PCR_PRODUCT', lim_size=True, pass_condition=None, include_left=True)[source]

Expand the list of alignments from existing regions. Produces new fragments in the following two situations:

if `include_left`
|--------|          alignment 1
    |--------|      alignment 2
|---|               new alignment


|--------|          alignment 1
     |--------|     alignment 2
     |---|          new alignment
Parameters
  • alignment_groups (List[AlignmentGroup]) – list of alignment groups to expand

  • atype – the alignment type label for expanded alignments

  • lim_size (bool) – if True, only add alignments that pass the size limitations

  • pass_condition (Optional[Callable]) – an optional callable that takes group_a (AlignmentGroup) and group_b (AlignmentGroup). If the returned value is False, alignments are skipped.

  • include_left (bool) – if True, will add overlapping region and the left region up to the overlap.

Return type

List[Alignment]

Returns

list of new alignments

expand_primer_pairs(alignment_groups, lim_size=True)[source]

Creates new alignments for all possible primer pairs. Searches for fwd and rev primer pairs that exist within other alignments and produces all combinations of alignments that can form from these primer pairs.

Return type

List[Alignment]

Returns

list

find_groups_by_pos(a, b, group_type, groups=None)[source]

Return a list of groups that have the same positions (a, b) and same group_type.

Parameters
  • a (int) – starting position

  • b (int) – ending position

  • group_type (str) – group_type

  • groups – optional list of groups to search

Return type

List[Union[AlignmentGroup, PCRProductAlignmentGroup]]

Returns

list of groups

freeze()[source]

Freeze the container, disallowing further modifications to alignments.

get_groups_by_types(types)[source]

Return AlignmentGroups by fragment type.

Parameters

types (List[str]) – list of types

Return type

Union[AlignmentGroup, List[AlignmentGroup]]

Returns

groups_by_type()[source]

Return alignment groups according to their alignment ‘type’.

Return type

Dict[str, List[Union[AlignmentGroup, PCRProductAlignmentGroup]]]

Returns

dict

classmethod redundent_alignment_groups(alignments)[source]

Return AlignmentGroups that have been grouped by alignment_hash.

Parameters

alignments (List[Alignment]) –

Return type

List[AlignmentGroup]

Returns

property types

Return all valid types.

Return type

Tuple[Any, …]

Returns

unfreeze()[source]

Unfreeze the container, allowing modifications to alignments.

class dasi.models.alignment_container.AlignmentContainerFactory(seqdb)[source]

Bases: object

Class that maintains a shared list of alignments and shared sequence database.

AlignmentContainers can be retrieved in a dict grouped by their query via .containers()

Construct a new AlignmentContainer.

Parameters

seqdb (Dict[str, SeqRecord]) – a sequence record database

Attributes

alignments

Return dict of alignments keyed by query_key.

Methods

containers()

Return dictionary of AlignmentContainers keyed by query_keys.

load_blast_json(data, atype)

Create alignments from a formatted BLAST JSON result.

property alignments

Return dict of alignments keyed by query_key.

Return type

frozendict

Returns

containers()[source]

Return dictionary of AlignmentContainers keyed by query_keys.

Return type

Dict[str, AlignmentContainer]

Returns

load_blast_json(data, atype)[source]

Create alignments from a formatted BLAST JSON result.

Parameters
  • data (List[Dict]) – formatted BLAST JSON result

  • atype (str) – the type of alignment to initialize

Returns

None

dasi.models.alignment_container.blast_to_region(query_or_subject, seqdb)[source]

Converts a blast data result to a Region. Blast results are indicated by two positions with index starting at 1 and positions being inclusive. This returns a Region with index starting at 0 and the end point position being exclusive.

Parameters
  • query_or_subject (dict) –

  • seqdb (Dict[str, SeqRecord]) –

Returns

Return type