In species with sex chromosomes, males and females do not carry the same number of copies of every chromosome. An XY male has one X, an XX female has two. Without telling Qploidy2 about this, every male looks like it has lost an X chromosome, and sex-chromosome aneuploidies (XXY, XYY, X0) cannot be told apart from normal males and females.

When you give hmm_estimate_CN() the sex-determination system (sex_system) and the chromosomes that carry the sex chromosomes (sex_chr), Qploidy2:

  • scores the presence of the Y from the read depth of Y-specific markers,
  • infers the sex and the sex-chromosome complement of each sample (XX, XY, XXY, …),
  • compares the X with the copy number expected for that sex, so one X in a male is not reported as a loss, while an extra X in an XXY male is reported as a gain.

These options do not change the copy-number calls of the HMM. They are stored in the result and used by karyotype_notation(), count_types(), plot_karyotype() and compare_cn_track_summary().

This tutorial uses a simulated population of 100 individuals of a diploid XY species, of which only 30 are known females. The population also has a few sex-chromosome aneuploids and a few triploid, tetraploid and pentaploid individuals. The tutorial goes through the whole analysis, from raw read counts to the inferred sex of every individual, and compares the results with the truth.

library(Qploidy2)
library(ggplot2)

1 Sex-determination systems

sex_system Females Males Sex inferred from sex_chr groups Examples
"XY" XX XY Y present → male X, Y, PAR mammals, hemp (Cannabis), spinach, asparagus, papaya, Silene latifolia
"ZW" ZW ZZ W present → female Z, W, PAR birds, butterflies and moths, some strawberries (Fragaria), willows (Salix)
"X0" XX X0 number of X copies: equal to the ploidy → female, half → male X grasshoppers, many other insects, C. elegans (hermaphrodites XX)
"haplodiploid" 2x 1x sample ploidy none bees, ants, wasps
"none" (default) not inferred none species without sex chromosomes

The ZW system mirrors the XY system with the sexes swapped: the female is the sex with two different sex chromosomes. Everything this tutorial says about X and Y applies to Z and W. The haplodiploid system needs no sex-chromosome markers, because males and females differ in the ploidy of the whole genome.

Note: all systems above are implemented, but only the XY system has been tested with real datasets so far. If you would like to use Qploidy2 with a ZW, X0 or haplodiploid species, please contact us at Breeding Insight by opening an issue. We are happy to help and to learn how the feature performs with your data.

2 Three kinds of sex-chromosome markers

Markers on the sex chromosomes fall in three groups. Qploidy2 needs to know which group each marker belongs to, through the chromosome ID in geno.pos.

  • X-specific markers sit in sequence found only on the X. Their copy number is the number of X chromosomes: 2 in an XX female, 1 in an XY male.
  • Y-specific markers sit in sequence found only on the Y. Their copy number is the number of Y chromosomes: 0 in a female, 1 in a male.
  • Pseudoautosomal (PAR) markers sit in sequence found on both X and Y.

2.1 What is the pseudoautosomal region?

X and Y evolved from a pair of ordinary chromosomes. Over time most of the Y stopped recombining with the X and diverged from it, but in most species a segment at one or both ends of the X and Y still pairs and recombines at meiosis. This segment is the pseudoautosomal region (PAR). Within it, the X and Y carry the same sequence, so a marker in the PAR is read from every X and every Y in the sample, and it is inherited like an autosomal marker (hence pseudo-autosomal).

For copy number this means:

  • the PAR copy number is X + Y: 2 in an XX female and also 2 in an XY male;
  • males are heterozygous in the PAR (their X and Y copies can carry different alleles), while in the X-specific region a male has a single copy and is never heterozygous (he is hemizygous).

Markers in X–Y homologous sequence outside the true PAR, for example in genes that still have a similar copy on the X and on the Y (gametologs), behave the same way when the marker cannot tell the X copy from the Y copy. For Qploidy2 they belong to the PAR group too: what matters is not where the region sits, but that the marker is read from both chromosomes.

Group XX female XY male XXY male X0 female
X-specific 2 1 2 1
Y-specific 0 1 1 0
PAR (X + Y) 2 2 3 1

In polyploids the same rules apply with more copies, e.g. a tetraploid male can be XXXY or XXYY, and the PAR copy number is still X + Y.

2.2 X and Y markers must be specific

This is the most important requirement of the analysis. The sex of a sample is read from the Y-specific markers, and the number of Y copies from the difference between PAR and X (PAR − X = Y). Both only work if every marker is in the right group:

  • A marker placed in Y must have no signal in females. A marker that is also read from the X (a shared or homologous sequence) gives reads in every female, and the females are then scored as carrying a Y.
  • A marker placed in X must not be read from the Y. A PAR marker left in the X group has 2 copies in males, so males look like they carry a partial extra X.
  • PAR markers must be in their own group, with their own chromosome ID (e.g. ChrX_PAR), even when the reference genome has a single X chromosome with the PAR at its tip.

Section Why specificity matters shows what goes wrong otherwise.

3 Standardize with females only

Before the HMM, standardize() places every marker on a common scale. It builds, for each marker, reference BAF clusters and a reference depth (mean and standard deviation of R, used for the z-score) from the samples in genos, at the ploidy given by ploidy.standardization. All samples in data are then standardized against this reference.

