PageRenderTime 23ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/fingerprint/R/featurefp.R

http://github.com/rajarshi/cdkr
R | 50 lines | 31 code | 3 blank | 16 comment | 5 complexity | c4e0d4b459b8de6a1a982b6cc873d964 MD5 | raw file
  1. ## A feature fingerprint will be a vector of feature objects
  2. setClass("featvec",
  3. representation(features="list",
  4. provider="character",
  5. name="character",
  6. misc="list"),
  7. validity=function(object) {
  8. ## features must be a list of feature objects
  9. klasses <- unique(sapply(object@features, class))
  10. if (length(klasses) != 1 || klasses != 'feature')
  11. return("Must supply a list of 'feature' objects")
  12. iss4s <- sapply(object@features, isS4)
  13. if (!all(iss4s))
  14. return("Must supply a list of 'feature' objects")
  15. return(TRUE)
  16. },
  17. prototype(features=list(),
  18. provider="",
  19. name="",
  20. misc=list()))
  21. setMethod('show', 'featvec',
  22. function(object) {
  23. cat("Feature fingerprint\n")
  24. cat(" name = ", object@name, "\n")
  25. cat(" source = ", object@provider, "\n")
  26. cat(" features = ", paste(sapply(object@features, as.character), collapse=' '), "\n")
  27. })
  28. setMethod('as.character', 'featvec', function(x) {
  29. return(paste(sapply(x@features, as.character), collapse=' '))
  30. })
  31. setMethod("length", "featvec", function(x) {
  32. length(x@features)
  33. })
  34. ## featvec.to.binaryfp <- function(fps, bit.length = 256) {
  35. ## if (!all(sapply(fps, class) == 'featvec'))
  36. ## stop("Must supply a list of feature vector fingerprints")
  37. ## ## get all the features
  38. ## features <- sort(unique(unlist(lapply(fps, as.numeric))))
  39. ## nbit <- length(features)
  40. ## if (nbit %% 2 == 1) nbit <- nbit + 1
  41. ## ## based on the entire feature set, convert original fps to binary fps
  42. ## fps <- lapply(fps, function(x) {
  43. ## bitpos <- match(as.numeric(x), features)
  44. ## new("fingerprint", nbit=nbit, folded=FALSE, provider=x@provider,name=x@name, bits=bitpos)
  45. ## })
  46. ## return(fps)
  47. ## }