lawremi / ggbio

Grid and ggplot2 based visualization for biological data
111 stars 24 forks source link

adding color to transcripts plot by category #100

Closed anmwinter closed 6 years ago

anmwinter commented 6 years ago

Hello,

First, thanks for making and maintaining ggbio. I have a de novo genome and a set of transcripts across treatments (pure, early infection, late infection) that are up or down regulated. I used gmap to build a bam and gff file for reading into ggbio.

scaff <- readGAlignments("gmap_out_scaffold.bam",=TRUE)
seqinfo(scaff)
txdb <- makeTxDbFromGFF(file="gmap_pure_early.gff", format="gff3")
head(seqlevels(txdb))

For plotting I want to show the whole genome. We have it as a single contig. And I want to show where the UTRs, Transcripts, and Genes map to.

p0 <- autoplot(scaff, aes(color = strand, fill = strand), facets = strand ~ seqnames)

trans <- transcriptsBy(txdb, "exon")
trans

genes <- exonsBy(txdb, by="gene")
genes

fiveprimeUTR <- fiveUTRsByTranscript(txdb)

p3 <- autoplot(fiveprimeUTR, which=GRanges("scaffold1", IRanges(start=0, end=39000000)),
              names.expr = "gene_id",color = "red")

p4 <- autoplot(trans, which=GRanges("scaffold1", IRanges(start=0, end=39000000)),
               names.expr = "gene_id")

p5 <- autoplot(genes, which=GRanges("scaffold1", IRanges(start=0, end=39000000)),
               names.expr = "gene_id")

tracks(Genome=p0, UTR=p3, Transcripts=p4, Genes=p5, heights = c(3, 1, 2, 1)) + ylab("") +
  theme_tracks_sunset()

That will yield this plot, which I think is good so far.

test_plot

I would like to color code the Transcripts by up or down regulated and by treatment. Where in the ggbio pipeline would add this additional data. For a given transcript id like TRINITY_DN2409_c0_g2_i1 I have the up or down and the infection stage.

Thanks for any advice or help. ara

lawremi commented 6 years ago

If you had an mcols variable representing the up/down and treatment status on the trans GRanges, I think you could map that to a color by passing e.g. fill=that_variable to the autoplot() call that makes p4.

anmwinter commented 6 years ago

@lawremi Thanks! So I can add columns to the trans Granges? Or does that need to happen before the Granges object?

lawremi commented 6 years ago

Yes, like mcols(trans)$foo <- "bar".

anmwinter commented 6 years ago

Thanks! That worked well.