contagiongo

package module
v0.0.0-...-5bd8482 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2018 License: Apache-2.0 Imports: 19 Imported by: 2

README

Contagion

An Individual-based Model for Simulating Viral Evolution in Epidemics using Networks

Contagion is a new type of forward genetic simulator and disease outbreak simulator specially designed to explicitly model evolution both within- and between-host scales of reference simultaneously. At the within-host level, Contagion simulates the processes of replication, mutation, selection, and drift on viral pathogen sequences. At the host population level, Contagion performs like an epidemic simulator that tracks the infection status of individual hosts and simulates pathogen transmission between hosts conditioned on the available routes present in a given host population.

Important Notice

Contagion is currently under development and APIs may change.

Contact

If encounter problems or have questions or feature requests, please feel contact me -

Kent Kawashima
Email: kentkawashima@nig.ac.jp
Twitter: @kent

License

Apache License, Version 2.0 Copyright 2018 Kent Kawashima

Documentation

Index

Constants

View Source
const (
	// GraphPathogenTypeAssertionError is the message printed when
	// an GraphPathogen cannot be asserted for an interface
	GraphPathogenTypeAssertionError = "error asserting PathogenNode interface"

	InvalidFloatParameterError  = "invalid %s %f, %s"
	InvalidIntParameterError    = "invalid %s %d, %s"
	InvalidStringParameterError = "invalid %s %s, %s"
)
View Source
const (
	UnequalFloatParameterError = "expected %s %f, instead got %f"
	EqualFloatParameterError   = "%s should not be equal: %f, %f"
	FloatNotBetweenError       = "expected %s between %f and %f, instead got %f"

	UnequalIntParameterError = "expected %s %d, instead got %d"
	EqualIntParameterError   = "%s should not be equal: %d, %d"
	IntNotBetweenError       = "expected %s between %d and %d, instead got %d"

	UnequalStringParameterError = "expected %s %s, instead got %s"
	EqualStringParameterError   = "%s should not be idenitical: %s, %s"

	UnexpectedErrorWhileError = "encountered error while %s: %s"
	ExpectedErrorWhileError   = "expected an error while %s, instead got none"
	UnrecognizedKeywordError  = "%s is not a valid keyword for %s"
)
View Source
const (
	IdenticalPointerError    = "memory address of %s (%p) and %s (%p) are identical"
	NotIdenticalPointerError = "memory address of %s (%p) and %s (%p) are not identical"
)
View Source
const (
	SusceptibleStatusCode = 1
	ExposedStatusCode     = 2
	InfectedStatusCode    = 3
	InfectiveStatusCode   = 4
	RemovedStatusCode     = 5
	RecoveredStatusCode   = 6
	DeadStatusCode        = 7
	VaccinatedStatusCode  = 8
)

The following are status codes for different preset compartments that describe the current epidemiological status of a host in the simulation.

Variables

This section is empty.

Functions

func AppendToFile

func AppendToFile(path string, b []byte) error

AppendToFile creates a new file on the given path if it does not exist, or appends to the end of the existing file if the file exists.

func ConnectionDoesNotExistError

func ConnectionDoesNotExistError(a, b int) error

ConnectionDoesNotExistError indicates that a connection between hosts a and b (int) does not exist but is expected to exist.

func ConnectionExistsError

func ConnectionExistsError(a, b int, value float64) error

ConnectionExistsError indicates that a connection between the source host and the destination host exists and has the following value in float64.

func DuplicateSitePositionError

func DuplicateSitePositionError(pos int, lineNum int) error

DuplicateSitePositionError indicates that the site in the file is not unique and has been included more than once.

func DurationTooLongError

func DurationTooLongError(interval string, intervalDuration int, condition string, conditionValue int) error

DurationTooLongError indicates that the duration of a particular interval is longer than expected.

func DurationTooShortError

func DurationTooShortError(interval string, intervalDuration int, condition string, conditionValue int) error

DurationTooShortError indicates that the duration of a particular interval is shorter than expected.

func EmptyMatrixError

func EmptyMatrixError() error

func EmptyModelError

func EmptyModelError() error

EmptyModelError indicates that a model should exist but instead is nil.

func ExchangePathogens

func ExchangePathogens(i, t int, h1, h2 Host, h1Count, h2Count int, c chan<- ExchangeEvent, d chan<- TransmissionPackage, wg *sync.WaitGroup)

ExchangePathogens exchanges pathogens between neighboring hosts.

func Exists

func Exists(path string) (bool, error)

Exists returns whether the given file or directory exists or not, and accompanying errors.

func ExposedDurationTooLongError

func ExposedDurationTooLongError(intervalDuration int, conditionValue int) error

ExposedDurationTooLongError indicates that the duration in the exposed state is too long.

func ExposedDurationTooShortError

func ExposedDurationTooShortError(intervalDuration int, conditionValue int) error

ExposedDurationTooShortError indicates that the duration in the exposed state is too short.

func FileDoesNotExistError

func FileDoesNotExistError(path string) error

FileDoesNotExistError indicates that a file does not exist at the given path when it is expected to.

func FileExistsCheckError

func FileExistsCheckError(err error, path string) error

FileExistsCheckError indicates an error was encountered while checking if the files exists. This is not the same with an error because a file exists.

func FileExistsError

func FileExistsError(path string) error

FileExistsError indicates that a file exists at the given path.

func FileOpenError

func FileOpenError(err error) error

FileOpenError indicates that an error was encountered while opening a file.

func FileParsingError

func FileParsingError(err error, lineNum int) error

FileParsingError indicates a parsing error was encountered at a particular line in the file. Most likely the file was not properly formatted.

func FileSyncError

func FileSyncError(err error) error

FileSyncError indicates that an error was encountered while the file was being flushed from memory and being written to disk.

func FileWriteError

func FileWriteError(err error) error

FileWriteError indicates that an error was encountered while writing to the file in memory.

func InfectedDurationTooLongError

func InfectedDurationTooLongError(intervalDuration int, conditionValue int) error

InfectedDurationTooLongError indicates that the duration in the infected state is too long.

func InfectedDurationTooShortError

func InfectedDurationTooShortError(intervalDuration int, conditionValue int) error

InfectedDurationTooShortError indicates that the duration in the infected state is too short.

func InfectiveDurationTooLongError

func InfectiveDurationTooLongError(intervalDuration int, conditionValue int) error

InfectiveDurationTooLongError indicates that the duration in the infective state is too long.

func InfectiveDurationTooShortError

func InfectiveDurationTooShortError(intervalDuration int, conditionValue int) error

InfectiveDurationTooShortError indicates that the duration in the infective state is too short.

func IntKeyExists

func IntKeyExists(key int) error

IntKeyExists indicates that the given integer key already exists.

func IntKeyNotFoundError

func IntKeyNotFoundError(key int) error

IntKeyNotFoundError indicates that the given integer key does not exist.

func IntrinsicRateReplication

func IntrinsicRateReplication(pathogens []GenotypeNode, replFitness []float64, immuneSystem interface{}) <-chan GenotypeNode

IntrinsicRateReplication replicates pathogens by considering their fitness value as the growth rate.

func InvalidCharError

func InvalidCharError(pos int, enc uint8) error

func InvalidConnectionWeightError

func InvalidConnectionWeightError(wt float64, lineNum int) error

InvalidConnectionWeightError indicates that the given connection weight is less than 0.

func InvalidRowError

func InvalidRowError() error

func InvalidStateCharError

func InvalidStateCharError(char string, pos int) error

