def _getSequence(self, slic):
        data = self.data[slic]
        SNPTypes = self.chromosome.genome.SNPTypes

        if SNPTypes is None or self.refOnly:
            return data

        iterators = []
        for setName, SNPType in SNPTypes.iteritems():
            f = RabaQuery(str(SNPType),
                          namespace=self.chromosome._raba_namespace)
            f.addFilter({
                'start >=': slic.start,
                'start <': slic.stop,
                'setName': str(setName),
                'chromosomeNumber': self.chromosome.number
            })
            # conf.db.enableDebug(True)
            iterators.append(f.iterRun(sqlTail='ORDER BY start'))

        if len(iterators) < 1:
            return data

        polys = {}
        for iterator in iterators:
            for poly in iterator:
                if poly.start not in polys:
                    polys[poly.start] = {poly.setName: poly}
                else:
                    polys[poly.start][poly.setName] = poly

        data = list(data)
        for start, setPolys in polys.iteritems():

            seqPos = start - slic.start
            sequenceModifier = self.SNPFilter.filter(self.chromosome,
                                                     **setPolys)
            # print sequenceModifier.alleles
            if sequenceModifier is not None:
                if sequenceModifier.__class__ is SF.SequenceDel:
                    data = data[:seqPos] + data[seqPos +
                                                sequenceModifier.length:]
                elif sequenceModifier.__class__ is SF.SequenceSNP:
                    data[seqPos] = sequenceModifier.alleles
                elif sequenceModifier.__class__ is SF.SequenceInsert:
                    data[seqPos] = "%s%s" % (sequenceModifier.bases,
                                             data[seqPos])
                else:
                    raise TypeError(
                        "sequenceModifier on chromosome: %s starting at: %s is of unknown type: %s"
                        % (self.chromosome.number, snp.start,
                           sequenceModifier.__class__))
        # print data
        return ''.join(data)
Exemple #2
0
	def getSequenceData(self, slic) :
		data = self.data[slic].decode('utf-8')
		SNPTypes = self.chromosome.genome.SNPTypes
		if SNPTypes is None or self.refOnly :
			return data
		
		iterators = []
		for setName, SNPType in SNPTypes.items() :
			f = RabaQuery(str(SNPType), namespace = self.chromosome._raba_namespace)
			
			chromosomeNumber = self.chromosome.number

			if chromosomeNumber == 'MT':
				chromosomeNumber = 'M'
			
			f.addFilter({'start >=' : slic.start, 'start <' : slic.stop, 'setName' : str(setName), 'chromosomeNumber' : chromosomeNumber})
			# conf.db.enableDebug(True)
			iterators.append(f.run(sqlTail = 'ORDER BY start', gen=True))
		
		if len(iterators) < 1 :
			return data
		
		polys = {}
		for iterator in iterators :
			for poly in iterator :
				if poly.start not in polys :
					polys[poly.start] = {poly.setName : poly}
				else :
					try :
						polys[poly.start][poly.setName].append(poly)
					except :
						polys[poly.start][poly.setName] = [polys[poly.start][poly.setName]]
						polys[poly.start][poly.setName].append(poly)
						
		data = list(data)
		for start, setPolys in polys.items() :
			
			seqPos = start - slic.start
			sequenceModifier = self.SNPFilter.filter(self.chromosome, **setPolys)
			# print sequenceModifier.alleles
			if sequenceModifier is not None :
				if sequenceModifier.__class__ is SF.SequenceDel :
					seqPos = seqPos + sequenceModifier.offset
					#To avoid to change the length of the sequence who can create some bug or side effect
					data[seqPos:(seqPos + sequenceModifier.length)] = [''] * sequenceModifier.length
				elif sequenceModifier.__class__ is SF.SequenceSNP :
					data[seqPos] = sequenceModifier.alleles
				elif sequenceModifier.__class__ is SF.SequenceInsert :
					seqPos = seqPos + sequenceModifier.offset
					data[seqPos] = "%s%s" % (data[seqPos], sequenceModifier.bases)
				else :
					raise TypeError("sequenceModifier on chromosome: %s starting at: %s is of unknown type: %s" % (self.chromosome.number, snp.start, sequenceModifier.__class__))

		return data
	def _makeLoadQuery(self, objectType, *args, **coolArgs) :
		# conf.db.enableDebug(True)
		f = RabaQuery(objectType._wrapped_class, namespace = self._wrapped_class._raba_namespace)
		coolArgs[self._wrapped_class.__name__[:-5]] = self.wrapped_object #[:-5] removes _Raba from class name

		if len(args) > 0 and type(args[0]) is types.ListType :
			for a in args[0] :
				if type(a) is types.DictType :
					f.addFilter(**a)
		else :
			f.addFilter(*args, **coolArgs)

		return f
Exemple #4
0
	def _makeLoadQuery(self, objectType, *args, **coolArgs) :
		if issubclass(objectType, SNP_INDEL) :
			f = RabaQuery(objectType, namespace = self._wrapped_class._raba_namespace)
			coolArgs['species'] = self.genome.species
			coolArgs['chromosomeNumber'] = self.number

			if len(args) > 0 and type(args[0]) is types.ListType :
				for a in args[0] :
					if type(a) is types.DictType :
						f.addFilter(**a)
			else :
				f.addFilter(*args, **coolArgs)

			return f
		
		return pyGenoRabaObjectWrapper._makeLoadQuery(self, objectType, *args, **coolArgs)