<commit_before>import re, random, sys,pickle
from tools.SegmentTree import SegmentTree as SegmentTree
from tools.SecureMmap import SecureMmap as SecureMmap
from tools import UsefulFunctions as uf
from tools import SingletonManager

import configuration as conf
from Gene import Gene
from SNP import *

from tools.GTFTools import GTFFile

class GeneNotFound(Exception):
	def __init__(self, chromosome, geneSymbol, message = ''):
		self.message = message
		self.symbol = geneSymbol
		self.chromosome = chromosome
		
	def __str__(self):
		return """
		Description : %s
		gene_symbol : %s
		chromosome : %s\n"""%(self.message, self.symbol, self.chromosome)

class RequestError(Exception):
	def __init__(self, message = ''):
		self.message = message
		
	def __str__(self):
		return """Request Error: %s"""%(self.message)

def defaultSNVsFilter(casavaSnp) :
	"""The default rule to decide wether to take the most probable genotype or the
	reference, always returns true"""
	return True

def defaultDbSNPsFilter(dbSnp) :
	"""The default rule to decide wether to take the most probable genotype or the
	snp, always returns true"""
	return True
	
class Chromosome :
	"""A class that represents a Chromosome
	Attention: private region support en retard par rapport au public"""

	def __init__(self, number, genome, x1, x2, dbSNPVersion = None, verbose = False) :
		"""x1, x2 are the prosition of the chromosome in the genome"""
		self.reset(number, genome, x1, x2, dbSNPVersion, verbose)
		
	def reset(self, number, genome, x1, x2, dbSNPVersion = None, verbose = False) :
		"""x1, x2 are the prosition of the chromosome in the genome"""
		if verbose :
			print "Loading chromosome %s..."%(number)
		
		self.number = str(number).upper()
		self.genome = genome
		self.x1 = int(x1)
		self.x2 = int(x2)
		
		try :
			self.casavaSNPs = SNPFile('%s/chr%s.casavasnps'%(self.genome.getSequencePath(), self.number), CasavaSNP)
			refSeq = '%s/chr%s.dat'%(self.genome.getReferenceSequencePath(), self.number)
			
			if not SingletonManager.contains(refSeq) :
				SingletonManager.add(SecureMmap(refSeq), refSeq)
				
			self.data = SingletonManager.get(refSeq)
				
			self.isLight = True
		except IOError:
			try :
				self.data = SecureMmap('%s/chr%s.dat'%(self.genome.getSequencePath(), self.number))
			except IOError:
				print 'Warning : couldn\'t find local version of chromosome %s, loading reference instead...' % self.number
				self.data = SecureMmap('%s/chr%s.dat'%(self.genome.getReferenceSequencePath(), self.number))
				
			self.isLight = False

		gtfFp = '%s/chr%s.gtf'%(self.genome.getGeneSetsPath(), self.number)
		f = open(gtfFp, 'r')<commit_msg>effacage malencontreux de self.genes in Chromosome regle<commit_after>import re, random, sys,pickle
from tools.SegmentTree import SegmentTree as SegmentTree
from tools.SecureMmap import SecureMmap as SecureMmap
from tools import UsefulFunctions as uf
from tools import SingletonManager

import configuration as conf
from Gene import Gene
from SNP import *

from tools.GTFTools import GTFFile

class GeneNotFound(Exception):
	def __init__(self, chromosome, geneSymbol, message = ''):
		self.message = message
		self.symbol = geneSymbol
		self.chromosome = chromosome
		
	def __str__(self):
		return """
		Description : %s
		gene_symbol : %s
		chromosome : %s\n"""%(self.message, self.symbol, self.chromosome)

class RequestError(Exception):
	def __init__(self, message = ''):
		self.message = message
		
	def __str__(self):
		return """Request Error: %s"""%(self.message)

def defaultSNVsFilter(casavaSnp) :
	"""The default rule to decide wether to take the most probable genotype or the
	reference, always returns true"""
	return True

def defaultDbSNPsFilter(dbSnp) :
	"""The default rule to decide wether to take the most probable genotype or the
	snp, always returns true"""
	return True
	
class Chromosome :
	"""A class that represents a Chromosome
	Attention: private region support en retard par rapport au public"""

	def __init__(self, number, genome, x1, x2, dbSNPVersion = None, verbose = False) :
		"""x1, x2 are the prosition of the chromosome in the genome"""
		self.reset(number, genome, x1, x2, dbSNPVersion, verbose)
		
	def reset(self, number, genome, x1, x2, dbSNPVersion = None, verbose = False) :
		"""x1, x2 are the prosition of the chromosome in the genome"""
		if verbose :
			print "Loading chromosome %s..."%(number)
		
		self.number = str(number).upper()
		self.genome = genome
		self.x1 = int(x1)
		self.x2 = int(x2)
		self.genes = {}
		
		try :
			self.casavaSNPs = SNPFile('%s/chr%s.casavasnps'%(self.genome.getSequencePath(), self.number), CasavaSNP)
			refSeq = '%s/chr%s.dat'%(self.genome.getReferenceSequencePath(), self.number)
			
			if not SingletonManager.contains(refSeq) :
				SingletonManager.add(SecureMmap(refSeq), refSeq)
				
			self.data = SingletonManager.get(refSeq)
				
			self.isLight = True
		except IOError:
			try :
				self.data = SecureMmap('%s/chr%s.dat'%(self.genome.getSequencePath(), self.number))
			except IOError:
				print 'Warning : couldn\'t find local version of chromosome %s, loading reference instead...' % self.number
				self.data = SecureMmap('%s/chr%s.dat'%(self.genome.getReferenceSequencePath(), self.number))
				
			self.isLight = False

		gtfFp = '%s/chr%s.gtf'%(self.genome.getGeneSetsPath(), self.number)
		f = open(gtfFp, 'r')
{'fraction_non_alphanumeric': 0.11638333644685223, 'fraction_numerical': 0.005230711750420325, 'mean_word_length': 4.343313373253493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6384190', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1687, 'n_words': 508}