Beispiel #1
0
    def build_ctmc_system(self, isolation_time, migration_time, coal_rate,
                          recomb_rate, mig_rate):
        """Construct CTMCs and compute HMM matrices given the split times
        and the rates."""

        # We assume here that the coalescence rate is the same in the two
        # separate populations as it is in the ancestral. This is not necessarily
        # true but it worked okay in simulations in Mailund et al. (2012).

        isolation_rates = make_rates_table_isolation(coal_rate, coal_rate,
                                                     recomb_rate)
        isolation_ctmc = make_ctmc(self.isolation_state_space, isolation_rates)

        migration_rates = make_rates_table_migration(coal_rate, coal_rate,
                                                     recomb_rate, mig_rate,
                                                     mig_rate)
        migration_ctmc = make_ctmc(self.migration_state_space, migration_rates)

        single_rates = make_rates_table_single(coal_rate, recomb_rate)
        single_ctmc = make_ctmc(self.single_state_space, single_rates)

        tau1 = isolation_time
        tau2 = isolation_time + migration_time
        migration_break_points = uniform_break_points(self.no_mig_states, tau1,
                                                      tau2)
        ancestral_break_points = exp_break_points(self.no_ancestral_states,
                                                  coal_rate, tau2)

        return IsolationMigrationCTMCSystem(isolation_ctmc, migration_ctmc,
                                            single_ctmc,
                                            migration_break_points,
                                            ancestral_break_points)
Beispiel #2
0
    def build_ctmc_system(self, *parameters):
        """Construct CTMCs and compute HMM matrices given the split times
        and the rates."""

        isolation_time, migration_time, recomb_rate = parameters[:3]
        coal_rates = parameters[3:2 * self.no_epochs + 1 + 3]
        mig_rates = parameters[2 * self.no_epochs + 1 + 3:]

        assert len(
            coal_rates
        ) == self.no_epochs * 2 + 1, "Isolation + #Epochs migration + #Epochs ancestral"
        assert len(mig_rates) == self.no_epochs, "#Epochs migration epochs"

        isolation_rates = make_rates_table_isolation(coal_rates[0],
                                                     coal_rates[0],
                                                     recomb_rate)
        isolation_ctmc = make_ctmc(self.isolation_state_space, isolation_rates)

        migration_ctmcs = []
        ancestral_ctmcs = []

        for epoch in xrange(self.no_epochs):
            migration_rates = make_rates_table_migration(
                coal_rates[epoch + 1], coal_rates[epoch + 1], recomb_rate,
                mig_rates[epoch], mig_rates[epoch])
            migration_ctmc = make_ctmc(self.migration_state_space,
                                       migration_rates)

            # Repeat of the same CTMC throughout the epoch. Change here if different number of states per epoch
            for _ in xrange(self.no_mig_states):
                migration_ctmcs.append(migration_ctmc)

        for epoch in xrange(self.no_epochs):
            ancestral_rates = make_rates_table_single(
                coal_rates[epoch + self.no_epochs + 1], recomb_rate)
            ancestral_ctmc = make_ctmc(self.single_state_space,
                                       ancestral_rates)

            # Repeat of the same CTMC throughout the epoch. Change here if different number of states per epoch
            for _ in xrange(self.no_ancestral_states):
                ancestral_ctmcs.append(ancestral_ctmc)

        tau1 = isolation_time
        tau2 = isolation_time + migration_time
        migration_break_points = uniform_break_points(
            self.no_epochs * self.no_mig_states, tau1, tau2)

        # FIXME: This should take into account that the coal rate varies between epochs...
        coal_rate = mean(coal_rates[self.no_epochs + 1:])
        ancestral_break_points = exp_break_points(
            self.no_epochs * self.no_ancestral_states, coal_rate, tau2)

        return IsolationMigrationEpochsCTMCSystem(isolation_ctmc,
                                                  migration_ctmcs,
                                                  ancestral_ctmcs,
                                                  migration_break_points,
                                                  ancestral_break_points)
Beispiel #3
0
    def build_ctmc_system(self, tau1, tau2, coal1, coal2, coal3, coal12, coal123, recombination_rate):
        """Construct CTMC system."""
        epoch_1_ctmc = make_ctmc(Isolation3(), make_rates_table_3(coal1, coal2, coal3, recombination_rate))
        epoch_2_ctmc = make_ctmc(Isolation2(), make_rates_table_2(coal12, coal3, recombination_rate))
        epoch_3_ctmc = make_ctmc(Isolation1(), make_rates_table_1(coal123, recombination_rate))

        self.break_points_12 = trunc_exp_break_points(self.no_12_intervals, coal12, tau1 + tau2, tau1)
        self.break_points_123 = exp_break_points(self.no_123_intervals, coal123, tau1 + tau2)

        return ILSCTMCSystem(self, epoch_1_ctmc, epoch_2_ctmc, epoch_3_ctmc, self.break_points_12, self.break_points_123)
Beispiel #4
0
 def emission_points(self, isolation_time, migration_time, coal_rate,
                     recomb_rate, mig_rate):
     """Compute model specific coalescence points."""
     tau1 = isolation_time
     tau2 = isolation_time + migration_time
     migration_break_points = uniform_break_points(self.no_mig_states, tau1,
                                                   tau2)
     ancestral_break_points = exp_break_points(self.no_ancestral_states,
                                               coal_rate, tau2)
     break_points = list(migration_break_points) + list(
         ancestral_break_points)
     return coalescence_points(break_points, coal_rate)
Beispiel #5
0
    def emission_points(self, *parameters):
        """Compute model specific coalescence points."""

        isolation_time, migration_time, recomb_rate = parameters[:3]
        coal_rates = parameters[3:2 * self.no_epochs + 1 + 3]

        tau1 = isolation_time
        tau2 = isolation_time + migration_time

        migration_break_points = uniform_break_points(
            self.no_epochs * self.no_mig_states, tau1, tau2)

        # FIXME: This should really take into account that the coal rate varies between epochs...
        coal_rate = mean(coal_rates)
        ancestral_break_points = exp_break_points(
            self.no_epochs * self.no_ancestral_states, coal_rate, tau2)

        break_points = list(migration_break_points) + list(
            ancestral_break_points)
        return coalescence_points(break_points, coal_rate)
Beispiel #6
0
 def get_ancestral_break_points(self, tau_1, tau_2, coal_a):
     return exp_break_points(self.no_ancestral_states, coal_a,
                             tau_1 + tau_2)