InvalidStateCharError indicates that a character encountered is not in the set of expected characters.

func LoadFitnessMatrix

func LoadFitnessMatrix(path string, valueType string) (map[int]map[uint8]float64, error)

LoadFitnessMatrix parses and loads the fitness matrix encoded in the text file at the given path.

func LoadSequences

func LoadSequences(path string) (map[int][][]uint8, error)

LoadSequences parses a specially-formatted FASTA file to get the sequences, encode sequences into integers, and distribute to assigned hosts. Returns a map where the key is the host ID and the values are the pathogen sequences for the particular host.

func ModelExistsError

func ModelExistsError(modelName string, modelID int) error

ModelExistsError indicates that an existing model already exists a new model cannot be assigned to replace it.

func MotifExistsError

func MotifExistsError(motifID string) error

MotifExistsError indicates that a motif with the same sequence and positions already exists in the model.

func MultinomialReplication

func MultinomialReplication(pathogens []GenotypeNode, normedFitnesses []float64, newPopSize int) <-chan GenotypeNode

MultinomialReplication replicates and selects sequences based on normalized fitness values used as probabilities.

func MutateSequence

func MutateSequence(sequences <-chan GenotypeNode, tree GenotypeTree, model IntrahostModel) (<-chan GenotypeNode, <-chan GenotypeNode)

MutateSequence adds substitution mutations to sequenceNode.

func MutateSite

func MutateSite(transitionProbs ...float64) uint8

MutateSite returns the new state of a site based on the given a set of transition probabilities.

func NewFile

func NewFile(path string, b []byte) error

NewFile creates a new file on the given path if it does not exist. Returns an error if the file exists.

func OpenSQLiteDB

func OpenSQLiteDB(path, connectionString string) (*sql.DB, error)

OpenSQLiteDB establishes a database connection using the given connection string.

func OpenSQLiteDBOptimized

func OpenSQLiteDBOptimized(path string) (*sql.DB, error)

OpenSQLiteDBOptimized establishes a database connection using WAL and exclusive locking.

func OverlappingMotifError

func OverlappingMotifError(pos int) error

OverlappingMotifError indicates that a particular site cannot be used again because it is already being considered by another motif in the model.

func RecombineAnySequence

func RecombineAnySequence(numSeqs, numRecSites int, sequences <-chan GenotypeNode, tree GenotypeTree, model IntrahostModel) (<-chan GenotypeNode, <-chan GenotypeNode)

RecombineAnySequence recombines any two sequences at a random position similar to the behavior of template switching.

func RecombineSequencePairs

func RecombineSequencePairs(numSeqs, numRecSites int, sequences <-chan GenotypeNode, tree GenotypeTree, model IntrahostModel) (<-chan GenotypeNode, <-chan GenotypeNode)

RecombineSequencePairs recombines two sequences at random positions similar to the behavior of diploid chromosomes.

func RemovedDurationTooLongError

func RemovedDurationTooLongError(intervalDuration int, conditionValue int) error

RemovedDurationTooLongError indicates that the duration in the removed state is too long.

func RemovedDurationTooShortError

func RemovedDurationTooShortError(intervalDuration int, conditionValue int) error

RemovedDurationTooShortError indicates that the duration in the removed state is too short.

func SQLBeginTransactionError

func SQLBeginTransactionError(err error) error

SQLBeginTransactionError indicates that an error was encountered while a transaction was being initialized.

func SQLExecError

func SQLExecError(err error, stmt string) error

SQLExecError indicates that an error was encountered while executing an SQL statement. Returns the error raised by the database connection and the SQL statement that produced the error.

func SQLExecStatementError

func SQLExecStatementError(err error) error

SQLExecStatementError indicates that an error was encountered while a template statement was being substituted with actual values.

func SQLOpenError

func SQLOpenError(err error) error

SQLOpenError indicates that an error was encountered while open a database connection. Includes the error returned by sql.Open.

func SQLPrepareStatementError

func SQLPrepareStatementError(err error, stmt string) error

SQLPrepareStatementError indicates that an error was encountered while a template SQL statement was being initialized.

func SelfLoopError

func SelfLoopError(hostID int) error

SelfLoopError indicates that the start and end host are the same based on host ID, which results in a self-loop.

func SetFitnessModelExistsError

func SetFitnessModelExistsError(modelName string, modelID int) error

SetFitnessModelExistsError indicates that a fitness model has already been assigned to a host.

func SetIntrahostModelExistsError

func SetIntrahostModelExistsError(modelName string, modelID int) error

SetIntrahostModelExistsError indicates that an intrahost model has already been assigned to a host.

func SetTransmissionModelExistsError

func SetTransmissionModelExistsError(modelName string, modelID int) error

SetTransmissionModelExistsError indicates that a transmission model has already been assigned to a host.

func TransmitPathogens

func TransmitPathogens(i, t int, src, dst Host, numMigrants int, transmissionProb float64, count int, c chan<- TransmissionEvent, d chan<- TransmissionPackage, wg *sync.WaitGroup)

TransmitPathogens transmits the pathogen to its neighboring host/s. If transmission occurs, sends transmitted node over the channel to be added to the recepient. Also sends node information in order to record the event.

func UnequalNumStatesError

func UnequalNumStatesError(numStates, prevNumStates int, site int, lineNum int) error

UnequalNumStatesError indicates that the number of states specified in a site does not match the number of states in another site.

func ZeroItemsError

func ZeroItemsError() error

ZeroItemsError indicates that the length of a list or set is empty but at least one item is required.

Types

type BevertonHoltThresholdPopModel

type BevertonHoltThresholdPopModel struct {
	// contains filtered or unexported fields
}

BevertonHoltThresholdPopModel uses the Beverton-Holt population model modified to have a constant threshold population size.

func (*BevertonHoltThresholdPopModel) GrowthRate

func (m *BevertonHoltThresholdPopModel) GrowthRate() float64

func (*BevertonHoltThresholdPopModel) MaxPathogenPopSize

func (m *BevertonHoltThresholdPopModel) MaxPathogenPopSize() int

func (*BevertonHoltThresholdPopModel) ModelID

func (meta *BevertonHoltThresholdPopModel) ModelID() int

func (*BevertonHoltThresholdPopModel) ModelName

func (meta *BevertonHoltThresholdPopModel) ModelName() string

func (*BevertonHoltThresholdPopModel) MutationRate

func (params *BevertonHoltThresholdPopModel) MutationRate() float64

func (*BevertonHoltThresholdPopModel) NextPathogenPopSize

func (m *BevertonHoltThresholdPopModel) NextPathogenPopSize(n int) int

func (*BevertonHoltThresholdPopModel) ProbabilisticDuration

func (params *BevertonHoltThresholdPopModel) ProbabilisticDuration() bool

func (*BevertonHoltThresholdPopModel) RecombinationRate

func (params *BevertonHoltThresholdPopModel) RecombinationRate() float64

func (*BevertonHoltThresholdPopModel) ReplicationMethod

func (m *BevertonHoltThresholdPopModel) ReplicationMethod() string

func (*BevertonHoltThresholdPopModel) SetModelID

func (meta *BevertonHoltThresholdPopModel) SetModelID(id int)

func (*BevertonHoltThresholdPopModel) SetModelName

func (meta *BevertonHoltThresholdPopModel) SetModelName(name string)

func (*BevertonHoltThresholdPopModel) StatusDuration

func (params *BevertonHoltThresholdPopModel) StatusDuration(status int) int

