Skip to content

Commit

Permalink
Lint code
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrofale committed Jun 8, 2022
1 parent 4bad61f commit 49bacd0
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions scatrex/scatrex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,16 +1551,28 @@ def plot_cnv_inheritance(self):

def plot_proportions(self, dna=True, rna=True, show=True):
if dna:
dna_props = np.array([self.observed_tree.tree_dict[node]['weight'] for node in self.observed_tree.tree_dict])
dna_props = np.array(
[
self.observed_tree.tree_dict[node]["weight"]
for node in self.observed_tree.tree_dict
]
)
nodes_labels = np.array([node for node in self.observed_tree.tree_dict])
colors = np.array([self.observed_tree.tree_dict[node]['color'] for node in self.observed_tree.tree_dict])
colors = np.array(
[
self.observed_tree.tree_dict[node]["color"]
for node in self.observed_tree.tree_dict
]
)
s = np.argsort(np.array(nodes_labels))
dna_nodes_labels = nodes_labels[s]
dna_colors = colors[s]
dna_props = dna_props[s]

if rna:
rna_nodes, rna_props = self.ntssb.get_node_data_sizes(normalized=True, super_only=True)
rna_nodes, rna_props = self.ntssb.get_node_data_sizes(
normalized=True, super_only=True
)
nodes_labels = [node.label for node in nodes]
s = np.argsort(np.array(nodes_labels))
rna_nodes = np.array(rna_nodes)[s]
Expand All @@ -1570,12 +1582,19 @@ def plot_proportions(self, dna=True, rna=True, show=True):

if dna and rna:
if set(dna_nodes_labels) != set(rna_nodes_labels):
raise ValueError(f"DNA and RNA nodes are not the same! DNA: {dna_nodes_labels}, RNA: {rna_nodes_labels}")
raise ValueError(
f"DNA and RNA nodes are not the same! DNA: {dna_nodes_labels}, RNA: {rna_nodes_labels}"
)
handles = []
for i, node in enumerate(rna_nodes):
dna_bottom = np.sum(dna_props[:i])
rna_bottom = np.sum(rna_props[:i])
h = plt.bar(['DNA', 'RNA'], [dna_props[i], rna_props[i]], color=[dna_colors[i], rna_colors[i]], bottom=[dna_bottom, rna_bottom])
h = plt.bar(
["DNA", "RNA"],
[dna_props[i], rna_props[i]],
color=[dna_colors[i], rna_colors[i]],
bottom=[dna_bottom, rna_bottom],
)
handles.append(h[0])
plt.legend(handles, nodes_labels)
else:
Expand Down

0 comments on commit 49bacd0

Please sign in to comment.