R/library_reporter.R

Defines functions basic_reporter library_reporter

Documented in library_reporter

#' Generating a summary of the spectral library
#'
#' The function generates a report from input spectral library
#'
#' @param input_library A list generated by the function library_generator() or the name of mgf/msp/RData spectral library file
#' @export
#'
#'
#' @importFrom MSnbase fData readMgfData
#'
#
#@examples
#
# data(DRUG_THERMO_LIBRARY)
#library_reporter(library2)

library_reporter<-function(input_library){

  options(stringsAsFactors = FALSE)
  options(warn=-1)

  input_library = library_reader(input_library)
  input_library1 = input_library$complete
  input_library2 = input_library$consensus
  input_network = input_library$network
  
  cat("The entire library contains:")
  basic_reporter(input_library1)
  cat("\n")
  
  cat("The consensus library contains:")
  basic_reporter(input_library2)
  cat("\n")
  
  cat("The molecular network contains:")
  cat(nrow(input_network$nodes), " nodes and ", nrow(input_network$network), " edges")
  cat("\n")
}

########################
### Internal functions## 
########################

basic_reporter<-function(input_library){

  metadata = input_library$metadata
  spectrum_list = input_library$sp

  prec_mz = as.numeric(metadata$PEPMASS)
  prec_rt = as.numeric(metadata$RT)
  IDlist = metadata$ID
  IDs = unique(IDlist)

  MS1_num = sum(metadata$MSLEVEL==1)
  MS2_num = sum(metadata$MSLEVEL==2)
  cat(MS1_num, "MS1 scans and", MS2_num, "MS2 scans of", length(IDs), "compounds.")
  cat("\n")

  valid_2 = 0
  valid_1_2 = 0
  for (id in IDs){
    sub_levels = metadata$MSLEVEL[which(IDlist==id)]
    if (2 %in% sub_levels){valid_2 = valid_2 +1}
    if ((1 %in% sub_levels) & (2 %in% sub_levels)){valid_1_2 = valid_1_2 +1}
  }
  cat(valid_1_2, "compounds possess both MS1 and MS2 scans.")
  cat("\n")
  cat(valid_2, "compounds hold MS2 scans.")
  cat("\n")
}
daniellyz/MergeION2 documentation built on Jan. 26, 2024, 6:24 a.m.