func (*BevertonHoltThresholdPopModel) TransitionMatrix

func (params *BevertonHoltThresholdPopModel) TransitionMatrix() [][]float64

func (*BevertonHoltThresholdPopModel) TransitionProbs

func (params *BevertonHoltThresholdPopModel) TransitionProbs(char int) []float64

type CSVLogger

type CSVLogger struct {
	// contains filtered or unexported fields
}

CSVLogger is a DataLogger that writes simulation data as comma-delimited files.

func NewCSVLogger

func NewCSVLogger(basepath string, i int) *CSVLogger

NewCSVLogger creates a new logger that writes data into CSV files.

func (*CSVLogger) Init

func (l *CSVLogger) Init() error

Init creates CSV files and writes header information for each file.

func (*CSVLogger) SetBasePath

func (l *CSVLogger) SetBasePath(basepath string, i int)

SetBasePath sets the base path of the logger.

func (*CSVLogger) WriteGenotypeFreq

func (l *CSVLogger) WriteGenotypeFreq(c <-chan GenotypeFreqPackage)

WriteGenotypeFreq records the count of unique genotype nodes present within the host in a given time in the simulation.

func (*CSVLogger) WriteGenotypeNodes

func (l *CSVLogger) WriteGenotypeNodes(c <-chan GenotypeNode)

WriteGenotypeNodes records new genotype node's ID and associated genotype ID to file

func (*CSVLogger) WriteGenotypes

func (l *CSVLogger) WriteGenotypes(c <-chan Genotype)

WriteGenotypes records a new genotype's ID and sequence to file.

func (*CSVLogger) WriteMutations

func (l *CSVLogger) WriteMutations(c <-chan MutationPackage)

WriteMutations records every time a new genotype node is created. It records the time and in what host this new mutation arose.

func (*CSVLogger) WriteStatus

func (l *CSVLogger) WriteStatus(c <-chan StatusPackage)

WriteStatus records the status of each host every generation.

func (*CSVLogger) WriteTransmission

func (l *CSVLogger) WriteTransmission(c <-chan TransmissionPackage)

WriteTransmission records the ID's of genotype node that are transmitted between hosts.

type Config

type Config interface {
	Validate() error
	NewSimulation() (Epidemic, error)
	NumInstances() int
	NumGenerations() int
	LogFreq() int
	LogPath() string
	LogTransmission() bool
}

Config represents any top level TOML configuration that can create a new simulation.

type ConstantPopModel

type ConstantPopModel struct {
	// contains filtered or unexported fields
}

ConstantPopModel models a constant pathogen population size within the host.

func (*ConstantPopModel) MaxPathogenPopSize

func (m *ConstantPopModel) MaxPathogenPopSize() int

func (*ConstantPopModel) ModelID

func (meta *ConstantPopModel) ModelID() int

func (*ConstantPopModel) ModelName

func (meta *ConstantPopModel) ModelName() string

func (*ConstantPopModel) MutationRate

func (params *ConstantPopModel) MutationRate() float64

func (*ConstantPopModel) NextPathogenPopSize

func (m *ConstantPopModel) NextPathogenPopSize(n int) int

func (*ConstantPopModel) ProbabilisticDuration

func (params *ConstantPopModel) ProbabilisticDuration() bool

func (*ConstantPopModel) RecombinationRate

func (params *ConstantPopModel) RecombinationRate() float64

func (*ConstantPopModel) ReplicationMethod

func (m *ConstantPopModel) ReplicationMethod() string

func (*ConstantPopModel) SetModelID

func (meta *ConstantPopModel) SetModelID(id int)

func (*ConstantPopModel) SetModelName

func (meta *ConstantPopModel) SetModelName(name string)

func (*ConstantPopModel) StatusDuration

func (params *ConstantPopModel) StatusDuration(status int) int

func (*ConstantPopModel) TransitionMatrix

func (params *ConstantPopModel) TransitionMatrix() [][]float64

func (*ConstantPopModel) TransitionProbs

func (params *ConstantPopModel) TransitionProbs(char int) []float64

type DataLogger

type DataLogger interface {
	// SetBasePath sets the base path of the logger.
	SetBasePath(path string, i int)
	// Init initializes the logger. For example, if the logger writes a
	// CSV file, Init can create a file and write header information first.
	// Or if the logger writes to a database, Init can be used to
	// create a new table.
	Init() error
	// WriteGenotypes records a new genotype's ID and sequence to file.
	WriteGenotypes(c <-chan Genotype)
	// WriteGenotypeNodes records new genotype node's ID and
	// associated genotype ID to file
	WriteGenotypeNodes(c <-chan GenotypeNode)
	// WriteGenotypeFreq records the count of unique genotype nodes
	// present within the host in a given time in the simulation.
	WriteGenotypeFreq(c <-chan GenotypeFreqPackage)
	// WriteMutations records every time a new genotype node is created.
	// It records the time and in what host this new mutation arose.
	WriteMutations(c <-chan MutationPackage)
	// WriteStatus records the status of each host every generation.
	WriteStatus(c <-chan StatusPackage)
	// WriteTransmission records the ID's of genotype node that
	// are transmitted between hosts.
	WriteTransmission(c <-chan TransmissionPackage)
}

DataLogger is the general definition of a logger that records simulation data to file whether it writes a text file or writes to a database.

type EndTransSimulation

type EndTransSimulation struct {
	EpidemicSimulation
}

EndTransSimulation creates and runs a modified version of the SIR epidemiological simulation. In the endtrans model, transmissions are allowed to occur only at the last generation before pathogens are cleared from the host. To make transmission completely deterministic, set the transmission probability to 1.0, use the constant mode and set it to a constant size. This means that all paths connected to an infectable host gets infected at the end of the infection cycle of the current host. Endtrans assumes that the InfectedDuration is not zero.

func NewEndTransSimulation

func NewEndTransSimulation(config Config, logger DataLogger) (*EndTransSimulation, error)

NewEndTransSimulation creates a new SI simulation.

func (*EndTransSimulation) Run

func (sim *EndTransSimulation) Run(i int)

Run instantiates, runs, and records the a new simulation.

func (*EndTransSimulation) Transmit

func (sim *EndTransSimulation) Transmit(t int)

Transmit facilitates the sampling and migration process of pathogens between hosts.

func (*EndTransSimulation) Update

func (sim *EndTransSimulation) Update(t int)

type Epidemic

