Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/0ed41390408f
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:40:05 2012
Кодировка:

# HG changeset patch
# User boris
# Date 1290874877 -10800
# Node ID 0ed41390408f6fe2100944953c64ee63343e5be5
# Parent 9c79630645114bfeb07788cc90f37c3d7be7246e
repeats: rename group_start and group_end to group_real_start and group_real_end
add new methods group_start and group_end similar to start and end (~ min and ~ max)

diff -r 9c7963064511 -r 0ed41390408f repeats/repeat_joiner.py
--- a/repeats/repeat_joiner.py Sat Nov 27 18:47:13 2010 +0300
+++ b/repeats/repeat_joiner.py Sat Nov 27 19:21:17 2010 +0300
@@ -36,7 +36,7 @@
repeat_pair

in repeat_group (installes in init):
- group_start -- position of real_start() of this repeat in group
+ group_real_start -- position of real_start() of this repeat in group
group_ori -- if position of real_start() of this repeat in the group < position of real_end()
"""

@@ -45,7 +45,7 @@
self.start = pos_from
self.end = pos_to
self.ori = ori
- self.group_start = None # for repr
+ self.group_real_start = None # for repr
self.group_ori = None
if chromosome_name not in repeat_joiner:
repeat_joiner[chromosome_name] = Chromosome(chromosome_name)
@@ -92,33 +92,60 @@
return self.end - self.start

@property
- def group_end(self):
+ def group_real_end(self):
""" reletive end of repeat """
if self.group_ori:
- return self.group_start + len(self)
+ return self.group_real_start + len(self)
else:
- return self.group_start - len(self)
-
+ return self.group_real_start - len(self)
+
+ @property
+ def group_start(self):
+ """ min of repeat positions in group """
+ if self.group_ori:
+ return self.group_real_start
+ else:
+ return self.group_real_end + 1
+
+ @property
+ def group_end(self):
+ """ max of repeat positions in group """
+ if self.group_ori:
+ return self.group_real_end
+ else:
+ return self.group_real_start + 1
+
def inherit_from(self, other):
- """ Use other as source repeat to set group_ori and group_start of this """
+ """ Use other as source repeat to set group_ori and group_real_start of this """
if self.thick_edge() == other:
- self.group_start = other.group_start
+ self.group_real_start = other.group_real_start
self.group_ori = other.group_ori
else:
chromosome_ori = other.ori == other.group_ori
self.group_ori = self.ori == chromosome_ori
delta = self.real_start - other.real_start
if chromosome_ori:
- self.group_start = other.group_start + delta
+ self.group_real_start = other.group_real_start + delta
else:
- self.group_start = other.group_start - delta
+ self.group_real_start = other.group_real_start - delta

def __repr__(self):
- if self.group_start != None:
- return "%s: [%i(%i), %i(%i))" % (self.chromosome, self.real_start, self.group_start, self.real_end, self.group_end)
+ if self.group_real_start != None:
+ return "%s: [%i(%i), %i(%i))" % (self.chromosome, self.real_start,
+ self.group_real_start, self.real_end, self.group_real_end)
else:
return "%s: [%i, %i)" % (self.chromosome, self.real_start, self.real_end)

+ def __str__(self):
+ ori = 1 if self.ori else -1
+ if self.group_real_start != None:
+ group_ori = 1 if self.group_ori else -1
+ return "%s %i %i %i %i %i %i" % (self.chromosome, self.start,
+ self.end, self.group_start, self.group_end, ori, group_ori)
+ else:
+ return "%s %i %i %i" % (self.chromosome, self.start,
+ self.end, ori)
+
class RepeatPair(tuple):
""" (repeat, repeat) """
def __init__(self, repeat1_repeat2):
@@ -133,11 +160,11 @@
self.start = 0

def calc_start(self):
- """ shift all group_end to make min position zero """
- offset = -min(min(repeat.group_start, repeat.group_end)
+ """ shift all grou coordinates to make min position zero """
+ offset = -min(min(repeat.group_real_start, repeat.group_real_end)
for repeat in self)
for repeat in self:
- repeat.group_start += offset
+ repeat.group_real_start += offset

class RepeatJoiner(dict):
""" dictionary {: chromosome}
@@ -197,7 +224,7 @@
for repeat in self._repeats:
if repeat not in used:
repeat.group_ori = True
- repeat.group_start = repeat.real_start
+ repeat.group_real_start = repeat.real_start
repeat_group = RepeatGroup()
self.repeat_groups.append(repeat_group)
q = Queue.Queue()
diff -r 9c7963064511 -r 0ed41390408f repeats/test.py
--- a/repeats/test.py Sat Nov 27 18:47:13 2010 +0300
+++ b/repeats/test.py Sat Nov 27 19:21:17 2010 +0300
@@ -18,17 +18,17 @@
from2 = int(from2)
to2 = int(to2) + 1

- RepeatPair([Repeat(rj, c1, from1, to1, ori1), Repeat(rj, c2, from2, to2, ori2)])
+ r1 = Repeat(rj, c1, from1, to1, ori1)
+ r2 = Repeat(rj, c2, from2, to2, ori2)
+ RepeatPair([r1, r2])

rj.build_groups()
rj.repeat_groups.sort(key=lambda g: len(g), reverse=True)
+
+
print "group\tchr\tchr_from\tchr_to\tgroup_from\tgroup_to\tori\tgroup_ori"
for i, repeat_group in enumerate(rj.repeat_groups):
- repeat_group.sort(key=lambda r: min(r.group_start, r.group_end))
- # pprint.pprint(repeat_group)
+ repeat_group.sort(key=lambda r: r.group_start)
for repeat in repeat_group:
- ori = 1 if repeat.ori else -1
- group_ori = 1 if repeat.group_ori else -1
- print "%i\t%s\t%i\t%i\t%i\t%i\t%i\t%i" % (i, repeat.chromosome, repeat.start,
- repeat.end-1, repeat.group_start, repeat.group_end-1, ori, group_ori)
+ print "%i\t%s" % (i, str(repeat).replace(' ', '\t'))