Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert Paired End Reads BAM file to GRanges

    Hi,

    I would like to know ways to convert the Paired end bam file into GRanges (R Data Structure). I have readBamGappedAlignments function but I don't know if it works for paired end reads or not ? Any help/advice/hints would be appreciated..

    thanks

  • #2
    Hi ayushraman

    I've used the readGappedAlignments function in the Rsamtools package to plot gene coverage across genes. I had paired end Illumina data, and I used the function to read the data into a GRanges object as follows:

    Firstly, I created a GRanges object of genome position (with coordinated extracted from the CCDS database)
    Code:
    library(ggplot2)
    library(ggbio) 
    library(IRanges)
    library(GenomicRanges)
    library(Rsamtools)
    
    gene_coords <- GRanges (seqnames = chr, ranges = IRanges(start = cds_start, end = cds_end))
    I then used the readGappedAlignments function to read in paired-end data from the BAM file
    Code:
    bam_fields <- c("pos", "qwidth") #I believe these are the minimal parameters required
    				
    param <- ScanBamParam(which = gene_coords, what = bam_fields)
    				
    bam_file <- "path/to/paired-end-data-file.bam"
    				
    bam <- readGappedAlignments(bam_file, param = param)
    I converted the input data to a GRanges object
    Code:
    gr <- granges(bam)
    Once I had that I could plot the coverage (Providing the gene had any coverage) using the ggbio's autoplot function:
    Code:
    #Plot a gene if the gene region has any coverage
    gene_plot <- if(length(width(gr)) >= 1){
            #exons contains the start and stop regions for each exon in the gene
            exons <- data.frame(xmin = exon_starts, xmax = exon_ends, ymin = 0, ymax = Inf)
    					
    	cov_plot <- autoplot (
    		gr, 
    		stat = "coverage",
    		geom = "area",
    		colour = "black",
    		fill = "green",
    		xlab = "Position",
    		ylab = "Coverage",
    		main = "Coverage across gene"
    	
            #Marks the exon regions out so that you can see how much of the sequencing is on target				
    	) + geom_rect(
    		data = exons, 
    		aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax), 
    		fill = "yellow", 
    		colour = "black", alpha = 0.5
    					
    	)
    }
    
    #plot the graph				
    gene_plot
    This method for reading in data is relatively quick, not that memory intensive and quite simple.

    Hope this helps!
    Attached Files

    Comment

    Latest Articles

    Collapse

    • seqadmin
      Essential Discoveries and Tools in Epitranscriptomics
      by seqadmin


      The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist on Modified Bases...
      Yesterday, 07:01 AM
    • seqadmin
      Current Approaches to Protein Sequencing
      by seqadmin


      Proteins are often described as the workhorses of the cell, and identifying their sequences is key to understanding their role in biological processes and disease. Currently, the most common technique used to determine protein sequences is mass spectrometry. While still a valuable tool, mass spectrometry faces several limitations and requires a highly experienced scientist familiar with the equipment to operate it. Additionally, other proteomic methods, like affinity assays, are constrained...
      04-04-2024, 04:25 PM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, 04-11-2024, 12:08 PM
    0 responses
    55 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 10:19 PM
    0 responses
    52 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-10-2024, 09:21 AM
    0 responses
    45 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 04-04-2024, 09:00 AM
    0 responses
    55 views
    0 likes
    Last Post seqadmin  
    Working...
    X