# Using the circlizePlus Package

## Addition rules

ccPlot(contain n ccPars)+ccPar=ccPlot(contain n+1 ccPars),n>=0

ccPlot(contain n ccTracks)+ccTrack=ccPlot(contain n+1 ccTracks),n>=0

ccPlot(contain n ccLinks)+ccLink=ccPlot(contain n+1 ccLinks),n>=0

ccTrak(contain n ccTrakGeoms)+ccTrackGeom=ccTrack(contain n+1 ccTrackGeoms),n>=0

ccTrack(contain n ccCells)+ccCell=ccTrack(contain n+1 ccCells),n>=0

ccCell(contain n ccCellGeoms)+ccCellGeom=ccCell(contain n+1 ccCellGeoms),n>=0

## S4 class ccCell and ccCells

- ccCell: Generate a cell container that belongs to a particular sector.
- ccCells: A list of multiple `ccCell`. Any `ccCellGeom` and `ccCells` are added together as if they were added to each `ccCell` contained in the `ccCells`.

## API outline

### Initializer

- Class: ccPlot-class
- Function: ccPlot()

### Parameter

- Class: ccPar-class
- Function: ccPar()

### Cell container

- Class: ccCell-class, ccCells-class
- Function: ccCell(), ccCells()

### Cell geometry

- Class: ccCellGeom-class, ccGenomicCellGeom-class
- Function: ccText(), ccPoints(), ccLines(), ccSegments(), ccRect(), ccPolygon(), ccXaxis(), ccYaxis(), ccBarplot(), ccBoxplot(), ccViolin(), ccArrow(), ccRaster(), ccDendrogram(), ccGenomicPoints(), ccGenomicLines(), ccGenomicRect(), ccGenomicText(), ccGenomicAxis()

### Track container

- Class: ccTrack-class, ccGenomicTrack-class
- Function: ccTrack(), ccTrackHist(), ccGenomicTrack(), ccGenomicIdeogram(), ccGenomicHeatmap(), ccGenomicLabels(), ccGenomicRainfall(), ccGenomicDensity()

### Track geometry

- Class: ccTrackGeom-class
- Function: ccTrackLines(), ccTrackPoints(), ccTrackText()

### Link

- Class: ccLink-class, ccHeatmapLink-class, ccGenomicLink-class
- Function: ccLink(), ccHeatmapLink(), ccGenomicLink()

### Heatmap

- Class: ccHeatmap-class
- Function: ccHeatmap()

## Data mapping from track to cell geometry

ccTrack Constructor | ccGenomicTrack() | ccGenomicTrack() | ccGenomicTrack() | ccGenomicTrack() | ccTrack() | ccTrack() | ccTrack() | ccTrack() | ccTrack() | ccTrack()
Parameters in ccTrack Constructor | data | data | data | data | x, y | x, y | x, y | x, y | x, y | x, y
ccCellGeom Constructor | ccGenomicPoints() | ccGenomicLines() | ccGenomicRect() | ccGenomicText() | ccLines() | ccPoints() | ccPolygon() | ccText() | ccRect() | ccSegments()
Parameters in ccCellGeom Constructor | region, value | region, value | region, value | region, value | x, y | x, y | x, y | x, y | xleft, ybottom, xright, ytop | x0, y0, x1, y1

A combination of each column in the table above:

### Get track from ccGenomicTrack()

`region` and `value` in ccGenomicCellGeom constructor can be `NULL` or function like `function(region,value){...}`. The above data can be obtained from the `data` parameter of `ccGenomicTrack`.

In the following example code, the `region` and `value` in the `ccGenomicLines` constructor are `NULL`. Their real data comes from the `data` value of the corresponding sector in `ccGenomicTrack`. The `region` and `value` in the `ccGenomicPoints` constructor are `function`. Their real data is calculated based on the definition of the function.

    data = generateRandomBed(nr =30, nc = 2)
    all_chr = c("chr1","chr2","chr3","chr4","chr5","chr6","chr7","chr8","chr9","chr10","chr11","chr12","chr13","chr14","chr15","chr16","chr17","chr18","chr19","chr20","chr21","chr22","chrX","chrY")
    cc = ccPlot(initMode = "initializeWithIdeogram", plotType=NULL)
    t1 = ccGenomicTrack(data=data, numeric.column = 4,
                        panel.fun=function(region,value,...){
                          circos.genomicPoints(region,value,...)
                        })
    cells1 = ccCells(sector.indexes = all_chr) + ccGenomicLines(numeric.column=2) + ccGenomicPoints(region=\(region,value){region}, value=\(region,value){value}, numeric.column=2)
    t1 = t1 + cells1
    show(cc+t1)

### Get track from ccTrack()

`x`, `x0`, `x1`, `xleft`, `xright`, `y`, `y0`, `y1`, `ytop`, `ybottom` in ccCellGeom constructor can be `NULL` or function like `function(x,y){...}`. The above data can be obtained from the `x` and `y` parameter of `ccTrack`.

In the following example code, the `x` and `y` in the first `ccPoints` constructor are `NULL`. Their real data comes from the `x` and `y` of the corresponding sector in `ccTrack`. The `y` in the second `ccPoints` constructor are `function`. Their real data is calculated based on the definition of the function.

    sectors = c('a','a','a','a','b','b','b','b','c','c','c','c','d','d','d','d')
    x1 = c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
    y1 = c(1,2,3,4,4,3,2,1,1,1,1,1,1,2,1,2)
    cc = ccPlot(initMode = "initialize", sectors = sectors, x = x1)
    cells = ccCells(sector.indexes = letters[1:4])
    cc_point = ccPoints()
    cells = cells + cc_point + ccLines()
    track1 = ccTrack(sectors = sectors, x=x1, y = y1,panel.fun = function(x,y){
      circos.points(y,x)
    })
    cell_single = ccCell(sector.index = letters[3]) + ccPoints(y=\(x,y){x-y})
    track1 = track1 + cells + cell_single
    show(cc  + track1)