Standardization needs a reference of at least 30 individuals, and for the sex chromosomes the reference must have a single, known complement. So use only XX females (the homogametic sex) as the reference:

  • With only females in genos, every reference sample has 2 copies of the X. The X-specific markers are standardized at the same scale as the autosomes, and a male’s single X appears as a clean one-copy loss in depth (z-score) and as homozygous BAF.
  • If males are part of the reference, the X reference mixes 1-copy and 2-copy samples. The BAF clusters are blurred, the reference depth sits between the two sexes, and the difference between males and females in the X becomes smaller and noisier.
  • Y-specific markers have no reads in females, so they get no reference clusters and no reference depth, and they have no BAF or z-score after standardization. That is expected: Qploidy2 does not need them. It scores the presence of the Y from their raw depth (R), which is kept for all samples.

The other samples do not need a known sex: they are standardized against the female reference, and their sex is inferred afterwards. For a ZW species, use ZZ males as the reference for the same reasons.

4 A simulated XY dataset

The code below simulates raw read counts for 100 individuals of a diploid XY species, in the input format of standardize():

  • four autosomes (Chr1–Chr4) with 500 markers each;
  • one X chromosome in the reference genome (ChrX): the first 5 Mb are the PAR (150 markers), the rest is X-specific (500 markers);
  • a Y-specific contig (ChrY) with 40 markers, with no reads in females.

Every marker has its own allele frequency and its own depth, as in real sequencing, with a mean of 150 reads per marker. Read counts follow a negative binomial distribution, and the reads of the alternative allele are sampled from the true dosage. As in real data, every individual gets about the same number of reads whatever its ploidy, so a tetraploid has half as many reads per copy as a diploid.

set.seed(2026)

# Markers and their positions
n_auto <- 500; n_par <- 150; n_xspec <- 500; n_y <- 40
geno.pos <- rbind(
  data.frame(Chromosome = rep(sprintf("Chr%d", 1:4), each = n_auto),
             Position = rep(seq_len(n_auto) * 80000, 4)),
  data.frame(Chromosome = "ChrX",
             Position = c(round(seq(1e4, 5e6, length.out = n_par)),
                          round(seq(5.1e6, 6e7, length.out = n_xspec)))),
  data.frame(Chromosome = "ChrY", Position = seq_len(n_y) * 1e5)
)
geno.pos$MarkerName <- sprintf("%s_%d", geno.pos$Chromosome,
                               as.integer(geno.pos$Position))
geno.pos <- geno.pos[, c("MarkerName", "Chromosome", "Position")]

# True group of each marker (unknown to the analysis)
mk_group <- ifelse(geno.pos$Chromosome == "ChrY", "Y",
            ifelse(geno.pos$Chromosome == "ChrX" & geno.pos$Position <= 5e6, "PAR",
            ifelse(geno.pos$Chromosome == "ChrX", "X", "autosome")))
n_mk <- nrow(geno.pos)
allele_freq <- runif(n_mk, 0.15, 0.85)
# Reads per copy in a diploid, marker-specific: mean depth of 150 per marker
mk_depth <- 75 * exp(rnorm(n_mk, 0, 0.3))

The population has 30 known females (the reference) and 70 individuals of unknown sex:

  • 13 XX females and 46 XY males;
  • five diploids with a sex-chromosome aneuploidy: two XXY males, one XYY male and two X0 females;
  • six polyploids: a triploid female (XXX) and male (XXY), a tetraploid female (XXXX) and male (XXYY), and a pentaploid female (XXXXX) and male (XXXYY).
truth <- data.frame(
  SampleName = sprintf("S%03d", 1:100),
  complement = c(rep("XX", 30),
                 sample(c(rep("XX", 13), rep("XY", 46),
                          "XXY", "XXY", "XYY", "X0", "X0",
                          "3x:XXX", "3x:XXY", "4x:XXXX", "4x:XXYY",
                          "5x:XXXXX", "5x:XXXYY")))
)
truth$ploidy <- ifelse(grepl(":", truth$complement),
                       as.integer(substr(truth$complement, 1, 1)), 2L)
truth$complement <- sub("^.x:", "", truth$complement)
truth$n_x <- nchar(gsub("[^X]", "", truth$complement))
truth$n_y <- nchar(gsub("[^Y]", "", truth$complement))
truth$true_label <- paste0(truth$ploidy, "x ", truth$complement)

# The only sex information used in the analysis
reference_females <- truth$SampleName[1:30]

sim_sample <- function(i) {
  nx <- truth$n_x[i]; ny <- truth$n_y[i]; pl <- truth$ploidy[i]
  cn <- c(autosome = pl, X = nx, Y = ny, PAR = nx + ny)[mk_group]
  dose <- rbinom(n_mk, cn, allele_freq)
  # Same total depth whatever the ploidy: reads per copy scale with 2 / ploidy
  R <- rnbinom(n_mk, mu = pmax(mk_depth * cn * 2 / pl, 0.1), size = 30)
  R[cn == 0] <- 0L                                  # no Y reads in females
  p_alt <- ifelse(cn > 0, dose / pmax(cn, 1), 0.5) * 0.99 + 0.005
  alt <- rbinom(n_mk, R, p_alt)
  data.frame(MarkerName = geno.pos$MarkerName, SampleName = truth$SampleName[i],
             X = R - alt, Y = alt, R = R, ratio = ifelse(R > 0, alt / R, NA),
             dose = dose)
}
raw <- do.call(rbind, lapply(seq_len(nrow(truth)), sim_sample))

