Entering edit mode
stianlagstad
▴
90
@stianlagstad-9723
Last seen 4.8 years ago
I want to plot a transcript with it's coverage data as a histogram using DataTrack, but I'm a bit stuck.. Consider this code:
library(Rsamtools) library(RNAseqData.HNRNPC.bam.chr14) library(TxDb.Hsapiens.UCSC.hg19.knownGene) # Get reference to example bamfile bamfile <- RNAseqData.HNRNPC.bam.chr14_BAMFILES[1] # Exmple transcript name transcript <- "uc001yhh.1" # Get exons for transcript allExons <- GenomicFeatures::exons( TxDb.Hsapiens.UCSC.hg19.knownGene, vals = list(tx_name = transcript), columns = list("EXONNAME", "TXNAME", "GENEID")) # Expand GRanges allExons <- expand(allExons) # Remove unwanted rows allExons <- allExons[mcols(allExons)$TXNAME == transcript] # Set $transcript mcols mcols(allExons)$transcript <- mcols(allExons)$TXNAME # Create track trTrack <- Gviz::GeneRegionTrack(allExons) # Plot Gviz::plotTracks(trTrack) # Transcript plot works well # Get coverage cov <- GenomicAlignments::coverage(bamfile, param = Rsamtools::ScanBamParam(which = allExons)) # Coverage only for my transcript cov <- cov[allExons] # Unlist cov <- unlist(cov) # Turn into numeric vector cov <- as.numeric(cov) # How do I create a DataTrack object of with these coverage values? I wish to plot the transcript with the coverage data I now have in cov.
Any ideas? I don't want to use an AlignmentsTrack. For this task I have to extract coverage data using coverage() with the bamfile.
Thank you, that brings me closer!
I'm guessing this is because I unlisted the cov earlier, so that it does't contain the coordinates I need in order to plot the data at the right place. Does anyone have any pointers?