| Title: | Multi-SNP Haplotype Frequency Estimation |
|---|---|
| Description: | A method for multi-SNP haplotype frequency estimation. |
| Authors: | Aimee Taylor [aut, cre] |
| Maintainer: | Aimee Taylor <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-05 07:26:16 UTC |
| Source: | https://github.com/aimeertaylor/FreqEstimationModel |
Function to calculate the genotype counts that can be removed without rendering the ensuing likelihood equal to zero
calculate_genotype_counts_truncated( genotype_counts, comp_genotypes, raw_data, moi_prior_min2 )calculate_genotype_counts_truncated( genotype_counts, comp_genotypes, raw_data, moi_prior_min2 )
Function to calculate the log genotype counts proposal ratio
calculate_log_genotype_counts_proposal_ratio( moi_diff, genotype_counts_diff, neg_log_sum_frequency_truncated, mh_genotype_counts_truncated, y_character, log_target_ratio, datasampleID, no_total )calculate_log_genotype_counts_proposal_ratio( moi_diff, genotype_counts_diff, neg_log_sum_frequency_truncated, mh_genotype_counts_truncated, y_character, log_target_ratio, datasampleID, no_total )
Function to calculate the log MOI proposal ratio
calculate_log_moi_proposal_ratio( moi_max, moi_current, moi_proposed, moi_current_equal_moi_min, moi_proposed_equal_moi_min, datasampleID, no_total )calculate_log_moi_proposal_ratio( moi_max, moi_current, moi_proposed, moi_current_equal_moi_min, moi_proposed_equal_moi_min, datasampleID, no_total )
Function to ascertain the genotypes that are compatible with a given observation
compatible_genotypes(observation, as_numeric = TRUE)compatible_genotypes(observation, as_numeric = TRUE)
observation |
A vector of allelic calls for a given individual, with one call per loci. Heteroallelic loci can either be encoded as 0.5. Alternatively, all alleles detected at heteroallelic loci can be listed. See examples below. |
# Example where heteroallelic loci are encoded as 0.5 y <- c(0, 1, 0.5, 0.5) compatible_genotypes(y) compatible_genotypes(y, FALSE) # Example where all alleles detected at heteroallelic loci are listed y <- list(0, 1, c(0,1), c(0,1,2)) compatible_genotypes(y) compatible_genotypes(y, FALSE)# Example where heteroallelic loci are encoded as 0.5 y <- c(0, 1, 0.5, 0.5) compatible_genotypes(y) compatible_genotypes(y, FALSE) # Example where all alleles detected at heteroallelic loci are listed y <- list(0, 1, c(0,1), c(0,1,2)) compatible_genotypes(y) compatible_genotypes(y, FALSE)
Data and genotype compatibility check function
data_genotype_count_compatibility(comp_genotypes, genotype_counts, raw_data)data_genotype_count_compatibility(comp_genotypes, genotype_counts, raw_data)
Calculate the density of the dirichlet distribution. This function is exactly the same as that from MCMCpack, copied to minimise dependencies.
ddirichlet(x, alpha)ddirichlet(x, alpha)
Function for drawing frequency proposed per child
draw_frequency_proposed_child(Alpha, genotype_counts_current)draw_frequency_proposed_child(Alpha, genotype_counts_current)
Function for drawing initial genotype counts.
draw_genotype_counts_initial( moi_current, processed_data_list, frequency_current )draw_genotype_counts_initial( moi_current, processed_data_list, frequency_current )
Function for drawing initial MOIs.
draw_moi_initial(moi_list, datasampleID, y_no_mxed, y_mxed)draw_moi_initial(moi_list, datasampleID, y_no_mxed, y_mxed)
datasampleID |
is a vector of sample IDs; that is, a character vector such as |
y_no_mxed |
is a vector comprising a subset of |
y_mxed |
is a vector comprising a subset of |
moi_list$moi_prior |
is a character, either |
moi_list$moi_max |
is an integer defining the maximum moi possible in the model |
moi_list$moi_hyperparameter |
is a parameter of the prior distribution |
moi_list$moi_size_hyperparameter |
is a parameter of the prior distribution |
Function for drawing new MOI vector. Note that there is no option to stay still, and that Proposal density does not have equal probability over state space [m_min,..,m_max] and is not symmetric: Pr(m*|m)=Pr(m|m*)
draw_moi_proposed(moi_current, moi_current_equal_moi_min, moi_max)draw_moi_proposed(moi_current, moi_current_equal_moi_min, moi_max)
Calculate log likelihood of NGS data
log_likelihood_NGS(processed_data_list, genotype_counts)log_likelihood_NGS(processed_data_list, genotype_counts)
Calculate log likelihood of prevalence data
log_likelihood_prevalence(processed_data_list, genotype_counts)log_likelihood_prevalence(processed_data_list, genotype_counts)
Log moi prior calculation
log_moi_prior_calculation_geom(moi_store, moi_list, y_no_mxed, y_mxed)log_moi_prior_calculation_geom(moi_store, moi_list, y_no_mxed, y_mxed)
Log moi prior calculation
log_moi_prior_calculation_nbinom(moi_store, moi_list, y_no_mxed, y_mxed)log_moi_prior_calculation_nbinom(moi_store, moi_list, y_no_mxed, y_mxed)
Log moi prior calculation
log_moi_prior_calculation_pois(moi_store, moi_list, y_no_mxed, y_mxed)log_moi_prior_calculation_pois(moi_store, moi_list, y_no_mxed, y_mxed)
Log moi prior calculation
log_moi_prior_calculation_unif(moi_store, moi_list, y_no_mxed, y_mxed)log_moi_prior_calculation_unif(moi_store, moi_list, y_no_mxed, y_mxed)
Function to calculate the log of the prior MOI ratio when the MOI prior distribution is geometric. Note that the normalising constants due to truncation cancel.
log_prior_moi_ratio_geom( moi_proposed, moi_current, moi_hyperparameter, moi_size_hyperparameter )log_prior_moi_ratio_geom( moi_proposed, moi_current, moi_hyperparameter, moi_size_hyperparameter )
Function to calculate the log of the prior MOI ratio when the MOI prior distribution is negative binomial. Note that the normalising constants due to truncation cancel.
log_prior_moi_ratio_nbinom( moi_proposed, moi_current, moi_hyperparameter, moi_size_hyperparameter )log_prior_moi_ratio_nbinom( moi_proposed, moi_current, moi_hyperparameter, moi_size_hyperparameter )
Function to calculate the log of the prior MOI ratio when the MOI prior distribution is poisson. Note that the normalising constants due to truncation cancel.
log_prior_moi_ratio_pois( moi_proposed, moi_current, moi_hyperparameter, moi_size_hyperparameter )log_prior_moi_ratio_pois( moi_proposed, moi_current, moi_hyperparameter, moi_size_hyperparameter )
Function to calculate the log of the prior MOI ratio when the MOI prior distribution is a discrete uniform distribution. Note that the normalising constants due to truncation cancel.
log_prior_moi_ratio_unif( moi_proposed, moi_current, moi_hyperparameter, moi_size_hyperparameter )log_prior_moi_ratio_unif( moi_proposed, moi_current, moi_hyperparameter, moi_size_hyperparameter )
Function to implement mcmc sampler, which is embedded within data preprocessing and retrospective posterior calculations
mcmc_sampling( processed_data_list, moi_list, frequency_list, mcmc_variable_list )mcmc_sampling( processed_data_list, moi_list, frequency_list, mcmc_variable_list )
Function to implement mcmc sampler chains in parallel, followed retrospective posterior calculations
mcmc_sampling_parallel( processed_data_list, moi_list, frequency_list, mcmc_variable_list, cores_max, seed = 1234352 )mcmc_sampling_parallel( processed_data_list, moi_list, frequency_list, mcmc_variable_list, cores_max, seed = 1234352 )
processed_data_list |
List of processed data |
moi_list |
List of MOI settings |
frequency_list |
List of frequency settings |
mcmc_variable_list |
List of MCMC settings |
cores_max |
Maximum number of cores to register with doMC |
seed |
Integer seed for the per-chain RNG streams built by RNGseq(). |
Function to calculate the density of multiple realisations of the multinomial distribution simultaneously given either a single probability or a matrix of probability
my_log_dmultinom(x, prob, pop_fequency)my_log_dmultinom(x, prob, pop_fequency)
Function to preprocess data
preprocess_data( data_summary, log_like_zero, NGS, augment_missing_data, moi_prior_min2 )preprocess_data( data_summary, log_like_zero, NGS, augment_missing_data, moi_prior_min2 )
Returns an R list containing the character vector
c("foo", "bar") and the numeric vector c(0, 1).
rcpp_hello()rcpp_hello()
rcpp_hello()rcpp_hello()
Same as the rdirichlet function in MCMCpack but rewritten to minimise dependencies.
rdirichlet(n, alpha)rdirichlet(n, alpha)
Need to add log option
Function to update genotype counts conditional on current genotype counts and new multiplicity of infection (MOI)
update_genotype_counts( moi_diff, genotype_counts_current, current_genotype_counts_truncated, processed_data_list )update_genotype_counts( moi_diff, genotype_counts_current, current_genotype_counts_truncated, processed_data_list )
Function for addition of clone to a mixed data sample
update_y_mixed_add(to_update, genotype_counts_mixed_add, frequency_truncated)update_y_mixed_add(to_update, genotype_counts_mixed_add, frequency_truncated)
Function for removal of clone from mixed data sample
update_y_mixed_sub( to_update, genotype_counts_mixed_sub, genotype_counts_truncated )update_y_mixed_sub( to_update, genotype_counts_mixed_sub, genotype_counts_truncated )