.\" Man page generated from reStructuredText. . .TH "HTSEQ-COUNT" "1" "Oct 01, 2017" "0.6.1p1" "HTSeq" .SH NAME htseq-count \- Count the number of reads in a SAM alignment file that map to GFF features . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .sp Given a file with aligned sequencing reads and a list of genomic features, a common task is to count how many reads map to each feature. .sp A feature is here an interval (i.e., a range of positions) on a chromosome or a union of such intervals. .sp In the case of RNA\-Seq, the features are typically genes, where each gene is considered here as the union of all its exons. One may also consider each exon as a feature, e.g., in order to check for alternative splicing. For comparative ChIP\-Seq, the features might be binding region from a pre\-determined list. .sp Special care must be taken to decide how to deal with reads that overlap more than one feature. The \fBhtseq\-count\fP script allows to choose between three modes. Of course, if none of these fits your needs, you can write your own script with HTSeq. See the chapter tour for a step\-by\-step guide on how to do so. See also the FAQ at the end, if the following explanation seems to technical. .sp The three overlap resolution modes of \fBhtseq\-count\fP work as follows. For each position \fIi\fP in the read, a set \fIS(i)\fP is defined as the set of all features overlapping position \fIi\fP\&. Then, consider the set \fIS\fP, which is (with \fIi\fP running through all position within the read or a read pair) .INDENT 0.0 .IP \(bu 2 the union of all the sets \fIS(i)\fP for mode \fBunion\fP\&. This mode is recommended for most use cases. .IP \(bu 2 the intersection of all the sets \fIS(i)\fP for mode \fBintersection\-strict\fP\&. .IP \(bu 2 the intersection of all non\-empty sets \fIS(i)\fP for mode \fBintersection\-nonempty\fP\&. .UNINDENT .sp If \fIS\fP contains precisely one feature, the read (or read pair) is counted for this feature. If it contains more than one feature, the read (or read pair) is counted as \fBambiguous\fP (and not counted for any features), and if \fBS\fP is empty, the read (or read pair) is counted as \fBno_feature\fP\&. .sp The following figure illustrates the effect of these three modes: [image] .SH USAGE .sp After you have installed HTSeq (see install), you can run \fBhtseq\-count\fP from the command line: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C htseq\-count [options] .ft P .fi .UNINDENT .UNINDENT .sp If the file \fBhtseq\-qa\fP is not in your path, you can, alternatively, call the script with .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C python \-m HTSeq.scripts.count [options] .ft P .fi .UNINDENT .UNINDENT .sp The \fB\fP contains the aligned reads in the SAM format. (Note that the \fI\%SAMtools\fP contain Perl scripts to convert most alignment formats to SAM.) Make sure to use a splicing\-aware aligner such as TopHat. HTSeq\-count makes full use of the information in the CIGAR field. .sp To read from standard input, use \fB\-\fP as \fB\fP\&. .sp If you have paired\-end data, pay attention to the \fB\-r\fP option described below. .sp The \fB\fP contains the features in the \fI\%GFF format\fP\&. .sp The script outputs a table with counts for each feature, followed by the special counters, which count reads that were not counted for any feature for various reasons. The names of the special counters all start with a double underscore, to facilitate filtering. (Note: The double unscore was absent up to version 0.5.4). The special counters are: .INDENT 0.0 .IP \(bu 2 \fB__no_feature\fP: reads (or read pairs) which could not be assigned to any feature (set \fIS\fP as described above was empty). .IP \(bu 2 \fB__ambiguous\fP: reads (or read pairs) which could have been assigned to more than one feature and hence were not counted for any of these (set \fIS\fP had mroe than one element). .IP \(bu 2 \fB__too_low_aQual\fP: reads (or read pairs) which were skipped due to the \fB\-a\fP option, see below .IP \(bu 2 \fB__not_aligned\fP: reads (or read pairs) in the SAM file without alignment .IP \(bu 2 \fB__alignment_not_unique\fP: reads (or read pairs) with more than one reported alignment. These reads are recognized from the \fBNH\fP optional SAM field tag. (If the aligner does not set this field, multiply aligned reads will be counted multiple times, unless they getv filtered out by due to the \fB\-a\fP option.) .UNINDENT .sp \fIImportant:\fP The default for strandedness is \fIyes\fP\&. If your RNA\-Seq data has not been made with a strand\-specific protocol, this causes half of the reads to be lost. Hence, make sure to set the option \fB\-\-stranded=no\fP unless you have strand\-specific data! .SS Options .INDENT 0.0 .TP .B \-f , \-\-format= Format of the input data. Possible values are \fBsam\fP (for text SAM files) and \fBbam\fP (for binary BAM files). Default is \fBsam\fP\&. .UNINDENT .INDENT 0.0 .TP .B \-r , \-\-order= For paired\-end data, the alignment have to be sorted either by read name or by alignment position. If your data is not sorted, use the \fBsamtools sort\fP function of \fBsamtools\fP to sort it. Use this option, with \fBname\fP or \fBpos\fP for \fB\fP to indicate how the input data has been sorted. The default is \fBname\fP\&. .sp If \fBname\fP is indicated, \fBhtseq\-count\fP expects all the alignments for the reads of a given read pair to appear in adjacent records in the input data. For \fBpos\fP, this is not expected; rather, read alignments whose mate alignment have not yet been seen are kept in a buffer in memory until the mate is found. While, strictly speaking, the latter will also work with unsorted data, sorting ensures that most alignment mates appear close to each other in the data and hence the buffer is much less likely to overflow. .UNINDENT .INDENT 0.0 .TP .B \-s , \-\-stranded= whether the data is from a strand\-specific assay (default: \fByes\fP) .sp For \fBstranded=no\fP, a read is considered overlapping with a feature regardless of whether it is mapped to the same or the opposite strand as the feature. For \fBstranded=yes\fP and single\-end reads, the read has to be mapped to the same strand as the feature. For paired\-end reads, the first read has to be on the same strand and the second read on the opposite strand. For \fBstranded=reverse\fP, these rules are reversed. .UNINDENT .INDENT 0.0 .TP .B \-a , \-\-a= skip all reads with alignment quality lower than the given minimum value (default: 10 — Note: the default used to be 0 until version 0.5.4.) .UNINDENT .INDENT 0.0 .TP .B \-t , \-\-type= feature type (3rd column in GFF file) to be used, all features of other type are ignored (default, suitable for RNA\-Seq analysis using an \fI\%Ensembl GTF\fP file: \fBexon\fP) .UNINDENT .INDENT 0.0 .TP .B \-i , \-\-idattr= GFF attribute to be used as feature ID. Several GFF lines with the same feature ID will be considered as parts of the same feature. The feature ID is used to identity the counts in the output table. The default, suitable for RNA\-Seq analysis using an Ensembl GTF file, is \fBgene_id\fP\&. .UNINDENT .INDENT 0.0 .TP .B \-m , \-\-mode= Mode to handle reads overlapping more than one feature. Possible values for \fI\fP are \fBunion\fP, \fBintersection\-strict\fP and \fBintersection\-nonempty\fP (default: \fBunion\fP) .UNINDENT .INDENT 0.0 .TP .B \-o , \-\-samout= write out all SAM alignment records into an output SAM file called , annotating each line with its assignment to a feature or a special counter (as an optional field with tag ‘XF’) .UNINDENT .INDENT 0.0 .TP .B \-q, \-\-quiet suppress progress report and warnings .UNINDENT .INDENT 0.0 .TP .B \-h, \-\-help Show a usage summary and exit .UNINDENT .SS Frequenctly asked questions .INDENT 0.0 .TP .B \fIMy shell reports “command not found” when I try to run “htseq\-count”. How can I launch the script?\fP The file “htseq\-count” has to be in the system’s \fI\%search path\fP\&. By default, Python places it in its script directory, which you have to add to your search path. A maybe easier alternative is to write \fBpython \-m HTSeq.scripts.count\fP instead of \fBhtseq\-count\fP, followed by the options and arguments, which will launch the htseq\-count script as well. .UNINDENT .INDENT 0.0 .TP .B \fIWhy are multi\-mapping reads and reads overlapping multiple features discarded rather than counted for each feature?\fP The primary intended use case for \fBhtseq\-count\fP is \fIdifferential\fP expression analysis, where one compares the expression of the same gene across samples and not the expression of different genes within a sample. Now, consider two genes, which share a stretch of common sequence such that for a read mapping to this stretch, the aligner cannot decide which of the two genes the read originated from and hence reports a multiple alignment. If we discard all such reads, we undercount the total output of the genes, but the \fIratio\fP of expression strength (the “fold change”) between samples or experimental condition will still be correct, because we discard the same fratcion of reads in all samples. On the other hand, if we counted these reads for both genes, a subsequent diffential\-expression analysis might find false positives: Even if only one of the gene changes increases its expression in reaction to treatment, the additional read caused by this would be counted for both genes, giving the wrong appearance that both genes reacted to the treatment. .TP .B \fII have used a GTF file generated by the Table Browser function of the UCSC Genome Browser, and most reads are counted as ambiguous. Why?\fP In these files, the \fBgene_id\fP attribute incorrectly contains the same value as the \fBtranscript_id\fP attribute and hence a different value for each transcript of the same gene. Hence, if a read maps to an exon shared by several transcripts of the same gene, this will appear to \fBhtseq\-count\fP as and overlap with several genes. Therefore, these GTF files cannot be used as is. Either correct the incorrect \fBgene_id\fP attributes with a suitable script, or use a GTF file from a different source. .TP .B \fICan I use htseq\-count to count reads mapping to transcripts rather than genes?\fP In principle, you could instruct htseq\-count to count for each of a gene’s transcript individually, by specifying \fB\-\-idattr transcript_id\fP\&. However, all reads mapping to exons shared by several transcripts will then be considered ambiguous. (See second question.) Counting them for each transcript that contains the exons would be possible but makes little sense for typical use cases. (See first question.) If you want to perform differential expression analysis on the level of individual transcripts, maybe ahve a look at \fI\%our paper on DEXSeq\fP for a discussion on why we prefer performing such analyses on the level of exons instead. .UNINDENT .INDENT 0.0 .TP .B \fIFor paired\-end data, does htseq\-count count reads or read pairs?\fP Read pairs. The script is designed to count “units of evidence” for gene expression. If both mates map to the same gene, this still only shows that one cDNA fragment originated from that gene. Hence, it should be counted only once. .TP .B \fIWhat happens if the two reads in a pair overlap two different features?\fP The same as if one read overlaps two features: The read or read pair is counted as ambiguous. .TP .B \fIWhat happend if the mate of an aligned read is not aligned?\fP For the default mode “union”, only the aligned read determines how the read pair is counted. For the other modes, see their description. .TP .B \fIMost of my RNA\-Seq reads are counted as \(ga\(ga__no_feature\(ga\(ga. What could have gone wrong?\fP Common causes include: \- The \fB\-\-stranded\fP option was set wrongly. Use a genome browser (e.g., IGV) to check. \- The GTF file uses coordinates from another reference assembly as the SAM file. \- The chromosome names differ between GTF and SAM file (e.g., \fBchr1\fP in one file and jsut \fB1\fP in the other). .TP .B \fIWhich overlap mode should I use?\fP When I wrote \fBhtseq\-count\fP, I was not sure which option is best and included three possibilities. Now, several years later, I have seen very few cases where the default \fBunion\fP would not be appropriate and hence tend to recommend to just stick to \fBunion\fP\&. .TP .B \fII have a GTF file? How do I convert it to GFF?\fP No need to do that, because GTF is a tightening of the GFF format. Hence, all GTF files are GFF files, too. By default, htseq\-count expects a GTF file. .TP .B \fII have a GFF file, not a GTF file. How can I use it to count RNA\-Seq reads?\fP The GTF format specifies, inter alia, that exons are marked by the word \fBexon\fP in the third column and that the gene ID is given in an attribute named \fBgene_id\fP, and htseq\-count expects these words to be used by default. If you GFF file uses a word other than \fBexon\fP in its third column to mark lines describing exons, notify \fBhtseq\-count\fP using the \fB\-\-type\fP option. If the name of the attribute containing the gene ID for exon lines is not \fBgene_id\fP, use the \fB\-\-idattr\fP\&. Often, its is, for example, \fBParent\fP, \fBGeneID\fP or \fBID\fP\&. Make sure it is the gene ID and not the exon ID. .TP .B \fIHow can I count overlaps with features other than genes/exons?\fP If you have GFF file listing your features, use it together with the \fB\-\-type\fP and \fB\-\-idattr\fP options. If your feature intervals need to be computed, you are probably better off writing your own counting script (provided you have some knowledge of Python). Follow the tutorial in the other pages of this documentation to see how to use HTSeq for this. .TP .B \fIHow should I cite htseq\-count in a publication?\fP Please cite HTSeq as follows: S Anders, T P Pyl, W Huber: \fIHTSeq — A Python framework to work with high\-throughput sequencing data\fP\&. bioRxiv 2014. \fI\%doi: 10.1101/002824\fP\&. (This is a preprint currently under review. We will replace this with the reference to the final published version once available.) .UNINDENT .SH AUTHOR Simon Anders .SH COPYRIGHT 2017, Simon Anders .\" Generated by docutils manpage writer. .