Seqanswers Leaderboard Ad

Collapse

Announcement

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

  • HTSeq-count on bam

    Hi!
    Is there a way to directly run htseq-count on a bam file? I know that htseq supports bam input via HTSeq.BAM_Reader(), but is there a flag to tell the htseq-count script that I'm using a bam?

    Or which file in the source code (and how) do I modify to configure it to work with bams and not sams???

    Thanks in advance!

  • #2
    Hi

    I have EXACTLY the same question. Does htseq take BAM files, or do you have to convert to SAM first (don't want to do this if I don't have to)?

    Thanks

    Comment


    • #3
      If you're using the command line version, you can just use:
      Code:
      samtools view file.bam | htseq-count (options) - GTF > counts.txt
      where GTF is the GTF file and (options) are whatever options are appropriate.

      Comment


      • #4
        dpryan - that worked brilliantly, thanks!

        )

        Comment


        • #5
          counting reads

          If anyone else is trying this, be advised that HTseq count requires reads to be name-sorted. If you usually keep your bam coordinate-sorted, like I do, and you have paired-end reads, you need to do a bit more work to get it in the right shape, otherwise HTseq will end up skipping huge numbers of reads. I do:

          Code:
          samtools sort -on - output | samtools view -h - | htseq_count etc.

          Comment


          • #6
            Code:
            samtools sort -on - output | samtools view -h - | htseq_count etc.
            Could you expand on how you pipe-in to htseq-count?
            I get an error saying I need to provide two arguments to htseq-count.
            I just left it blank on the htseq-count commend assuming that it will know.
            my code is like below:

            Code:
             | htseq-count -m{option}  annotation.gtf >output.count
            Thank you.
            Last edited by Him26; 11-08-2013, 05:50 PM.

            Comment


            • #7
              Code:
              samtools sort -on file.bam | samtools view - | htseq-count (options) - GTF > counts.txt
              Or something like that. The "-" means read from the pipe/standard input in both samtools and htseq-count.

              Comment


              • #8
                Thank you dpryan for the quick reply.
                I tried the following code and I get the following error? any suggestions?

                Code:
                 samtools sort -on -m 300000000 accepted_hits.bam |samtools view -h - |htseq-count -m intersection-strict -  /genome/gencode.v18.annotation.gtf > hits.count
                Usage: samtools sort [options] <in.bam> <out.prefix>

                Options: -n sort by read name
                -f use <out.prefix> as full file name instead of prefix
                -o final output to stdout
                -l INT compression level, from 0 to 9 [-1]
                -@ INT number of sorting and compression threads [1]
                -m INT max memory per thread; suffix K/M/G recognized [768M]

                [bam_header_read] EOF marker is absent. The input is probably truncated.
                [bam_header_read] invalid BAM binary header (this is not a BAM file).
                [main_samview] fail to read the header from "-".
                100000 GFF lines processed.
                200000 GFF lines processed.
                300000 GFF lines processed.
                400000 GFF lines processed.
                500000 GFF lines processed.
                600000 GFF lines processed.
                700000 GFF lines processed.
                800000 GFF lines processed.
                900000 GFF lines processed.
                1000000 GFF lines processed.
                1100000 GFF lines processed.
                1200000 GFF lines processed.
                1300000 GFF lines processed.
                1400000 GFF lines processed.
                1500000 GFF lines processed.
                1600000 GFF lines processed.
                1700000 GFF lines processed.
                1800000 GFF lines processed.
                1900000 GFF lines processed.
                2000000 GFF lines processed.
                2100000 GFF lines processed.
                2200000 GFF lines processed.
                2300000 GFF lines processed.
                2400000 GFF lines processed.
                2500000 GFF lines processed.
                2600000 GFF lines processed.
                2614562 GFF lines processed.
                Error occured when reading first line of sam file.

                [Exception type: StopIteration, raised in count.py:83]
                Last edited by Him26; 11-09-2013, 06:23 AM. Reason: more information

                Comment


                • #9
                  Originally posted by Him26 View Post
                  [bam_header_read] EOF marker is absent. The input is probably truncated.
                  [bam_header_read] invalid BAM binary header (this is not a BAM file).
                  [main_samview] fail to read the header from "-".
                  So your BAM is not complete, try realigning, or use a different BAM.

                  Comment


                  • #10
                    You may also just see if the following produces the same result:

                    Code:
                    samtools sort -n -m 300000000 accepted_hits.bam namesorted
                    If so, then bruce01 is correct that your original BAM file is truncated. It's unclear which of the samtools steps is producing the fatal error and this would determine which it is (I too suspect that the original BAM file is just truncated).

                    Comment


                    • #11
                      Originally posted by astazangasta View Post
                      If anyone else is trying this, be advised that HTseq count requires reads to be name-sorted. If you usually keep your bam coordinate-sorted, like I do, and you have paired-end reads, you need to do a bit more work to get it in the right shape, otherwise HTseq will end up skipping huge numbers of reads. I do:

                      Code:
                      samtools sort -on - output | samtools view -h - | htseq_count etc.
                      I just came across the same problem and while browsing the htseq documentation I found out that there is a new option in version 0.6.1 that allows to read bam files which are sorted by position.

                      Code:
                      htseq_count -r pos etc.
                      More at their documentation

                      Comment


                      • #12
                        It unfortunately has a well known bug that causes the memory buffer to overflow sometimes. Named sort appears to be the most consistent method for getting a run completed.

                        Comment


                        • #13
                          Now, I think htseq can take directly the bam file, we only need to use the -f option as follows


                          htseq-count -f bam <file>.bam <file>.gtf > genes_count.txt


                          is i am Wrong? I tried it and it works

                          Comment


                          • #14
                            Originally posted by tsalem
                            after i run the command
                            htseq-count -f bam <file>.bam <file>.gtf > genes_count.txt

                            i got the following error,


                            Warning: Read UNC13-SN749_48:5:2105:5602:87765/2 claims to have an aligned mate which could not be found in an adjacent line.
                            Error occured when processing SAM input (record #40 in file sorted_genome_alignments.bam):
                            tid -1 out of range 0<=tid<25
                            [Exception type: ValueError, raised in csamfile.pyx:535]

                            is any one have an idea why this error? Thanks in advance
                            When you did QC/trimming of the data was a PE-read aware program used (to keep the pairs of reads in sync in both files) with the two data files at the same time (R1/R2)? It is possible that reads in your files went out of sync and this is resulting in the error above.

                            Comment


                            • #15
                              Actually, I didn't do any thing with the files, I just got the .gtf file from The ucsc.
                              and the .bam file from my advisor. and i am trying to get genes count from .bam file.

                              is possible to let me know how i can check if the pairs of reads in sync in both files

                              Thanks

                              Comment

                              Latest Articles

                              Collapse

                              • seqadmin
                                Strategies for Sequencing Challenging Samples
                                by seqadmin


                                Despite advancements in sequencing platforms and related sample preparation technologies, certain sample types continue to present significant challenges that can compromise sequencing results. Pedro Echave, Senior Manager of the Global Business Segment at Revvity, explained that the success of a sequencing experiment ultimately depends on the amount and integrity of the nucleic acid template (RNA or DNA) obtained from a sample. “The better the quality of the nucleic acid isolated...
                                03-22-2024, 06:39 AM
                              • seqadmin
                                Techniques and Challenges in Conservation Genomics
                                by seqadmin



                                The field of conservation genomics centers on applying genomics technologies in support of conservation efforts and the preservation of biodiversity. This article features interviews with two researchers who showcase their innovative work and highlight the current state and future of conservation genomics.

                                Avian Conservation
                                Matthew DeSaix, a recent doctoral graduate from Kristen Ruegg’s lab at The University of Colorado, shared that most of his research...
                                03-08-2024, 10:41 AM

                              ad_right_rmr

                              Collapse

                              News

                              Collapse

                              Topics Statistics Last Post
                              Started by seqadmin, Yesterday, 06:37 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, Yesterday, 06:07 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 03-22-2024, 10:03 AM
                              0 responses
                              49 views
                              0 likes
                              Last Post seqadmin  
                              Started by seqadmin, 03-21-2024, 07:32 AM
                              0 responses
                              66 views
                              0 likes
                              Last Post seqadmin  
                              Working...
                              X