File: fastacc.R

package info (click to toggle)
r-cran-seqinr 3.3-3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,844 kB
  • ctags: 69
  • sloc: ansic: 1,955; makefile: 13
file content (29 lines) | stat: -rw-r--r-- 904 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#                 fastacc: Fast Allele in Common Count
#
# Computes the number of common alleles between a target and a database
#
fastacc <- function(target, database)
{
  #
  # Check arguments:
  #
  if(!is.raw(target)) stop("raw vector expected for target")
  noc <- length(target)
  if(noc < 1) stop("empty target")
  if(!is.raw(database)) stop("raw vector expected for database")
  if(length(database) %% noc != 0) stop("database length must be a multiple of target length")
  #
  # n is the total number of entries in DB
  #
  n <- length(database)/noc
  n <- as.integer(n)
  #
  # Pre-compute the table giving the number of bits per octet
  #
  bits_in_char <- sapply(as.raw(0:255), function(x) sum(as.integer(rawToBits(x))))
  bits_in_char <- as.integer(bits_in_char) # just to make sure
  
  res <- .Call("fastacc", bits_in_char, target, database, noc, n, PACKAGE = "seqinr")
  
  return(res)
}