API reference
- class polymera.Alphabet(letters={}, complements={}, relations=None)
Bases:
object
The Alphabet class describes the relations between the letters.
- Parameters:
letters (set) – The set of letters (symbols) used for the sequence.
complements (dict) – The dict of complement relations. Format: {“A”: [“T”], “T”: [“A”, “6”], …}.
relations (None) – Not implemented yet. Non-complement relations between letters.
- exception polymera.DuplicateChoiceError
Bases:
ValueError
- class polymera.Polymer(sequence, alphabet)
Bases:
object
Class for representing a sequence with its alphabet.
- Parameters:
- get_choice_complement(seq)
Return the complement of a sequence string (choice).
- Parameters:
seq (str) – String to complement.
- get_choice_reverse(seq)
Get reverse of a sequence string (choice).
- Parameters:
seq (str) – String to reverse.
- get_information_content(method)
Get information content of the polymer sequence in bits.
An ambiguous position can mean one of two things in a sequence: 1. Options: all letters noted in the position are suitable. 2. Uncertainty: it’s not exactly known what letter occupies the position.
- Parameters:
method (str) – Interpretation of ambiguity: option or uncertainty.
- get_option_information_content()
Get information content of the polymer sequence.
Ambiguity is interpreted as options.
- get_segment_complement(segment)
Return the complement of a Segment.
- Parameters:
segment (Segment) – Segment to complement.
- get_segment_reverse(segment)
Return the reverse of a Segment.
- Parameters:
segment (Segment) – Segment to reverse.
- get_sequence_complement()
Return the complement of the polymer sequence.
- get_sequence_reverse()
Return the reverse of the polymer sequence.
- get_sequence_reverse_complement()
Return the reverse complement of the polymer sequence.
- get_uncertainty_information_content()
Get information content of the polymer sequence.
Ambiguity is interpreted as uncertainty: the information content equals to the negative base 2 logarithm of the probability of the sequence. The probability equals to the number of sequences represented, divided by the number of possible sequences with the same length: -log2(represented / possible).
- class polymera.Segment(choices)
Bases:
object
Segments store the possible subsequences (choices) for a given region.
- Parameters:
choices (list) – The list of segment choice strings.
- class polymera.Sequence(segments=None, separators={'choice': ',', 'del': '-', 'letter': '.', 'segment': '|'})
Bases:
object
The Sequence class stores the sequence (string).
- Parameters:
segments (list) – A list of `Segment`s.
separators (dict) – The separator characters in a dict. Format: {“segment”: “|”, “choice”: “,”, “letter”: “.”, “del”: “-“}. Letter separators are not implemented yet.
- add_sequence_from_string(string)
Convert a string into segments and append to the sequence.
- Parameters:
string (str) – String to convert into segments.
- calculate_number_of_combinations()
Calculate the number of exact sequences represented.
- create_choices_from_string(string)
- create_segments_from_string(string)
Create a list of Segment instances from the sequence attribute.
- get_exact_seq(randomize=False)
Get an exact sequence and combine the segments.
- Parameters:
random (bool) – Choice selection. If True, use a random choice for each segment, if False, use the first choice for each segment.
- get_length()
Return the length of the sequence.
- to_string()
Return a string representation of the ambiguous sequence.
- exception polymera.UnequalLengthError
Bases:
ValueError
- exception polymera.WrongLetterError
Bases:
ValueError
- polymera.break_segment(segment)
Return a list of n 1-length Segments from a Segment of length n.
- polymera.convert_to_nosegment(seq)
Convert Sequence segments to length 1 segments.
- polymera.hamming(seq1, seq2, comparison='options')
Calculate Hamming distance between two sequences.
- polymera.hamming_options(seq1, seq2)
Calculate Hamming distance between two sequences.
Interpret ambiguity as options.
- polymera.hamming_uncertainty(seq1, seq2)
Calculate Hamming distance between two sequences.
Interpret ambiguity as uncertainty.