opqua.internal package

Submodules

opqua.internal.data module

Contains data wrangling methods.

opqua.internal.data.compartmentDf(data, populations=[], hosts=True, vectors=False, save_to_file='')[source]

Create dataframe with number of naive, susc., inf., rec. hosts/vectors.

Creates a pandas Dataframe with dynamics of all compartments (naive, infected, recovered, dead) across selected populations in the model, with one time point in each row and columns for time as well as each compartment.

Parameters:

data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:
  • populations (list of Strings) – IDs of populations to include in analysis; if empty, uses all populations in model. Defaults to [].

  • hosts (Boolean) – whether to count hosts. Defaults to True.

  • vectors (Boolean) – whether to count vectors. Defaults to False.

  • save_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

Returns:

pandas DataFrame with model compartment dynamics as described above.

opqua.internal.data.compositionDf(data, populations=[], type_of_composition='Pathogens', hosts=True, vectors=False, num_top_sequences=-1, track_specific_sequences=[], genomic_positions=[], count_individuals_based_on_model=None, save_to_file='', n_cores=0, **kwargs)[source]

Create dataframe with counts for pathogen genomes or resistance.

Creates a pandas Dataframe with dynamics of the pathogen strains or protection sequences across selected populations in the model, with one time point in each row and columns for pathogen genomes or protection sequences.

Of note: sum of totals for all sequences in one time point does not necessarily equal the number of infected hosts and/or vectors, given multiple infections in the same host/vector are counted separately.

Parameters:

data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:
  • populations (list of Strings) – IDs of populations to include in analysis; if empty, uses all populations in model. Defaults to [].

  • type_of_composition (String) – field of data to count totals of, can be either ‘Pathogens’ or ‘Protection’. Defaults to ‘Pathogens’.

  • hosts (Boolean) – whether to count hosts. Defaults to True.

  • vectors (Boolean) – whether to count vectors. Defaults to False.

  • num_top_sequences (int) – how many sequences to count separately and include as columns, remainder will be counted under column “Other”; if <0, includes all genomes in model. Defaults to -1.

  • track_specific_sequences (list of Strings) – contains specific sequences to have as a separate column if not part of the top num_top_sequences sequences. Defaults to [].

  • genomic_positions (list of lists of int) – list in which each element is a list with loci positions to extract (e.g. genomic_positions=[ [0,3], [5,6] ] extracts positions 0, 1, 2, and 5 from each genome); if empty, takes full genomes. Defaults to [].

  • count_individuals_based_on_model (None or Model) – Model object with populations and fitness functions used to evaluate the most fit pathogen genome in each host/vector in order to count only a single pathogen per host/vector, as opposed to all pathogens within each host/vector; if None, counts all pathogens. Defaults to None.

  • save_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

  • n_cores (int) – number of cores to parallelize processing across, if 0, all cores available are used. Defaults to 0.

  • **kwargs – additional arguents for joblib multiprocessing.

Returns:

pandas DataFrame with model sequence composition dynamics as described above.

opqua.internal.data.getGenomeTimesDf(data, samples=1, save_to_file='', n_cores=0, **kwargs)[source]

Create DataFrame with times genomes first appeared during simulation.

Parameters:

data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:
  • samples (int) – how many timepoints to uniformly sample from the total timecourse; if <0, takes all timepoints. Defaults to 1.

  • save_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

  • n_cores (int) – number of cores to parallelize across, if 0, all cores available are used. Defaults to 0.

  • **kwargs – additional arguents for joblib multiprocessing.

Returns:

pandas DataFrame with genomes and times as described above.

opqua.internal.data.getPathogenDistanceHistoryDf(data, samples=1, num_top_sequences=-1, track_specific_sequences=[], seq_names=[], save_to_file='', n_cores=0)[source]

Create DataFrame with pairwise Hamming distances for pathogen sequences in data.

DataFrame has indexes and columns named according to genomes or argument seq_names, if passed. Distance is measured as percent Hamming distance from an optimal genome sequence.

Parameters:

data (pandas DataFrame) – dataframe with model history as produced by saveToDf function

Keyword Arguments:
  • samples (int) – how many timepoints to uniformly sample from the total timecourse; if <0, takes all timepoints. Defaults to 1.

  • num_top_sequences (int) – how many sequences to include in matrix; if <0, includes all genomes in data passed. Defaults to -1.

  • track_specific_sequences (list of Strings) – contains specific sequences to include in matrix if not part of the top num_top_sequences sequences. Defaults to [].

  • seq_names (list of Strings) – list with names to be used for sequence labels in matrix must be of same length as number of sequences to be displayed; if empty, uses sequences themselves. Defaults to [].

  • save_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

  • n_cores (int) – number of cores to parallelize distance compute across, if 0, all cores available are used (default 0; int)

Returns:

pandas DataFrame with distance matrix as described above.

opqua.internal.data.getPathogens(data, save_to_file='')[source]

Create Dataframe with counts for all pathogen genomes in data.

Returns sorted pandas DataFrame with counts for occurrences of all pathogen genomes in data passed.

Parameters:

data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:

save_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

Returns:

pandas DataFrame with Series as described above.

opqua.internal.data.getProtections(data, save_to_file='')[source]

Create Dataframe with counts for all protection sequences in data.

Returns sorted pandas DataFrame with counts for occurrences of all protection sequences in data passed.

Parameters:

data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:

save_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

Returns:

pandas DataFrame with Series as described above.

opqua.internal.data.pathogenDistanceDf(data, num_top_sequences=-1, track_specific_sequences=[], seq_names=[], save_to_file='', n_cores=0)[source]

Create DataFrame with pairwise Hamming distances for pathogen sequences in data.

DataFrame has indexes and columns named according to genomes or argument seq_names, if passed. Distance is measured as percent Hamming distance from an optimal genome sequence.

Parameters:

