Running htseq-count over BAM files I am trying to derive an expression matrix from BAM files using htseq-count. These are bulk RNASeq BAM's by the way.
I have read the htseq-count documentation as well as samtools and figured that the following command should work:
samtools sort -on file.bam | samtools view -h - | htseq-count --type=exon --idattr=gene_id --additional-attr=gene_name - Homo_sapiens.GRCh38.77.gtf &gt; counts.txt

The .gtf file here is from ensembl.
I have tried many variations of the above command but have failed to generate a count matrix. The error message states:
&quot;0 SAM alignments processed&quot;
Here are the first few lines of my .gtf file:
#!genome-build GRCh37.p13
#!genome-version GRCh37
#!genome-date 2009-02
#!genome-build-accession NCBI:GCA_000001405.14
#!genebuild-last-updated 2013-09
1       pseudogene      gene    11869   14412   .       +       .       gene_id &quot;ENSG00000223972&quot;; gene_name &quot;DDX11L1&quot;;
gene_source &quot;ensembl_havana&quot;; gene_biotype &quot;pseudogene&quot;;
1       processed_transcript    transcript      11869   14409   .       +       .       gene_id &quot;ENSG00000223972&quot;; trans
cript_id &quot;ENST00000456328&quot;; gene_name &quot;DDX11L1&quot;; gene_source &quot;ensembl_havana&quot;; gene_biotype &quot;pseudogene&quot;; transcript_nam
e &quot;DDX11L1-002&quot;; transcript_source &quot;havana&quot;;
1       processed_transcript    exon    11869   12227   .       +       .       gene_id &quot;ENSG00000223972&quot;; transcript_id
 &quot;ENST00000456328&quot;; exon_number &quot;1&quot;; gene_name &quot;DDX11L1&quot;; gene_source &quot;ensembl_havana&quot;; gene_biotype &quot;pseudogene&quot;; trans
cript_name &quot;DDX11L1-002&quot;; transcript_source &quot;havana&quot;; exon_id &quot;ENSE00002234944&quot;;

And all the genes in the text file have an expression value of 0. What exactly is going wrong in this step? Is the conversion to a SAM file the problem? I'm completely lost so any help would me much appreciated.
Thanks!
EDIT:: For anybody who sees this post cause they have a similar problem. Just note that the newer versions of htseq-count don't require sorted .bam files and, so following the editing of the .gtf file, all I needed to do was convert it to .sam using samtools view -h and then pipe this to htseq-count. Sorting the files prior to this conversion would cause errors.
If your BAM file is using UCSC chromosome names (chr1, chr2, etc.) and your GTF file is using Ensembl chromosome names (1, 2, etc.) then htseq-count won't know how to match your alignments to any of the genes. The simplest solution is to not use htseq-count, but instead to use featureCounts, which will handle the chromosome name difference transparently (it's one of the few programs that does) and is much faster anyway. In the future, download your GTF and fasta files from the same source, don't mix and match them.