Learn R Programming

RFLPtools (version 2.0)

sim2dist: Convert similarity matrix to dist object.

Description

Function to convert similarity matrix to object of S3 class "dist".

Usage

sim2dist(x, maxSim = 1)

Arguments

x

symmetric matrix: similarity matrix.

maxSim

maximum similarity possible.

Value

Object of S3 class "dist" is returned; see dist.

Details

Similarity is converted to distance by maxSim - x. The resulting matrix is converted to an object of S3 class "dist" by as.dist

References

Flessa, F., Kehl, A., Kohl, M. Analysing diversity and community structures using PCR-RFLP: a new software application. Molecular Ecology Resources 2013 Jul; 13(4):726-33.

See Also

BLASTdata, simMatrix

Examples

Run this code
# NOT RUN {
data(BLASTdata)

## without sequence range
# }
# NOT RUN {
res <- simMatrix(BLASTdata)
# }
# NOT RUN {
## with sequence range
range(BLASTdata$alignment.length)
res1 <- simMatrix(BLASTdata, sequence.range = TRUE, Min = 100, Max = 450)
res2 <- simMatrix(BLASTdata, sequence.range = TRUE, Min = 500)

## visualize similarity matrix
library(MKomics)
simPlot(res2, minVal = 0, 
        labels = colnames(res2), title = "(Dis-)Similarity Plot")


## or
library(lattice)
myCol <- colorRampPalette(brewer.pal(8, "RdYlGn"))(128)
levelplot(res2, col.regions = myCol,
          at = do.breaks(c(0, max(res2)), 128),
          xlab = "", ylab = "",
          ## Rotate label of x axis
          scales = list(x = list(rot = 90)),
          main = "(Dis-)Similarity Plot")

## convert to distance
res.d <- sim2dist(res2)

## hierarchical clustering
plot(hclust(res.d))
# }

Run the code above in your browser using DataLab