data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:
  • num_top_sequences (int) – how many sequences to include in matrix; if <0, includes all genomes in data passed. Defaults to -1.

  • track_specific_sequences (list of Strings) – contains specific sequences to include in matrix if not part of the top num_top_sequences sequences. Defaults to [].

  • seq_names (list of Strings) – list with names to be used for sequence labels in matrix must be of same length as number of sequences to be displayed; if empty, uses sequences themselves. Defaults to [].

  • save_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

  • n_cores (int) – number of cores to parallelize distance compute across, if 0, all cores available are used. Defaults to 0.

Returns:

pandas DataFrame with distance matrix as described above.

opqua.internal.data.populationsDf(data, compartment='Infected', hosts=True, vectors=False, num_top_populations=-1, track_specific_populations=[], save_to_file='')[source]

Create dataframe with aggregated totals per population.

Creates a pandas Dataframe in long format with dynamics of a compartment across populations in the model, with one time point in each row and columns for time as well as each population.

Parameters:

data (pandas DataFrame) –

Keyword Arguments:
  • compartment (String) – subset of hosts/vectors to count totals of, can be either ‘Naive’,’Infected’,’Recovered’, or ‘Dead’. Defaults to ‘Infected’.

  • hosts (Boolean) – whether to count hosts. Defaults to True.

  • vectors (Boolean) – whether to count vectors. Defaults to False.

  • num_top_populations (int) – how many populations to count separately and include as columns, remainder will be counted under column “Other”; if <0, includes all populations in model. Defaults to -1.

  • track_specific_populations (list of Strings) – contains IDs of specific populations to have as a separate column if not part of the top num_top_populations populations. Defaults to [].

  • save_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

Returns:

pandas DataFrame with model population dynamics as described above.

opqua.internal.data.saveToDf(history, save_to_file, n_cores=0, verbose=10, **kwargs)[source]

Save status of model to dataframe, write to file location given.

Creates a pandas Dataframe in long format with the given model history, with one host or vector per simulation time in each row, and columns:

  • Time - simulation time of entry

  • Population - ID of this host/vector’s population

  • Organism - host/vector

  • ID - ID of host/vector

  • Pathogens - all genomes present in this host/vector separated by ‘;’

  • Protection - all genomes present in this host/vector separated by ‘;’

  • Alive - whether host/vector is alive at this time, True/False

Writing straight to a file and then reading into a pandas dataframe was actually more efficient than concatenating directly into a pd dataframe.

Parameters:
  • history (dict) – dictionary containing model state history, with keys`=`times and values`=`Model objects with model snapshot at that time point.

  • save_to_file (String) – file path and name to save model data under.

Keyword Arguments:
  • n_cores (int) – number of cores to parallelize file export across, if 0, all cores available are used. Defaults to 0.

  • **kwargs – additional arguents for joblib multiprocessing.

Returns:

pandas DataFrame with model history as described above.

opqua.internal.gillespie module

Contains class Population.

class opqua.internal.gillespie.Gillespie(model)[source]

Bases: object

Class contains methods for simulating model with Gillespie algorithm.

Class defines a model’s events and methods for changing system state according to the possible events and simulating a timecourse using the Gillespie algorithm.

model

the model this simulation belongs to.

Type:

Model object

BIRTH_HOST = 18
BIRTH_VECTOR = 19
CONTACT_HOST_HOST = 5
CONTACT_HOST_VECTOR = 6
CONTACT_VECTOR_HOST = 7
DIE_HOST = 16
DIE_VECTOR = 17
EVENT_IDS = {0: 'MIGRATE_HOST', 1: 'MIGRATE_VECTOR', 2: 'POPULATION_CONTACT_HOST_HOST', 3: 'POPULATION_CONTACT_HOST_VECTOR', 4: 'POPULATION_CONTACT_VECTOR_HOST', 5: 'CONTACT_HOST_HOST', 6: 'CONTACT_HOST_VECTOR', 7: 'CONTACT_VECTOR_HOST', 8: 'RECOVER_HOST', 9: 'RECOVER_VECTOR', 10: 'MUTATE_HOST', 11: 'MUTATE_VECTOR', 12: 'RECOMBINE_HOST', 13: 'RECOMBINE_VECTOR', 14: 'KILL_HOST', 15: 'KILL_VECTOR', 16: 'DIE_HOST', 17: 'DIE_VECTOR', 18: 'BIRTH_HOST', 19: 'BIRTH_VECTOR'}
KILL_HOST = 14
KILL_VECTOR = 15
MIGRATE_HOST = 0
MIGRATE_VECTOR = 1
MUTATE_HOST = 10
MUTATE_VECTOR = 11
POPULATION_CONTACT_HOST_HOST = 2
POPULATION_CONTACT_HOST_VECTOR = 3
POPULATION_CONTACT_VECTOR_HOST = 4
RECOMBINE_HOST = 12
RECOMBINE_VECTOR = 13
RECOVER_HOST = 8
RECOVER_VECTOR = 9
doAction(act, pop, rand)[source]

Change system state according to act argument passed

Parameters:
  • act (int) – defines action to be taken, one of the event ID constants.

  • pop (Population object) – where the population action will happen in.

  • rand (number 0-1) – random number used to define event.

Returns:

Boolean indicationg whether or not the model has changed state.

getRates(population_ids)[source]

Wrapper for calculating event rates as per current system state.

Parameters:

population_ids (list of Strings) – list with IDs for every population in the model.

Returns:

Matrix with rates as values for events (rows) and populations (columns). Populations in order given in argument.

run(t0, tf, time_sampling=0, host_sampling=0, vector_sampling=0, print_every_n_events=1000)[source]

Simulate model for a specified time between two time points.

Simulates a time series using the Gillespie algorithm.

Parameters:
  • t0 (number) – initial time point to start simulation at.

  • tf (number) – initial time point to end simulation at.

Keyword Arguments:
  • time_sampling (int) – how many events to skip before saving a snapshot of the system state (saves all by default), if <0, saves only final state. Defaults to 0.

  • host_sampling (int) – how many hosts to skip before saving one in a snapshot of the system state (saves all by default). Defaults to 0.

  • vector_sampling (int) – how many vectors to skip before saving one in a snapshot of the system state (saves all by default). Defaults to 0.

  • print_every_n_events (int>0) – number of events a message is printed to console. Defaults to 1000.

