Editing BAM file using pysam
1
0
Entering edit mode
4.6 years ago
sam ▴ 30

Hi All, I am working with a BAM file generated using cell ranger. I am trying to edit the BAM file where i want the cell barcode and UMI to be added to the read name. The cell barcode is provided in CR tag and error corrected cell barcode is provided in CB tag. Similarly, for UMI, UR is UMI and UB is error corrected. I am using pysam to to edit the BAM file.

bamfile = pysam.AlignmentFile("sample.bam", "rb")
for read in bamfile.fetch('chr1',100,1000):
  if read.has_tag('CB'):
     CB=read.get_tag('CB')
     UB=read.get_tag('UB')
     EditedReadName=read.query_name+'_'+CB.split('-')[0]+'_'+UBenter code here

Now i wanted to add the other columns of the read (as it is) to the edited read name. I tried to split the line but the pysam.libcalignedsegment.AlignedSegment' object has no attribute split. Any help? Thanks in advance!

alignment • 2.8k views
ADD COMMENT
1
Entering edit mode
4.6 years ago

If you are trying to split the read, convert to str() and then str(read).split("\t").

read.get_tag already returns string.

ADD COMMENT
0
Entering edit mode

Thank you Geek for your suggestion!

ADD REPLY
0
Entering edit mode

Please accept the answer if it solved your issue. Otherwise it will bump into feed in future unnecessarily .

ADD REPLY

Login before adding your answer.

Traffic: 2018 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