<commit_before>import configuration as conf

from pyGenoObjectBases import *

import rabaDB.fields as rf

from tools import UsefulFunctions as uf
from Exon import *
from SNP import SNP_INDEL

from tools.BinarySequence import NucBinarySequence


class Transcript_Raba(pyGenoRabaObject) :
	"""The wrapped Raba object that really holds the data"""
	
	_raba_namespace = conf.pyGeno_RABA_NAMESPACE

	id = rf.Primitive()
	name = rf.Primitive()
	length = rf.Primitive()
	start = rf.Primitive()
	end = rf.Primitive()
	coding = rf.Primitive()
	
	genome = rf.RabaObject('Genome_Raba')
	chromosome = rf.RabaObject('Chromosome_Raba')
	gene = rf.RabaObject('Gene_Raba')
	protein = rf.RabaObject('Protein_Raba')
	exons = rf.Relation('Exon_Raba')
	
	def _curate(self) :
		if self.name != None :
			self.name = self.name.upper()
		
		self.length = abs(self.end - self.start)
		if self.exons[0].CDS_start is not None and self.exons[-1].CDS_end is not None :
			self.coding = True
		else :
			self.coding = False

class Transcript(pyGenoRabaObjectWrapper) :
	"""The wrapper for playing with Transcripts"""
	
	_wrapped_class = Transcript_Raba

	def __init__(self, *args, **kwargs) :
		pyGenoRabaObjectWrapper.__init__(self, *args, **kwargs)
		self.exons = RLWrapper(self, Exon, self.wrapped_object.exons)
		self._load_sequencesTriggers = set(["UTR5", "UTR3", "cDNA", "sequence"])
		self.exonsDict = {}
	
	def _makeLoadQuery(self, objectType, *args, **coolArgs) :
		if issubclass(objectType, SNP_INDEL) :
			# conf.db.enableDebug(True)
			f = RabaQuery(objectType, namespace = self._wrapped_class._raba_namespace)
			coolArgs['species'] = self.genome.species
			coolArgs['chromosomeNumber'] = self.chromosome.number
			coolArgs['start >='] = self.start
			coolArgs['start <'] = self.end
		
			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)
		
	def _load_sequences(self) :
		def getV(k) :
			return pyGenoRabaObjectWrapper.__getattribute__(self, k)

		def setV(k, v) :
			return pyGenoRabaObjectWrapper.__setattr__(self, k, v)

		sequence = []
		cDNA = []
		UTR5 = []
		UTR3 = []
		exons = []
		prime5 = True
		for ee in self.wrapped_object.exons :
			e = pyGenoRabaObjectWrapper_metaclass._wrappers[Exon_Raba](wrapped_object_and_bag = (ee, getV('bagKey')))
			self.exonsDict[(e.start, e.end)] = e
			exons.append(e)
			sequence.append(e.sequence)

			if e.hasCDS() :
				UTR5.append(e.UTR5)
				cDNA.append(e.CDS)
				UTR3.append(e.UTR3)
				prime5 = False
			else :<commit_msg>fixing coding bug<commit_after>import configuration as conf

from pyGenoObjectBases import *

import rabaDB.fields as rf

from tools import UsefulFunctions as uf
from Exon import *
from SNP import SNP_INDEL

from tools.BinarySequence import NucBinarySequence


class Transcript_Raba(pyGenoRabaObject) :
	"""The wrapped Raba object that really holds the data"""
	
	_raba_namespace = conf.pyGeno_RABA_NAMESPACE

	id = rf.Primitive()
	name = rf.Primitive()
	length = rf.Primitive()
	start = rf.Primitive()
	end = rf.Primitive()
	coding = rf.Primitive()
	
	genome = rf.RabaObject('Genome_Raba')
	chromosome = rf.RabaObject('Chromosome_Raba')
	gene = rf.RabaObject('Gene_Raba')
	protein = rf.RabaObject('Protein_Raba')
	exons = rf.Relation('Exon_Raba')
	
	def _curate(self) :
		if self.name != None :
			self.name = self.name.upper()
		
		self.length = abs(self.end - self.start)
		have_CDS_start = False
		have_CDS_end = False
		for exon in self.exons :
			if exon.CDS_start is not None :
				have_CDS_start = True
			if exon.CDS_end is not None :
				have_CDS_end = True

		if have_CDS_start and have_CDS_end :
			self.coding = True
		else :
			self.coding = False

class Transcript(pyGenoRabaObjectWrapper) :
	"""The wrapper for playing with Transcripts"""
	
	_wrapped_class = Transcript_Raba

	def __init__(self, *args, **kwargs) :
		pyGenoRabaObjectWrapper.__init__(self, *args, **kwargs)
		self.exons = RLWrapper(self, Exon, self.wrapped_object.exons)
		self._load_sequencesTriggers = set(["UTR5", "UTR3", "cDNA", "sequence"])
		self.exonsDict = {}
	
	def _makeLoadQuery(self, objectType, *args, **coolArgs) :
		if issubclass(objectType, SNP_INDEL) :
			# conf.db.enableDebug(True)
			f = RabaQuery(objectType, namespace = self._wrapped_class._raba_namespace)
			coolArgs['species'] = self.genome.species
			coolArgs['chromosomeNumber'] = self.chromosome.number
			coolArgs['start >='] = self.start
			coolArgs['start <'] = self.end
		
			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)
		
	def _load_sequences(self) :
		def getV(k) :
			return pyGenoRabaObjectWrapper.__getattribute__(self, k)

		def setV(k, v) :
			return pyGenoRabaObjectWrapper.__setattr__(self, k, v)

		sequence = []
		self.data = []
		cDNA = []
		UTR5 = []
		UTR3 = []
		exons = []
		prime5 = True
		for ee in self.wrapped_object.exons :
			e = pyGenoRabaObjectWrapper_metaclass._wrappers[Exon_Raba](wrapped_object_and_bag = (ee, getV('bagKey')))
			self.exonsDict[(e.start, e.end)] = e
			exons.append(e)
			sequence.append(e.sequence)
			self.data.extend(e.data)
			
			if e.hasCDS() :
				UTR5.append(e.UTR5)
				cDNA.append(e.CDS)
				UTR3.append(e.UTR3)
				prime5 = False
			else :
{'fraction_non_alphanumeric': 0.12341262743695225, 'fraction_numerical': 0.005008048649615454, 'mean_word_length': 4.015246636771301, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4361217', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2059, 'n_words': 428}