Package bamm :: Module bamRead :: Class ReadSetManager
[hide private]
[frames] | no frames]

Class ReadSetManager

source code

object --+
         |
        ReadSetManager

The principle manager of a collection of ReadSet objects

Determines the exact names of the output files when extracting reads. Ensures that only one thread can write to one file at a time.

Instance Methods [hide private]
 
__init__(self, manager)
Default constructor.
source code
 
invalidateThreads(self)
Stop all the threads from running
source code
 
setResponseQueues(self, queues)
Set response queues used to pass ReadSets to the extract threads
source code
 
setPrintQueue(self, queue)
Set the print queue for communcating upwards
source code
 
getReadSet(self, bid, gid, rpi, threadId)
Ensure that only one thread at a time has access to a read set
source code
 
freeReadSet(self, bid, gid, rpi, threadId)
Indicate that a thread is finished with a read set
source code
 
manageRequests(self)
Manage requests by parsing threads to access ReadSets
source code
 
organiseOutFiles(self, prettyBamFileNames, groupNames, zipped, interleaved, mixBams, mixGroups, mixReads, headersOnly, outFolder, prefix)
Determine all the outFile prefixes needed for extraction.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, manager)
(Constructor)

source code 
Default constructor.

Initializes a ReadSet instance with the provided set of properties.

Inputs:
 manager - multiprocessing.Manager() instance owned by the
           BamExtractor use this to make all Queues.
Outputs:
 None

Overrides: object.__init__

invalidateThreads(self)

source code 
Stop all the threads from running

Also stops any looping processes in the ReadSets

Inputs:
 None
Outputs:
 None

setResponseQueues(self, queues)

source code 
Set response queues used to pass ReadSets to the extract threads

Inputs:
 queues - dict { outPrefix : mp.Manager().Queue() }, one for each
          thread that's parsing BAM files for the BAmExtractor
Outputs:
 None

setPrintQueue(self, queue)

source code 
Set the print queue for communcating upwards

Inputs:
 queue - mp.Manager().Queue(), print queue managed by the BamExtractor
Outputs:
 None

getReadSet(self, bid, gid, rpi, threadId)

source code 
Ensure that only one thread at a time has access to a read set

Inputs:
 bid - int, the unique identifier for a BAM file
 gid - int, the unique identifier for a target group
 rpi - enum, describes the type of read (RPI.FIR etc.)
 threadId - string, identifies the thread that is requesting
            the resource.
Outputs:
 The requested read set or None if it is not available

freeReadSet(self, bid, gid, rpi, threadId)

source code 
Indicate that a thread is finished with a read set

Inputs:
 bid - int, the unique identifier for a BAM file
 gid - int, the unique identifier for a target group
 rpi - enum, describes the type of read (RPI.FIR etc.)
 threadId - string, identifies the thread that is freeing
            the resource.
Outputs:
 None

Raises:
 InvalidParameterSetException - if the supplied information
                                doesn't make sense

manageRequests(self)

source code 
Manage requests by parsing threads to access ReadSets

This process runs on it's own thread and continues until it discovers
a None on the requestQueue or self._threadsAreValid is set to False

Inputs:
 None

Outputs:
 None

organiseOutFiles(self, prettyBamFileNames, groupNames, zipped, interleaved, mixBams, mixGroups, mixReads, headersOnly, outFolder, prefix)

source code 
Determine all the outFile prefixes needed for extraction.

The RSM manages a collection of output file objects called ReadSets
These are made here and placed into hashes for retrieval later. This
function also populates instance variables self.fnPrefix2ReadSet and
self.outFiles; the two main ways that ReadSets can be accessed.

File names vary wildly depending on the values of flags such as:
mixGroups, mixBams etc. Take care when modifying this code.

Inputs:
 prettyBamFileNames - [ string ] simple versions of the BAM filenames
 groupNames - [ string ] identify contig groups. EX: [bin1, bin2]
 zipped - bool, True if the output should be zipped
 interleaved - bool, True if the output should be interleaved
 mixBams - bool, True if BAM file origin should be ignored
 mixGroups - bool, True if group origin should be ignored
 mixReads - bool, True if (un)paired distinction should be ignored
 headersOnly - bool, True if only headers should be printed
 outFolder - string, folder to write output to
 prefix - string, prefix to apply to all output files

Outputs:
 of_prefixes - { bamId : { groupId : { rpi : outFile prefix } } },
               this hash can be used to get the file name prefix for a
               read set based on BAM file origin, group origin and
               pairing information.