type Epidemic interface {
	// Host returns the selected host in the simulation.
	Host(id int) Host
	// HostStatus retrieves the current status of the selected host.
	HostStatus(id int) int
	// SetHostStatus sets the current status of the selected host
	// to a given status code.
	SetHostStatus(id, status int)
	// HostTimer returns the current number of generations remaining
	// before the host changes status.
	HostTimer(id int) int
	// SetHostTimer sets the number of generations for the host to
	// remain in its current status.
	SetHostTimer(id, interval int)
	// InfectableStatuses returns the list of statuses that infected
	// hosts can transmit to.
	InfectableStatuses() []int

	// HostMap returns the hosts in the simulation in the form of a map.
	// The key is the host's ID and the value is the pointer to the host.
	HostMap() map[int]Host
	// HostConnection returns the weight of a connection between two hosts
	// if it exists, returns 0 otherwise.
	HostConnection(a, b int) float64
	// HostNeighbors retrieves the directly connected hosts to the current
	// host based on the supplied adjacency matrix.
	HostNeighbors(id int) []Host

	// NewInstance creates a new instance from the stored configuration
	NewInstance() (Epidemic, error)

	// GenotypeNodeMap returns the set of all GenotypeNodes seen since the
	// start of the simulation.
	GenotypeNodeMap() map[ksuid.KSUID]GenotypeNode

	// GenotypeSet returns the set of all Genotypes seen since the
	// start of the simulation.
	GenotypeSet() GenotypeSet

	// StopSimulation check whether the simulation has satisfied at least one
	// of the conditions that will halt the simulation in the current interation.
	StopSimulation() bool

	// SusceptibleProcess performs intrahost processes while the host is in
	// the susceptible status.
	SusceptibleProcess(i, t int, host Host, wg *sync.WaitGroup)
	// ExposedProcess performs intrahost processes while the host is in
	// the exposed status.
	ExposedProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)
	// InfectedProcess performs intrahost processes while the host is in
	// the infected status.
	InfectedProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)
	// InfectiveProcess performs intrahost processes while the host is in
	// the infective status.
	InfectiveProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)
	// RemovedProcess performs intrahost processes while the host is in
	// the removed status.
	RemovedProcess(i, t int, host Host, wg *sync.WaitGroup)
	// RecoveredProcess performs intrahost processes while the host is in
	// the recovered status.
	RecoveredProcess(i, t int, host Host, wg *sync.WaitGroup)
	// DeadProcess performs intrahost processes while the host is in
	// the dead status.
	DeadProcess(i, t int, host Host, wg *sync.WaitGroup)
	// DeadProcess performs intrahost processes while the host is in
	// the dead status.
	VaccinatedProcess(i, t int, host Host, wg *sync.WaitGroup)
}

Epidemic encapsulates the set of hosts, its connections, the pathogen tree lineage and the host types used to create a simulated epidemic.

type EpidemicSimulation

type EpidemicSimulation interface {
	Epidemic
	DataLogger

	// Run runs the whole simulation
	Initialize(params ...interface{})
	Run(i int)
	Update(t int)
	Process(t int)
	Transmit(t int)
	Finalize()

	// Metadata
	SetInstanceID(i int)
	InstanceID() int
	SetTime(t int)
	Time() int
	SetGenerations(n int)
	NumGenerations() int
	LogTransmission() bool
	LogFrequency() int
	SetStopped(b bool)
	Stopped() bool
}

EpidemicSimulation is a simulation environment that simulates the spread of disease between hosts in a connected host network.

type EvoEpiConfig

type EvoEpiConfig struct {
	SimParams          *epidemicSimConfig      `toml:"simulation"`
	LogParams          *logConfig              `toml:"logging"`
	IntrahostModels    []*intrahostModelConfig `toml:"intrahost_model"`
	FitnessModels      []*fitnessModelConfig   `toml:"fitness_model"`
	TransmissionModels []*transModelConfig     `toml:"transmission_model"`
	StopConditions     []*stopConditionConfig  `toml:"stop_condition"`
	// contains filtered or unexported fields
}

EvoEpiConfig contains parameters to create a simulated infection in a connected network of hosts.

func LoadEvoEpiConfig

func LoadEvoEpiConfig(path string) (*EvoEpiConfig, error)

LoadEvoEpiConfig creates an EvoEpiConfig struct from a TOML file.

func (*EvoEpiConfig) LogFreq

func (c *EvoEpiConfig) LogFreq() int

LogFreq returns the number of pathogen generations in the simulation until data is recorded.

func (*EvoEpiConfig) LogPath

func (c *EvoEpiConfig) LogPath() string

LogPath returns the path where to write results. This can a path to a folder, or directory_path/prefix format

func (*EvoEpiConfig) LogTransmission

func (c *EvoEpiConfig) LogTransmission() bool

LogTransmission indicates whether transmissions are logged or discarded.

func (*EvoEpiConfig) NewSimulation

func (c *EvoEpiConfig) NewSimulation() (Epidemic, error)

NewSimulation creates a new SingleHostSimulation simulation.

func (*EvoEpiConfig) NumGenerations

func (c *EvoEpiConfig) NumGenerations() int

NumGenerations returns the number of pathogen generation in a single simulation run.

func (*EvoEpiConfig) NumInstances

func (c *EvoEpiConfig) NumInstances() int

NumInstances returns the number of independent realizations to run.

func (*EvoEpiConfig) Validate

func (c *EvoEpiConfig) Validate() error

Validate checks the validity of the configuration.

type ExchangeEvent

type ExchangeEvent struct {
	// contains filtered or unexported fields
}

ExchangeEvent is a struct for sending and receiving exchange event information.

type ExchangeSimulation

type ExchangeSimulation struct {
	SISimulation
	// contains filtered or unexported fields
}

ExchangeSimulation creates and runs a modified version of the SIR epidemiological simulation. In ExchangeSimulation, all hosts are initially infected.

func NewExchangeSimulation

func NewExchangeSimulation(config Config, logger DataLogger) (*ExchangeSimulation, error)

NewExchangeSimulation creates a new migration simulation.

func (*ExchangeSimulation) Process

func (sim *ExchangeSimulation) Process(t int)

Process runs the internal evolution simulation in each host. During intrahost evolution, if new mutations appear, the new sequence and ancestry is recorded to file.

func (*ExchangeSimulation) Run

func (sim *ExchangeSimulation) Run(i int)

Run instantiates, runs, and records the a new simulation.

func (*ExchangeSimulation) Transmit

func (sim *ExchangeSimulation) Transmit(t int)

Transmit facilitates the sampling and migration process of pathogens between hosts.

func (*ExchangeSimulation) Update

func (sim *ExchangeSimulation) Update(t int)

Update looks at the timer or internal state to decide if the status of the host remains the same of will change. After the status updates, each host's status is recorded to file.

type FitnessDependentPopModel

type FitnessDependentPopModel struct {
	// contains filtered or unexported fields
}

FitnessDependentPopModel does not use a population model to determine the population of pathogens. Instead population size is dependent on fitness which is implemented outside of this model. The NextPathogenPopSize method for this model always returns -1 regardless of the input value.

func (*FitnessDependentPopModel) MaxPathogenPopSize

func (m *FitnessDependentPopModel) MaxPathogenPopSize() int

func (*FitnessDependentPopModel) ModelID

func (meta *FitnessDependentPopModel) ModelID() int

func (*FitnessDependentPopModel) ModelName

func (meta *FitnessDependentPopModel) ModelName() string

func (*FitnessDependentPopModel) MutationRate

func (params *FitnessDependentPopModel) MutationRate() float64

func (*FitnessDependentPopModel) NextPathogenPopSize

func (m *FitnessDependentPopModel) NextPathogenPopSize(n int) int

func (*FitnessDependentPopModel) ProbabilisticDuration

func (params *FitnessDependentPopModel) ProbabilisticDuration() bool

func (*FitnessDependentPopModel) RecombinationRate

func (params *FitnessDependentPopModel) RecombinationRate() float64

func (*FitnessDependentPopModel) ReplicationMethod

func (m *FitnessDependentPopModel) ReplicationMethod() string

func (*FitnessDependentPopModel) SetModelID

func (meta *FitnessDependentPopModel) SetModelID(id int)

func (*FitnessDependentPopModel) SetModelName

func (meta *FitnessDependentPopModel) SetModelName(name string)

func (*FitnessDependentPopModel) StatusDuration

func (params *FitnessDependentPopModel) StatusDuration(status int) int

func (*FitnessDependentPopModel) TransitionMatrix

func (params *FitnessDependentPopModel) TransitionMatrix() [][]float64

