calculateWeightedEuclideanDistanceFor2Samples: Calculate Weighted Euclidean distance-based metric between...

View source: R/CNVMetricsLog2ratioInternalMethods.R

calculateWeightedEuclideanDistanceFor2SamplesR Documentation

Calculate Weighted Euclidean distance-based metric between samples.

Description

The weighted Euclidean distance-based metric corresponds to the euclidean distance between 2 samples multiplied by the natural logarithm of the number of bases of the analyzed segment. The final metric is 1 over 1 added to the squared sum of the values obtained for all segments that are not excluded of the analysis.

Usage

calculateWeightedEuclideanDistanceFor2Samples(segmentData, minThreshold)

Arguments

segmentData

a list marked as a preMetricSegments class that contains the disjoint segment information from 2 samples and the log2ratio values of the samples in the metadata columns.

minThreshold

a single numeric setting the minimum value to consider two segments as different for the metric calculation. If the absolute difference is below or equal to threshold, the value will be replaced by zero.

Details

The weighted euclidean distance is 1/(1 + (\sum((x_i - y_i)^2 * log2(nbrBases_i))^0.5) where x and y are the values of 2 samples for a specific segment i and nbrBases the number of bases of the segment i.

Value

a numeric representing the weighted euclidean distance between the two samples. If the distance cannot be calculated as the two samples don't share any segments with log2ratio value, the value NA is assigned.

Author(s)

Astrid DeschĂȘnes

Examples


## Load required package to generate the two samples
require(GenomicRanges)

# Create first Granges representing first sample
sample01 <- GRanges(seqnames="chr1",
    ranges=IRanges(start=c(100, 201, 400), end=c(200, 350, 500)),
    strand="*", log2ratio=c(0.3091175, 0.4582058, -0.3798390))

# Create second Granges representing second sample
sample02 <- GRanges(seqnames="chr1",
    ranges=IRanges(start=c(150, 200, 450), end=c(250, 350, 500)),
    strand="*", log2ratio=c(0.222174, 0.3282156, -0.2728292))

# Create disjoint segment using the 2 samples and without any region
# excluded from the analysis (parameter bedExclusion set to null)
disjoinGRange <- CNVMetrics:::createDisjoinSegmentsForTwoSamples(
    segmentDataSample1=sample01, segmentDataSample2=sample02, 
    bedExclusion=NULL)

## Calculate the weighted ecucidean distance between the two samples
CNVMetrics:::calculateWeightedEuclideanDistanceFor2Samples(
    segmentData=disjoinGRange, minThreshold=0.2)


KrasnitzLab/CNVMetrics documentation built on July 30, 2023, 2:22 p.m.