# Input of standardize(): read counts of all samples ...
data <- raw[, c("MarkerName", "SampleName", "X", "Y", "R", "ratio")]
# ... and genotype calls of the reference females only (in real data, from a
# genotype caller such as updog or fitPoly)
in_ref <- raw$SampleName %in% reference_females & !is.na(raw$ratio)
genos <- data.frame(MarkerName = raw$MarkerName[in_ref],
                    SampleName = raw$SampleName[in_ref],
                    geno = raw$dose[in_ref], prob = 0.99)
head(data)

The truth table is used only at the end, to check the results.

5 Defining the marker groups

The reference genome has a single ChrX and a Y contig. Before the analysis, the PAR has to be separated from the X-specific region, and the Y markers checked for specificity. The known females are the guide.

5.1 Y-specific markers and likely males

A Y-specific marker has no reads in any female and reads in every male. Here the depth of each ChrY marker is checked in the 30 reference females, and the fraction of covered ChrY markers (depth above 6) is computed for every other individual.

y_mks <- geno.pos$MarkerName[geno.pos$Chromosome == "ChrY"]
y_data <- data[data$MarkerName %in% y_mks, ]
y_data$covered <- y_data$R > 6
y_data$reference <- y_data$SampleName %in% reference_females

# Fraction of reference females covered at each Y marker: must be 0
cov_in_females <- tapply(y_data$covered[y_data$reference],
                         y_data$MarkerName[y_data$reference], mean)
summary(cov_in_females)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0       0       0       0       0       0
# Fraction of Y markers covered in each of the other individuals
y_by_sample <- tapply(y_data$covered[!y_data$reference],
                      y_data$SampleName[!y_data$reference], mean)
ggplot(data.frame(frac = y_by_sample), aes(x = frac)) +
  geom_histogram(bins = 41, fill = "#2c7fb8") +
  labs(x = "Fraction of Y markers covered", y = "Individuals") +
  theme_bw()

likely_males <- names(y_by_sample)[y_by_sample > 0.5]
length(likely_males)
## [1] 52

No Y marker has reads in any reference female, so all 40 are Y-specific and can be used. The other individuals split into two clear groups: those with no Y marker covered, and those with nearly all covered, the likely males. In real data, drop Y markers covered in some females, and markers missing in most of the likely males.

5.2 Finding the PAR boundary

In the PAR, males are heterozygous like females. In the X-specific region they carry a single X and are never heterozygous. The fraction of heterozygous markers along ChrX in the likely males shows where the PAR ends.

chrx <- merge(data, geno.pos[geno.pos$Chromosome == "ChrX", ], by = "MarkerName")
chrx <- chrx[chrx$SampleName %in% c(reference_females, likely_males), ]
chrx$het <- chrx$ratio > 0.1 & chrx$ratio < 0.9
chrx$group <- ifelse(chrx$SampleName %in% likely_males,
                     "likely males", "reference females")
chrx$bin_Mb <- floor(chrx$Position / 1e6) + 0.5
het_bins <- aggregate(het ~ bin_Mb + group, chrx, mean)

ggplot(het_bins, aes(x = bin_Mb, y = het, colour = group)) +
  geom_line() + geom_point(size = 1) +
  geom_vline(xintercept = 5, linetype = "dashed", colour = "grey40") +
  labs(x = "Position on ChrX (Mb)", y = "Fraction of heterozygous markers",
       colour = NULL) +
  theme_bw()

Heterozygosity in the likely males drops to almost zero after 5 Mb: the first 5 Mb are the PAR. It is not exactly zero because two of the likely males are polyploids with two copies of the X (3x XXY and 4x XXYY), which can be heterozygous in the X-specific region. In real data, check the depth too: in the X-specific region the male depth is lower than that of females, while in the PAR it is the same.

The PAR markers get their own chromosome ID in geno.pos:

in_par <- geno.pos$Chromosome == "ChrX" & geno.pos$Position <= 5e6
geno.pos$Chromosome[in_par] <- "ChrX_PAR"
table(geno.pos$Chromosome)
## 
##     Chr1     Chr2     Chr3     Chr4     ChrX ChrX_PAR     ChrY 
##      500      500      500      500      500      150       40

6 Standardization

Only the genotypes of the 30 reference females are given in genos; data holds all 100 individuals.

