Class for HIV population genetics (genome size = 10000).
This class is the main object for simulating the evolution of HIV.
The class offers a number of functions, but an example will explain the basic
idea:
#####################################
# EXAMPLE SCRIPT #
#####################################
import numpy as np
import matplotlib.pyplot as plt
import FFPopSim as h
c = h.hivpopulation(2000) # Create a population of 2000 individuals
c.evolve(100) # Evolve (neutrally) for 100 generations
c.plot_divergence_histogram()
plt.show()
#####################################
This class is a subclass of haploid_high and offers most of its methods.
In addition to the haploid_highd class, this class offers functions for reading
fitness and drug resistance landscapes from a text file, and to save genomes as
plain text or in compressed NumPy format.
Moreover, there are two phenotypic traits, replication and resistance. Their
relative importance for viral fitness is set by the treatment attribute:
f[trait] = trait[0] + treatment * trait[1]
By default, treatment is set to zero, to simulate non-treated patients.
The gene structure of HIV is not modelled explicitely, except for a stub of
1000 sites between position 7000 and 8000 to roughly model the _env_ gene.
-
__init__(N=0, rng_seed=0, mutation_rate=3e-5, coinfection_rate=1e-2, crossover_rate=1e-3)
Construct a HIV population with certain parameters.
Parameters:
- N number of viral particles
- rng_seed seed for the random number generator. If this is 0, time(NULL)+getpid() is used.
- mutation_rate mutation rate in events / generation / site
- coinfection_rate probability of coinfection of the same cell by two viral particles in events / generation
- crossover_rate probability of template switching during coinfection in events / site
Note
the genome length is 10000 (see HIVGENOME).
-
__str__() <==> str(x)
-
__repr__() <==> repr(x)
-
treatment
Treatment weight (between 0 and 1)
Note
this variable controls how important is either of the two phenotypic
traits, replication and resistance. Their contribution to fitness is
always linear (in this implementation).
-
write_genotypes(filename, sample_size, gt_label='', start=0, length=0)
Store random genotypes into a plain text file.
- Parameters:
- filename: string with the name of the file to store the genotype into
- sample_size: how many random genotypes to store
- gt_label: common fasta label for the genotypes (e.g. ‘HIV-sim’)
- start: if only a portion of the genome is to be stored, start from this position
- length: store a chunk from start to this length
-
write_genotypes_compressed(filename, sample_size, gt_label='', start=0, length=0)
Store random genotypes into a compressed file.
- Parameters:
- filename: string with the name of the file to store the genotype into
- sample_size: how many random genotypes to store
- gt_label: common fasta label for the genotypes (e.g. “HIV-sim”)
- start: if only a portion of the genome is to be stored, start from this position
- length: store a chunk from start to this length
The genotypes can be read using numpy.load.
-
read_replication_coefficients(filename)
Read replication coefficients from a text file
- Parameters:
- filename: string with the name of the file to read the coefficients from
-
read_resistance_coefficients(filename)
Read resistance coefficients from a text file
- Parameters:
- filename: string with the name of the file to read the coefficients from
-
set_trait_landscape(traitnumber=0, lethal_fraction=0.05, deleterious_fraction=0.8, adaptive_fraction=0.01, effect_size_lethal=0.8, effect_size_deleterious=0.1, effect_size_adaptive=0.01, env_fraction=0.1, effect_size_env=0.01, number_epitopes=0, epitope_strength=0.05, number_valleys=0, valley_strength=0.1)
Set HIV trait landscape according to some general parameters.
- Parameters:
- lethal_fraction: fraction of lethal sites
- deleterious_fraction: fraction of deleterious sites
- adaptive_fraction: fraction of beneficial sites
- effect_size_lethal: effect of lethal changes
- effect_size_deleterious: average effect of deleterious changes
- effect_size_adaptive: average effect of beneficial changes
- env_fraction: fraction of beneficial sites in env
- effect_size_env: average effect of beneficial changes in env
- number_epitopes: number of (epistatic) epitopes
- epitope_strength: average height of an epitope escape mutation
- number_valleys: number of (epistatic) valleys
- valley_strength: average depth of a valley
Note
the effects of deleterious and beneficial sites are exponentially
distributed, i.e. most of them will still be almost neutral.
Note
fractions refer to first and second positions only. For instance,
by default, 80% of first and second positions outside env are
deleterious.
Note
the third positions are always neutral (synonymous).
-
set_replication_landscape(lethal_fraction=0.05, deleterious_fraction=0.8, adaptive_fraction=0.01, effect_size_lethal=0.8, effect_size_deleterious=0.1, effect_size_adaptive=0.01, env_fraction=0.1, effect_size_env=0.01, number_epitopes=0, epitope_strength=0.05, number_valleys=0, valley_strength=0.1)
Set the phenotypic landscape for the replication capacity of HIV.
- Parameters:
- lethal_fraction: fraction of lethal sites
- deleterious_fraction: fraction of deleterious sites
- adaptive_fraction: fraction of beneficial sites
- effect_size_lethal: effect of lethal changes
- effect_size_deleterious: average effect of deleterious changes
- effect_size_adaptive: average effect of beneficial changes
- env_fraction: fraction of beneficial sites in env
- effect_size_env: average effect of beneficial changes in env
- number_epitopes: number of (epistatic) epitopes
- epitope_strength: average height of an epitope escape mutation
- number_valleys: number of (epistatic) valleys
- valley_strength: average depth of a valley
Note
the effects of deleterious and beneficial sites are exponentially
distributed, i.e. most of them will still be almost neutral.
Note
fractions refer to first and second positions only. For instance,
by default, 80% of first and second positions outside env are
deleterious.
Note
the third positions are always neutral (synonymous).
-
set_resistance_landscape(lethal_fraction=0.05, deleterious_fraction=0.8, adaptive_fraction=0.01, effect_size_lethal=0.8, effect_size_deleterious=0.1, effect_size_adaptive=0.01, env_fraction=0.1, effect_size_env=0.01, number_epitopes=0, epitope_strength=0.05, number_valleys=0, valley_strength=0.1)
Set the phenotypic landscape for the drug resistance of HIV.
- Parameters:
- lethal_fraction: fraction of lethal sites
- deleterious_fraction: fraction of deleterious sites
- adaptive_fraction: fraction of beneficial sites
- effect_size_lethal: effect of lethal changes
- effect_size_deleterious: average effect of deleterious changes
- effect_size_adaptive: average effect of beneficial changes
- env_fraction: fraction of beneficial sites in env
- effect_size_env: average effect of beneficial changes in env
- number_epitopes: number of (epistatic) epitopes
- epitope_strength: average height of an epitope escape mutation
- number_valleys: number of (epistatic) valleys
- valley_strength: average depth of a valley
Note
the effects of deleterious and beneficial sites are exponentially
distributed, i.e. most of them will still be almost neutral.
Note
fractions refer to first and second positions only. For instance,
by default, 80% of first and second positions outside env are
deleterious.
Note
the third positions are always neutral (synonymous).
-
get_replication_additive()
The additive part of the replication lansdscape.
- Returns:
- coefficients: array of additive replication coefficients
Warning
the -/+ basis is used throughout the library.
If you are used to the 0/1 basis, keep in mind that
the interaction series-expansion is different.
-
get_resistance_additive()
The additive part of the resistance lansdscape.
- Returns:
- coefficients: array of additive drug resistance coefficients
Warning
the -/+ basis is used throughout the library.
If you are used to the 0/1 basis, keep in mind that
the interaction series-expansion is different.
-
set_replication_additive(coefficients)
Set the additive replication coefficients
- Parameters:
- coefficients: array of additive replication coefficients
Warning
the -/+ basis is used throughout the library.
If you are used to the 0/1 basis, keep in mind that
the interaction series-expansion is different.
-
set_resistance_additive(coefficients)
Set the additive drug resistance coefficients
- Parameters:
- coefficients: array of additive drug resistance coefficients
Warning
the -/+ basis is used throughout the library.
If you are used to the 0/1 basis, keep in mind that
the interaction series-expansion is different.
-
copy(rng_seed=0)
Copy population into new instance.
- Parameters:
- rng_seed: random number to initialize the new population
-
get_replication_additive()
The additive part of the replication lansdscape.
- Returns:
- coefficients: array of additive replication coefficients
Warning
the -/+ basis is used throughout the library.
If you are used to the 0/1 basis, keep in mind that
the interaction series-expansion is different.
-
get_resistance_additive()
The additive part of the resistance lansdscape.
- Returns:
- coefficients: array of additive drug resistance coefficients
Warning
the -/+ basis is used throughout the library.
If you are used to the 0/1 basis, keep in mind that
the interaction series-expansion is different.
-
read_replication_coefficients()
Read replication coefficients from a text file
- Parameters:
- filename: string with the name of the file to read the coefficients from
-
read_resistance_coefficients()
Read resistance coefficients from a text file
- Parameters:
- filename: string with the name of the file to read the coefficients from
-
set_replication_additive(coefficients)
Set the additive replication coefficients
- Parameters:
- coefficients: array of additive replication coefficients
Warning
the -/+ basis is used throughout the library.
If you are used to the 0/1 basis, keep in mind that
the interaction series-expansion is different.
-
set_replication_landscape(lethal_fraction=0.05, deleterious_fraction=0.8, adaptive_fraction=0.01, effect_size_lethal=0.8, effect_size_deleterious=0.1, effect_size_adaptive=0.01, env_fraction=0.1, effect_size_env=0.01, number_epitopes=0, epitope_strength=0.05, number_valleys=0, valley_strength=0.1)
Set the phenotypic landscape for the replication capacity of HIV.
- Parameters:
- lethal_fraction: fraction of lethal sites
- deleterious_fraction: fraction of deleterious sites
- adaptive_fraction: fraction of beneficial sites
- effect_size_lethal: effect of lethal changes
- effect_size_deleterious: average effect of deleterious changes
- effect_size_adaptive: average effect of beneficial changes
- env_fraction: fraction of beneficial sites in env
- effect_size_env: average effect of beneficial changes in env
- number_epitopes: number of (epistatic) epitopes
- epitope_strength: average height of an epitope escape mutation
- number_valleys: number of (epistatic) valleys
- valley_strength: average depth of a valley
Note
the effects of deleterious and beneficial sites are exponentially
distributed, i.e. most of them will still be almost neutral.
Note
fractions refer to first and second positions only. For instance,
by default, 80% of first and second positions outside env are
deleterious.
Note
the third positions are always neutral (synonymous).
-
set_resistance_additive(coefficients)
Set the additive drug resistance coefficients
- Parameters:
- coefficients: array of additive drug resistance coefficients
Warning
the -/+ basis is used throughout the library.
If you are used to the 0/1 basis, keep in mind that
the interaction series-expansion is different.
-
set_resistance_landscape(lethal_fraction=0.05, deleterious_fraction=0.8, adaptive_fraction=0.01, effect_size_lethal=0.8, effect_size_deleterious=0.1, effect_size_adaptive=0.01, env_fraction=0.1, effect_size_env=0.01, number_epitopes=0, epitope_strength=0.05, number_valleys=0, valley_strength=0.1)
Set the phenotypic landscape for the drug resistance of HIV.
- Parameters:
- lethal_fraction: fraction of lethal sites
- deleterious_fraction: fraction of deleterious sites
- adaptive_fraction: fraction of beneficial sites
- effect_size_lethal: effect of lethal changes
- effect_size_deleterious: average effect of deleterious changes
- effect_size_adaptive: average effect of beneficial changes
- env_fraction: fraction of beneficial sites in env
- effect_size_env: average effect of beneficial changes in env
- number_epitopes: number of (epistatic) epitopes
- epitope_strength: average height of an epitope escape mutation
- number_valleys: number of (epistatic) valleys
- valley_strength: average depth of a valley
Note
the effects of deleterious and beneficial sites are exponentially
distributed, i.e. most of them will still be almost neutral.
Note
fractions refer to first and second positions only. For instance,
by default, 80% of first and second positions outside env are
deleterious.
Note
the third positions are always neutral (synonymous).
-
set_trait_landscape(traitnumber=0, lethal_fraction=0.05, deleterious_fraction=0.8, adaptive_fraction=0.01, effect_size_lethal=0.8, effect_size_deleterious=0.1, effect_size_adaptive=0.01, env_fraction=0.1, effect_size_env=0.01, number_epitopes=0, epitope_strength=0.05, number_valleys=0, valley_strength=0.1)
Set HIV trait landscape according to some general parameters.
- Parameters:
- lethal_fraction: fraction of lethal sites
- deleterious_fraction: fraction of deleterious sites
- adaptive_fraction: fraction of beneficial sites
- effect_size_lethal: effect of lethal changes
- effect_size_deleterious: average effect of deleterious changes
- effect_size_adaptive: average effect of beneficial changes
- env_fraction: fraction of beneficial sites in env
- effect_size_env: average effect of beneficial changes in env
- number_epitopes: number of (epistatic) epitopes
- epitope_strength: average height of an epitope escape mutation
- number_valleys: number of (epistatic) valleys
- valley_strength: average depth of a valley
Note
the effects of deleterious and beneficial sites are exponentially
distributed, i.e. most of them will still be almost neutral.
Note
fractions refer to first and second positions only. For instance,
by default, 80% of first and second positions outside env are
deleterious.
Note
the third positions are always neutral (synonymous).
-
write_genotypes()
Store random genotypes into a plain text file.
- Parameters:
- filename: string with the name of the file to store the genotype into
- sample_size: how many random genotypes to store
- gt_label: common fasta label for the genotypes (e.g. ‘HIV-sim’)
- start: if only a portion of the genome is to be stored, start from this position
- length: store a chunk from start to this length
-
write_genotypes_compressed(filename, sample_size, gt_label='', start=0, length=0)
Store random genotypes into a compressed file.
- Parameters:
- filename: string with the name of the file to store the genotype into
- sample_size: how many random genotypes to store
- gt_label: common fasta label for the genotypes (e.g. “HIV-sim”)
- start: if only a portion of the genome is to be stored, start from this position
- length: store a chunk from start to this length
The genotypes can be read using numpy.load.
-
env
hivpopulation_env_get(hivpopulation self) -> hivgene
-
thisown
The membership flag
-
treatment
Treatment weight (between 0 and 1)
Note
this variable controls how important is either of the two phenotypic
traits, replication and resistance. Their contribution to fitness is
always linear (in this implementation).