├── DESCRIPTION ├── LICENSE ├── NAMESPACE ├── OmicsNetR.Rproj ├── R ├── DataUtils.R ├── FunctionUtils.R ├── GraphFileUtils.R ├── MSPeakNet.R ├── MiscUtils.R ├── NetID_src.R ├── NetworkUtils.R ├── RcppExports.R ├── lc8_src.R ├── utils_convertIgraph2JSON.R ├── utils_graph_io.R ├── utils_peak_net.R ├── utils_phenoscanner.R ├── utils_reg_enrich.R └── utils_snp.R ├── README.md ├── data ├── elem_table.csv └── elem_table.rda ├── inst ├── db │ ├── compound_db.rds │ ├── currency.qs │ ├── empirical_rule.qs │ ├── hmdb_lib.qs │ ├── kegg_lib.qs │ ├── ms2_lib.qs │ ├── propagation_rule.qs │ └── pubchem_lib.qs └── test │ ├── ibd_met.txt │ ├── ibd_peaks_p.csv │ ├── malaria_peaks.csv │ ├── omicsnet_graph_file_1.json │ ├── sample.txt │ └── test_ko.txt ├── man ├── BuildMinConnectedGraphs.Rd ├── BuildPCSFNet.Rd ├── BuildSeedProteinNet.Rd ├── CreateGraph.Rd ├── DoGba.Rd ├── ExtractModule.Rd ├── FilterByPvalue.Rd ├── FilterByTissue.Rd ├── FindCommunities.Rd ├── GetRCommandHistory.Rd ├── GetShortestPaths.Rd ├── ImportMSPeaks.Rd ├── Init.Data.Rd ├── InitiatePeakSet.Rd ├── PerformAnnotation.Rd ├── PerformDataProcessing.Rd ├── PerformGlobalOptimization.Rd ├── PerformMetEnrichment.Rd ├── PerformNetEnrichment.Rd ├── PerformPropagation.Rd ├── PlotBetweennessHistogram.Rd ├── PlotDegreeHistogram.Rd ├── PrepareGraph.Rd ├── PrepareInputList.Rd ├── PrepareNetwork.Rd ├── PreparePeaksNetwork.Rd ├── QueryNet.Rd ├── ReadGraphFile.Rd ├── RecordRCommand.Rd ├── SanityCheckSelection.Rd ├── SaveNetworkJson.Rd ├── SetMetPotentialOpts.Rd ├── SetPpiZero.Rd ├── SetSnp2GeneOpts.Rd ├── UpdateCmpdDB.Rd ├── call_sr.Rd ├── elem_table.Rd ├── queryFilterDB.Rd └── resetNetwork.Rd └── src ├── MSAnnotate.cpp ├── MSPeak.cpp ├── PCSF.cpp └── RcppExports.cpp /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: OmicsNetR 2 | Title: OmicsNetR 3 | Version: 1.0.0 4 | Authors@R: c( 5 | person(given = "Guangyan", 6 | family = "Zhou", 7 | role = c("aut", "cre"), 8 | email = "guangyan.zhou@mail.mcgill.ca" 9 | ) 10 | ) 11 | Description: Underlying R functions for OmicsNet web server. 12 | License: GPL-3 + file LICENSE 13 | Depends: R (>= 4.0) 14 | Imports: Rcpp, Cairo, igraph, RJSONIO, ggplot2 15 | Suggests: data.table, metap, RSQLite, RandomWalkRestartMH, fitdistrplus, slam, 16 | dplyr, ggforce, graphlayouts, httr, lpsymphony, plyr, pryr, stringr, tidyr, knitr, RColorBrewer, qs, rjson 17 | LinkingTo: Rcpp, BH 18 | VignetteBuilder: knitr 19 | BugReports: https://github.com/xia-lab/OmicsNetR/issues/new 20 | URL: https://github.com/xia-lab/OmicsNetR 21 | Encoding: UTF-8 22 | Roxygen: list(markdown = TRUE) 23 | RoxygenNote: 7.1.2 24 | LazyData: true 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022-2023 Jeff Xia and others 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | useDynLib(OmicsNetR, .registration=TRUE) 3 | importFrom(Rcpp, evalCpp) 4 | exportPattern("^[[:alpha:]]+") 5 | export(BuildMinConnectedGraphs) 6 | export(BuildPCSFNet) 7 | export(BuildSeedProteinNet) 8 | export(CreateGraph) 9 | export(DoGba) 10 | export(ExtractModule) 11 | export(FilterByPvalue) 12 | export(FilterByTissue) 13 | export(FindCommunities) 14 | export(GetRCommandHistory) 15 | export(ImportMSPeaks) 16 | export(Init.Data) 17 | export(InitiatePeakSet) 18 | export(PerformAnnotation) 19 | export(PerformDataProcessing) 20 | export(PerformGlobalOptimization) 21 | export(PerformMetEnrichment) 22 | export(PerformNetEnrichment) 23 | export(PerformPropagation) 24 | export(PlotBetweennessHistogram) 25 | export(PlotDegreeHistogram) 26 | export(PrepareGraph) 27 | export(PrepareInputList) 28 | export(PrepareNetwork) 29 | export(PreparePeaksNetwork) 30 | export(QueryNet) 31 | export(ReadGraphFile) 32 | export(RecordRCommand) 33 | export(SanityCheckSelection) 34 | export(SaveNetworkJson) 35 | export(SetMetPotentialOpts) 36 | export(SetPpiZero) 37 | export(SetSnp2GeneOpts) 38 | export(UpdateCmpdDB) 39 | export(queryFilterDB) 40 | export(resetNetwork) 41 | import(Cairo) 42 | -------------------------------------------------------------------------------- /OmicsNetR.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | PackageBuildArgs: --resave-data --no-build-vignettes 22 | PackageBuildBinaryArgs: --resave-data --no-build-vignettes 23 | -------------------------------------------------------------------------------- /R/DataUtils.R: -------------------------------------------------------------------------------- 1 | ################################################## 2 | ## R scripts for OmicsNet 3 | ## Description: Data I/O functions 4 | ## Author: Jeff Xia, jeff.xia@mcgill.ca 5 | ################################################### 6 | 7 | .onAttach <- function (libname, pkgname){ 8 | .on.public.web <<- FALSE; 9 | k1 <- paste("OmicsNetR", 10 | utils::packageVersion( "OmicsNetR"), 11 | "initialized Successfully !") 12 | k0 <- "\n"; 13 | packageStartupMessage(c(k1,k0)); 14 | } 15 | 16 | #' Initialize dataSet object for downstream functions 17 | #' 18 | #' @export 19 | Init.Data<-function(){ 20 | 21 | #if(exists("dataSet")){ 22 | # return(1) 23 | #} 24 | if(!exists(".on.public.web")){ 25 | .on.public.web <<- FALSE; 26 | } 27 | 28 | dataSet <- list(); 29 | dataSet$imgSet <- list(); 30 | dataSet$snpRegion <- F; 31 | dataSet$allOrgs <- ""; 32 | dataSet$viewTable <- list(); 33 | dataSet$require.exp <- T; 34 | dataSet$ppiZero <- F; 35 | dataSet$min.score <- 900; 36 | dataSet$seeds.proteins <- vector(); 37 | dataSet$mat <- dataSet$exp.mat <- dataSet$seed <- list(); 38 | dataSet$mic.thresh <- 0.8; 39 | dataSet$toremove <- c("Metabolic pathways", 40 | "Biosynthesis of secondary metabolites", 41 | "Microbial metabolism in diverse environments", 42 | "Biosynthesis of antibiotics", 43 | "Carbon metabolism", 44 | "2-Oxocarboxylic acid metabolism", 45 | "Fatty acid metabolism", 46 | "Biosynthesis of amino acids", 47 | "Degradation of aromatic compounds"); 48 | 49 | dataSet$mic.exclude.opt <- "currency"; 50 | dataSet$currExclude <- "true"; 51 | dataSet$orphExclude <- dataSet$uniExclude <- "TRUE"; 52 | dataSet$snp2gene$phesc.opt <- "eqtl"; 53 | dataSet$snp2gene$vep.opt <- "dis"; 54 | dataSet$snp2gene$vep.num <- 1; 55 | dataSet$snp2gene$vep.dis <- 5; 56 | 57 | 58 | dataSet <<- dataSet; 59 | 60 | # set up other global vars 61 | net.info <<- list(gene.ids=vector(),protein.ids=vector()); 62 | initNetwork(); 63 | uploadedGraph <<- FALSE; 64 | data.org <<- NULL; 65 | module.count <<- 0; 66 | max.row <<- 2000; # maximal rows to display interaction table in web page 67 | current.msg <<- ""; 68 | partialToBeSaved <<- c("Rload.RData", "Rhistory.R") 69 | lib.path <<- "../../data/"; 70 | if(file.exists("/home/glassfish/sqlite/")){ 71 | sqlite.path <<- "/home/glassfish/sqlite/"; #public server + qiang local 72 | }else if(file.exists("/Users/xialab/Dropbox/sqlite/")){ 73 | sqlite.path <<- "/Users/xialab/Dropbox/sqlite/"; #xia local 74 | }else if(file.exists("/Users/jeffxia/Dropbox/sqlite/")){ 75 | sqlite.path <<- "/Users/jeffxia/Dropbox/sqlite/"; #xia local2 76 | }else if(file.exists("/home/zgy/sqlite/")){ 77 | sqlite.path <<- "/home/zgy/sqlite/"; #zgy local 78 | }else if(file.exists("/home/ly/sqlite/")){ 79 | sqlite.path <<- "/home/ly/sqlite/"; #ly local 80 | }else if(file.exists("/Users/lzy/sqlite")){ 81 | sqlite.path <<- "/Users/lzy/sqlite/"; #luyao local 82 | }else{ 83 | sqlite.path <<-"/media/zzggyy/disk/sqlite/"; #zgy local 84 | } 85 | 86 | if(!.on.public.web) { 87 | sqlite.path <<- paste0(getwd(), "/"); 88 | lib.path <<- "https://www.omicsnet.ca/OmicsNet/resources/data/"; 89 | message("A dataset has been initiated."); 90 | return(dataSet); 91 | } else { 92 | .on.public.web <<- TRUE; 93 | } 94 | return(1) 95 | } 96 | 97 | SetUploadedGraph<- function(bool){ 98 | uploadedGraph <<- bool; 99 | } 100 | 101 | SetOrganism <- function(org){ 102 | data.org <<- org; 103 | } 104 | 105 | SetCurrentDataMulti <- function(){ 106 | dataSet$type <- nms.vec; 107 | rm('nms.vec', envir = .GlobalEnv); 108 | return(.set.nSet(dataSet)); 109 | } 110 | 111 | 112 | #' Process input list 113 | #' 114 | #' @param dataSetObj Input the name of the created dataSetObj (see Init.Data) 115 | #' @param inputList Tab-delimited String of input omics list 116 | #' @param org organism code: hsa, mmu, microbiome, rno, cel, dme, dre, sce, bta, gga 117 | #' @param type character, type 118 | #' @param queryType character, queryType 119 | #' 120 | #' @export 121 | PrepareInputList <- function(dataSetObj="NA", inputList, org, type, queryType){ 122 | 123 | if(!exists("dataSet")){ 124 | Init.Data(); 125 | } 126 | dataSet <- .get.nSet(dataSetObj); 127 | dataSet$name <- type; 128 | dataSet$orig <- inputList; 129 | 130 | current.msg <<- NULL; 131 | data.org <<- org; 132 | if(type == "gene" & exists("signature.gene")){ 133 | if(nrow(signature.gene)>200){ 134 | signature.gene <- as.matrix(signature.gene[1:200,]); 135 | } 136 | prot.mat <- gene.mat <- signature.gene; 137 | }else if(type == "met" & exists("signature.cmpds")){ 138 | if(nrow(signature.cmpds)>50){ 139 | signature.cmpds <- as.matrix(signature.cmpds[1:50,]); 140 | } 141 | prot.mat <- gene.mat <- signature.cmpds; 142 | queryType <- signature.type; 143 | } else if(type == "peak"){ 144 | prot.mat <- gene.mat <- inputList; 145 | } else{ 146 | prot.mat <- gene.mat <- .parseListInput(inputList, queryType); 147 | } 148 | 149 | gene.mat <<- gene.mat 150 | GeneAnotDB <-doProteinIDMapping(rownames(gene.mat), queryType); 151 | na.inx <- is.na(GeneAnotDB[,1]) | is.na(GeneAnotDB[,2]); 152 | 153 | if(type == "ko"){ 154 | dataSet$ko <- GeneAnotDB; 155 | } 156 | 157 | if(type == "snp"){ 158 | if(queryType == "region"){ 159 | dataSet$snpRegion <- TRUE 160 | }else{ 161 | dataSet$snpRegion <- FALSE 162 | } 163 | } 164 | 165 | if(sum(!na.inx) < 2){ 166 | current.msg <<- "Less than two hits found in uniprot database. "; 167 | print(current.msg); 168 | } 169 | if(type == "met" || type == "mir" ){ 170 | col1 <- 1; 171 | if(queryType == "mir_acc" || (type == "met" && queryType != "kegg")){ 172 | col1 <- 2; 173 | } 174 | hit.inx <- match(tolower(rownames(prot.mat)), tolower(GeneAnotDB[,col1])); 175 | if(is.null(dim(prot.mat))){ 176 | prot.mat <- matrix(prot.mat); 177 | } 178 | rownames(prot.mat) <- GeneAnotDB[,"gene_id"][hit.inx]; 179 | na.inx1 <- is.na(rownames(prot.mat)); 180 | prot.mat = as.matrix(prot.mat[!na.inx1,]) 181 | }else if(type == "peak"){ 182 | hit.inx <- match(rownames(prot.mat), GeneAnotDB[,1]); 183 | if(is.null(dim(prot.mat))){ 184 | prot.mat <- matrix(prot.mat); 185 | } 186 | rownames(prot.mat)[!is.na(hit.inx)] <- as.character(GeneAnotDB[,2][!is.na(hit.inx)]); 187 | } else{ 188 | rownames(prot.mat) <- GeneAnotDB[,"gene_id"]; 189 | prot.mat <- prot.mat[!na.inx, , drop=F]; 190 | } 191 | # now merge duplicates 192 | prot.mat <- RemoveDuplicates(prot.mat, "mean", quiet=T); 193 | 194 | if(is.null(dim(prot.mat))){ 195 | prot.mat <- matrix(prot.mat); 196 | } 197 | 198 | seed.proteins <- rownames(prot.mat); 199 | dataSet$GeneAnotDB <- GeneAnotDB; 200 | 201 | if(type == "mic" && sum(gene.mat) == 0){ 202 | gene.mat[gene.mat == 0,] <- 1; 203 | prot.mat <- gene.mat 204 | } 205 | 206 | if(type %in% c("gene", "geneonly", "protein1")){ 207 | if(length(dataSet$mat[["gene"]]) == 0){ 208 | dataSet$mat[["gene"]] <- gene.mat; 209 | dataSet$exp.mat[["gene"]] <- prot.mat; 210 | dataSet$seed[["gene"]] <- prot.mat; 211 | if(type == "geneonly"){ 212 | dataSet$gene_type_vec = rep(2, nrow(prot.mat)) 213 | }else if (type == "protein"){ 214 | dataSet$gene_type_vec = rep(3, nrow(prot.mat)) 215 | }else if (type == "snp"){ 216 | dataSet$gene_type_vec = rep(4, nrow(prot.mat)) 217 | }else{ 218 | dataSet$gene_type_vec = rep(1, nrow(prot.mat)) 219 | } 220 | }else{ 221 | dataSet$mat[["gene"]] <- rbind(dataSet$mat[["gene"]], gene.mat); 222 | dataSet$exp.mat[["gene"]] <- rbind(dataSet$exp.mat[["gene"]], prot.mat); 223 | dataSet$seed[["gene"]] <- rbind(dataSet$seed[["gene"]], prot.mat); 224 | if(type == "geneonly"){ 225 | dataSet$gene_type_vec = c(dataSet$gene_type_vec, rep(2, nrow(prot.mat))); 226 | }else if (type == "protein"){ 227 | dataSet$gene_type_vec = c(dataSet$gene_type_vec, rep(3, nrow(prot.mat))); 228 | }else if (type == "snp"){ 229 | dataSet$gene_type_vec = c(dataSet$gene_type_vec, rep(4, nrow(prot.mat))); 230 | }else{ 231 | dataSet$gene_type_vec = c(dataSet$gene_type_vec, rep(1, nrow(prot.mat))); 232 | } 233 | } 234 | }else{ 235 | dataSet$mat[[type]] <- gene.mat; 236 | dataSet$exp.mat[[type]] <- prot.mat; 237 | dataSet$seed[[type]] <- prot.mat; 238 | } 239 | 240 | if(length(dataSet$type) == 1){ 241 | dataSet$prot.mat <- rbind(dataSet$prot.mat, prot.mat); 242 | dataSet$seeds.proteins <- c(dataSet$seeds.proteins, seed.proteins); 243 | } else{ 244 | for(i in 1:length(dataSet$exp.mat)){ 245 | dataSet$prot.mat <- c(dataSet$prot.mat, dataSet$exp.mat[[i]]); 246 | dataSet$seeds.proteins <- c(dataSet$seeds.proteins, rownames(dataSet$exp.mat[[i]])); 247 | } 248 | } 249 | dataSet$seeds.proteins <- unique(dataSet$seeds.proteins) 250 | dataSet$seeds.expr <- as.matrix(dataSet$prot.mat); 251 | message(paste0("Preparing input list with the type of ", type, " completed.")) 252 | if(.on.public.web){ 253 | .set.nSet(dataSet); 254 | return (seed.proteins); 255 | }else{ 256 | return (.set.nSet(dataSet)); 257 | } 258 | } 259 | 260 | 261 | # given a text from input area: one or two-col entries (geneID and logFC) 262 | # parse out return the a matrix containing the logFc, with rows named by gene ID 263 | # if no 2nd col (logFC), the value will be padded by 0s 264 | .parseListInput <- function(geneIDs, IDtype){ 265 | 266 | lines <- unlist(strsplit(geneIDs, "\r|\n|\r\n")[1]); 267 | if(substring(lines[1],1,1)=="#"){ 268 | lines <- lines[-1]; 269 | } 270 | if(IDtype == "meta" || IDtype == "name"){ 271 | gene.lists <- lines; 272 | if(!is.list(gene.lists)){ 273 | gene.lists <- strsplit(lines, "\\s+"); 274 | gene.lists <- lapply(gene.lists, function(x) paste(x,collapse = " ")); 275 | } 276 | }else{ 277 | gene.lists <- strsplit(lines, "\\s+"); 278 | } 279 | gene.mat <- do.call(rbind, gene.lists); 280 | 281 | if(dim(gene.mat)[2] == 1){ # add 0 282 | gene.mat <- cbind(gene.mat, rep(0, nrow(gene.mat))); 283 | current.msg <- "Only one column found in the list. Abundance will be all zeros. "; 284 | }else if(dim(gene.mat)[2] > 2){ 285 | gene.mat <- gene.mat[,1:2]; 286 | current.msg <- "More than two columns found in the list. Only first two columns will be used. "; 287 | } 288 | 289 | rownames(gene.mat) <- gene.mat[,1]; 290 | gene.mat <- gene.mat[,-1, drop=F]; 291 | gene.mat <- RemoveDuplicates(gene.mat, "mean", quiet=T); 292 | good.inx <- !is.na(gene.mat[,1]); 293 | gene.mat <- gene.mat[good.inx, , drop=F]; 294 | 295 | if(IDtype %in% c("class", "family","order" ,"genus","species","strain", "phylum")){ 296 | rownames(gene.mat) <- gsub("_", " ", rownames(gene.mat)); 297 | } 298 | 299 | return(gene.mat); 300 | } 301 | 302 | SetDbType <- function(dbType){ 303 | dbu.type <<- dbType; 304 | } 305 | 306 | 307 | SetMirBo <- function(mirBo){ 308 | requireMirExp <<- mirBo 309 | } 310 | 311 | SetAllOrgs <- function(orgs){ 312 | dataSet$allOrgs <<- orgs 313 | } 314 | 315 | GetAllOrgs <- function(){ 316 | print(dataSet$allOrgs); 317 | print("allOrgs"); 318 | return(dataSet$allOrgs); 319 | } 320 | 321 | GetInputTypes <- function(dataSetObj=NA){ 322 | dataSet <- .get.nSet(dataSetObj); 323 | types.vec <- c(names(dataSet$exp.mat)); 324 | return(types.vec); 325 | } 326 | 327 | GetInputNames <- function(dataSetObj=NA){ 328 | dataSet <- .get.nSet(dataSetObj); 329 | types.vec <- c(names(dataSet$exp.mat)); 330 | length.vec <- sapply(dataSet$exp.mat,function(x) { 331 | length(unique(rownames(x))) 332 | }) 333 | names.vec <- convertInputTypes2Names(types.vec); 334 | nms.and.size.vec <- vector(); 335 | 336 | containsProtein <- F; 337 | if(length(rownames(dataSet$exp.mat[["gene"]])[dataSet$gene_type_vec == 3]) > 0){ 338 | containsProtein <- T; 339 | } 340 | 341 | containsGene <- F; 342 | if(length(rownames(dataSet$exp.mat[["gene"]])[dataSet$gene_type_vec == 1]) > 0){ 343 | containsGene <- T; 344 | } 345 | for(i in 1:length(names.vec)){ 346 | nm <- names.vec[i] 347 | if(!containsGene && nm == "Gene"){ 348 | nm <- "Protein"; 349 | }else if(containsProtein && nm == "Gene"){ 350 | nm <- "mRNA/Protein"; 351 | } 352 | nms.and.size.vec[i] <- paste0(nm, " (", length.vec[i], ")"); 353 | } 354 | dataSet$inputInfo <- nms.and.size.vec; 355 | dataSet <<- dataSet 356 | return(nms.and.size.vec); 357 | } 358 | 359 | convertInputTypes2Names <- function(types){ 360 | typesCol <- c("gene","protein", "tf", "mir", "met", "peak", "mic", "snp", "ko"); 361 | namesCol <- c("mRNA","Protein", "Transcription factor", "miRNA", "Metabolite", "LC-MS peak", "Microbial taxa", "SNP", "KO"); 362 | db.map <- data.frame(type=typesCol, name=namesCol); 363 | hit.inx <- match(types, db.map[, "type"]); 364 | names <- db.map[hit.inx, "name"]; 365 | mode(names) <- "character"; 366 | na.inx <- is.na(names); 367 | names[na.inx] <- types[na.inx]; 368 | return(names); 369 | } 370 | 371 | convertInteraction2Names <- function(types){ 372 | typesCol <- c("gene", "tf", "mir", "met", "peak", "mic", "snp", "ko", "m2m"); 373 | namesCol <- c("PPI", "TF-gene", "miRNA-gene", "Metabolite-protein", "Peak-metabolite", "Taxon-metabolite", "SNP Annotation", "ko", "Metabolite-metabolite"); 374 | db.map <- data.frame(type=typesCol, name=namesCol); 375 | hit.inx <- match(types, db.map[, "type"]); 376 | #print(hit.inx); 377 | names <- db.map[hit.inx, "name"]; 378 | mode(names) <- "character"; 379 | return(names); 380 | } 381 | 382 | doEmblGene2EntrezMapping <- function(emblgene.vec){ 383 | db.path <- paste(lib.path, data.org, "/entrez_embl_gene.rds", sep=""); 384 | db.map <- readRDS(db.path); 385 | hit.inx <- match(emblgene.vec, db.map[, "accession"]); 386 | entrezs <- db.map[hit.inx, "gene_id"]; 387 | mode(entrezs) <- "character"; 388 | return(entrezs); 389 | } 390 | 391 | GetInputListStat <- function(listNm){ 392 | geneList <- rownames(dataSet$exp.mat[["gene"]]); 393 | tfList <- rownames(dataSet$exp.mat[["tf"]]); 394 | mirList <- rownames(dataSet$exp.mat[["mir"]]); 395 | metList <- rownames(dataSet$exp.mat[["met"]]); 396 | peakList <- rownames(dataSet$exp.mat[["peak"]]); 397 | micList <- rownames(dataSet$exp.mat[["mic"]]); 398 | snpList <- rownames(dataSet$seed[["snp"]]); 399 | koList <- rownames(dataSet$exp.mat[["ko"]]); 400 | return(c(length(rownames(dataSet$exp.mat[["gene"]])),length(rownames(dataSet$exp.mat[["protein"]])),length(unique(tfList)),length(unique(mirList)),length(unique(metList)), length(unique(koList)), length(unique(peakList)), length(unique(micList)), length(unique(snpList)))); 401 | } 402 | 403 | GetFilesToBeSaved <-function(naviString){ 404 | return(unique(partialToBeSaved)); 405 | } 406 | 407 | GetCurrentJson <-function(type){ 408 | return(dataSet$jsonNms[[type]]); 409 | } 410 | 411 | SetSnpTissueType <- function(type){ 412 | dataSet$snpTissueType <<- type; 413 | } 414 | 415 | #'Export R Command History 416 | #'@param dataSetObj Input the name of the created dataSetObj (see Init.Data) 417 | #'@export 418 | GetRCommandHistory <- function(dataSetObj=NA){ 419 | dataSet <- .get.nSet(dataSetObj); 420 | if(length(dataSet$cmdSet) == 0){ 421 | return("No commands found"); 422 | } 423 | return(dataSet$cmdSet); 424 | } 425 | 426 | #'Record R Commands 427 | #'@param dataSetObj Input the name of the created dataSetObj (see Init.Data) 428 | #'@param cmd Commands 429 | #'@export 430 | RecordRCommand <- function(dataSetObj=NA, cmd){ 431 | dataSet <- .get.nSet(dataSetObj); 432 | dataSet$cmdSet <- c(dataSet$cmdSet, cmd); 433 | return(.set.nSet(dataSet)); 434 | } 435 | 436 | 437 | SaveRCommands <- function(dataSetObj=NA){ 438 | dataSet <- .get.nSet(dataSetObj); 439 | cmds <- paste(dataSet$cmdSet, collapse="\n"); 440 | pid.info <- paste0("# PID of current job: ", Sys.getpid()); 441 | cmds <- c(pid.info, cmds); 442 | write(cmds, file = "Rhistory.R", append = FALSE); 443 | } 444 | 445 | RemoveEdgeEntry <- function(tblnm, row.id) { 446 | inx <- which(rownames(dataSet$viewTable[tblnm][[1]]) == row.id); 447 | if(length(inx) > 0){ 448 | dataSet$viewTable[tblnm][[1]] <- dataSet$viewTable[tblnm][[1]][-inx,]; 449 | edgeu.res.list[[tblnm]] <- edgeu.res.list[[tblnm]][-inx,]; 450 | } 451 | edgeu.res.list <<- edgeu.res.list; 452 | dataSet<<-dataSet 453 | return(1) 454 | } 455 | 456 | GetEdgeResRowNames <- function(netType){ 457 | resTable <- dataSet$viewTable[[netType]] 458 | if(nrow(resTable) > max.row){ 459 | resTable <- resTable[1:max.row, ]; 460 | current.msg <<- "Due to computational constraints, only top 2000 rows will be displayed."; 461 | } 462 | rownames(resTable); 463 | } 464 | 465 | GetEdgeResCol <- function(netType, colInx){ 466 | 467 | resTable <- dataSet$viewTable[[netType]] 468 | 469 | if(nrow(resTable) > max.row){ 470 | resTable <- resTable[1:max.row, ]; 471 | #current.msg <<- "Due to computational constraints, only top 1000 rows will be displayed."; 472 | } 473 | res <- resTable[, colInx]; 474 | hit.inx <- is.na(res) | res == ""; # note, must use | for element-wise operation 475 | res[hit.inx] <- "N/A"; 476 | return(res); 477 | } 478 | 479 | 480 | # batch remove based on 481 | UpdateEdgeTableEntries <- function(table.nm,table.type, col.id, method, value, action) { 482 | 483 | col <- dataSet$viewTable[[table.nm]][,col.id]; 484 | 485 | if(method == "contain"){ 486 | hits <- grepl(value, col, ignore.case = TRUE); 487 | }else if(method == "match"){ 488 | hits <- tolower(col) %in% tolower(value); 489 | } 490 | 491 | if(action == "keep"){ 492 | hits = !hits; 493 | } 494 | 495 | if(sum(hits) > 0){ 496 | row.ids <- rownames(dataSet$viewTable[[table.nm]])[hits]; 497 | dataSet$viewTable[[table.nm]] <- dataSet$viewTable[[table.nm]][!hits,]; 498 | edgeu.res.list[[table.nm]]$table <- dataSet$viewTable[[table.nm]] 499 | UpdateModifiedTable(edgeu.res.list); 500 | fast.write.csv(dataSet$viewTable[[table.nm]], file="omicsnet_edgelist.csv", row.names=FALSE); 501 | .set.nSet(dataSet); 502 | return(row.ids); 503 | }else{ 504 | return("NA"); 505 | } 506 | } 507 | 508 | UpdateModifiedTable <- function(edgeu.res.list) { 509 | edge.res <- data.frame(); 510 | 511 | if(length(edgeu.res.list) > 0){ 512 | for(i in 1:length(edgeu.res.list)){ 513 | edge.res <- rbind(edge.res, edgeu.res.list[[i]]$table); 514 | } 515 | } 516 | 517 | omics.net$edge.data <- unique(edge.res); 518 | omics.net <<- omics.net; 519 | #print(omics.net$edge.data); 520 | 521 | return(1) 522 | } 523 | 524 | GetOrg <- function(){ 525 | return(data.org); 526 | } 527 | 528 | PrepareSqliteDB <- function(sqlite_Path, onweb = TRUE) { 529 | if(onweb) {return(TRUE)}; 530 | if(file.exists(sqlite_Path)) {return(TRUE)}; 531 | 532 | dbNM <- basename(sqlite_Path); 533 | DonwloadLink <- paste0("https://www.xialab.ca/resources/sqlite/", dbNM); 534 | download.file(DonwloadLink, sqlite_Path); 535 | return(TRUE) 536 | } 537 | 538 | #importFrom("grDevices", "col2rgb", "colorRampPalette", "dev.off","hsv", "rainbow") 539 | #importFrom("stats", "aggregate", "complete.cases", "dnorm", "filter","formula", "lm", "median", "na.omit", "p.adjust", "phyper","quantile", "wilcox.test") 540 | #importFrom("utils", "capture.output", "install.packages","installed.packages", "object.size", "read.csv","read.table", "sessionInfo", "write.csv") 541 | 542 | 543 | SetFunctionByDbVersion <- function(db_version) { 544 | funcs <- c('Init.Data', 'PrepareSqliteDB') 545 | version_suffix <- '_2022' 546 | 547 | for (func in funcs) { 548 | if (db_version == "previousDB") { 549 | SetToPrevious(func, version_suffix) 550 | } else { 551 | SetToCurrent(func, version_suffix) 552 | } 553 | } 554 | } 555 | 556 | SetToCurrent <- function(func, version_suffix) { 557 | sql <- "/sqlite" 558 | sql_versioned <- paste0("/sqlite",version_suffix) 559 | 560 | original_path <- sqlite.path 561 | if (grepl(sql_versioned, original_path)) { 562 | modified_path <- gsub(sql_versioned, sql, original_path) 563 | if (file.exists(modified_path)) { 564 | sqlite.path <<- modified_path 565 | } 566 | } 567 | 568 | original_func <- get(func, envir = .GlobalEnv) 569 | original_body <- body(original_func) 570 | 571 | modified_body <- lapply(original_body, function(line) { 572 | if (is.call(line) && any(grepl(sql_versioned, deparse(line)))) { 573 | modified_line <- gsub(sql_versioned, sql, deparse(line)) 574 | return(parse(text = modified_line)[[1]]) 575 | } else { 576 | return(line) 577 | } 578 | }) 579 | 580 | modified_func <- original_func 581 | body(modified_func) <- as.call(modified_body) 582 | assign(func, modified_func, envir = .GlobalEnv) 583 | } 584 | 585 | SetToPrevious <- function(func, version_suffix) { 586 | sql <- "/sqlite" 587 | sql_versioned <- paste0("/sqlite",version_suffix) 588 | 589 | original_path <- sqlite.path 590 | if (!grepl(sql_versioned, original_path) && grepl(sql, original_path)) { 591 | modified_path <- gsub(sql, sql_versioned, original_path) 592 | if (file.exists(modified_path)) { 593 | sqlite.path <<- modified_path 594 | } 595 | } 596 | 597 | original_func <- get(func, envir = .GlobalEnv) 598 | original_body <- body(original_func) 599 | 600 | modified_body <- lapply(original_body, function(line) { 601 | if (is.call(line) && any(grepl(sql, deparse(line))) && !any(grepl(sql_versioned, deparse(line)))) { 602 | modified_line <- gsub(sql, sql_versioned, deparse(line)) 603 | return(parse(text = modified_line)[[1]]) 604 | } else { 605 | return(line) 606 | } 607 | }) 608 | 609 | modified_func <- original_func 610 | body(modified_func) <- as.call(modified_body) 611 | assign(func, modified_func, envir = .GlobalEnv) 612 | } 613 | -------------------------------------------------------------------------------- /R/GraphFileUtils.R: -------------------------------------------------------------------------------- 1 | ################################################## 2 | ## R scripts for OmicsNet 3 | ## Description: Data IO functions 4 | ## Author: Jeff Xia, jeff.xia@mcgill.ca 5 | ################################################### 6 | 7 | ProcessOmicsNetJson <- function(dataSet, fileName) { 8 | require("RJSONIO"); 9 | obj <- RJSONIO::fromJSON(fileName) 10 | seed <- obj$dataSet$seed 11 | for(i in 1:length(seed)){ 12 | df <- seed[[i]]; 13 | df1 <- data.frame(expr = df$expr, id = df$id) 14 | rownames(df1) <- df1$id; 15 | seed[[i]] <- df1; 16 | } 17 | dataSet$seed <- seed; 18 | dataSet$seeds.expr <- obj$dataSet$seeds.expr; 19 | dataSet$seeds.proteins <- obj$dataSet$seeds.proteins; 20 | 21 | seed.expr <<- obj$seed.expr; 22 | omics.net <- obj$omics.net; 23 | if(is.null(dim(obj$omics.net$node.data))){ 24 | node.data.df <- data.frame(Id=omics.net$node.data, Label=omics.net$node.data); 25 | }else{ 26 | node.data.df <- data.frame(Id=omics.net$node.data$Id, Label=omics.net$node.data$Label); 27 | } 28 | node.data.df <- unique(node.data.df); 29 | edge.data.df <- data.frame(Source=omics.net$edge.data$Source, Target=omics.net$edge.data$Target); 30 | omics.net$node.data <- node.data.df 31 | omics.net$edge.data <- edge.data.df 32 | seed.proteins <<- node.data.df[,1]; 33 | seed.genes <<- node.data.df[,1]; 34 | omics.net <<- omics.net; 35 | net.info <<- obj$net.info 36 | data.org <<- obj$data.org 37 | 38 | if(is.null(obj$snpRegion)){ 39 | dataSet$snpRegion <- F; 40 | }else{ 41 | dataSet$snpRegion <- obj$snpRegion; 42 | } 43 | 44 | if(is.null(obj$allOrgs)){ 45 | dataSet$allOrgs <- data.org; 46 | }else{ 47 | dataSet$allOrgs <- obj$allOrgs; 48 | } 49 | 50 | dataSet <<- dataSet; 51 | CreateGraph(dataSet); 52 | net.nm <- names(ppi.comps)[1]; 53 | net.nmu <<- net.nm; 54 | current.net.nm <<- net.nm; 55 | g <- ppi.comps[[net.nm]]; 56 | 57 | dataSet <- .computeSubnetStats(dataSet, ppi.comps); 58 | return(.set.nSet(dataSet)); 59 | } 60 | 61 | #' ReadGraphFile 62 | #' 63 | #' @param dataSetObj dataSetObj 64 | #' @param fileName fileName, Input name of graph file 65 | #' @param fileType fileType, File type of graph file (".json", ".graphml", ".txt", ".sif") 66 | #' @export 67 | ReadGraphFile <- function(dataSetObj=NA, fileName, fileType) { 68 | if(!exists("my.read.graphfile")){ # public web on same user dir 69 | compiler::loadcmp("../../rscripts/OmicsNetR/R/utils_graph_io.Rc"); 70 | } 71 | return(my.read.graphfile(dataSetObj, fileName, fileType)); 72 | } 73 | 74 | convertIgraph2JSONFromFile <- function(net.nm, filenm, dim=3){ 75 | 76 | if(!exists("my.convert.Igraph2JSONFromFile")){ # public web on same user dir 77 | compiler::loadcmp("../../rscripts/OmicsNetR/R/utils_graph_io.Rc"); 78 | } 79 | return(my.convert.Igraph2JSONFromFile(net.nm, filenm, dim)); 80 | } 81 | 82 | getGraphStatsFromFile <- function(){ 83 | g <- ppi.comps[[net.nmu]]; 84 | nms <- V(g)$name; 85 | edge.mat <- get.edgelist(g); 86 | return(c(length(nms), nrow(edge.mat))); 87 | } 88 | -------------------------------------------------------------------------------- /R/MiscUtils.R: -------------------------------------------------------------------------------- 1 | ################################################## 2 | ## R scripts for OmicsNet 3 | ## Various utility methods 4 | ## Author: Jeff Xia, jeff.xia@mcgill.ca 5 | ################################################### 6 | 7 | # new range [a, b] 8 | rescale2NewRange <- function(qvec, a, b){ 9 | qvec = replace(qvec, qvec == 0, 1) 10 | q.min <- min(qvec); 11 | q.max <- max(qvec); 12 | if(length(qvec) < 50){ 13 | a <- a*2; 14 | } 15 | if(q.max == q.min){ 16 | new.vec <- rep(8, length(qvec)); 17 | }else{ 18 | coef.a <- (b-a)/(q.max-q.min); 19 | const.b <- b - coef.a*q.max; 20 | new.vec <- coef.a*qvec + const.b; 21 | } 22 | return(new.vec); 23 | } 24 | 25 | # #FFFFFF to rgb(1, 0, 0) 26 | hex2rgba <- function(cols){ 27 | return(apply(sapply(cols, col2rgb), 2, function(x){paste("rgba(", x[1], ",", x[2], ",", x[3], ",0.8)", sep="")})); 28 | } 29 | 30 | # re-arrange one vector elements according to another vector values 31 | # usually src is character vector to be arranged 32 | # target is numberic vector of same length 33 | 34 | # given a data with duplicates, dups is the one with duplicates 35 | RemoveDuplicates <- function(data, lvlOpt, quiet=T){ 36 | 37 | all.nms <- rownames(data); 38 | colnms <- colnames(data); 39 | dup.inx <- duplicated(all.nms); 40 | dim.orig <- dim(data); 41 | data <- suppressWarnings(apply(data, 2, as.numeric)); # force to be all numeric 42 | dim(data) <- dim.orig; # keep dimension (will lost when only one item) 43 | rownames(data) <- all.nms; 44 | colnames(data) <- colnms; 45 | if(sum(dup.inx) > 0){ 46 | uniq.nms <- all.nms[!dup.inx]; 47 | uniq.data <- data[!dup.inx,,drop=F]; 48 | 49 | dup.nms <- all.nms[dup.inx]; 50 | uniq.dupnms <- unique(dup.nms); 51 | uniq.duplen <- length(uniq.dupnms); 52 | 53 | for(i in 1:uniq.duplen){ 54 | nm <- uniq.dupnms[i]; 55 | hit.inx.all <- which(all.nms == nm); 56 | hit.inx.uniq <- which(uniq.nms == nm); 57 | 58 | # average the whole sub matrix 59 | if(lvlOpt == "mean"){ 60 | uniq.data[hit.inx.uniq, ]<- apply(data[hit.inx.all,,drop=F], 2, mean, na.rm=T); 61 | }else if(lvlOpt == "median"){ 62 | uniq.data[hit.inx.uniq, ]<- apply(data[hit.inx.all,,drop=F], 2, median, na.rm=T); 63 | }else if(lvlOpt == "max"){ 64 | uniq.data[hit.inx.uniq, ]<- apply(data[hit.inx.all,,drop=F], 2, max, na.rm=T); 65 | }else{ # sum 66 | uniq.data[hit.inx.uniq, ]<- apply(data[hit.inx.all,,drop=F], 2, sum, na.rm=T); 67 | } 68 | } 69 | if(!quiet){ 70 | current.msg <<- paste(current.msg, paste("A total of ", sum(dup.inx), " of duplicates were replaced by their ", lvlOpt, ".", sep=""), collapse="\n"); 71 | } 72 | return(uniq.data); 73 | }else{ 74 | if(!quiet){ 75 | current.msg <<- paste(current.msg, "All IDs are unique.", collapse="\n"); 76 | } 77 | return(data); 78 | } 79 | } 80 | 81 | generate_breaks = function(x, n, center = F){ 82 | if(center){ 83 | m = max(abs(c(min(x, na.rm = T), max(x, na.rm = T)))); 84 | res = seq(-m, m, length.out = n + 1); 85 | } else { 86 | res = seq(min(x, na.rm = T), max(x, na.rm = T), length.out = n + 1); 87 | } 88 | return(res) 89 | } 90 | 91 | ComputeColorGradient <- function(nd.vec, background = "black", centered = FALSE) { 92 | require("RColorBrewer") 93 | 94 | # Check if the input is a list of vectors or a vector 95 | if (is.list(nd.vec) && all(sapply(nd.vec, is.numeric))) { 96 | # Flatten the list of vectors into a single numerical vector 97 | flat_vec <- unlist(nd.vec) 98 | } else if (is.numeric(nd.vec)) { 99 | flat_vec <- nd.vec 100 | } else { 101 | stop("Input must be a vector or a list of numeric vectors") 102 | } 103 | 104 | # Compute min and max values 105 | minval <- min(flat_vec, na.rm = TRUE) 106 | maxval <- max(flat_vec, na.rm = TRUE) 107 | res <- maxval - minval 108 | 109 | # Handle the case where all values are the same 110 | if (res == 0) { 111 | return(rep("#0b6623", length(flat_vec))) 112 | } 113 | 114 | # Generate the color gradient 115 | color <- GetColorGradient(background, centered) 116 | breaks <- generate_breaks(flat_vec, length(color), center = centered) 117 | color_vec <- scale_vec_colours(flat_vec, col = color, breaks = breaks) 118 | 119 | # If input was a list of vectors, map the colors back to the original list structure 120 | if (is.list(nd.vec) && all(sapply(nd.vec, is.numeric))) { 121 | color_list <- split(color_vec, ceiling(seq_along(color_vec) / 2)) 122 | return(color_list) 123 | } else { 124 | return(color_vec) 125 | } 126 | } 127 | 128 | 129 | GetColorGradient <- function(background, center){ 130 | if(background == "black"){ 131 | if(center){ 132 | return(c(colorRampPalette(c("#31A231", "#5BC85B", "#90EE90", "#C1FFC1"))(50), colorRampPalette(c("#FF9DA6", "#FF7783", "#E32636", "#BD0313"))(50))); 133 | }else{ 134 | return(c(colorRampPalette(c("#edf8fb","#b2e2e2","#66c2a4","#2ca25f","#006d2c"))(100))); 135 | } 136 | }else{ # white background 137 | if(center){ 138 | return(c(colorRampPalette(c("#137B13", "#31A231", "#5BC85B", "#90EE90"))(50), colorRampPalette(c("#FF7783", "#E32636", "#BD0313", "#96000D"))(50))); 139 | }else{ 140 | return(colorRampPalette(hsv(h = seq(0.72, 1, 0.035), s = 0.72, v = 1))(100)); 141 | } 142 | } 143 | } 144 | 145 | scale_vec_colours = function(x, col = rainbow(10), breaks = NA){ 146 | breaks <- sort(unique(breaks)); 147 | return(col[as.numeric(cut(x, breaks = breaks, include.lowest = T))]); 148 | } 149 | 150 | scale_colours = function(mat, col = rainbow(10), breaks = NA){ 151 | mat = as.matrix(mat) 152 | return(matrix(scale_vec_colours(as.vector(mat), col = col, breaks = breaks), nrow(mat), ncol(mat), dimnames = list(rownames(mat), colnames(mat)))) 153 | } 154 | 155 | ########### 156 | # improved list of objects 157 | .ls.objects <- function (pos = 1, pattern, order.by, 158 | decreasing=FALSE, head=FALSE, n=5) { 159 | napply <- function(names, fn) sapply(names, function(x) 160 | fn(get(x, pos = pos))) 161 | names <- ls(pos = pos, pattern = pattern) 162 | obj.class <- napply(names, function(x) as.character(class(x))[1]) 163 | obj.mode <- napply(names, mode) 164 | obj.type <- ifelse(is.na(obj.class), obj.mode, obj.class) 165 | obj.prettysize <- napply(names, function(x) { 166 | capture.output(format(utils::object.size(x), units = "auto")) }) 167 | obj.size <- napply(names, object.size) 168 | obj.dim <- t(napply(names, function(x) 169 | as.numeric(dim(x))[1:2])) 170 | vec <- is.na(obj.dim)[, 1] & (obj.type != "function") 171 | obj.dim[vec, 1] <- napply(names, length)[vec] 172 | out <- data.frame(obj.type, obj.size, obj.prettysize, obj.dim) 173 | names(out) <- c("Type", "Size", "PrettySize", "Rows", "Columns") 174 | if (!missing(order.by)) 175 | out <- out[order(out[[order.by]], decreasing=decreasing), ] 176 | if (head) 177 | out <- head(out, n) 178 | out 179 | } 180 | 181 | # shorthand 182 | ShowMemoryUse <- function(..., n=30) { 183 | require("pryr"); 184 | sink(); # make sure print to screen 185 | print(pryr::mem_used()); 186 | print(sessionInfo()); 187 | print(.ls.objects(..., order.by="Size", decreasing=TRUE, head=TRUE, n=n)); 188 | print(warnings()); 189 | } 190 | 191 | CleanMemory <- function(){ 192 | gc(); 193 | } 194 | 195 | # need to obtain the full path to convert (from imagemagik) for cropping images 196 | GetBashFullPath<-function(){ 197 | path <- system("which bash", intern=TRUE); 198 | if((length(path) == 0) && (typeof(path) == "character")){ 199 | print("Could not find bash in the PATH!"); 200 | return("NA"); 201 | } 202 | return(path); 203 | } 204 | 205 | # private method for all sqlite queries 206 | .query.sqlite <- function(db.con, statement, offline=TRUE){ 207 | rs <- dbSendQuery(db.con, statement); 208 | res <- fetch(rs, n=-1); # get all records 209 | dbClearResult(rs); 210 | if(offline){ 211 | dbDisconnect(db.con); 212 | } 213 | cleanMem(); 214 | return(res); 215 | } 216 | 217 | fast.write.csv <- function(dat, file, row.names=TRUE){ 218 | tryCatch( 219 | { 220 | if(is.data.frame(dat)){ 221 | # there is a rare bug in data.table (R 3.6) which kill the R process in some cases 222 | data.table::fwrite(dat, file, row.names=row.names); 223 | }else{ 224 | write.csv(dat, file, row.names=row.names); 225 | } 226 | }, error=function(e){ 227 | print(e); 228 | write.csv(dat, file, row.names=row.names); 229 | }, warning=function(w){ 230 | print(w); 231 | write.csv(dat, file, row.names=row.names); 232 | }); 233 | } 234 | 235 | cleanMem <- function(n=10) { for (i in 1:n) gc() } 236 | 237 | .set.nSet <- function(dataSetObj=NA){ 238 | dataSet <<- dataSetObj; 239 | if(!exists(".on.public.web")){ 240 | .on.public.web <<- T; 241 | } 242 | if(.on.public.web){ 243 | return (1); 244 | }else{ 245 | return(dataSetObj); 246 | } 247 | } 248 | 249 | .get.nSet <- function(dataSetObj=NA){ 250 | if(.on.public.web){ 251 | return(dataSet) 252 | }else{ 253 | return(dataSetObj); 254 | } 255 | } 256 | 257 | ReadList <- function(dataSetObj=NA, fullPath, fileNm){ 258 | fullUrl <- url(paste0(fullPath,"/", fileNm)) 259 | all_str <- paste0(readLines(fullUrl),collapse="\n"); 260 | return(all_str); 261 | } 262 | 263 | 264 | makeReadable <- function(str){ 265 | result <- switch(str, 266 | pct = "Percent", 267 | abs = "Absolute", 268 | log = "Log2", 269 | rle = "RLE", 270 | array = "Microarray", 271 | count= "RNA-Seq", 272 | hsa = "H. sapiens (human)", 273 | mmu = "M. musculus (mouse)", 274 | rno = "R. norvegicus (rat)", 275 | cel = "C. elegans (roundworm)", 276 | dme = "D. melanogaster (fruitfly)", 277 | dre = "D. rerio (zebrafish)", 278 | sce = "S. cerevisiae (yeast)", 279 | eco = "E. coli", 280 | ath = "A. thaliana (Arabidopsis)", 281 | bta = "B. taurus (cow)", 282 | gga = "G. gallus (chicken)", 283 | mun = "M. unguiculatus (Mongolian gerbil)", 284 | bsu = "B. subtilis", 285 | pae = "P. aeruginosa", 286 | mtb = "M. tuberculosis", 287 | smm = "S. mansoni (schistosomiasis)", 288 | tbr = "T. brucei (trypanosoma)", 289 | pfa = "P. falciparum (malaria)", 290 | cjo = "C. japonica (japanese quail)", 291 | xla = "X. laevis (African clawed frog)", 292 | ppr = "P. promelas (fathead minnow; custom)", 293 | fhm = "P. promelas (fathead minnow; NCBI)", 294 | nlf = "L. pipiens (northern leopard frog)", 295 | omk = "O. mykiss (rainbow trout)", 296 | ham = "H. americanus (American lobster)", 297 | cdi = "C. dilutus", 298 | dma = "D. magna", 299 | rsu = "R. subcapitata", 300 | haz = "H. azteca", 301 | fcd = "F. candida", 302 | "entrez" = "Entrez ID", 303 | "refseq" = "RefSeq ID", 304 | "gb" = "Genbank ID", 305 | "symbol" = "Official Gene Symbol", 306 | "embl_gene" = "Ensembl Gene ID", 307 | "embl_transcript" = "Ensemble Transcript ID", 308 | "embl_protein" = "Ensembl Protein ID", 309 | "uniprot" = "Uniprot Accession ID", 310 | "hgu95a" = "Affymetrix Human Genome U95 (chip hgu95a)", 311 | "hgu95av2" = "Affymetrix Human Genome U95 (chip hgu95av2)", 312 | "hgu95b" = "Affymetrix Human Genome U95 (chip hgu95b)", 313 | "hgu95c" = "Affymetrix Human Genome U95 (chip hgu95c)", 314 | "hgu95d" = "Affymetrix Human Genome U95 (chip hgu95d)", 315 | "hgu95e" = "Affymetrix Human Genome U95 (chip hgu95e)", 316 | "hgu133a" = "Affymetrix Human Genome U133 (chip hgu133a)", 317 | "hgu133b" = "Affymetrix Human Genome U133 (chip hgu133b)", 318 | "hgu133plus2" = "Affymetrix Human Genome U133plus2 (hgu133plus2)", 319 | "hgu133plus2pm" = "Affymetrix Human Genome U133plus2_PM (hgu133plus2pm)", 320 | "lumiht12v3" = "Illumina HumanHT-12 V3 BeadArray", 321 | "lumiht12v4" = "Illumina HumanHT-12 V4 BeadArray", 322 | "lumiref8v2" = "Illumina HumanRef-8 V2 BeadArray", 323 | "lumiref8v3" = "Illumina HumanRef-8 V3 BeadArray", 324 | "lumiwg6v2" = "Illumina HumanWG-6 V2 BeadArray", 325 | "lumiwg6v3" = "Illumina HumanWG-6 V3 BeadArray", 326 | "agi4100a" = "Agilent Human 1 cDNA Microarray (4100A)", 327 | "agi4101a" = "Agilent Human 2 cDNA Microarray (4101A)", 328 | "agi4110b" = "Agilent Human 1A cDNA Microarray (4110B)", 329 | "agi4111a" = "Agilent Human 1B cDNA Microarray (4111A)", 330 | "agi4112a" = "Agilent Human Genome Whole Microarray (4x44k/4112)", 331 | "agi4845a" = "Agilent Human AMADID 026652 Microarray (4845A)", 332 | "lumiwg6v1" = "Illumina MouseWG-6 v1.0 Bead Array", 333 | "lumiwg6v11" = "Illumina MouseWG-6 v1.1 Bead Array", 334 | "lumiwg6v2" = "Illumina MouseWG-6 v2.0 Bead Array", 335 | "lumiref8v1" = "Illumina MouseRef-8 v1.0 Bead Array", 336 | "lumiref8v2" = "Illumina MouseRef-8 v2.0 Bead Array", 337 | "mgu74a" = "Affymetrix Murine Genome U74v2 (chip mgu74a)", 338 | "mgu74av2" = "Affymetrix Murine Genome U74v2 (chip mgu74av2)", 339 | "mgu74b" = "Affymetrix Murine Genome U74v2 (chip mgu74b)", 340 | "mgu74bv2" = "Affymetrix Murine Genome U74v2 (chip mgu74bv2)", 341 | "mgu74c" = "Affymetrix Murine Genome U74v2 (chip mgu74c)", 342 | "mgu74cv2" = "Affymetrix Murine Genome U74v2 (chip mgu74cv2)", 343 | "moe430a" = "Affymetrix Mouse Expression Set 430 (chip moe430a)", 344 | "moe430b" = "Affymetrix Mouse Expression Set 430 (chip moe430b)", 345 | "moe430_2" = "Affymetrix GeneChip Mouse Genome 430 2.0", 346 | "mgi_st1" = "Affymetrix Mouse Gene 1.0 ST Array", 347 | "mgu4101a" = "Agilent Mouse Array (chip mgug4104a)", 348 | "mgu4120a" = "Agilent Mouse Array (chip mgug4120a)", 349 | "mgu4121a" = "Agilent Mouse Array (chip mgug4121a)", 350 | "mgu4122a" = "Agilent Mouse Array (chip mgug4122a)", 351 | "kegg" = "KEGG", 352 | "keggp" = "KEGG species specific", 353 | "reactome" = "Reactome", 354 | "go_bp" = "GO:BP", 355 | "go_mf" = "GO:MF", 356 | "go_cc" = "GO:CC", 357 | "panth" = "PANTHER Slim", 358 | "motif_set" = "Motif", 359 | "trrust" = "TRRUST", 360 | "encode" = "ENCODE", 361 | "chea" = "CHEA", 362 | "jaspar" = "JASPAR", 363 | "innate" = "InnateDB", 364 | "string" = "StringDB", 365 | "intact" = "IntAct", 366 | "huri" = "HuRI", 367 | "mirtarbase" = "miRTarBase", 368 | "tarbase" = "TarBase", 369 | "mirecords" = "miRecords", 370 | "mirtarbase" = "miRTarBase", 371 | "tarbase" = "TarBase", 372 | "recon2" = "Recon2", 373 | "recon3" = "Recon3D", 374 | "agora" = "AGORA", 375 | "embl" ="EMBL", 376 | "vep" = "VEP", 377 | "admire" = "ADmiRE", 378 | "snp2tfbs" = "SNP2TFBS", 379 | "hmdb" = "HMDB", 380 | "pubchem" = "PubChem", 381 | str) 382 | } 383 | 384 | 385 | GetNodeMat <- function(){ 386 | if(is.null(dataSet$imgSet$node_table)){ 387 | df <- .readDataTable('node_table.csv') 388 | df[,-c(1:2)] <- lapply(df[,-c(1:2)], function(col) as.numeric(as.character(col))) 389 | dataSet$imgSet$node_table <<- df; 390 | } 391 | return(as.matrix(dataSet$imgSet$node_table[,-c(1:2)])) # ensure matrix of numerics 392 | } 393 | 394 | GetNodeRowNames <- function(){ 395 | if(is.null(dataSet$imgSet$node_table)){ 396 | df <- .readDataTable('node_table.csv') 397 | dataSet$imgSet$node_table <<- df; 398 | 399 | } 400 | dataSet$imgSet$node_table$Id; 401 | } 402 | 403 | GetNodeGeneSymbols <- function(){ 404 | if(is.null(dataSet$imgSet$node_table)){ 405 | df <- .readDataTable('node_table.csv') 406 | dataSet$imgSet$node_table <<- df; 407 | 408 | } 409 | dataSet$imgSet$node_table$Label; 410 | } 411 | 412 | GetNodeColNames <- function(){ 413 | if(is.null(dataSet$imgSet$node_table)){ 414 | df <- .readDataTable('node_table.csv') 415 | dataSet$imgSet$node_table <<- df; 416 | 417 | } 418 | return(colnames(dataSet$imgSet$node_table[,-c(1:2)])); 419 | 420 | } 421 | 422 | CleanNumber <-function(bdata){ 423 | if(sum(bdata==Inf)>0){ 424 | inx <- bdata == Inf; 425 | bdata[inx] <- NA; 426 | bdata[inx] <- 999999; 427 | } 428 | if(sum(bdata==-Inf)>0){ 429 | inx <- bdata == -Inf; 430 | bdata[inx] <- NA; 431 | bdata[inx] <- -999999; 432 | } 433 | bdata; 434 | } 435 | 436 | CheckDetailsTablePerformed <-function(type){ 437 | performed <- T; 438 | if(type == "node"){ 439 | performed <- file.exists("node_table.csv"); 440 | }else if(type %in% c( "network_enr", "regNetwork_enr", "gba_enr", "module_enr", "defaultEnr")){ 441 | clean_type <- gsub("_enr", "", type); 442 | performed <- !is.null(dataSet$imgSet$enrTables[[clean_type]]); 443 | }else if(type %in% c( "peak_anot")){ 444 | performed <- file.exists("peak_annotation.csv") 445 | } 446 | print(paste("checkPerformed=", type, "====",performed)); 447 | 448 | return(performed) 449 | } 450 | 451 | 452 | GetPeakAnnotMat <- function(){ 453 | if(is.null(dataSet$imgSet$peak_annotation)){ 454 | df <- .readDataTable('peak_annotation.csv') 455 | dataSet$imgSet$peak_annotation <<- df; 456 | } 457 | df <- dataSet$imgSet$peak_annotation 458 | cols_to_exclude <- c("class", "formula", "annotation") 459 | cols_to_convert <- setdiff(names(df), cols_to_exclude) 460 | 461 | df[cols_to_convert] <- lapply(df[cols_to_convert], function(col) as.numeric(as.character(col))) 462 | return(as.matrix(df[cols_to_convert])) # ensure matrix of numerics 463 | } 464 | 465 | GetPeakAnnotRowNames <- function(){ 466 | if(is.null(dataSet$imgSet$peak_annotation)){ 467 | df <- .readDataTable('peak_annotation.csv') 468 | dataSet$imgSet$peak_annotation <<- df; 469 | 470 | } 471 | dataSet$imgSet$peak_annotation$annotation; 472 | } 473 | 474 | GetPeakAnnotClass <- function(){ 475 | if(is.null(dataSet$imgSet$peak_annotation)){ 476 | df <- .readDataTable('peak_annotation.csv') 477 | dataSet$imgSet$node_table <<- df; 478 | 479 | } 480 | dataSet$imgSet$peak_annotation$class; 481 | } 482 | 483 | 484 | GetPeakAnnotColNames <- function(){ 485 | if(is.null(dataSet$imgSet$peak_annotation)){ 486 | df <- .readDataTable('peak_annotation.csv') 487 | dataSet$imgSet$peak_annotation <<- df; 488 | 489 | } 490 | df <- dataSet$imgSet$peak_annotation 491 | cols_to_exclude <- c("class", "formula", "annotation") 492 | cols_to_convert <- setdiff(names(df), cols_to_exclude) 493 | 494 | return(colnames(dataSet$imgSet$peak_annotation[cols_to_convert])); 495 | 496 | } -------------------------------------------------------------------------------- /R/RcppExports.R: -------------------------------------------------------------------------------- 1 | # Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | path_annotate <- function(ilp_nodes, canu_met, ilp_edges_anno_met, dis_mat_met, g_annotation, canu_nonmet, ilp_edges_anno_nonmet, dis_mat_nonmet, g_anno_non) { 5 | .Call(`_OmicsNetR_path_annotate`, ilp_nodes, canu_met, ilp_edges_anno_met, dis_mat_met, g_annotation, canu_nonmet, ilp_edges_anno_nonmet, dis_mat_nonmet, g_anno_non) 6 | } 7 | 8 | matchHMDB <- function(annotation, Restable, peakidx, formularidx) { 9 | .Call(`_OmicsNetR_matchHMDB`, annotation, Restable, peakidx, formularidx) 10 | } 11 | 12 | convert2KEGG <- function(HMDBIDs, database) { 13 | .Call(`_OmicsNetR_convert2KEGG`, HMDBIDs, database) 14 | } 15 | 16 | initialize_structureset <- function(NodeSet) { 17 | .Call(`_OmicsNetR_initialize_structureset`, NodeSet) 18 | } 19 | 20 | Heterodimer_connection_core <- function(pgroup, ppm) { 21 | .Call(`_OmicsNetR_Heterodimer_connection_core`, pgroup, ppm) 22 | } 23 | 24 | fast_calculate_formula <- function(formular1, transformulas, sign) { 25 | .Call(`_OmicsNetR_fast_calculate_formula`, formular1, transformulas, sign) 26 | } 27 | 28 | propagate_heterodimer_core <- function(df_heterodimer, sf, propagation_category, node_mass, ppm_threshold) { 29 | .Call(`_OmicsNetR_propagate_heterodimer_core`, df_heterodimer, sf, propagation_category, node_mass, ppm_threshold) 30 | } 31 | 32 | #' Internal function \code{call_sr} 33 | #' 34 | #' This function is internally used to solve the PCST. 35 | #' 36 | #' @keywords internal 37 | #' 38 | #' @param from A \code{CharacterVector} that corresponds to \code{head} nodes of the edges. 39 | #' @param to A \code{CharacterVector} that corresponds the \code{tail} nodes of the edges. 40 | #' @param cost A \code{NumericVector} which represents the edge weights. 41 | #' @param node_names A \code{CharacterVector} demonstrates the names of the nodes. 42 | #' @param node_prizes A \code{NumericVector} which corresponds to the node prizes. 43 | #' @author Murodzhon Akhmedov 44 | #' 45 | call_sr <- function(from, to, cost, node_names, node_prizes) { 46 | .Call(`_OmicsNetR_call_sr`, from, to, cost, node_names, node_prizes) 47 | } 48 | 49 | -------------------------------------------------------------------------------- /R/lc8_src.R: -------------------------------------------------------------------------------- 1 | ## LC8 package source 2 | ## source: https://github.com/LiChenPU/Formula_manipulation/ 3 | ## Reference: https://www.nature.com/articles/s41592-021-01303-3 4 | ## 5 | 6 | 7 | 8 | my_calculate_formula <- function(Formula1,Formula2,sign = 1, Valid_formula = FALSE){ 9 | formula2_ls = list() 10 | for(i in 1:length(Formula2)){ 11 | formula2 = Formula2[i] 12 | { 13 | formula2 <- gsub("D", "[2]H", formula2) 14 | ende2 <- nchar(formula2) 15 | element2 <- c() 16 | number2 <- c() 17 | j <- c(1) 18 | while (j <= ende2) { 19 | if (substr(formula2, j, j) == c("[")) { 20 | b <- j 21 | while (any(substr(formula2, j, j) == c("]")) != 22 | TRUE) { 23 | j <- c(j + 1) 24 | } 25 | k <- j 26 | while (any(substr(formula2, j, j) == c("-", ".", "0", "1", 27 | "2", "3", "4", "5", "6", "7", "8", "9")) != 28 | TRUE) { 29 | j <- c(j + 1) 30 | } 31 | m <- c(j - 1) 32 | element2 <- c(element2, substr(formula2, b, m)) 33 | } 34 | if (any(substr(formula2, j, j) == c("-", ".", "0", "1", "2", "3", 35 | "4", "5", "6", "7", "8", "9")) != TRUE) { 36 | k <- j 37 | while (any(substr(formula2, j, j) == c("-", ".", "0", "1", 38 | "2", "3", "4", "5", "6", "7", "8", "9")) != 39 | TRUE) { 40 | j <- c(j + 1) 41 | } 42 | m <- c(j - 1) 43 | j <- c(j - 1) 44 | element2 <- c(element2, substr(formula2, k, m)) 45 | } 46 | if (any(substr(formula2, j, j) == c("-", ".", "0", "1", "2", "3", 47 | "4", "5", "6", "7", "8", "9")) == TRUE) { 48 | k <- j 49 | while (any(substr(formula2, j, j) == c("-", ".", "0", "1", 50 | "2", "3", "4", "5", "6", "7", "8", "9")) == 51 | TRUE) { 52 | j <- c(j + 1) 53 | } 54 | m <- c(j - 1) 55 | j <- c(j - 1) 56 | number2 <- c(number2, as.numeric(substr(formula2, 57 | k, m))) 58 | } 59 | j <- j + 1 60 | 61 | } 62 | 63 | } 64 | number2 = number2 * sign 65 | formula2_ls[[length(formula2_ls)+1]] = list(element2, number2) 66 | } 67 | 68 | formula1_ls = list() 69 | for(i in 1:length(Formula1)){ 70 | formula1 = Formula1[i] 71 | { 72 | formula1 <- gsub("D", "[2]H", formula1) 73 | ende2 <- nchar(formula1) 74 | element1 <- c() 75 | number1 <- c() 76 | j <- c(1) 77 | while (j <= ende2) { 78 | if (substr(formula1, j, j) == c("[")) { 79 | b <- j 80 | while (any(substr(formula1, j, j) == c("]")) != 81 | TRUE) { 82 | j <- c(j + 1) 83 | } 84 | k <- j 85 | while (any(substr(formula1, j, j) == c("-", ".", "0", "1", 86 | "2", "3", "4", "5", "6", "7", "8", "9")) != 87 | TRUE) { 88 | j <- c(j + 1) 89 | } 90 | m <- c(j - 1) 91 | element1 <- c(element1, substr(formula1, b, m)) 92 | } 93 | if (any(substr(formula1, j, j) == c("-", ".", "0", "1", "2", "3", 94 | "4", "5", "6", "7", "8", "9")) != TRUE) { 95 | k <- j 96 | while (any(substr(formula1, j, j) == c("-", ".", "0", "1", 97 | "2", "3", "4", "5", "6", "7", "8", "9")) != 98 | TRUE) { 99 | j <- c(j + 1) 100 | } 101 | m <- c(j - 1) 102 | j <- c(j - 1) 103 | element1 <- c(element1, substr(formula1, k, m)) 104 | } 105 | if (any(substr(formula1, j, j) == c("-", ".", "0", "1", "2", "3", 106 | "4", "5", "6", "7", "8", "9")) == TRUE) { 107 | k <- j 108 | while (any(substr(formula1, j, j) == c("-", ".", "0", "1", 109 | "2", "3", "4", "5", "6", "7", "8", "9")) == 110 | TRUE) { 111 | j <- c(j + 1) 112 | } 113 | m <- c(j - 1) 114 | j <- c(j - 1) 115 | number1 <- c(number1, as.numeric(substr(formula1, 116 | k, m))) 117 | } 118 | j <- j + 1 119 | } 120 | } 121 | formula1_ls[[length(formula1_ls)+1]] = list(element1, number1) 122 | } 123 | 124 | formula_mat = matrix("", nrow = length(formula1_ls), ncol = length(formula2_ls)) 125 | valid_mat = matrix(F, nrow = length(formula1_ls), ncol = length(formula2_ls)) 126 | for(row_i in 1:length(Formula1)){ 127 | element1 = formula1_ls[[row_i]][[1]] 128 | number1 = formula1_ls[[row_i]][[2]] 129 | for(col_j in 1:length(Formula2)){ 130 | element2 = formula2_ls[[col_j]][[1]] 131 | number2 = formula2_ls[[col_j]][[2]] 132 | count_all = number1 133 | elem_all = element1 134 | for(i in 1:length(element2)){ 135 | if(any(element2[i]==elem_all) == TRUE){ 136 | count_all[elem_all==element2[i]] = count_all[elem_all==element2[i]]+number2[i] 137 | }else{ 138 | count_all = c(count_all,number2[i]) 139 | elem_all = c(elem_all,element2[i]) 140 | } 141 | } 142 | 143 | if(any(count_all<0)){ 144 | valid_mat[row_i,col_j]=F 145 | } 146 | 147 | elem_order = order(elem_all) 148 | count_all = count_all[elem_order] 149 | elem_all = elem_all[elem_order] 150 | 151 | elem_all=elem_all[count_all!=0] 152 | count_all=count_all[count_all!=0] 153 | formula_all=c() 154 | for (i in 1:length(count_all)) { 155 | formula_all <- c(formula_all, elem_all[i], 156 | count_all[i]) 157 | } 158 | formula_mat[row_i,col_j]=paste0(formula_all, collapse = "") 159 | } 160 | } 161 | 162 | if(length(Formula1)==1 & length(Formula2)==1){ 163 | formula_mat = as.vector(formula_mat) 164 | valid_mat = as.vector(valid_mat) 165 | } 166 | 167 | if(Valid_formula){ 168 | return(list(formula_mat, valid_mat)) 169 | } else { 170 | return(formula_mat) 171 | } 172 | } 173 | 174 | formula_mz <- function(formula = "C2H4O1", charge = 0, elem_table = OmicsNetR::elem_table){ 175 | 176 | mz = numeric() 177 | for(i in 1:length(formula)){ 178 | temp_formula = formula[i] 179 | if(is.na(temp_formula) | is.null(temp_formula)){ 180 | mz[i] = NA 181 | next 182 | } 183 | if(temp_formula == ""){ 184 | mz[i] = 0 185 | next 186 | } 187 | 188 | temp_formula <- gsub("D", "[2]H", temp_formula) 189 | ende2 <- nchar(temp_formula) 190 | element2 <- c() 191 | number2 <- c() 192 | j <- c(1) 193 | while (j <= ende2) { 194 | if (substr(temp_formula, j, j) == c("[")) { 195 | b <- j 196 | while (any(substr(temp_formula, j, j) == c("]")) != 197 | TRUE) { 198 | j <- c(j + 1) 199 | } 200 | k <- j 201 | while (any(substr(temp_formula, j, j) == c("-", ".","0", "1", 202 | "2", "3", "4", "5", "6", "7", "8", "9")) != 203 | TRUE) { 204 | j <- c(j + 1) 205 | } 206 | m <- c(j - 1) 207 | element2 <- c(element2, substr(temp_formula, b, m)) 208 | } 209 | if (any(substr(temp_formula, j, j) == c("-", ".","0", "1", "2", "3", 210 | "4", "5", "6", "7", "8", "9")) != TRUE) { 211 | k <- j 212 | while (any(substr(temp_formula, j, j) == c("-", ".","0", "1", 213 | "2", "3", "4", "5", "6", "7", "8", "9")) != 214 | TRUE) { 215 | j <- c(j + 1) 216 | } 217 | m <- c(j - 1) 218 | j <- c(j - 1) 219 | element2 <- c(element2, substr(temp_formula, k, m)) 220 | } 221 | if (any(substr(temp_formula, j, j) == c("-", ".","0", "1", "2", "3", 222 | "4", "5", "6", "7", "8", "9")) == TRUE) { 223 | k <- j 224 | while (any(substr(temp_formula, j, j) == c("-", ".","0", "1", 225 | "2", "3", "4", "5", "6", "7", "8", "9")) == 226 | TRUE) { 227 | j <- c(j + 1) 228 | } 229 | m <- c(j - 1) 230 | j <- c(j - 1) 231 | number2 <- c(number2, as.numeric(substr(temp_formula, 232 | k, m))) 233 | } 234 | j <- j + 1 235 | 236 | } 237 | 238 | mz[i]=0 239 | 240 | for(j in 1:length(element2)){ 241 | mz[i] = mz[i] + elem_table$mass[element2[j] == elem_table$element] * number2[j] 242 | } 243 | 244 | 245 | e_mass = 0.00054857990943 246 | mz[i] = mz[i] - e_mass*charge 247 | 248 | } 249 | return(mz) 250 | } 251 | 252 | #' formula_rdbe 253 | #' 254 | #' @param formula e.g. "C2H4O1" 255 | #' @param elem_table a table records unsaturation 256 | #' @noRd 257 | #' @return the ring and double bond number 258 | #' 259 | #' @examples formula_rdbe(formula = "C2H4O1", elem_table = OmicsNetR::elem_table) 260 | formula_rdbe = function(formula = "C2H4O1", elem_table = OmicsNetR::elem_table){ 261 | 262 | rdbe = numeric() 263 | for(i in 1:length(formula)){ 264 | 265 | temp_formula = formula[i] 266 | temp_formula <- gsub("D", "[2]H", temp_formula) 267 | ende2 <- nchar(temp_formula) 268 | element2 <- c() 269 | number2 <- c() 270 | j <- c(1) 271 | while (j <= ende2) { 272 | if (substr(temp_formula, j, j) == c("[")) { 273 | b <- j 274 | while (any(substr(temp_formula, j, j) == c("]")) != 275 | TRUE) { 276 | j <- c(j + 1) 277 | } 278 | k <- j 279 | while (any(substr(temp_formula, j, j) == c("-", ".", "0", "1", 280 | "2", "3", "4", "5", "6", "7", "8", "9")) != 281 | TRUE) { 282 | j <- c(j + 1) 283 | } 284 | m <- c(j - 1) 285 | element2 <- c(element2, substr(temp_formula, b, m)) 286 | } 287 | if (any(substr(temp_formula, j, j) == c("-", ".", "0", "1", "2", "3", 288 | "4", "5", "6", "7", "8", "9")) != TRUE) { 289 | k <- j 290 | while (any(substr(temp_formula, j, j) == c("-", ".", "0", "1", 291 | "2", "3", "4", "5", "6", "7", "8", "9")) != 292 | TRUE) { 293 | j <- c(j + 1) 294 | } 295 | m <- c(j - 1) 296 | j <- c(j - 1) 297 | element2 <- c(element2, substr(temp_formula, k, m)) 298 | } 299 | if (any(substr(temp_formula, j, j) == c("-", ".", "0", "1", "2", "3", 300 | "4", "5", "6", "7", "8", "9")) == TRUE) { 301 | k <- j 302 | while (any(substr(temp_formula, j, j) == c("-", ".", "0", "1", 303 | "2", "3", "4", "5", "6", "7", "8", "9")) == 304 | TRUE) { 305 | j <- c(j + 1) 306 | } 307 | m <- c(j - 1) 308 | j <- c(j - 1) 309 | number2 <- c(number2, as.numeric(substr(temp_formula, 310 | k, m))) 311 | } 312 | j <- j + 1 313 | 314 | } 315 | 316 | rdbe[i]=1 317 | for (j in 1:length(element2)) { 318 | rdbe[i] = rdbe[i] + elem_table$unsaturation[element2[j] == 319 | elem_table$element] * number2[j] 320 | } 321 | } 322 | return(rdbe) 323 | } 324 | 325 | #' isotopic_abundance 326 | #' 327 | #' @param formula e.g. "C2H4O1" 328 | #' @param elem_table a table records unsaturation 329 | #' @param isotope e.g. [13]C, or [13]C2 for M+2 330 | #' @noRd 331 | #' @return the ratio of given formula and its isotopic peak 332 | #' 333 | #' @examples isotopic_abundance(formula = "C2H4O1", elem_table = OmicsNetR::elem_table) 334 | isotopic_abundance = function(formula = "C2H4O1", isotope = "[13]C1", elem_table = OmicsNetR::elem_table){ 335 | formula <- gsub("D", "[2]H", formula) 336 | ende2 <- nchar(formula) 337 | element2 <- c() 338 | number2 <- c() 339 | j <- c(1) 340 | while (j <= ende2) { 341 | 342 | if (substr(formula, j, j) == c("[")) { 343 | b <- j 344 | while (any(substr(formula, j, j) == c("]")) != 345 | TRUE) { 346 | j <- c(j + 1) 347 | } 348 | k <- j 349 | while (any(substr(formula, j, j) == c("-", "0", "1", 350 | "2", "3", "4", "5", "6", "7", "8", "9")) != 351 | TRUE) { 352 | j <- c(j + 1) 353 | } 354 | m <- c(j - 1) 355 | element2 <- c(element2, substr(formula, b, m)) 356 | } 357 | if (any(substr(formula, j, j) == c("-", "0", "1", "2", "3", 358 | "4", "5", "6", "7", "8", "9")) != TRUE) { 359 | k <- j 360 | while (any(substr(formula, j, j) == c("-", "0", "1", 361 | "2", "3", "4", "5", "6", "7", "8", "9")) != 362 | TRUE) { 363 | j <- c(j + 1) 364 | } 365 | m <- c(j - 1) 366 | j <- c(j - 1) 367 | element2 <- c(element2, substr(formula, k, m)) 368 | } 369 | if (any(substr(formula, j, j) == c("-", "0", "1", "2", "3", 370 | "4", "5", "6", "7", "8", "9")) == TRUE) { 371 | k <- j 372 | while (any(substr(formula, j, j) == c("-", "0", "1", 373 | "2", "3", "4", "5", "6", "7", "8", "9")) == 374 | TRUE) { 375 | j <- c(j + 1) 376 | } 377 | m <- c(j - 1) 378 | j <- c(j - 1) 379 | number2 <- c(number2, as.numeric(substr(formula, 380 | k, m))) 381 | } 382 | j <- j + 1 383 | 384 | } 385 | 386 | 387 | number1 = number2 388 | element1 = element2 389 | 390 | 391 | formula <- gsub("D", "[2]H", isotope) 392 | ende2 <- nchar(formula) 393 | element2 <- c() 394 | number2 <- c() 395 | j <- c(1) 396 | while (j <= ende2) { 397 | 398 | if (substr(formula, j, j) == c("[")) { 399 | b <- j 400 | while (any(substr(formula, j, j) == c("]")) != 401 | TRUE) { 402 | j <- c(j + 1) 403 | } 404 | k <- j 405 | while (any(substr(formula, j, j) == c("-", "0", "1", 406 | "2", "3", "4", "5", "6", "7", "8", "9")) != 407 | TRUE) { 408 | j <- c(j + 1) 409 | if(j>ende2){ break } 410 | } 411 | m <- c(j - 1) 412 | element2 <- c(element2, substr(formula, b, m)) 413 | } 414 | if(j>ende2){ 415 | number2 = c(number2, 1) 416 | break 417 | } 418 | if (any(substr(formula, j, j) == c("-", "0", "1", "2", "3", 419 | "4", "5", "6", "7", "8", "9")) != TRUE) { 420 | k <- j 421 | while (any(substr(formula, j, j) == c("-", "0", "1", 422 | "2", "3", "4", "5", "6", "7", "8", "9")) != 423 | TRUE) { 424 | j <- c(j + 1) 425 | if(j>ende2){ break } 426 | } 427 | m <- c(j - 1) 428 | j <- c(j - 1) 429 | element2 <- c(element2, substr(formula, k, m)) 430 | } 431 | if(j>ende2){ 432 | number2 = c(number2, 1) 433 | break 434 | } 435 | if (any(substr(formula, j, j) == c("-", "0", "1", "2", "3", 436 | "4", "5", "6", "7", "8", "9")) == TRUE) { 437 | k <- j 438 | while (any(substr(formula, j, j) == c("-", "0", "1", 439 | "2", "3", "4", "5", "6", "7", "8", "9")) == 440 | TRUE) { 441 | j <- c(j + 1) 442 | } 443 | m <- c(j - 1) 444 | j <- c(j - 1) 445 | number2 <- c(number2, as.numeric(substr(formula, 446 | k, m))) 447 | } 448 | j <- j + 1 449 | 450 | } 451 | 452 | selected_isotopes = grepl("\\[\\d+\\]",element2) 453 | number_isotopes = number2[selected_isotopes] 454 | element_isotopes = element2[selected_isotopes] 455 | 456 | ratio = 1 457 | for(i in 1:length(element_isotopes)){ 458 | element_isotope = element_isotopes[i] 459 | element_parent = gsub("\\[\\d+\\]", "", element_isotope) 460 | num_isotope_formula2 = number_isotopes[i] 461 | 462 | 463 | num_parent_formula1 = 0 464 | num_isotpe_formula1 = 0 465 | if(any(element1 == element_parent)){ 466 | num_parent_formula1 = number1[element1 == element_parent] 467 | } 468 | if(any(element1 == element_isotope)){ 469 | num_isotpe_formula1 = number1[element1 == element_isotope] 470 | } 471 | 472 | natural_abundance = elem_table$abundance[elem_table$element == element_isotope] 473 | 474 | inten_formula1 = choose((num_parent_formula1+num_isotpe_formula1),num_isotpe_formula1)*natural_abundance^(num_isotpe_formula1) 475 | inten_formula2 = choose((num_parent_formula1+num_isotpe_formula1),(num_isotpe_formula1+num_isotope_formula2))*natural_abundance^(num_isotpe_formula1+num_isotope_formula2) 476 | 477 | ratio = ratio * (inten_formula2/inten_formula1) 478 | 479 | } 480 | 481 | return(ratio) 482 | } 483 | 484 | #' my_break_formula 485 | #' 486 | #' @param formula any chemical formula 487 | #' @noRd 488 | #' @return a list containing elem and count 489 | #' 490 | #' @examples my_break_formula("[13]C1C-1H4N2") 491 | my_break_formula = function(formula = "[13]C1C-1H4N2"){ 492 | formula <- gsub("D", "[2]H", formula) 493 | ende2 <- nchar(formula) 494 | element2 <- c() 495 | number2 <- c() 496 | j <- c(1) 497 | while (j <= ende2) { 498 | if (substr(formula, j, j) == c("[")) { 499 | b <- j 500 | while (any(substr(formula, j, j) == c("]")) != 501 | TRUE) { 502 | j <- c(j + 1) 503 | } 504 | k <- j 505 | while (any(substr(formula, j, j) == c("-", ".", "0", "1", 506 | "2", "3", "4", "5", "6", "7", "8", "9")) != 507 | TRUE) { 508 | j <- c(j + 1) 509 | } 510 | m <- c(j - 1) 511 | element2 <- c(element2, substr(formula, b, m)) 512 | } 513 | if (any(substr(formula, j, j) == c("-", ".", "0", "1", "2", "3", 514 | "4", "5", "6", "7", "8", "9")) != TRUE) { 515 | k <- j 516 | while (any(substr(formula, j, j) == c("-", ".", "0", "1", 517 | "2", "3", "4", "5", "6", "7", "8", "9")) != 518 | TRUE) { 519 | j <- c(j + 1) 520 | } 521 | m <- c(j - 1) 522 | j <- c(j - 1) 523 | element2 <- c(element2, substr(formula, k, m)) 524 | } 525 | if (any(substr(formula, j, j) == c("-", ".", "0", "1", "2", "3", 526 | "4", "5", "6", "7", "8", "9")) == TRUE) { 527 | k <- j 528 | while (any(substr(formula, j, j) == c("-", ".", "0", "1", 529 | "2", "3", "4", "5", "6", "7", "8", "9")) == 530 | TRUE) { 531 | j <- c(j + 1) 532 | } 533 | m <- c(j - 1) 534 | j <- c(j - 1) 535 | number2 <- c(number2, as.numeric(substr(formula, 536 | k, m))) 537 | } 538 | j <- j + 1 539 | 540 | } 541 | 542 | return(list(elem=element2, count=number2)) 543 | 544 | } 545 | 546 | #my function to process formula 547 | table_to_formula <- function(temp_formula){ 548 | r = c() 549 | elem = temp_formula$elem 550 | count = temp_formula$count 551 | len = length(elem) 552 | for(i in 1:len){ 553 | if(count[i]!=0){ 554 | r=paste(r, elem[i], count[i], sep="") 555 | } 556 | } 557 | if(sum(count<0)!=0){ 558 | r=paste(r, "Illegal_formula") 559 | } 560 | return (r) 561 | } 562 | 563 | #' elem_num_query 564 | #' 565 | #' @param formula for example "C2H4O2" 566 | #' @param elem_query it refers to element in query 567 | #' 568 | #' @return It returns the number of element in formula 569 | #' @noRd 570 | #' 571 | #' @examples elem_num_query("C2H4O2","C") 572 | elem_num_query = function(formula,elem_query){ 573 | 574 | 575 | if(!is.character(formula)|is.na(formula)){return(NA)} 576 | 577 | formula <- gsub("D", "[2]H", formula) 578 | ende2 <- nchar(formula) 579 | element2 <- c() 580 | number2 <- c() 581 | j <- c(1) 582 | while (j <= ende2) { 583 | #browser() 584 | if (substr(formula, j, j) == c("[")) { 585 | b <- j 586 | while (any(substr(formula, j, j) == c("]")) != 587 | TRUE) { 588 | j <- c(j + 1) 589 | } 590 | k <- j 591 | while (any(substr(formula, j, j) == c("-", ".", "0", "1", 592 | "2", "3", "4", "5", "6", "7", "8", "9")) != 593 | TRUE) { 594 | j <- c(j + 1) 595 | } 596 | m <- c(j - 1) 597 | element2 <- c(element2, substr(formula, b, m)) 598 | } 599 | if (any(substr(formula, j, j) == c("-", ".", "0", "1", "2", "3", 600 | "4", "5", "6", "7", "8", "9")) != TRUE) { 601 | k <- j 602 | while (any(substr(formula, j, j) == c("-", ".", "0", "1", 603 | "2", "3", "4", "5", "6", "7", "8", "9")) != 604 | TRUE) { 605 | j <- c(j + 1) 606 | } 607 | m <- c(j - 1) 608 | j <- c(j - 1) 609 | element2 <- c(element2, substr(formula, k, m)) 610 | } 611 | if (any(substr(formula, j, j) == c("-", ".", "0", "1", "2", "3", 612 | "4", "5", "6", "7", "8", "9")) == TRUE) { 613 | k <- j 614 | while (any(substr(formula, j, j) == c("-", ".", "0", "1", 615 | "2", "3", "4", "5", "6", "7", "8", "9")) == 616 | TRUE) { 617 | j <- c(j + 1) 618 | } 619 | m <- c(j - 1) 620 | j <- c(j - 1) 621 | number2 <- c(number2, as.numeric(substr(formula, 622 | k, m))) 623 | } 624 | j <- j + 1 625 | } 626 | 627 | if(any(element2 == elem_query )){ 628 | num_query = number2[elem_query == element2] 629 | 630 | } 631 | else{ 632 | num_query=0 633 | 634 | } 635 | return(num_query) 636 | } 637 | 638 | 639 | 640 | 641 | 642 | -------------------------------------------------------------------------------- /R/utils_convertIgraph2JSON.R: -------------------------------------------------------------------------------- 1 | 2 | #color shape layout important 3 | my.convert.igraph <- function(dataSetObj=NA, net.nm, filenm, thera=FALSE, dim=3){ 4 | #save.image("igraph.RData"); 5 | if(exists("lbls",envir = .GlobalEnv)) { 6 | lbls <- get("lbls", envir = .GlobalEnv) 7 | } else { 8 | lbls <<- NA; 9 | } 10 | 11 | dataSet <- .get.nSet(dataSetObj); 12 | dim <- as.numeric(dim) 13 | types_arr <<- dataSet$type; 14 | 15 | if(thera){ 16 | g <- my.ppi; 17 | }else{ 18 | g <- ppi.comps[[net.nm]]; 19 | } 20 | current.net.nm <<- net.nm; 21 | modules = "NA" 22 | 23 | nms <- V(g)$name; 24 | #save(omics.net,g, file = "omics.net___checking.rda") 25 | 26 | hit.inx <- match(nms, omics.net$node.data[,1]); 27 | lbls <- omics.net$node.data[hit.inx, 2]; 28 | 29 | # setup shape (gene circle, other squares) 30 | if("peak" %in% dataSet$type){ 31 | shapes <- rep("putative_met", length(nms)); 32 | }else{ 33 | shapes <- rep("gene", length(nms)); 34 | } 35 | itypes <- rep("circle", length(nms)); 36 | 37 | # get edge data 38 | edge.mat <- get.edgelist(g); 39 | edge.mat1 = data.frame(edge.mat) 40 | edge.mat1$color = "target" 41 | edge.mat1 = as.matrix(edge.mat1) 42 | 43 | edge.mat <- cbind(id=1:nrow(edge.mat), source=edge.mat[,1], target=edge.mat[,2], color = edge.mat1[,3]); 44 | 45 | # now get coords 46 | pos.xy <- PerformLayOut(net.nm, "Default"); 47 | # get the note data 48 | node.btw <- as.numeric(betweenness(g)); 49 | node.clo <- as.numeric(closeness(g)); 50 | node.eig <- eigen_centrality(g); 51 | node.eig = as.numeric(node.eig$vector); 52 | 53 | node.dgr <- as.numeric(degree(g)); 54 | exp <-as.vector(get.vertex.attribute(g, name="abundance", index = V(g))); 55 | exp[is.na(exp)] <- 0; 56 | node.exp <- as.numeric(exp); 57 | exp2 <- parse_expression_data(dataSet, exp,nms); 58 | 59 | # node size to degree values 60 | if(vcount(g)>500){ 61 | min.size = 2; 62 | }else if(vcount(g)>200){ 63 | min.size = 3; 64 | }else{ 65 | min.size = 3; 66 | } 67 | 68 | node.sizes <- as.numeric(rescale2NewRange((log(node.btw+1))^2, min.size, 9))*3 +5; 69 | node.sizes2d <- as.numeric(rescale2NewRange((log(node.btw+1))^2, min.size, 12)); 70 | centered <- T; 71 | notcentered <- F; 72 | 73 | require("RColorBrewer"); 74 | topo.val <- log(node.btw+1); 75 | topo.colsb <- topo.colsb1 <- rep("#D3D3D3", length(nms)); 76 | topo.colsw <- topo.colsw1 <- rep("#D3D3D3", length(nms)); 77 | 78 | # color based on expression 79 | bad.inx <- is.na(node.exp) | node.exp==0; 80 | if(!all(bad.inx)){ 81 | exp.val <- node.exp; 82 | node.colsb.exp <- ComputeColorGradient(exp.val, "black", centered); 83 | node.colsw.exp <- ComputeColorGradient(exp.val, "white", centered); 84 | node.cols.pie <- ComputeColorGradient(exp2, "black", centered); 85 | node.colsb.exp[bad.inx] <- "#d3d3d3"; 86 | node.colsw.exp[bad.inx] <- "#c6c6c6"; 87 | }else{ 88 | node.colsb.exp <- rep("#D3D3D3",length(node.dgr)); 89 | node.colsw.exp <- rep("#C6C6C6",length(node.dgr)); 90 | node.cols.pie <- rep("#D3D3D3",length(node.dgr)); 91 | 92 | } 93 | 94 | gene.nms <- rownames(dataSet$seed[["gene"]] ) 95 | prot.nms <- rownames(dataSet$seed[["protein"]] ) 96 | 97 | # now update for bipartite network 98 | 99 | #edge.mat1 <<- edge.mat 100 | gene.inx <- nms %in% c(net.info$gene.ids, net.info$ko.ids); 101 | 102 | if(length(net.info$gene.ids) == 0 && length(net.info$protein.ids) == 0 ){ 103 | #gene.inx = predicted.inx; 104 | #predicted.inx = rep(FALSE,length(node.dgr)); 105 | } 106 | 107 | kncmpd.inx <- nms %in% net.info$kncmpd.ids 108 | prot.inx <- nms %in% net.info$protein.ids; 109 | tf.inx <- nms %in% net.info$tf.ids; 110 | mir.inx <- nms %in% net.info$mir.ids; 111 | peak.inx <- nms %in% net.info$peak.ids; 112 | met.inx <- nms %in% net.info$met.ids; 113 | reg.inx <- nms %in% net.info$reg.ids; 114 | mic.inx <- nms %in% net.info$mic.ids; 115 | snp.inx <- nms %in% rownames(dataSet$seed[["snp"]]); 116 | 117 | 118 | containsGP <- any(gene.nms %in% prot.nms); ## check if any overlap between gene and protein 119 | 120 | 121 | topo.colsw[gene.inx] <- "#FF8484"; 122 | topo.colsw[kncmpd.inx] <- "#00ffff"; 123 | topo.colsw[prot.inx] <- "#FF8484"; 124 | topo.colsw[tf.inx] <- "#39FF14"; 125 | topo.colsw[mir.inx] <- "#00f6ff"; 126 | topo.colsw[peak.inx] <- "#D3D3D3"; 127 | 128 | topo.colsw[met.inx] <- "#ffff00"; 129 | topo.colsw[reg.inx] <- "#ff9900"; 130 | topo.colsw[mic.inx] <- "#39FF14"; 131 | topo.colsw[snp.inx] <- "#4B0082"; 132 | topo.colsw[nms %in% gene.nms] <- "#d3d3d3"; 133 | 134 | topo.colsb <- topo.colsw; 135 | 136 | if(containsGP){ 137 | inx <- nms %in% gene.nms 138 | topo.colsb[inx] <- "#D3D3D3"; 139 | topo.colsw[inx] <- "#D3D3D3"; 140 | color.vec <- c("#D3D3D3", "#FF8484", "#39FF14","#00f6ff", "#D3D3D3", "#00ffff", "#ffff00", "#4B0082", "#39FF14"); 141 | }else{ 142 | color.vec <- c("#FF8484", "#FF8484", "#39FF14","#00f6ff", "#D3D3D3", "#00ffff", "#ffff00", "#4B0082", "#39FF14"); 143 | } 144 | names(color.vec) <- c("gene", "protein", "tf", "mir", "peak", "kncmpd", "met", "reg", "mic"); 145 | 146 | #if(any(predicted.inx)){ 147 | # types_arr <<- c(types_arr, "interactor"); 148 | #} 149 | if(any(gene.inx) && !"gene" %in% types_arr){ 150 | types_arr <<- c(types_arr, "gene"); 151 | } 152 | 153 | shapes[gene.inx] <- "gene"; 154 | shapes[prot.inx] <- "protein"; 155 | shapes[tf.inx] <- "tf"; 156 | shapes[mir.inx] <- "mir"; 157 | shapes[kncmpd.inx] <- "kncmpd"; 158 | 159 | shapes[peak.inx] <- "putative_met"; 160 | shapes[met.inx] <- "met"; 161 | shapes[reg.inx] <- "reg" 162 | shapes[mic.inx] <- "microbe" 163 | shapes[snp.inx] <- "snp"; 164 | 165 | types <- rep("", length(shapes)) 166 | types[gene.inx] <- paste(types[gene.inx],"gene"); 167 | types[peak.inx] <- "putative_met" 168 | types[prot.inx] <- paste(types[prot.inx],"protein"); 169 | types[tf.inx] <- "tf" 170 | types[mir.inx] <- "mir"; 171 | types[met.inx] <- "met"; 172 | types[snp.inx] <- "snp"; 173 | types[kncmpd.inx] <- "kncmpd"; 174 | 175 | types <- trimws(types); 176 | 177 | network_prop = list(); 178 | for(i in 1:length(node.sizes)){ 179 | network_prop[[i]] <- list( 180 | closeness = node.clo[i], 181 | eigen = node.eig[i] 182 | ) 183 | } 184 | 185 | seed.inx <- nms %in% names(expr.vec); 186 | 187 | seed_arr <- rep("notSeed",length(node.dgr)); 188 | seed_arr[seed.inx] <- "seed"; 189 | 190 | type <- rep(FALSE,length(node.dgr)) 191 | type[seed.inx] = TRUE 192 | 193 | lblsu <<- lbls; 194 | node_attr = list.vertex.attributes(g); 195 | node_attr = node_attr[which(node_attr!="names")] 196 | 197 | # now create the json object 198 | nodes <- vector(mode="list"); 199 | 200 | 201 | require("stringr") 202 | displayedLabel<-lbls; 203 | long.inx <- which(stringr:::str_length(lbls) > 32); 204 | displayedLabel[long.inx] <- paste0(strtrim(lbls[long.inx], rep(32, length(lbls[long.inx]))), "..." ) 205 | 206 | moltypes <- shapes; 207 | moltypes[nms %in% gene.nms] <- "gene"; 208 | moltypes[nms %in% prot.nms] <- "protein"; 209 | #moltypes[(nms %in% prot.nms) & (nms %in% gene.nms)] <- "gene_protein"; 210 | for(i in 1:length(node.sizes)){ 211 | nodes[[i]] <- list( 212 | id=nms[i], 213 | idx=i, 214 | label=lbls[i], 215 | displayedLabel = displayedLabel[i], 216 | size=node.sizes[i], 217 | size2d=node.sizes2d[i], 218 | type=shapes[i], 219 | molType=moltypes[i], 220 | types=types[i], 221 | seedArr =seed_arr[i], 222 | color=topo.colsb[i], 223 | colorb=topo.colsb[i], 224 | colorw=topo.colsw[i], 225 | topocolb=topo.colsb[i], 226 | topocolw=topo.colsw[i], 227 | expcolb=node.colsb.exp[i], 228 | expcolw=node.colsw.exp[i], 229 | x2d = pos.xy[i,1], 230 | y2d = pos.xy[i,2], 231 | user =network_prop[[i]], 232 | attributes=list( 233 | degree=node.dgr[i], 234 | between=node.btw[i], 235 | expr = node.exp[i], 236 | closeness = node.clo[i], 237 | eigen = node.eig[i] 238 | ) 239 | ); 240 | } 241 | 242 | if(containsGP){ 243 | nodes[[i]]$exp2 = exp2[[i]]; 244 | nodes[[i]]$expcolpie = node.cols.pie[[i]]; 245 | } 246 | 247 | middleLayerType <- unique(shapes)[1] 248 | 249 | for(i in 1:length(unique(shapes))){ 250 | inx <- shapes == unique(shapes)[i] 251 | if(i == 1){ 252 | sumDgrs <- sum(node.dgr[inx]) 253 | }else{ 254 | if(sumDgrs < sum(node.dgr[inx])){ 255 | middleLayerType <-unique(shapes)[i] 256 | } 257 | } 258 | } 259 | 260 | V(g)$layers <- as.numeric(as.factor(moltypes)); 261 | ppi.comps[[net.nm]] <<- g; 262 | 263 | summary = vector(mode="list"); 264 | summary[[1]] = list(nodes=vcount(g)); 265 | summary[[2]] = list(edges=ecount(g)); 266 | 267 | # save node table 268 | 269 | 270 | # Collect all potential columns as a named list 271 | node_data <- list( 272 | Id = nms, 273 | Label = lbls, 274 | Degree = node.dgr, 275 | Betweenness = if (length(node.btw) > 0) round(node.btw, 2) else NULL, 276 | Expression = node.exp, 277 | Closeness = node.clo, 278 | Eigenvalue = node.eig 279 | ) 280 | 281 | # Filter out NULL or 0-length entries 282 | node_data <- Filter(function(x) length(x) > 0, node_data) 283 | 284 | # Check that all remaining vectors have the same length 285 | lens <- sapply(node_data, length) 286 | 287 | if (length(unique(lens)) == 1 && lens[1] > 0) { 288 | nd.tbl <- as.data.frame(node_data) 289 | } else { 290 | warning("Node table not created: inconsistent or empty inputs.") 291 | nd.tbl <- NULL 292 | } 293 | # order 294 | ord.inx <- order(nd.tbl[,3], nd.tbl[,4], decreasing = TRUE) 295 | nd.tbl <- nd.tbl[ord.inx, ]; 296 | 297 | netData <- list(nodes=nodes,typeVec=dataSet$gene_type_vec, edges=edge.mat, modules=modules, prot.nms=prot.nms,gene.nms=gene.nms, containsGP=containsGP, middleLayerType = middleLayerType); 298 | 299 | dataSet$imgSet$node_table <- nd.tbl; 300 | 301 | if(exists("PeakSet",envir = .GlobalEnv)) { 302 | PeakSet <- get("PeakSet", envir = .GlobalEnv) 303 | netData[["peakNodes"]] <- PeakSet$nodes; 304 | netData[["peakEdges"]] <- PeakSet$edges; 305 | } 306 | 307 | if(file.exists("micSet.qs")){ 308 | micSet <- qs::qread("micSet.qs"); 309 | inx = names(micSet$met.mic) %in% nms; 310 | netData[["metMic"]] <- micSet$met.mic[inx]; 311 | netData[["metMicScore"]] <- micSet$met.mic.score[inx]; 312 | micTbl <- list(); 313 | j = 1; 314 | for(i in 1:length(micSet$met.mic.table)){ 315 | if(micSet$met.mic.table[[i]]["KEGG"] %in% nms){ 316 | micTbl[[j]] <- micSet$met.mic.table[[i]] 317 | j = j + 1; 318 | } 319 | } 320 | netData[["metMicTable"]] <- micTbl 321 | netData[["micThresh"]] <- dataSet$mic.thresh; 322 | } 323 | 324 | if(any(dataSet$gene_type_vec == 4)){ 325 | netData[["snpTable"]] <- snpTable; 326 | netData[["snpTableConsequence"]] <- snpTableConsequence; 327 | } 328 | 329 | netData[["colorVec"]] <- color.vec; 330 | dataSet$jsonNms$network <- filenm 331 | partialToBeSaved <<- c(partialToBeSaved, c(filenm)) 332 | sink(filenm); 333 | cat(RJSONIO::toJSON(netData)); 334 | sink(); 335 | 336 | dataSet <<- dataSet; 337 | return(.set.nSet(dataSet)); 338 | } 339 | 340 | # Define the function 341 | parse_expression_data <- function(dataSet, exp, nms) { 342 | # Create an empty list to store the parsed data 343 | parsed_data <- list() 344 | # Loop through each name in nms 345 | for (i in seq_along(nms)) { 346 | nm <- nms[i] 347 | 348 | # Initialize a vector to store the values 349 | values <- numeric(2) 350 | 351 | # Get the expression value 352 | values[1] <- exp[i] 353 | 354 | # Find the corresponding value in the dataSet$exp.mat matrices 355 | for (name in names(dataSet$exp.mat)) { 356 | mat <- dataSet$exp.mat[[name]] 357 | if (nm %in% rownames(mat)) { 358 | values[2] <- mat[nm, 1] 359 | } else { 360 | values[2] <- 0 361 | } 362 | } 363 | 364 | # Add the vector to the parsed_data list 365 | parsed_data[[i]] <- values 366 | } 367 | 368 | # Return the parsed data 369 | return(parsed_data) 370 | } -------------------------------------------------------------------------------- /R/utils_graph_io.R: -------------------------------------------------------------------------------- 1 | my.read.graphfile <- function(dataSetObj=NA, fileName, fileType) { 2 | dataSet <- .get.nSet(dataSetObj); 3 | require("igraph"); 4 | types_arr <<- ""; 5 | lbls <- ""; 6 | dataSet$fileType <- fileType; 7 | current.msg <<- NULL; 8 | 9 | if(grepl("scatter", fileName)){ 10 | require("RJSONIO") 11 | j = fromJSON(fileName) 12 | nm = "scatter3D.json" 13 | sink(nm); 14 | cat(toJSON(j)); 15 | sink(); 16 | return(1); 17 | } 18 | 19 | if(fileType == "jsonOmicsnet"){ 20 | res <- ProcessOmicsNetJson(dataSet, fileName); 21 | return(res); 22 | }else if(fileType == "jsonGraph"){ 23 | return(.set.nSet(dataSet)); 24 | }else if(fileType == "graphml"){ 25 | graphX = tryCatch({ 26 | read_graph(fileName, format = "graphml") 27 | }, warning = function(w) { 28 | current.msg <<- "Wrong format, please make sure that the file is formatted correctly"; 29 | return(0); 30 | }, error = function(e) { 31 | current.msg <<- "Wrong format, please make sure that the file is formatted correctly"; 32 | return(0); 33 | }, finally = { 34 | 35 | }) 36 | }else if(fileType == "sif"){ 37 | graphX = tryCatch({ 38 | read.sif(fileName, format="igraph", directed = FALSE) 39 | }, warning = function(w) { 40 | current.msg <<- "Wrong format, please make sure that the file is formatted correctly"; 41 | return(0); 42 | }, error = function(e) { 43 | current.msg <<- "Wrong format, please make sure that the file is formatted correctly"; 44 | return(0); 45 | }, finally = { 46 | 47 | }) 48 | }else if(fileType == "txt"){ 49 | df <- read.table(fileName, header=FALSE, stringsAsFactors = FALSE) 50 | df <- as.matrix(df); 51 | graphX = tryCatch({ 52 | graph_from_edgelist(df) 53 | }, warning = function(w) { 54 | current.msg <<- "Wrong format, please make sure that the file is formatted correctly"; 55 | return(0); 56 | }, error = function(e) { 57 | current.msg <<- "Wrong format, please make sure that the file is formatted correctly"; 58 | return(0); 59 | }, finally = { 60 | 61 | }) 62 | 63 | 64 | }else if(fileType == "json"){ 65 | require("RJSONIO"); 66 | dat <- fromJSON(fileName); 67 | if(!is.null(dat$data[["__Org"]])){ 68 | data.org <<- dat$data[["__Org"]]; 69 | } 70 | dfn <- unlist(dat$elements$nodes); 71 | conv <- data.frame(id1=dfn[which(names(dfn)=='data.id')], name1=dfn[which(names(dfn)=='data.name')]); 72 | dfe <- unlist(dat$elements$edges); 73 | dffe <- data.frame(id1=dfe[which(names(dfe) == "data.source")], id2=dfe[which(names(dfe) == "data.target")]); 74 | dfint <- merge(conv, dffe, by="id1"); 75 | colnames(conv) <- c("id2", "name2"); 76 | df <- merge(conv, dfint, by="id2"); 77 | df <- df[,c("id1", "id2")]; 78 | df <- as.matrix(df); 79 | 80 | graphX = tryCatch({ 81 | graph_from_edgelist(df, directed=FALSE); 82 | }, warning = function(w) { 83 | current.msg <<- "Wrong format, please make sure that the file is formatted correctly"; 84 | return(0); 85 | }, error = function(e) { 86 | current.msg <<- "Wrong format, please make sure that the file is formatted correctly"; 87 | return(0); 88 | }, finally = { 89 | 90 | }) 91 | nms <- V(graphX)$name 92 | hit.inx <- match(nms, conv$id2); 93 | lbls <- conv[hit.inx, "name2"]; 94 | mode(lbls) <- "character"; 95 | na.inx <- is.na(lbls); 96 | lbls[na.inx] <- nms[na.inx]; 97 | 98 | }else { 99 | current.msg <<- "Unknown format, please make sure that the file is saved in the supported formats!"; 100 | return(0); 101 | } 102 | 103 | if(!is_igraph(graphX)){ 104 | current.msg <<- "Failed to parse your file, please make sure that the file is formatted correctly"; 105 | return(0); 106 | } 107 | current.msg <<- "Sucessfully parsed your graph file!"; 108 | 109 | nms <- V(graphX)$name; 110 | if(length(nms)<1){ 111 | nms <- V(graphX)$id; 112 | graphX <- set_vertex_attr(graphX, "name", value=nms); 113 | } 114 | 115 | if(length(lbls) == 0){ 116 | lbls <- nms; 117 | } 118 | 119 | node.data <- data.frame(nms, lbls); 120 | seed.proteins <<- nms; 121 | seed.genes <<- seed.proteins; 122 | e <- get.edgelist(graphX) 123 | edge.data <- data.frame(Source=e[,1], Target=e[,2]) 124 | seed.expr <<- rep(0, length(node.data)); 125 | dataSet$seed <- list(); 126 | dataSet$seeds.proteins <- c(); 127 | dataSet <<- dataSet; 128 | omics.net <<- list( 129 | netw.type="graph", 130 | order=1, 131 | seeds=nms, 132 | table.nm=" ", 133 | node.data = node.data, 134 | edge.data = edge.data 135 | ); 136 | 137 | CreateGraph(dataSet); 138 | net.nm <- names(ppi.comps)[1]; 139 | net.nmu <<- net.nm; 140 | current.net.nm <<- net.nm; 141 | g <- ppi.comps[[net.nm]]; 142 | 143 | if(fileType == "json"){ 144 | dataSet$nodeLabels <- conv 145 | } 146 | dataSet <- .computeSubnetStats(dataSet, ppi.comps); 147 | return(.set.nSet(dataSet)); 148 | } 149 | 150 | 151 | read.sif <- function (sif.file, format = "graphNEL", directed = FALSE, header = TRUE, sep = "\t", ...) { 152 | 153 | net <- read.csv(file = sif.file, sep = sep, colClasses = "character", header = header, ...) 154 | 155 | # Assume form: node1 linktype node2 side.info.. 156 | if ( ncol(net) > 2 ) { 157 | 158 | # remove NA nodes 159 | nas <- apply(net, 1, function (x) {any(is.na(x[c(1,3)]))}) 160 | if (any(nas)) { 161 | net <- net[!nas, ]; 162 | warning("NAs removed from network node list, ", sum(nas), " edges removed."); 163 | } 164 | 165 | net <- graph.edgelist(as.matrix(net[, -2]), directed = directed); 166 | 167 | } else if ( ncol(net) == 2 ) { # assume form: node1 node2 168 | 169 | # remove NA nodes 170 | nas <- apply(net, 1, function (x) {any(is.na(x))}); 171 | if (any(nas)) { 172 | net <- net[!nas, ]; 173 | warning("NAs removed from network node list, ", sum(nas), " edges removed."); 174 | } 175 | 176 | net <- graph.edgelist(cbind(net[,1],net[,2]), directed = directed); 177 | } 178 | 179 | if (format == "graphNEL") { net <- igraph.to.graphNEL(net) } 180 | # if (format == "igraph") { net <- igraph.from.graphNEL(igraph.to.graphNEL(net)) } 181 | 182 | net 183 | } 184 | 185 | my.convert.Igraph2JSONFromFile <- function(net.nm, filenm, dim=3){ 186 | dim = as.numeric(dim); 187 | g <- ppi.comps[[net.nm]]; 188 | 189 | # annotation 190 | nms <- V(g)$name; 191 | lbls = nms; 192 | if(length(V(g)$Label) >0){ 193 | lbls <- V(g)$Label; 194 | }else if(length(dataSet$nodeLabels) > 0){ 195 | conv <- dataSet$nodeLabels; 196 | hit.inx <- match(nms, conv$id2); 197 | lbls <- conv[hit.inx, "name2"]; 198 | mode(lbls) <- "character"; 199 | na.inx <- is.na(lbls); 200 | lbls[na.inx] <- nms[na.inx]; 201 | } 202 | #print(lbls); 203 | # setup shape (gene circle, other squares) 204 | shapes <- rep("circle", length(nms)); 205 | 206 | # get edge data 207 | edge.mat <- get.edgelist(g); 208 | 209 | edge.mat = data.frame(edge.mat); 210 | edge.mat$color = "target"; 211 | # edge.mat1 = as.matrix(edge.mat1); 212 | 213 | edge.mat <- cbind(id=1:nrow(edge.mat), source=edge.mat[,1], target=edge.mat[,2], true_col = edge.mat[,3]); 214 | edge.exp <- get.edge.attribute(g, name="Expression", index = E(g)); 215 | edge.pval <- get.edge.attribute(g, name="Pval", index = E(g)); 216 | 217 | 218 | if(length(edge.pval) > 0){ 219 | edge.sizes <- as.numeric(rescale2NewRange(abs(edge.pval), 0.3, 6)); 220 | edge.mat <- cbind(edge.mat, size=edge.sizes); 221 | edge.label <-get.edge.attribute(g, name="Label", index = E(g)); 222 | edge.mat <- cbind(edge.mat, label=edge.label); 223 | } 224 | 225 | if(length(edge.exp) > 0){ 226 | bad.inx <- is.na(edge.exp) | edge.exp==0; 227 | edge.col <- ComputeColorGradient(edge.exp, "black", T); 228 | edge.col[bad.inx] <- "#d3d3d3"; 229 | edge.mat[,4] <- edge.col; 230 | } 231 | # get the node data 232 | if(length(E(g)$weight)>0){ 233 | E(g)$weight = abs(E(g)$weight); 234 | weight = E(g)$weight; 235 | ppi.comps[[net.nm]] <<- g; 236 | } 237 | node.btw <- as.numeric(betweenness(g)); 238 | node.clo <- as.numeric(closeness(g)); 239 | #node.adh <- as.numeric(adhesion(g)); 240 | node.eig <- eigen_centrality(g); 241 | node.eig = as.numeric(node.eig$vector); 242 | 243 | node.dgr <- as.numeric(degree(g)); 244 | node.exp <- as.numeric(get.vertex.attribute(g, name="Expression", index = V(g))); 245 | 246 | if(length(node.exp) == 0){ 247 | node.exp <- rep(0,length(node.dgr)); 248 | } 249 | 250 | node.type <- get.vertex.attribute(g, name="Type", index = V(g)); 251 | 252 | if(length(node.type) == 0){ 253 | node.type <- rep("Nodes",length(node.dgr)); 254 | } 255 | 256 | # node size to degree values 257 | if(vcount(g)>500){ 258 | min.size = 1; 259 | }else if(vcount(g)>200){ 260 | min.size = 2; 261 | }else{ 262 | min.size = 3; 263 | } 264 | 265 | minval = min(node.dgr, na.rm=T); 266 | maxval = max(node.dgr, na.rm=T); 267 | result = maxval-minval; 268 | 269 | if(result == 0){ 270 | node.sizes <- rep((log(node.dgr))^2, length(nms)); 271 | node.sizes2d <- node.sizes; 272 | }else{ 273 | node.sizes <- as.numeric(rescale2NewRange((log(node.dgr))^2, min.size, 9))*3 +5; 274 | node.sizes2d <- as.numeric(rescale2NewRange((log(node.btw+1))^2, min.size, 12)); 275 | } 276 | 277 | nsize <- get.vertex.attribute(g, name="Pval", index = V(g)); 278 | if(length(nsize) > 0){ 279 | nsize[is.na(nsize)] <- 0; 280 | node.sizes <- as.numeric(rescale2NewRange(abs(nsize), min.size, 9))*3 +5; 281 | node.sizes2d <- as.numeric(rescale2NewRange(abs(nsize), min.size, 12)); 282 | } 283 | 284 | centered = T; 285 | notcentered = F; 286 | # update node color based on betweenness 287 | require("RColorBrewer"); 288 | topo.val <- log(node.btw+1); 289 | topo.colsb <- ComputeColorGradient(topo.val, "black", notcentered); 290 | topo.colsw <- ComputeColorGradient(topo.val, "white", notcentered); 291 | 292 | # color based on expression 293 | bad.inx <- is.na(node.exp) | node.exp==0; 294 | if(!all(bad.inx)){ 295 | exp.val <- node.exp; 296 | node.colsb.exp <- ComputeColorGradient(exp.val, "black", centered); 297 | node.colsw.exp <- ComputeColorGradient(exp.val, "white", centered); 298 | node.colsb.exp[bad.inx] <- "#d3d3d3"; 299 | node.colsw.exp[bad.inx] <- "#c6c6c6"; 300 | }else{ 301 | node.colsb.exp <- rep("#d3d3d3",length(node.exp)); 302 | node.colsw.exp <- rep("#c6c6c6",length(node.exp)); 303 | } 304 | 305 | node_attr = list.vertex.attributes(g); 306 | 307 | attr=list(); 308 | for(j in 1:length(node_attr)){ 309 | attr[[node_attr[j]]] = vertex_attr(g, node_attr[j]); 310 | } 311 | attr_names <- names(attr); 312 | attr_nd <- list(); 313 | arr <- list(); 314 | for(i in 1:length(node.sizes)){ 315 | for(j in 1:length(attr)){ 316 | attr_nd[node_attr[j]] = as.character(unlist(attr[node_attr[j]])[i]) 317 | } 318 | arr[[i]] = attr_nd; 319 | } 320 | network_prop <- list(); 321 | for(i in 1:length(node.sizes)){ 322 | network_prop[[i]] <- list( 323 | closeness = node.clo[i], 324 | eigen = node.eig[i] 325 | ) 326 | } 327 | 328 | lblsu <<- lbls; 329 | pos.xy <- PerformLayOut(net.nm, "Default"); 330 | 331 | if(length(V(g)$x) >0){ 332 | pos.xy[,1] <-V(g)$x; 333 | pos.xy[,2] <-V(g)$y; 334 | } 335 | 336 | # now create the json object 337 | nodes <- vector(mode="list"); 338 | 339 | require("stringr") 340 | displayedLabel<-lbls; 341 | long.inx <- which(stringr:::str_length(lbls) > 32); 342 | displayedLabel[long.inx] <- paste0(strtrim(lbls[long.inx], rep(32, length(lbls[long.inx]))), "..." ) 343 | 344 | for(i in 1:length(node.sizes)){ 345 | nodes[[i]] <- list( 346 | id=nms[i], 347 | label=lbls[i], 348 | displayedLabel=displayedLabel[i], 349 | size=node.sizes[i], 350 | size2d=node.sizes2d[i], 351 | type="circle", 352 | types=node.type[i], 353 | molType=node.type[i], 354 | x2d = pos.xy[i,1], 355 | y2d = pos.xy[i,2], 356 | colorb=topo.colsb[i], 357 | colorw=topo.colsw[i], 358 | topocolb=topo.colsb[i], 359 | topocolw=topo.colsw[i], 360 | expcolb=node.colsb.exp[i], 361 | expcolw=node.colsw.exp[i], 362 | user=network_prop[[i]], 363 | attributes=list( 364 | expr = node.exp[i], 365 | degree=node.dgr[i], 366 | between=node.btw[i] 367 | ) 368 | ); 369 | } 370 | 371 | if(length(edge.exp) == 0){ 372 | edge.exp <- rep("Nodes",length(E(g)$name)); 373 | } 374 | 375 | # save node table 376 | nd.tbl <- data.frame(Id=nms, Degree=node.dgr, Betweenness=round(node.btw,2)); 377 | # order 378 | ord.inx <- order(nd.tbl[,2], nd.tbl[,3], decreasing =TRUE); 379 | nd.tbl <- nd.tbl[ord.inx, ]; 380 | fast.write.csv(nd.tbl, file="node_table.csv", row.names=FALSE); 381 | 382 | # covert to json 383 | require("RJSONIO"); 384 | dg <- decompose.graph(g) 385 | if(length(dg)>1){ 386 | modules <- "NA"; 387 | }else{ 388 | modules <- FindCommunities("infomap", FALSE); 389 | } 390 | netData <- list(nodes=nodes, edges=edge.mat, modules=modules, conv="NA", gene.nms=c("NA"), prot.nms=c("NA")); 391 | if(exists("netPropU")){ 392 | netData[["netProp"]] <- netPropU; 393 | } 394 | partialToBeSaved <<- c(partialToBeSaved, c(filenm)); 395 | sink(filenm); 396 | cat(RJSONIO::toJSON(netData)); 397 | sink(); 398 | } 399 | -------------------------------------------------------------------------------- /R/utils_peak_net.R: -------------------------------------------------------------------------------- 1 | 2 | my.peak.net <- function(dataSetObj=NA){ 3 | #save.image("peaknet.RData"); 4 | #print("peaknet1"); 5 | 6 | dataSet <- .get.nSet(dataSetObj); 7 | if(exists("PeakSetDone",envir = .GlobalEnv)) { 8 | PeakSet <- get("PeakSetDone", envir = .GlobalEnv); 9 | } else if(exists("PeakSet",envir = .GlobalEnv)) { 10 | PeakSet <- get("PeakSet", envir = .GlobalEnv); 11 | } else { 12 | return(0L); 13 | } 14 | nodes <- PeakSet$nodes; 15 | edges <- PeakSet$edges; 16 | met.kg.ids <- nodes$KEGGID; 17 | 18 | tmpsIDs <- nodes$HMDBID; 19 | tmpsIDs <- tmpsIDs[tmpsIDs != ""] 20 | if(all(grepl("^C[0-9]+", tmpsIDs))){ 21 | met.ids <- nodes$KEGGID; 22 | met.ids[met.ids == ""] <- nodes$formula[met.ids == ""]; 23 | lbls <- doKegg2NameMapping(met.ids); 24 | } else if (all(grepl("^HMDB[0-9]+", tmpsIDs))) { 25 | met.ids <- nodes$HMDBID; 26 | met.ids[met.ids == ""] <- nodes$formula[met.ids == ""]; 27 | lbls <- doHMDB2NameMapping(met.ids); 28 | } else if (all(grepl("^PBCM[0-9]+", tmpsIDs))) { 29 | met.ids <- nodes$HMDBID; 30 | met.ids[met.ids == ""] <- nodes$formula[met.ids == ""]; 31 | lbls <- doPubchem2NameMapping(met.ids); 32 | } 33 | 34 | met.kg.ids[met.kg.ids == ""] <- nodes$formula[met.kg.ids == ""]; 35 | PeakSet$nodes$KEGGID_realID <- met.kg.ids; 36 | PeakSet$nodes$KEGGID <- met.ids; 37 | art.ids <- PeakSet$nodes$name[which(PeakSet$nodes$class == "Artifact")] 38 | 39 | PeakSet$mets <- unique(PeakSet$nodes$KEGGID[which(PeakSet$nodes$class == "Metabolite")]); 40 | PeakSet$put.mets <- PeakSet$nodes$KEGGID[which(PeakSet$nodes$class == "Putative metabolite")]; 41 | PeakSet$mets.ids <- PeakSet$nodes$name[which(PeakSet$nodes$class == "Metabolite")]; 42 | PeakSet$put.mets.ids <- PeakSet$nodes$name[which(PeakSet$nodes$class == "Putative metabolite")]; 43 | 44 | 45 | PeakSet$nodes.df <- data.frame(Id=met.ids, Label=lbls) 46 | edges.df0 <- data.frame(from=edges[,1], to=edges[,2]) 47 | edges.df01 <- edges.df0[!edges.df0[,1] %in% art.ids,]; 48 | edges.df02 <- edges.df01[!edges.df01[,2] %in% art.ids,]; 49 | conv1 <- data.frame(from=PeakSet$nodes$name, Source=PeakSet$nodes$KEGGID); 50 | conv2 <- data.frame(to=PeakSet$nodes$name, Target=PeakSet$nodes$KEGGID); 51 | edges.df1 <- merge(edges.df02, conv1, by = "from"); 52 | edges.df2 <- merge(edges.df1, conv2, by = "to"); 53 | PeakSet$edges.df <- data.frame(Source=edges.df2$Source, Target=edges.df2$Target); 54 | 55 | if(length(which(grepl("HMDB", PeakSet$mets)))/length(PeakSet$mets) > 0){ 56 | PeakSet$mets <- doHMDB2KEGGMapping(PeakSet$mets); 57 | PeakSet$nodes.df[,1] <- doHMDB2KEGGMapping(PeakSet$nodes.df[,1]); 58 | PeakSet$edges.df[,1] <- doHMDB2KEGGMapping(PeakSet$edges.df[,1]); 59 | PeakSet$edges.df[,2] <- doHMDB2KEGGMapping(PeakSet$edges.df[,2]); 60 | 61 | } 62 | 63 | if(length(which(grepl("PBCM", PeakSet$mets)))/length(PeakSet$mets) > 0){ 64 | PeakSet$mets <- doPubchem2KEGGMapping(PeakSet$mets); 65 | PeakSet$nodes.df[,1] <- doPubchem2KEGGMapping(PeakSet$nodes.df[,1]); 66 | PeakSet$edges.df[,1] <- doPubchem2KEGGMapping(PeakSet$edges.df[,1]); 67 | PeakSet$edges.df[,2] <- doPubchem2KEGGMapping(PeakSet$edges.df[,2]); 68 | 69 | } 70 | 71 | dataSet$seed[["peak"]] <- data.frame(rep(0, length(unique(PeakSet$mets)))); 72 | 73 | rownames(dataSet$seed[["peak"]]) <-unique(PeakSet$mets); 74 | dataSet$exp.mat[["peak"]] <- data.frame(rep(0, length(PeakSet$NetID_output$peak_id))); 75 | rownames(dataSet$exp.mat[["peak"]]) <- paste0(PeakSet$NetID_output$peak_id,"_", PeakSet$NetID_output$medMz); 76 | 77 | cmp.nms <- PrepareInputList(dataSet, rownames(dataSet$seed[["peak"]]), data.org, "peak", "kegg"); 78 | #print("peaknet2"); 79 | qs:::qsave(PeakSet, "PeakSet_net.qs"); 80 | dataSet <<- dataSet; 81 | if(.on.public.web){ 82 | .set.nSet(dataSet); 83 | return(1L); 84 | }else{ 85 | return(.set.nSet(dataSet)); 86 | } 87 | } -------------------------------------------------------------------------------- /R/utils_phenoscanner.R: -------------------------------------------------------------------------------- 1 | 2 | my.query.phenoscanner <- function(snpquery=NULL, genequery=NULL, regionquery=NULL, catalogue="GWAS", pvalue=1E-5, proxies="None", r2=0.8, build=37){ 3 | 4 | if(is.null(snpquery) & is.null(regionquery) & is.null(genequery)) stop("no query has been requested") 5 | if((length(snpquery[1])+length(regionquery[1])+length(genequery[1]))>1) stop("only one query type allowed") 6 | if(!(catalogue=="None" | catalogue=="GWAS" | catalogue=="eQTL" | catalogue=="pQTL" | catalogue=="mQTL" | catalogue=="methQTL")) stop("catalogue has to be one of None, GWAS, eQTL, pQTL, mQTL or methQTL") 7 | if(!(proxies=="None" | proxies=="AFR" | proxies=="AMR" | proxies=="EAS" | proxies=="EUR" | proxies=="SAS")) stop("proxies has to be one of None, AFR, AMR, EAS, EUR or SAS") 8 | if(length(snpquery)>100) stop("a maximum of 100 SNP queries can be requested at one time") 9 | if(length(genequery)>10) stop("a maximum of 10 gene queries can be requested at one time") 10 | if(length(regionquery)>10) stop("a maximum of 10 region queries can be requested at one time") 11 | if(!(pvalue>0 & pvalue<=1)) stop("the p-value threshold has to be greater than 0 and less than or equal to 1") 12 | if(!(r2>=0.5 & r2<=1)) stop("the r2 threshold has to be greater than or equal to 0.5 and less than or equal to 1") 13 | if(!(build==37 | build==38)) stop("the build has to be equal to 37 or 38") 14 | if(!is.null(regionquery)){ 15 | for(i in 1:length(regionquery)){ 16 | if(length(gregexpr(pattern =':',regionquery[i])[[1]])>1){ 17 | rp <- gregexpr(pattern =':',regionquery[i])[[1]][2]-1 18 | regionquery[i] = substr(regionquery[i], 1,rp) 19 | } 20 | } 21 | ub <- as.numeric(sub(".*-", "", sub(".*:", "",regionquery))) 22 | lb <- as.numeric(sub("-.*", "", sub(".*:", "",regionquery))) 23 | dist <- ub - lb 24 | if(any(dist>1000000)) stop("region query can be maximum of 1MB in size") 25 | } 26 | if(length(snpquery)>0){ 27 | results <- data.frame() 28 | snps <- data.frame() 29 | n_queries <- length(snpquery) %/% 10 30 | if((length(snpquery) %% 10)>0){n_queries <- n_queries + 1} 31 | for(i in 1:n_queries){ 32 | if(i < n_queries){qsnps <- paste0(snpquery[(1+10*(i-1)):(10*i)], collapse="+")}else{qsnps <- paste0(snpquery[(1+10*(i-1)):length(snpquery)], collapse="+")} 33 | json_file <- paste0("http://www.phenoscanner.medschl.cam.ac.uk/api/?snpquery=",qsnps,"&catalogue=",catalogue,"&p=",pvalue,"&proxies=",proxies,"&r2=",r2,"&build=",build) 34 | json_data <- getApiResult(json_file) 35 | if(length(json_data$results)==0 & length(json_data$snps)==0){ 36 | print(paste0("Error: ",json_data$error)) 37 | next 38 | } 39 | if (length(json_data$results) > 0) { 40 | fields <- json_data$results[[1]] 41 | json_data$results[[1]] <- NULL 42 | if (length(json_data$results) > 0) { 43 | tables <- 44 | as.data.frame(matrix( 45 | unlist(json_data$results), 46 | ncol = length(fields), 47 | byrow = T 48 | ), stringsAsFactors = F) 49 | names(tables) <- fields 50 | results <- rbind(results, tables) 51 | if (length(snpquery) == 1) { 52 | print(paste0(snpquery, " -- queried")) 53 | } else{ 54 | print(paste0(i, " -- chunk of 10 SNPs queried")) 55 | } 56 | } else{ 57 | if (length(snpquery) == 1) { 58 | print(paste0("Warning: no results found for ", snpquery)) 59 | } else{ 60 | print(paste0("Warning: no results found for chunk ", i)) 61 | } 62 | } 63 | } 64 | if (length(json_data$snps) > 0) { 65 | fields_snps <- json_data$snps[[1]] 66 | json_data$snps[[1]] <- NULL 67 | if (length(json_data$snps) > 0) { 68 | tables_snps <- 69 | as.data.frame(matrix( 70 | unlist(json_data$snps), 71 | ncol = length(fields_snps), 72 | byrow = T 73 | ), stringsAsFactors = F) 74 | names(tables_snps) <- fields_snps 75 | snps <- rbind(snps, tables_snps) 76 | if (length(json_data$results) == 0) { 77 | if (length(snpquery) == 1) { 78 | print(paste0(snpquery, " -- queried")) 79 | } else{ 80 | print(paste0(i, " -- chunk of 10 SNPs queried")) 81 | } 82 | } 83 | } else{ 84 | if (length(json_data$results) == 0) { 85 | if (length(snpquery) == 1) { 86 | print(paste0("Warning: no results found for ", snpquery)) 87 | } else{ 88 | print(paste0("Warning: no results found for chunk ", i)) 89 | } 90 | } 91 | } 92 | } 93 | } 94 | output <- list(snps=snps, results=results) 95 | } 96 | if(length(genequery)>0){ 97 | results <- data.frame() 98 | genes <- data.frame() 99 | n_queries <- length(genequery) 100 | for(i in 1:n_queries){ 101 | json_file <- paste0("http://www.phenoscanner.medschl.cam.ac.uk/api/?genequery=",genequery[i],"&catalogue=",catalogue,"&p=",pvalue,"&proxies=None&r2=1&build=",build) 102 | json_data <- getApiResult(json_file) 103 | if(length(json_data$results)==0 & length(json_data$genes)==0){ 104 | print(paste0("Error: ", json_data$error)) 105 | next 106 | } 107 | if(length(json_data$results)>0){ 108 | fields <- json_data$results[[1]]; json_data$results[[1]] <- NULL 109 | if(length(json_data$results)>0){ 110 | tables <- as.data.frame(matrix(unlist(json_data$results), ncol=length(fields), byrow=T), stringsAsFactors=F) 111 | names(tables) <- fields 112 | results <- rbind(results,tables) 113 | print(paste0(genequery," -- queried")) 114 | }else{print(paste0("Warning: no results found for ",genequery))} 115 | } 116 | if(length(json_data$genes)>0){ 117 | fields_genes <- json_data$genes[[1]]; json_data$genes[[1]] <- NULL 118 | if(length(json_data$genes)>0){ 119 | tables_genes <- as.data.frame(matrix(unlist(json_data$genes), ncol=length(fields_genes), byrow=T), stringsAsFactors=F) 120 | names(tables_genes) <- fields_genes 121 | genes <- rbind(genes,tables_genes) 122 | } 123 | } 124 | } 125 | output <- list(genes=genes, results=results) 126 | } 127 | if(length(regionquery)>0){ 128 | results <- data.frame() 129 | regions <- data.frame() 130 | n_queries <- length(regionquery) 131 | for(i in 1:n_queries){ 132 | json_file <- paste0("http://www.phenoscanner.medschl.cam.ac.uk/api/?regionquery=", regionquery[i],"&catalogue=",catalogue,"&p=",pvalue,"&proxies=None&r2=1&build=",build) 133 | json_data <- getApiResult(json_file) 134 | if(length(json_data$results)==0 & length(json_data$locations)==0){ 135 | print(paste0("Error: ",json_data$error)) 136 | next 137 | } 138 | if(length(json_data$results)>0){ 139 | fields <- json_data$results[[1]]; json_data$results[[1]] <- NULL 140 | if(length(json_data$results)>0){ 141 | tables <- as.data.frame(matrix(unlist(json_data$results), ncol=length(fields), byrow=T), stringsAsFactors=F) 142 | names(tables) <- fields 143 | results <- rbind(results,tables) 144 | print(paste0(regionquery," -- queried")) 145 | }else{print(paste0("Warning: no results found for ",regionquery))} 146 | } 147 | if(length(json_data$locations)>0){ 148 | fields_regions <- json_data$locations[[1]]; json_data$locations[[1]] <- NULL 149 | if(length(json_data$locations)>0){ 150 | tables_regions <- as.data.frame(matrix(unlist(json_data$locations), ncol=length(fields_regions), byrow=T), stringsAsFactors=F) 151 | names(tables_regions) <- fields_regions 152 | regions <- rbind(regions,tables_regions) 153 | } 154 | } 155 | } 156 | output <- list(regions=regions, results=results) 157 | } 158 | if(is.null(output)) stop("there is no output") 159 | cat("PhenoScanner done\n") 160 | return(output) 161 | } 162 | -------------------------------------------------------------------------------- /R/utils_reg_enrich.R: -------------------------------------------------------------------------------- 1 | 2 | my.reg.enrich <- function(file.nm, fun.type, ora.vec, netInv, idType){ 3 | require("plyr") 4 | ora.nms <- names(ora.vec); 5 | # prepare for the result table 6 | set.size<-100; 7 | 8 | if (fun.type %in% c("chea", "encode", "jaspar", "trrust")){ 9 | table.nm <- paste(data.org, fun.type, sep="_"); 10 | res <- QueryTFSQLite(table.nm, ora.vec, netInv); 11 | # no hits 12 | if(nrow(res)==0){ return(c(0,0)); } 13 | edge.res <- data.frame(gene=res[,"entrez"], symbol=res[,"symbol"],id=res[,"tfid"], name=res[,"tfname"]); 14 | node.ids <- c(res[,"entrez"], res[,"tfid"]); 15 | node.nms <- c(res[,"symbol"], res[,"tfname"]); 16 | 17 | }else if(fun.type == "mirnet"){ # in miRNA, table name is org code, colname is id type 18 | table.nm <- data.org 19 | res <- QueryMirSQLite(table.nm, "entrez", ora.vec, "inverse", data.org); 20 | if(nrow(res)==0){ return(c(0,0)); } 21 | edge.res <- data.frame(gene=res[,"entrez"], symbol=res[,"symbol"], id=res[,"mir_acc"], name=res[,"mir_id"] ); 22 | node.ids <- c(res[,"entrez"], res[,"mir_acc"]) 23 | node.nms <- c(res[,"symbol"], res[,"mir_id"]); 24 | 25 | }else if(fun.type == "met"){ 26 | table.nm <- paste(data.org, "kegg", sep="_"); 27 | res <- QueryMetSQLiteNet(table.nm, ora.vec, "inverse"); 28 | if(nrow(res)==0){ return(c(0,0)); } 29 | edge.res <- data.frame(gene=res[,"entrez"], symbol=res[,"symbol"], id=res[,"kegg"], name=res[,"met"] ); 30 | node.ids <- c(res[,"entrez"], res[,"kegg"]) 31 | node.nms <- c(res[,"symbol"], res[,"met"]); 32 | 33 | }else{ 34 | table.nm <- paste("drug", data.org, sep="_"); 35 | ora.vec <- doEntrez2UniprotMapping(ora.vec); 36 | res <- QueryDrugSQLite(ora.vec); 37 | if(nrow(res)==0){ return(c(0,0)); } 38 | edge.res <- data.frame(gene=doUniprot2EntrezMapping(res[,"upid"]), symbol=res[,"symbol"], id=res[,"dbid"], name=res[,"dbname"] ); 39 | node.ids <- c(doUniprot2EntrezMapping(res[,"upid"]), res[,"dbid"]) 40 | node.nms <- c(res[,"symbol"], res[,"dbname"]); 41 | } 42 | 43 | edge.res$mix <- paste0(edge.res[,1], edge.res[,3]); 44 | edge.res <- edge.res[!duplicated(edge.res$mix),]; 45 | 46 | row.names(edge.res) <- 1:nrow(edge.res); 47 | fast.write.csv(edge.res, file="orig_edge_list.csv",row.names=FALSE); 48 | 49 | hit.freq <- count(edge.res, 'id') 50 | hit.freq <- hit.freq[order(hit.freq$freq, decreasing = TRUE),] 51 | hit.freqnm <- count(edge.res, 'name') 52 | hit.freqnm <- hit.freqnm[order(hit.freqnm$freq, decreasing = TRUE),] 53 | hit.freq$name <- hit.freqnm$name 54 | hits.gene <- list() 55 | 56 | if(idType == "uniprot"){ 57 | for(i in 1:nrow(hit.freq)){ 58 | df <- edge.res[which(edge.res$id == hit.freq$id[i]),]; 59 | gene.vec <- as.vector(df$gene); 60 | gene.vec <- doEntrez2UniprotMapping(gene.vec) 61 | hits.gene[[i]] <- gene.vec; 62 | } 63 | } else if(idType == "entrez") { 64 | for(i in 1:nrow(hit.freq)){ 65 | df <- edge.res[which(edge.res$id == hit.freq$id[i]),]; 66 | gene.vec <- as.vector(df$gene); 67 | hits.gene[[i]] <- gene.vec; 68 | } 69 | }else { 70 | for(i in 1:nrow(hit.freq)){ 71 | df <- edge.res[which(edge.res$id == hit.freq$id[i]),]; 72 | gene.vec <- as.vector(df$gene); 73 | gene.vec <- doEntrez2EmblProteinMapping(gene.vec) 74 | hits.gene[[i]] <- gene.vec; 75 | } 76 | } 77 | names(hits.gene) = hit.freq$name; 78 | 79 | resTable1 = data.frame(hit.freq$id, hit.freq$name, hit.freq$freq) 80 | colnames(resTable1) = c("Id", "Name", "Hits") 81 | resTable1 = resTable1[order(-resTable1$Hits),] 82 | current.msg <<- "Regulatory element enrichment analysis was completed"; 83 | 84 | if(regBool == "true"){ 85 | resTable1 <- resTable1[which(resTable1$Hits == regCount),] 86 | } 87 | # write json 88 | require("RJSONIO"); 89 | fun.ids <- resTable1[,1]; 90 | fun.nms <- resTable1[,2]; 91 | fun.hits <- resTable1[,3]; 92 | json1.res <- list( 93 | fun.ids = fun.ids, 94 | fun.nms = fun.nms, 95 | fun.hits = fun.hits, 96 | fun.genes = hits.gene 97 | ); 98 | json.mat <- toJSON(json1.res); 99 | json.nm <- paste(file.nm, ".json", sep=""); 100 | sink(json.nm) 101 | cat(json.mat); 102 | sink(); 103 | 104 | resTable1$Features = hits.gene 105 | 106 | type = "regNetwork"; 107 | # write csv 108 | csv.nm <- paste(file.nm, ".csv", sep=""); 109 | fast.write.csv(resTable1, file=csv.nm, row.names=F); 110 | fast.write.csv(resTable1, file=paste0(type, "_enr_table.csv"), row.names=F); 111 | 112 | #record table for report 113 | dataSet$imgSet$enrTables[[type]] <- list() 114 | dataSet$imgSet$enrTables[[type]]$table <- resTable1; 115 | dataSet$imgSet$enrTables[[type]]$res.mat <- resTable1[,3, drop=F]; 116 | 117 | dataSet$imgSet$enrTables[[type]]$library <- fun.type 118 | dataSet$imgSet$enrTables[[type]]$algo <- "Overrepresentation Analysis" 119 | dataSet <<- dataSet 120 | 121 | return(1); 122 | } -------------------------------------------------------------------------------- /R/utils_snp.R: -------------------------------------------------------------------------------- 1 | 2 | my.snp.query <- function(dataSet, q.vec, db.type, netInv, zero=FALSE, snpRegion=FALSE){ 3 | require('RSQLite'); 4 | if(db.type == "PhenoScanner"){ 5 | 6 | require("tidyr"); 7 | if(dataSet$snp2gene$phesc.opt=="eqtl"){ 8 | 9 | res <- Query.PhenoScanner(snpquery= q.vec,catalogue="eQTL"); 10 | fast.write.csv(res$results, file="phenoscanner.eQtl.csv",row.names=FALSE); 11 | res <- res$results[,c("rsid","exp_gene")]; 12 | res <- unique(res[which(!(is.na(res$exp_gene)) &res$exp_gene !=""&res$exp_gene !="-" ),]); 13 | colnames(res)[2] = "symbol"; 14 | res <- unique(data.frame(tidyr::separate_rows(res,symbol,sep =";"),stringsAsFactors = F)); 15 | 16 | }else{ 17 | 18 | res <- Query.PhenoScanner(snpquery= q.vec); 19 | res <- res$snps; 20 | fast.write.csv(res, file="phenoscanner.nearest.csv",row.names=FALSE); 21 | colnames(res)[which(colnames(res)=="hgnc")] = "symbol"; 22 | res <- unique(data.frame(tidyr::separate_rows(res,symbol,sep =";"),stringsAsFactors = F)) 23 | } 24 | 25 | res$entrez = doGeneIDMapping(res$symbol,type="symbol"); 26 | res$entrez[is.na(res$entrez)] = res$symbol[is.na(res$entrez)]; 27 | 28 | }else if(db.type == "vep"){ 29 | 30 | if(dataSet$snp2gene$vep.opt=="dis"){ 31 | res <- QueryVEP(q.vec, vepDis=dataSet$snp2gene$vep.dis, snpRegion = snpRegion); 32 | fast.write.csv(res, file="vep.map.csv",row.names=FALSE); 33 | res <- unique(res[which(res$gene_symbol !="NA"),c("rsid","gene_symbol")]); 34 | }else{ 35 | require("dplyr") 36 | res<- QueryVEP(q.vec, vepDis=50,snpRegion = snpRegion) 37 | fast.write.csv(res, file="vep.map.csv",row.names=FALSE); 38 | res$distance[which(res$distance=="NA")] = 0; 39 | res <- unique(res[!(is.na(res$gene_symbol)),c("gene_symbol","rsid","distance")]); 40 | res <- unique(res[!(duplicated(res$gene_symbol,res$rsid)),]); 41 | res <- data.frame(res %>% arrange(distance) %>% 42 | group_by(rsid) %>% 43 | mutate(rank = rank(distance)),stringsAsFactors=F); 44 | res <- res[which(res$rank<(dataSet$snp2gene$vep.num + 1)),]; 45 | } 46 | 47 | res$entrez <- doGeneIDMapping(res$gene_symbol,type="symbol") 48 | res$entrez[is.na(res$entrez)] <- res$gene_symbol[is.na(res$entrez)] 49 | 50 | }else{ 51 | if(db.type == "admire"){ 52 | file.nm <- "snp2mir"; 53 | }else{ 54 | file.nm <- "snp2tfbs"; 55 | } 56 | db.path <- paste(sqlite.path, file.nm, sep=""); 57 | table.nm <- "hsa"; 58 | col.nm <- "rsid"; 59 | res <- Query.snpDB(db.path, q.vec, table.nm, col.nm); 60 | } 61 | 62 | if(db.type == "admire"){ 63 | targetColNm <- "MIRNA_Name"; 64 | }else if(db.type == "PhenoScanner"){ 65 | targetColNm <- "entrez"; 66 | }else if(db.type == "vep"){ 67 | targetColNm <- "entrez"; 68 | }else{ 69 | targetColNm <- "entrez"; 70 | } 71 | colInx <- which(colnames(res) == targetColNm); 72 | 73 | snp.list <- list(); 74 | snp.type.list <- list(); 75 | snpTable <<- snp.list; 76 | 77 | edge.res <- data.frame(Source=res[,"rsid"],Target=res[,colInx], stringsAsFactors=FALSE); 78 | 79 | if(nrow(res)!=0){ 80 | row.names(edge.res) <- 1:nrow(res); 81 | } 82 | fast.write.csv(edge.res, file="orig_edge_list.csv",row.names=FALSE); 83 | node.ids <- c(edge.res[,"Source"], edge.res[,"Target"]) 84 | 85 | # print(node.ids) 86 | if(db.type == "admire"){ 87 | symb <- res[,"MIRNA_Acc"]; 88 | }else if(db.type == "PhenoScanner"){ 89 | symb <- res[,"symbol"]; 90 | }else if(db.type == "vep"){ 91 | symb <- res[,"gene_symbol"]; 92 | }else{ 93 | symb <- doEntrez2SymbolMapping(res[,"entrez"]); 94 | } 95 | node.nms <- c(res[,"rsid"], symb); 96 | 97 | if(netInv == "direct"){ 98 | targetIds <- unique(c(net.info$gene.ids, node.ids[!node.ids %in% q.vec])); 99 | net.info$snp.ids <- unique(q.vec); 100 | }else{ 101 | net.info$snp.ids <- unique(res[,"rsid"]); 102 | if(!zero){ 103 | targetIds <- c(unique(q.vec)); 104 | } 105 | } 106 | 107 | if(db.type == "admire"){ 108 | net.info$mir.ids <- targetIds; 109 | }else if(db.type == "snp2tfbs"){ 110 | net.info$tf.ids <- targetIds; 111 | }else if(db.type == "PhenoScanner"){ 112 | net.info$gene.ids <- targetIds; 113 | }else{ 114 | net.info$gene.ids <- targetIds; 115 | } 116 | 117 | net.info$snpi.ids <- unique(node.ids); 118 | 119 | res <- list( 120 | edge.res = edge.res, 121 | node.ids = node.ids, 122 | node.nms = node.nms, 123 | net.info= net.info 124 | ); 125 | return(res); 126 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Description 3 | 4 | **_OmicsNetR_** is the underlying R package synchronized with OmicsNet web server. It is designed for network-based multi-omics integration and systems-level interpretation. The R package is composed of R functions necessary for the web-server to perform network creation, trimming and analysis. 5 | 6 | Following installation and loading of _OmicsNetR_, users will be able to reproduce web server results from their local computers using the R command history downloaded from OmicsNet. Running the R functions will allow more flexibility and reproducibility. 7 | 8 | Note - OmicsNetR is still under development - we cannot guarantee full functionality 9 | # Installation 10 | 11 | **Step 1. Install package dependencies** 12 | 13 | To use OmcisNetR, make sure your R version is >4.0.3 and install all package dependencies. Ensure that you are able to download packages from Bioconductor. To install package dependencies, use the pacman R package. Note that some of these packages may require additional library dependencies that need to be installed prior to their own successful installation. 14 | 15 | ``` 16 | install.packages("pacman") 17 | 18 | library(pacman) 19 | 20 | pacman::p_load(igraph, RColorBrewer, qs, rjson, RSQLite) 21 | ``` 22 | 23 | **Step 2. Install the package** 24 | 25 | OmicsNetR is freely available from GitHub. The package documentation, including the vignettes for each module and user manual is available within the downloaded R package file. If all package dependencies were installed, you will be able to install the OmicsNetR. 26 | 27 | Install the package directly from github using the _devtools_ package. Open R and enter: 28 | 29 | ``` 30 | 31 | # Step 1: Install devtools 32 | install.packages(devtools) 33 | library(devtools) 34 | 35 | # Step 2: Install OmicsNetR WITHOUT documentation 36 | devtools::install_github("xia-lab/OmicsNetR", build = TRUE, build_opts = c("--no-resave-data", "--no-manual", "--no-build-vignettes")) 37 | 38 | # Step 2: Install OmicsNetR WITH documentation 39 | devtools::install_github("xia-lab/OmicsNetR", build = TRUE, build_opts = c("--no-resave-data", "--no-manual"), build_vignettes = TRUE) 40 | ``` 41 | 42 | # Tips for using the OmicsNetR package 43 | 44 | 1. The first function that you will use in every module is the `Init.Data` function, which initiates the _dataSet_ object that stores user's data for further processing and analysis. 45 | 2. The OmicsNetR package will output data files/tables/analysis/networks outputs in your current working directory. 46 | 3. Every function must be executed in sequence as it is shown on the R Command history, please do not skip any commands as this can result in errors downstream. 47 | 4. Each main function in OmicsNetR is documented. Use the _?Function_ format to open its documentation. For instance, use `?OmicsNetR::QueryNet` to find out more about this function. 48 | 49 | # Examples 50 | 51 | ## Starting from a list of genes 52 | 53 | ``` 54 | library(OmicsNetR) 55 | 56 | # Step 1. Initiate the dataSet object 57 | dataSet<-Init.Data() 58 | 59 | # Step 2. Map list of genes to the application 60 | dataSet<-PrepareInputList(dataSet,"#Entrez logFC 61 | 4495 61.12 62 | 4496 51.06 63 | 4499 23.79 64 | 6354 21.04 65 | 6369 19.76", "hsa", "gene", "entrez", "direct"); 66 | 67 | # Step 3. Identify interacting partners 68 | dataSet<-QueryNet(dataSet, "gene", "innate") 69 | 70 | # Step 4. Build interaction subnetwork 71 | CreateGraph(); 72 | 73 | # Step 5. Prepare the network file to be used for visualization, the output will be in JSON format. 74 | dataSet<-PrepareNetwork(dataSet, "subnetwork1", "omicsnet_1.json") 75 | ``` 76 | 77 | ## Starting from list of genes and miRNA 78 | 79 | ``` 80 | library(OmicsNetR) 81 | 82 | # Step 1. Initiate the dataSet object 83 | dataSet<-Init.Data() 84 | 85 | # Step 2. Map list of genes to the application 86 | dataSet<-PrepareInputList(dataSet,"#Entrez logFC 87 | 4495 61.12 88 | 4496 51.06 89 | 4499 23.79 90 | 6354 21.04 91 | 6369 19.76", "hsa", "gene", "entrez"); 92 | 93 | # Step 2. Map list of miRNA to the application 94 | dataSet<-PrepareInputList(dataSet,"hsa-mir-101-3p 95 | hsa-mir-133b 96 | hsa-mir-147a 97 | hsa-mir-3140-3p 98 | hsa-mir-361-5p 99 | hsa-mir-510-5p", "hsa", "mir", "mir_id"); 100 | 101 | # Step 3. Build PPI network from uploaded list of genes 102 | dataSet<-QueryNetMulti(dataSet, "gene", "innate", "gene" ) 103 | 104 | # Step 4. Build miRNA-gene network from uploaded list of miRNA 105 | dataSet<-QueryNetMulti(dataSet, "mir", "mirtarbase", "mir" ) 106 | 107 | # Step 5. Merge networks together through shared nodes and decompose into interconnected subnetworks 108 | CreateGraph(); 109 | 110 | # Step 6. Prepare the network file to be used for visualization, the output will be in JSON format. 111 | dataSet<-PrepareNetwork(dataSet, "subnetwork1", "omicsnet_1.json") 112 | ``` 113 | 114 | ## Save OmicsNet JSON file for saving current analysis. 115 | 116 | ``` 117 | library(OmicsNetR) 118 | 119 | # Step 1. Initiate the dataSet object 120 | dataSet<-Init.Data() 121 | 122 | # Step 2. Map list of genes to the application 123 | dataSet<-PrepareInputList(dataSet,"#Entrez logFC 124 | 4495 61.12 125 | 4496 51.06 126 | 4499 23.79 127 | 6354 21.04 128 | 6369 19.76", "hsa", "gene", "entrez", "direct"); 129 | 130 | # Step 3. Identify interacting partners 131 | dataSet<-QueryNet(dataSet, "gene", "innate") 132 | 133 | # Step 4. Decompose network into interconnected subnetworks 134 | CreateGraph(); 135 | 136 | # Step 5. Save the JSON file, this file can be uploaded again to restore analysis session 137 | SaveNetworkJson("omicsnet_graph_file_1.json") 138 | ``` 139 | 140 | 141 | ## Load OmicsNet JSON file to restore analysis session 142 | 143 | ``` 144 | library(OmicsNetR) 145 | 146 | # Step 1. Initiate the dataSet object 147 | dataSet<-Init.Data() 148 | 149 | # Step 2. Read graph file, specify correct file format 150 | dataSet<-ReadGraphFile(dataSet, "Your file path", "jsonOmicsnet"); 151 | 152 | # Step 3. Prepare the network file to be used for visualization, the output will be in JSON format. 153 | dataSet<-PrepareNetwork(dataSet, "subnetwork1", "omicsnet_1.json") 154 | ``` 155 | 156 | -------------------------------------------------------------------------------- /data/elem_table.csv: -------------------------------------------------------------------------------- 1 | element,isotope,mass,abundance,ratioC,Mass_Dif,unsaturation 2 | H,1H,1.007825032,1,6,0,-0.5 3 | [2]H,2H,2.014101778,0.000115013,6,1.006276746,-0.5 4 | [3]He,3He,3.016029319,1.34E-06,0,-0.986573935,0 5 | He,4He,4.002603254,1,0,0,0 6 | [6]Li,6Li,6.0151223,0.082133968,0,-1.0008818,-0.5 7 | Li,7Li,7.0160041,1,0,0,-0.5 8 | Be,9Be,9.0121822,1,0,0,-1 9 | [10]B,10B,10.0129371,0.248439451,0,-0.9963684,0.5 10 | B,11B,11.0093055,1,0,0,0.5 11 | C,12C,12,1,0,0,1 12 | [13]C,13C,13.00335484,0.010815728,0,1.00335484,1 13 | N,14N,14.00307401,1,4,0,0.5 14 | [15]N,15N,15.00010897,0.003653298,4,0.99703496,0.5 15 | O,16O,15.99491462,1,3,0,0 16 | [17]O,17O,16.9991315,0.000380926,3,1.00421688,0 17 | [18]O,18O,17.9991604,0.002054994,3,2.00424578,0 18 | F,19F,18.9984032,1,6,0,-0.5 19 | Ne,20Ne,19.99244018,1,0,0,0 20 | [21]Ne,21Ne,20.99384668,0.002984085,0,1.0014065,0 21 | [22]Ne,22Ne,21.99138511,0.102232538,0,1.99894493,0 22 | Na,23Na,22.98976966,1,0,0,-0.5 23 | Mg,24Mg,23.98504187,1,0,0,-1 24 | [25]Mg,25Mg,24.985837,0.126598304,0,1.00079513,-1 25 | [26]Mg,26Mg,25.982593,0.139384732,0,1.99755113,-1 26 | Al,27Al,26.98153863,1,0,0,-1.5 27 | Si,28Si,27.97692649,1,1,0,1 28 | [29]Si,29Si,28.97649468,0.050800776,1,0.99956819,1 29 | [30]Si,30Si,29.97377018,0.033527428,1,1.99684369,1 30 | P,31P,30.97376149,1,2,0,0.5 31 | S,32S,31.97207073,1,3,0,0 32 | [33]S,33S,32.97145854,0.007895568,3,0.99938781,0 33 | [34]S,34S,33.96786687,0.044741552,3,1.99579614,0 34 | [36]S,36S,35.96708088,0.000105274,3,3.99501015,0 35 | Cl,35Cl,34.96885271,1,2,0,-0.5 36 | [37]Cl,37Cl,36.9659026,0.319957761,2,1.99704989,-0.5 37 | [36]Ar,36Ar,35.96754511,0.003378504,0,-3.99483801,0 38 | [38]Ar,38Ar,37.9627324,0.000634536,0,-1.99965072,0 39 | Ar,40Ar,39.96238312,1,0,0,0 40 | K,39K,38.9637069,1,0,0,-0.5 41 | [40]K,40K,39.96399867,0.000125458,0,1.00029177,-0.5 42 | [41]K,41K,40.96182597,0.072167458,0,1.99811907,-0.5 43 | Ca,40Ca,39.9625912,1,0,0,-1 44 | [42]Ca,42Ca,41.9586183,0.006674163,0,1.9960271,-1 45 | [43]Ca,43Ca,42.9587668,0.0013926,0,2.9961756,-1 46 | [44]Ca,44Ca,43.9554811,0.021518243,0,3.9928899,-1 47 | [46]Ca,46Ca,45.9536927,4.13E-05,0,5.9911015,-1 48 | [48]Ca,48Ca,47.952533,0.001929008,0,7.9899418,-1 49 | Sc,45Sc,44.9559119,1,0,0,0 50 | [46]Ti,46Ti,45.9526316,0.111909929,0,-1.9953147,0 51 | [47]Ti,47Ti,46.9517631,0.100922409,0,-0.9961832,0 52 | Ti,48Ti,47.9479463,1,0,0,0 53 | [49]Ti,49Ti,48.94787,0.073385784,0,0.9999237,0 54 | [50]Ti,50Ti,49.9447912,0.070265871,0,1.9968449,0 55 | [50]V,50V,49.9471585,0.002506266,0,-0.996801,0 56 | V,51V,50.9439595,1,0,0,0 57 | [50]Cr,50Cr,49.9460442,0.051856449,0,-1.9944633,0 58 | Cr,52Cr,51.9405075,1,0,0,0 59 | [53]Cr,53Cr,52.9406494,0.113391973,0,1.0001419,0 60 | [54]Cr,54Cr,53.9388804,0.028225662,0,1.9983729,0 61 | Mn,55Mn,54.9380451,1,0,0,0 62 | [54]Fe,54Fe,53.9396147,0.063702945,0,-1.9953271,0 63 | Fe,56Fe,55.9349418,1,0,0,0 64 | [57]Fe,57Fe,56.9353983,0.023094361,0,1.0004565,0 65 | [58]Fe,58Fe,57.9332801,0.003073435,0,1.9983383,0 66 | Co,59Co,58.933195,1,0,0,0 67 | Ni,58Ni,57.9353429,1,0,0,-1 68 | [60]Ni,60Ni,59.9307864,0.38519821,0,1.9954435,-1 69 | [61]Ni,61Ni,60.931056,0.016744299,0,2.9957131,-1 70 | [62]Ni,62Ni,61.9283451,0.053388154,0,3.9930022,-1 71 | [64]Ni,64Ni,63.927966,0.013596389,0,5.9926231,-1 72 | Cu,63Cu,62.9295975,1,0,0,0 73 | [65]Cu,65Cu,64.9277895,0.446131598,0,1.998192,0 74 | Zn,64Zn,63.9291422,1,0,0,0 75 | [66]Zn,66Zn,65.9260334,0.579576531,0,1.9968912,0 76 | [67]Zn,67Zn,66.9271273,0.08498384,0,2.9979851,0 77 | [68]Zn,68Zn,67.9248442,0.394132759,0,3.995702,0 78 | [70]Zn,70Zn,69.9253193,0.013072843,0,5.9961771,0 79 | Ga,69Ga,68.9255736,1,0,0,0 80 | [71]Ga,71Ga,70.9247013,0.663672057,0,1.9991277,0 81 | [70]Ge,70Ge,69.9242474,0.555010893,0,-3.9969304,0 82 | [72]Ge,72Ge,71.9220758,0.743736383,0,-1.999102,0 83 | [73]Ge,73Ge,72.9234589,0.211328976,0,-0.9977189,0 84 | Ge,74Ge,73.9211778,1,0,0,0 85 | [76]Ge,76Ge,75.9214026,0.213235294,0,2.0002248,0 86 | As,75As,74.9215965,1,0,0,0 87 | [74]Se,74Se,73.9224764,0.017939931,0,-5.9940449,0 88 | [76]Se,76Se,75.9192136,0.188873211,0,-3.9973077,0 89 | [77]Se,77Se,76.919914,0.153799637,0,-2.9966073,0 90 | [78]Se,78Se,77.9173091,0.479137271,0,-1.9992122,0 91 | Se,80Se,79.9165213,1,0,0,0 92 | [82]Se,82Se,81.9166994,0.175972586,0,2.0001781,0 93 | Br,79Br,78.9183379,1,2,0,-0.5 94 | [81]Br,81Br,80.916291,0.972775695,2,1.9979531,-0.5 95 | [78]Kr,78Kr,77.9203648,0.006229491,0,-5.9911422,0 96 | [80]Kr,80Kr,79.916379,0.040114412,0,-3.995128,0 97 | [82]Kr,82Kr,81.9134836,0.203432362,0,-1.9980234,0 98 | [83]Kr,83Kr,82.914136,0.201800411,0,-0.997371,0 99 | Kr,84Kr,83.911507,1,0,0,0 100 | [86]Kr,86Kr,85.91061073,0.303209504,0,1.99910373,0 101 | Rb,85Rb,84.91178974,1,0,0,0 102 | [87]Rb,87Rb,86.90918053,0.385617293,0,1.99739079,0 103 | [84]Sr,84Sr,83.913425,0.006781303,0,-3.9921871,0 104 | [86]Sr,86Sr,85.9092602,0.11939937,0,-1.9963519,0 105 | [87]Sr,87Sr,86.9088771,0.084766287,0,-0.996735,0 106 | Sr,88Sr,87.9056121,1,0,0,0 107 | Y,89Y,88.9058483,1,0,0,0 108 | Zr,90Zr,89.9047044,1,0,0,0 109 | [91]Zr,91Zr,90.9056458,0.218075802,0,1.0009414,0 110 | [92]Zr,92Zr,91.9050408,0.333333333,0,2.0003364,0 111 | [94]Zr,94Zr,93.9063152,0.337803693,0,4.0016108,0 112 | [96]Zr,96Zr,95.9082734,0.054421769,0,6.003569,0 113 | Nb,93Nb,92.9063781,1,0,0,0 114 | [92]Mo,92Mo,91.906811,0.610582885,0,-5.9985972,0 115 | [94]Mo,94Mo,93.9050883,0.381562629,0,-4.0003199,0 116 | [95]Mo,95Mo,94.9058421,0.657296403,0,-2.9995661,0 117 | [96]Mo,96Mo,95.9046795,0.689541133,0,-2.0007287,0 118 | [97]Mo,97Mo,96.9060215,0.39520463,0,-0.9993867,0 119 | Mo,98Mo,97.9054082,1,0,0,0 120 | [100]Mo,100Mo,99.90747,0.399751964,0,2.0020618,0 121 | [96]Ru,96Ru,95.907598,0.175594295,0,-5.9967513,0 122 | [98]Ru,98Ru,97.905287,0.059270998,0,-3.9990623,0 123 | [99]Ru,99Ru,98.9059393,0.404437401,0,-2.99841,0 124 | [100]Ru,100Ru,99.9042195,0.399366086,0,-2.0001298,0 125 | [101]Ru,101Ru,100.9055821,0.540729002,0,-0.9987672,0 126 | Ru,102Ru,101.9043493,1,0,0,0 127 | [104]Ru,104Ru,103.905433,0.590174326,0,2.0010837,0 128 | Rh,103Rh,102.905504,1,0,0,0 129 | [102]Pd,102Pd,101.905609,0.037321625,0,-3.997877,0 130 | [104]Pd,104Pd,103.904036,0.407610684,0,-1.99945,0 131 | [105]Pd,105Pd,104.905085,0.81705086,0,-0.998401,0 132 | Pd,106Pd,105.903486,1,0,0,0 133 | [108]Pd,108Pd,107.903892,0.96816685,0,2.000406,0 134 | [110]Pd,110Pd,109.905153,0.428832784,0,4.001667,0 135 | Ag,107Ag,106.905097,1,0,0,0 136 | [109]Ag,109Ag,108.904752,0.929049557,0,1.999655,0 137 | [106]Cd,106Cd,105.906459,0.043508528,0,-7.9968995,0 138 | [108]Cd,108Cd,107.904184,0.030978072,0,-5.9991745,0 139 | [110]Cd,110Cd,109.9030021,0.434737208,0,-4.0003564,0 140 | [111]Cd,111Cd,110.9041781,0.445527323,0,-2.9991804,0 141 | [112]Cd,112Cd,111.9027578,0.839888618,0,-2.0006007,0 142 | [113]Cd,113Cd,112.9044017,0.425339367,0,-0.9989568,0 143 | Cd,114Cd,113.9033585,1,0,0,0 144 | [116]Cd,116Cd,115.904756,0.260703098,0,2.0013975,0 145 | [113]In,113In,112.904058,0.044822903,0,-1.99982,0 146 | In,115In,114.903878,1,0,0,0 147 | [112]Sn,112Sn,111.904818,0.029772867,0,-7.9973767,0 148 | [114]Sn,114Sn,113.902779,0.020257827,0,-5.9994157,0 149 | [115]Sn,115Sn,114.903342,0.01043585,0,-4.9988527,0 150 | [116]Sn,116Sn,115.901741,0.446286065,0,-4.0004537,0 151 | [117]Sn,117Sn,116.902952,0.23572744,0,-2.9992427,0 152 | [118]Sn,118Sn,117.901603,0.743400859,0,-2.0005917,0 153 | [119]Sn,119Sn,118.903308,0.263658686,0,-0.9988867,0 154 | Sn,120Sn,119.9021947,1,0,0,0 155 | [122]Sn,122Sn,121.903439,0.142111725,0,2.0012443,0 156 | [124]Sn,124Sn,123.9052739,0.17771639,0,4.0030792,0 157 | Sb,121Sb,120.9038157,1,0,0,0 158 | [123]Sb,123Sb,122.904214,0.747946163,0,2.0003983,0 159 | [120]Te,120Te,119.90402,0.002640845,0,-10.0022044,0 160 | [122]Te,122Te,121.9030439,0.074823944,0,-8.0031805,0 161 | [123]Te,123Te,122.90427,0.026115023,0,-7.0019544,0 162 | [124]Te,124Te,123.9028179,0.139084507,0,-6.0034065,0 163 | [125]Te,125Te,124.9044307,0.207453052,0,-5.0017937,0 164 | [126]Te,126Te,125.9033117,0.552816901,0,-4.0029127,0 165 | [128]Te,128Te,127.9044631,0.931338028,0,-2.0017613,0 166 | Te,130Te,129.9062244,1,0,0,0 167 | I,127I,126.904473,1,0,0,-0.5 168 | [124]Xe,124Xe,123.905893,0.003537902,0,-7.9982605,0 169 | [126]Xe,126Xe,125.904274,0.003307493,0,-5.9998795,0 170 | [128]Xe,128Xe,127.9035313,0.070988457,0,-4.0006222,0 171 | [129]Xe,129Xe,128.9047794,0.981121277,0,-2.9993741,0 172 | [130]Xe,130Xe,129.903508,0.151289922,0,-2.0006455,0 173 | [131]Xe,131Xe,130.9050824,0.789056287,0,-0.9990711,0 174 | Xe,132Xe,131.9041535,1,0,0,0 175 | [134]Xe,134Xe,133.9053945,0.387820251,0,2.001241,0 176 | [136]Xe,136Xe,135.907219,0.329162424,0,4.0030655,0 177 | Cs,133Cs,132.9054519,1,0,0,0 178 | [130]Ba,130Ba,129.9063208,0.001478423,0,-7.9989264,0 179 | [132]Ba,132Ba,131.9050613,0.001408686,0,-6.0001859,0 180 | [134]Ba,134Ba,133.9045084,0.033710843,0,-4.0007388,0 181 | [135]Ba,135Ba,134.9056886,0.091941198,0,-2.9995586,0 182 | [136]Ba,136Ba,135.9045759,0.109542805,0,-2.0006713,0 183 | [137]Ba,137Ba,136.9058274,0.156657089,0,-0.9994198,0 184 | Ba,138Ba,137.9052472,1,0,0,0 185 | [138]La,138La,137.907112,0.000900811,0,-0.9992413,0 186 | La,139La,138.9063533,1,0,0,0 187 | [136]Ce,136Ce,135.907172,0.002091577,0,-3.9982667,0 188 | [138]Ce,138Ce,137.905991,0.002837761,0,-1.9994477,0 189 | Ce,140Ce,139.9054387,1,0,0,0 190 | [142]Ce,142Ce,141.909244,0.125652911,0,2.0038053,0 191 | Pr,141Pr,140.9076528,1,0,0,0 192 | Nd,142Nd,141.9077233,1,0,0,0 193 | [143]Nd,143Nd,142.9098143,0.448529412,0,1.002091,0 194 | [144]Nd,144Nd,143.9100873,0.875,0,2.002364,0 195 | [145]Nd,145Nd,144.9125736,0.305147059,0,3.0048503,0 196 | [146]Nd,146Nd,145.9131169,0.632352941,0,4.0053936,0 197 | [148]Nd,148Nd,147.916893,0.209558824,0,6.0091697,0 198 | [150]Nd,150Nd,149.920891,0.205882353,0,8.0131677,0 199 | [144]Sm,144Sm,143.911999,0.114766355,0,-8.0077334,0 200 | [147]Sm,147Sm,146.9148979,0.560373832,0,-5.0048345,0 201 | [148]Sm,148Sm,147.9148227,0.420186916,0,-4.0049097,0 202 | [149]Sm,149Sm,148.9171847,0.516635514,0,-3.0025477,0 203 | [150]Sm,150Sm,149.9172755,0.27588785,0,-2.0024569,0 204 | Sm,152Sm,151.9197324,1,0,0,0 205 | [154]Sm,154Sm,153.9222093,0.85046729,0,2.0024769,0 206 | [151]Eu,151Eu,150.9198502,0.916075877,0,-2.0013801,0 207 | Eu,153Eu,152.9212303,1,0,0,0 208 | [152]Gd,152Gd,151.919791,0.00805153,0,-6.0043129,0 209 | [154]Gd,154Gd,153.9208656,0.087761675,0,-4.0032383,0 210 | [155]Gd,155Gd,154.922622,0.595813205,0,-3.0014819,0 211 | [156]Gd,156Gd,155.9221227,0.824074074,0,-2.0019812,0 212 | [157]Gd,157Gd,156.9239601,0.630032206,0,-1.0001438,0 213 | Gd,158Gd,157.9241039,1,0,0,0 214 | [160]Gd,160Gd,159.9270541,0.880032206,0,2.0029502,0 215 | Tb,159Tb,158.9253468,1,0,0,0 216 | [156]Dy,156Dy,155.924283,0.001981599,0,-8.0048918,0 217 | [158]Dy,158Dy,157.924409,0.003361642,0,-6.0047658,0 218 | [160]Dy,160Dy,159.9251975,0.082413305,0,-4.0039773,0 219 | [161]Dy,161Dy,160.9269334,0.668400566,0,-3.0022414,0 220 | [162]Dy,162Dy,161.9267984,0.901450814,0,-2.0023764,0 221 | [163]Dy,163Dy,162.9287312,0.880962491,0,-1.0004436,0 222 | Dy,164Dy,163.9291748,1,0,0,0 223 | Ho,165Ho,164.9303221,1,0,0,0 224 | [162]Er,162Er,161.928778,0.004148882,0,-4.0015151,0 225 | [164]Er,164Er,163.9292,0.047786765,0,-2.0010931,0 226 | Er,166Er,165.9302931,1,0,0,0 227 | [167]Er,167Er,166.9320482,0.682595588,0,1.0017551,0 228 | [168]Er,168Er,167.9323702,0.805241322,0,2.0020771,0 229 | [170]Er,170Er,169.9354643,0.445034773,0,4.0051712,0 230 | Tm,169Tm,168.9342133,1,0,0,0 231 | [168]Yb,168Yb,167.933897,0.004084197,0,-6.0049651,0 232 | [170]Yb,170Yb,169.9347618,0.095507383,0,-4.0041003,0 233 | [171]Yb,171Yb,170.9363258,0.448633365,0,-3.0025363,0 234 | [172]Yb,172Yb,171.9363815,0.685830977,0,-2.0024806,0 235 | [173]Yb,173Yb,172.9382108,0.506754634,0,-1.0006513,0 236 | Yb,174Yb,173.9388621,1,0,0,0 237 | [176]Yb,176Yb,175.9425717,0.400879673,0,2.0037096,0 238 | Lu,175Lu,174.9407718,1,0,0,0 239 | [176]Lu,176Lu,175.9426863,0.026588646,0,1.0019145,0 240 | [174]Hf,174Hf,173.940046,0.004561003,0,-6.006504,0 241 | [176]Hf,176Hf,175.9414086,0.149942987,0,-4.0051414,0 242 | [177]Hf,177Hf,176.9432207,0.530216648,0,-3.0033293,0 243 | [178]Hf,178Hf,177.9436988,0.777651083,0,-2.0028512,0 244 | [179]Hf,179Hf,178.9458161,0.388255416,0,-1.0007339,0 245 | Hf,180Hf,179.94655,1,0,0,0 246 | [180]Ta,180Ta,179.9474648,0.000120014,0,-1.000531,0 247 | Ta,181Ta,180.9479958,1,0,0,0 248 | [180]W,180W,179.946704,0.003916449,0,-4.0042272,0 249 | [182]W,182W,181.9482042,0.864882507,0,-2.002727,0 250 | [183]W,183W,182.950223,0.467036554,0,-1.0007082,0 251 | W,184W,183.9509312,1,0,0,0 252 | [186]W,186W,185.9543641,0.927872063,0,2.0034329,0 253 | [185]Re,185Re,184.952955,0.597444089,0,-2.0027981,0 254 | Re,187Re,186.9557531,1,0,0,0 255 | [184]Os,184Os,183.9524891,0.000490436,0,-8.0089916,0 256 | [186]Os,186Os,185.9538382,0.038989701,0,-6.0076425,0 257 | [187]Os,187Os,186.9557505,0.048062776,0,-5.0057302,0 258 | [188]Os,188Os,187.9558382,0.324668955,0,-4.0056425,0 259 | [189]Os,189Os,188.9581475,0.396027464,0,-3.0033332,0 260 | [190]Os,190Os,189.958447,0.643943109,0,-2.0030337,0 261 | Os,192Os,191.9614807,1,0,0,0 262 | [191]Ir,191Ir,190.960594,0.594896332,0,-2.0023324,0 263 | Ir,193Ir,192.9629264,1,0,0,0 264 | [190]Pt,190Pt,189.959932,0.000413809,0,-5.0048591,0 265 | [192]Pt,192Pt,191.961038,0.023114211,0,-3.0037531,0 266 | [194]Pt,194Pt,193.9626803,0.97443249,0,-1.0021108,0 267 | Pt,195Pt,194.9647911,1,0,0,0 268 | [196]Pt,196Pt,195.9649515,0.746098368,0,1.0001604,0 269 | [198]Pt,198Pt,197.967893,0.211722629,0,3.0031019,0 270 | Au,197Au,196.9665687,1,0,0,0 271 | [196]Hg,196Hg,195.965833,0.005023443,0,-6.00481,0 272 | [198]Hg,198Hg,197.966769,0.333891494,0,-4.003874,0 273 | [199]Hg,199Hg,198.9682799,0.564969859,0,-3.0023631,0 274 | [200]Hg,200Hg,199.968326,0.773610181,0,-2.002317,0 275 | [201]Hg,201Hg,200.9703023,0.441393168,0,-1.0003407,0 276 | Hg,202Hg,201.970643,1,0,0,0 277 | [204]Hg,204Hg,203.9734939,0.230073677,0,2.0028509,0 278 | [203]Tl,203Tl,202.9723442,0.418842225,0,-2.0020833,0 279 | Tl,205Tl,204.9744275,1,0,0,0 280 | [204]Pb,204Pb,203.9730436,0.026717557,0,-4.0036085,0 281 | [206]Pb,206Pb,205.9744653,0.459923664,0,-2.0021868,0 282 | [207]Pb,207Pb,206.9758969,0.421755725,0,-1.0007552,0 283 | Pb,208Pb,207.9766521,1,0,0,0 284 | Bi,209Bi,208.9803987,1,0,0,0 285 | Th,232Th,232.0380553,1,0,0,0 286 | Pa,231Pa,231.035884,1,0,0,0 287 | [234]U,234U,234.0409521,5.44E-05,0,-4.0098361,0 288 | [235]U,235U,235.0439299,0.007256669,0,-3.0068583,0 289 | U,238U,238.0507882,1,0,0,0 290 | -------------------------------------------------------------------------------- /data/elem_table.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/data/elem_table.rda -------------------------------------------------------------------------------- /inst/db/compound_db.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/inst/db/compound_db.rds -------------------------------------------------------------------------------- /inst/db/currency.qs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/inst/db/currency.qs -------------------------------------------------------------------------------- /inst/db/empirical_rule.qs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/inst/db/empirical_rule.qs -------------------------------------------------------------------------------- /inst/db/hmdb_lib.qs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/inst/db/hmdb_lib.qs -------------------------------------------------------------------------------- /inst/db/kegg_lib.qs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/inst/db/kegg_lib.qs -------------------------------------------------------------------------------- /inst/db/ms2_lib.qs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/inst/db/ms2_lib.qs -------------------------------------------------------------------------------- /inst/db/propagation_rule.qs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/inst/db/propagation_rule.qs -------------------------------------------------------------------------------- /inst/db/pubchem_lib.qs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xia-lab/OmicsNetR/50f6c9f88b8673dedcdf5696ad3adff1114ed06e/inst/db/pubchem_lib.qs -------------------------------------------------------------------------------- /inst/test/ibd_met.txt: -------------------------------------------------------------------------------- 1 | HMDB0000020 2 | HMDB0000030 3 | HMDB0000034 4 | HMDB0000036 5 | HMDB0000039 6 | HMDB0000043 7 | HMDB0000062 8 | HMDB0000064 9 | HMDB0000097 10 | HMDB0000101 11 | HMDB0000126 12 | HMDB0000128 13 | HMDB0000132 14 | HMDB0000133 15 | HMDB0000138 16 | HMDB0000157 17 | HMDB0000192 18 | HMDB0000209 19 | HMDB0000210 20 | HMDB0000237 21 | HMDB0000244 22 | HMDB0000262 23 | HMDB0000289 24 | HMDB0000292 25 | HMDB0000300 26 | HMDB0000355 27 | HMDB0000448 28 | HMDB0000452 29 | HMDB0000506 30 | HMDB0000518 31 | HMDB0000535 32 | HMDB0000562 33 | HMDB0000619 34 | HMDB0000626 35 | HMDB0000631 36 | HMDB0000637 37 | HMDB0000698 38 | HMDB0000708 39 | HMDB0000717 40 | HMDB0000764 41 | HMDB0000766 42 | HMDB0000786 43 | HMDB0000870 44 | HMDB0000873 45 | HMDB0000883 46 | HMDB0000888 47 | HMDB0000893 48 | HMDB0000951 49 | HMDB0001008 50 | HMDB0001488 51 | HMDB0001847 52 | HMDB0002000 53 | HMDB0002100 54 | HMDB0002250 55 | HMDB0002302 56 | HMDB0002320 57 | HMDB0004159 58 | HMDB0004193 59 | HMDB0004326 60 | HMDB0006023 61 | HMDB0012252 62 | HMDB0012252 63 | HMDB0014420 64 | HMDB0015070 65 | HMDB0029723 66 | HMDB0094704 67 | -------------------------------------------------------------------------------- /inst/test/sample.txt: -------------------------------------------------------------------------------- 1 | VCAN UBC VCAN PITX3 VCAN CD44 VCAN CXCL10 VCAN FBLN2 VCAN FBN1 VCAN PF4 VCAN CCL21 VCAN HAPLN1 VCAN CCL2 VCAN CCL5 VCAN SELL VCAN SELP VCAN CXCL12 VCAN CXCR3 VCAN CCL20 VCAN CCL8 VCAN SELPLG HERC3 CCL22 CCR7 CCL22 CCR7 CCL19 NFKB1 PLD3 NFKB1 CCL22 NFKB1 CXCL10 NFKB1 CCL19 CCR4 CCL22 SP3 PTGES UBC PLD3 UBC CA12 UBC MT1X UBC CPVL UBC FBP1 UBC SERPINA1 UBC ANKRD1 UBC HIST2H2AC UBC HIST2H2AA3 UBC PDLIM7 UBC MT1H UBC ALDH1A1 UBC CCL19 UBC MT1G UBC PTGES UBC MT1F UBC LIPA UBC GPNMB UBC TREM1 SP1 PTGES EGR1 PTGES PLD3 BCL2L1 PLD3 SPP1 PLD3 ERP44 PLD3 PPP5C PLD3 EIF2S3 PLD3 NUDCD1 PLD3 FBXO6 PLD3 GJA1 PLD3 FUBP1 PLD3 HGS PLD3 TK1 PLD3 ANXA7 CA12 KATNBL1 CA12 MAPK6 CA12 SGSM2 CA12 ATP5C1 CA12 CUX1 CA12 LGALS7B CA12 LGALS7B CA12 RDH11 CA12 TOE1 CA12 MRPL9 CA12 DAXX MT1X POT1 MT1X VKORC1 MT1X TERF1 MT1X HNF4A MT1X HNF1A MT1X ELAVL1 MT1X NCOR1 MT1X TERF2IP MT1X SIAH2 MT1X AR MAPK6 PPBP CPVL ATAD5 CPVL PLRG1 CPVL NRBF2 CPVL MAP3K3 CPVL CTNNBIP1 FBP1 POT1 FBP1 HSPA8 FBP1 FXR2 FBP1 BIN1 FBP1 TERF1 FBP1 ASL FBP1 KLRC2 FBP1 BCL2L1 FBP1 ASCC2 FBP1 HDAC6 FBP1 PTK2 FBP1 DYNC1I1 FBP1 AMPH FBP1 LNX1 FBP1 PCNXL4 FBP1 PARK2 FBP1 CSNK1E FBP1 ATP5J2 FBP1 RNF183 SERPINA1 DERL2 SERPINA1 LGALS3 SERPINA1 ELANE SERPINA1 OS9 SERPINA1 VCP SERPINA1 PRTN3 SERPINA1 VKORC1 SERPINA1 GZMM SERPINA1 PITX3 SERPINA1 SMAD4 SERPINA1 CTSG SERPINA1 TCF3 SERPINA1 DERL1 SERPINA1 HNF4A SERPINA1 HNF1A SERPINA1 KLK3 SERPINA1 ADAMTS4 SERPINA1 RAP2A SERPINA1 CANX SERPINA1 ECHS1 SERPINA1 SDC2 SERPINA1 PRSS3 SERPINA1 ATP5C1 SERPINA1 SSR1 SERPINA1 LRP1 SERPINA1 GSDMB SERPINA1 ERLEC1 SERPINA1 RCHY1 SERPINA1 MIS12 SERPINA1 UGGT1 SERPINA1 KLK13 ANKRD1 MYOM2 ANKRD1 TULP3 ANKRD1 TTN ANKRD1 DYSF ANKRD1 MYPN ANKRD1 ARHGDIB ANKRD1 DNAJB6 ANKRD1 MYL1 ANKRD1 LRPPRC ANKRD1 MYBPC1 ANKRD1 DST ANKRD1 REPS1 ANKRD1 ASH2L ANKRD1 APPL1 HIST2H2AC CENPA HIST2H2AC SMN1 HIST2H2AC C17orf79 HIST2H2AC MORF4L2 HIST2H2AC CTCFL HIST2H2AC HAT1 HIST2H2AC BMI1 HIST2H2AC USP22 HIST2H2AC SUMO2 HIST2H2AC PBRM1 HIST2H2AC DDB2 HIST2H2AC MORF4L1 HIST2H2AC TSSK6 HIST2H2AC GATAD2A HIST2H2AC SMC2 HIST2H2AC KLK3 HIST2H2AC RNF20 HIST2H2AC RNF169 HIST2H2AC CRP HIST2H2AC SSRP1 HIST2H2AC SMN1 HIST2H2AC HIST1H2BA HIST2H2AC ANP32A HIST2H2AC CTCF HIST2H2AC BRCA1 HIST2H2AC PRMT7 HIST2H2AC ASXL1 HIST2H2AC CTDP1 HIST2H2AC ATXN7 HIST2H2AC UIMC1 HIST2H2AC NEDD8 HIST2H2AC NAP1L4 HIST2H2AC BARD1 HIST2H2AC CHFR HIST2H2AC TAF1B HIST2H2AC SIRT7 HIST2H2AC RNF8 HIST2H2AC UBR2 HIST2H2AC EIF2AK2 HIST2H2AC HDAC5 HIST2H2AC USP12 HIST2H2AC NPM1 HIST2H2AC PRAME HIST2H2AC H2AFX HIST2H2AC ATXN7L3 HIST2H2AC NCAPH HIST2H2AC RBBP4 HIST2H2AC POLR2C HIST2H2AC PARP10 HIST2H2AC KAT2A HIST2H2AC UBE2B HIST2H2AC MECP2 HIST2H2AC USP46 HIST2H2AC MSL2 HIST2H2AC EP300 HIST2H2AC TAF15 HIST2H2AC RCC1 HIST2H2AC UBE2D3 HIST2H2AC BMI1 HIST2H2AC BAP1 HIST2H2AC PRMT5 HIST2H2AC RAG1 HIST2H2AC MYSM1 HIST2H2AC HIST1H1B HIST2H2AC DNMT3L HIST2H2AC ENY2 HIST2H2AC RNF168 HIST2H2AC DEK HIST2H2AC BAZ1B HIST2H2AC SCMH1 HIST2H2AC RNF2 HIST2H2AC KAT7 HIST2H2AC UBB HIST2H2AC NCL HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H4A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC HIST1H3A HIST2H2AC TSPY1 HIST2H2AC TSPY1 HIST2H2AC TSPY1 HIST2H2AC ERCC6 HIST2H2AC TAF1A HIST2H2AC RBBP7 HIST2H2AC PELP1 HIST2H2AC GATAD2B HIST2H2AC TCF20 IRF1 CXCL10 IRF1 IL18BP IRF1 CCL19 POT1 ALDH1A1 NOS2 ALDH1A1 NUPR1 ALDH1A1 ALDH2 ALDH1A1 ELANE CAMP PRTN3 CAMP SMAD4 GPNMB CTSG CAMP RNF115 CST3 CSTB CST3 RNF115 CST3 CTSB CST3 ALB PPBP ALB CST3 CCL22 CCL19 CCL22 RELA CCL22 RELB CCL22 CRYAB CCL22 VCAM1 CCL22 DPP4 CCL22 GCLC COPS7A PPBP CMTM6 PPBP PMAIP1 PPBP SCFD1 PPBP PLEKHJ1 PPBP IL7R PPBP PIAS1 CXCL10 DPP8 CXCL10 IRF7 CXCL10 IRF7 CCL19 IGFBP7 CXCL10 PPBP MMP1 PPBP MMP9 PPBP EFNA1 PPBP NR4A1 PPBP CXCR1 PPBP CXCR2 PPBP RPS27 PPBP RAB10 PPBP CSNK2A1 PPBP DMWD PPBP COX17 PPBP MOB3B PPBP CELF1 PPBP STRN4 PPBP NDUFB11 PPBP COPG1 CCL7 CCR1 CCL7 ELAVL1 CCL7 CTNNB1 CCL7 AES CCL7 MMP2 CCL7 CCR5 CCL7 CCR3 CCL7 CCBP2 CCL7 CCR2 CCL7 CCRL1 CCL7 NR3C1 CCL7 BCL6 CCL7 STAT6 CCL7 CXCR3 CCL7 FEZ1 SHBG MT1G SHBG MT1F HIST2H2AA3 HNF4A HIST2H2AA3 BMI1 HIST2H2AA3 SUMO2 HIST2H2AA3 RNF20 HIST2H2AA3 MSL2 HIST2H2AA3 BMI1 HIST2H2AA3 RNF168 HIST2H2AA3 IL33 HIST2H2AA3 RNF2 HIST2H2AA3 PARP1 HIST2H2AA3 HDAC1 HIST2H2AA3 DNAJC2 HIST2H2AA3 CHD1L HIST2H2AA3 MEN1 HIST2H2AA3 G3BP1 HIST2H2AA3 TBL1X HIST2H2AA3 NOC2L HIST2H2AA3 SRRM1 HIST2H2AA3 PRMT6 HIST2H2AA3 CHD1L HIST2H2AA3 APP CAMP FOS CAMP GAPDH CAMP IGF1R CAMP VDR CAMP JUN CAMP CREB1 CAMP SPI1 CAMP PGC CAMP MAPK8 CAMP KLK7 CAMP P2RX7 CAMP KLK5 PDLIM7 SPP1 PDLIM7 PRKD2 PDLIM7 PCBP1 PDLIM7 GEM PDLIM7 FBXW11 PDLIM7 ZMYND11 PDLIM7 BSG PDLIM7 TAB2 PDLIM7 PAK7 PDLIM7 GFAP PDLIM7 MYC PDLIM7 SH3BP2 PDLIM7 WWP2 PDLIM7 UBE2I PDLIM7 SMURF1 PDLIM7 ENKD1 PDLIM7 PSMF1 PDLIM7 TP53 PDLIM7 RET PDLIM7 TPM2 PDLIM7 NR2C2 PDLIM7 HOXA1 PDLIM7 ZNF165 PDLIM7 MDM2 PDLIM7 TRAF2 PDLIM7 TRAF3 PDLIM7 TRADD PDLIM7 SMAD1 PDLIM7 AP5B1 PDLIM7 C1orf65 PDLIM7 C20orf195 PDLIM7 UBQLN4 PDLIM7 TRAF6 IL3RA IL3 IL3RA BCL6 LEF1 MMP7 CD44 MMP7 DEFB4A MMP7 ETV4 MMP7 HBEGF MMP7 DEFA1 MMP7 DEFB1 MMP7 DEFB4A MMP7 DEFA1 MMP7 CST3 C4A CST3 ATXN1 CXCL10 CCR3 CXCL10 RELA CXCL10 IRF2 CXCL10 DPP4 CXCL10 STAT1 CXCL10 CXCR3 CXCL10 POLR2F CXCL10 IRF9 CXCL10 IRF3 CXCL10 PRMT1 RNASE1 RELA RNASE1 RNH1 IL18BP CEBPB IL18BP IL18 IL18BP IL37 CYP27B1 CEBPB CYP27B1 CITED1 MT1H HNF4A MT1H HNF1A MT1H SPINK7 MT1H DNAJC1 CCR8 CCL1 CCR1 CCL1 AHR CCL1 HNF4A ALDH1A1 HNF4A HSD11B1 GKAP1 HSD11B1 CD36 HSD11B1 HNF1A HSD11B1 ELAVL1 LIPA CCL19 CCRL2 CCL19 RELA CCL19 CCRL1 CCL19 CCR10 CCL19 RNF31 CCL19 STAT2 CCL19 RELB CCL19 IRF5 CCL19 STAT1 CCL19 NFKB2 CCL19 IRF9 CCL19 IRF3 CCL1 STAT6 MMP7 FASLG MMP7 BCAN MMP7 TCF7L2 CCL24 CCR3 MT1G SPINK7 MT1M PAN2 MT1M RELB ITSN2 GPNMB TLR4 TREM1 TYROBP TREM1 -------------------------------------------------------------------------------- /inst/test/test_ko.txt: -------------------------------------------------------------------------------- 1 | K00262 K10200 K15633 K02355 K04077 K02931 K03809 K00626 K00074 K02996 K00041 K00874 K01006 K04043 K02358 K01939 K01439 K02867 K02982 K02357 K01923 K03737 K03043 K01610 K03046 K03561 K01507 K12340 K02986 K02027 K10192 K02988 K02994 K02887 K01810 K00046 K01835 K02879 K01876 K01938 K02863 K12257 K07335 K02992 K01893 K03040 K03070 K02959 K14062 K02967 K01872 K00600 K03695 K09475 K01639 K00625 K07405 K01687 K02956 K02952 K07175 K00927 K01625 K00244 K02935 K04078 K00602 K03521 K10112 K00850 K02890 K01715 K02118 K00925 K00845 K02564 K10117 K01624 K01803 K01874 K00700 K02112 K02838 K00053 K01886 K02881 K10254 K10540 K02926 K01571 K00688 K03530 K00962 K03527 K02878 K04079 K01952 K04564 UNGROUPED K02117 K03585 K18682 K01734 K02356 K01960 K02886 K00198 K01869 K00346 K00239 K02933 K02897 K13993 K01937 K00639 K02647 K00645 K02876 K01915 K01744 K02948 K02946 K01866 K03545 K01951 K01784 K02895 K03615 K00248 K00259 K02902 K00789 K11934 K01873 K11065 K02945 K01270 K00948 K00024 K01714 K03924 K01756 K02906 K01745 K01588 K00133 K02884 K01881 K10542 K00928 K00609 K00703 K01733 K02950 K00525 K03839 K02519 K00382 K07030 K03784 K00134 K01805 K03522 K04516 K00821 K06142 K02217 K01790 K00812 K00040 K01258 K01875 K07568 K00762 K01710 K00174 K01736 K03775 K01686 K01647 K03286 K01887 K01940 K02803 K02804 K02058 K00048 K01889 K00605 K00975 K03624 K00813 -------------------------------------------------------------------------------- /man/BuildMinConnectedGraphs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{BuildMinConnectedGraphs} 4 | \alias{BuildMinConnectedGraphs} 5 | \title{Compute minimum connected network composed of seed nodes using shortest path based approach} 6 | \usage{ 7 | BuildMinConnectedGraphs(dataSetObj = NA, max.len = 200) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | 12 | \item{max.len}{Maximum number of seeds, if more than this number, take top 100 seed nodes based on degrees} 13 | } 14 | \value{ 15 | check overall.graph object for result 16 | } 17 | \description{ 18 | Compute minimum connected network composed of seed nodes using shortest path based approach 19 | } 20 | -------------------------------------------------------------------------------- /man/BuildPCSFNet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{BuildPCSFNet} 4 | \alias{BuildPCSFNet} 5 | \title{Compute minimum connect subnetwork based on input nodes using prize-collecting steiner forest approach} 6 | \usage{ 7 | BuildPCSFNet(dataSetObj = NA) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | } 12 | \value{ 13 | check overall.graph object for result 14 | } 15 | \description{ 16 | Compute minimum connect subnetwork based on input nodes using prize-collecting steiner forest approach 17 | } 18 | -------------------------------------------------------------------------------- /man/BuildSeedProteinNet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{BuildSeedProteinNet} 4 | \alias{BuildSeedProteinNet} 5 | \title{Create network from only input (seeds)} 6 | \usage{ 7 | BuildSeedProteinNet(dataSetObj = NA) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | } 12 | \description{ 13 | Create network from only input (seeds) 14 | } 15 | -------------------------------------------------------------------------------- /man/CreateGraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{CreateGraph} 4 | \alias{CreateGraph} 5 | \title{Create igraph object from edgelist created from database selection and decompose into connected subnetworks} 6 | \usage{ 7 | CreateGraph(dataSetObj = NA) 8 | } 9 | \description{ 10 | Create igraph object from edgelist created from database selection and decompose into connected subnetworks 11 | } 12 | -------------------------------------------------------------------------------- /man/DoGba.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{DoGba} 4 | \alias{DoGba} 5 | \title{Guilt-by-association analysis using Random Walk With Restart} 6 | \usage{ 7 | DoGba(fileNm = "NA", method = "rwr", nodeids) 8 | } 9 | \arguments{ 10 | \item{fileNm}{Input file name for exporting result table as .csv} 11 | 12 | \item{method}{Method name, only "rwr" is supported} 13 | 14 | \item{nodeids}{The IDs of nodes set as seed nodes "; " separated.} 15 | } 16 | \description{ 17 | Guilt-by-association analysis using Random Walk With Restart 18 | } 19 | -------------------------------------------------------------------------------- /man/ExtractModule.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{ExtractModule} 4 | \alias{ExtractModule} 5 | \title{Compute minimum connected subnetwork from input nodes using shortest path based approach} 6 | \usage{ 7 | ExtractModule(dataSetObj = NA, nodeids, dim = "3") 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | 12 | \item{nodeids}{The ids of input nodes} 13 | 14 | \item{dim}{dimension of network results to be exported} 15 | } 16 | \description{ 17 | Compute minimum connected subnetwork from input nodes using shortest path based approach 18 | } 19 | -------------------------------------------------------------------------------- /man/FilterByPvalue.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{FilterByPvalue} 4 | \alias{FilterByPvalue} 5 | \title{Filter peaks by p-value cutoff for peak processing} 6 | \usage{ 7 | FilterByPvalue(pvaluecutoff) 8 | } 9 | \arguments{ 10 | \item{pvaluecutoff}{Input the p-value cutoff} 11 | } 12 | \description{ 13 | Filter peaks by p-value cutoff for peak processing 14 | } 15 | -------------------------------------------------------------------------------- /man/FilterByTissue.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{FilterByTissue} 4 | \alias{FilterByTissue} 5 | \title{FilterByTissue} 6 | \usage{ 7 | FilterByTissue(dataSetObj = NA, type, tissue) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{dataSetObj} 11 | 12 | \item{type}{Input database name} 13 | 14 | \item{tissue}{Input the tissue name} 15 | } 16 | \description{ 17 | Filter gene/protein by tissue 18 | } 19 | -------------------------------------------------------------------------------- /man/FindCommunities.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{FindCommunities} 4 | \alias{FindCommunities} 5 | \title{Detect graph communities using function from igraph} 6 | \usage{ 7 | FindCommunities(method = "infomap", use.weight = FALSE) 8 | } 9 | \arguments{ 10 | \item{method}{algorithm choice: walktrap, infomap, label propagation} 11 | 12 | \item{use.weight}{Boolean consider edge weight: FALSE} 13 | } 14 | \description{ 15 | Detect graph communities using function from igraph 16 | } 17 | -------------------------------------------------------------------------------- /man/GetRCommandHistory.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/DataUtils.R 3 | \name{GetRCommandHistory} 4 | \alias{GetRCommandHistory} 5 | \title{Export R Command History} 6 | \usage{ 7 | GetRCommandHistory(dataSetObj = NA) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | } 12 | \description{ 13 | Export R Command History 14 | } 15 | -------------------------------------------------------------------------------- /man/GetShortestPaths.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{GetShortestPaths} 4 | \alias{GetShortestPaths} 5 | \title{Compute the shortest path between two nodes} 6 | \usage{ 7 | GetShortestPaths(from, to, intermediate = "false") 8 | } 9 | \arguments{ 10 | \item{from}{ID of from node} 11 | 12 | \item{to}{ID of target node} 13 | 14 | \item{intermediate}{if true check whether from and target node connects to each other} 15 | } 16 | \description{ 17 | Compute the shortest path between two nodes 18 | } 19 | -------------------------------------------------------------------------------- /man/ImportMSPeaks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MSPeakNet.R 3 | \name{ImportMSPeaks} 4 | \alias{ImportMSPeaks} 5 | \title{ImportMSPeaks} 6 | \usage{ 7 | ImportMSPeaks(PeakFile = NA) 8 | } 9 | \arguments{ 10 | \item{PeakFile}{PeakFile path} 11 | } 12 | \description{ 13 | ImportMSPeaks 14 | } 15 | -------------------------------------------------------------------------------- /man/Init.Data.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/DataUtils.R 3 | \name{Init.Data} 4 | \alias{Init.Data} 5 | \title{Initialize dataSet object for downstream functions} 6 | \usage{ 7 | Init.Data() 8 | } 9 | \description{ 10 | Initialize dataSet object for downstream functions 11 | } 12 | -------------------------------------------------------------------------------- /man/InitiatePeakSet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MSPeakNet.R 3 | \name{InitiatePeakSet} 4 | \alias{InitiatePeakSet} 5 | \title{InitiatePeakSet} 6 | \usage{ 7 | InitiatePeakSet(ionMode = -1, ppm = 10, database = "KEGG", p_cutoff = 0.1) 8 | } 9 | \arguments{ 10 | \item{ionMode}{ion mode, postive is 1 and negative is -1} 11 | 12 | \item{ppm}{ppm value of mass} 13 | 14 | \item{database}{database, can be "KEGG", "HMDB" or "Pubchem"} 15 | 16 | \item{p_cutoff}{p value cutoff for filtration, default is 0.1} 17 | } 18 | \description{ 19 | InitiatePeakSet 20 | } 21 | -------------------------------------------------------------------------------- /man/PerformAnnotation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MSPeakNet.R 3 | \name{PerformAnnotation} 4 | \alias{PerformAnnotation} 5 | \title{PerformAnnotation} 6 | \usage{ 7 | PerformAnnotation() 8 | } 9 | \description{ 10 | PerformAnnotation 11 | } 12 | -------------------------------------------------------------------------------- /man/PerformDataProcessing.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MSPeakNet.R 3 | \name{PerformDataProcessing} 4 | \alias{PerformDataProcessing} 5 | \title{PerformDataProcessing} 6 | \usage{ 7 | PerformDataProcessing() 8 | } 9 | \description{ 10 | PerformDataProcessing 11 | } 12 | -------------------------------------------------------------------------------- /man/PerformGlobalOptimization.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MSPeakNet.R 3 | \name{PerformGlobalOptimization} 4 | \alias{PerformGlobalOptimization} 5 | \title{PerformGlobalOptimization} 6 | \usage{ 7 | PerformGlobalOptimization() 8 | } 9 | \description{ 10 | PerformGlobalOptimization 11 | } 12 | -------------------------------------------------------------------------------- /man/PerformMetEnrichment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FunctionUtils.R 3 | \name{PerformMetEnrichment} 4 | \alias{PerformMetEnrichment} 5 | \title{Perform metabolite or gene/metabolite enrichment analysis} 6 | \usage{ 7 | PerformMetEnrichment(dataSetObj = NA, file.nm, fun.type, ids) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | 12 | \item{file.nm}{File name of result table to be exported in csv format, do not include file extension} 13 | 14 | \item{fun.type}{Enrichment type: keggm (kegg metabolite), integ (joint gene/metabolite)} 15 | 16 | \item{ids}{String of ids to be tested separated by "; "} 17 | } 18 | \description{ 19 | Perform metabolite or gene/metabolite enrichment analysis 20 | } 21 | -------------------------------------------------------------------------------- /man/PerformNetEnrichment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/FunctionUtils.R 3 | \name{PerformNetEnrichment} 4 | \alias{PerformNetEnrichment} 5 | \title{Perform gene enrichment analysis or identify gene regulatory targets} 6 | \usage{ 7 | PerformNetEnrichment(file.nm, fun.type, IDs) 8 | } 9 | \arguments{ 10 | \item{file.nm}{File name of result table to be exported in csv format, do not include file extension} 11 | 12 | \item{fun.type}{Enrichment database type} 13 | 14 | \item{IDs}{String of ids to be tested separated by "; "} 15 | } 16 | \description{ 17 | Perform gene enrichment analysis or identify gene regulatory targets 18 | } 19 | -------------------------------------------------------------------------------- /man/PerformPropagation.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MSPeakNet.R 3 | \name{PerformPropagation} 4 | \alias{PerformPropagation} 5 | \title{PerformPropagation} 6 | \usage{ 7 | PerformPropagation() 8 | } 9 | \description{ 10 | PerformPropagation 11 | } 12 | -------------------------------------------------------------------------------- /man/PlotBetweennessHistogram.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{PlotBetweennessHistogram} 4 | \alias{PlotBetweennessHistogram} 5 | \title{PlotBetweennessHistogram} 6 | \usage{ 7 | PlotBetweennessHistogram(imgNm, netNm = "NA", dpi = 72, format = "png") 8 | } 9 | \arguments{ 10 | \item{imgNm}{image name} 11 | 12 | \item{netNm}{network name} 13 | 14 | \item{dpi}{dpi value} 15 | 16 | \item{format}{format} 17 | } 18 | \description{ 19 | PlotBetweennessHistogram 20 | } 21 | -------------------------------------------------------------------------------- /man/PlotDegreeHistogram.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{PlotDegreeHistogram} 4 | \alias{PlotDegreeHistogram} 5 | \title{PlotDegreeHistogram} 6 | \usage{ 7 | PlotDegreeHistogram(imgNm, netNm = "NA", dpi = 72, format = "png") 8 | } 9 | \arguments{ 10 | \item{imgNm}{image name} 11 | 12 | \item{netNm}{network name} 13 | 14 | \item{dpi}{dpi value} 15 | 16 | \item{format}{format} 17 | } 18 | \description{ 19 | PlotDegreeHistogram 20 | } 21 | -------------------------------------------------------------------------------- /man/PrepareGraph.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{PrepareGraph} 4 | \alias{PrepareGraph} 5 | \title{PrepareGraph} 6 | \usage{ 7 | PrepareGraph(net.nm, type = "", export = T) 8 | } 9 | \arguments{ 10 | \item{net.nm}{net.nm} 11 | 12 | \item{type}{type} 13 | 14 | \item{export}{export} 15 | } 16 | \description{ 17 | PrepareGraph 18 | } 19 | -------------------------------------------------------------------------------- /man/PrepareInputList.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/DataUtils.R 3 | \name{PrepareInputList} 4 | \alias{PrepareInputList} 5 | \title{Process input list} 6 | \usage{ 7 | PrepareInputList(dataSetObj = "NA", inputList, org, type, queryType) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | 12 | \item{inputList}{Tab-delimited String of input omics list} 13 | 14 | \item{org}{organism code: hsa, mmu, microbiome, rno, cel, dme, dre, sce, bta, gga} 15 | 16 | \item{type}{character, type} 17 | 18 | \item{queryType}{character, queryType} 19 | } 20 | \description{ 21 | Process input list 22 | } 23 | -------------------------------------------------------------------------------- /man/PrepareNetwork.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{PrepareNetwork} 4 | \alias{PrepareNetwork} 5 | \title{Prepare the json file for network visualization} 6 | \usage{ 7 | PrepareNetwork(dataSetObj = NA, net.nm, json.nm) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | 12 | \item{net.nm}{Name of subnetwork created from network building (i.e subnetwork1)} 13 | 14 | \item{json.nm}{Name of json file to be exported for network visualization} 15 | } 16 | \description{ 17 | Prepare the json file for network visualization 18 | } 19 | -------------------------------------------------------------------------------- /man/PreparePeaksNetwork.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{PreparePeaksNetwork} 4 | \alias{PreparePeaksNetwork} 5 | \title{PreparePeaksNetwork} 6 | \usage{ 7 | PreparePeaksNetwork(dataSetObj = NA) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{dataSetObj} 11 | } 12 | \description{ 13 | PreparePeaksNetwork 14 | } 15 | -------------------------------------------------------------------------------- /man/QueryNet.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{QueryNet} 4 | \alias{QueryNet} 5 | \title{Query database using input list or previously computed network} 6 | \usage{ 7 | QueryNet( 8 | dataSetObj = NA, 9 | type = "gene", 10 | dbType = "default", 11 | inputType = "gene" 12 | ) 13 | } 14 | \arguments{ 15 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 16 | 17 | \item{type}{Network type (gene, met, mir, tf, mic, peak, m2m, snp)} 18 | 19 | \item{dbType}{Database name (i.e innatedb)} 20 | 21 | \item{inputType}{Omics type of input features (gene, protein, met, tf, mic, peak, snp)} 22 | } 23 | \description{ 24 | Query database using input list or previously computed network 25 | } 26 | -------------------------------------------------------------------------------- /man/ReadGraphFile.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/GraphFileUtils.R 3 | \name{ReadGraphFile} 4 | \alias{ReadGraphFile} 5 | \title{ReadGraphFile} 6 | \usage{ 7 | ReadGraphFile(dataSetObj = NA, fileName, fileType) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{dataSetObj} 11 | 12 | \item{fileName}{fileName, Input name of graph file} 13 | 14 | \item{fileType}{fileType, File type of graph file (".json", ".graphml", ".txt", ".sif")} 15 | } 16 | \description{ 17 | ReadGraphFile 18 | } 19 | -------------------------------------------------------------------------------- /man/RecordRCommand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/DataUtils.R 3 | \name{RecordRCommand} 4 | \alias{RecordRCommand} 5 | \title{Record R Commands} 6 | \usage{ 7 | RecordRCommand(dataSetObj = NA, cmd) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | 12 | \item{cmd}{Commands} 13 | } 14 | \description{ 15 | Record R Commands 16 | } 17 | -------------------------------------------------------------------------------- /man/SanityCheckSelection.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{SanityCheckSelection} 4 | \alias{SanityCheckSelection} 5 | \title{SanityCheckSelection} 6 | \usage{ 7 | SanityCheckSelection(dataSetObj = NA) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{dataSetObj} 11 | } 12 | \description{ 13 | SanityCheckSelection 14 | } 15 | -------------------------------------------------------------------------------- /man/SaveNetworkJson.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{SaveNetworkJson} 4 | \alias{SaveNetworkJson} 5 | \title{Save graph file in OmicsNet json format} 6 | \usage{ 7 | SaveNetworkJson(fileNm) 8 | } 9 | \arguments{ 10 | \item{fileNm}{The file name of output json file} 11 | } 12 | \description{ 13 | Save graph file in OmicsNet json format 14 | } 15 | -------------------------------------------------------------------------------- /man/SetMetPotentialOpts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{SetMetPotentialOpts} 4 | \alias{SetMetPotentialOpts} 5 | \title{SetMetPotentialOpts} 6 | \usage{ 7 | SetMetPotentialOpts(metPotentialThresh, currExclude, uniExclude, orphExclude) 8 | } 9 | \arguments{ 10 | \item{metPotentialThresh}{metPotentialThresh} 11 | 12 | \item{currExclude}{currExclude} 13 | 14 | \item{uniExclude}{uniExclude} 15 | 16 | \item{orphExclude}{orphExclude} 17 | } 18 | \description{ 19 | SetMetPotentialOpts 20 | } 21 | -------------------------------------------------------------------------------- /man/SetPpiZero.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{SetPpiZero} 4 | \alias{SetPpiZero} 5 | \title{SetPpiZero} 6 | \usage{ 7 | SetPpiZero(ppiZero) 8 | } 9 | \arguments{ 10 | \item{ppiZero}{ppiZero} 11 | } 12 | \description{ 13 | SetPpiZero 14 | } 15 | -------------------------------------------------------------------------------- /man/SetSnp2GeneOpts.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{SetSnp2GeneOpts} 4 | \alias{SetSnp2GeneOpts} 5 | \title{SetSnp2GeneOpts} 6 | \usage{ 7 | SetSnp2GeneOpts(snpDBType, phescOpt, vepOpt, vepNum, vepDis) 8 | } 9 | \arguments{ 10 | \item{snpDBType}{snpDBType} 11 | 12 | \item{phescOpt}{phescOpt} 13 | 14 | \item{vepOpt}{vepOpt} 15 | 16 | \item{vepNum}{vepNum} 17 | 18 | \item{vepDis}{vepDis} 19 | } 20 | \description{ 21 | SetSnp2GeneOpts 22 | } 23 | -------------------------------------------------------------------------------- /man/UpdateCmpdDB.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MSPeakNet.R 3 | \name{UpdateCmpdDB} 4 | \alias{UpdateCmpdDB} 5 | \title{UpdateCmpdDB} 6 | \usage{ 7 | UpdateCmpdDB(dbNM) 8 | } 9 | \arguments{ 10 | \item{dbNM}{database name, KEGG, HMDB or PubChem} 11 | } 12 | \description{ 13 | UpdateCmpdDB 14 | } 15 | -------------------------------------------------------------------------------- /man/call_sr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{call_sr} 4 | \alias{call_sr} 5 | \title{Internal function \code{call_sr}} 6 | \usage{ 7 | call_sr(from, to, cost, node_names, node_prizes) 8 | } 9 | \arguments{ 10 | \item{from}{A \code{CharacterVector} that corresponds to \code{head} nodes of the edges.} 11 | 12 | \item{to}{A \code{CharacterVector} that corresponds the \code{tail} nodes of the edges.} 13 | 14 | \item{cost}{A \code{NumericVector} which represents the edge weights.} 15 | 16 | \item{node_names}{A \code{CharacterVector} demonstrates the names of the nodes.} 17 | 18 | \item{node_prizes}{A \code{NumericVector} which corresponds to the node prizes.} 19 | } 20 | \description{ 21 | This function is internally used to solve the PCST. 22 | } 23 | \author{ 24 | Murodzhon Akhmedov 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/elem_table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/MSPeakNet.R 3 | \docType{data} 4 | \name{elem_table} 5 | \alias{elem_table} 6 | \title{elem_table} 7 | \format{ 8 | A data frame with 288 rows and 7 variables: 9 | \describe{ 10 | \item{\code{element}}{character COLUMN_DESCRIPTION} 11 | \item{\code{isotope}}{character COLUMN_DESCRIPTION} 12 | \item{\code{mass}}{double COLUMN_DESCRIPTION} 13 | \item{\code{abundance}}{double COLUMN_DESCRIPTION} 14 | \item{\code{ratioC}}{double COLUMN_DESCRIPTION} 15 | \item{\code{Mass_Dif}}{double COLUMN_DESCRIPTION} 16 | \item{\code{unsaturation}}{double COLUMN_DESCRIPTION} 17 | } 18 | } 19 | \usage{ 20 | elem_table 21 | } 22 | \description{ 23 | elem_table 24 | } 25 | \details{ 26 | DETAILS 27 | } 28 | \keyword{datasets} 29 | -------------------------------------------------------------------------------- /man/queryFilterDB.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{queryFilterDB} 4 | \alias{queryFilterDB} 5 | \title{queryFilterDB} 6 | \usage{ 7 | queryFilterDB(type, org) 8 | } 9 | \arguments{ 10 | \item{type}{database type} 11 | 12 | \item{org}{organism key} 13 | } 14 | \description{ 15 | queryFilterDB 16 | } 17 | -------------------------------------------------------------------------------- /man/resetNetwork.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NetworkUtils.R 3 | \name{resetNetwork} 4 | \alias{resetNetwork} 5 | \title{Resetting individual omics networks generated from database selection step} 6 | \usage{ 7 | resetNetwork(dataSetObj = NA) 8 | } 9 | \arguments{ 10 | \item{dataSetObj}{Input the name of the created dataSetObj (see Init.Data)} 11 | } 12 | \description{ 13 | Resetting individual omics networks generated from database selection step 14 | } 15 | -------------------------------------------------------------------------------- /src/MSAnnotate.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace Rcpp; 3 | using namespace std; 4 | 5 | // This script is developed to accerate NetID annotation process 6 | // Author: Zhiqiang Pang [zhiqiang.pang@mail.mcgill.ca] 7 | // ref: NetID paper (https://www.nature.com/articles/s41592-021-01303-3) 8 | 9 | int find_int_pos (int num, IntegerVector numVec) { 10 | for (int i = 0; i < numVec.length(); i++) { 11 | if(numVec[i] == num) { 12 | return(i); 13 | } 14 | } 15 | return(-1); 16 | } 17 | 18 | IntegerVector find_int_poss (int num, IntegerVector numVec) { 19 | IntegerVector res; 20 | for (int i = 0; i < numVec.length(); i++) { 21 | if(numVec[i] == num) { 22 | res.push_back(i); 23 | } 24 | } 25 | return(res); 26 | } 27 | 28 | 29 | void coreFUN (int i, 30 | StringVector &res, 31 | IntegerVector &solRes, 32 | IntegerVector &ilpNodeIdVec, 33 | CharacterVector &colNMs, 34 | CharacterVector &rowNMs, 35 | IntegerVector &core_ilpNIdVec, 36 | StringVector &core_annoVec, 37 | NumericMatrix &dis_mat, 38 | List &g_annotation, 39 | Function &f, 40 | IntegerVector &IP_edge_From, 41 | IntegerVector &IP_edge_To, 42 | StringVector &classVec, 43 | StringVector &IP_edge_cat, 44 | StringVector &IP_edge_linktp, 45 | StringVector &IP_edge_fm1, 46 | StringVector &IP_edge_fm2, 47 | IntegerVector &IP_edge_dir, 48 | string igraphmode) { 49 | 50 | int IlpNodeID = ilpNodeIdVec[i]; // this equals query_ilp_id 51 | 52 | if(std::find(colNMs.begin(), colNMs.end(), IlpNodeID) == colNMs.end()) { 53 | res[i] = "not exited in dm"; 54 | return; 55 | } 56 | //std::to_string() 57 | if(std::find(rowNMs.begin(), rowNMs.end(), IlpNodeID) != rowNMs.end()){ 58 | int core_pos = find_int_pos(IlpNodeID, core_ilpNIdVec); 59 | res[i] = core_annoVec[core_pos]; 60 | return; 61 | } 62 | 63 | int tmp_pos = std::find(colNMs.begin(), colNMs.end(), IlpNodeID).index(); 64 | NumericVector v = dis_mat(_, tmp_pos); 65 | double dm_min = min(v); 66 | double inf = std::numeric_limits::infinity(); 67 | 68 | if(dm_min == inf) { 69 | res[i] = "No edge existed!"; 70 | return; 71 | } 72 | int np = which_min(v); 73 | String parent_selected = rowNMs[np]; 74 | 75 | List path_nodes = f(g_annotation, 76 | Named("from", parent_selected), 77 | Named("to", std::to_string(IlpNodeID)), 78 | Named("mode", igraphmode), 79 | Named("output", "vpath")); 80 | List tmp1 = as(path_nodes[0]); 81 | IntegerVector tmp2 = as(tmp1[0]); 82 | StringVector tmp3 = tmp2.names(); 83 | IntegerVector ilp_node_path(tmp3.size()); 84 | for(int j = 0; j < tmp3.size(); j++){ 85 | String tmp4 = tmp3[j]; 86 | ilp_node_path[j] = stoi(tmp4.get_cstring()); 87 | } 88 | 89 | int corePos = find_int_pos(ilp_node_path[0], core_ilpNIdVec); 90 | 91 | String temp_core = core_annoVec[corePos]; 92 | String transform_path; 93 | int dir; 94 | 95 | for(int k =0; k < ilp_node_path.size()-1; k++) { 96 | IntegerVector resFrom = find_int_poss(ilp_node_path[k], IP_edge_From); 97 | IntegerVector resTo = find_int_poss(ilp_node_path[k+1], IP_edge_To); 98 | IntegerVector resposs = intersect(resFrom, resTo); 99 | resposs = resposs.sort(); 100 | 101 | if(resposs.size() > 0) { 102 | dir = IP_edge_dir[resposs[0]]; 103 | } else if(resposs.size() == 0) { 104 | resFrom = find_int_poss(ilp_node_path[k], IP_edge_To); 105 | resTo = find_int_poss(ilp_node_path[k+1], IP_edge_From); 106 | resposs = intersect(resFrom, resTo); 107 | dir = -1; 108 | } 109 | 110 | string temp_sign; 111 | if(classVec[i] == "Artifact") { 112 | if(IP_edge_cat[resposs[0]] == "Oligomer") { 113 | temp_sign = "*"; 114 | } else if (IP_edge_cat[resposs[0]] == "Multicharge") { 115 | temp_sign = "/"; 116 | } else if (IP_edge_cat[resposs[0]] == "Heterodimer") { 117 | temp_sign = "+ Peak"; 118 | } else if (dir == 1) { 119 | temp_sign = "+"; 120 | } else if (dir == -1){ 121 | temp_sign = "-"; 122 | } 123 | } else { 124 | temp_sign = (dir == 1) ? "+" : "-"; 125 | } 126 | 127 | String temp_linktype = IP_edge_linktp[resposs[0]]; 128 | String temp_formula = (dir == 1) ? IP_edge_fm2[resposs[0]] : IP_edge_fm1[resposs[0]]; 129 | 130 | string seperator = " "; 131 | transform_path = 132 | transform_path.get_cstring() + seperator + 133 | temp_sign + seperator + 134 | temp_linktype.get_cstring() + seperator + "-> " + 135 | temp_formula.get_cstring(); 136 | } 137 | string reso = transform_path.get_cstring(); 138 | string resx= temp_core.get_cstring() + reso; 139 | res[i] = resx; 140 | 141 | } 142 | 143 | // [[Rcpp::export]] 144 | StringVector path_annotate(DataFrame ilp_nodes, 145 | DataFrame canu_met, //core_annotation_unique_* 146 | DataFrame ilp_edges_anno_met, //ilp_edges_annotate_* 147 | NumericMatrix dis_mat_met, 148 | List g_annotation, 149 | DataFrame canu_nonmet, //core_annotation_unique_* 150 | DataFrame ilp_edges_anno_nonmet, //ilp_edges_annotate_* 151 | NumericMatrix dis_mat_nonmet, 152 | List g_anno_non) { 153 | 154 | IntegerVector solRes = as(ilp_nodes[27]); 155 | IntegerVector ilpNodeIdVec = as(ilp_nodes[0]); 156 | StringVector classVec = as(ilp_nodes[12]); 157 | StringVector res(solRes.length()); 158 | 159 | // for met 160 | IntegerVector core_ilpNIdVec1 = as(canu_met[0]); 161 | StringVector core_annoVec1 = as(canu_met[2]); 162 | 163 | CharacterVector colNMs1 = colnames(dis_mat_met); 164 | CharacterVector rowNMs1 = rownames(dis_mat_met); 165 | 166 | IntegerVector IP_edge_From1 = as(ilp_edges_anno_met[0]); 167 | IntegerVector IP_edge_To1 = as(ilp_edges_anno_met[1]); 168 | IntegerVector IP_edge_dir1 = as(ilp_edges_anno_met[8]); 169 | StringVector IP_edge_linktp1 = as(ilp_edges_anno_met[7]); 170 | StringVector IP_edge_fm1_1 = as(ilp_edges_anno_met[10]); 171 | StringVector IP_edge_fm2_1 = as(ilp_edges_anno_met[11]); 172 | StringVector IP_edge_cat1 = as(ilp_edges_anno_met[6]); 173 | 174 | // for nonmet 175 | IntegerVector core_ilpNIdVec2 = as(canu_nonmet[0]); 176 | StringVector core_annoVec2 = as(canu_nonmet[2]); 177 | 178 | CharacterVector colNMs2 = colnames(dis_mat_nonmet); 179 | CharacterVector rowNMs2 = rownames(dis_mat_nonmet); 180 | 181 | IntegerVector IP_edge_From2 = as(ilp_edges_anno_nonmet[0]); 182 | IntegerVector IP_edge_To2 = as(ilp_edges_anno_nonmet[1]); 183 | IntegerVector IP_edge_dir2 = as(ilp_edges_anno_nonmet[8]); 184 | StringVector IP_edge_linktp2 = as(ilp_edges_anno_nonmet[7]); 185 | StringVector IP_edge_fm1_2 = as(ilp_edges_anno_nonmet[10]); 186 | StringVector IP_edge_fm2_2 = as(ilp_edges_anno_nonmet[11]); 187 | StringVector IP_edge_cat2 = as(ilp_edges_anno_nonmet[6]); 188 | 189 | // igraph FUN 190 | Environment pkg = Environment::namespace_env("igraph"); 191 | Function f = pkg["shortest_paths"]; 192 | 193 | for(int i = 0; i < solRes.size(); i++) { 194 | if(solRes[i] == 0) {continue;} 195 | if(classVec[i] == "Metabolite" || classVec[i] == "Putative metabolite") { 196 | coreFUN(i, 197 | res, 198 | solRes, 199 | ilpNodeIdVec, 200 | colNMs1, 201 | rowNMs1, 202 | core_ilpNIdVec1, 203 | core_annoVec1, 204 | dis_mat_met, 205 | g_annotation, 206 | f, 207 | IP_edge_From1, 208 | IP_edge_To1, 209 | classVec, 210 | IP_edge_cat1, 211 | IP_edge_linktp1, 212 | IP_edge_fm1_1, 213 | IP_edge_fm2_1, 214 | IP_edge_dir1, 215 | "all"); 216 | } else if (classVec[i] == "Artifact") { 217 | coreFUN(i, 218 | res, 219 | solRes, 220 | ilpNodeIdVec, 221 | colNMs2, 222 | rowNMs2, 223 | core_ilpNIdVec2, 224 | core_annoVec2, 225 | dis_mat_nonmet, 226 | g_anno_non, 227 | f, 228 | IP_edge_From2, 229 | IP_edge_To2, 230 | classVec, 231 | IP_edge_cat2, 232 | IP_edge_linktp2, 233 | IP_edge_fm1_2, 234 | IP_edge_fm2_2, 235 | IP_edge_dir2, 236 | "out"); 237 | } else { 238 | res[i] = "Unknown"; 239 | } 240 | } 241 | 242 | return res; 243 | } 244 | 245 | 246 | // [[Rcpp::export]] 247 | StringVector matchHMDB(DataFrame annotation, 248 | DataFrame Restable, 249 | int peakidx, 250 | int formularidx) { 251 | IntegerVector PeakIDs = as(Restable[peakidx]); 252 | StringVector formulasIDs = as(Restable[formularidx]); 253 | StringVector res(PeakIDs.size()); 254 | IntegerVector NodeIDs = as(annotation[3]); 255 | StringVector formulas = as(annotation[4]); 256 | StringVector HMDBIDs = as(annotation[23]); 257 | for(int i = 0; i < PeakIDs.size(); i++) { 258 | for(int j = 0; j < NodeIDs.size(); j++) { 259 | if(PeakIDs[i] == NodeIDs[j] && formulasIDs[i] == formulas[j]) { 260 | res[i] = HMDBIDs[j]; 261 | break; 262 | } 263 | } 264 | } 265 | return res; 266 | } 267 | 268 | 269 | // [[Rcpp::export]] 270 | StringVector convert2KEGG(StringVector HMDBIDs, DataFrame database) { 271 | StringVector res(HMDBIDs.size()); 272 | StringVector HMDBDBids = as(database[0]); 273 | StringVector KEGGDBids = as(database[9]); 274 | for(int i=0; i< HMDBIDs.size(); i++){ 275 | if(HMDBIDs[i] != "") { 276 | for(int j=0; j < HMDBDBids.size(); j++) { 277 | if(HMDBIDs[i] == HMDBDBids[j]) { 278 | res[i] = KEGGDBids[j]; 279 | break; 280 | } 281 | } 282 | } 283 | } 284 | 285 | return res; 286 | } 287 | -------------------------------------------------------------------------------- /src/MSPeak.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace Rcpp; 5 | using namespace std; 6 | 7 | // This script is developed to accerate NetID analysis workflow 8 | // Author: Zhiqiang Pang [zhiqiang.pang@mail.mcgill.ca] 9 | // ref: NetID paper (https://www.nature.com/articles/s41592-021-01303-3) 10 | 11 | // [[Rcpp::export]] 12 | List initialize_structureset(List NodeSet) { 13 | List res(NodeSet.length()); 14 | for(int i = 0; i< NodeSet.length(); i++) { 15 | List lst = as(NodeSet[i]); 16 | DataFrame df = DataFrame::create(Named("node_id") = i + 1, 17 | _["formula"] = "Unknown", 18 | _["mass"] = lst[0], 19 | _["rdbe"] = 0.0, 20 | _["category"] = "Unknown", 21 | _["parent_id"] = i+1, 22 | _["parent_formula"] = "Unknown", 23 | _["transform"] = "", 24 | _["direction"] = 0, 25 | _["steps"] = 0.0); 26 | res[i] = df; 27 | } 28 | 29 | 30 | return(res); 31 | } 32 | 33 | // [[Rcpp::export]] 34 | List Heterodimer_connection_core(List pgroup, double ppm) { 35 | 36 | List res; 37 | double ppm_tol = ppm/1E6; 38 | 39 | for(int i=0; i < pgroup.length(); i++) { 40 | List temp_e = as(pgroup[i]); 41 | IntegerVector node1Vec = temp_e[0]; 42 | IntegerVector node2Vec = temp_e[1]; 43 | NumericVector tempe = temp_e[2]; 44 | NumericVector tm2 = temp_e[3]; 45 | bool condit0 = 0; 46 | 47 | double mass2 = tm2[0]; 48 | int nnr = tempe.size(); 49 | 50 | IntegerVector dfnode1Vec; 51 | IntegerVector dflinktypeVec; 52 | IntegerVector dfnode2Vec; 53 | std::vector ppmVec; 54 | 55 | for(int r1 =0; r1 < nnr; r1++) { 56 | for(int r2=0; r2 < nnr; r2++) { 57 | double reladiff = fabs(tempe[r1] + tempe[r2] - mass2)/mass2; 58 | if(reladiff < ppm_tol) { 59 | condit0 = 1; 60 | int tnode1 = node1Vec[r2]; 61 | int linktype = node1Vec[r1]; 62 | 63 | int n2 = node2Vec[0]; 64 | 65 | dfnode1Vec.push_back(tnode1); 66 | dflinktypeVec.push_back(linktype); 67 | dfnode2Vec.push_back(n2); 68 | ppmVec.push_back(reladiff); 69 | } 70 | 71 | } 72 | } 73 | 74 | if(condit0) { 75 | DataFrame df = DataFrame::create(Named("node1") = dfnode1Vec, 76 | _["linktype"] = dflinktypeVec, 77 | _["node2"] = dfnode2Vec, 78 | _["mass_dif"] = ppmVec); 79 | res.push_back(df); 80 | } 81 | } 82 | 83 | return(res); 84 | } 85 | 86 | List formula_core (StringVector formulas, int sign) { 87 | 88 | List res; 89 | 90 | for(int i = 0; i < formulas.size(); i++) { 91 | 92 | String fml = formulas[i]; 93 | fml.replace_all("D", "[2]H"); 94 | std::string fmls = fml.get_cstring(); 95 | 96 | int ende2 = fmls.length(); 97 | std::vector element2; 98 | std::vector number2; 99 | int j = 0; 100 | vector NumCharVec = {"-", ".", "0", "1", 101 | "2", "3", "4", "5", 102 | "6", "7", "8", "9"}; 103 | 104 | int b, k, m; 105 | 106 | while (j <= ende2-1) { 107 | 108 | // 1st if condition 109 | if(fmls.substr(j,1) == "[") { 110 | b = j; 111 | 112 | while (fmls.substr(j,1) != "]") { 113 | j++; 114 | } 115 | k = j; 116 | 117 | while (std::find(NumCharVec.begin(), NumCharVec.end(), fmls.substr(j,1)) == NumCharVec.end()) { 118 | j++; 119 | } 120 | m = j -1; 121 | 122 | element2.push_back(fmls.substr(b, m-b+1)); 123 | } 124 | 125 | // 2nd if condition 126 | if(std::find(NumCharVec.begin(), NumCharVec.end(), fmls.substr(j,1)) == NumCharVec.end()) { 127 | k = j; 128 | while (std::find(NumCharVec.begin(), NumCharVec.end(), fmls.substr(j,1)) == NumCharVec.end()) { 129 | j++; 130 | } 131 | 132 | m = j -1; 133 | j--; 134 | element2.push_back(fmls.substr(k, m-k+1)); 135 | } 136 | 137 | // 3rd if condition 138 | if(std::find(NumCharVec.begin(), NumCharVec.end(), fmls.substr(j,1)) != NumCharVec.end()) { 139 | k = j; 140 | 141 | while (std::find(NumCharVec.begin(), NumCharVec.end(), fmls.substr(j,1)) != NumCharVec.end()) { 142 | j++; 143 | } 144 | 145 | m = j -1; 146 | j--; 147 | 148 | string tmpnum = fmls.substr(k, m-k+1); 149 | int thisnum = stoi(tmpnum)*sign; 150 | 151 | number2.push_back(thisnum); 152 | } 153 | j++; 154 | } 155 | 156 | res.push_back(List::create(_["element2"] = element2, 157 | _["number2"] = number2)); 158 | 159 | } 160 | 161 | return(res); 162 | } 163 | 164 | bool is_negative(int element){ 165 | return (element < 0); 166 | } 167 | 168 | IntegerVector eleCount_sort(IntegerVector x, StringVector y) { 169 | IntegerVector idx = seq_along(x) - 1; 170 | std::sort(idx.begin(), idx.end(), [&](int i, int j){ 171 | String ss = y[i]; 172 | string sss = ss.get_cstring(); 173 | 174 | String xx = y[j]; 175 | string xxx = xx.get_cstring(); 176 | bool res = 0; 177 | if(sss.substr(0,1) == "[" && xxx.substr(0,1) != "[") { 178 | res = 1; 179 | return res; 180 | } else if (sss.substr(0,1) != "[" && xxx.substr(0,1) == "[") { 181 | res = 0; 182 | return res; 183 | } 184 | return y[i] < y[j]; 185 | } 186 | ); 187 | return x[idx]; 188 | } 189 | 190 | StringVector element_sort (StringVector y) { 191 | IntegerVector idx = seq_len(y.length()) - 1; 192 | std::sort(idx.begin(), idx.end(), [&](int i, int j){ 193 | String ss = y[i]; 194 | string sss = ss.get_cstring(); 195 | 196 | String xx = y[j]; 197 | string xxx = xx.get_cstring(); 198 | bool res = 0; 199 | if(sss.substr(0,1) == "[" && xxx.substr(0,1) != "[") { 200 | res = 1; 201 | return res; 202 | } else if (sss.substr(0,1) != "[" && xxx.substr(0,1) == "[") { 203 | res = 0; 204 | return res; 205 | } 206 | return y[i] < y[j]; 207 | } 208 | ); 209 | return y[idx]; 210 | } 211 | 212 | // [[Rcpp::export]] 213 | StringVector fast_calculate_formula (StringVector formular1, StringVector transformulas, int sign) { 214 | // This function is designed to speed up "my_calculate_formula" from lc8 215 | 216 | int signNum = sign; 217 | List formulaList1 = formula_core(formular1, sign = 1); 218 | List formulaList2 = formula_core(transformulas, sign = signNum); 219 | 220 | int nrow = formulaList1.length(); 221 | int ncol = formulaList2.length(); 222 | 223 | StringMatrix formula_mat (nrow, ncol); 224 | LogicalMatrix valid_mat (nrow, ncol); 225 | 226 | StringVector res; 227 | 228 | for (int r = 0; r < nrow; r++) { 229 | List lst1 = as(formulaList1[r]); 230 | StringVector elements1 = lst1[0]; 231 | IntegerVector numbers1 = lst1[1]; 232 | 233 | for (int c = 0; c < ncol; c++) { 234 | List lst2 = as(formulaList2[c]); 235 | StringVector elements2 = lst2[0]; 236 | IntegerVector numbers2 = lst2[1]; 237 | 238 | IntegerVector count_all = Rcpp::clone(numbers1);; 239 | StringVector elem_all = Rcpp::clone(elements1); 240 | 241 | int endEleIdx = elem_all.end().index(); 242 | 243 | for(int e =0; e < elements2.size(); e++) { 244 | int matchedElement = std::find(elem_all.begin(), elem_all.end(), elements2[e]).index(); 245 | 246 | if(matchedElement < endEleIdx) { 247 | count_all[matchedElement] = count_all[matchedElement] + numbers2[e]; 248 | } else { 249 | count_all.push_back(numbers2[e]); 250 | elem_all.push_back(elements2[e]); 251 | } 252 | } 253 | 254 | if(std::any_of(count_all.begin(), count_all.end(), is_negative)) { 255 | valid_mat(r,c) = 0; 256 | } 257 | 258 | count_all = eleCount_sort(count_all,elem_all); 259 | elem_all = element_sort(elem_all); 260 | 261 | String realformula; 262 | 263 | for(int cc = 0; cc < count_all.size(); cc++){ 264 | if(count_all[cc] == 0) { 265 | count_all.erase(cc); 266 | elem_all.erase(cc); 267 | cc--; 268 | continue; 269 | } 270 | 271 | int count_s = count_all[cc]; 272 | String ssss = elem_all[cc]; 273 | realformula = realformula.push_back(ssss).push_back(count_s); 274 | } 275 | formula_mat(r,c) = realformula; 276 | } 277 | 278 | //if(formular1.size() == 1 && transformulas.size() == 1) { 279 | // res = formula_mat(1,1); 280 | //} else { 281 | //res = StringVector(formula_mat); 282 | //} 283 | } 284 | 285 | // for(int rr = 0; rr < nrow; rr++) { 286 | // Rcout << "running here subres <-- rr " << rr << "\n"; 287 | // for(int cl = 0; cl < ncol; cl++) { 288 | // Rcout << "running here subres <-- cl " << rr << " | "<< cl << "\n"; 289 | // String subres = formula_mat(rr,cl); 290 | // res.push_back(subres); 291 | // } 292 | // } 293 | res = StringVector(formula_mat); 294 | return(res); 295 | } 296 | 297 | // [[Rcpp::export]] 298 | List propagate_heterodimer_core(DataFrame df_heterodimer, 299 | List sf, 300 | StringVector propagation_category, 301 | NumericVector node_mass, 302 | double ppm_threshold) { 303 | 304 | List res; 305 | 306 | NumericVector parantIDVec = df_heterodimer[5]; 307 | NumericVector trasnformVec = df_heterodimer[7]; 308 | NumericVector node2Vec = df_heterodimer[10]; 309 | NumericVector rdbeVec = df_heterodimer[3]; 310 | NumericVector massVec = df_heterodimer[2]; 311 | 312 | StringVector formulaVec = df_heterodimer[1]; 313 | StringVector parentForVec = df_heterodimer[6]; 314 | 315 | 316 | for(int i = 0; i < trasnformVec.size(); i++) { 317 | // Replace the dyplr part here 318 | DataFrame df = as(sf[trasnformVec[i]-1]); 319 | IntegerVector ndidVec = df[0]; 320 | StringVector formuVec = df[1]; 321 | NumericVector msVec = df[2]; 322 | NumericVector reVec = df[3]; 323 | StringVector catVec = df[4]; 324 | NumericVector stpsVec = df[9]; 325 | 326 | StringVector us = unique(formuVec); 327 | IntegerVector order_row = IntegerVector::create(0); 328 | 329 | IntegerVector parentid_res, transform_res, node2_res; 330 | NumericVector rdbe_res, mass_res; 331 | StringVector parentf_res, formula_res; 332 | 333 | for(int j = 0; j < us.size(); j++) { 334 | for(int r = 0; r < df.nrow(); r ++) { 335 | if(formuVec[r] == us[j]) { 336 | // filter according to steps 337 | bool cond1 = (stpsVec[r] <= 0.01 || (stpsVec[r] >= 1 && stpsVec[r] <= 1.01)); 338 | // filter according to category 339 | bool cond2 = 0; 340 | for(int k = 0; k < propagation_category.size(); k++) { 341 | if(propagation_category[k] == catVec[r]){ 342 | cond2 = 1; 343 | break; 344 | } 345 | } 346 | // filter mass 347 | bool cond3 = fabs(node_mass[ndidVec[r] -1] - msVec[r]) < ppm_threshold*msVec[r]; 348 | 349 | if(cond1 && cond2 && cond3) { 350 | // it r equals transform 351 | // it i equals temp 352 | 353 | order_row.push_back(r); 354 | 355 | parentid_res.push_back(parantIDVec[i]); 356 | transform_res.push_back(trasnformVec[i]); 357 | node2_res.push_back(node2Vec[i]); 358 | parentf_res.push_back(parentForVec[i]); 359 | 360 | mass_res.push_back(massVec[i] + msVec[r]); 361 | rdbe_res.push_back(rdbeVec[i] + reVec[r]); 362 | 363 | formula_res.push_back(formuVec[r]); 364 | break; 365 | } 366 | } 367 | } 368 | } 369 | 370 | if(order_row.size() == 1) { 371 | continue; 372 | } 373 | 374 | // Create list 375 | StringVector tmpStrVec = StringVector::create(""); 376 | tmpStrVec[0] = formulaVec[i]; 377 | formula_res = fast_calculate_formula(tmpStrVec, formula_res, 1); 378 | 379 | res.push_back(List::create(_["parent_id"] = parentid_res, 380 | _["transform"] = transform_res, 381 | _["node2"] = node2_res, 382 | _["parent_formula"] = parentf_res, 383 | _["formula"] = formula_res, 384 | _["rdbe"] = rdbe_res, 385 | _["mass"] = mass_res)); 386 | 387 | } 388 | return(res); 389 | } 390 | 391 | 392 | -------------------------------------------------------------------------------- /src/PCSF.cpp: -------------------------------------------------------------------------------- 1 | 2 | // ************************ Prize-collecting Steiner Forest (PCSF) *********************// 3 | // This is a C++ implementation of our heuristic algorithm for the PCSF (Akhmedov et al 2017). 4 | // The heuristic is developed for functional analyses of large biological networks in a reasonable time. 5 | 6 | 7 | // Loading the required libraries 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | using namespace boost; 37 | using namespace Rcpp; 38 | using namespace std; 39 | 40 | 41 | // Node class 42 | class Node 43 | { public: 44 | vector children; 45 | int father; 46 | int size; 47 | double price; 48 | Node(){}; 49 | Node(const Node & other){ 50 | father=other.father; 51 | children= other.children;} 52 | 53 | Node & operator= (const Node & other){ 54 | father=other.father; 55 | children= other.children; 56 | return *this; 57 | } 58 | 59 | }; 60 | 61 | // Properties of Vertices in the network 62 | struct VertexProperties { 63 | VertexProperties() :c(0) {} 64 | VertexProperties(string const & name) : name(name),c(0){} 65 | string name; 66 | double c; 67 | }; 68 | 69 | // Properties of the graph that is used within the BOOST 70 | typedef adjacency_list > GraphBase; 71 | typedef graph_traits::vertex_iterator vertex_iterator; 72 | typedef graph_traits::out_edge_iterator edge_iterator; 73 | typedef graph_traits::edge_iterator graph_edge_iterator; 74 | typedef graph_traits::edge_descriptor Edge; 75 | typedef graph_traits::vertex_descriptor Vertex; 76 | 77 | 78 | GraphBase g, g_adjusted; GraphBase G; GraphBase G_pruned; 79 | property_map::type weight_g; 80 | property_map::type weight_g_adjusted; 81 | property_map::type weight_G; 82 | property_map::type weight_G_pruned; 83 | 84 | int Root = -1; 85 | static map g_map; 86 | static map G_map; 87 | static map G_pruned_map; 88 | 89 | void clear_variables(){ 90 | g.clear(); 91 | g_adjusted.clear(); 92 | G.clear(); 93 | G_pruned.clear(); 94 | g_map.clear(); 95 | G_map.clear(); 96 | G_pruned_map.clear(); 97 | } 98 | 99 | // Map 100 | int idx_g(String const & id) 101 | { 102 | map::iterator mit = g_map.find(id); 103 | if (mit == g_map.end()) 104 | return g_map[id] = add_vertex(VertexProperties(id), g); 105 | return mit->second; 106 | } 107 | int idx_G(string const & id) 108 | { 109 | map::iterator mit = G_map.find(id); 110 | if (mit == G_map.end()) 111 | return G_map[id] = add_vertex(VertexProperties(id), G); 112 | return mit->second; 113 | } 114 | int idx_G_pruned(string const & id) 115 | { 116 | map::iterator mit = G_pruned_map.find(id); 117 | if (mit == G_pruned_map.end()) 118 | return G_pruned_map[id] = add_vertex(VertexProperties(id), G_pruned); 119 | return mit->second; 120 | } 121 | 122 | 123 | // Reading the input network 124 | void read_input_graph(CharacterVector from, CharacterVector to, NumericVector cost, CharacterVector prize, NumericVector prize_v) 125 | { 126 | for(int i=0; i < from.size(); i++){ 127 | add_edge(vertex(idx_g(from[i]), g), vertex(idx_g(to[i]), g), cost[i], g); 128 | } 129 | for(int i=0; i & predecessor, int & current_node){ 155 | int node=current_node; 156 | for(unsigned int j=0; j & predecessor, int & current_node, Edge &e, bool &found){ 164 | for(unsigned int i=0; i & predecessor, int & current_node, Edge &e, bool &found){ 179 | for(unsigned int i=0; i 0) 186 | predecessor[predecessor[node].father].price = predecessor[predecessor[node].father].price + predecessor[node].price - weight_G_pruned[e]; 187 | } 188 | } 189 | 190 | 191 | 192 | 193 | // After reading the input network information from the input file, the algorithm constructs a 194 | vector< Vertex > constructG(vector & terminals, int &Root){ 195 | 196 | // Distance: all-pairs-shortest-path distance matrix 197 | // perPath: List of arcs in all-pairs-shortest-path distance matrix 198 | vector > > perPath; 199 | vector > Distance; 200 | perPath.resize (terminals.size()); 201 | Distance.resize (terminals.size()); 202 | for (unsigned int i = 0; i < terminals.size(); ++i) { 203 | perPath [i].resize(terminals.size()); 204 | Distance [i].resize(terminals.size()); 205 | } 206 | 207 | // Computing all-pairs-shortest-path distance matrix 208 | Vertex from; int current, pred, outer = 0, inner; 209 | std::vector p = vector (num_vertices(g)); 210 | std::vector d = vector (num_vertices(g)); 211 | 212 | for (std::vector::iterator first=terminals.begin(); first!=terminals.end(); ++first){ 213 | 214 | from = vertex(*first, g_adjusted); 215 | dijkstra_shortest_paths(g_adjusted, from, 216 | predecessor_map(boost::make_iterator_property_map(p.begin(), get(boost::vertex_index, g_adjusted))). 217 | distance_map(boost::make_iterator_property_map(d.begin(), get(boost::vertex_index, g_adjusted)))); 218 | 219 | inner = outer + 1; 220 | for (std::vector::iterator second = first+1; second!=terminals.end(); ++second) { 221 | current=*second; pred=p[current]; 222 | Distance[outer][inner] = d[current]; 223 | Distance[inner][outer] = d[current]; 224 | while(pred!=current){perPath[outer][inner].push_back(current); current=pred; pred=p[current]; } perPath[outer][inner].push_back(current); 225 | inner++; 226 | } 227 | outer++; 228 | } 229 | 230 | 231 | 232 | 233 | // Heuristic Clustering, given large input network, the algorithm clusters input network into 234 | // smaller clusters, and solves the MST afterwards 235 | set V; 236 | set D; 237 | unsigned int root_index = -1; 238 | vector node_labels; 239 | node_labels.resize(terminals.size()); 240 | for(unsigned int i=0; i< node_labels.size(); i++){ 241 | node_labels[i] = 0;} 242 | for(unsigned int i=0; i= Distance[current][targ] && g[terminals[targ]].c >= Distance[current][targ]){ 261 | if(g[terminals[targ]].c > 0){ 262 | D.insert(targ); V.erase(targ); 263 | } 264 | node_labels[targ]=clusterID; 265 | } 266 | } 267 | } 268 | 269 | while(!D.empty()){ 270 | current = *D.begin(); D.erase(current); 271 | for (unsigned int i=0; i < terminals.size(); i++) { 272 | targ = i; 273 | if(node_labels[targ] == 0 && current != targ && i != root_index){ 274 | if(g[terminals[current]].c >= Distance[current][targ] && g[terminals[targ]].c >= Distance[current][targ]){ 275 | if(g[terminals[targ]].c > 0){ D.insert(targ); V.erase(targ);} 276 | node_labels[targ]=clusterID; 277 | } 278 | } 279 | } 280 | } 281 | 282 | } 283 | 284 | // Identfying the vertex membership with respect to clusters 285 | vector > clusters(clusterID+1); 286 | for(unsigned int i=0; i< node_labels.size(); i++){ 287 | for(int j=0; j<=clusterID; j++){ 288 | if(node_labels[i] == j){ 289 | clusters[j].push_back(i); 290 | } 291 | } 292 | } 293 | 294 | std::vector::iterator it, itt; int num_clusters=0; 295 | for(unsigned int i=1; i 1) num_clusters++; 297 | } 298 | 299 | if(num_clusters == 0){ 300 | //cout<<"There is no tree in construct G ()"< threshold_num){ 313 | for (itt=clusters[j].begin(); itt!=clusters[j].end(); ++itt){ 314 | if(min_distance > Distance[*it][*itt] -g[terminals[*it]].c - g[terminals[*itt]].c ){ 315 | min_distance = Distance[*it][*itt] -g[terminals[*it]].c - g[terminals[*itt]].c; min_index = j; 316 | } 317 | } 318 | } 319 | } 320 | 321 | 322 | if (min_index != -1){ 323 | clusters[min_index].push_back(*it); 324 | *it = -1; 325 | } 326 | } 327 | } 328 | 329 | } 330 | 331 | 332 | 333 | // Construct an artificial graph G, which is composed of all clusters determined 334 | // from Heuristic Clustering phase 335 | 336 | string str; unsigned int index1=-1, index2=-1; 337 | 338 | for (unsigned int l = 0; l spanning_tree_G(num_vertices(G)); 372 | prim_minimum_spanning_tree(G, & spanning_tree_G[0]); 373 | 374 | 375 | Edge beg; Vertex sour, tar; double cost; 376 | Edge e; bool found; 377 | 378 | weight_g = get(edge_weight, g); 379 | 380 | vector path; index1=0; index2=0; 381 | edge_iterator out_i, out_end; int add=0; 382 | 383 | // Solving the Minimum Spanning Tree on G 384 | for(unsigned int i = 0; i < spanning_tree_G.size(); ++i ){ 385 | 386 | if(spanning_tree_G[i]!=i ){ 387 | 388 | if(i> spanning_tree_G[i]) path=perPath[spanning_tree_G[i]][i]; 389 | else path=perPath[i][spanning_tree_G[i]]; 390 | 391 | for(unsigned int j=0; jspanning_tree_G_pruned(num_vertices(G_pruned)); 410 | prim_minimum_spanning_tree(G_pruned, &spanning_tree_G_pruned[0]); 411 | 412 | 413 | double total1=0; 414 | for(unsigned int i = 0; i < spanning_tree_G_pruned.size(); ++i ){ 415 | if(spanning_tree_G_pruned[i] != i){ 416 | sour= vertex(i,G_pruned); tar=vertex(spanning_tree_G_pruned[i], G_pruned); 417 | boost::tuples::tie(beg, found) = edge(sour, tar,G_pruned); 418 | total1+=get(weight_G_pruned, beg); 419 | } 420 | } 421 | 422 | 423 | return spanning_tree_G_pruned; 424 | 425 | } 426 | 427 | 428 | // After obtaining MST tree, the algorithm prunes the leaf nodes 429 | // which have prizes smaller than connection cost 430 | double cut(int &Root, vector< Vertex > &spanning_tree_G_pruned, vector< string > &tree_from, vector< string > &tree_to, vector< double > &tree_cost, map < string, double > &tree_terminals){ 431 | 432 | weight_G_pruned = get(edge_weight, G_pruned); 433 | 434 | Edge e; bool found; 435 | 436 | Edge beg; Vertex sour, tar; int ancestor=-1; bool select=false; 437 | 438 | 439 | int root= -1; 440 | if(Root == -1){ 441 | double max=0; 442 | vertex_iterator ei, ef; 443 | for(tie(ei, ef)= vertices(G_pruned); ei!=ef; ei++){ 444 | if(g[boost::lexical_cast(G_pruned[*ei].name)].c > max){ 445 | root = *ei; 446 | max = g[boost::lexical_cast(G_pruned[*ei].name)].c; 447 | } 448 | } 449 | } else {root = idx_G_pruned(to_string(Root));} 450 | 451 | 452 | 453 | select = true; 454 | 455 | bool ancestor_changed=true; unsigned int father, temp; ancestor = root; 456 | if (select){ 457 | father=spanning_tree_G_pruned[ancestor]; 458 | spanning_tree_G_pruned[ancestor]=ancestor; 459 | while(ancestor_changed){ 460 | if(spanning_tree_G_pruned[father]==father){ 461 | ancestor_changed=false; 462 | spanning_tree_G_pruned[father]=ancestor; 463 | }else{ 464 | temp=spanning_tree_G_pruned[father]; 465 | spanning_tree_G_pruned[father]=ancestor; 466 | ancestor=father; father=temp; 467 | } 468 | 469 | } 470 | 471 | }else{ 472 | //cout <<"There is no tree"< predecessor(num_vertices(G_pruned)); 479 | if(select){ 480 | for(unsigned int i = 0; i < spanning_tree_G_pruned.size(); ++i ){ 481 | if(spanning_tree_G_pruned[i]!=i){ 482 | predecessor[i].father=spanning_tree_G_pruned[i]; 483 | predecessor[spanning_tree_G_pruned[i]].children.push_back(i); 484 | }else{predecessor[i].father=i;} 485 | } 486 | } 487 | 488 | 489 | for(unsigned int i = 0; i < predecessor.size(); ++i ){ 490 | predecessor[i].size=predecessor[i].children.size(); 491 | predecessor[i].price=g[boost::lexical_cast(G_pruned[i].name)].c; 492 | 493 | } 494 | 495 | 496 | price_collect(predecessor, root, e, found); 497 | 498 | process_leafs(predecessor, root, e, found); 499 | 500 | weight_g = get(edge_weight, g); 501 | 502 | // Tree 503 | for(unsigned int i = 0; i < predecessor.size(); ++i ){ 504 | if(predecessor[i].father != -1 && predecessor[i].father != (int) i ){ 505 | sour= vertex(boost::lexical_cast(G_pruned[i].name),g); tar = vertex(boost::lexical_cast(G_pruned[predecessor[i].father].name),g); 506 | boost::tuples::tie(beg, found) = edge(sour, tar,g); 507 | tree_from.push_back(g[boost::lexical_cast(G_pruned[i].name)].name); 508 | tree_to.push_back(g[boost::lexical_cast(G_pruned[predecessor[i].father].name)].name); 509 | tree_cost.push_back(weight_g[beg]); 510 | tree_terminals[g[boost::lexical_cast(G_pruned[i].name)].name] = g[boost::lexical_cast(G_pruned[i].name)].c; 511 | tree_terminals[g[boost::lexical_cast(G_pruned[predecessor[i].father].name)].name] = g[boost::lexical_cast(G_pruned[predecessor[i].father].name)].c; 512 | } 513 | } 514 | 515 | 516 | 517 | double total = 0, lostPrice =0; 518 | int uncovered_nodes = 0; 519 | for(unsigned int i = 0; i < predecessor.size(); ++i ){ 520 | if(predecessor[i].father != -1){ 521 | if(predecessor[i].father != (int) i){ 522 | sour= vertex(i,G_pruned); tar = vertex(predecessor[i].father,G_pruned); 523 | boost::tuples::tie(beg, found) = edge(sour, tar,G_pruned); 524 | total+=get(weight_G_pruned, beg); 525 | } 526 | } 527 | } 528 | 529 | 530 | // Lsit of nodes that are outside of final tree 531 | vector calculatecost(num_vertices(g)); 532 | for(unsigned int i = 0; i < predecessor.size(); ++i ){ 533 | if(predecessor[i].father != -1 && predecessor[i].father != (int) i){ 534 | sour= vertex(boost::lexical_cast(G_pruned[i].name),g); tar = vertex(boost::lexical_cast(G_pruned[predecessor[i].father].name),g); 535 | calculatecost[sour]=1; calculatecost[tar]=1; 536 | } 537 | } 538 | 539 | // Uncovered nodes 540 | for(unsigned int i = 0; i < num_vertices(g); ++i ){ 541 | if(calculatecost[i] == 0 && (int) i != root ){ 542 | lostPrice += g[i].c; 543 | uncovered_nodes++; 544 | } 545 | } 546 | 547 | // The list of Nodes in the final Tree 548 | for(unsigned int i = 0; i < num_vertices(g); ++i ){ 549 | if(calculatecost[i] == 1){ 550 | } 551 | } 552 | 553 | // Objective value 554 | return total + lostPrice; 555 | 556 | } 557 | 558 | 559 | //' Internal function \code{call_sr} 560 | //' 561 | //' This function is internally used to solve the PCST. 562 | //' 563 | //' @keywords internal 564 | //' 565 | //' @param from A \code{CharacterVector} that corresponds to \code{head} nodes of the edges. 566 | //' @param to A \code{CharacterVector} that corresponds the \code{tail} nodes of the edges. 567 | //' @param cost A \code{NumericVector} which represents the edge weights. 568 | //' @param node_names A \code{CharacterVector} demonstrates the names of the nodes. 569 | //' @param node_prizes A \code{NumericVector} which corresponds to the node prizes. 570 | //' @author Murodzhon Akhmedov 571 | //' 572 | // [[Rcpp::export]] 573 | List call_sr(CharacterVector from, CharacterVector to, NumericVector cost, CharacterVector node_names, NumericVector node_prizes) 574 | { 575 | clear_variables(); 576 | 577 | vector terminals; 578 | 579 | read_input_graph(from, to, cost, node_names, node_prizes); 580 | 581 | Root = idx_g("DUMMY"); 582 | 583 | double max_price=0; int max_price_index = -1; 584 | for(unsigned int i=0; i max_price){ 586 | max_price = g[i].c; 587 | max_price_index = i; 588 | } 589 | } 590 | 591 | if(Root != -1){ 592 | for(unsigned int i=0; i0){ 594 | terminals.push_back(i); 595 | } 596 | } 597 | }else{ 598 | Root = max_price_index; 599 | for(unsigned int i=0; i0){ 601 | terminals.push_back(i); 602 | } 603 | } 604 | } 605 | 606 | terminals.push_back(Root); 607 | 608 | 609 | if(terminals.size() <=1){ 610 | // There is no tree 611 | //return 0; 612 | } 613 | 614 | 615 | vector< Vertex > spanning_tree; 616 | spanning_tree = constructG(terminals, Root); 617 | 618 | vector< string > tree_from; 619 | vector< string > tree_to; 620 | vector< double > tree_cost; 621 | map < string, double > tree_terminals; 622 | double obj = cut(Root, spanning_tree, tree_from, tree_to, tree_cost, tree_terminals); if (obj == 0) return 0; 623 | 624 | CharacterVector tree_f(tree_from.size()); 625 | CharacterVector tree_t(tree_to.size()); 626 | NumericVector tree_c(tree_cost.size()); 627 | CharacterVector tree_ter(tree_terminals.size()); 628 | NumericVector tree_ter_p(tree_terminals.size()); 629 | 630 | for(unsigned int i=0; i::iterator it=tree_terminals.begin(); it!=tree_terminals.end(); ++it){ 638 | tree_ter[counter] = it->first; 639 | tree_ter_p[counter] = it->second; 640 | counter++; 641 | } 642 | 643 | List tree = List::create(tree_from, tree_to, tree_cost, tree_ter, tree_ter_p); 644 | 645 | 646 | return tree; 647 | } 648 | 649 | 650 | 651 | 652 | 653 | 654 | -------------------------------------------------------------------------------- /src/RcppExports.cpp: -------------------------------------------------------------------------------- 1 | // Generated by using Rcpp::compileAttributes() -> do not edit by hand 2 | // Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 3 | 4 | #include 5 | 6 | using namespace Rcpp; 7 | 8 | #ifdef RCPP_USE_GLOBAL_ROSTREAM 9 | Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); 10 | Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); 11 | #endif 12 | 13 | // path_annotate 14 | StringVector path_annotate(DataFrame ilp_nodes, DataFrame canu_met, DataFrame ilp_edges_anno_met, NumericMatrix dis_mat_met, List g_annotation, DataFrame canu_nonmet, DataFrame ilp_edges_anno_nonmet, NumericMatrix dis_mat_nonmet, List g_anno_non); 15 | RcppExport SEXP _OmicsNetR_path_annotate(SEXP ilp_nodesSEXP, SEXP canu_metSEXP, SEXP ilp_edges_anno_metSEXP, SEXP dis_mat_metSEXP, SEXP g_annotationSEXP, SEXP canu_nonmetSEXP, SEXP ilp_edges_anno_nonmetSEXP, SEXP dis_mat_nonmetSEXP, SEXP g_anno_nonSEXP) { 16 | BEGIN_RCPP 17 | Rcpp::RObject rcpp_result_gen; 18 | Rcpp::RNGScope rcpp_rngScope_gen; 19 | Rcpp::traits::input_parameter< DataFrame >::type ilp_nodes(ilp_nodesSEXP); 20 | Rcpp::traits::input_parameter< DataFrame >::type canu_met(canu_metSEXP); 21 | Rcpp::traits::input_parameter< DataFrame >::type ilp_edges_anno_met(ilp_edges_anno_metSEXP); 22 | Rcpp::traits::input_parameter< NumericMatrix >::type dis_mat_met(dis_mat_metSEXP); 23 | Rcpp::traits::input_parameter< List >::type g_annotation(g_annotationSEXP); 24 | Rcpp::traits::input_parameter< DataFrame >::type canu_nonmet(canu_nonmetSEXP); 25 | Rcpp::traits::input_parameter< DataFrame >::type ilp_edges_anno_nonmet(ilp_edges_anno_nonmetSEXP); 26 | Rcpp::traits::input_parameter< NumericMatrix >::type dis_mat_nonmet(dis_mat_nonmetSEXP); 27 | Rcpp::traits::input_parameter< List >::type g_anno_non(g_anno_nonSEXP); 28 | rcpp_result_gen = Rcpp::wrap(path_annotate(ilp_nodes, canu_met, ilp_edges_anno_met, dis_mat_met, g_annotation, canu_nonmet, ilp_edges_anno_nonmet, dis_mat_nonmet, g_anno_non)); 29 | return rcpp_result_gen; 30 | END_RCPP 31 | } 32 | // matchHMDB 33 | StringVector matchHMDB(DataFrame annotation, DataFrame Restable, int peakidx, int formularidx); 34 | RcppExport SEXP _OmicsNetR_matchHMDB(SEXP annotationSEXP, SEXP RestableSEXP, SEXP peakidxSEXP, SEXP formularidxSEXP) { 35 | BEGIN_RCPP 36 | Rcpp::RObject rcpp_result_gen; 37 | Rcpp::RNGScope rcpp_rngScope_gen; 38 | Rcpp::traits::input_parameter< DataFrame >::type annotation(annotationSEXP); 39 | Rcpp::traits::input_parameter< DataFrame >::type Restable(RestableSEXP); 40 | Rcpp::traits::input_parameter< int >::type peakidx(peakidxSEXP); 41 | Rcpp::traits::input_parameter< int >::type formularidx(formularidxSEXP); 42 | rcpp_result_gen = Rcpp::wrap(matchHMDB(annotation, Restable, peakidx, formularidx)); 43 | return rcpp_result_gen; 44 | END_RCPP 45 | } 46 | // convert2KEGG 47 | StringVector convert2KEGG(StringVector HMDBIDs, DataFrame database); 48 | RcppExport SEXP _OmicsNetR_convert2KEGG(SEXP HMDBIDsSEXP, SEXP databaseSEXP) { 49 | BEGIN_RCPP 50 | Rcpp::RObject rcpp_result_gen; 51 | Rcpp::RNGScope rcpp_rngScope_gen; 52 | Rcpp::traits::input_parameter< StringVector >::type HMDBIDs(HMDBIDsSEXP); 53 | Rcpp::traits::input_parameter< DataFrame >::type database(databaseSEXP); 54 | rcpp_result_gen = Rcpp::wrap(convert2KEGG(HMDBIDs, database)); 55 | return rcpp_result_gen; 56 | END_RCPP 57 | } 58 | // initialize_structureset 59 | List initialize_structureset(List NodeSet); 60 | RcppExport SEXP _OmicsNetR_initialize_structureset(SEXP NodeSetSEXP) { 61 | BEGIN_RCPP 62 | Rcpp::RObject rcpp_result_gen; 63 | Rcpp::RNGScope rcpp_rngScope_gen; 64 | Rcpp::traits::input_parameter< List >::type NodeSet(NodeSetSEXP); 65 | rcpp_result_gen = Rcpp::wrap(initialize_structureset(NodeSet)); 66 | return rcpp_result_gen; 67 | END_RCPP 68 | } 69 | // Heterodimer_connection_core 70 | List Heterodimer_connection_core(List pgroup, double ppm); 71 | RcppExport SEXP _OmicsNetR_Heterodimer_connection_core(SEXP pgroupSEXP, SEXP ppmSEXP) { 72 | BEGIN_RCPP 73 | Rcpp::RObject rcpp_result_gen; 74 | Rcpp::RNGScope rcpp_rngScope_gen; 75 | Rcpp::traits::input_parameter< List >::type pgroup(pgroupSEXP); 76 | Rcpp::traits::input_parameter< double >::type ppm(ppmSEXP); 77 | rcpp_result_gen = Rcpp::wrap(Heterodimer_connection_core(pgroup, ppm)); 78 | return rcpp_result_gen; 79 | END_RCPP 80 | } 81 | // fast_calculate_formula 82 | StringVector fast_calculate_formula(StringVector formular1, StringVector transformulas, int sign); 83 | RcppExport SEXP _OmicsNetR_fast_calculate_formula(SEXP formular1SEXP, SEXP transformulasSEXP, SEXP signSEXP) { 84 | BEGIN_RCPP 85 | Rcpp::RObject rcpp_result_gen; 86 | Rcpp::RNGScope rcpp_rngScope_gen; 87 | Rcpp::traits::input_parameter< StringVector >::type formular1(formular1SEXP); 88 | Rcpp::traits::input_parameter< StringVector >::type transformulas(transformulasSEXP); 89 | Rcpp::traits::input_parameter< int >::type sign(signSEXP); 90 | rcpp_result_gen = Rcpp::wrap(fast_calculate_formula(formular1, transformulas, sign)); 91 | return rcpp_result_gen; 92 | END_RCPP 93 | } 94 | // propagate_heterodimer_core 95 | List propagate_heterodimer_core(DataFrame df_heterodimer, List sf, StringVector propagation_category, NumericVector node_mass, double ppm_threshold); 96 | RcppExport SEXP _OmicsNetR_propagate_heterodimer_core(SEXP df_heterodimerSEXP, SEXP sfSEXP, SEXP propagation_categorySEXP, SEXP node_massSEXP, SEXP ppm_thresholdSEXP) { 97 | BEGIN_RCPP 98 | Rcpp::RObject rcpp_result_gen; 99 | Rcpp::RNGScope rcpp_rngScope_gen; 100 | Rcpp::traits::input_parameter< DataFrame >::type df_heterodimer(df_heterodimerSEXP); 101 | Rcpp::traits::input_parameter< List >::type sf(sfSEXP); 102 | Rcpp::traits::input_parameter< StringVector >::type propagation_category(propagation_categorySEXP); 103 | Rcpp::traits::input_parameter< NumericVector >::type node_mass(node_massSEXP); 104 | Rcpp::traits::input_parameter< double >::type ppm_threshold(ppm_thresholdSEXP); 105 | rcpp_result_gen = Rcpp::wrap(propagate_heterodimer_core(df_heterodimer, sf, propagation_category, node_mass, ppm_threshold)); 106 | return rcpp_result_gen; 107 | END_RCPP 108 | } 109 | // call_sr 110 | List call_sr(CharacterVector from, CharacterVector to, NumericVector cost, CharacterVector node_names, NumericVector node_prizes); 111 | RcppExport SEXP _OmicsNetR_call_sr(SEXP fromSEXP, SEXP toSEXP, SEXP costSEXP, SEXP node_namesSEXP, SEXP node_prizesSEXP) { 112 | BEGIN_RCPP 113 | Rcpp::RObject rcpp_result_gen; 114 | Rcpp::RNGScope rcpp_rngScope_gen; 115 | Rcpp::traits::input_parameter< CharacterVector >::type from(fromSEXP); 116 | Rcpp::traits::input_parameter< CharacterVector >::type to(toSEXP); 117 | Rcpp::traits::input_parameter< NumericVector >::type cost(costSEXP); 118 | Rcpp::traits::input_parameter< CharacterVector >::type node_names(node_namesSEXP); 119 | Rcpp::traits::input_parameter< NumericVector >::type node_prizes(node_prizesSEXP); 120 | rcpp_result_gen = Rcpp::wrap(call_sr(from, to, cost, node_names, node_prizes)); 121 | return rcpp_result_gen; 122 | END_RCPP 123 | } 124 | 125 | static const R_CallMethodDef CallEntries[] = { 126 | {"_OmicsNetR_path_annotate", (DL_FUNC) &_OmicsNetR_path_annotate, 9}, 127 | {"_OmicsNetR_matchHMDB", (DL_FUNC) &_OmicsNetR_matchHMDB, 4}, 128 | {"_OmicsNetR_convert2KEGG", (DL_FUNC) &_OmicsNetR_convert2KEGG, 2}, 129 | {"_OmicsNetR_initialize_structureset", (DL_FUNC) &_OmicsNetR_initialize_structureset, 1}, 130 | {"_OmicsNetR_Heterodimer_connection_core", (DL_FUNC) &_OmicsNetR_Heterodimer_connection_core, 2}, 131 | {"_OmicsNetR_fast_calculate_formula", (DL_FUNC) &_OmicsNetR_fast_calculate_formula, 3}, 132 | {"_OmicsNetR_propagate_heterodimer_core", (DL_FUNC) &_OmicsNetR_propagate_heterodimer_core, 5}, 133 | {"_OmicsNetR_call_sr", (DL_FUNC) &_OmicsNetR_call_sr, 5}, 134 | {NULL, NULL, 0} 135 | }; 136 | 137 | RcppExport void R_init_OmicsNetR(DllInfo *dll) { 138 | R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); 139 | R_useDynamicSymbols(dll, FALSE); 140 | } 141 | --------------------------------------------------------------------------------