Returns:

dictionary containing model state history, with keys`=`times and

values`=`Model objects with model snapshot at that time point.

opqua.internal.host module

Contains class Host.

class opqua.internal.host.Host(population, id, slim=False)[source]

Bases: object

Class defines main entities to be infected by pathogens in model.

population

the population this host belongs to.

Type:

Population object

id

unique identifier for this host within population.

Type:

String

slim

whether to create a slimmed-down representation of the population for data storage (only ID, host and vector lists). Defaults to False.

Type:

Boolean

acquirePathogen(genome)[source]

Adds given genome to this host’s pathogens.

Modifies event coefficient matrix accordingly.

Parameters:

genome (String) – the genome to be added.

applyTreatment(resistance_seqs)[source]

Remove all infections with genotypes susceptible to given treatment.

Pathogens are removed if they are missing at least one of the sequences in resistance_seqs from their genome. Removes this organism from population infected list and adds to healthy list if appropriate.

Parameters:

resistance_seqs (list of Strings) – contains sequences required for treatment resistance.

birth(rand)[source]

Add a new host to population based on this host.

copyState()[source]

Returns a slimmed-down representation of the current host state.

Returns:

Host object with current pathogens and protection_sequences.

die()[source]

Add host to population’s dead list, remove it from alive ones.

getWeightedRandomGenome(rand, r)[source]

Returns index of element chosen from weights and given random number.

Parameters:
  • rand (number 0-1) – random number.

  • r (numpy array) – array with weights.

Returns:

new 0-1 random number.

infectHost(host)[source]

Infect given host with a sample of this host’s pathogens.

Each pathogen in the infector is sampled as present or absent in the inoculum by drawing from a Poisson distribution with a mean equal to the mean inoculum size of the organism being infected weighted by each genome’s fitness as a fraction of the total in the infector as the probability of each trial (minimum 1 pathogen transfered). Each pathogen present in the inoculum will be added to the infected organism, if it does not have protection from the pathogen’s genome. Fitnesses are computed for the pathogens’ genomes in the infected organism, and the organism is included in the poplation’s infected list if appropriate.

Parameters:

vector (Vector object) – the vector to be infected.

Returns:

Boolean indicating whether or not the model has changed state.

infectVector(vector)[source]

Infect given host with a sample of this host’s pathogens.

Each pathogen in the infector is sampled as present or absent in the inoculum by drawing from a Poisson distribution with a mean equal to the mean inoculum size of the organism being infected weighted by each genome’s fitness as a fraction of the total in the infector as the probability of each trial (minimum 1 pathogen transfered). Each pathogen present in the inoculum will be added to the infected organism, if it does not have protection from the pathogen’s genome. Fitnesses are computed for the pathogens’ genomes in the infected organism, and the organism is included in the poplation’s infected list if appropriate.

Parameters:

vector (Vector object) – the vector to be infected.

Returns:

Boolean indicating whether or not the model has changed state.

mutate(rand)[source]

Mutate a single, random locus in a random pathogen.

Creates a new genotype from a de novo mutation event.

recombine(rand)[source]

Recombine two random pathogen genomes at random locus.

Creates a new genotype from two random possible pathogens.

recover()[source]

Remove all infections from this host.

If model is protecting upon recovery, add protecion sequence as defined by the indexes in the corresponding model parameter. Remove from population infected list and add to healthy list.

opqua.internal.intervention module

Contains class Intervention.

class opqua.internal.intervention.Intervention(time, method_name, args, model)[source]

Bases: object

Class defines a new intervention to be done at a specified time.

time

time at which intervention will take place.

Type:

number

method_name

intervention to be carried out, must correspond to the name of a method of the Model object.

Type:

String

args

contains arguments for function in positinal order.

Type:

array-like

model

Model object this intervention is associated to.

Type:

Model object

doIntervention()[source]

Execute intervention function with specified arguments.

opqua.internal.plot module

Contains graphmaking methods.

opqua.internal.plot.clustermap(file_name, data, num_top_sequences=-1, track_specific_sequences=[], seq_names=[], n_cores=0, method='weighted', metric='euclidean', save_data_to_file='', legend_title='Distance', legend_values=[], figsize=(10, 10), dpi=200, color_map=<matplotlib.colors.ListedColormap object>)[source]

Create a heatmap and dendrogram for pathogen genomes in data passed.

Parameters:
  • file_name (String) – file path, name, and extension to save plot under.

  • data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:
  • num_top_sequences (int) – how many sequences to include in matrix; if <0, includes all genomes in data passed. Deafults to -1.

  • track_specific_sequences (list of Strings) – contains specific sequences to include in matrix if not part of the top num_top_sequences sequences. Defaults to [].

  • seq_names (list of Strings) – list with names to be used for sequence labels in matrix must be of same length as number of sequences to be displayed; if empty, uses sequences themselves. Defaults to [].

  • n_cores (int) – number of cores to parallelize distance compute across, if 0, all cores available are used. Defaults to 0.

  • method (String) – clustering algorithm to use with seaborn clustermap. Defaults to ‘weighted’.

  • metric (String) – distance metric to use with seaborn clustermap. Defaults to ‘euclidean’.

  • save_data_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

  • legend_title (String) – legend title. Defaults to ‘Distance’.

  • figsize (array-like of two ints) – dimensions of figure. Defaults to (8,4).

  • dpi (int) – figure resolution. Defaults to 200.

  • color_map (cmap object) – color map to use for traces. Defaults to DEF_CMAP.

Returns:

figure object for plot with heatmap and dendrogram as described.

opqua.internal.plot.compartmentPlot(file_name, data, populations=[], hosts=True, vectors=False, save_data_to_file='', x_label='Time', y_label='Hosts', legend_title='Compartment', legend_values=[], figsize=(8, 4), dpi=200, palette=['#E69F00', '#56B4E9', '#009E73', '#F0E442', '#0072B2', '#D55E00', '#CC79A7', '#999999'], stacked=False)[source]

Create plot with num. of naive, susc., inf., rec. hosts/vectors vs. time.

