R/drawinitial.r

.drawfigs <- function(.cguienv){

  sapply(1:length(.cguienv$cpdata$loadplot), FUN = function(x){
    print(qscatter(x = time, 
                   y = mz, 
                   data = .cguienv$cpdata$loadplot[[x]], 
                   main = paste('loadSample: ', .cguienv$cpdata$loaddata[[x]]@filepath),
                   xlab="Seconds", 
                   ylab="m/z",
                   xlim=range(.cguienv$cpdata$loadplot[[x]]$time), 
                   ylim=range(.cguienv$cpdata$loadplot[[x]]$mz)))
          
    print(qscatter(x = time,
                   y = mz,
                   data = .cguienv$cpdata$genprofplot[[x]],
                   main = paste('genProfile: ', .cguienv$cpdata$genprofdata[[x]]@filepath),
                   xlab = "Seconds",
                   ylab = "m/z",
                   xlim=range(.cguienv$cpdata$loadplot[[x]]$time), 
                   ylim=range(.cguienv$cpdata$loadplot[[x]]$mz)))
    


    add_listener(.cguienv$cpdata$loadplot[[x]], function(i, j){
      
      if(j == '.brushed'){
        seltime <-  unique(round(.cguienv$cpdata$loadplot[[x]][.cguienv$cpdata$loadplot[[x]]$.brushed,]$time))
        selmz <- unique(round(.cguienv$cpdata$loadplot[[x]][.cguienv$cpdata$loadplot[[x]]$.brushed,]$mz))
        
        if(nrow(.cguienv$cpdata$genprofplot[[x]][round(.cguienv$cpdata$genprofplot[[x]]$time) %in% seltime &
                                                   .cguienv$cpdata$genprofplot[[x]]$mz %in% selmz,]) > 0){
          
          .cguienv$cpdata$genprofplot[[x]][round(.cguienv$cpdata$genprofplot[[x]]$time) %in% seltime &
                                             .cguienv$cpdata$genprofplot[[x]]$mz %in% selmz,
                                         '.brushed'] <- TRUE
          .cguienv$cpdata$genprofplot[[x]][!(round(.cguienv$cpdata$genprofplot[[x]]$time) %in% seltime &
                                               .cguienv$cpdata$genprofplot[[x]]$mz %in% selmz),
                                        '.brushed'] <- FALSE
        }
      } else if(j == '.size'){
        .cguienv$cpdata$genprofplot[[x]]$.size <- unique(.cguienv$cpdata$loadplot[[x]]$.size)
      } else{
        print(j)
      }
    })
    
   
  })
  
}
mariev/chromatoplotsgui documentation built on May 21, 2019, 11:46 a.m.