R/computeNodeDetectionPercentage.R

Defines functions computeNodeDetectionPercentage

# Hello, world!
#
# This is an example function named 'hello'
# which prints 'Hello, world!'.
#
# You can learn more about package authoring with RStudio at:
#
#   http://r-pkgs.had.co.nz/
#
# Some useful keyboard shortcuts for package authoring:
#
#   Install Package:           'Cmd + Shift + B'
#   Check Package:             'Cmd + Shift + E'
#   Test Package:              'Cmd + Shift + T'

computeNodeDetectionPercentage <- function(pdb, sty) {

  styDetected <- unique(sty[!is.na(sty$norm), ]$pSite)

  ## Add indicator variables if the nodes are detected
  pdb$i2 <- 0
  pdb$i3 <- 0
  pdb$i4 <- 0
  pdb$i5 <- 0
  pdb$i6 <- 0

  pdb[pdb$Node2 %in% styDetected, ]$i2 <- 1
  pdb[pdb$Node3 %in% styDetected, ]$i3 <- 1
  pdb[pdb$Node4 %in% styDetected, ]$i4 <- 1
  pdb[pdb$Node5 %in% styDetected, ]$i5 <- 1
  pdb[pdb$Node6 %in% styDetected, ]$i6 <- 1

  ## Determine how many of the path nodes are detected
  pdb$iSum <- pdb$i2 + pdb$i3 + pdb$i4 + pdb$i5 + pdb$i6
  pdb$detectedPercent <- pdb$iSum / (pdb$pathLength-1)
  return(pdb)
}
tastymethod/TaSTY documentation built on Nov. 20, 2019, 12:05 a.m.