Question: Hi !

I'm currently working with paired-end RNA-Seq data from an oriented library (fr-stranded firststrand) of *Salmonella enterica*. Within this context, I'm performing some analysis with a tool developed in my lab that uses XS-strand attribute that TopHat adds in BAM files. It is known that Tophat is not designed to work on bacteria and returns poorer mapping results than Bowtie2 or STAR on those organisms (so far, my observations confirm this fact : ~65% uniquely mapped read with TopHat, ~80% to ~84% with Bowtie and STAR. Each time, the intron length was set to 0 or 1; because I suppose there is no intron in Salmonella, it's a bacteria).

My goal is to reproduce TopHat's XS-Strand attribute with a post treatment on a Bowtie/STAR mapping. I thought TopHat was using the SAM-Flag present in the second column of SAM/BAM files to guess the XS-Strand. To be sure, I ran the following command line:

grep -Po '\t[0-9]+\t.*XS:A:[\+\-]' accepted_hits.sam | awk '{print $1"\t"$NF}' | sort -n | uniq -c

Where `accepted_hits.sam` is the result of my TopHat run.

The following lines are an extract of the proportion of SAM-flags the previous command line returned:

```
NB Reads | SAM-Flag | XS-Strand attribute
262102 81 XS:A:+
59 81 XS:A:-
11563221 99 XS:A:-
1150 99 XS:A:+
11562241 147 XS:A:-
2130 147 XS:A:+
251 163 XS:A:-
9854904 163 XS:A:+
```

A read with a 99 SAM-Flag has the following characteristics (according to [[1][1]]): read paired, read mapped in proper pair, mate reverse strand, first in pair. I thought this SAM-Flag would refer to a + Stranded read ... But TopHat does not agree (11,563,221 times!). Notwithstanding this remark, a read with a 147 SAM-Flag has the following characteristics (according to [[1][1]]): read paired, read mapped in proper pair, read reverse strand, second in pair. I totally agree with the XS-Strand attribute predominant group, the read is on the `-` strand.

To be sure, I opened my BAM files with two genome viewers (Artemis and IGV) and had a look at my data. Both Genome viewers displayed the read orientation I was waiting for, and not the one TopHat wrote in its' 99s-XS-Strand attributes.

Here is a summary of my questions:

1. With TopHat, one SAM flag can lead to both XS-Strand attributes (with a large predominance of one on the other). How is that possible?
2. The predominant TopHat's XS-Strand-attribute group and [the information given by the Broad Institute][1] seems (sometime) contradictory. Which one should I trust?

If you have any questions, please feel free to ask. Many thanks in advance for your help !

PS : Here are the first lines of the `accepted_hits.bam` (obtained with: `samtools view -h accepted_hits.bam | head`). There is also my TopHat command line.

```
@HD VN:1.0 SO:coordinate
@SQ SN:gi|378697983|ref|NC_016810.1| LN:4878012
@PG ID:TopHat VN:2.0.9 CL:/usr/bin/tophat -p 5 -o ./Output_Salmonella/ --library-type fr-firststrand Index/salmonella.fasta_ref fastq/Salmonella_R1_egal.fastq fastq/Salmonella_R2_egal.fastq --min-intron-length 0 --max-intron-length 1
NS500446:4:H18FBBGXX:1:23206:24124:12692 153 gi|378697983|ref|NC_016810.1| 3 50 150M * 0 0 AGATTACGTCAGGTTGCAAGAGATCATGACAGGGGGAATTGGTTGAAAATAAATATATCGCCAGCAGCTCATGAACAAGTTTCGGAATGTGATCAATTTAAAAATTTATTGACTTAGGCGGGCAGATACTTTAACCAATATAGGAATACA FFFF7FFFFF.7FFAFFF][2]

[1]: https://broadinstitute.github.io/picard/explain-flags.html
[2]: https://ppotato.files.wordpress.com/2010/08/sam_output2.png

Answer: OK. It seems you have paid much attention to this issue. There is nothing wrong in the bam file. Everything in it is subtle. This is because the orientation of the flag means the orientation of the read comparative to the genome which may not have the relation to the real base direction of the genome while the orientation of the tag XS means the orientation of the read comparative to the real base direction of the genome.

And you should extract the precise flag number which is useful here, not 81, 99, etc. with so many meanings in it. If you can type in this command:
samtools view -X *.bam|less
then the r and R in the flag field means the direction information.