Ejemplo n.º 1
0
 def __init__(self, gaReadGroupSet, samFileName):
     filename = os.path.split(samFileName)[1]
     localId = os.path.splitext(filename)[0]
     self.gaReadGroup = reads.AbstractReadGroup(gaReadGroupSet, localId)
     self.id = self.gaReadGroup.getId()
     self.samFile = pysam.AlignmentFile(samFileName)
     self.reads = []
     self.refIds = collections.defaultdict(list)
     for read in self.samFile:
         if read.reference_id != -1:
             # mapped read
             refId = self.samFile.getrname(read.reference_id)
             self.refIds[refId].append(read)
         self.reads.append(read)
Ejemplo n.º 2
0
 def testGetReadGroup(self):
     path = "/readgroups"
     for dataset in self.backend.getDatasets():
         for readGroupSet in dataset.getReadGroupSets():
             for readGroup in readGroupSet.getReadGroups():
                 responseObject = self.sendGetObject(
                     path, readGroup.getId(), protocol.ReadGroup)
                 self.verifyReadGroupsEqual(responseObject, readGroup)
             for badId in self.getBadIds():
                 readGroup = reads.AbstractReadGroup(readGroupSet, badId)
                 self.verifyGetMethodFails(path, readGroup.getId())
         for badId in self.getBadIds():
             readGroupSet = reads.AbstractReadGroupSet(dataset, badId)
             self.verifyGetMethodFails(path, readGroupSet.getId())
     for badId in self.getBadIds():
         self.verifyGetMethodFails(path, badId)
Ejemplo n.º 3
0
 def __init__(self, gaReadGroupSet, samFile, readGroupName):
     self.gaReadGroup = reads.AbstractReadGroup(gaReadGroupSet,
                                                readGroupName)
     self.id = self.gaReadGroup.getId()
     self.samFile = samFile
     self.mappedReads = collections.defaultdict(list)
     for read in self.samFile:
         tags = dict(read.tags)
         if 'RG' not in tags or tags['RG'] != readGroupName:
             continue
         if read.reference_id != -1:
             # mapped read
             referenceName = self.samFile.getrname(read.reference_id)
             self.mappedReads[referenceName].append(read)
     self.numAlignedReads = -1
     self.numUnalignedReads = -1
     self.programs = []
     if 'PG' in self.samFile.header:
         self.programs = self.samFile.header['PG']
     self.sampleId = None
     self.description = None
     self.predictedInsertSize = None
     self.instrumentModel = None
     self.sequencingCenter = None
     self.experimentDescription = None
     self.library = None
     self.platformUnit = None
     self.runTime = None
     if 'RG' in self.samFile.header:
         readGroupHeader = [
             rgHeader for rgHeader in self.samFile.header['RG']
             if rgHeader['ID'] == readGroupName
         ][0]
         self.sampleId = readGroupHeader.get('SM', None)
         self.description = readGroupHeader.get('DS', None)
         if 'PI' in readGroupHeader:
             self.predictedInsertSize = int(readGroupHeader['PI'])
         self.instrumentModel = readGroupHeader.get('PL', None)
         self.sequencingCenter = readGroupHeader.get('CN', None)
         self.experimentDescription = readGroupHeader.get('DS', None)
         self.library = readGroupHeader.get('LB', None)
         self.platformUnit = readGroupHeader.get('PU', None)
         self.runTime = readGroupHeader.get('DT', None)
Ejemplo n.º 4
0
 def testNonexistantReadGroup(self):
     # a request for a readGroup that doesn't exist should throw an error
     readGroup = reads.AbstractReadGroup(self.readGroupSet, 'notFound')
     self.request.readGroupIds = [readGroup.getId()]
     with self.assertRaises(exceptions.ReadGroupNotFoundException):
         self.backend.readsGenerator(self.request)
Ejemplo n.º 5
0
 def getReadGroup(self):
     return reads.AbstractReadGroup(self.getReadGroupSet(), "readGroup")