std <- standardize(
  data = data,
  genos = genos,                 # reference: the 30 known females only
  geno.pos = geno.pos,
  ploidy.standardization = 2,
  threshold.n.clusters = 2,
  type = "counts",
  verbose = FALSE
)
std
## This is an object of class 'qploidy_standardization'
## --------------------------------------------------------------------
## Parameters
##                                                           
## 1 Standardization type:                             counts
## 2 Ploidy:                                           2     
## 3 Min # of heterozygous classes (clusters) present: 2     
## 4 Max proportion of missing genotype by marker:     0.9   
## 5 Max proportion of missing genotype by sample:     1     
## 6 Min genotype probability:                         0.8   
## --------------------------------------------------------------------
## Filters
##                                                                     
## 1  # markers at raw data:                             2690 (100%)   
## 2  # individuals in standardized data:                100  -        
## 3  % datapoints filtered by low probability:          -    (0 %)    
## 4  # datapoints filtered by depth (min/max):          0    (0 %)    
## 5  # samples filtered by missing data:                0    -        
## 6  # markers filtered by missing data:                0    (0 %)    
## 7  # markers filtered by min number of clusters:      0    (0 %)    
## 8  # markers filtered by lack of genomic information: 0    (0 %)    
## 9  # markers remaining with estimated BAF:            2650 (98.51 %)
## 10 # markers remaining with estimated z-score:        2650 (98.51 %)

Because the female samples used as reference don’t have the Y chromosome, the standardization does not return BAF or zscore for this chromosome. Only its total depth is kept to verify presence and absence:

y_std <- std$data[std$data$Chr == "ChrY", ]
c(markers = length(unique(y_std$MarkerName)),
  with_z = sum(!is.na(y_std$z)), with_R = sum(!is.na(y_std$R)))
## markers  with_z  with_R 
##      40       0    4000

7 Running the HMM with the sex system

sex_system and sex_chr are passed to hmm_estimate_CN() or hmm_estimate_CN_multi(). sex_chr is a named list: each name is a marker group and each element is the chromosome ID(s) of that group. A group can hold several IDs, e.g. Y = c("ChrY_contig1", "ChrY_contig2").

sex_chr <- list(X = "ChrX", Y = "ChrY", PAR = "ChrX_PAR")

res <- hmm_estimate_CN_multi(
  std,
  n_cores = 2,
  cn_grid = 1:7,
  verbose = FALSE,
  sex_system = "XY",
  sex_chr = sex_chr
)

cn_grid = 1:7 lets the HMM find the ploidy of the polyploids. For each sample, the copy numbers tested are then restricted to two around its own ploidy (max_cn_dev = 2), e.g. 1 to 4 in diploids and 3 to 7 in pentaploids.

The presence of the Y is decided from the raw depth of the Y-specific markers, before any filter, with two arguments:

  • sex_min_depth (default 6): a Y marker counts as covered when its depth is above this value;
  • sex_min_markers (default 2): the Y is present when at least this many Y markers are covered.

The result is stored per sample as a score, e.g. "40/40" (40 of the 40 Y markers covered). The Y-specific markers have no z-score or BAF, so they get no copy-number call and are absent from the HMM tracks.

8 Results

8.1 Checking unreliable windows

Before the results are read, the calls with a low CN_reliability should be checked. Here is the sex-chromosome complement of every sample, compared with the truth:

ct_raw <- count_types(res)
check_raw <- merge(ct_raw$sex, truth, by.x = "Sample", by.y = "SampleName")
table(true = check_raw$true_label, inferred = check_raw$SexChr)
##           inferred
## true       X0 XX XXX XXXX XXXXX XXXYY XXY XXYY XY XYY
##   2x X0     2  0   0    0     0     0   0    0  0   0
##   2x XX     0 43   0    0     0     0   0    0  0   0
##   2x XXY    0  0   0    0     0     0   0    2  0   0
##   2x XY     0  0   0    0     0     0   0    0 46   0
##   2x XYY    0  0   0    0     0     0   0    0  0   1
##   3x XXX    0  0   1    0     0     0   0    0  0   0
##   3x XXY    0  0   0    0     0     0   1    0  0   0
##   4x XXXX   0  0   0    1     0     0   0    0  0   0
##   4x XXYY   0  0   0    0     0     0   0    1  0   0
##   5x XXXXX  0  0   0    0     1     0   0    0  0   0
##   5x XXXYY  0  0   0    0     0     1   0    0  0   0

The two diploid XXY males are reported as XXYY. Their PAR, which has 3 copies, was called 4, with a low CN_reliability:

xxy <- truth$SampleName[truth$true_label == "2x XXY"]
bw <- res$by_window
bw[bw$Sample %in% xxy & bw$Chr == "ChrX_PAR",
   c("Sample", "Chr", "n_het", "CN_call", "post_max", "CN_reliability",
     "rel_baf_agree")]
plot_cn_track(res, std, sample_id = xxy[1])$arranged

The BAF of the PAR clearly shows the peaks of 3 copies (1/3 and 2/3), not those of 4, so rel_baf_agree is low and CN_reliability falls below 0.5 (see the CN reliability tutorial). The call comes from the z-score.

8.2 Why the PAR was called 4: the z-score scale

The z-score means of the copy-number states are not fixed. For each sample, they are set from the range of its own z-scores: the expected ploidy sits at the mean z, and the lowest and highest states of the grid are placed at the ends of the observed range. The more states the grid has, the smaller the z-score jump between two consecutive copy numbers.

With cn_grid = 1:7 and max_cn_dev = 2, a diploid is tested for 1 to 4 copies. In these XXY males the PAR is the only gain in the genome, so it holds the highest z-score, and that z-score becomes the mean of the highest state, 4 copies. The state of 3 copies falls halfway between 2 and 4:

res$params_samples[[xxy[1]]]$mu
##           1           2           3           4 
## -0.92742485 -0.06400727  1.45592897  2.49416365
tapply(bw$z[bw$Sample == xxy[1]], bw$Chr[bw$Sample == xxy[1]], mean)
##        Chr1        Chr2        Chr3        Chr4        ChrX    ChrX_PAR 
## -0.03633464 -0.12304301 -0.03615459  0.01507383 -0.04779434  2.49416365

The z-score of the PAR then fits 4 copies much better than 3, and this large jump outweighs the BAF, even though the BAF clearly shows 3 copies.

8.3 Fixing the two samples with max_cn_dev = 1

With max_cn_dev = 1, a diploid is tested only for 1 to 3 copies. The highest state is now 3, the z-score of the PAR sits on the mean of 3 copies, and BAF and z-score agree. The two samples are re-run on their own and replaced in the result with update_hmm_CN_multi():

for (s in xxy) {
  fix <- hmm_estimate_CN(std, sample_id = s, cn_grid = 1:7, max_cn_dev = 1,
                         sex_system = "XY", sex_chr = sex_chr,
                         verbose = FALSE)
  res <- update_hmm_CN_multi(res, fix)
}
res$params_samples[[xxy[1]]]$mu
##           1           2           3 
## -1.04535586 -0.06400728  2.49416365
bw <- res$by_window
bw[bw$Sample %in% xxy & bw$Chr == "ChrX_PAR",
   c("Sample", "Chr", "n_het", "CN_call", "post_max", "CN_reliability",
     "rel_baf_agree")]
plot_cn_track(res, std, sample_id = xxy[1])$arranged

The PAR is now called 3 copies, with a CN_reliability of 1.

Why not use max_cn_dev = 1 for every sample from the start? A narrower grid cannot call changes of more than one copy, and in a population with polyploids and aneuploids it is safer to keep the default and re-run only the samples whose BAF disagrees with the call. When only single-copy changes are expected, max_cn_dev = 1 can be used for the whole population.

8.4 Filtering unreliable windows

The remaining windows with a low CN_reliability are masked with filter_hmm_CN():

res_f <- filter_hmm_CN(res, min_CN_reliability = 0.5)
res_f$by_window[is.na(res_f$by_window$CN_call) &
                  res_f$by_window$Chr %in% c("ChrX", "ChrX_PAR"),
                c("Sample", "Chr", "Start", "End")]

On the sex chromosomes, only the PAR of three XY males is masked. Their sex is still known from the Y markers. The rest of the tutorial uses the filtered result.

8.5 Sex of each sample

count_types() adds a $sex table and the sex counts to its summary:

ct <- count_types(res_f)
ct
## 
## Sample classification summary
## ====================================================
##   2x  (n = 94)
##     2x - euploid            89
##     2x - aneuploid          5
##   3x  (n = 2)
##     3x - euploid            2
##   4x  (n = 2)
##     4x - euploid            2
##   5x  (n = 2)
##     5x - euploid            2
## ----------------------------------------------------
##   Total euploid              95
##   Total aneuploid            5
##   Total segmental aneuploidy 0
##   Grand total                100
##   Sex: female 48 | male 52 | ? 0 | unknown 0
## ====================================================
head(ct$sex)

How each column of $sex is built:

  • SexHetScore: Y markers covered / Y markers.
  • Sex: male when the Y is present by depth, female otherwise.
  • SexHetCN: number of Y copies. The Y has no copy-number call, so it is computed as PAR − X: an XYY male has 3 PAR copies and one X, so 2 Y.
  • SexChr: the sex-chromosome complement. Each 0 marks a copy missing relative to the ploidy, as in an X0 female.
  • SexChrConsistent: whether the Y depth agrees with the copy numbers. Y present must go with PAR > X (at least one Y copy), and Y absent with PAR = X. A sample where they disagree gets FALSE and Sex = "?" (see When the sex is reported as ?).

Sex chromosomes are excluded from the sample ploidy, and normal males are not counted as aneuploid: only the individuals with an abnormal complement are.

8.6 Comparison with the truth

check <- merge(ct$sex, truth, by.x = "Sample", by.y = "SampleName")
table(true = check$true_label, inferred = check$SexChr)
##           inferred
## true       X0 XX XXX XXXX XXXXX XXXYY XXY XXYY XY XYY
##   2x X0     2  0   0    0     0     0   0    0  0   0
##   2x XX     0 43   0    0     0     0   0    0  0   0
##   2x XXY    0  0   0    0     0     0   2    0  0   0
##   2x XY     0  0   0    0     0     0   0    0 46   0
##   2x XYY    0  0   0    0     0     0   0    0  0   1
##   3x XXX    0  0   1    0     0     0   0    0  0   0
##   3x XXY    0  0   0    0     0     0   1    0  0   0
##   4x XXXX   0  0   0    1     0     0   0    0  0   0
##   4x XXYY   0  0   0    0     0     0   0    1  0   0
##   5x XXXXX  0  0   0    0     1     0   0    0  0   0
##   5x XXXYY  0  0   0    0     0     1   0    0  0   0
check[!check$true_label %in% c("2x XX", "2x XY"),
      c("Sample", "true_label", "Sex", "SexChr", "SexHetCN", "SexHetScore")]