Creates a line or stacked line plot with dynamics of all compartments (naive, infected, recovered, dead) across selected populations in the model, with one line for each compartment.

Parameters:
  • file_name (String) – file path, name, and extension to save plot under.

  • data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:
  • populations (list of Strings) – IDs of populations to include in analysis; if empty, uses all populations in model. Defaults to [].

  • hosts (Boolean) – whether to count hosts. Defaults to True.

  • vectors (Boolean) – whether to count vectors. Defaults to False.

  • save_data_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

  • x_label (String) – X axis title. Defaults to ‘Time’.

  • y_label (String) – Y axis title. Defaults to ‘Hosts’.

  • legend_title (String) – legend title. Defaults to ‘Population’.

  • legend_values (list of Strings) – labels for each trace, if empty list, uses population IDs. Defaults to [].

  • figsize (array-like of two ints) – dimensions of figure. Defaults to (8,4).

  • dpi (int) – figure resolution. Defaults to 200.

  • palette (list of color Strings) – color palette to use for traces. Defaults to CB_PALETTE.

  • stacked (Boolean) – whether to draw a regular line plot instead of a stacked one. Defaults to False.

Returns:

axis object for plot with model compartment dynamics as described above.

opqua.internal.plot.compositionPlot(file_name, data, composition_dataframe=None, populations=[], type_of_composition='Pathogens', hosts=True, vectors=False, num_top_sequences=7, track_specific_sequences=[], genomic_positions=[], count_individuals_based_on_model=None, save_data_to_file='', x_label='Time', y_label='Infections', legend_title='Genotype', legend_values=[], figsize=(8, 4), dpi=200, palette=['#E69F00', '#56B4E9', '#009E73', '#F0E442', '#0072B2', '#D55E00', '#CC79A7', '#999999'], stacked=True, remove_legend=False, population_fraction=False, **kwargs)[source]

Create plot with counts for pathogen genomes or resistance across time.

Creates a line or stacked line plot with dynamics of the pathogen strains or protection sequences across selected populations in the model, with one line for each pathogen genome or protection sequence being shown.

Of note: sum of totals for all sequences in one time point does not necessarily equal the number of infected hosts and/or vectors, given multiple infections in the same host/vector are counted separately.

Parameters:
  • file_name (String) – file path, name, and extension to save plot under.

  • data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:
  • composition_dataframe (Pandas DataFrame) – output of compositionDf() if already computed. Defaults to None.

  • populations (list of Strings) – IDs of populations to include in analysis; if empty, uses all populations in model. Defaults to [].

  • type_of_composition (String) – field of data to count totals of, can be either ‘Pathogens’ or ‘Protection’. Defaults to ‘Pathogens’.

  • hosts (Boolean) – whether to count hosts. Defaults to True.

  • vectors (Boolean) – whether to count vectors. Defaults to False.

  • num_top_sequences (int) – how many sequences to count separately and include as columns, remainder will be counted under column “Other”; if <0, includes all genomes in model. Defaults to 7.

  • track_specific_sequences (list of Strings) – contains specific sequences to have as a separate column if not part of the top num_top_sequences sequences. Defaults to [].

  • genomic_positions (list of lists of int) – list in which each element is a list with loci positions to extract (e.g. genomic_positions=[ [0,3], [5,6] ] extracts positions 0, 1, 2, and 5 from each genome); if empty, takes full genomes. Defaults to [].

  • count_individuals_based_on_model (None or Model) – Model object with populations and fitness functions used to evaluate the most fit pathogen genome in each host/vector in order to count only a single pathogen per host/vector, as opposed to all pathogens within each host/vector; if None, counts all pathogens. Defaults to None.

  • save_data_to_file (String) – file path and name to save model data under, no saving occurs if empty string. Defaults to “”.

  • x_label (String) – X axis title. Defaults to ‘Time’.

  • y_label (String) – Y axis title. Defaults to ‘Hosts’.

  • legend_title (String) – legend title. Defaults to ‘Population’.

  • legend_values (list of Strings) – labels for each trace, if empty list, uses population IDs. Defaults to [].

  • figsize (int) – dimensions of figure. Defaults to (8,4).

  • dpi (int) – figure resolution. Defaults to 200.

  • palette (list of color Strings) – color palette to use for traces. Defaults to CB_PALETTE.

  • stacked (Boolean) – whether to draw a regular line plot instead of a stacked one. Defaults to False.

  • remove_legend (Boolean) – whether to print the sequences on the figure legend instead of printing them on a separate csv file. Defaults to True.

  • population_fraction (Boolean) – whether to graph fractions of pathogen population instead of pathogen counts. Defaults to False.

  • **kwargs – additional arguents for joblib multiprocessing.

Returns:

axis object for plot with model sequence composition dynamics as described.

opqua.internal.plot.populationsPlot(file_name, data, compartment='Infected', hosts=True, vectors=False, num_top_populations=7, track_specific_populations=[], save_data_to_file='', x_label='Time', y_label='Infected hosts', legend_title='Population', legend_values=[], figsize=(8, 4), dpi=200, palette=['#E69F00', '#56B4E9', '#009E73', '#F0E442', '#0072B2', '#D55E00', '#CC79A7', '#999999'], stacked=False)[source]

Create plot with aggregated totals per population across time.

Creates a line or stacked line plot with dynamics of a compartment across populations in the model, with one line for each population.

Parameters:
  • file_name (String) – file path, name, and extension to save plot under.

  • data (pandas DataFrame) – dataframe with model history as produced by saveToDf function.

