Type: Package
Title: Visualize and Parse the Output of 'BeXY'
Version: 0.1.3
Maintainer: Madleina Caduff <madleina.caduff@unifr.ch>
Description: Provides functions for summarizing and plotting the output of the command-line tool 'BeXY' (https://bitbucket.org/wegmannlab/bexy), a tool that performs Bayesian inference of sex chromosome karyotypes and sex-linked scaffolds from low-depth sequencing data.
License: GPL-2
Encoding: UTF-8
Imports: TeachingDemos,Ternary
RoxygenNote: 7.3.1
NeedsCompilation: no
Packaged: 2024-08-23 13:08:09 UTC; madleina
Author: Madleina Caduff [aut, cre], Raphael Eckel [ctb], Christoph Leuenberger [ctb], Daniel Wegmann [aut]
Repository: CRAN
Date/Publication: 2024-08-23 13:30:02 UTC

Function to create a legend

Description

Function to create a legend

Usage

.addLegend.bexy(x_coord, y_coord, colors)

Arguments

x_coord

The x-coordinate for legend.

y_coord

The y-coordinate for legend.

colors

A vector of length three with the colors for aneuploid, XX and XY samples, respectively.

Value

No return value, called for side effects.


Function to create a legend for autosomal trisomy

Description

Function to create a legend for autosomal trisomy

Usage

.addLegendAutosomalTrisomy.bexy(x_coord, y_coord, scaffoldName, colors)

Arguments

x_coord

The x-coordinate for legend.

y_coord

The y-coordinate for legend.

scaffoldName

The name of the scaffold to plot (has to be an autosome).

colors

A vector of length two with the colors for triploid and diploid samples, respectively.

Value

No return value, called for side effects.


Function that returns all possible autosomal trisomy states used in BeXY

Description

Function that returns all possible autosomal trisomy states used in BeXY

Usage

.getAllPossibleAutosomalTrisomy.bexy(scaffoldName)

Arguments

scaffoldName

A vector of size one with the name of a scaffold.

Value

A vector of characters.


Function that returns all possible scaffold types used in BeXY

Description

Function that returns all possible scaffold types used in BeXY

Usage

.getAllPossibleScaffoldTypes.bexy()

Value

A vector of characters.


Function that returns all possible sex karyotypes used in BeXY

Description

Function that returns all possible sex karyotypes used in BeXY

Usage

.getAllPossibleSexKaryotypes.bexy()

Value

A vector of characters.


Function to extract specific columns from a data frame or matrix

Description

Function to extract specific columns from a data frame or matrix

Usage

.getColumns.bexy(what, name)

Arguments

what

A matrix or data frame

name

The name of the parameter to extract.

Value

A subset of the matrix or data frame containing only the columns whose names match the argument 'name'


Function that returns the index of a given scaffold

Description

Function that returns the index of a given scaffold

Usage

.getIndexScaffold.bexy(object, scaffoldName, takeIfNotFound)

Arguments

object

A bexy object.

scaffoldName

A string representing the name of a scaffold.

takeIfNotFound

A string ("X-linked" or "Y-linked") that denotes the type of scaffold to use if scaffoldName could not be found

Value

A single integer representing the index of the scaffold.


Function that returns the index of a given scaffold & checks if it is valid for autosomal trisomy

Description

Function that returns the index of a given scaffold & checks if it is valid for autosomal trisomy

Usage

.getIndexScaffoldAutosomalTrisomy.bexy(object, scaffoldName)

Arguments

object

A bexy object.

scaffoldName

A vector of size one with the name of a scaffold.

Value

A list containing the index of the scaffold within posterior_mode_z and counts.


Function that transforms state posteriors of sex karyotype to ternary-format

Description

Function that transforms state posteriors of sex karyotype to ternary-format

Usage

.getInputTernary.bexy(object)

Arguments

object

A bexy object.

Value

A matrix with 3 rows: P(aneuploid), P(XX), P(XY).


Function to select samples that should be highlighted

Description

Function to select samples that should be highlighted

Usage

.getSamplesToHighlight.bexy(object, sampleNamesToHighlight)

Arguments

object

A bexy object.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

Value

A vector of integers corresponding to indices of samples to highlight


Function to select samples that should be highlighted for autosomal trisomy

Description

Function to select samples that should be highlighted for autosomal trisomy

Usage

.getSamplesToHighlightAutosomalTrisomy.bexy(object, ix, sampleNamesToHighlight)

Arguments

object

A bexy object.

ix

A list containing the index of a specific scaffold within z.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

Value

A vector of integers corresponding to indices of samples to highlight


Function that returns the scaffold names of z

Description

Function that returns the scaffold names of z

Usage

.getScaffoldNames.bexy(names_z, numSamples)

Arguments

names_z

A character vector with the column names of z

numSamples

The number of samples

Value

A vector of characters.


Function to get the width of a string on the current plotting device in user coordinates

Description

Function to get the width of a string on the current plotting device in user coordinates

Usage

.getStringWidth.bexy(name)

Arguments

name

A string.

Value

The width of the input string on the current plotting device in user coordinates.


Function to open a file and generate error message if it was not found

Description

Function to open a file and generate error message if it was not found

Usage

.openFile.bexy(path, files, patterns)

Arguments

path

A file path.

files

A vector of character strings corresponding to file names found in the path.

patterns

A vector of patterns to search for within 'files'.

Value

A file connection.


Function to plot counts of a specific autosome and color them according to BeXY posterior mode of autosomal trisomy

Description

Function to plot counts of a specific autosome and color them according to BeXY posterior mode of autosomal trisomy

Usage

.plotAutosomalTrisomy.bexy(
  object,
  scaffoldName,
  plotCounts,
  colors,
  sampleNamesToHighlight,
  label,
  ...
)

Arguments

object

A bexy object.

scaffoldName

The name of the scaffold to plot (has to be an autosome)

plotCounts

A boolean. If TRUE, the counts are plotted. If FALSE, the posterior probabilities are plotted.

colors

A vector of length two with the colors for diploid and triploid samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

...

Other parameters used for plotting

Value

No return value, called for side effects.


Function to plot a ternary plot of the probabilities for being aneuploid, XX or XY

Description

Function to plot a ternary plot of the probabilities for being aneuploid, XX or XY

Usage

.plotTernary.bexy(object, colors, sampleNamesToHighlight, label, ...)

Arguments

object

A bexy object.

colors

A vector of length three with the colors for aneuploid, XX and XY samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

...

More parameters passed to TernaryPlot()

Value

The upper boundary of the plot.


Function to plot ternary plot with 7-cell plots displaying posterior probabilities of karyotypes

Description

Function to plot ternary plot with 7-cell plots displaying posterior probabilities of karyotypes

Usage

.plotTernaryAndTicTacToe.bexy(
  object,
  colors,
  sampleNamesToHighlight,
  label,
  addSquares,
  ...
)

Arguments

object

A bexy object.

colors

A vector of length three with the colors for aneuploid, XX and XY samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

addSquares

Boolean indicating whether 7-cell posterior probability square plots should be drawn.

...

Other parameters used for plotting

Value

No return value, called for side effects.


Function to plot a single 7-cell plot displaying posterior probabilities of karyotypes

Description

Function to plot a single 7-cell plot displaying posterior probabilities of karyotypes

Usage

.plotTicTacToeWithCoordinates.bexy(
  object,
  ix,
  label,
  x_coords,
  y_coords,
  last,
  colors
)

Arguments

object

A bexy object.

ix

The sample index.

label

The sample name used as a label.

x_coords

Left and right x-coordinates for 7-cell plot.

y_coords

Bottom and top y-coordinates for 7-cell plot.

last

Boolean indicating if this is the last sample to be plotted.

colors

A vector of length three with the colors for aneuploid, XX and XY samples, respectively.

Value

No return value, called for side effects.


Function to plot X vs Y counts and color them according to BeXY posterior mode

Description

Function to plot X vs Y counts and color them according to BeXY posterior mode

Usage

.plotXVsY.bexy(object, ix_X, ix_Y, colors, sampleNamesToHighlight, label, ...)

Arguments

object

A bexy object.

ix_X

An integer representing the index of the scaffold to be plotted on the x-axis.

ix_Y

An integer representing the index of the scaffold to be plotted on the y-axis.

colors

A vector of length three with the colors for aneuploid, XX and XY samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

...

Other parameters used for plotting

Value

No return value, called for side effects.


Function to reformat column names

Description

Function to reformat column names

Usage

.renameHeader.bexy(file, pattern)

Arguments

file

A file whose header should be renamed.

pattern

Where to split.

Value

A new file with re-formatted column names.


Accurate Bayesian inference of sex chromosome karyotypes and sex-linked scaffolds from low-depth sequencing data

Description

Visualization of results produced by BeXY

Usage

bexy(path = NULL, readMCMCTrace = FALSE)

Arguments

path

The path where all the output files of BeXY are located. If NULL, the example files will be loaded.

readMCMCTrace

If TRUE, read the full trace of the MCMC of all parameters (potentially slow).

Value

An object of type bexy.


Getting posterior mean rho (ploidy ratio parameter) for each scaffold

Description

Getting posterior mean rho (ploidy ratio parameter) for each scaffold

Usage

getPosteriorMeanRho(object)

Arguments

object

A bexy object.

Value

A numeric vector containing the posterior mean of rho for each scaffold

See Also

bexy

Examples

bex <- bexy()
getPosteriorMeanRho(bex)

Getting the posterior mode for each autosomal trisomy

Description

Getting the posterior mode for each autosomal trisomy

Usage

getPosteriorModeAutosomalTrisomy(
  object,
  scaffoldName,
  threshold_certainty = 0.9
)

Arguments

object

A bexy object.

scaffoldName

The scaffold name, must be an autosome.

threshold_certainty

The threshold for certainty on the posterior probabilities. All samples that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

A character vector containing the trisomy classification for each sample for the given scaffold

See Also

bexy

Examples

bex <- bexy()
getPosteriorModeAutosomalTrisomy(bex, "21")

Getting the posterior mode for each scaffold type

Description

Getting the posterior mode for each scaffold type

Usage

getPosteriorModeScaffoldTypes(object, threshold_certainty = 0.9)

Arguments

object

A bexy object.

threshold_certainty

The threshold for certainty on the posterior probabilities. All scaffolds that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

A character vector containing the scaffold type classification for each scaffold

See Also

bexy

Examples

bex <- bexy()
getPosteriorModeScaffoldTypes(bex)

Getting the posterior mode for each sex karyotype

Description

Getting the posterior mode for each sex karyotype

Usage

getPosteriorModeSexKaryotypes(object, threshold_certainty = 0.9)

Arguments

object

A bexy object.

threshold_certainty

The threshold for certainty on the posterior probabilities. All samples that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

A character vector containing the sex karyotype classification for each sample

See Also

bexy

Examples

bex <- bexy()
getPosteriorModeSexKaryotypes(bex)

Getting all samples classified as a certain autosomal trisomy

Description

Getting all samples classified as a certain autosomal trisomy

Usage

getSamplesWithAutosomalTrisomy(object, scaffoldName, threshold_certainty = 0.9)

Arguments

object

A bexy object.

scaffoldName

The scaffold name, must be an autosome.

threshold_certainty

The threshold for certainty on the posterior probabilities. All samples that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

A character vector containing all sample names that are classified as having an autosomal trisomy of scaffold 'scaffoldName'

See Also

bexy

Examples

bex <- bexy()
getSamplesWithAutosomalTrisomy(bex, "21")

Getting all samples classified as a specific sex karyotype

Description

Getting all samples classified as a specific sex karyotype

Usage

getSamplesWithThisKaryotype(object, karyotype, threshold_certainty = 0.9)

Arguments

object

A bexy object.

karyotype

One specific sex karyotype, can be XY, XX, X0, XXY, XYY, XXX or XXYY.

threshold_certainty

The threshold for certainty on the posterior probabilities. All samples that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

A character vector containing all sample names that are classified as the sex karyotype given by argument 'karyotype'.

See Also

bexy

Examples

bex <- bexy()
getSamplesWithThisKaryotype(bex, "XX")

Getting all scaffolds classified as a specific scaffold type

Description

Getting all scaffolds classified as a specific scaffold type

Usage

getScaffoldsWithThisType(object, type, threshold_certainty = 0.9)

Arguments

object

A bexy object.

type

One specific scaffold type, can be Autosome, Y-linked, X-linked or Different.

threshold_certainty

The threshold for certainty on the posterior probabilities. All scaffolds that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

A character vector containing all scaffold names that are classified as the scaffold type given by argument 'type'.

See Also

bexy

Examples

bex <- bexy()
getScaffoldsWithThisType(bex, "X-linked")

Plotting a bexy object. To customize the plots, please call the respective plotting functions directly (e.g. plotTernary, plotCounts, plotBars...).

Description

Plotting a bexy object. To customize the plots, please call the respective plotting functions directly (e.g. plotTernary, plotCounts, plotBars...).

Usage

## S3 method for class 'bexy'
plot(x, ...)

Arguments

x

A bexy object.

...

Other parameters used for plotting.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
plot(bex)

Plotting the autosomal trisomies

Description

Plotting the autosomal trisomies

Usage

plotAutosomalTrisomy(
  x,
  scaffoldName,
  colors = c("deepskyblue4", "darkred"),
  sampleNamesToHighlight = c(),
  label = TRUE,
  ...
)

Arguments

x

A bexy object.

scaffoldName

The name of the scaffold to plot (has to be an autosome)

colors

A vector of length two with the colors for diploid and triploid samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

...

Other parameters used for plotting.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
plotAutosomalTrisomy(bex, "21")

Plotting the autosomal trisomies: counts on that scaffold

Description

Plotting the autosomal trisomies: counts on that scaffold

Usage

plotAutosomalTrisomyCounts(
  x,
  scaffoldName,
  colors = c("deepskyblue4", "darkred"),
  sampleNamesToHighlight = c(),
  label = TRUE,
  ...
)

Arguments

x

A bexy object.

scaffoldName

The name of the scaffold to plot (has to be an autosome)

colors

A vector of length two with the colors for diploid and triploid samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

...

Other parameters used for plotting.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
plotAutosomalTrisomyCounts(bex, "21")

Plotting the autosomal trisomies: posterior probabilities

Description

Plotting the autosomal trisomies: posterior probabilities

Usage

plotAutosomalTrisomyPosteriorProbabilities(
  x,
  scaffoldName,
  colors = c("deepskyblue4", "darkred"),
  sampleNamesToHighlight = c(),
  label = TRUE,
  ...
)

Arguments

x

A bexy object.

scaffoldName

The name of the scaffold to plot (has to be an autosome)

colors

A vector of length two with the colors for diploid and triploid samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

...

Other parameters used for plotting.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
plotAutosomalTrisomyPosteriorProbabilities(bex, "21")

Plotting a barplot with the posterior probabilities of each sex karyotype per sample

Description

Plotting a barplot with the posterior probabilities of each sex karyotype per sample

Usage

plotBars(
  x,
  colors = c("lightblue", "lightpink", "khaki", "maroon1", "dodgerblue3", "red4", "navy"),
  maxNumSamplesPerPlot = 100,
  sortByKaryotype = TRUE,
  sampleNames = c(),
  ...
)

Arguments

x

A bexy object.

colors

A vector of length 7 with the colors for XY, XX, X0, XXY, XYY, XXX and XXYY, respectively.

maxNumSamplesPerPlot

How many samples to place next to each other into one barplot. If there are more samples, multiple barplots will be generated. This is to ensure that the labels are readable.

sortByKaryotype

If TRUE, the samples (i.e. the bars) are ordered by the posterior mode of the sex karyotype.

sampleNames

A vector of sample names that represents the order in which the bars are plotted. Overrides any argument given to sortByKaryotype.

...

Other parameters used for plotting.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
plotBars(bex)

Plotting the percentage of counts mapping to two scaffolds (by default a Y-linked scaffold against a X-linked scaffold), colored by sex karyotype

Description

Plotting the percentage of counts mapping to two scaffolds (by default a Y-linked scaffold against a X-linked scaffold), colored by sex karyotype

Usage

plotCounts(
  x,
  scaffoldX = NULL,
  scaffoldY = NULL,
  colors = c("turquoise3", "darkorange", "royalblue4"),
  sampleNamesToHighlight = c(),
  label = TRUE,
  ...
)

Arguments

x

A bexy object.

scaffoldX

A string with the name of the scaffold to be plotted on the x-axis. If NULL (default), a X-linked scaffold is used.

scaffoldY

A string with the name of the scaffold to be plotted on the y-axis. If NULL (default), a Y-linked scaffold is used.

colors

A vector of length three with the colors for aneuploid, XX and XY samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

...

Other parameters used for plotting.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
plotCounts(bex)

Plot the MCMC trace for a specific parameter

Description

Plot the MCMC trace for a specific parameter

Usage

plotMCMCTrace(object, parameterName, maxNumPlots = 20)

Arguments

object

A bexy object.

parameterName

The name of the parameter to plot (e.g. rho, logSigma, epsilon, s, t, a, f, ...)

maxNumPlots

The maximum number of plots to plot, default 20.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy(readMCMCTrace = TRUE)
plotMCMCTrace(bex, "rho", maxNumPlots = 1)

Plotting the ternary of a bexy object

Description

Plotting the ternary of a bexy object

Usage

plotTernary(
  x,
  colors = c("turquoise3", "darkorange", "royalblue4"),
  sampleNamesToHighlight = c(),
  label = TRUE,
  addSquares = TRUE,
  ...
)

Arguments

x

A bexy object.

colors

A vector of length three with the colors for aneuploid, XX and XY samples, respectively.

sampleNamesToHighlight

A vector of sample names that should be highlighted. If empty, samples are automatically highlighted based on the posterior probabilities.

label

Boolean indicating whether samples should be labeled.

addSquares

Boolean indicating whether 7-cell posterior probability square plots should be drawn.

...

Other parameters used for plotting.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
plotTernary(bex)

Printing a bexy object

Description

Printing a bexy object

Usage

## S3 method for class 'bexy'
print(x, ...)

Arguments

x

A bexy object.

...

Additional parameters passed to print functions.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
print(bex)

Summarizing a bexy object

Description

Summarizing a bexy object

Usage

## S3 method for class 'bexy'
summary(object, ...)

Arguments

object

A bexy object.

...

Additional parameters passed to summary functions.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
print(bex)

Write a file with the posterior mode for each autosomal trisomy

Description

Write a file with the posterior mode for each autosomal trisomy

Usage

writePosteriorModeAutosomalTrisomies(
  object,
  scaffoldName,
  file,
  threshold_certainty = 0.9
)

Arguments

object

A bexy object.

scaffoldName

The scaffold name, must be an autosome.

file

The name of the output file.

threshold_certainty

The threshold for certainty on the posterior probabilities. All samples that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
tf <- tempfile(fileext = ".txt")
writePosteriorModeAutosomalTrisomies(bex, "21", tf)

Write a file with the posterior mode for each scaffold type

Description

Write a file with the posterior mode for each scaffold type

Usage

writePosteriorModeScaffoldTypes(object, file, threshold_certainty = 0.9)

Arguments

object

A bexy object.

file

The name of the output file.

threshold_certainty

The threshold for certainty on the posterior probabilities. All scaffolds that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
tf <- tempfile(fileext = ".txt")
writePosteriorModeScaffoldTypes(bex, tf)

Write a file with the posterior mode for each sex karyotype

Description

Write a file with the posterior mode for each sex karyotype

Usage

writePosteriorModeSexKaryotypes(object, file, threshold_certainty = 0.9)

Arguments

object

A bexy object.

file

The name of the output file.

threshold_certainty

The threshold for certainty on the posterior probabilities. All samples that have a posterior probability less than this threshold are classified as 'uncertain'.

Value

No return value, called for side effects.

See Also

bexy

Examples

bex <- bexy()
tf <- tempfile(fileext = ".txt")
writePosteriorModeSexKaryotypes(bex, tf)