Every individual gets its true complement, including the 70 whose sex was not given to the analysis and the polyploids.

8.7 Polyploids

In a polyploid, the expected sex-chromosome complement fills the ploidy: a triploid male is XXY, a tetraploid male can be XXXY or XXYY. So a 3x XXY male is euploid, while a 2x XXY male is aneuploid. In the count_types() summary above, the polyploids are counted under their own ploidy and as euploid, and only the five diploid aneuploids are counted as aneuploid.

SexHetCN gives the number of Y copies (PAR − X): 2 in the 4x XXYY and 5x XXXYY males.

8.8 Karyotype notation

karyotype_notation() reports, for each sample and chromosome, the copy number expected for its sex (ExpectedCN) and the segments that deviate from it.

pick <- function(label) truth$SampleName[31:100][truth$true_label[31:100] == label][1]
ex <- c(female = pick("2x XX"), male = pick("2x XY"), XXY = pick("2x XXY"),
        X0 = pick("2x X0"), XYY = pick("2x XYY"), male_4x = pick("4x XXYY"))
ex
##  female    male     XXY      X0     XYY male_4x 
##  "S037"  "S031"  "S067"  "S059"  "S051"  "S080"
kn <- as.data.frame(karyotype_notation(res_f, sample_name = ex[-5]))
kn[kn$ChrID %in% c("ChrX", "ChrX_PAR"),
   c("SampleName", "Ploidy", "ChrID", "ChrType", "ChrCN", "ExpectedCN",
     "SexChr", "Segment")]
  • In the XY male, the single X is expected (ExpectedCN = 1), so no segment is reported.
  • In the 2x XXY male, the X and the PAR carry one copy more than expected for a male (2 instead of 1, and 3 instead of 2) and are reported as gains.
  • In the X0 female, the X and the PAR carry one copy less than expected for a female and are reported as losses.
  • In the 4x XXYY male, 2 copies of the X and 4 of the PAR are expected, so no segment is reported.

The Y has no copy-number call, so a Y aneuploidy is not reported on the Y itself. In the XYY male it shows in SexChr and in the PAR (3 copies instead of 2). Because the expected complement is the one that fills the ploidy (X + Y = 2), a diploid with two Y is expected to carry no X, and his single X is reported as a segment as well. Read the sex-chromosome segments together with SexChr.

8.9 Plots

plot_karyotype() draws the expected copies of each chromosome, labels the sex chromosomes, and adds the inferred sex and the Y score to the subtitle.

plot_karyotype(res_f, sample_name = ex[["male"]])

plot_karyotype(res_f, sample_name = ex[["XXY"]])

plot_karyotype(res_f, sample_name = ex[["male_4x"]])

compare_cn_track_summary() adds the sex of each sample, e.g. M (XY), next to the copy-number tracks. Here for 20 individuals, including the aneuploids and the polyploids. Windows masked by filter_hmm_CN() are left blank:

to_plot <- unique(c(truth$SampleName[!truth$true_label %in% c("2x XX", "2x XY")],
                    truth$SampleName[31:50]))[1:20]
compare_cn_track_summary(res_f, samples_to_plot = to_plot)

In plot_cn_track() of a male, the BAF of the X-specific region has no heterozygous markers and its depth is lower, while the PAR looks like an autosome.

plot_cn_track(res_f, std, sample_id = ex[["male"]])$arranged

9 Why specificity matters

9.1 PAR markers left in the X group

Here the PAR is not separated from the X: the whole of ChrX is given as X.

std_unsplit <- std
std_unsplit$data$Chr[std_unsplit$data$Chr == "ChrX_PAR"] <- "ChrX"

res_unsplit <- hmm_estimate_CN_multi(
  std_unsplit, sample_ids = ex[c("female", "male")], n_cores = 1,
  cn_grid = 1:4, verbose = FALSE, sex_system = "XY",
  sex_chr = list(X = "ChrX", Y = "ChrY")
)
kn_unsplit <- as.data.frame(karyotype_notation(res_unsplit))
kn_unsplit[kn_unsplit$ChrID == "ChrX",
           c("SampleName", "ChrCN", "ExpectedCN", "SexChr", "Segment")]

The male is still called XY, because most of the X is X-specific. But the PAR, where he has two copies, is now reported as a segmental gain of the X (ChrX:g.10000_...×2) that he does not have. In a species with a large PAR, the PAR can even become the most common copy number of the X and make every male look like XXY.

9.2 Markers shared with the X in the Y group

Here 8 of the 40 markers given as Y are in a sequence that also exists on the X, so they have reads in females too. To keep the example short, only one female and one male are analysed.

std_bad <- std
shared <- std_bad$data$Chr == "ChrY" & std_bad$data$Position <= 8e5 &
  std_bad$data$SampleName %in% ex[c("female", "male")]
set.seed(9)
std_bad$data$R[shared] <- rpois(sum(shared), 150)

res_bad <- hmm_estimate_CN_multi(
  std_bad, sample_ids = ex[c("female", "male")], n_cores = 1, cn_grid = 1:4,
  verbose = FALSE, sex_system = "XY", sex_chr = sex_chr
)
count_types(res_bad)$sex

