[Seqinr-commits] r1737 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Mar 7 12:12:46 CET 2010
Author: lobry
Date: 2010-03-07 12:12:45 +0100 (Sun, 07 Mar 2010)
New Revision: 1737
Added:
pkg/R/rho.R
Log:
rho() has gained a wordsize argument as suggested by Avril Coghlan
Added: pkg/R/rho.R
===================================================================
--- pkg/R/rho.R (rev 0)
+++ pkg/R/rho.R 2010-03-07 11:12:45 UTC (rev 1737)
@@ -0,0 +1,16 @@
+rho <- function (sequence, wordsize = 2, alphabet = s2c("acgt"))
+{
+ wordcount <- count(sequence, wordsize, freq = FALSE, alphabet = alphabet)
+ uni <- count(sequence, 1, freq = TRUE, alphabet = alphabet)
+
+ expected_wordfreq <- function (wordsize, uni)
+ {
+ if (wordsize == 1)
+ return(uni)
+ else kronecker(uni, expected_wordfreq(wordsize - 1, uni))
+ }
+
+ expected_wordcount <- sum(wordcount)*expected_wordfreq(wordsize, uni)
+
+ return(wordcount/expected_wordcount)
+}
More information about the Seqinr-commits
mailing list