## Load PubChem SDFset sample
data(sdfsample); sdfset <- sdfsample
cid(sdfset) <- sdfid(sdfset)
## Convert base 64 encoded fingerprints to character vector or binary matrix
fpset <- fp2bit(sdfset)
## Alternatively, one can use atom pair fingerprints
## Not run:
# fpset <- desc2fp(sdf2ap(sdfset))
# ## End(Not run)
## Pairwise compound structure comparisons
fpSim(x=fpset[1], y=fpset[2], method="Tanimoto")
## Structure similarity searching: x is query and y is fingerprint database
fpSim(x=fpset[1], y=fpset)
## Controlling the output
fpSim(x=fpset[1], y=fpset, method="Tversky", cutoff=0.4, top=4, alpha=0.5, beta=1)
## Use custom distance function
myfct <- function(a, b, c, d) c/(a+b+c+d)
fpSim(x=fpset[1], y=fpset, method=myfct)
## Compute fingerprint-based Tanimoto similarity matrix
simMA <- sapply(cid(fpset), function(x) fpSim(x=fpset[x], fpset, sorted=FALSE))
## Hierarchical clustering with simMA as input
hc <- hclust(as.dist(1-simMA), method="single")
## Plot hierarchical clustering tree
plot(as.dendrogram(hc), edgePar=list(col=4, lwd=2), horiz=TRUE)
Run the code above in your browser using DataLab