Learn R Programming

BGData (version 2.4.1)

segments: Find non-overlapping segments based on a summary statistic

Description

Given a summary statistic and a threshold, this function computes the number of non-overlapping segments, each defined as a discovery (i.e., statistic[i] <= threshold) +/- a gap, in the same units as bp (often base-pair position).

Usage

segments(statistic, chr, bp, threshold, gap, trim = FALSE, verbose = FALSE)

Value

A data frame containing the following information:

chr

Chromosome

start

Index where segment starts within statistic.

end

Index where segment ends within statistic.

length

Length of segment.

bpStart

Base-pair position where segment starts.

bpEnd

Base-pair position where segment ends.

bpLength

Length of segment in base-pair positions.

minValue

Smallest value of statistic within segment.

minValuePos

Position of variant with the smallest value of statistic within segment.

Arguments

statistic

A statistic (e.g., BFDR or p-values).

chr

A vector containing the chromosome for each value of statistic.

bp

A vector containing the base-pair positions for each value of statistic.

threshold

The threshold to determine 'significance' (e.g., 1e-5 for p-values).

gap

1/2 of the length of the desired segments.

trim

Whether to collapse segments that were artifically inflated by gap. Defaults to FALSE.

verbose

Whether progress updates will be posted. Defaults to FALSE.

Examples

Run this code
library(BGData)

# Load example data
bg <- BGData:::loadExample()

# Perform GWAS
pValues <- GWAS(
    formula = FT10 ~ 1,
    data = bg,
    method = "rayOLS"
)

# Determine segments within +/- 1MB from a significant variant
segments <- segments(
    statistic = pValues[, 4],
    chr = map(bg)$chromosome,
    bp = map(bg)$base_pair_position,
    threshold = 1e-5,
    gap = 1e6,
    trim = FALSE,
    verbose = FALSE
)

Run the code above in your browser using DataLab