From 51955a66529690d37b51471a04c9ca11159b8a14 Mon Sep 17 00:00:00 2001 From: Sam Minot Date: Mon, 5 Feb 2024 16:13:46 -0800 Subject: [PATCH] Fix up indexing --- bin/bin_metagenomes.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/bin_metagenomes.py b/bin/bin_metagenomes.py index c54d767..0ca8933 100755 --- a/bin/bin_metagenomes.py +++ b/bin/bin_metagenomes.py @@ -170,6 +170,7 @@ def from_read_alignments( self.calc_bin_silhouette_score() self.est_genome_abund() self.calc_rel_abund() + del self.data.uns["filtered_out"] return self @@ -464,7 +465,7 @@ def est_genome_abund(self): genome_abund .T .reindex( - index=self.data.obs_names, + index=self.filtered_samples, columns=group_profile.columns.values ) ), @@ -475,7 +476,7 @@ def est_genome_abund(self): ) ) .reindex( - index=self.data.obs_names + index=self.filtered_samples ) ), var=( @@ -527,7 +528,12 @@ def calc_rel_abund(self, mods=None, prefix="Relative to "): assert kw in self.data.mod["genes"].obs new_kw = f"{prefix}{label}" logger.info(f"Computing {mod} {new_kw}") - rel_abund = (abund.T / self.data.mod["genes"].obs[kw]).T + rel_abund = ( + abund.T / + self.data.mod["genes"].obs[kw].reindex( + index=abund.index.values + ) + ).T self.data.mod[mod].layers[new_kw] = rel_abund def compare_groups(self, category, mods=None): @@ -1138,7 +1144,11 @@ def box( hue_df .reset_index() .melt( - id_vars=[hue_df.index.name], + id_vars=[( + "index" + if hue_df.index.name is None + else hue_df.index.name + )], var_name="variable" ) )