Keyword Arguments:
  • compartment (String) – subset of hosts/vectors to count totals of, can be either ‘Naive’,’Infected’,’Recovered’, or ‘Dead’. (default ‘Infected’)

  • hosts (Boolean) – whether to count hosts. Defaults to True.

  • vectors (Boolean) – whether to count vectors. Defaults to False.

  • num_top_populations (int) – how many populations to count separately and include as columns, remainder will be counted under column “Other”; if <0, includes all populations in model. Defaults to 7.

  • track_specific_populations (list of Strings) – contains IDs of specific populations to have as a separate column if not part of the top num_top_populations populations. Defaults to [].

  • save_data_to_file (String) – file path and name to save model plot data under, no saving occurs if empty string. Defaults to “”.

  • x_label (String) – X axis title. Defaults to ‘Time’.

  • y_label (String) – Y axis title. Defaults to ‘Hosts’.

  • legend_title (String) – legend title. Defaults to ‘Population’.

  • legend_values (list of Strings) – labels for each trace, if empty list, uses population IDs. Defaults to [].

  • figsize (array-like of two ints) – dimensions of figure. Defaults to (8,4).

  • dpi (int) – figure resolution. Defaults to 200.

  • palette (list of color Strings) – color palette to use for traces. Defaults to CB_PALETTE.

  • stacked (Boolean) – whether to draw a regular line plot instead of a stacked one. Defaults to False.

Returns:

axis object for plot with model population dynamics as described above.

opqua.internal.population module

Contains class Population.

class opqua.internal.population.Population(model, id, setup, num_hosts, num_vectors, slim=False)[source]

Bases: object

Class defines a population with hosts, vectors, and specific parameters.

CONSTANTS: These all denote positions in coefficients_hosts and coefficients_vectors

  • INFECTED – position of “infected” Boolean values for each individual inside

    coefficients array.

  • CONTACT – position of intra-population aggregated contact rate for each

    individual inside coefficients array.

  • RECEIVE_CONTACT – position of intra-population aggregated receiving contact

    rate for each individual inside coefficients array.

  • LETHALITY – position of aggregated death rate for each individual inside

    coefficients array.

  • NATALITY – position of aggregated birth rate for each individual inside

    coefficients array.

  • RECOVERY – position of aggregated recovery rate for each individual inside

    coefficients array.

  • MIGRATION – position of aggregated inter-population migration rate for each

    individual inside coefficients array.

  • POPULATION_CONTACT – position of inter-population aggregated contact rate

    for each individual inside coefficients array.

  • RECEIVE_POPULATION_CONTACT – position of inter-population aggregated

    receiving contact rate for each individual inside coefficients array.

  • MUTATION – position of aggregated mutation rate for each individual inside

    coefficients array.

  • RECOMBINATION – position of aggregated recovery rate for each individual

    inside coefficients array.

  • NUM_COEFFICIENTS – total number of types of coefficients (columns) in

    coefficient arrays.

  • CHROMOSOME_SEPARATOR – character reserved to denote separate chromosomes in

    genomes.

model

parent model this population is a part of.

Type:

Model object

id

unique identifier for this population in the model.

Type:

String

setup

setup object with parameters for this population.

Type:

String

num_hosts

number of hosts to initialize population with.

Type:

int

num_vectors

number of hosts to initialize population with.

Type:

int

slim

whether to create a slimmed-down representation of the population for data storage (only ID, host and vector lists). Defaults to False.

Type:

Boolean

CHROMOSOME_SEPARATOR = '/'
CONTACT = 1
INFECTED = 0
LETHALITY = 3
MIGRATION = 6
MUTATION = 9
NATALITY = 4
NUM_COEFFICIENTS = 11
POPULATION_CONTACT = 7
RECEIVE_CONTACT = 2
RECEIVE_POPULATION_CONTACT = 8
RECOMBINATION = 10
RECOVERY = 5
addHosts(num_hosts)[source]

Add a number of healthy hosts to population, return list with them.

Parameters:

num_hosts (int) – number of hosts to be added.

Returns:

list containing new hosts.

addPathogensToHosts(genomes_numbers, hosts=[])[source]

Add specified pathogens to random hosts, optionally from a list.

Parameters:

genomes_numbers (dict with keys=Strings, values=int) – dictionary conatining pathogen genomes to add as keys and number of hosts each one will be added to as values.

Keyword Arguments:

hosts (list of Host objects) – list of specific hosts to sample from, if empty, samples from whole population. Defaults to [].

addPathogensToVectors(genomes_numbers, vectors=[])[source]

Add specified pathogens to random vectors, optionally from a list.

Parameters:

genomes_numbers (dict with keys=Strings, values=int) – dictionary conatining pathogen genomes to add as keys and number of vectors each one will be added to as values.

Keyword Arguments:

vectors (list of Vector objects) – list of specific vectors to sample from, if empty, samples from whole population. Defaults to [].

addVectors(num_vectors)[source]

Add a number of healthy vectors to population, return list with them.

Parameters:

num_vectors (int) – number of vectors to be added.

Returns:

list containing new vectors

birthHost(rand)[source]

Add host at this index to population, remove it from alive ones.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual to make parent.

birthVector(rand)[source]

Add host at this index to population, remove it from alive ones.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual to make parent.

contactHostHost(rand)[source]

Contact any two (weighted) random hosts in population.

Carries out possible infection events from the first organism into the second.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individuals to contact.

Returns:

Boolean indicating whether or not the model has changed state.

contactHostVector(rand)[source]

Contact a (weighted) random host and vector in population.

Carries out possible infection events from the first organism into the second.

Arguments: rand (number): uniform random number from 0 to 1 to use when choosing

individuals to contact.

Returns:

Boolean indicating whether or not the model has changed state.

contactVectorHost(rand)[source]

Contact a (weighted) random vector and host in population.

Carries out possible infection events from the first organism into the second.

Parameters:

rand (number) – individuals to contact.

Returns:

Boolean indicating whether or not the model has changed state.

copyState(host_sampling=0, vector_sampling=0)[source]

Returns a slimmed-down version of the current population state.

Parameters:
  • host_sampling (int) – how many hosts to skip before saving one in a snapshot of the system state (saves all by default). Defaults to 0.

  • vector_sampling (int) – how many vectors to skip before saving one in a snapshot of the system state (saves all by default). Defaults to 0.

Returns:

Population object with current host and vector lists.

dieHost(rand)[source]

Remove host at this index from alive lists.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual to kill.

dieVector(rand)[source]

Remove vector at this index from alive lists.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual to kill.

getWeightedRandom(rand, r)[source]

Returns index of element chosen from weights and given random number.

