This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Type error in argument header

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

Hi, Any suggestions to get rid of the TypeError?

0 answers

No answers yet.

Log in to answer this question.