The female now has 8 Y markers covered, above sex_min_markers = 2, so the Y is scored as present. Her PAR and X have the same copy number, which is not possible with a Y, so SexChrConsistent is FALSE and her sex is "?". Qploidy2 flags the conflict, but cannot tell which evidence is wrong. The fix is to remove the non-specific markers from the Y group (see Y-specific markers and likely males). Raising sex_min_markers hides the problem without fixing it.

A sample with a few Y markers covered can also be real: contamination with male DNA, or a female sample mixed with a male one. In both cases the sample is flagged in the same way and deserves a look.

10 When the sex is reported as ?

Sex = "?" (always with SexChr = "?") is a warning flag: the sex-chromosome evidence of the sample contradicts itself, or is not enough to split the PAR copies between X and Y. These samples should be inspected before their sex is used.

Qploidy2 checks the presence of the Y, scored from depth, against the copy numbers called by the HMM. The two must agree:

  • Y present ⇒ the PAR has more copies than the X (PAR − X ≥ 1 Y copy);
  • Y absent ⇒ the PAR and the X have the same number of copies.

When they do not agree, SexChrConsistent is FALSE and the sex is "?":

Situation Possible causes What to check
Y present, but PAR = X Y markers that also have reads from the X (see Markers shared with the X in the Y group); contamination with male DNA; two samples mixed SexHetScore: a low fraction of covered Y markers (e.g. 8/40) points to a few non-specific markers or contamination, nearly all (e.g. 40/40) to a wrong PAR or X call; Y coverage of the reference females
Y absent, but PAR > X Y markers with low depth in this sample (below sex_min_depth) or failed; a wrong PAR or X call SexHetScore and the overall depth of the sample; CN_reliability of the PAR and X windows; plot_cn_track()
PAR < X not possible biologically: markers in the wrong group, or a wrong PAR or X call the marker groups (see Defining the marker groups); CN_reliability

The sex is also "?", with SexChrConsistent NA, when the Y is present but the X has no copy-number call. The PAR then gives only X + Y, which cannot be split: a diploid PAR of 2 could be XY or YY, a tetraploid PAR of 4 could be XXXY, XXYY or XYYY. This happens when no X group is given in sex_chr, or when the X windows were masked by filter_hmm_CN(). For example, without the X group every male of this dataset becomes "?", while the females are still resolved (Y absent, so all PAR copies are X):

ct_y_par <- count_types(res_f, sex_chr = list(Y = "ChrY", PAR = "ChrX_PAR"))
table(true = truth$true_label[match(ct_y_par$sex$Sample, truth$SampleName)],
      inferred_sex = ct_y_par$sex$Sex)
##           inferred_sex
## true        ? female
##   2x X0     0      2
##   2x XX     0     43
##   2x XXY    2      0
##   2x XY    46      0
##   2x XYY    1      0
##   3x XXX    0      1
##   3x XXY    1      0
##   4x XXXX   0      1
##   4x XXYY   1      0
##   5x XXXXX  0      1
##   5x XXXYY  1      0

Sex = NA is different from "?": it means there is no evidence to infer the sex, not conflicting evidence. For example, with no Y markers (or no Y group) and the PAR or X masked, as in When some marker groups are missing; in the "X0" system, when the X copy number is neither the ploidy (female) nor half of it (male); and in the "haplodiploid" system, when the sample ploidy is neither 1 nor 2.

The count_types() summary prints the number of samples to check (Sex chromosomes to check), and they can be listed with:

ct$sex[ct$sex$Sex %in% "?" | ct$sex$SexChrConsistent %in% FALSE, ]

The expected copy numbers of a "?" sample are still estimated from the available evidence, so an X that deviates from them is still reported in karyotype_notation(), but the complement itself should not be trusted until the conflict is explained.

11 When some marker groups are missing

sex_chr does not need all three groups. For "XY" give Y, or both X and PAR:

Groups given How the Y is detected Limits
X, Y, PAR depth of Y markers; Y copies = PAR − X none; recommended
X, PAR Y copies = PAR − X, from copy-number calls only no depth check; SexChrConsistent is NA
Y, PAR depth of Y markers without the X, PAR = X + Y cannot be split: males get "?"
X, Y depth of Y markers; Y copies = ploidy − X no PAR check of the Y copy number

Stored results can be re-read with other groups without re-running the HMM, by passing sex_chr to karyotype_notation(), count_types() or plot_karyotype(). Without the Y markers:

ct_no_y <- count_types(res_f, sex_chr = list(X = "ChrX", PAR = "ChrX_PAR"))
check_no_y <- merge(ct_no_y$sex, truth, by.x = "Sample", by.y = "SampleName")
table(true = check_no_y$true_label, inferred = check_no_y$SexChr)
##           inferred
## true       X0 XX XXX XXXX XXXXX XXXYY XXY XXYY XY XYY
##   2x X0     2  0   0    0     0     0   0    0  0   0
##   2x XX     0 43   0    0     0     0   0    0  0   0
##   2x XXY    0  0   0    0     0     0   2    0  0   0
##   2x XY     0  0   0    0     0     0   0    0 43   0
##   2x XYY    0  0   0    0     0     0   0    0  0   1
##   3x XXX    0  0   1    0     0     0   0    0  0   0
##   3x XXY    0  0   0    0     0     0   1    0  0   0
##   4x XXXX   0  0   0    1     0     0   0    0  0   0
##   4x XXYY   0  0   0    0     0     0   0    1  0   0
##   5x XXXXX  0  0   0    0     1     0   0    0  0   0
##   5x XXXYY  0  0   0    0     0     1   0    0  0   0