Since sampling from coefficient arrays which contain a dummy first row, index is decreased by 1.

Parameters:
  • rand (number) – 0-1 random number.

  • r (numpy array) – array with weights.

Returns:

new 0-1 random number.

healthyCoefficientRow()[source]

Returns coefficient values corresponding to a healthy host/vector.

killHost(rand)[source]

Add host at this index to dead list, remove it from alive ones.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual to kill.

killVector(rand)[source]

Add host at this index to dead list, remove it from alive ones.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual to kill.

migrate(target_pop, num_hosts, num_vectors, rand=None)[source]

Transfer hosts and/or vectors from this population to another.

Parameters:
  • target_pop (Population objects) – population towards which migration will occur.

  • num_hosts (int) – number of hosts to transfer.

  • num_vectors (int) – number of vectors to transfer.

Keyword Arguments:

rand (number 0-1) – uniform random number from 0 to 1 to use when choosing individuals to migrate; if None, generates new random number to choose (through numpy), otherwise, assumes event is happening through Gillespie class call and migrates a single host or vector. Defaults to None.

mutateHost(rand)[source]

Mutate a single, random locus in a random pathogen in the given host.

Creates a new genotype from a de novo mutation event in the host given.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual in which to choose a pathogen to mutate.

mutateVector(rand)[source]

Mutate a single, random locus in a random pathogen in given vector.

Creates a new genotype from a de novo mutation event in the vector given.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual in which to choose a pathogen to mutate.

newHostGroup(hosts=-1, type='any')[source]

Return a list of random hosts in population.

Keyword Arguments:
  • hosts (number) – number of hosts to be sampled randomly: if <0, samples from whole population; if <1, takes that fraction of population; if >=1, samples that integer number of hosts. Defaults to -1.

  • type (String = {'healthy', 'infected', 'any'}) – whether to sample healthy hosts only, infected hosts only, or any hosts. Defaults to ‘any’.

Returns:

list containing sampled hosts.

newVectorGroup(vectors=-1, type='any')[source]

Return a list of random vectors in population.

Keyword Arguments:
  • vectors (number) – number of vectors to be sampled randomly: if <0, samples from whole population; if <1, takes that fraction of population; if >=1, samples that integer number of vectors. Defaults to -1.

  • type (String = {'healthy', 'infected', 'any'}) – whether to sample healthy vectors only, infected vectors. Defaults to ‘any’.

Returns:

list containing sampled vectors.

populationContact(target_pop, rand, host_origin=True, host_target=True)[source]

Contacts hosts and/or vectors from this population to another.

Parameters:
  • target_pop (Population object) – population towards which migration will occur.

  • rand (number) – uniform random number from 0 to 1 to use when choosing individuals to contact.

Keyword Arguments:
  • host_origin (Boolean) – whether to draw from hosts in the origin population (as opposed to vectors). Defaults to True.

  • host_target (Boolean) – whether to draw from hosts in the target population (as opposed to vectors). Defaults to True.

protectHosts(frac_hosts, protection_sequence, hosts=[])[source]

Protect a random fraction of infected hosts against some infection.

Adds protection sequence specified to a random fraction of the hosts specified. Does not cure them if they are already infected.

Parameters:
  • frac_hosts (number 0-1) – fraction of hosts considered to be randomly selected.

  • protection_sequence (String) – sequence against which to protect.

Keyword Arguments:

hosts (list of Host objects) – list of specific hosts to sample from, if empty, samples from whole population. Defaults to [].

protectVectors(frac_vectors, protection_sequence, vectors=[])[source]

Protect a random fraction of infected vectors against some infection.

Adds protection sequence specified to a random fraction of the vectors specified. Does not cure them if they are already infected.

Parameters:
  • frac_vectors (number 0-1) – fraction of vectors considered to be randomly selected.

  • protection_sequence (String) – sequence against which to protect.

Keyword Arguments:

vectors (list of Vector objects) – list of specific vectors to sample from, if empty, samples from whole population. Defaults to [].

recombineHost(rand)[source]

Recombine 2 random pathogen genomes at random locus in given host.

Creates a new genotype from two random possible pathogens in the host given.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual in which to choose pathogens to recombine.

recombineVector(rand)[source]

Recombine 2 random pathogen genomes at random locus in given vector.

Creates a new genotype from two random possible pathogens in the vector given.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual in which to choose pathogens to recombine.

recoverHost(rand)[source]

Remove all infections from host at this index.

If model is protecting upon recovery, add protecion sequence as defined by the indexes in the corresponding model parameter. Remove from population infected list and add to healthy list.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual to recover.

recoverVector(rand)[source]

Remove all infections from vector at this index.

If model is protecting upon recovery, add protecion sequence as defined by the indexes in the corresponding model parameter. Remove from population infected list and add to healthy list.

Parameters:

rand (number) – uniform random number from 0 to 1 to use when choosing individual to recover.

removeHosts(num_hosts_or_list)[source]

Remove a number of specified or random hosts from population.

Parameters:

num_hosts_or_list (int or list of Host objects) – number of hosts to be sampled randomly for removal or list of hosts to be removed, must be hosts in this population.

removeVectors(num_vectors_or_list)[source]

Remove a number of specified or random vectors from population.

Parameters:

num_vectors_or_list (int or list of Vector objects) – number of vectors to be sampled randomly for removal or list of vectors to be removed, must be vectors in this population.

setHostHostPopulationContactNeighbor(neighbor, rate)[source]

Set host-host contact rate from this population towards another one.

Parameters:
  • neighbor (Population object) – population towards which migration rate will be specified.

  • rate (number) – migration rate from this population to the neighbor.

setHostMigrationNeighbor(neighbor, rate)[source]

Set host migration rate from this population towards another one.

Parameters:
  • neighbor (Population object) – population towards which migration rate will be specified.

  • rate (number) – migration rate from this population to the neighbor.

setHostVectorPopulationContactNeighbor(neighbor, rate)[source]

Set host-vector contact rate from this population to another one.

Parameters:
  • neighbor (Population object) – population towards which migration rate will be specified.

  • rate (number) – migration rate from this population to the neighbor.

