11# ' Computes allele frequencies for specified populations given SNP array data
22# '
3- # ' @param geno matrix of genotypes coded as the dosage of allele B { 0, 1, 2, ..., ploidy}
3+ # ' @param geno matrix of genotypes coded as the dosage of allele B \code{{ 0, 1, 2, ..., ploidy} }
44# ' with individuals in rows (named) and SNPs in columns (named)
55# ' @param populations list of named populations. Each population has a vector of IDs
66# ' that belong to the population. Allele frequencies will be derived from all animals
77# ' @param ploidy integer indicating the ploidy level (default is 2 for diploid)
88# ' @return data.frame consisting of allele_frequencies for populations (columns) for
99# ' each SNP (rows)
10+ # ' @references Funkhouser SA, Bates RO, Ernst CW, Newcom D, Steibel JP. Estimation of genome-wide and locus-specific
11+ # ' breed composition in pigs. Transl Anim Sci. 2017 Feb 1;1(1):36-44.
12+ # '
13+ # ' @examples
14+ # ' # Example inputs
15+ # ' geno_matrix <- matrix(
16+ # ' c(4, 1, 4, 0, # S1
17+ # ' 2, 2, 1, 3, # S2
18+ # ' 0, 4, 0, 4, # S3
19+ # ' 3, 3, 2, 2, # S4
20+ # ' 1, 4, 2, 3),# S5
21+ # ' nrow = 4, ncol = 5, byrow = FALSE, # individuals=rows, SNPs=cols
22+ # ' dimnames = list(paste0("Ind", 1:4), paste0("S", 1:5))
23+ # ' )
24+ # '
25+ # 'pop_list <- list(
26+ # ' PopA = c("Ind1", "Ind2"),
27+ # ' PopB = c("Ind3", "Ind4")
28+ # ' )
29+ # '
30+ # ' allele_freqs <- allele_freq_poly(geno = geno_matrix, populations = pop_list, ploidy = 4)
31+ # ' print(allele_freqs)
32+ # '
1033# ' @export
1134allele_freq_poly <- function (geno , populations , ploidy = 2 ) {
1235
@@ -37,16 +60,20 @@ allele_freq_poly <- function(geno, populations, ploidy = 2) {
3760}
3861
3962
40- # Performs whole genome breed composition prediction.
41- #
42- # @param Y numeric vector of genotypes (with names as SNPs) from a single animal.
43- # coded as dosage of allele B {0, 1, 2}
44- # @param X numeric matrix of allele frequencies from reference animals
45- # @param p numeric indicating number of breeds represented in X
46- # @param names character names of breeds
47- # @return data.frame of breed composition estimates
48- # @import quadprog
49- # @export
63+ # ' Performs whole genome breed composition prediction.
64+ # '
65+ # ' @param Y numeric vector of genotypes (with names as SNPs) from a single animal.
66+ # ' coded as dosage of allele B \code{{0, 1, 2, ..., ploidy}}
67+ # ' @param X numeric matrix of allele frequencies from reference animals
68+ # ' @param p numeric indicating number of breeds represented in X
69+ # ' @param names character names of breeds
70+ # ' @return data.frame of breed composition estimates
71+ # ' @import quadprog
72+ # ' @importFrom stats cor
73+ # ' @references Funkhouser SA, Bates RO, Ernst CW, Newcom D, Steibel JP. Estimation of genome-wide and locus-specific
74+ # ' breed composition in pigs. Transl Anim Sci. 2017 Feb 1;1(1):36-44.
75+ # '
76+ # ' @noRd
5077QPsolve <- function (Y , X ) {
5178
5279 # Remove NAs from Y and remove corresponding
@@ -90,7 +117,7 @@ QPsolve <- function(Y, X) {
90117# ' batch of animals.
91118# '
92119# ' @param Y numeric matrix of genotypes (columns) from all animals (rows) in population
93- # ' coded as dosage of allele B { 0, 1, ..., ploidy}
120+ # ' coded as dosage of allele B \code{{ 0, 1, 2, ..., ploidy} }
94121# ' @param X numeric matrix of allele frequencies (rows) from each reference panel (columns). Frequencies are
95122# ' relative to allele B.
96123# ' @param ped data.frame giving pedigree information. Must be formatted "ID", "Sire", "Dam"
@@ -107,6 +134,37 @@ QPsolve <- function(Y, X) {
107134# ' @return A data.frame or list of data.frames (if groups is !NULL) with breed/ancestry composition
108135# ' results
109136# ' @import quadprog
137+ # ' @references Funkhouser SA, Bates RO, Ernst CW, Newcom D, Steibel JP. Estimation of genome-wide and locus-specific
138+ # ' breed composition in pigs. Transl Anim Sci. 2017 Feb 1;1(1):36-44.
139+ # '
140+ # ' @examples
141+ # ' # Example inputs for solve_composition_poly (ploidy = 4)
142+ # '
143+ # ' # (This would typically be the output from allele_freq_poly)
144+ # ' allele_freqs_matrix <- matrix(
145+ # ' c(0.625, 0.500,
146+ # ' 0.500, 0.500,
147+ # ' 0.500, 0.500,
148+ # ' 0.750, 0.500,
149+ # ' 0.625, 0.625),
150+ # ' nrow = 5, ncol = 2, byrow = TRUE,
151+ # ' dimnames = list(paste0("SNP", 1:5), c("VarA", "VarB"))
152+ # ' )
153+ # '
154+ # ' # Validation Genotypes (individuals x SNPs)
155+ # ' val_geno_matrix <- matrix(
156+ # ' c(2, 1, 2, 3, 4, # Test1 dosages for SNP1-5
157+ # ' 3, 4, 2, 3, 0), # Test2 dosages for SNP1-5
158+ # ' nrow = 2, ncol = 5, byrow = TRUE,
159+ # ' dimnames = list(paste0("Test", 1:2), paste0("SNP", 1:5))
160+ # ' )
161+ # '
162+ # ' # Calculate Breed Composition
163+ # ' composition <- solve_composition_poly(Y = val_geno_matrix,
164+ # ' X = allele_freqs_matrix,
165+ # ' ploidy = 4)
166+ # ' print(composition)
167+ # '
110168# ' @export
111169solve_composition_poly <- function (Y ,
112170 X ,
0 commit comments