func (*FitnessDependentPopModel) TransitionProbs

func (params *FitnessDependentPopModel) TransitionProbs(char int) []float64

type FitnessMatrix

type FitnessMatrix interface {
	// ID returns the ID for this fitness model.
	ModelID() int
	// Name returns the name for this fitness model.
	ModelName() string
	SetModelID(id int)
	SetModelName(name string)
	// ComputeFitness returns the corresponding fitness value given
	// a set of sequences as integers.
	ComputeFitness(chars ...uint8) (fitness float64, err error)
	// SiteFitness returns the fitness value associated for a particular
	// character at the given site.
	SiteCharFitness(position int, state uint8) (fitness float64, err error)
	// Log tells whether the fitness values are decimal or log.
	// Usually fitness is in log.
	Log() bool
}

FitnessMatrix is a type of FitnessModel where the fitness of each individual character at every site is specified.

func NeutralAdditiveFM

func NeutralAdditiveFM(id int, name string, sites, alleles, growthRate int) (FitnessMatrix, error)

NeutralAdditiveFM returns a additive fitness matrix where the sum of all sites using any allele combination is equal to the growth rate.

func NeutralMultiplicativeFM

func NeutralMultiplicativeFM(id int, name string, sites, alleles int) (FitnessMatrix, error)

NeutralMultiplicativeFM returns a multiplicative fitness matrix where all the values are 0 (ln 1) such that all changes have no effect and are therefore neutral.

func NewAdditiveFM

func NewAdditiveFM(id int, name string, matrix map[int]map[uint8]float64) (FitnessMatrix, error)

NewAdditiveFM create a new additive fitness matrix using a map of maps. Assumes that the values are in decimal form.

func NewMultiplicativeFM

func NewMultiplicativeFM(id int, name string, matrix map[int]map[uint8]float64) (FitnessMatrix, error)

NewMultiplicativeFM create a new multiplicative fitness matrix using a map of maps. Assumes that the values are in log form.

type FitnessModel

type FitnessModel interface {
	// ID returns the ID for this fitness model.
	ModelID() int
	// Name returns the name for this fitness model.
	ModelName() string
	SetModelID(id int)
	SetModelName(name string)
	// ComputeFitness returns the corresponding fitness value given
	// a set of sequences as integers.
	ComputeFitness(chars ...uint8) (fitness float64, err error)
}

FitnessModel represents a general method to determine the fitness value associated to a particular genotype.

type Genotype

type Genotype interface {
	GenotypeUID() ksuid.KSUID
	// Sequence returns the sequence of the current node.
	Sequence() []uint8
	// SetSequence changes the sequence of genotype.
	SetSequence(sequence []uint8)
	// StringSequence returns the string representation of the
	// integer-coded sequence of the current node.
	StringSequence() string
	// Fitness returns the fitness value of this node based on its current
	// sequence and the given fitness model. If the fitness of the node has
	// been computed before using the same fitness model, then the value is
	// returned from memory and is not recomputed.
	Fitness(f FitnessModel) float64
	// NumSites returns the number of sites being modeled in this pathogen node.
	NumSites() int
	// StateCounts returns the number of sites by state.
	StateCounts() map[uint8]int
	// StatePositions returns the indexes of sites in a particular state.
	StatePositions(state uint8) []int
}

Genotype represents a unique pathogen sequence.

func NewGenotype

func NewGenotype(s []uint8) Genotype

NewGenotype creates a new genotype from sequence.

type GenotypeFreqPackage

type GenotypeFreqPackage struct {
	// contains filtered or unexported fields
}

GenotypeFreqPackage encapsulates the data to be written everytime the frequency of genotypes have to be recorded.

type GenotypeNode

type GenotypeNode interface {
	// UID returns the unique ID of the node. Uses KSUID to generate
	// random unique IDs with effectively no collision.
	UID() ksuid.KSUID
	GenotypeUID() ksuid.KSUID
	// Parents returns the parent of the node.
	Parents() []GenotypeNode
	// Children returns the children of the node.
	Children() []GenotypeNode
	// AddChild appends a child to the list of children.
	AddChild(child GenotypeNode)
	// Sequence returns the sequence of the current node.
	Sequence() []uint8
	// SetSequence changes the sequence of genotype.
	SetSequence(sequence []uint8)
	// StringSequence returns the string representation of the
	// integer-coded sequence of the current node.
	StringSequence() string
	// CurrentGenotype returns the current genotype of the current node.
	CurrentGenotype() Genotype
	// History returns the list of sequences that resulted into the extant
	// sequence.
	History(h [][]uint8) [][]uint8
	// Fitness returns the fitness value of this node based on its current
	// sequence and the given fitness model. If the fitness of the node has
	// been computed before using the same fitness model, then the value is
	// returned from memory and is not recomputed.
	Fitness(f FitnessModel) float64
	// NumSites returns the number of sites being modeled in this pathogen node.
	NumSites() int
	// StateCounts returns the number of sites by state.
	StateCounts() map[uint8]int
	// StatePositions returns the indexes of sites in a particular state.
	StatePositions(state uint8) []int
}

GenotypeNode represents a genotype together with its relationship to its parents and children.

type GenotypeSet

type GenotypeSet interface {
	// Add adds the genotype to the set if the sequence does not exist yet.
	Add(g Genotype)
	// AddSequence creates a new genotype from the sequence if it is not present
	// in the set. Otherwise, returns the existing genotype in the set.
	AddSequence(s []uint8) Genotype
	// Remove removes genotype of a particular sequence from the set.
	Remove(s []uint8)
	// Size returns the size of the set.
	Size() int
	Map() map[string]Genotype
}

GenotypeSet is a collection of genotypes.

func EmptyGenotypeSet

func EmptyGenotypeSet() GenotypeSet

EmptyGenotypeSet creates a new empty set.

type GenotypeTree

type GenotypeTree interface {
	// Set returns the GenotypeSet associated with this tree.
	Set() GenotypeSet
	// NewNode creates a new genotype node from a given sequence.
	// Automatically adds sequence to the genotypeSet if it is not yet present.
	NewNode(sequence []uint8, subs int, parents ...GenotypeNode) GenotypeNode
	NewRecombinantNode(sequence []uint8, recombs int, parents ...GenotypeNode) GenotypeNode
	// Nodes returns the map of genotype node ID found in the tree to its
	// corresponding genotype.
	NodeMap() map[ksuid.KSUID]GenotypeNode
}

GenotypeTree represents the genotypes as a series of differences from its ancestor.

func EmptyGenotypeTree

func EmptyGenotypeTree() GenotypeTree

EmptyGenotypeTree creates a new empty genotype tree.

type Host

