Browse code

add searcherable infomation.

JIANHONG OU authored on 02/12/2021 21:48:03
Showing 10 changed files

... ...
@@ -44,4 +44,4 @@ Lazyload: yes
44 44
 LazyData: true
45 45
 biocViews: Sequencing, Microarray, GraphAndNetwork
46 46
 VignetteBuilder: knitr
47
-RoxygenNote: 7.1.1
47
+RoxygenNote: 7.1.2
48 48
new file mode 100644
... ...
@@ -0,0 +1,7 @@
1
+# Generated by using Rcpp::compileAttributes() -> do not edit by hand
2
+# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3
+
4
+filterNodes <- function(xx_from, xx_to, xx_miRNA, xx_logFC, xx_pval, xx_dir, rows, rootgene, rootlogFC, tol, minify, miRNAtol, lFC, pVAL) {
5
+    .Call('_GeneNetworkBuilder_filterNodes', PACKAGE = 'GeneNetworkBuilder', xx_from, xx_to, xx_miRNA, xx_logFC, xx_pval, xx_dir, rows, rootgene, rootlogFC, tol, minify, miRNAtol, lFC, pVAL)
6
+}
7
+
... ...
@@ -256,7 +256,8 @@ filterNetwork<-function(rootgene, sifNetwork, exprsData, mergeBy="symbols", miRN
256 256
 #'                         If TURE, use logFC value as weight.
257 257
 #'                         If FALSE, use constant 1 as weight.
258 258
 #' @param nodecolor a character vector of color set. 
259
-#'                  The node color will be mapped to color set by log fold change
259
+#'                  The node color will be mapped to color set by log fold change.
260
+#'                  Or the column names for the colors.
260 261
 #' @param nodeBg background of node
261 262
 #' @param nodeBorderColor a list of broder node color set. 
262 263
 #'                        nodeBorderColor's element must be gene and miRNA
... ...
@@ -294,8 +295,13 @@ polishNetwork<-function(cifNetwork,
294 295
   if(length(intersect(c("from", "to", "logFC", "miRNA"), colnames(cifNetwork)))<4){
295 296
     stop("colnames of cifNetwork must contain 'from', 'to', 'logFC' and 'miRNA'");
296 297
   }
298
+  preDefinedColor <- FALSE
297 299
   if(length(nodecolor) < 2){
298
-    stop("nodecolor should have more than 1 elements")
300
+    if(nodecolor %in% colnames(cifNetwork)){
301
+      preDefinedColor <- TRUE
302
+    }else{
303
+      stop("nodecolor should have more than 1 elements")
304
+    }
299 305
   }
300 306
   if(length(setdiff(c('gene', 'miRNA'), names(nodeBorderColor))) > 0){
301 307
     stop("nodeBorderColor's element must be 'gene' and 'miRNA'")
... ...
@@ -337,35 +343,67 @@ polishNetwork<-function(cifNetwork,
337 343
   for(i in unique(as.character(cifNetwork$from))){
338 344
     nodeData(gR, n=i, attr="size")<-ceiling(5*length(edL[[i]]$edges)/length(node)) * nodesDefaultSize/2 + nodesDefaultSize
339 345
   }
346
+  ## add additional message 
347
+  additionalInfoCol <- colnames(cifNetwork)
348
+  additionalInfoCol <-
349
+    additionalInfoCol[!additionalInfoCol %in%
350
+                        c("to", "from", "gene", "P.Value", "logFC", "miRNA",
351
+                          "dir")]
352
+  additionalInfoCol <- additionalInfoCol[
353
+    vapply(additionalInfoCol, FUN=function(.e){
354
+      inherits(cifNetwork[, .e], c("character", "factor")) &&
355
+        length(unique(cifNetwork[, .e])) > 1
356
+    }, FUN.VALUE=FALSE)
357
+  ]
358
+  if(length(additionalInfoCol)){
359
+    for(j in additionalInfoCol){
360
+      nodeDataDefaults(gR, attr=j)<-""
361
+      for(i in unique(as.character(cifNetwork$from))){
362
+        nodeData(gR, n=i, attr=j) <-
363
+          cifNetwork[match(i, cifNetwork$to), j]
364
+      }
365
+    }
366
+  }
340 367
   ## set node color    
341 368
   nodeDataDefaults(gR, attr="fill")<-nodeBg
342
-  lfcMax<-ceiling(max(abs(cifNetwork[!is.na(cifNetwork$logFC),"logFC"])))
343
-  lfcSeq<-seq(-1*lfcMax,lfcMax,length.out=length(nodecolor)+1)
344
-  colset<-unique(cifNetwork[!is.na(cifNetwork$logFC),c("to","logFC")])
345
-  colset<-apply(colset, 1, function(.ele,color,lfcSeq){
346
-    id=0
347
-    for(i in 1:length(lfcSeq)){
348
-      .elelfc<-as.numeric(as.character(.ele[2]))
349
-      if(lfcSeq[i]<=.elelfc & lfcSeq[i+1]>=.elelfc){
350
-        id=i
351
-        break
369
+  if(!preDefinedColor){
370
+    lfcMax<-ceiling(max(abs(cifNetwork[!is.na(cifNetwork$logFC),"logFC"])))
371
+    lfcSeq<-seq(-1*lfcMax,lfcMax,length.out=length(nodecolor)+1)
372
+    colset<-unique(cifNetwork[!is.na(cifNetwork$logFC),c("to","logFC")])
373
+    colset<-apply(colset, 1, function(.ele,color,lfcSeq){
374
+      id=0
375
+      for(i in 1:length(lfcSeq)){
376
+        .elelfc<-as.numeric(as.character(.ele[2]))
377
+        if(lfcSeq[i]<=.elelfc & lfcSeq[i+1]>=.elelfc){
378
+          id=i
379
+          break
380
+        }
381
+      }
382
+      if(id!=0){
383
+        c(.ele,nodecolor[id])
384
+      }else{
385
+        c(.ele,nodeBg)
352 386
       }
387
+    },nodecolor,lfcSeq)
388
+    colors<-colset[3,]
389
+    names(colors)<-colset[1,]
390
+    for(i in names(colors)){
391
+      nodeData(gR, n=i, attr="fill")<-colors[i]
353 392
     }
354
-    if(id!=0){
355
-      c(.ele,nodecolor[id])
356
-    }else{
357
-      c(.ele,nodeBg)
393
+    colset<-node[!node %in% names(colors)]
394
+    names(colset)<-colset
395
+    colset<-nodeBg
396
+    colors<-c(colors,colset)
397
+  }else{
398
+    colors <- cifNetwork[match(node, cifNetwork$to), nodecolor]
399
+    names(colors) <- node
400
+    colors[is.na(colors)] <- nodeBg
401
+    for(i in node) {
402
+      tmp <- cifNetwork[match(i, cifNetwork$to), nodecolor]
403
+      nodeData(gR, n=i, attr="fill") <- 
404
+        ifelse(is.na(tmp), nodeBg, tmp)
358 405
     }
359
-  },nodecolor,lfcSeq)
360
-  colors<-colset[3,]
361
-  names(colors)<-colset[1,]
362
-  for(i in names(colors)){
363
-    nodeData(gR, n=i, attr="fill")<-colors[i]
364 406
   }
365
-  colset<-node[!node %in% names(colors)]
366
-  names(colset)<-colset
367
-  colset<-nodeBg
368
-  colors<-c(colors,colset)
369 407
   ## set node border color    
370 408
   miRNAs<-unique(as.character(cifNetwork[cifNetwork[,"miRNA"],"to"]))
371 409
   nodeBC<-character(length(node))
... ...
@@ -379,6 +417,7 @@ polishNetwork<-function(cifNetwork,
379 417
       nodeBC[i]<-nodeBorderColor$gene
380 418
     }
381 419
   }
420
+  
382 421
   graph::nodeRenderInfo(gR) <- list(col=nodeBC, fill=colors, ...)
383 422
   graph::edgeRenderInfo(gR) <- list(lwd=edgelwd)
384 423
   gR
... ...
@@ -26,7 +26,8 @@ If TURE, use logFC value as weight.
26 26
 If FALSE, use constant 1 as weight.}
27 27
 
28 28
 \item{nodecolor}{a character vector of color set. 
29
-The node color will be mapped to color set by log fold change}
29
+The node color will be mapped to color set by log fold change.
30
+Or the column names for the colors.}
30 31
 
31 32
 \item{nodeBg}{background of node}
32 33
 
... ...
@@ -1,2 +1,6 @@
1 1
 ## Use the R HOME indirection to support installations of multiple R version
2
-PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
3 2
\ No newline at end of file
3
+PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
4
+
5
+all: $(SHLIB)
6
+
7
+clean: rm -f $(PKG_OBJECTS)
4 8
\ No newline at end of file
... ...
@@ -1,2 +1,6 @@
1 1
 ## Use the R HOME indirection to support installations of multiple R version
2
-PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()")
3 2
\ No newline at end of file
3
+PKG_LIBS = $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "Rcpp:::LdFlags()")
4
+
5
+all: $(SHLIB)
6
+
7
+clean: rm -f $(PKG_OBJECTS)
4 8
\ No newline at end of file
5 9
new file mode 100644
... ...
@@ -0,0 +1,49 @@
1
+// Generated by using Rcpp::compileAttributes() -> do not edit by hand
2
+// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
3
+
4
+#include <Rcpp.h>
5
+
6
+using namespace Rcpp;
7
+
8
+#ifdef RCPP_USE_GLOBAL_ROSTREAM
9
+Rcpp::Rostream<true>&  Rcpp::Rcout = Rcpp::Rcpp_cout_get();
10
+Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
11
+#endif
12
+
13
+// filterNodes
14
+RcppExport SEXP filterNodes(SEXP xx_from, SEXP xx_to, SEXP xx_miRNA, SEXP xx_logFC, SEXP xx_pval, SEXP xx_dir, SEXP rows, SEXP rootgene, SEXP rootlogFC, SEXP tol, SEXP minify, SEXP miRNAtol, SEXP lFC, SEXP pVAL);
15
+RcppExport SEXP _GeneNetworkBuilder_filterNodes(SEXP xx_fromSEXP, SEXP xx_toSEXP, SEXP xx_miRNASEXP, SEXP xx_logFCSEXP, SEXP xx_pvalSEXP, SEXP xx_dirSEXP, SEXP rowsSEXP, SEXP rootgeneSEXP, SEXP rootlogFCSEXP, SEXP tolSEXP, SEXP minifySEXP, SEXP miRNAtolSEXP, SEXP lFCSEXP, SEXP pVALSEXP) {
16
+BEGIN_RCPP
17
+    Rcpp::RObject rcpp_result_gen;
18
+    Rcpp::RNGScope rcpp_rngScope_gen;
19
+    Rcpp::traits::input_parameter< SEXP >::type xx_from(xx_fromSEXP);
20
+    Rcpp::traits::input_parameter< SEXP >::type xx_to(xx_toSEXP);
21
+    Rcpp::traits::input_parameter< SEXP >::type xx_miRNA(xx_miRNASEXP);
22
+    Rcpp::traits::input_parameter< SEXP >::type xx_logFC(xx_logFCSEXP);
23
+    Rcpp::traits::input_parameter< SEXP >::type xx_pval(xx_pvalSEXP);
24
+    Rcpp::traits::input_parameter< SEXP >::type xx_dir(xx_dirSEXP);
25
+    Rcpp::traits::input_parameter< SEXP >::type rows(rowsSEXP);
26
+    Rcpp::traits::input_parameter< SEXP >::type rootgene(rootgeneSEXP);
27
+    Rcpp::traits::input_parameter< SEXP >::type rootlogFC(rootlogFCSEXP);
28
+    Rcpp::traits::input_parameter< SEXP >::type tol(tolSEXP);
29
+    Rcpp::traits::input_parameter< SEXP >::type minify(minifySEXP);
30
+    Rcpp::traits::input_parameter< SEXP >::type miRNAtol(miRNAtolSEXP);
31
+    Rcpp::traits::input_parameter< SEXP >::type lFC(lFCSEXP);
32
+    Rcpp::traits::input_parameter< SEXP >::type pVAL(pVALSEXP);
33
+    rcpp_result_gen = Rcpp::wrap(filterNodes(xx_from, xx_to, xx_miRNA, xx_logFC, xx_pval, xx_dir, rows, rootgene, rootlogFC, tol, minify, miRNAtol, lFC, pVAL));
34
+    return rcpp_result_gen;
35
+END_RCPP
36
+}
37
+
38
+RcppExport SEXP filterNodes(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
39
+
40
+static const R_CallMethodDef CallEntries[] = {
41
+    {"_GeneNetworkBuilder_filterNodes", (DL_FUNC) &_GeneNetworkBuilder_filterNodes, 14},
42
+    {"filterNodes", (DL_FUNC) &filterNodes, 14},
43
+    {NULL, NULL, 0}
44
+};
45
+
46
+RcppExport void R_init_GeneNetworkBuilder(DllInfo *dll) {
47
+    R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
48
+    R_useDynamicSymbols(dll, FALSE);
49
+}
... ...
@@ -6,7 +6,7 @@
6 6
 
7 7
 using namespace Rcpp;
8 8
 using namespace std;
9
-
9
+// [[Rcpp::export]]
10 10
 RcppExport SEXP filterNodes(SEXP xx_from, SEXP xx_to, SEXP xx_miRNA, SEXP xx_logFC, SEXP xx_pval, SEXP xx_dir, SEXP rows, 
11 11
 							SEXP rootgene, SEXP rootlogFC, SEXP tol, SEXP minify, SEXP miRNAtol, SEXP lFC, SEXP pVAL)
12 12
 {
13 13
deleted file mode 100644
... ...
@@ -1,10 +0,0 @@
1
-// RegisteringDynamic Symbols
2
-
3
-#include <R.h>
4
-#include <Rinternals.h>
5
-#include <R_ext/Rdynload.h>
6
-
7
-void R_init_markovchain(DllInfo* info) {
8
-  R_registerRoutines(info, NULL, NULL, NULL, NULL);
9
-  R_useDynamicSymbols(info, TRUE);
10
-}
11 0
\ No newline at end of file
... ...
@@ -49,9 +49,20 @@ try({ ## just in case STRINGdb not work
49 49
     IDsMap <- expressionData$gene
50 50
     names(IDsMap) <- expressionData$symbols
51 51
     cifNetwork <- convertID(cifNetwork, IDsMap)
52
+    ## add additional info for searching, any character content columns
53
+    cifNetwork$info1 <- sample(c("groupA", "groupB"),
54
+                               size = nrow(cifNetwork),
55
+                               replace = TRUE)
52 56
     ## polish network
53 57
     gR<-polishNetwork(cifNetwork)
54 58
     ## browse network
55 59
     browseNetwork(gR)
60
+    
61
+    ## try predifined colors
62
+    cifNetwork$color <- sample(rainbow(7), nrow(cifNetwork), replace = TRUE)
63
+    ## polish network
64
+    gR<-polishNetwork(cifNetwork, nodecolor="color")
65
+    ## browse network
66
+    browseNetwork(gR)
56 67
 })
57 68
 ```