I am using this code to filter a bam file for mapping quality but its not working rightly. Instead of producing a new file it is giving strange characters.
pysam.view("-q", "30","-b",filename,"pysam.bam")
Where filename is the name of bam file i.e 'reads.sorted.bam'
Output:
\x1f\x8b\x08\x04\x00\x00\x00\x00\x00\xff\x06\x00BC\x02\x00\xbf\x00sr\xf4e\x9c\xc1\xc0\xc0\xe0\xe0\xe1\xc2\x19\xe6ge\xa8g\xcc\x19\xeco\x95\x9c '....
How can I get a filtered file based on mapping qualities using above code??
your output looks like a binary header of a valid BAM :
The complete output of my above python script is given below: \x1f\x8b\x08\x04\x00\x00\x00\x00\x00\xff\x06\x00BC\x02\x00\xbf\x00sr\xf4e\x9c\xc1\xc0\xc0\xe0\xe0\xe1\xc2\x19\xe6ge\xa8g\xcc\x19\xeco\x95\x9c\x9f_\x94\x92\x99\x97X\x92\xca\xe5\x10\x1c\xc8\x19\xecg\x95\x9eYcdjhalhh
VS\x94\x9aV\xe3\xe7\x1co
hdid\xa0gX\xc3\xe9\x03\xd4ifjf\xc9\xe5\x10\xe0\xce\xe9\xe9b\x95T\x9e\xc8\x19\xe0\x07\xa6\x80\x86\x1a\xe8\x99\xeb\x19\x1a\xe9\x16\x19\x1a\x18[r:\xfb\x80\x84\x15\x8a\x13s\x8bS\x15\x8a\x92\x8b\x8a\xf5\xd2\x12\x15\x12s\xf2",,\xf4\x8a\x133\x15"\n\x8aR\x8b\x8b\x81\x9c\xb4\xc4\xe2\x92B.F\xa0\xdb\xe4\x80\x18\xaf\xfd\x0c;\x1d\x18\x18\x00\x99\x18\x95\x8c\xca\x00\x00\x00\x1f\x8b\x08\x04\x00\x00\x00\x00\x00\xff\x06\x00BC\x02\x00\x1b\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00'Don't know whether it looks like header or not because your command for header produces larger no of lines, as given below
output:
0000000 8b1f 0408 0000 0000 ff00 0006 4342 0002 0000010 00bf 7273 65f4 c19c c0c0 e0e0 c2e1 e619 0000020 6567 67a8 19cc 6fec 9c95 5f9f 9294 9799 0000030 9258 e5ca 1c10 19c8 67ec 9e95 6359 6a64 0000040 6168 686c 6068 5356 9a94 e356 1ce7 606f 0000050 6468 6469 67a0 c358 03e9 69d4 6a66 c966 0000060 10e5 cee0 e9e9 9562 9e54 19c8 07e0 80a6 0000070 1a86 99e8 19eb e91a 1916 181a 725b fb3a 0000080 8480 8a15 7313 538b 8a15 8b92 f58a 12d2 0000090 1215 f273 2c22 f42c 138a 1533 0a22 528a
output:
229087