type Host interface {
	// ID returns the unique ID of the host.
	ID() int
	// TypeID returns the ID representing the host's type in a multi-host
	// simulation. Generally, the host type ID is used to identify hosts
	// belonging to the same group that share the same properties.
	TypeID() int
	// PickPathogens returns a random list of pathogens from the
	// current host.
	// Returns nil if no pathogen exists.
	PickPathogens(n int) []GenotypeNode
	// Pathogens returns a list of all pathogens present in the host.
	// This elements of the list are pointers to GenotypeNodes.
	Pathogens() []GenotypeNode
	// PathogenPopSize returns the number of pathogens inside the host.
	PathogenPopSize() int
	// AddPathogens appends a pathogen to the pathogen space of the host.
	// Returns the new pathogen population size.
	AddPathogens(p ...GenotypeNode) int
	// RemoveAllPathogens removes all the pathogens from the host.
	// Internally, this removes all the pointers that refer to GenotypeNodes.
	RemoveAllPathogens()
	// SetIntrahostModel associates the current host to a given intrahost model.
	// The intrahost model governs intrahost processes by specifying the
	// mutation, replication, recombination, and infection modes and parameters
	// to be used.
	SetIntrahostModel(intrahostModel IntrahostModel) error
	// SetFitnessModel associates the current host to a given fitness model.
	SetFitnessModel(fitnessModel FitnessModel) error
	// SetTransmissionModel associates the current host to a given
	// transmission model. This model sets the transmission probability
	// (if not set in the adjacency matrix) and the transmission size.
	SetTransmissionModel(transmissionModel TransmissionModel) error
	// GetIntrahostModel retrieves the associated intrahost model
	// for the current host.
	GetIntrahostModel() IntrahostModel
	// GetFitnessModel retrieves the associated fitness model
	// for the current host.
	GetFitnessModel() FitnessModel
	// GetTransmissionModel retrieves the associated transmission model
	// for the current host.
	GetTransmissionModel() TransmissionModel
}

Host encapsulates pathogens together and ties its evolution to a particular set of parameters given by its assigned host type.

func EmptySequenceHost

func EmptySequenceHost(ids ...int) Host

EmptySequenceHost creates a new host without an intrahost model and no pathogens.

type HostNetwork

type HostNetwork interface {
	// ConnectedPopSize returns the total number of hosts in the network.
	ConnectedPopSize() int
	// GetNeighbors retrieves the unordered list of neighbors from
	// the adjacency matrix.
	GetNeighbors(ID int) (neighbors []int)
	// ConnectionExists checks if a connection a-b exists in the adjacency matrix.
	ConnectionExists(a, b int) bool
	// AddConnection adds a one way connection a-b to the adjacency matrix if
	// the connection a-b does not exists. Returns an error if given connection
	// already exists.
	AddConnection(a, b int) error
	// AddWeightedConnection adds a one way connection a-b to the adjacency
	// matrix with a given weight w.
	AddWeightedConnection(a, b int, w float64) error
	// UpdateConnectionWeight changes the weight value of an existing
	// connection. If the given connection does not exist, nothing is
	// updated.
	UpdateConnectionWeight(a, b int, w float64) error
	// UpsertConnectionWeight changes the weight value of an existing
	// connection or creates a new connection with the given weight if the
	// connection does not exist.
	UpsertConnectionWeight(a, b int, w float64)

	// AddWeightedBiConnection adds a two way reciprocal connection to the
	// adjacency matrix with a given weight.
	AddWeightedBiConnection(a, b int, w float64) error

	// DeleteConnection removes a one way connection a-b.
	DeleteConnection(a, b int) error

	// Copy returns a new copy of the adjacency matrix.
	// Changes made to the original copy will not affect the new copy
	// and changes made to the copy will likewise not affect the original.
	Copy() adjacencyMatrix

	// Dump serialized the adjacency matrix into a string stored as a byteslice.
	Dump() []byte

	// Connection returns the weight of a connection is it exists,
	// returns 0 otherwise.
	Connection(a, b int) float64
}

HostNetwork interface describes a host population connected together as a network.

func EmptyAdjacencyMatrix

func EmptyAdjacencyMatrix() HostNetwork

EmptyAdjacencyMatrix creates a new 2D mapping with no contents.

func LoadAdjacencyMatrix

func LoadAdjacencyMatrix(path string) (HostNetwork, error)

LoadAdjacencyMatrix creates a new 2D mapping based on a text file.

type Infection

type Infection interface {
	// Host returns the selected host in the simulation.
	Host() Host

	// HostStatus retrieves the current status of the selected host.
	HostStatus() int
	// SetHostStatus sets the current status of the selected host
	// to a given status code.
	SetHostStatus(status int)
	// HostStatusDuration returns the number of generations a host
	// remains in a given status.
	HostStatusDuration(status int) int
	// HostTime returns the current number of generations remaining
	// before the host changes status.
	HostTimer() int
	// SetHostTimer sets the number of generations for the host to
	// remain in its current status.
	SetHostTimer(interval int)

	// SusceptibleProcess performs intrahost processes while the host is in
	// the susceptible status.
	SusceptibleProcess(i, t int, host Host, wg *sync.WaitGroup)
	// ExposedProcess performs intrahost processes while the host is in
	// the exposed status.
	ExposedProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)
	// InfectedProcess performs intrahost processes while the host is in
	// the infected status.
	InfectedProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)
	// InfectiveProcess performs intrahost processes while the host is in
	// the infective status.
	InfectiveProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)
	// RemovedProcess performs intrahost processes while the host is in
	// the removed status.
	RemovedProcess(i, t int, host Host, wg *sync.WaitGroup)
	// RecoveredProcess performs intrahost processes while the host is in
	// the recovered status.
	RecoveredProcess(i, t int, host Host, wg *sync.WaitGroup)
	// DeadProcess performs intrahost processes while the host is in
	// the dead status.
	DeadProcess(i, t int, host Host, wg *sync.WaitGroup)
	// DeadProcess performs intrahost processes while the host is in
	// the dead status.
	VaccinatedProcess(i, t int, host Host, wg *sync.WaitGroup)
}

Infection encapsulates a single host and the pathogen tree lineage to trace the evolution of pathogens within one host. This is useful to strudy intrahost evolutionary dynamics especially in chronic diseases.

type InfectionSimulation

type InfectionSimulation interface {
	Infection
	// Run runs the whole simulation
	Init(params ...interface{})
	Run(i int)
	Update(t int)
	Process(t int)
	Transmit(t int)
}

InfectionSimulation is a simulation environment that simulates the infection within a single hosts or in an evironment where a network configuration is not necessary.

type IntrahostModel

type IntrahostModel interface {
	ModelID() int
	ModelName() string
	SetModelID(id int)
	SetModelName(name string)

	// MutationRate returns the mutation rate for this model.
	MutationRate() float64
	// TransitionMatrix returns the conditioned mutation rate matrix
	// for this model.
	TransitionMatrix() [][]float64
	// TransitionProbs returns the conditioned transition probabilities
	// for the given state.
	TransitionProbs(char int) []float64

	// MaxPathogenPopSize returns the maximum number of pathogens allowed within
	// a single host of this particular host type.
	MaxPathogenPopSize() int
	// NextPathogenPopSize returns the pathogen population size for the next
	// generation of pathogens given the current population size.
	// This is used in conjunction with a population model under
	// relative fitness.
	NextPathogenPopSize(n int) int
	// ReplicationMethod returns whether relative, or absolute is used.
	ReplicationMethod() string

	// RecombinationRate returns the recombination rate for this model.
	RecombinationRate() float64

	// StatusDuration
	StatusDuration(status int) int
	ProbabilisticDuration() bool
}

IntrahostModel is an interface for any type of intrahost model.

type MotifModel

type MotifModel interface {
	// ID returns the ID for this fitness model.
	ModelID() int
	// Name returns the name for this fitness model.
	ModelName() string
	SetModelID(id int)
	SetModelName(name string)
	// ComputeFitness returns the corresponding fitness value given
	// a set of sequences as integers.
	ComputeFitness(chars ...uint8) (fitness float64, err error)

	AddMotif(sequence []uint8, pos []int, value float64) error
}

MotifModel is a type of FitnessModel where the fitness of a sequence depends on the presence of the particular motifs.

