This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extract counts from paired end bam files

I have two bam file for each sample which are paired end sequenced. I need to extract raw counts from these bam files which they look like S1.bam and s2.bam for each sample. I founf these by a search but still don't know how to move forward as they are paired end and two bam files.

featureCounts -T 4 -s 2 \   -a ~/annotations/Homo_sapiens.GRCh38.104.gtf
\   -o ~/results/counts/s1_featurecounts.txt \  
~/results/STAR/bams/*.out.bam

Apparently as they are paired, they need to be sorted by

samtools sort

but I don’t know how to make a single bam file from the two paired that I already have. And how to insert it in this formula. Any help would be appreciated.

featurecounts fastqc star samtools

1 answer

It's far simpler than you probably think. featureCounts will sort paired-end files as needed if you tell it that the data are paired. You don't need to manually do any sorting or indexing. In fact I never sort files from STAR as featureCounts anyway would sort them back by name in case of paired-end data.

#/ The -p flag tells it to consider the files as paired-end
featureCounts -T 4 -s 2 -a ~/annotations/Homo_sapiens.GRCh38.104.gtf \
  -p \
  -o ~/results/counts/s1_featurecounts.txt \
  ~/results/STAR/bams/*.out.bam

There is not more to do, no merging or whatever.

Thanks for your quick resoponse ATpoint , but how can I add my two paired bam files here in this formula?

It's the ~/results/STAR/bams/*.out.bam part, it means "use all bam files". Alternatively replace that with the paths to your bam files.

how can I add my two paired bam files here in this formula?

I hope you did not align your paired-end reads independently i.e. Read 1 is in S1.bam and R2 is in S2.bam. That would be incorrect. You have to align paired-end data in a single alignment run.

I didn't align anything. I just put two end paired bam files that I had in a folder and run the above code by changing only .out.bam to .bam. This worked but I don't know if this is correct or not.

BAM files are not paired-end but they can have alignments that came from a paired-end dataset. Hopefully that is clear.

Two bams implies two different samples. You could combine them if you are sure they are the same thing, but it doesn't sound like you are sure.

Log in to answer this question.