The complements are the same, computed from copy numbers only, but three XY males are missing from the table: those whose PAR windows were masked by the filter. Without the Y markers, the number of Y copies can only come from PAR − X, so their complement is unknown (NA). With the Y markers, their sex is still known from depth. This is why giving all three groups is recommended.

12 Other systems

The other systems use the same arguments.

# ZW (birds, Lepidoptera, some strawberries): standardize with ZZ males
hmm_estimate_CN_multi(std, sex_system = "ZW",
                      sex_chr = list(Z = "ChrZ", W = "ChrW", PAR = "ChrZ_PAR"))

# X0: only the X; sex from the number of X copies
hmm_estimate_CN_multi(std, sex_system = "X0", sex_chr = list(X = "ChrX"))

# Haplodiploid: no sex_chr; sex from the sample ploidy (1x male, 2x female)
hmm_estimate_CN_multi(std, cn_grid = 1:3, sex_system = "haplodiploid")

In the haplodiploid system a diploid male cannot be told apart from a female.

These systems have not yet been tested with real datasets. Please contact us if you plan to use them.

13 Notes for array data

  • On arrays, Y-specific probes give background signal in females, not zero. Set sex_min_depth above the female background of the R values (check them in known females first).
  • With 0 in cn_grid (grid route, array data), the HMM can also call a copy number of 0, and the Y presence can be read from copy-number calls. The depth score is still used when available.

14 Summary

  1. Choose the sex_system of your species.
  2. Split the sex-chromosome markers into X-specific, Y-specific and PAR groups, with one chromosome ID per group in geno.pos. Use known females: Y-specific markers have no reads in them, and the likely males (with Y reads) are not heterozygous in the X-specific region.
  3. Make sure X and Y markers are specific: no Y marker covered in females, no PAR marker left in the X group.
  4. Standardize with at least 30 known females (males in ZW species) as the reference, in genos, and all samples in data.
  5. Pass sex_system and sex_chr to hmm_estimate_CN_multi(). Check the windows with low CN_reliability: when the BAF shows one copy fewer than the call, re-run the sample with max_cn_dev = 1 and replace it with update_hmm_CN_multi(). Mask the remaining unreliable windows with filter_hmm_CN().
  6. Read the sex and complement in count_types()$sex or karyotype_notation(), and inspect every sample with Sex = "?" or SexChrConsistent = FALSE.

15 How to cite

Run citation("Qploidy2") in R for the references in BibTeX format.

15.1 Qploidy2: HMM and grid-approach BAF model selection

Manuscript in preparation. Until it is published, please cite the software with its Research Resource Identifier, RRID:SCR_028622, and the package version you used:

Taniguti, C. H. et al. Qploidy2: Estimation of large-scale copy number variation using genotyping data. Manuscript in preparation. R package available at https://github.com/Breeding-Insight/Qploidy2 (RRID:SCR_028622).

15.2 Qploidy: standardization

Taniguti, C. H., Lau, J., Hochhaus, T., Arias, D. C. L., Hokanson, S. C., Zlesak, D. C., Byrne, D. H., Klein, P. E., & Riera-Lizarazu, O. (2025). Exploring chromosomal variations in garden roses: Insights from high-density SNP array data and a new tool, Qploidy. The Plant Genome, e70044. https://doi.org/10.1002/tpg2.70044

15.3 nQuack: EM-approach BAF model selection

Gaynor, M., Landis, J., O’Connor, T., Laport, R., Doyle, J., Soltis, D., Ponciano, J., & Soltis, P. (2024). nQuack: An R package for predicting ploidal level from sequence data using site-based heterozygosity. Applications in Plant Sciences, 12(4), e11606. https://doi.org/10.1002/aps3.11606

16 Acknowledgments

16.1 Qploidy version 1.0.0

This work was funded in part by the Robert E. Basye Endowment in Rose Genetics, Dept. of Horticultural Sciences, Texas A&M University, and by USDA’s National Institute of Food and Agriculture (NIFA) Specialty Crop Research Initiative (SCRI) projects “Tools for Genomics-Assisted Breeding in Polyploids: Development of a Community Resource” (Award No. 2020-51181-32156) and “Developing Sustainable Rose Landscapes via Rose Rosette Disease Education, Socioeconomic Assessments, and Breeding RRD-Resistant Roses with Stable Black Spot Resistance” (Award No. 2022-51181-38330).

16.2 Qploidy versions after 1.0.0 and Qploidy2

Supported by Breeding Insight.

16.3 Use of AI tools

Parts of the code, unit tests, and documentation of Qploidy2 were developed with the assistance of GitHub Copilot and Claude Code (Anthropic; Claude Opus and Sonnet models), used for code review, bug fixing, implementing features specified by the authors, writing tests, and drafting documentation. All AI-assisted changes were reviewed, tested, and approved by the package authors, who take full responsibility for the code and its scientific content.