func EmptyMotifModel

func EmptyMotifModel(id int, name string) MotifModel

EmptyMotifModel returns a new motif model without any registered motifs.

type MutationPackage

type MutationPackage struct {
	// contains filtered or unexported fields
}

MutationPackage encapsulates information to be written to track when and where mutations occur in the simulation.

type SIRSimulation

type SIRSimulation struct {
	EpidemicSimulation
}

SIRSimulation creates and runs an SIR epidemiological simulation. Within this simulation, hosts may or may not run independent genetic evolution simulations.

func NewSIRSimulation

func NewSIRSimulation(config Config, logger DataLogger) (*SIRSimulation, error)

NewSIRSimulation creates a new SI simulation.

func (*SIRSimulation) Process

func (sim *SIRSimulation) Process(t int)

Process runs the internal evolution simulation in each host. During intrahost evolution, if new mutations appear, the new sequence and ancestry is recorded to file.

func (*SIRSimulation) Run

func (sim *SIRSimulation) Run(i int)

Run instantiates, runs, and records the a new simulation.

func (*SIRSimulation) Update

func (sim *SIRSimulation) Update(t int)

Update looks at the timer or internal state to decide if the status of the host remains the same of will change. After the status updates, each host's status is recorded to file.

type SISSimulation

type SISSimulation struct {
	EpidemicSimulation
}

SISSimulation creates and runs an SIR epidemiological simulation. Within this simulation, hosts may or may not run independent genetic evolution simulations.

func NewSISSimulation

func NewSISSimulation(config Config, logger DataLogger) (*SISSimulation, error)

NewSISSimulation creates a new SIS simulation.

func (*SISSimulation) Process

func (sim *SISSimulation) Process(t int)

Process runs the internal evolution simulation in each host. During intrahost evolution, if new mutations appear, the new sequence and ancestry is recorded to file.

func (*SISSimulation) Run

func (sim *SISSimulation) Run(i int)

Run instantiates, runs, and records the a new simulation.

func (*SISSimulation) Update

func (sim *SISSimulation) Update(t int)

Update looks at the timer or internal state to decide if the status of the host remains the same of will change. After the status updates, each host's status is recorded to file.

type SISimulation

type SISimulation struct {
	Epidemic
	DataLogger
	// contains filtered or unexported fields
}

SISimulation creates and runs an SI epidemiological simulation. Within this simulation, hosts may or may not run independent genetic evolution simulations.

func NewSISimulation

func NewSISimulation(config Config, logger DataLogger) (*SISimulation, error)

NewSISimulation creates a new SI simulation.

func (*SISimulation) Finalize

func (sim *SISimulation) Finalize()

Finalize performs processes to finish and close the simulation.

func (*SISimulation) Initialize

func (sim *SISimulation) Initialize(params ...interface{})

Initialize initializes the simulation and accepts 0 or more parameters. For example, creating datbases etc.

func (*SISimulation) InstanceID

func (sim *SISimulation) InstanceID() int

InstanceID returns the ID of the current realized simulation.

func (*SISimulation) LogFrequency

func (sim *SISimulation) LogFrequency() int

LogFrequency returns the interval in number of pathogen generation between data recordings.

func (*SISimulation) LogTransmission

func (sim *SISimulation) LogTransmission() bool

LogTransmission returns true is transmission events are saved to disk. If false, transmssion events occur but are not recorded.

func (*SISimulation) NumGenerations

func (sim *SISimulation) NumGenerations() int

NumGenerations returns the total number of pathogen generations the simulation will simulate. This is equivalent to the total number of iterations of the simulation.

func (*SISimulation) Process

func (sim *SISimulation) Process(t int)

Process runs the internal evolution simulation in each host. During intrahost evolution, if new mutations appear, the new sequence and ancestry is recorded to file.

func (*SISimulation) Run

func (sim *SISimulation) Run(i int)

Run instantiates, runs, and records the a new simulation.

func (*SISimulation) SetGenerations

func (sim *SISimulation) SetGenerations(n int)

SetGenerations sets the total number of pathogen generations the simulation will simulate. This is equivalent to the total number of iterations of the simulation.

func (*SISimulation) SetInstanceID

func (sim *SISimulation) SetInstanceID(i int)

SetInstanceID sets the instance ID of the current realized simulation.

func (*SISimulation) SetStopped

func (sim *SISimulation) SetStopped(b bool)

SetStopped sets the internal status of the current simulation. If set to true, this indicates that the simulation has stopped. If set to false, the current simulation has not yet stopped. By default, the value of internal status is false.

func (*SISimulation) SetTime

func (sim *SISimulation) SetTime(t int)

SetTime sets the current internal time of the simulation. The simulation's internal time is based on the number of iterations that has taken place. This is equivalent to the number of pathogen generations.

func (*SISimulation) Stopped

func (sim *SISimulation) Stopped() bool

Stopped returns true if the current simulation has stopped. If it returns false, the current simulation has not yet stopped

func (*SISimulation) Time

func (sim *SISimulation) Time() int

Time returns the current internal time of the simulation. The simulation's internal time should be the number of iterations that has taken place. This is equivalent to the number of pathogen generations.

func (*SISimulation) Transmit

func (sim *SISimulation) Transmit(t int)

Transmit facilitates the sampling and migration process of pathogens between hosts.

func (*SISimulation) Update

func (sim *SISimulation) Update(t int)

Update looks at the timer or internal state to decide if the status of the host remains the same of will change. After the status updates, each host's status is recorded to file.

type SQLiteLogger

type SQLiteLogger struct {
	// contains filtered or unexported fields
}

SQLiteLogger is a DataLogger that writes simulation data t0 SQLite databases. Each writer function writes to an independent SQLite database and foreign keys are added to each database at the closing phase after the simulation is completed.

func NewSQLiteLogger

func NewSQLiteLogger(basepath string, i int) *SQLiteLogger

NewSQLiteLogger creates a new logger that writes to a SQLite database.

func (*SQLiteLogger) Init

func (l *SQLiteLogger) Init() error

Init creates a new tables in the database. For example, each new realization of the simulation creates a new table for transmissions, frequencies, statuses, nodes and genotypes.

func (*SQLiteLogger) SetBasePath

func (l *SQLiteLogger) SetBasePath(basepath string, i int)

SetBasePath sets the base path of the logger.

func (*SQLiteLogger) WriteGenotypeFreq

func (l *SQLiteLogger) WriteGenotypeFreq(c <-chan GenotypeFreqPackage)

WriteGenotypeFreq records the count of unique genotype nodes present within the host in a given time in the simulation.

func (*SQLiteLogger) WriteGenotypeNodes

func (l *SQLiteLogger) WriteGenotypeNodes(c <-chan GenotypeNode)

WriteGenotypeNodes records new genotype node's ID and associated genotype ID to file

func (*SQLiteLogger) WriteGenotypes

func (l *SQLiteLogger) WriteGenotypes(c <-chan Genotype)

WriteGenotypes records a new genotype's ID and sequence to file.

func (*SQLiteLogger) WriteMutations

func (l *SQLiteLogger) WriteMutations(c <-chan MutationPackage)

WriteMutations records every time a new genotype node is created. It records the time and in what host this new mutation arose.

func (*SQLiteLogger) WriteStatus

func (l *SQLiteLogger) WriteStatus(c <-chan StatusPackage)

WriteStatus records the status of each host every generation.

func (*SQLiteLogger) WriteTransmission

func (l *SQLiteLogger) WriteTransmission(c <-chan TransmissionPackage)

