| Title: | Analysis of Qualitative Traits, Segregation and Genetic Linkage |
|---|---|
| Description: | A colour-first toolkit for the analysis of qualitative (categorical) traits in plant breeding and genetics. It tests observed segregation against the classical Mendelian expectations, fitting every standard mono-, di- and trihybrid ratio automatically and ranking them by goodness of fit, with Yates continuity correction and Monte Carlo exact tests for sparse tables. It partitions chi-square across families into pooled and heterogeneity components, so that a poor overall fit can be attributed either to the hypothesised ratio or to variation between families. Genetic linkage is estimated by maximum likelihood from two-locus second filial generation and backcross data, with logarithm of odds scores and likelihood-ratio confidence intervals for the recombination fraction. The package further computes Shannon-Weaver and Simpson diversity for descriptor states used in distinctness, uniformity and stability testing, and performs multiple correspondence analysis and Gower-distance clustering of mixed categorical and quantitative descriptors. Every analysis returns a tidy result object and a publication-ready 'ggplot2' figure. Methods follow Mather (1951, <ISBN:9780416470406>), Allard (1956) <doi:10.3733/hilg.v24n10p235> and Gower (1971) <doi:10.2307/2528823>. |
| Authors: | Praveen Kumar B. K. [aut, cre] |
| Maintainer: | Praveen Kumar B. K. <[email protected]> |
| License: | GPL-3 |
| Version: | 0.1.0 |
| Built: | 2026-10-05 08:24:38 UTC |
| Source: | https://github.com/bkpraveenars-del/bkqualit |
Tools for the genetic analysis of qualitative (discretely inherited) characters: testing observed segregation against Mendelian expectations, partitioning chi-square across families into pooled and heterogeneity components, estimating linkage by maximum likelihood, and summarising and clustering qualitative descriptors of the kind recorded on a distinctness, uniformity and stability (DUS) form.
bq_segregateFit observed counts to Mendelian ratios; ranks a library of classical ratios and names the gene action implied.
bq_heterogeneityPartition the total chi-square over families into pooled and heterogeneity components.
bq_linkageEstimate the recombination fraction by maximum likelihood with a logarithm of odds (LOD) score and a likelihood-ratio confidence interval.
bq_diversityShannon, Simpson and evenness indices for qualitative descriptors, with discriminating power.
bq_mcaMultiple correspondence analysis with the Benzecri adjustment, plus Gower-distance clustering of accessions.
bq_data loads the bundled example datasets, bq_plot draws every result, bq_save writes all figures for a result to disk, and bq_palette, theme_bq, scale_colour_bq and scale_fill_bq provide the shared visual style.
Every analysis function returns a classed list with a print method that states the conclusion in words as well as numbers, and a bq_plot method. Nothing is written to the user's file space unless bq_save is called explicitly.
Praveen Kumar B. K. [email protected]
Mather K (1951). The Measurement of Linkage in Heredity, 2nd edition. Methuen, London.
Allard RW (1956). Formulas and tables to facilitate the calculation of recombination values in heredity. Hilgardia 24, 235–278. doi:10.3733/hilg.v24n10p235
Gower JC (1971). A general coefficient of similarity and some of its properties. Biometrics 27, 857–871. doi:10.2307/2528823
Reads one of the demonstration datasets shipped with the package. The datasets are simulated from known parameters and exist for documentation, teaching and regression testing.
bq_data(name = c("f2", "families", "linkage", "dus"))bq_data(name = c("f2", "families", "linkage", "dus"))
name |
One of |
A data frame.
str(bq_data("f2")) head(bq_data("dus"))str(bq_data("f2")) head(bq_data("dus"))
Summarises a set of categorical descriptors, of the kind recorded on a distinctness, uniformity and stability (DUS) form, into per-descriptor diversity indices, and identifies which descriptors actually discriminate among accessions.
bq_diversity(data, descriptors, accession = NULL, group = NULL)bq_diversity(data, descriptors, accession = NULL, group = NULL)
data |
A data frame with one row per accession. |
descriptors |
Character vector naming the categorical columns. |
accession |
Character or |
group |
Character or |
Three complementary indices are reported for each descriptor. The Shannon-Weaver index is sensitive to rare states; the Simpson index is dominated by common states; and evenness rescales Shannon by the number of observed states so that descriptors with different numbers of states can be compared directly. A descriptor with a single observed state is monomorphic, contributes nothing to discrimination, and is flagged.
A descriptor is useful only if it separates accessions. The discriminating power reported here is the probability that two randomly chosen accessions differ in that descriptor, which equals the Simpson index; descriptors are ranked on it so that the least informative can be dropped from a characterisation form.
An object of class bq_diversity containing per-descriptor diversity indices, the frequency of every state, and, if group is supplied, the same indices within each group.
d <- bq_data("dus") res <- bq_diversity(d, descriptors = c("growth_habit", "leaf_pubescence", "flower_colour", "seed_colour", "seed_shape"), accession = "accession") res bq_plot(res) bq_plot(res, type = "frequencies")d <- bq_data("dus") res <- bq_diversity(d, descriptors = c("growth_habit", "leaf_pubescence", "flower_colour", "seed_colour", "seed_shape"), accession = "accession") res bq_plot(res) bq_plot(res, type = "frequencies")
Partitions the total chi-square computed over several segregating families into a pooled component and a heterogeneity component. This is the standard way to decide why a segregation hypothesis fails.
bq_heterogeneity(data, family, classes, trait = NULL, ratio = c(3, 1))bq_heterogeneity(data, family, classes, trait = NULL, ratio = c(3, 1))
data |
A data frame with one row per family. |
family |
Character; the family identifier column. |
classes |
Character vector; the columns holding counts of each phenotype class. |
trait |
Character or |
ratio |
Numeric vector giving the expected ratio, default |
Writing for the goodness-of-fit statistic of family , the total is on degrees of freedom, the pooled statistic is computed from the summed counts on degrees of freedom, and the heterogeneity statistic is the difference on degrees of freedom, where is the number of families and the number of phenotype classes. The partition is exact.
The two components answer different questions. A significant pooled chi-square with a non-significant heterogeneity means the families behave alike but the hypothesised ratio is wrong. A significant heterogeneity means the families do not behave alike, so pooling them is not justified and the pooled test should not be interpreted.
An object of class bq_heterogeneity containing the per-family goodness of fit and the pooled, heterogeneity and total chi-square components.
d <- bq_data("families") res <- bq_heterogeneity(d, family = "family", classes = c("dominant", "recessive"), trait = "trait", ratio = c(3, 1)) res bq_plot(res)d <- bq_data("families") res <- bq_heterogeneity(d, family = "family", classes = c("dominant", "recessive"), trait = "trait", ratio = c(3, 1)) res bq_plot(res)
Estimates the recombination fraction between two loci from two-locus second filial generation (F2) or backcross counts, and tests it against independent assortment.
bq_linkage(data, pair, classes, design = NULL, phase = NULL, conf = 0.95)bq_linkage(data, pair, classes, design = NULL, phase = NULL, conf = 0.95)
data |
A data frame with one row per locus pair. |
pair |
Character; a column naming the locus pair. |
classes |
Character vector of length four giving the count columns, in the order A_B_, A_bb, aaB_, aabb. |
design |
Character or |
phase |
Character or |
conf |
Confidence level (default 0.95). |
For a backcross the recombination fraction is the proportion of recombinant progeny, a binomial parameter. For an F2 in coupling phase the four phenotype classes occur in the proportions , , and with ; in repulsion phase the outer and inner proportions are exchanged. The recombination fraction is obtained by maximising the multinomial likelihood numerically rather than from the older product-ratio approximation.
The LOD score compares the fitted model with independent assortment, and a value above 3 is the conventional threshold for declaring linkage. The confidence interval is obtained by likelihood-ratio inversion, retaining every value of the recombination fraction whose log-likelihood lies within 1.921 of the maximum; this is preferred to a symmetric standard-error interval because the likelihood is skewed near the boundary. Map distance is reported as 100 times the recombination fraction and is not corrected for double crossovers.
An object of class bq_linkage containing the estimated recombination fraction, its confidence interval, the logarithm of odds (LOD) score, the map distance and a test against independent assortment, together with the likelihood profile for plotting.
Allard RW (1956). Formulas and tables to facilitate the calculation of recombination values in heredity. Hilgardia 24, 235–278. doi:10.3733/hilg.v24n10p235
d <- bq_data("linkage") res <- bq_linkage(d, pair = "pair", classes = c("AB", "Ab", "aB", "ab"), design = "design", phase = "phase") res bq_plot(res) bq_plot(res, type = "estimates")d <- bq_data("linkage") res <- bq_linkage(d, pair = "pair", classes = c("AB", "Ab", "aB", "ab"), design = "design", phase = "phase") res bq_plot(res) bq_plot(res, type = "estimates")
Places accessions and descriptor states in a common low-dimensional space by multiple correspondence analysis (MCA), and groups the accessions by hierarchical clustering of the Gower distance.
bq_mca(data, descriptors, accession = NULL, numeric_vars = NULL, k = 3, ndim = 2)bq_mca(data, descriptors, accession = NULL, numeric_vars = NULL, k = 3, ndim = 2)
data |
A data frame with one row per accession. |
descriptors |
Character vector naming the categorical columns. |
accession |
Character or |
numeric_vars |
Character vector or |
k |
Number of clusters to cut the dendrogram into (default 3). |
ndim |
Number of dimensions to retain (default 2). |
MCA is computed from the singular value decomposition of the standardised indicator matrix. Writing for the indicator of descriptors, , and , for its row and column margins, the decomposition is applied to . Row and column principal coordinates then satisfy the transition relation , so an accession sits at the centroid of the descriptor states it carries, which is what makes an MCA biplot directly readable.
The raw principal inertias of an indicator MCA understate the structure badly, because coding a descriptor into several columns injects inertia that carries no information. The Benzecri adjustment is therefore also reported: axes with inertia above are rescaled to . Interpret the adjusted percentages, not the raw ones.
The Gower distance handles nominal and numeric descriptors together: nominal descriptors contribute 0 when two accessions match and 1 when they differ, numeric descriptors contribute the absolute difference divided by the range, and the contributions are averaged. Clustering uses Ward's minimum-variance criterion on that distance.
An object of class bq_mca containing the principal inertias with the Benzecri adjustment, row and column coordinates, the Gower distance matrix, the clustering, and a modal profile of each cluster.
Gower JC (1971). A general coefficient of similarity and some of its properties. Biometrics 27, 857–871. doi:10.2307/2528823
d <- bq_data("dus") res <- bq_mca(d, descriptors = c("growth_habit", "leaf_pubescence", "flower_colour", "seed_colour", "seed_shape", "pod_curvature"), accession = "accession", numeric_vars = "plant_height_cm", k = 3) res bq_plot(res) bq_plot(res, type = "dendrogram") bq_plot(res, type = "scree")d <- bq_data("dus") res <- bq_mca(d, descriptors = c("growth_habit", "leaf_pubescence", "flower_colour", "seed_colour", "seed_shape", "pod_curvature"), accession = "accession", numeric_vars = "plant_height_cm", k = 3) res bq_plot(res) bq_plot(res, type = "dendrogram") bq_plot(res, type = "scree")
Returns the colours used throughout the package. Categorical palettes are returned unchanged when enough colours are available and interpolated otherwise; sequential palettes are always interpolated.
bq_palette(name = c("phenotype", "fit", "linkage", "descriptor", "contrast"), n = NULL, reverse = FALSE)bq_palette(name = c("phenotype", "fit", "linkage", "descriptor", "contrast"), n = NULL, reverse = FALSE)
name |
Palette name. |
n |
Number of colours. If |
reverse |
Logical; reverse the colour order. |
A character vector of hexadecimal colours.
bq_palette("phenotype") bq_palette("linkage", 6)bq_palette("phenotype") bq_palette("linkage", 6)
A single plotting verb for every analysis in the package. The method chosen depends on the class of x.
bq_plot(x, ...)bq_plot(x, ...)
x |
An object returned by one of the |
... |
Arguments passed to the method, typically |
Several results accept a type argument selecting among alternative views: bq_linkage offers "profile" and "estimates"; bq_diversity offers "indices" and "frequencies"; bq_mca offers "biplot", "dendrogram" and "scree".
A ggplot object.
res <- bq_segregate(bq_data("f2"), phenotype = "phenotype", count = "count", trait = "trait") bq_plot(res)res <- bq_segregate(bq_data("f2"), phenotype = "phenotype", count = "count", trait = "trait") bq_plot(res)
Convenience wrapper that writes all available views of a result to disk as PNG files. Nothing is written unless this function is called.
bq_save(x, path = tempdir(), prefix = NULL, width = 8, height = 5.5, dpi = 300)bq_save(x, path = tempdir(), prefix = NULL, width = 8, height = 5.5, dpi = 300)
x |
An object returned by one of the |
path |
Directory to write into. Defaults to a temporary directory. |
prefix |
File-name prefix. Defaults to the class of |
width, height, dpi
|
Passed to |
Character vector of the files written, invisibly.
res <- bq_segregate(bq_data("f2"), phenotype = "phenotype", count = "count", trait = "trait") bq_save(res, path = tempdir())res <- bq_segregate(bq_data("f2"), phenotype = "phenotype", count = "count", trait = "trait") bq_save(res, path = tempdir())
Fits observed phenotype counts to the classical Mendelian expectations. When no ratio is stated, a library of standard mono-, di- and trihybrid ratios with the matching number of classes is fitted and ranked, and the gene action implied by the best fit is named.
bq_segregate(data = NULL, phenotype = NULL, count = NULL, trait = NULL, ratio = NULL, counts = NULL, simulate = TRUE, B = 10000, seed = 1L)bq_segregate(data = NULL, phenotype = NULL, count = NULL, trait = NULL, ratio = NULL, counts = NULL, simulate = TRUE, B = 10000, seed = 1L)
data |
A data frame in long form, one row per phenotype class. |
phenotype |
Character; the phenotype-class column. |
count |
Character; the observed-count column. |
trait |
Character or |
ratio |
Numeric vector giving a specific expected ratio. If |
counts |
Named numeric vector, an alternative to supplying |
simulate |
Logical; also run a Monte Carlo exact test (default |
B |
Monte Carlo replicates (default 10000). |
seed |
Random seed for the Monte Carlo test. |
The Pearson chi-square is reported with the Yates continuity correction applied only when there is a single degree of freedom, which is where the correction is defined; applying it more widely is a common error that makes tests conservative. A Monte Carlo exact test is also run, because the chi-square approximation is unreliable when an expected count falls below five, as it often does in the rarest class of a 63:1 or 9:3:3:1 table.
A high p value does not prove the hypothesis. It means the data are compatible with it. Where two ratios fit almost equally well, the printed output says so rather than declaring a winner.
An object of class bq_segregate holding the fitted ratios ranked by goodness of fit, the observed and expected counts, and the gene action implied by the best-fitting ratio.
Mather K (1951). The Measurement of Linkage in Heredity, 2nd edition. Methuen, London.
d <- bq_data("f2") res <- bq_segregate(d, phenotype = "phenotype", count = "count", trait = "trait") res bq_plot(res) ## a single trait against a stated hypothesis bq_segregate(counts = c(purple = 312, white = 104), ratio = c(3, 1))d <- bq_data("f2") res <- bq_segregate(d, phenotype = "phenotype", count = "count", trait = "trait") res bq_plot(res) ## a single trait against a stated hypothesis bq_segregate(counts = c(purple = 312, white = 104), ratio = c(3, 1))
Discrete scales built on the package palettes. scale_color_bq is an alias of scale_colour_bq.
scale_colour_bq(pal_name = "phenotype", reverse = FALSE, ...) scale_fill_bq(pal_name = "phenotype", reverse = FALSE, ...)scale_colour_bq(pal_name = "phenotype", reverse = FALSE, ...) scale_fill_bq(pal_name = "phenotype", reverse = FALSE, ...)
pal_name |
Palette name; see |
reverse |
Logical; reverse the colour order. |
... |
Passed to |
A ggplot2 scale object.
library(ggplot2) ggplot(bq_data("dus"), aes(growth_habit, fill = seed_shape)) + geom_bar() + scale_fill_bq("descriptor", name = "Seed shape") + theme_bq()library(ggplot2) ggplot(bq_data("dus"), aes(growth_habit, fill = seed_shape)) + geom_bar() + scale_fill_bq("descriptor", name = "Seed shape") + theme_bq()
A clean theme with a soft background, muted grid and a coloured title, applied by every plotting method in the package. It can be added to any ggplot of your own.
theme_bq(base_size = 12, base_family = "", grid = TRUE)theme_bq(base_size = 12, base_family = "", grid = TRUE)
base_size |
Base font size in points. |
base_family |
Base font family. |
grid |
Logical; draw the background grid. |
A ggplot2 theme object.
library(ggplot2) ggplot(bq_data("dus"), aes(growth_habit)) + geom_bar(fill = bq_palette("phenotype", 1)) + theme_bq()library(ggplot2) ggplot(bq_data("dus"), aes(growth_habit)) + geom_bar(fill = bq_palette("phenotype", 1)) + theme_bq()