Commit 7a2fe556 authored by Penom Nom's avatar Penom Nom
Browse files

Fix bug on remove row.

Clean sum calculation in several methods.
parent 1a3548fb
......@@ -186,7 +186,7 @@ class SparseData( dict ):
if self.has_key( remove_idx ):
del self[remove_idx]
# Change indexes
all_rows_idx = self.keys()
all_rows_idx = sorted( self.keys(), key=int )
for row_idx in all_rows_idx:
if row_idx > remove_idx:
self[row_idx - 1] = self[row_idx]
......@@ -379,12 +379,12 @@ class Biom:
@param min_nb : [int] The observations with a count inferior to 'min_nb' is removed.
@param max_nb : [int] The observations with a count superior to 'min_nb' is removed.
"""
OTU_count, nb_total_elts = self._count_by_OTU()
removed_OTU_names = list()
for current_OTU in OTU_count:
if current_OTU['nb'] < min_nb or (max_nb is not None and current_OTU['nb'] > max_nb):
removed_OTU_names.append( current_OTU["id"] )
self.remove_observations( removed_OTU_names )
removed_obs_names = list()
for observation_idx in range( len(self.rows) ):
observation_count = self.data.get_row_sum( observation_idx )
if observation_count < min_nb or (max_nb is not None and observation_count > max_nb):
removed_obs_names.append( self.rows[observation_idx]["id"] )
self.remove_observations( removed_obs_names )
def merge_samples( self, samples, merged_sample_id=None ):
"""
......@@ -455,12 +455,9 @@ class Biom:
"""
nb_total_elt = 0
OTU_count = list()
for row_idx in range(len(self.rows)):
nb_elt_for_OTU = 0
for columns_idx in range(len(self.columns)):
nb_elt_for_OTU += self.data.nb_at( row_idx, columns_idx )
for row_idx in range( len(self.rows) ):
OTU_count.append( { "id" : self.rows[row_idx]["id"],
"nb" : nb_elt_for_OTU } )
"nb" : self.get_row_sum( row_idx ) } )
nb_total_elt += nb_elt_for_OTU
return OTU_count, nb_total_elt
......
Supports Markdown
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