setSetup(setup)[source]

Assign parameters stored in Setup object to this population.

Parameters:

setup (Setup object) – the setup to be assigned.

setVectorHostPopulationContactNeighbor(neighbor, rate)[source]

Set vector-host contact rate from this population to another one.

Parameters:
  • neighbor (Population object) – population towards which migration rate will be specified.

  • rate (number) – migration rate from this population to the neighbor.

setVectorMigrationNeighbor(neighbor, rate)[source]

Set vector migration rate from this population towards another one.

Arguments: neighbor (Population object): population towards which migration rate will be specified. rate (number): migration rate from this population to the neighbor.

treatHosts(frac_hosts, resistance_seqs, hosts=[])[source]

Treat random fraction of infected hosts against some infection.

Removes all infections with genotypes susceptible to given treatment. Pathogens are removed if they are missing at least one of the sequences in resistance_seqs from their genome. Removes this organism from population infected list and adds to healthy list if appropriate.

Parameters:
  • frac_hosts (number 0-1) – fraction of hosts considered to be randomly selected.

  • resistance_seqs (list of Strings) – contains sequences required for treatment resistance.

Keyword arguments: hosts (list of Host objects): list of specific hosts to sample from, if empty, samples from

whole population. Defaults to [].

treatVectors(frac_vectors, resistance_seqs, vectors=[])[source]

Treat random fraction of infected vectors agains some infection.

Removes all infections with genotypes susceptible to given treatment. Pathogens are removed if they are missing at least one of the sequences in resistance_seqs from their genome. Removes this organism from population infected list and adds to healthy list if appropriate.

Parameters:
  • frac_vectors (number 0-1) – fraction of vectors considered to be randomly selected.

  • resistance_seqs (list of Strings) – contains sequences required for treatment resistance.

Keyword Arguments:

vectors (list of Vector objects) – list of specific vectors to sample from, if empty, samples from whole population. Defaults to [].

updateHostCoefficients()[source]

Updates event coefficient values in population’s hosts.

updateVectorCoefficients()[source]

Updates event coefficient values in population’s vectors.

wipeProtectionHosts(hosts=[])[source]

Removes all protection sequences from hosts.

Keyword Arguments:

hosts (list of Host objects) – list of specific hosts to sample from, if empty, samples from whole population. Defaults to [].

wipeProtectionVectors(vectors=[])[source]

Removes all protection sequences from vectors.

Keyword Arguments:

vectors (list of Vector objects) – list of specific vectors to sample from, if empty, samples from whole population. Defaults to [].

opqua.internal.setup module

Contains class Intervention.

class opqua.internal.setup.Setup(id, num_loci, possible_alleles, fitnessHost, contactHost, receiveContactHost, mortalityHost, natalityHost, recoveryHost, migrationHost, populationContactHost, receivePopulationContactHost, mutationHost, recombinationHost, fitnessVector, contactVector, receiveContactVector, mortalityVector, natalityVector, recoveryVector, migrationVector, populationContactVector, receivePopulationContactVector, mutationVector, recombinationVector, contact_rate_host_vector, transmission_efficiency_host_vector, transmission_efficiency_vector_host, contact_rate_host_host, transmission_efficiency_host_host, mean_inoculum_host, mean_inoculum_vector, recovery_rate_host, recovery_rate_vector, mortality_rate_host, mortality_rate_vector, recombine_in_host, recombine_in_vector, num_crossover_host, num_crossover_vector, mutate_in_host, mutate_in_vector, death_rate_host, death_rate_vector, birth_rate_host, birth_rate_vector, vertical_transmission_host, vertical_transmission_vector, inherit_protection_host, inherit_protection_vector, protection_upon_recovery_host, protection_upon_recovery_vector)[source]

Bases: object

Class defines a setup with population parameters.

id

key of the Setup inside model dictionary.

Type:

String

num_loci

length of each pathogen genome string.

Type:

int>0

possible_alleles

set of possible characters in all genome string, or at each position in genome string.

Type:

String or list of Strings with num_loci elements

fitnessHost

function that evaluates relative fitness in head-to-head competition for different genomes within the same host.

Type:

callable, takes a String argument and returns a number >= 0

contactHost

function that returns coefficient modifying probability of a given host being chosen to be the infector in a contact event, based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

receiveContactHost

function that returns coefficient modifying probability of a given host being chosen to be the infected in a contact event, based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

mortalityHost

function that returns coefficient modifying death rate for a given host, based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

natalityHost

function that returns coefficient modifying birth rate for a given host, based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

recoveryHost

function that returns coefficient modifying recovery rate for a given host based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

migrationHost

function that returns coefficient modifying migration rate for a given host based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

populationContactHost

function that returns coefficient modifying population contact rate for a given host based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

mutationHost

function that returns coefficient modifying mutation rate for a given host based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

recombinationHost

function that returns coefficient modifying recombination rate for a given host based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

fitnessVector

function that evaluates relative fitness in head-to-head competition for different genomes within the same vector.

Type:

callable, takes a String argument and returns a number >=0

contactVector

function that returns coefficient modifying probability of a given vector being chosen to be the infector in a contact event, based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

receiveContactVector

function that returns coefficient modifying probability of a given vector being chosen to be the infected in a contact event, based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

mortalityVector

function that returns coefficient modifying death rate for a given vector, based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

natalityVector

function that returns coefficient modifying birth rate for a given vector, based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

recoveryVector

function that returns coefficient modifying recovery rate for a given vector based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

migrationVector

function that returns coefficient modifying migration rate for a given vector based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

populationContactVector

function that returns coefficient modifying population contact rate for a given vector based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

mutationVector

function that returns coefficient modifying mutation rate for a given vector based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

recombinationVector

function that returns coefficient modifying recombination rate for a given vector based on genome sequence of pathogen.

Type:

callable, takes a String argument and returns a number 0-1

contact_rate_host_vector

rate of host-vector contact events, not necessarily transmission, assumes constant population density; evts/time.

Type:

number >= 0

transmission_efficiency_host_vector

fraction of host-vector contacts that result in successful transmission.

