genome_entropy.entropy.shannon
Shannon entropy calculation for sequences.
Functions
|
Calculate entropy for multiple sequences. |
|
Calculate entropy for a biological sequence. |
|
Calculate Shannon entropy of a sequence. |
Classes
|
Report containing entropy values at different representation levels. |
- class genome_entropy.entropy.shannon.EntropyReport(dna_entropy_global, orf_nt_entropy, protein_aa_entropy, three_di_entropy, alphabet_sizes)[source]
Report containing entropy values at different representation levels.
- Parameters:
- genome_entropy.entropy.shannon.shannon_entropy(sequence, alphabet=None, normalize=False)[source]
Calculate Shannon entropy of a sequence.
Shannon entropy: H = -Σ(p_i × log₂(p_i)) where p_i is the frequency of symbol i.
- Parameters:
- Returns:
Shannon entropy value (bits) - Returns 0.0 for empty sequences - Returns normalized entropy in [0, 1] if normalize=True
- Return type:
Examples
>>> shannon_entropy("AAAA") 0.0 >>> shannon_entropy("ACGT") 2.0 >>> shannon_entropy("ACGT", normalize=True, alphabet=set("ACGT")) 1.0
- genome_entropy.entropy.shannon.calculate_sequence_entropy(sequence, alphabet=None, normalize=False)[source]
Calculate entropy for a biological sequence.
Convenience wrapper around shannon_entropy that handles common preprocessing (e.g., converting to uppercase).