Analogy of exifread library in pysam for bam and vcf header files
0
0
Entering edit mode
5.9 years ago
aiteteji ▴ 10

Hi Biostars community,

Is there an analogous way in Pysam to the code below to extract the header information in .bam and .vcf (or .vcf.gz) files? Help with a code snippet will great. The code snippet below uses exifread library to get the meta-info (in key-value pair) in jpeg and tiff files.

import exifread

def acPostProcForPut(rule_args, callback, rei): sv = session_vars.get_map(rei) phypath = sv['data_object']['file_path'] objpath = sv['data_object']['object_path'] exiflist = [] with open(phypath, 'rb') as f: tags = exifread.process_file(f, details=False) for (k, v) in tags.iteritems(): if k not in ('JPEGThumbnail', 'TIFFThumbnail', 'Filename', 'EXIF MakerNote'): exifpair = '{0}={1}'.format(k, v) exiflist.append(exifpair) exifstring = '%'.join(exiflist) <post>

bam vcf pysam bcftools htslib • 1.5k views
ADD COMMENT
0
Entering edit mode
ADD REPLY
0
Entering edit mode

Thanks for posting the link. I read it, but I didn't get how to remove the "@" in .bam and "##" in vcf file. I was hoping that someone who knows better can help. Here is my approach:

import pysam

pysamlist = []

with pysam.AlignmentFile("ex1.bam", "rb") as f:
    tags = pysam.view("-h", f)
    for (k, v) in tags.iteritems():
        pysampair = '{0}={1}'.format(k, v)
        pysamlist.append(pysampair)
    pysamstring = '%'.join(pysamlist)
ADD REPLY
0
Entering edit mode

Could you please give an example how your output should look like?

ADD REPLY

Login before adding your answer.

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