Type:

float

transmission_efficiency_vector_host

fraction of vector-host contacts that result in successful transmission.

Type:

float

contact_rate_host_host

rate of host-host contact events, not necessarily transmission, assumes constant population density; evts/time.

Type:

number >= 0

transmission_efficiency_host_host

fraction of host-host contacts that result in successful transmission.

Type:

float

mean_inoculum_host

mean number of pathogens that are transmitted from a vector or host into a new host during a contact event.

Type:

int >= 0

mean_inoculum_vector

from a host to a vector during a contact event.

Type:

int >= 0

recovery_rate_host

rate at which hosts clear all pathogens; 1/time.

Type:

number >= 0

recovery_rate_vector

rate at which vectors clear all pathogens 1/time.

Type:

number >= 0

recovery_rate_vector

rate at which vectors clear all pathogens 1/time.

Type:

number >= 0

mortality_rate_host

rate at which infected hosts die from disease.

Type:

number 0-1

mortality_rate_vector

rate at which infected vectors die from disease.

Type:

number 0-1

recombine_in_host

rate at which recombination occurs in host; evts/time.

Type:

number >= 0

recombine_in_vector

rate at which recombination occurs in vector; evts/time.

Type:

number >= 0

num_crossover_host

mean of a Poisson distribution modeling the number of crossover events of host recombination events.

Type:

number >= 0

num_crossover_vector

mean of a Poisson distribution modeling the number of crossover events of vector recombination events.

Type:

number >= 0

mutate_in_host

rate at which mutation occurs in host; evts/time.

Type:

number >= 0

mutate_in_vector

rate at which mutation occurs in vector; evts/time.

Type:

number >= 0

death_rate_host

natural host death rate; 1/time.

Type:

number >= 0

death_rate_vector

natural vector death rate; 1/time.

Type:

number >= 0

birth_rate_host

infected host birth rate; 1/time.

Type:

number >= 0

birth_rate_vector

infected vector birth rate; 1/time.

Type:

number >= 0

vertical_transmission_host

probability that a host is infected by its parent at birth.

Type:

number 0-1

vertical_transmission_vector

probability that a vector is infected by its parent at birth.

Type:

number 0-1

inherit_protection_host

probability that a host inherits all protection sequences from its parent.

Type:

number 0-1

inherit_protection_vector

probability that a vector inherits all protection sequences from its parent.

Type:

number 0-1

protection_upon_recovery_host

defines indexes in genome string that define substring to be added to host protection sequences after recovery.

Type:

None or array-like of length 2 with int 0-num_loci

protection_upon_recovery_vector

defines indexes in genome string that define substring to be added to vector protection sequences after recovery.

Type:

None or array-like of length 2 with int 0-num_loci

opqua.internal.vector module

Contains class Vector.

class opqua.internal.vector.Vector(population, id, slim=False)[source]

Bases: object

Class defines vector entities to be infected by pathogens in model.

These can infect hosts, the main entities in the model.

population

the population this vector belongs to.

Type:

Population object

id

unique identifier for this vector within population.

Type:

String

slim

whether to create a slimmed-down representation of the population for data storage (only ID, host and vector lists). Defaults to False.

Type:

Boolean

acquirePathogen(genome)[source]

Adds given genome to this vector’s pathogens.

Modifies event coefficient matrix accordingly.

Parameters:

genome (String) – the genome to be added.

Returns:

Boolean indicating whether or not the model has changed state.

applyTreatment(resistance_seqs)[source]

Remove all infections with genotypes susceptible to given treatment.

Pathogens are removed if they are missing at least one of the sequences in resistance_seqs from their genome. Removes this organism from population infected list and adds to healthy list if appropriate.

Parameters:

resistance_seqs (list of Strings) – contains sequences required for treatment resistance.

birth(rand)[source]

Add vector to population based on this vector.

copyState()[source]

Returns a slimmed-down representation of the current vector state.

Returns:

Vector object with current pathogens and protection_sequences.

die()[source]

Add vector to population’s dead list, remove it from alive ones.

getWeightedRandomGenome(rand, r)[source]

Returns index of element chosen from weights and given random number.

Parameters:
  • rand (number) – 0-1 random number.

  • r (numpy array) – array with weights.

Returns:

new 0-1 random number.

infectHost(host)[source]

Infect given host with a sample of this vector’s pathogens.

Each pathogen in the infector is sampled as present or absent in the inoculum by drawing from a Poisson distribution with a mean equal to the mean inoculum size of the organism being infected weighted by each genome’s fitness as a fraction of the total in the infector as the probability of each trial (minimum 1 pathogen transfered). Each pathogen present in the inoculum will be added to the infected organism, if it does not have protection from the pathogen’s genome. Fitnesses are computed for the pathogens’ genomes in the infected organism, and the organism is included in the poplation’s infected list if appropriate.

Parameters:

vector (Vector object) – the vector to be infected.

Returns:

Boolean indicating whether or not the model has changed state.

infectVector(vector)[source]

Infect given host with a sample of this vector’s pathogens.

Each pathogen in the infector is sampled as present or absent in the inoculum by drawing from a Poisson distribution with a mean equal to the mean inoculum size of the organism being infected weighted by each genome’s fitness as a fraction of the total in the infector as the probability of each trial (minimum 1 pathogen transfered). Each pathogen present in the inoculum will be added to the infected organism, if it does not have protection from the pathogen’s genome. Fitnesses are computed for the pathogens’ genomes in the infected organism, and the organism is included in the poplation’s infected list if appropriate.

Parameters:

vector (Vector object) – the vector to be infected.

Returns:

Boolean indicating whether or not the model has changed state.

mutate(rand)[source]

Mutate a single, random locus in a random pathogen.

Creates a new genotype from a de novo mutation event.

recombine(rand)[source]

Recombine two random pathogen genomes at random locus.

Creates a new genotype from two random possible pathogens.

recover()[source]

Remove all infections from this vector.

If model is protecting upon recovery, add protection sequence as defined by the indexes in the corresponding model parameter. Remove from population infected list and add to healthy list.

Module contents