library( gstudio )
library( dplyr )11 Parentage
This chapter covers making offspring from known parents and the parentage tools in gstudio: maternal subtraction, fractional paternity, transition probabilities and exclusion. Forward-time simulation of whole populations has its own chapter, Chapter 10.
11.1 Mating and Offspring
The mate() function creates offspring from two parents:
f <- data.frame( Locus = rep( paste0( "Loc", 1:4 ), each = 3 ),
Allele = rep( LETTERS[1:3], times = 4 ),
Frequency = rep( 1 / 3, times = 12 ) )
adults <- f |>
make_population( N = 20 )
offs <- adults |>
slice( 1 ) |>
mate( slice( adults, 2 ), N = 5 )
offs ID Loc1 Loc2 Loc3 Loc4
1 1 B:C C:C A:A A:C
2 1 B:C B:C A:B A:C
3 1 B:C C:C A:B A:C
4 1 B:C B:C A:A A:C
5 1 B:C B:C A:A A:C
11.2 Maternal Subtraction
The minus_mom() function removes the maternal contribution from offspring genotypes. It takes a single data.frame where mothers have OffID = 0 and offspring have OffID != 0:
# Combine mother (OffID = 0) and offspring into one data.frame
family <- bind_rows( adults |>
slice( 1 ) |>
mutate( OffID = 0 ),
offs |>
mutate( OffID = row_number() ) )
family |>
minus_mom() ID Loc1 Loc2 Loc3 Loc4 OffID
2 1 C C A C 1
3 1 C B:C A:B C 2
4 1 C C A:B C 3
5 1 C B:C A C 4
6 1 C B:C A C 5
11.3 Fractional Paternity
The paternity() function estimates the probability of each potential father siring each offspring:
offs <- offs |>
mutate( OffID = row_number(),
MomID = adults$ID[1] )
pat <- offs |>
paternity( slice( adults, 1 ), adults )
pat |>
head() MomID OffID DadID Fij
1 1 1 2 1.0000
2 1 2 2 0.5000
3 1 2 11 0.2500
4 1 2 7 0.1250
5 1 2 4 0.0625
6 1 2 8 0.0625
The Fij column gives the fractional paternity probability. Use strict = TRUE to retain only unambiguous assignments:
offs |>
paternity( slice( adults, 1 ), adults, strict = TRUE ) MomID OffID DadID Fij
1 1 1 2 1
11.4 Transition Probabilities and the Paternity Index
transition_probability() gives the Mendelian probability of an offspring genotype from a pair of parents, as a product across loci (multilocus = FALSE returns the per-locus values):
mom <- slice( adults, 1 )
dad <- slice( adults, 2 )
transition_probability( slice( offs, 1 ), mom, dad )[1] 0.125
transition_probability( slice( offs, 1 ), mom, dad, multilocus = FALSE )Loc1 Loc2 Loc3 Loc4
1.00 0.25 0.50 1.00
To judge a putative father, compare that value with the probability of the offspring given the mother and a random male. Pass only the mother and an allele frequency table from frequencies(); at each locus this is the chance the mother transmits an allele the offspring carries times the frequency of the offspring’s other allele. The ratio is the paternity index, how many times more likely the male is to be the father than a random male:
adult_freqs <- adults |>
frequencies()
T_random <- transition_probability( slice( offs, 1 ),
mom,
freqs = adult_freqs )
transition_probability( slice( offs, 1 ), mom, dad ) / T_random[1] 27.88671
Without freqs, the one-parent value is only a compatibility score (zero when the parent is excluded), not a likelihood, so do not use it as the denominator of a paternity index.
11.5 Single-Parent Exclusion
The parent_finder() function identifies compatible parents for each offspring using exclusion. It requires a data.frame with ID and OffID columns, where adults have OffID = 0:
# Prepare a combined data.frame: adults (OffID = 0) then offspring
locus_cols <- adults |>
column_class( "locus" )
combined <- bind_rows( adults |>
select( ID, all_of( locus_cols ) ) |>
mutate( OffID = 0 ),
offs |>
select( ID, all_of( locus_cols ) ) |>
mutate( OffID = row_number() ) )
combined |>
parent_finder() |>
head() ID OffID ParentID T
2 1 1 2 0.1250
1 1 1 1 0.0625
3 1 1 5 0.0625
4 1 1 10 0.0625
5 1 1 19 0.0625
6 1 2 1 0.0625
Its T column is the one-parent compatibility score from transition_probability() (without freqs): it ranks the compatible parents of each offspring, but it is not a likelihood.
11.6 Identifying Bad Parents
The bad_parents() function takes the same combined data.frame and flags each offspring’s listed parent as compatible (PossibleParent = TRUE) or excluded:
combined |>
bad_parents() ID OffID PossibleParent
1 1 1 TRUE
2 1 2 TRUE
3 1 3 TRUE
4 1 4 TRUE
5 1 5 TRUE
11.7 Bundled Parentage Datasets
The cornus and cornus_florida datasets contain Cornus florida genotype data for parentage analysis:
data( cornus )
cornus |>
head() Population SampleID X.Coordinate Y.Coordinate Cf.G8 Cf.H18 Cf.N5 Cf.N10
1 2 203 3040 6146 157:165 117:119 170:170 189:191
2 2 204 3070 6114 159:163 101:103 166:170 193:201
3 2 205 3096 6148 151:157 113:119 193:195
4 2 206 3124 6136 153:161 117:119 197:201
5 2 207 3082 6126 159:163 105:119 158:170 193:193
6 2 208 3148 5180 181:181 119:119 170:170 199:201
Cf.O5
1 198:198
2 178:182
3 178:182
4 178:198
5 178:196
6 176:182
data( cornus_florida )
cornus_florida |>
head() ID OffID X Y G8 H18 N5 N10 O5
1 226 0 1392 3534 162:180 114:114 124:126 192:192 185:195
2 232 0 1656 3414 158:180 112:112 124:126 184:192 185:185
3 234 0 1718 3330 158:180 112:96 128:128 184:192 185:185
4 300 0 1175 3114 180:188 112:116 126:126 198:200 191:195
5 305 0 1529 3237 154:170 122:124 124:126 188:192 181:195
6 432 0 1336 2748 164:180 114:116 124:126 198:202 185:193
11.8 Without Pipes
adults <- make_population( f, N = 20 )
offs <- mate( adults[1, ], adults[2, ], N = 5 )
offs$OffID <- seq_len( nrow( offs ) )
offs$MomID <- adults$ID[1]
pat <- paternity( offs, adults[1, ], adults )
T_random <- transition_probability( offs[1, ],
adults[1, ],
freqs = frequencies( adults ) )
parent_finder( combined )
bad_parents( combined )