plot_igraph: Plotting functions for Gene Regulatory Network.

View source: R/plot_functions.R

plot_igraphR Documentation

Plotting functions for Gene Regulatory Network.

Description

Collection of functions for generating graphs layouts to plot GRN obtained from NET_run() method. return_layout() generates a layout from the graph object returned by NET_run() and return_layout_phenotype() plots targets according to the t-statistic from the differential expression analysis of the desired phenotype. plot_igraph() takes in the igraph object and generated layout and generates plot.

Usage

plot_igraph(
  mygraph = NULL,
  mytitle = "",
  titlecol = "black",
  mylayout = NULL,
  includelegend = FALSE
)

return_layout(regs = NULL, targets = NULL, namehash = NULL)

return_layout_phenotype(
  regs = NULL,
  targets = NULL,
  varfile = NULL,
  namehash = NULL
)

orderGraphWeights(graph, edgelist)

heatmapplot(
  heatm,
  plotname = "",
  myzlim = c(min(heatm), max(heatm)),
  cvec = c("red", "white", "blue"),
  showRows = TRUE
)

plot_expression_row(
  mymat = NULL,
  rowdesc = "Regulators",
  plotheight = 200,
  myshowrows = TRUE,
  samps2pheno = NULL,
  phenostrs = c("nonrespond", "responder"),
  htmlfile = "./",
  imgdir = "imgs/",
  modnum = 1,
  plotwidth = 800,
  mycvec = c("darkorange", "gray100", "darkblue"),
  plotzlim = c(-10, 10)
)

plot_correlation_row(
  cormats = NULL,
  rowdesc = "regulators",
  xnames = NULL,
  ynames = NULL,
  plotheight = 200,
  myshowrows = TRUE,
  htmlfile = "./",
  imgdir = "imgs/",
  modnum = 1,
  plotwidth = 200,
  mycvec = c("darkred", "gray100", "darkgreen"),
  plotzlim = c(-1, 1),
  plottitle = NULL
)

plot_gene_pair_scatter(
  pname,
  myx,
  myy,
  xgenename,
  ygenename,
  mylabels,
  alltext = NULL,
  plotdir = ""
)

plot_gene_pair_scatter_by_class(
  plotdir,
  pname,
  myx,
  myy,
  xgenename,
  ygenename,
  mylabels,
  lab1text,
  lab2text,
  alltext
)

Arguments

mygraph

igraph object returned from NET_run().

mytitle

Desired tittle.

titlecol

Color for the tittle.

mylayout

desired layout.

includelegend

whether to include legend, boolean. (Default: FALSE)

regs

regulators name list

targets

targets name list

namehash

list containing the drivers genes as names and transcripts as values. If only genes are required, leave it empty.

varfile

two column file containing, gene names as rows, t-statistic from the differential expression analysis of the desired phenotype column and a boolean variable for regulator (1) - no regulator (0) column.

graph

igraph object

edgelist

list containing the edges of the igraph object.

heatm

input matrix for plot.

plotname

name of the plot.

myzlim

the range of z values for which colors should be plotted.

cvec

vector of colors for the palette of the plot.

showRows

boolean specifying the option of showing row names.

mymat

input matrix for plot.

rowdesc

name uses to specify regulator.

plotheight

height of the plot.

myshowrows

boolean specifying the option of showing row names.

samps2pheno

matrix of sample to phenotype.

phenostrs

strings uses distinguish for phenotypes.

htmlfile

directory to html files.

imgdir

directory for image.

modnum

the number of supermodule.

plotwidth

width of the plot.

mycvec

vector of colors for the palette of the plot.

plotzlim

the range of z values for which colors should be plotted.

cormats

input correlation matrix for plot.

xnames

names for the x axis.

ynames

names for the x axis.

plottitle

the title of the plot.

pname

name for the plot.

myx

the coordinates of points of the first gene.

myy

the coordinates of points of the second gene.

xgenename

the names of the first gene.

ygenename

the names of the second gene.

mylabels

integer class labels.

alltext

text label for the plot.

plotdir

directory for the plot.

lab1text

text label of a class.

lab2text

text label of the other class.

Value

plot of the desired single GRN using a specific layout.

Examples


   ## Assume we have run the rewiring method and the `NET_run()` method to generate the
   ## igraph object. We are going to generate and plot both layouts for the example.
   ## We are going to generate all the files we need except for the igraph object, which
   ## is included as an example file in this package.

   ## We load the igraph object that we generated from the `NET_run()` example.
   ## Note: the igraph object is inside the list `NET_run()` generates.

   graph <- readRDS(paste0(system.file('extdata',package='TraRe'),
                    '/graph_netrun_example.rds'))$graphs$VBSR

   ## We first generate the normal layout for the plot.
   ## We need the drivers and target names.

   drivers <- readRDS(paste0(system.file('extdata',package='TraRe'),'/tfs_linker_example.rds'))
   drivers_n <- rownames(drivers)

   targets <- readRDS(paste0(system.file('extdata',package='TraRe'),'/targets_linker_example.rds'))
   targets_n <- rownames(targets)

   ## As for this example we are working at gene level (we dont have transcripts inside genes),
   ## we will generate a dictionary with genes as keys and values (see param `namehash`)

   normal_layout <- return_layout(drivers_n,targets_n)

   ## We now generate the phenotype layout and the `varfile` we ned for this layout.
   ## (I leave here a way to generate) We need to separate our expression matrix by
   ## a binary phenotype, for this case, i will consider the first 40 samples are
   ## responding to a treatment (R) and the rest not (NR).

   gnames <- c(drivers_n,targets_n)
   expmat <-rbind(drivers,targets)

   phenotype <- utils::read.delim(paste0(system.file('extdata',package='TraRe'),
                                  '/phenotype_rewiring_example.txt'))

   expmat_R <- expmat[,phenotype$Class=='R']
   expmat_NR <- expmat[,phenotype$Class=='NR']


   varfile <- t(as.matrix(sapply(gnames,
              function(x) c(stats::t.test(expmat_R[x,],expmat_NR[x,])$statistic,
              if(x%in%drivers_n) 1 else 0))))

   colnames(varfile)<-c('t-stat','is-regulator')

   phenotype_layout <- return_layout_phenotype(drivers_n,targets_n,varfile)

   plot_igraph(graph,mytitle='Normal Layout',titlecol='black',mylayout=normal_layout)
   plot_igraph(graph,mytitle='Phenotype Layout',titlecol='black',mylayout=phenotype_layout)


ubioinformat/TraRe documentation built on March 10, 2024, 1:11 a.m.