Previously, I shared with the world a function to create a pairwise matrix of the number of transitions and transversions between two DNA sequences. Klaus Schliep kindly pointed out the possibility of a bug in the function and offered a faster, more accurate version. Thanks Klaus!

titv<-function(dat){

mat<-as.matrix(dat)

res<-matrix(NA, ncol=dim(mat)[1], nrow=dim(mat)[1], dimnames=list(x=names(dat), y=names(dat)))

for(i in 1:(dim(mat)[1] – 1)){

for(j in (i+1):dim(mat)[1]){

vec<-as.numeric(mat[i,])+as.numeric(mat[j,])-8

res[j,i]<-sum(!is.na(match(vec,c(200,56))))#Transitions

res[i,j]<-sum(!is.na(match(vec,c(152,168,88,104))))#Transversions

}

}

res

}

The previous version of the function considered the difference between an unknown base (coded as N) and a T as a transition. The new version does not detect this difference.

*Related*

To

**leave a comment** for the author, please follow the link and comment on their blog:

** The Praise of Insects**.

R-bloggers.com offers

**daily e-mail updates** about

R news and

tutorials on topics such as:

Data science,

Big Data, R jobs, visualization (

ggplot2,

Boxplots,

maps,

animation), programming (

RStudio,

Sweave,

LaTeX,

SQL,

Eclipse,

git,

hadoop,

Web Scraping) statistics (

regression,

PCA,

time series,

trading) and more...

If you got this far, why not

__subscribe for updates__ from the site? Choose your flavor:

e-mail,

twitter,

RSS, or

facebook...