Hi, This question is for those who are familiar with pysam.
pysam is used as follows:
samfile = pysam.AlignmentFile('file.bam', 'rb')
In the examples shown in the documentation, he always ends the code with:
Similar to when closing a file in python.
I can't find anything about the exact purpose of this in the documentation for pysam. Is it similar to when closing a regular file?
I'm asking because I wan't to create a function where samfile is returned to the caller function. Would I then need to close the samfile in the caller function?
def open_bam(file): samfile = pysam.AlignmentFile(file, 'rb') return samfile samfile.close()
And then use it as follows:
def analyze_bam(sfile): for read in sfile.fetch(): print read sfile.close()
Or can I simply skip closing it in analyze_bam()?