Type error in argument header
0
0
Entering edit mode
4.6 years ago
sam ▴ 30

Hi All, I have tried toe dit the bam file by adding the cell barcode and UMI to the read name of my bam file. While writing out to a bam file, i get TypeError: Argument 'header' has incorrect type.

samfile = pysam.AlignmentFile("sample.bam", "rb")
header = samfile.header
print (header)
outfile=pysam.AlignmentFile("sample_final.bam", "wb", template=samfile)
for read in samfile:

  if read.has_tag('CB'):
     CB=read.get_tag('CB')
     UB=read.get_tag('UB')
     split_read1=str(read).split('\t')
     Corrected_readname1=read.query_name+'_'+UB+'_'+CB.split('-')[0]
     final_read1=Corrected_readname1+'\t'+str(split_read1[1:])[1:-1].replace('"','')
     outfile.write(pysam.libcalignedsegment.AlignedSegment(final_read1))

The error i get is : TypeError: Argument 'header' has incorrect type (expected pysam.libcalignmentfile.AlignmentHeader, got str)

Thanks in advance!

alignment pysam • 1.2k views
ADD COMMENT
0
Entering edit mode

Hi, Any suggestions to get rid of the TypeError?

ADD REPLY

Login before adding your answer.

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