AlignmentFile takes as the first argument:
filepath_or_object
So instead of supplying a filename, you can supply an object that supports a file-like interface, i.e. the methods seek
, read
, tell
.
When implementing a class for this, you can also implement caching on the reads, which of course have to depend on current cursor position.
If filesize is small enough so that it fits into memory, you can read the complete file and operate on an io.BytesIO
object, no need to make your own class:
data = io.BytesIO(open('datafile','rb').read())
your_object = AlignmentFile(data, <other args>)
I am not sure that this will speed things up much, because i assume that modern operating systems (i know linux will do that) do cache file access. So maybe it is enough to rely on that.
io.BytesIO
object and then passing it toAlignmentFile
results inio.UnsupportedOperation: fileno
– Delinquency