R/computeNodeDetectionProportion.R

Defines functions computeNodeDetectionProportion

# 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'

computeNodeDetectionProportion <- 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 not needed - only score intermediate nodes

  pdb[pdb$Node2 %in% styDetected, ]$i2 <- 1
  pdb[pdb$Node3 %in% styDetected & pdb$pathLength %in% c(4,5,6), ]$i3 <- 1
  pdb[pdb$Node4 %in% styDetected & pdb$pathLength %in% c(5,6), ]$i4 <- 1
  pdb[pdb$Node5 %in% styDetected & pdb$pathLength %in% c(6), ]$i5 <- 1
  #pdb[pdb$Node6 %in% styDetected, ]$i6 <- 1

  ## Determine how many of the path nodes are detected
  pdb$iSum <- 0
  pdb$iSum <- rowSums(pdb[ ,c('i2', 'i3', 'i4', 'i5')], na.rm=TRUE)
  pdb$detectedPercent <- pdb$iSum / (pdb$pathLength-2)
  return(pdb)
}
tastymethod/TaSTY documentation built on Nov. 20, 2019, 12:05 a.m.