Counting reads with htseq-count produces the following error
Error occured when processing input (record #977823 in file <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>):
header not available in closed files [Exception type: ValueError, raised in libcalignmentfile.pyx:1884]
record #977823 is the last record (see below)
The command used to run htseq was
samtools view -F 2304 -f 1 -bh Samp1_PE.bam | samtools sort -n -O SAM - | htseq-count -s reverse -o Samp1_w_feature_PE.bam -p bam - /Annotation/Genes/masked.gtf >! htseq_pe.txt
The resultant text file is empty. The resultant bam file (Samp1_w_feature_PE) has all reads except for the last one (sorted by name). When counting the number of lines
> samtools view -F 2304 -f 1 -bh Samp1_PE.bam | wc -l
is exactly 977823, so I understand that record #977823 is the last record.
I have not found this error message when googling. Any help?