Pages

Tuesday, October 22, 2013

Fast Tanimoto Similarity Calculation using rcdk

Well many of you ,who are using r for cheminformatics must be knowing rcdk . Regarding the tanimoto calculation i have seen it seem it takes a long time to calculate the code in rcdk code looks neat but still the similarity calculation can be performed much faster using the inner products.Below given a simple code to do that and also the time taken is like 10 times faster than the rcdk code. Quite an impressive performance boost . I have made a pull request to Rajarshi's code, it should be available soon in the main package.


##Consider m is the binary matrix of 0 and 1 which you calculated using fp.sim.matrix###


Time taken for the new method
user  system elapsed 
  2.962   0.012   2.971 

#Normal method in rcdk

user  system elapsed 
 43.644   0.064  43.707 


Dynamic plots with R Studio.


Few days back i came to know that R Studio provides dynamic plots like you can plot histograms and move sliders, tick check boxes and also you can select from the drop down list the items you want to display from your dataset.I will provide some examples of this below. Quite cool enough from Rstudio group.

//Sliders
library(mosaic)
if(require(manipulate)) {
manipulate(
histogram( ~ eruptions, data=faithful, n=n),
n = slider(5,40)
)

}

//CheckBoxes
library(mosaic)
if(require(manipulate)) {
manipulate(
histogram( ~ age, data=HELP, n=n, density=density),
n = slider(5,40),
density = checkbox()
)
}

Check box with density plot



//Dropdowns

library(mosaic)
if(require(manipulate)) {
manipulate(
histogram( ~ age, data=HELP, n=n, fit=distribution, dlwd=4),
n = slider(5,40),
distribution =
picker('normal', 'gamma', 'exponential', 'lognormal',
label="distribution")
)
}


//dropdown and density

library(mosaic)
manipulate(
  histogram(as.matrix(mtcars[,factor]), 
          beside = TRUE, main = factor,density=density),
  factor = picker("mpg", "disp", "hp","drat","wt"),density = checkbox())



This way you can make your ggplots dynamic with the manipulate package.