Skip to content

Commit

Permalink
Add phicoef() (will be needed for "Overlap encodings" vignette).
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Jun 20, 2012
1 parent 5c2db51 commit 5a1eec9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Suggests: Biostrings (>= 2.25.3), Rsamtools (>= 1.9.15), BSgenome,
RUnit
License: Artistic-2.0
Collate: utils.R
phicoef.R
cigar-utils.R
transcript-utils.R
constraint.R
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ exportClasses(
)

export(
phicoef,

validCigar, cigarOpTable,
cigarToQWidth, cigarToWidth, cigarQNarrow, cigarNarrow,
cigarToIRanges, cigarToIRangesListByAlignment, cigarToIRangesListByRName,
Expand Down
29 changes: 29 additions & 0 deletions R/phicoef.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### Based on http://en.wikipedia.org/wiki/Phi_coefficient

phicoef <- function(x, y=NULL)
{
if (is.null(y)) {
if (!is.integer(x) || length(x) != 4L)
stop("when 'y' is not supplied, 'x' must be a 2x2 integer matrix ",
"or a vector of length 4")
a <- x[1L]
c <- x[2L]
b <- x[3L]
d <- x[4L]
} else {
if (!is.logical(x) || !is.logical(y) || length(x) != length(y))
stop("when 'y' is supplied, 'x' and 'y' must be ",
"2 logical vectors of the same length")
a <- sum(x & y)
b <- sum(x & !y)
c <- sum(!x & y)
d <- sum(!x & !y)
}
a <- as.double(a)
b <- as.double(b)
c <- as.double(c)
d <- as.double(d)
div <- sqrt((a + b) * (c + d) * (a + c) * (b + d))
(a * d - b * c) / div
}

0 comments on commit 5a1eec9

Please sign in to comment.