Commit 9fde1155 authored by Thonier Florian's avatar Thonier Florian

fuse.py; add functions to compute distributions values

link to #3902
parent 18c2e936
......@@ -741,6 +741,44 @@ class ListWindows(VidjilJson):
return
def compute_distribution(self, list_distrib):
""" list_distrib is a list of distrib to compute """
for filename in self.d["samples"].d["original_names"]:
for clone in self.d["clones"]:
clone.control()
for distrib_pos in range( len(self.d["distributions"]["repertoires"][filename]) ):
distrib = list_distrib[distrib_pos]
clone_values = clone.get_axes_values( distrib )
nb_reads = clone.get_reads(self.get_filename_pos(filename))
self.add_clone_values( filename, distrib_pos, clone_values, nb_reads)
return
def add_clone_values(self, filename, distrib_pos, values, nb_reads):
""" Add value of a clone to a specific distribution """
obj = self.distributions["repertoires"][filename][distrib_pos]["values"]
obj = self.recursive_add(obj, values, nb_reads) ## Add by recursion
self.distributions["repertoires"][filename][distrib_pos]["values"] = obj
return
def recursive_add( self, obj, values, nb_reads):
""" Add by recusivity the newer value to existing value; return the obj """
if len(values) > 1:
# Should increase for one depth
nvalues = values[1:]
obj[values[0]] = self.recursive_add(obj[values[0]], nvalues, nb_reads)
else:
# last depth
if not obj:
obj = defaultdict(lambda: False)
if not obj[values[0]]:
obj[values[0]] = [0, 0]
obj[values[0]][0] += 1
obj[values[0]][1] += nb_reads
return obj
### some data used for test
w1 = Window(1)
w1.d ={"id" : "aaa", "reads" : [5], "top" : 3 }
......
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