Adding annotations to the bam file from the txt file
1
0
Entering edit mode
4.5 years ago
ssaaren • 0

Dear all,

I have bam file (bamfile.bam) where I need to add a flag and annotation from text file.

The bam file looks like this:

NS500688:631:HFLVJBGXF:1:11105:17585:2382       4       *       0       0       *       *       0       0       GTTGTGAAACATCTCAGTACCCACAGGAAGA //A///EEEEEAEEEE//EEA<EAEEEEEAE B0:Z:AGTTCCCGCATAGTGCC       B3:Z:ATCTTTA    RG:Z:0  B0:Z:AGTTCCCGCATAGTGCCG B1:Z:4  B2:Z:18

Then I have in a txt file (annotations.txt) all the annotations.

NS500688:631:HFLVJBGXF:1:11105:17585:2382       TRINITY_DN3616_c0_g2_i2: 121: 0: 31M`

I want to add the annotation to the bam file with the XF flag so that it will look like this:

NS500688:631:HFLVJBGXF:1:11105:17585:2382       4       *       0       0       *       *       0       0       GTTGTGAAACATCTCAGTACCCACAGGAAGA //A///EEEEEAEEEE//EEA<EAEEEEEAE B0:Z:AGTTCCCGCATAGTGCC       B3:Z:ATCTTTA    RG:Z:0  B0:Z:AGTTCCCGCATAGTGCCG B1:Z:4  B2:Z:18  XF:Z:TRINITY_DN3616_c0_g2_i2: 121: 0: 31M`

Basically each row in bam file should have the XF:Z: + annotation included after the correct read. What would be the best way to do this?

Thanks a lot!

RNA-Seq sequence bam samtools • 1.0k views
ADD COMMENT
0
Entering edit mode

how big is the annotations.txt file ?

ADD REPLY
0
Entering edit mode

I'm not sure those spaces in TRINITY_DN3616_c0_g2_i2: 121: 0: 31M are valid.

ADD REPLY
0
Entering edit mode
4.5 years ago
Ido Tamir 5.2k

"best" is subjective. In python I would read in the the annotations per name into a dict, then iterate through the bam file with pysam adding the annotation based on the read name writing each one out into a new bam file

ADD COMMENT

Login before adding your answer.

Traffic: 1672 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6