SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
Thread Thread Starter Forum Replies Last Post
htseq-count paolo.kunder Bioinformatics 10 10-22-2014 04:45 AM
convert sorted bam to sorted sam for htseq-count ugolino Bioinformatics 3 10-19-2012 06:30 AM
Output of HTseq-count? kasutubh Bioinformatics 8 08-21-2012 10:39 PM
multiBamCov or htseq-count to count read per feature ? NicoBxl Bioinformatics 1 07-03-2012 02:05 AM
htseq-count error sissi Bioinformatics 0 03-20-2012 11:40 PM

Reply
 
Thread Tools
Old 11-07-2012, 06:57 PM   #1
dvanic
Member
 
Location: Sydney, Australia

Join Date: Jan 2012
Posts: 61
Default 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!
dvanic is offline   Reply With Quote
Old 11-09-2012, 07:23 AM   #2
hlwright
Member
 
Location: Liverpool, UK

Join Date: Feb 2011
Posts: 30
Default

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
hlwright is offline   Reply With Quote
Old 11-09-2012, 07:51 AM   #3
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,480
Default

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.
dpryan is offline   Reply With Quote
Old 11-09-2012, 10:37 AM   #4
hlwright
Member
 
Location: Liverpool, UK

Join Date: Feb 2011
Posts: 30
Default

dpryan - that worked brilliantly, thanks!

)
hlwright is offline   Reply With Quote
Old 07-29-2013, 04:05 PM   #5
astazangasta
Junior Member
 
Location: San Francisco

Join Date: Jul 2013
Posts: 1
Default 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.
astazangasta is offline   Reply With Quote
Old 11-08-2013, 04:46 PM   #6
Him26
Member
 
Location: California US

Join Date: Aug 2011
Posts: 19
Default

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 at 04:50 PM.
Him26 is offline   Reply With Quote
Old 11-09-2013, 03:19 AM   #7
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,480
Default

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.
dpryan is offline   Reply With Quote
Old 11-09-2013, 04:32 AM   #8
Him26
Member
 
Location: California US

Join Date: Aug 2011
Posts: 19
Thumbs up

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 at 05:23 AM. Reason: more information
Him26 is offline   Reply With Quote
Old 11-11-2013, 04:29 AM   #9
bruce01
Senior Member
 
Location: .

Join Date: Mar 2011
Posts: 157
Default

Quote:
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.
bruce01 is offline   Reply With Quote
Old 11-11-2013, 04:35 AM   #10
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,480
Default

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).
dpryan is offline   Reply With Quote
Old 03-02-2014, 05:06 PM   #11
flek
Junior Member
 
Location: Japan

Join Date: Mar 2014
Posts: 1
Default

Quote:
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
flek is offline   Reply With Quote
Old 08-17-2014, 10:19 AM   #12
dstorey
Junior Member
 
Location: Tennessee

Join Date: Feb 2013
Posts: 5
Default

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.
dstorey is offline   Reply With Quote
Old 11-12-2014, 11:06 AM   #13
tsalem
Junior Member
 
Location: USA

Join Date: Nov 2014
Posts: 5
Default

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
tsalem is offline   Reply With Quote
Old 11-12-2014, 11:30 AM   #14
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,950
Default

Quote:
Originally Posted by tsalem View Post
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.
GenoMax is offline   Reply With Quote
Old 11-12-2014, 11:36 AM   #15
tsalem
Junior Member
 
Location: USA

Join Date: Nov 2014
Posts: 5
Default

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
tsalem is offline   Reply With Quote
Old 11-12-2014, 11:49 AM   #16
tsalem
Junior Member
 
Location: USA

Join Date: Nov 2014
Posts: 5
Default

Quote:
Originally Posted by GenoMax View Post
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.

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
tsalem is offline   Reply With Quote
Old 11-12-2014, 04:01 PM   #17
GenoMax
Senior Member
 
Location: East Coast USA

Join Date: Feb 2008
Posts: 6,950
Default

Do you know how the bam was generated (is there more than 1 bam per sample)? Do you have access to the original read files?
GenoMax is offline   Reply With Quote
Old 11-12-2014, 04:46 PM   #18
tsalem
Junior Member
 
Location: USA

Join Date: Nov 2014
Posts: 5
Default

I don't know how it has been generated, i have different samples and there is one bam file for every sample.

I don't have access to the original read files.
tsalem is offline   Reply With Quote
Old 11-12-2014, 05:52 PM   #19
tsalem
Junior Member
 
Location: USA

Join Date: Nov 2014
Posts: 5
Default

I got the solution I was using Wrong .gtf file.

Thanks Geno for looking at this.
tsalem is offline   Reply With Quote
Reply

Tags
htseq, htseq-count, python

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 04:29 PM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO