Skip to content

Commit

Permalink
remove gene biotype
Browse files Browse the repository at this point in the history
  • Loading branch information
junjunlab committed Jul 14, 2022
1 parent 7c5e7c0 commit a4575ff
Show file tree
Hide file tree
Showing 3 changed files with 365 additions and 3 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^transPlotR\.Rproj$
^\.Rproj\.user$
^LICENSE\.md$
^test-code\.R$
7 changes: 4 additions & 3 deletions R/trancriptVis.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
#' cowplot::plot_grid(p1,p2,ncol = 2,align = 'hv')

# global variables
globalVariables(c('end', 'gene_biotype', 'gene_id', 'gene_name','seqnames',
globalVariables(c('end', 'gene_id', 'gene_name','seqnames',
'start', 'strand','transcript_id','transcript_name', 'type', 'vl_x1' ,'width', 'yPos'))

# use_package("tidyverse", type = "depends")
Expand Down Expand Up @@ -191,18 +191,19 @@ trancriptVis <- function(gtfFile = NULL,
revNegStrand = FALSE){
##############################################################################
# test whether with a given specific gene or region

if(is.null(gene)){
# filter gene by region
myGene <- gtfFile %>%
dplyr::filter(seqnames == Chr & start >= posStart & end <= posEnd) %>%
dplyr::filter(type != 'gene') %>%
dplyr::select(seqnames,start,end,width,strand,type,gene_id,gene_name,gene_biotype,transcript_id,transcript_name)
dplyr::select(seqnames,start,end,width,strand,type,gene_id,gene_name,transcript_id,transcript_name)
}else{
# filter gene by gene name
myGene <- gtfFile %>%
dplyr::filter(gene_name %in% gene) %>%
dplyr::filter(type != 'gene') %>%
dplyr::select(seqnames,start,end,width,strand,type,gene_id,gene_name,gene_biotype,transcript_id,transcript_name)
dplyr::select(seqnames,start,end,width,strand,type,gene_id,gene_name,transcript_id,transcript_name)
}

##############################################################################
Expand Down
360 changes: 360 additions & 0 deletions test-code.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
# # library(transPlotR)
# # data(gtf)
# #
# # # non-coding gene
# # trancriptVis(gtfFile = gtf,
# # gene = 'Xist')
# #
# # # coding gene
# # trancriptVis(gtfFile = gtf,
# # gene = 'Nanog')
# #
# # # change fill color
# # trancriptVis(gtfFile = gtf,
# # gene = 'Nanog',
# # exonFill = '#CCFF00')
# #
# # # change inrton line size
# # trancriptVis(gtfFile = gtf,
# # gene = 'Nanog',
# # intronSize = 1)
# #
# # # change label size,color and position
# # trancriptVis(gtfFile = gtf,
# # gene = 'Nanog',
# # textLabelSize = 4,
# # textLabelColor = 'red',
# # relTextDist = 0)
# #
# # # aes by gene name
# # trancriptVis(gtfFile = gtf,
# # gene = 'Nanog',
# # textLabel = 'gene_name')
# #
# # # color aes by transcript
# # trancriptVis(gtfFile = gtf,
# # gene = 'Tpx2',
# # exonColorBy = 'transcript_id')
# #
# # # change arrow color and type
# # trancriptVis(gtfFile = gtf,
# # gene = 'Nanog',
# # arrowCol = 'orange',
# # arrowType = 'closed')
# #
# # # no intron gene and add arrow color
# # # change arrow color and type
# # trancriptVis(gtfFile = gtf,
# # gene = 'Jun',
# # textLabel = 'gene_name',
# # arrowCol = 'white',
# # arrowType = 'closed') +
# # theme_void()
# #
# # # add arrow breaks
# # trancriptVis(gtfFile = gtf,
# # gene = 'Nanog',
# # arrowCol = 'orange',
# # arrowType = 'closed',
# # arrowBreak = 0.1)
# #
# # # draw specific transcript
# # p1 <- trancriptVis(gtfFile = gtf,
# # gene = 'Commd7')
# #
# # p2 <- trancriptVis(gtfFile = gtf,
# # gene = 'Commd7',
# # myTranscript = c('ENSMUST00000071852','ENSMUST00000109782'))
# #
# # # combine
# # cowplot::plot_grid(p1,p2,ncol = 2,align = 'hv')
# #
# # ########################################################
# # # add specific arrow
# # pneg <- trancriptVis(gtfFile = gtf,
# # gene = 'Gucy2e',
# # newStyleArrow = T)
# #
# # ppos <- trancriptVis(gtfFile = gtf,
# # gene = 'Tex15',
# # newStyleArrow = T)
# #
# # # combine
# # cowplot::plot_grid(pneg,ppos,ncol = 2,align = 'hv')
# #
# # # remove normal arrow specific arrow
# # trancriptVis(gtfFile = gtf,
# # gene = 'Fat1',
# # newStyleArrow = T,
# # addNormalArrow = F)
# #
# # # draw absolute
# # trancriptVis(gtfFile = gtf,
# # gene = 'Fat1',
# # newStyleArrow = T,
# # addNormalArrow = F,
# # absSpecArrowLen = T)
# #
# # # change position size color and height
# # trancriptVis(gtfFile = gtf,
# # gene = 'Fat1',
# # newStyleArrow = T,
# # addNormalArrow = F,
# # speArrowRelPos = 0.5,
# # speArrowLineSize = 1,
# # speArrowCol = 'red',
# # speArrowRelHigh = 3)
# #
# # # circle plot with specific arrow
# # trancriptVis(gtfFile = gtf,
# # gene = 'F11',
# # newStyleArrow = T,
# # addNormalArrow = F,
# # circle = T,
# # ylimLow = -2)
# #
# # ########################################################
# # # support multiple gene
# # # should on same chromosome and close to each other
# # trancriptVis(gtfFile = gtf,
# # gene = c('Trmt6','Mcm8','Crls1','Lrrn4','Fermt1'),
# # textLabel = 'gene_name')
# #
# # # color by gene and change arrow length
# # trancriptVis(gtfFile = gtf,
# # gene = c('Crls1','Fermt1'),
# # textLabel = 'gene_name',
# # exonColorBy = 'gene_name',
# # newStyleArrow = T,
# # speArrowRelLen = 1)
# #
# # # collapse gene
# # trancriptVis(gtfFile = gtf,
# # gene = c('Trmt6','Mcm8','Crls1','Lrrn4','Fermt1'),
# # textLabel = 'gene_name',
# # collapse = T,
# # relTextDist = 0.2)
# #
# # ########################################################
# # # support plot at a given region
# # trancriptVis(gtfFile = gtf,
# # Chr = 11,
# # posStart = 69609973,
# # posEnd = 69624790)
# #
# # ########################################################
# # # draw circle structure
# # trancriptVis(gtfFile = gtf,
# # gene = 'Gucy2e',
# # textLabelSize = 4,
# # circle = T)
# #
# # # change circle small
# # trancriptVis(gtfFile = gtf,
# # gene = 'Gucy2e',
# # textLabelSize = 4,
# # circle = T,
# # ylimLow = 0)
# #
# # # change circle angle
# # c1 <- trancriptVis(gtfFile = gtf,
# # gene = 'F11',
# # textLabelSize = 4,
# # circle = T,
# # ylimLow = 0,
# # openAngle = 0)
# #
# # c2 <- trancriptVis(gtfFile = gtf,
# # gene = 'F11',
# # textLabelSize = 4,
# # circle = T,
# # ylimLow = 0,
# # openAngle = 0.2)
# #
# # # combine
# # cowplot::plot_grid(c1,c2,ncol = 2,align = 'hv')
# #
# # # chenge aes fill
# # trancriptVis(gtfFile = gtf,
# # gene = 'Gucy2e',
# # textLabelSize = 4,
# # circle = T,
# # ylimLow = 0,
# # exonColorByTrans = T)
# #
# # # change segment color
# # trancriptVis(gtfFile = gtf,
# # gene = 'Gucy2e',
# # textLabelSize = 4,
# # circle = T,
# # ylimLow = 0,
# # exonColorByTrans = T,
# # circSegCol = 'black')
# #
# # # add gene name
# # trancriptVis(gtfFile = gtf,
# # gene = 'Gucy2e',
# # textLabel = 'gene_name',
# # textLabelSize = 5,
# # circle = T,
# # ylimLow = 0,
# # exonColorByTrans = T)
# #
# # # remove line
# # trancriptVis(gtfFile = gtf,
# # gene = 'Gucy2e',
# # textLabel = 'gene_name',
# # textLabelSize = 5,
# # circle = T,
# # ylimLow = 0,
# # exonColorByTrans = T,
# # text_only = T)
# #
# # # multiple gene
# # trancriptVis(gtfFile = gtf,
# # gene = c('Pfn1','Eno3','Spag7'),
# # textLabel = 'gene_name',
# # textLabelSize = 2,
# # circle = T,
# # ylimLow = -5,
# # text_only = T,
# # circSegCol = 'grey80',
# # exonColorByTrans = T)
#
#
# #########################################################
# library(transPlotR)
# data(gtf)
#
# # single plot
# lapply(c('Camk1g','Daw1','Oprk1'), function(x){
# trancriptVis(gtfFile = gtf,
# gene = x,
# textLabel = 'gene_name')
# }) -> plist
#
# # combine
# cowplot::plot_grid(plotlist = plist,ncol = 3,align = 'hv')
#
# # plot tegether
# trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Daw1','Oprk1'),
# textLabel = 'gene_name')
#
# # facet by gene
# trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Daw1','Oprk1'),
# facetByGene = T)
#
# # add new arrow and remove normal arrow
# trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Daw1','Oprk1'),
# facetByGene = T,
# newStyleArrow = T,
# absSpecArrowLen = T,
# speArrowRelLen = 0.1,
# addNormalArrow = F)
#
# # for different chromosome genes
# # chr1:Camk1g chr2:Duox2 chr3:Ttll7
# trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Duox2','Ttll7'),
# facetByGene = T)
#
# # textlabel with transcript_name
# trancriptVis(gtfFile = gtf,
# gene = 'Gucy2e',
# textLabelSize = 4,
# circle = T,
# ylimLow = 0,
# textLabel = 'transcript_name',
# addNormalArrow = F,
# newStyleArrow = T)

# # transform relative position
# trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Daw1','Oprk1'),
# facetByGene = T,
# newStyleArrow = T,
# absSpecArrowLen = T,
# speArrowRelLen = 0.1,
# addNormalArrow = F,
# forcePosRel = T)
#
# # ajusted with facet parameters
# trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Daw1','Oprk1'),
# facetByGene = T,
# newStyleArrow = T,
# absSpecArrowLen = T,
# speArrowRelLen = 0.1,
# addNormalArrow = F,
# forcePosRel = T,
# ncolGene = 1,
# scales = 'free_y',
# strip.position = 'left',
# textLabelSize = 2,
# exonColorBy = 'gene_name',
# textLabel = 'transcript_name',
# panel.spacing = 0)
#
# # cicular plot with relative position
# trancriptVis(gtfFile = gtf,
# gene = 'Nanog',
# textLabelSize = 4,
# circle = T,
# ylimLow = 0,
# textLabel = 'transcript_name',
# addNormalArrow = F,
# newStyleArrow = T,
# exonColorBy = 'transcript_name',
# forcePosRel = T)

# # reverse negtive strand
# trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Daw1','Oprk1'),
# facetByGene = T,
# newStyleArrow = T,
# absSpecArrowLen = T,
# speArrowRelLen = 0.1,
# addNormalArrow = F,
# forcePosRel = T,
# revNegStrand = T)
#
# # ajusted with facet parameters
# p1 <- trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Daw1','Oprk1'),
# facetByGene = T,
# newStyleArrow = T,
# absSpecArrowLen = T,
# speArrowRelLen = 0.1,
# addNormalArrow = F,
# forcePosRel = T,
# ncolGene = 1,
# scales = 'free_y',
# strip.position = 'left',
# textLabelSize = 2,
# exonColorBy = 'gene_name',
# textLabel = 'transcript_name',
# panel.spacing = 0)
#
# # reverse negtive strand
# p2 <- trancriptVis(gtfFile = gtf,
# gene = c('Camk1g','Daw1','Oprk1'),
# facetByGene = T,
# newStyleArrow = T,
# absSpecArrowLen = T,
# speArrowRelLen = 0.1,
# addNormalArrow = F,
# forcePosRel = T,
# ncolGene = 1,
# scales = 'free_y',
# strip.position = 'left',
# textLabelSize = 2,
# exonColorBy = 'gene_name',
# textLabel = 'transcript_name',
# panel.spacing = 0,
# revNegStrand = T)
#
# # combine
# cowplot::plot_grid(plotlist = list(p1,p2),ncol = 2,align = 'hv')

0 comments on commit a4575ff

Please sign in to comment.