WriteTransmission records the ID's of genotype node that are transmitted between hosts.

type SequenceNodeEpidemic

type SequenceNodeEpidemic struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SequenceNodeEpidemic is a type of Epidemic that uses a SequenceNode to represent pathogens.

func (*SequenceNodeEpidemic) DeadProcess

func (sim *SequenceNodeEpidemic) DeadProcess(i, t int, host Host, wg *sync.WaitGroup)

DeadProcess executes within-host processes that occurs when a host is in the dead state state that is perpetually uninfectable. This state is identically to Removed but is used to distinguish from a recovered, but perpetually immune state.

func (*SequenceNodeEpidemic) ExposedProcess

func (sim *SequenceNodeEpidemic) ExposedProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)

ExposedProcess executes within-host processes that occurs when a host is in the exposed state. By default, it is same as InfectedProcess.

func (*SequenceNodeEpidemic) GenotypeNodeMap

func (sim *SequenceNodeEpidemic) GenotypeNodeMap() map[ksuid.KSUID]GenotypeNode

GenotypeNodeMap returns the set of all GenotypeNodes seen since the start of the simulation.

func (*SequenceNodeEpidemic) GenotypeSet

func (sim *SequenceNodeEpidemic) GenotypeSet() GenotypeSet

GenotypeSet returns the set of all Genotypes seen since the start of the simulation.

func (*SequenceNodeEpidemic) Host

func (sim *SequenceNodeEpidemic) Host(id int) Host

Host returns the selected host in the simulation.

func (*SequenceNodeEpidemic) HostConnection

func (sim *SequenceNodeEpidemic) HostConnection(a, b int) float64

HostConnection returns the weight of a connection between two hosts if it exists, returns 0 otherwise.

func (*SequenceNodeEpidemic) HostMap

func (sim *SequenceNodeEpidemic) HostMap() map[int]Host

HostMap returns the hosts in the simulation in the form of a map. The key is the host's ID and the value is the pointer to the host.

func (*SequenceNodeEpidemic) HostNeighbors

func (sim *SequenceNodeEpidemic) HostNeighbors(id int) []Host

HostNeighbors retrieves the directly connected hosts to the current host based on the supplied adjacency matrix.

func (*SequenceNodeEpidemic) HostStatus

func (sim *SequenceNodeEpidemic) HostStatus(id int) int

HostStatus retrieves the current status of the selected host.

func (*SequenceNodeEpidemic) HostTimer

func (sim *SequenceNodeEpidemic) HostTimer(id int) int

HostTimer returns the current number of generations remaining before the host changes status.

func (*SequenceNodeEpidemic) InfectableStatuses

func (sim *SequenceNodeEpidemic) InfectableStatuses() []int

InfectableStatuses returns the list of statuses that infected hosts can transmit to.

func (*SequenceNodeEpidemic) InfectedProcess

func (sim *SequenceNodeEpidemic) InfectedProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)

InfectedProcess executes within-host processes that occurs when a host is in the infected state.

func (*SequenceNodeEpidemic) InfectiveProcess

func (sim *SequenceNodeEpidemic) InfectiveProcess(i, t int, host Host, c chan<- MutationPackage, wg *sync.WaitGroup)

InfectiveProcess executes within-host processes that occurs when a host is in the infective state. By default, it is same as InfectedProcess.

func (*SequenceNodeEpidemic) NewInstance

func (sim *SequenceNodeEpidemic) NewInstance() (Epidemic, error)

NewInstance creates a new instance from the stored configuration

func (*SequenceNodeEpidemic) RecoveredProcess

func (sim *SequenceNodeEpidemic) RecoveredProcess(i, t int, host Host, wg *sync.WaitGroup)

RecoveredProcess executes within-host processes that occurs when a host is in the recovered state that is perpetually uninfectable. This state is identically to Removed but is used to distinguish from a dead state.

func (*SequenceNodeEpidemic) RemovedProcess

func (sim *SequenceNodeEpidemic) RemovedProcess(i, t int, host Host, wg *sync.WaitGroup)

RemovedProcess executes within-host processes that occurs when a host is in the removed state that is perpetually uninfectable.

func (*SequenceNodeEpidemic) SetHostStatus

func (sim *SequenceNodeEpidemic) SetHostStatus(id, status int)

SetHostStatus sets the current status of the selected host to a given status code.

func (*SequenceNodeEpidemic) SetHostTimer

func (sim *SequenceNodeEpidemic) SetHostTimer(id, interval int)

SetHostTimer sets the number of generations for the host to remain in its current status.

func (*SequenceNodeEpidemic) StopSimulation

func (sim *SequenceNodeEpidemic) StopSimulation() bool

StopSimulation check whether the simulation has satisfied at least one of the conditions that will halt the simulation in the current interation. Returns true is the simulation should stop, false otherwise.

func (*SequenceNodeEpidemic) SusceptibleProcess

func (sim *SequenceNodeEpidemic) SusceptibleProcess(i, t int, host Host, wg *sync.WaitGroup)

SusceptibleProcess executes within-host processes that occurs when a host is in the susceptible state.

func (*SequenceNodeEpidemic) VaccinatedProcess

func (sim *SequenceNodeEpidemic) VaccinatedProcess(i, t int, host Host, wg *sync.WaitGroup)

VaccinatedProcess executes within-host processes that occurs when a host is in a globally immune state with the chance to become globally susceptible again.

type StatusPackage

type StatusPackage struct {
	// contains filtered or unexported fields
}

StatusPackage encapsulates the data to be written everytime the status of a host has to be recorded.

type StopCondition

type StopCondition interface {
	Reason() string
	Check(sim Epidemic) bool
}

StopCondition describes simulation conditions that must be satisfied in order for the simulation to continue. The Check method checks if the simulation still satisfies the imposed condition.

func NewAlleleExistsCondition

func NewAlleleExistsCondition(char uint8, site int) StopCondition

NewAlleleExistsCondition creates a new StopCondition that stops the simulation once the given char at a particular site becomes extinct.

func NewAlleleFixedLostCondition

func NewAlleleFixedLostCondition(char uint8, site int) StopCondition

NewAlleleFixedLostCondition creates a new StopCondition that stops the simulation once the particular allele in a given site has either been fixed or been lost.

func NewGenotypeExistsCondition

func NewGenotypeExistsCondition(sequence []uint8) StopCondition

NewGenotypeExistsCondition creates a new StopCondition that stops the simulation once the given sequence genotype becomes extinct.

type TransmissionEvent

type TransmissionEvent struct {
	// contains filtered or unexported fields
}

TransmissionEvent is a struct for sending and receiving transmission event information.

type TransmissionModel

type TransmissionModel interface {
	// ID returns the ID for this transmission model.
	ModelID() int
	// Name returns the name for this transmission model.
	ModelName() string
	SetModelID(id int)
	SetModelName(name string)
	// TransmissionProb returns the probability that a transmission event
	// occurs between one host and one neighbor (per capita event) occurs.
	TransmissionProb() float64

	// TransmissionSize returns the number of pathogens transmitted given
	// a transmission event occurs.
	TransmissionSize() int
}

TransmissionModel describes the transmission probability and number of pathogens that transmits per event. The model may be constant or probabilistic.

type TransmissionPackage

type TransmissionPackage struct {
	// contains filtered or unexported fields
}

TransmissionPackage encapsulates information to be written to track the movement of genotype nodes across the host population.

Directories

Path Synopsis
bin

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL