Seqanswers Leaderboard Ad

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • swaraj
    Member
    • Feb 2012
    • 50

    Raw counts of 12 column bed file (against multiple BAM)

    Hello Everyone,

    I am sharing a perl script to get raw read counts from mulitple BAM files, for a given bed file. The script requires bedtools and samtools to be preinstalled in the system.

    I hope it is useful for users. An alternative solution exists in python
    (http://seqanswers.com/forums/showthread.php?t=18182)
    Attached Files
  • jason_ARGONAUTE
    Member
    • Aug 2013
    • 14

    #2
    thanks so much for ur script.
    But you didn't give the usage info.

    I hv a .gtf file download from EMBL for D.mel now, should i convert it to .bed in advance?
    and the usage is?
    perl bed_count.pl annotated.bed dir_of_my_bamfiles tmpcount/ my.exon my.count

    Comment

    • swaraj
      Member
      • Feb 2012
      • 50

      #3
      Dear Jason,

      A much quicker solution is to

      1. Convert GTF to BED. A nice script is found here http://ea-utils.googlecode.com/svn/t...lipper/gtf2bed

      2. Convert the BED file to exon coordinates (BEDTools package).
      bed12toBed6 -i filename.bed > filename.exons

      3. Get read counts from multiple BAM files (BEDTools package)
      multiBamCov -bams aln.1.bam aln.2.bam -bed filename.exons > filename.counts
      (Remember to build index of each BAM file using samtools index, else multiBamCov wont work)

      4. Load the count file in R environment.

      filename <- read.delim("filename.counts", header=FALSE,sep = "\t", stringsAsFactors =FALSE)

      5. Sum the exons into gene counts using apply function in R
      input <- filename[,7:ncol(filename)]
      names <- filename$V4

      filename.gene.count<-apply(input,2,function(x){tapply(x,names,function(y){sum(y)})})

      6. Write the count file as a text file
      write.table(filename.gene.count, file = "filename.gene.count", quote = FALSE, row.names=FALSE, col.names=FALSE)

      The order of the counts for samples will be the same order in which you give the BAM files. My previous script is easier to implement but little slower. If you open the script in a text editor you can give the name of the directory of BAM files and the BED file. Hope this helps.

      Comment

      • jason_ARGONAUTE
        Member
        • Aug 2013
        • 14

        #4
        Dear swaraj,

        It helps me a lot. Thanks again^^
        But i hv encountered a now problem now when adopting the new solution. I hv got 23017 exons in total while 14797 genes are mapped to the genome by Tophat & Cufflinks. and 14797 is a proper count for fruit fly. I notice that ur solution use exon coordinates(FBtrxxxx instead of FBgnxxxxx).
        I am confused now. what else do i need to do to process the matrix of raw counts i just got before importing it into R packages like edgeR for DEG analysis?

        Comment

        • swaraj
          Member
          • Feb 2012
          • 50

          #5
          In step 2 I coverted transcript BED file into exon file. Here the name of each exon is the transcript name which means transcript name is reduddant. In step 5 this same file is converted back into transcript file using R. All reads in exons with same transcript name are summed up. I would not go into using exon names. Just keep the same name (gene name or trasncript name) for each exon of a feature. This makes it quicker in R to sum the counts of all exons.

          Comment

          • jason_ARGONAUTE
            Member
            • Aug 2013
            • 14

            #6
            ya, i know and i do exactly as ur pipeline. might be i mixed the concept of exon and transcript. i thought they were the same thing.(both named "FBtrxxx")
            So, this is not the reason why i got almost twice counts of genes as i expected.
            Could you figure out any other reason? Thank you!

            Comment

            • jason_ARGONAUTE
              Member
              • Aug 2013
              • 14

              #7
              Or,
              what do i need to do to get raw counts for each gene?
              Thank you!

              Comment

              • dpryan
                Devon Ryan
                • Jul 2011
                • 3478

                #8
                Originally posted by jason_ARGONAUTE View Post
                Or,
                what do i need to do to get raw counts for each gene?
                Thank you!
                If you have a GTF file, just use htseq-count.

                Comment

                • jason_ARGONAUTE
                  Member
                  • Aug 2013
                  • 14

                  #9
                  I hv tried htseq-count, really hard.
                  But it cannt be installed on our lab server.
                  Thank you all the same^^

                  Comment

                  Latest Articles

                  Collapse

                  • seqadmin
                    New Genomics Tools and Methods Shared at AGBT 2025
                    by seqadmin


                    This year’s Advances in Genome Biology and Technology (AGBT) General Meeting commemorated the 25th anniversary of the event at its original venue on Marco Island, Florida. While this year’s event didn’t include high-profile musical performances, the industry announcements and cutting-edge research still drew the attention of leading scientists.

                    The Headliner
                    The biggest announcement was Roche stepping back into the sequencing platform market. In the years since...
                    03-03-2025, 01:39 PM
                  • seqadmin
                    Investigating the Gut Microbiome Through Diet and Spatial Biology
                    by seqadmin




                    The human gut contains trillions of microorganisms that impact digestion, immune functions, and overall health1. Despite major breakthroughs, we’re only beginning to understand the full extent of the microbiome’s influence on health and disease. Advances in next-generation sequencing and spatial biology have opened new windows into this complex environment, yet many questions remain. This article highlights two recent studies exploring how diet influences microbial...
                    02-24-2025, 06:31 AM

                  ad_right_rmr

                  Collapse

                  News

                  Collapse

                  Topics Statistics Last Post
                  Started by seqadmin, Yesterday, 07:27 AM
                  0 responses
                  11 views
                  0 reactions
                  Last Post seqadmin  
                  Started by seqadmin, 03-18-2025, 12:50 PM
                  0 responses
                  14 views
                  0 reactions
                  Last Post seqadmin  
                  Started by seqadmin, 03-03-2025, 01:15 PM
                  0 responses
                  185 views
                  0 reactions
                  Last Post seqadmin  
                  Started by seqadmin, 02-28-2025, 12:58 PM
                  0 responses
                  283 views
                  0 reactions
                  Last Post seqadmin  
                  Working...