Many thanks for this, I have done the counting using software..
Hello, I have BAM file has ~ 11M Paired-End reads I'm trying to count the number of fragments in any region. To start; my understanding is that each two(mates) count (1). With the aid of region coordinate from gtf file and BAM fields i'm trying to figure out how many fragments. In BAM file
Col 4 (POS) the starting position of the mate Col 8 (PNEXT) Position of the primary alignment of the NEXT read in the template. Col 9 TLEN: signed observed Template LENgth. If all segments are mapped to the same reference, the unsigned observed template length equals the number of bases from the leftmost mapped base to the rightmost mapped base. so the number in col 4 tells where exactly within the region this mate starts; and the number in col 8 tells the starting position of the other mate starts. col 9 (I'm still confused) does it give the length of the current mate within the region? what does it mean if there is (-)? does that mean it is located on the reverse strand?
in order to count how many fragments assign to the region I used col 4 and 8 then match them?? if i find identical sequences in one location how it would be counted?
Any explanation is greatly appreciated...
EDIT: I HAVE DONE the counting using software but I'm interested in using BAM information in counting
1 answer
Use featureCounts from subread package. Given you have a GTF file and a paired-end BAM, the simplest command would be:
./featureCounts -a file.gtf -o output_countMatrix.txt -F GTF -Q 1 -p input_file.bam
It will count the reads per exon in the GTF, using paired-end data (-p) with a mapping quality > 0 (-Q 1). Multithreading is possible via -T. option.
Log in to answer this question.
If you want to get the counts of aligned reads in respect of a gtf file use tools like FeatureCounts or HTseq-count.
what do you actually mean?
The answer to the question you've framed ("How do I count the fragments from BAM files") has been given with featureCounts.
Are you, in fact, interested in _understanding_ the BAM file entries?