text: user4001: 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 > 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:
  "0 SAM alignments processed"
  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 "ENSG00000223972"; gene_name "DDX11L1";
  gene_source "ensembl_havana"; gene_biotype "pseudogene";
  1       processed_transcript    transcript      11869   14409   .       +       .       gene_id "ENSG00000223972"; trans
  cript_id "ENST00000456328"; gene_name "DDX11L1"; gene_source "ensembl_havana"; gene_biotype "pseudogene"; transcript_nam
  e "DDX11L1-002"; transcript_source "havana";
  1       processed_transcript    exon    11869   12227   .       +       .       gene_id "ENSG00000223972"; transcript_id
   "ENST00000456328"; exon_number "1"; gene_name "DDX11L1"; gene_source "ensembl_havana"; gene_biotype "pseudogene"; trans
  cript_name "DDX11L1-002"; transcript_source "havana"; exon_id "ENSE00002234944";
  
  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.
  
  user77: 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.
  
original_text: 4001: <p>I am trying to derive an expression matrix from BAM files using <code>htseq-count</code>. These are bulk RNASeq BAM's by the way.</p>
  <p>I have read the <code>htseq-count</code> documentation as well as <code>samtools</code> and figured that the following command <em>should</em> work:</p>
  <pre><code>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
  </code></pre>
  <p>The <code>.gtf</code> file here is from ensembl.</p>
  <p>I have tried many variations of the above command but have failed to generate a count matrix. The <em>error</em> message states:</p>
  <p>&quot;0 SAM alignments processed&quot;</p>
  <p>Here are the first few lines of my .gtf file:</p>
  <pre><code>#!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;;
  </code></pre>
  <p>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.</p>
  <p>Thanks!</p>
  <p>EDIT:: For anybody who sees this post cause they have a similar problem. Just note that the newer versions of <code>htseq-count</code> don't require sorted .bam files and, so following the editing of the <code>.gtf</code> file, all I needed to do was convert it to <code>.sam</code> using <code>samtools view -h</code> and then pipe this to <code>htseq-count</code>. Sorting the files prior to this conversion would cause errors.</p>
   77: <p>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.</p>
  