2""" @brief Definition of genes as DNA segment having semantics.
"""
4#============================================================================#
5# EVOLIFE http://evolife.telecom-paris.fr Jean-Louis Dessalles
21if __name__ ==
'__main__': sys.path.append(
'../..')
27 """ definition of semantic segments on DNA.
28 A gene is a geographical entity: start_position, end_position, length...
31 def __init__(self, gene_name, gene_length, locus, position, coding):
32 """ A gene knows its name, its length,
33 its locus (order in the list of genes)
and its start
and end position
38 if self.
length == 0:
error(
'Gene definition',
'Zero length with zero Default length')
43 if self.
coding in range(-1,3):
45 self.
coding = [
'Nocoding',
'Weighted',
'Unweighted',
'Gray'][self.
coding+1]
49 return 'L' + str(self.
locus) +
': ' + self.
name +
' ' + str(self.
start) +
'->' + str(self.
end) +
' '
52 """ a Genetic_map is a series of genes, located one after the other
55 """ just calls init_genes
60 """ creates genes and puts them into 'GeneMap'
62 ['genename1',
'genename2',...]: lengths
and coding are retrieved
from configuration.
63 [(
'genename1', 8), (
'genename2', 4),...]: numbers give lengths
in bits; coding
is retrieved
from configuration.
64 [(
'genename1', 8,
'Weighted'), (
'genename2', 4,
'Unweighted'),...]: coding can be
'Weighted',
'Unweighted',
'Gray',
'NoCoding'.
65 Note that
'Unweighted' is unsuitable to explore large space.
71 for GeneDefinition
in gene_list:
73 g_length = self.Parameter(
'GeneLength', Default=0)
74 g_coding = self.Parameter(
'GeneCoding')
75 if isinstance(GeneDefinition, tuple):
76 if len(GeneDefinition) == 2:
77 (g_name,g_length) = GeneDefinition
78 elif len(GeneDefinition) == 3:
79 (g_name,g_length, g_coding) = GeneDefinition
80 else:
error(
"Bad definition of gene map")
81 else: g_name = GeneDefinition
82 if g_length == 0: g_length = self.Parameter(
'GeneLength')
83 NewGene =
Gene_def(g_name, g_length, locus, current_pos, g_coding)
86 current_pos = NewGene.end
89 """ returns GeneMap[locus]
94 error(
"Gene_def: incorrect locus")
97 """ returns the gene's locus
100 if g.name == gene_name:
102 error(
"Genetic_map: unknown gene name: " + str(gene_name))
106 """ finds the name of the gene at locus
111 """ returns genes' names as a list
113 return [g.name
for g
in self.
GeneMap]
116 """ finds the gene's boundaries on the DNA
121 """ returns the gene's coding type (weighted, unweighted, ...)
126 """ finds the gene's boundaries on the DNA
128 return get_boundaries(self,
get_locus(self, gene_name))
131 """ location of the end of the last gene on Genemap
136 """ returns the maximal amplitude of the gene at Locus
138 coding = self.get_gene(Locus).coding.lower()
139 if coding
in [
'weighted',
'gray']:
141 return (1 << self.
get_gene(Locus).length ) - 1
142 elif coding ==
'unweighted':
145 elif coding ==
'nocoding':
148 error(
"Genetic Map",
'unknown binary coding mode: %s' % str(coding))
151 """ returns the maximal amplitude of the gene
156 """ returns a binary mask showing gene alternation on DNA
161 pattern += [G] * g.length
163 return tuple(pattern)
166 return "Genetic map:\n\t" +
'\n\t'.join([g.__str__()
for g
in self.
GeneMap])
170if __name__ ==
"__main__":
172 print(Gene_def.__doc__)
173 print(Genetic_map.__doc__ +
'\n')
182if __name__ ==
"__main__":
183 from Evolife.Scenarii.Parameters
import Parameters
186 Parameters.__init__(self,
'../Evolife.evo')
187 Genetic_map.__init__(self,[(
'sex',1), (
'prems',4),(
'deuze',7),(
'terce',2)])
191 print(GeneMap.gene_pattern())
192 raw_input(
'[Return]')
195__author__ =
'Dessalles'
def __init__(self)
just calls init_genes
definition of semantic segments on DNA.
a Genetic_map is a series of genes, located one after the other
def get_gene_boundaries(self, locus)
finds the gene's boundaries on the DNA
def get_gene_names(self)
returns genes' names as a list
def get_gene(self, locus)
returns GeneMap[locus]
def geneMap_length(self)
location of the end of the last gene on Genemap
def init_genes(self, gene_list)
creates genes and puts them into 'GeneMap' Accepted syntax: ['genename1', 'genename2',...
def __init__(self, GeneMap)
just calls init_genes
def get_coding(self, locus)
returns the gene's coding type (weighted, unweighted, ...)
def gene_range(self, gene_name)
returns the maximal amplitude of the gene
def get_locus(self, gene_name)
returns the gene's locus
def get_gene_name(self, locus)
finds the name of the gene at locus
def gene_pattern(self)
returns a binary mask showing gene alternation on DNA
def locus_range(self, Locus)
returns the maximal amplitude of the gene at Locus
def gene_boundaries(self, gene_name)
finds the gene's boundaries on the DNA