Commit 466fbeba authored by Mathieu Giraud's avatar Mathieu Giraud

fuse.py: ListWindows, __iter__/__getitem__/__len__ methods

parent 0ee4e4e9
...@@ -281,13 +281,26 @@ class ListWindows: ...@@ -281,13 +281,26 @@ class ListWindows:
self.d["clusters"] = [] self.d["clusters"] = []
def __str__(self): def __str__(self):
return "<ListWindows : %s %d >" % ( self.d["reads"].d["segmented"], len(self.d["clones"]) ) return "<ListWindows: %s %d>" % ( self.d["reads"].d["segmented"], len(self) )
# Iterator and access functions
def __iter__(self):
return self.d["clones"].__iter__()
def __getitem__(self, i):
### not efficient !
for clone in self:
if clone.d["id"] == i:
return clone
def __len__(self):
return len(self.d["clones"])
### print info about each Windows stored ### print info about each Windows stored
def info(self): def info(self):
print self print self
for i in range(len(self.d["clones"])): for clone in self:
print self.d["clones"][i] print clone
### check vidjil_json_version ### check vidjil_json_version
def check_version(self, filepath): def check_version(self, filepath):
...@@ -301,8 +314,8 @@ class ListWindows: ...@@ -301,8 +314,8 @@ class ListWindows:
ranges = [1000, 100, 10, 1] ranges = [1000, 100, 10, 1]
result = [[0 for col in range(len(self.d['reads'].d["segmented"]))] for row in range(len(ranges))] result = [[0 for col in range(len(self.d['reads'].d["segmented"]))] for row in range(len(ranges))]
for w in self.d["clones"]: for clone in self:
for i, s in enumerate(w.d["reads"]): for i, s in enumerate(clone.d["reads"]):
for r in range(len(ranges)): for r in range(len(ranges)):
if s >= ranges[r]: if s >= ranges[r]:
break break
...@@ -357,9 +370,9 @@ class ListWindows: ...@@ -357,9 +370,9 @@ class ListWindows:
def getTop(self, top): def getTop(self, top):
result = [] result = []
for w in self.d["clones"] : for clone in self:
if w.d["top"] <= top : if clone.d["top"] <= top :
result.append(w.d["id"]) result.append(clone.d["id"])
return result return result
def filter(self, f): def filter(self, f):
...@@ -453,17 +466,16 @@ class ListWindows: ...@@ -453,17 +466,16 @@ class ListWindows:
def cut(self, limit, nb_points): def cut(self, limit, nb_points):
'''Remove information from sequence/windows who never enter in the most represented sequences. Put this information in 'other' windows.''' '''Remove information from sequence/windows who never enter in the most represented sequences. Put this information in 'other' windows.'''
length = len(self.d["clones"]) length = len(self)
w=[] w=[]
others = OtherWindows(nb_points) others = OtherWindows(nb_points)
for index in range(length): for clone in self:
win = self.d["clones"][index] if (int(clone.d["top"]) < limit or limit == 0) :
if (int(win.d["top"]) < limit or limit == 0) : w.append(clone)
w.append(win)
#else: #else:
#others += win #others += clone
self.d["clones"] = w #+ list(others) self.d["clones"] = w #+ list(others)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment