Skip to content

Commit

Permalink
added one new edge case to plottedgraph and associated test to test_p…
Browse files Browse the repository at this point in the history
…lotting
  • Loading branch information
fairliereese committed May 29, 2020
1 parent b3f5e64 commit 14da6a9
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
10 changes: 9 additions & 1 deletion swan_vis/plottedgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,16 @@ def init_plot_settings(self, sg,
else:
self.graph_type = 'summary'


# if we have new datasets
if len(list(set(old_dataset_cols)-set(self.dataset_cols))) != 0:
self.new_gene(sg)
if not self.browser:
self.calc_node_edge_styles()
self.get_ordered_edges()

# plotting the same transcript
if old_tid == self.tid and self.tid != None:
elif old_tid == self.tid and self.tid != None:
if not browser:
if old_indicate_dataset != self.indicate_dataset \
or old_indicate_novel != self.indicate_novel:
Expand Down
7 changes: 5 additions & 2 deletions swan_vis/swangraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,8 @@ def find_ir_genes(self):
if len(temp_df.index) > 0:
ir_genes.append(gid)

print('Found {} novel ir events from {} genes.'.format(len(ir_genes),
len(list(set(ir_genes)))))
ir_genes = list(set(ir_genes))
return ir_genes

Expand Down Expand Up @@ -1100,6 +1102,8 @@ def find_es_genes(self):
if len(temp_df.index) > 0:
es_genes.append(gid)

print('Found {} novel es events from {} genes.'.format(len(es_genes),
len(list(set(es_genes)))))
es_genes = list(set(es_genes))
return es_genes

Expand Down Expand Up @@ -1560,8 +1564,7 @@ def gen_report(self,
t_df = reset_dupe_index(t_df, 'tid')
t_df['significant'] = False
t_df = t_df.merge(de_df[['tid', 'qval']], how='left', on='tid')
t_df['significant'] = False
t_df['significant'] = t_df.loc[t_df.qval <= q]
t_df['significant'] = t_df.qval <= q
t_df = set_dupe_index(t_df, 'tid')

# if user doesn't care about datasets, just show all transcripts
Expand Down
73 changes: 70 additions & 3 deletions testing/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ def test_plotting(self):
gene1_edge_df['edge_id'] = gene1_edge_df.apply(lambda x:
(x.v1, x.v2), axis=1)

sg.loc_df = gene1_loc_df
sg.edge_df = gene1_edge_df
sg.t_df = gene1_t_df

sg.loc_df = create_dupe_index(sg.loc_df, 'vertex_id')
sg.loc_df = set_dupe_index(sg.loc_df, 'vertex_id')
sg.edge_df = create_dupe_index(sg.edge_df, 'edge_id')
sg.edge_df = set_dupe_index(sg.edge_df, 'edge_id')
sg.t_df = create_dupe_index(sg.t_df, 'tid')
sg.t_df = set_dupe_index(sg.t_df, 'tid')
sg.get_loc_types()

# testing
gene1_tids = gene1_t_df.tid.tolist()
gene1_locs = gene1_loc_df.vertex_id.tolist()
gene1_edges = gene1_edge_df.edge_id.tolist()

# 0th plot - gene summary graph of ENSG01
sg.datasets = ['annotation', 'a']
sg = plot0(sg, gene1_tids, gene1_locs, gene1_edges)

gene2_loc_df = pd.DataFrame({'chrom': [4, 4, 4, 4, 4, 4, 4],
'coord': [35, 30, 25, 20, 15, 10, 5],
'strand': ['-', '-', '-', '-', '-', '-', '-'],
Expand Down Expand Up @@ -76,13 +97,14 @@ def test_plotting(self):
sg.get_loc_types()

# testing
gene1_tids = gene1_t_df.tid.tolist()
gene1_locs = gene1_loc_df.vertex_id.tolist()
gene1_edges = gene1_edge_df.edge_id.tolist()
gene2_tids = gene2_t_df.tid.tolist()
gene2_locs = gene2_loc_df.vertex_id.tolist()
gene2_edges = gene2_edge_df.edge_id.tolist()

# remake the same plot and force it to update
sg.datasets = ['annotation', 'a', 'b']
sg = plot0_5(sg, gene2_tids, gene1_locs, gene1_edges)

# first plot - gene summary graph of ENSG01
sg = plot1(sg, gene1_tids, gene1_locs, gene1_edges)

Expand Down Expand Up @@ -116,6 +138,51 @@ def test_plotting(self):

# add a new dataset to the graph and plot a transcript from a different gene

def plot0(sg, tids, locs, edges):
sg.plot_graph('ENSG01')
check_subset(sg, tids, edges, locs)
node_colors_ctrl = [(0, 'light_blue'), (1, 'yellow'),
(2, 'light_blue'), (3, 'yellow'),
(4, 'yellow'), (5, 'orange'), (6, 'orange')]
curve_ctrl = [((0,1),None), ((1,2),None),
((2,3),None), ((3,4),None),
((4,5),None), ((0,3),'curved'),
((4,6),'curved'),((1,4),'curved')]
edge_color_ctrl = [((0,1),'green'), ((1,2),'pink'),
((2,3),'green'), ((3,4),'pink'),
((4,5),'green'), ((0,3),'green'),
((4,6),'green'),((1,4),'pink')]
check_nodes(sg.pg.loc_df, node_colors_ctrl)
check_edges(sg.pg.edge_df, edge_color_ctrl, curve_ctrl)
return sg

def plot0_5(sg, tids, locs, edges):
sg.plot_graph('ENSG02', indicate_dataset='a')
swan.save_fig('scratch/ensg02_dataset')
check_subset(sg, tids, edges, locs)
edgecolor_ctrl = [(0, 'k'), (1, 'k'),
(2, None), (3, 'k'),
(4, 'k'), (5, 'k'), (6, 'k')]
node_colors_ctrl = [(0, 'light_blue'), (1, 'yellow'),
(2, 'light_blue'), (3, 'yellow'),
(4, 'yellow'), (5, 'orange'), (6, 'orange')]
curve_ctrl = [((0,1),None), ((1,2),None),
((2,3),None), ((3,4),None),
((4,5),None), ((0,3),'curved'),
((4,6),'curved'),((1,4),'curved')]
edge_color_ctrl = [((0,1),'green'), ((1,2),'pink'),
((2,3),'green'), ((3,4),'pink'),
((4,5),'green'), ((0,3),'green'),
((4,6),'green'),((1,4),'pink')]
style_ctrl = [((0,1),'dashed'), ((1,2),None),
((2,3),None), ((3,4),'dashed'),
((4,5),'dashed'), ((0,3),'dashed'),
((4,6),'dashed'),((1,4),'dashed')]
check_nodes(sg.pg.loc_df, node_colors_ctrl, edgecolor_ctrl)
check_edges(sg.pg.edge_df, edge_color_ctrl, curve_ctrl, style_ctrl)
return sg


def plot1(sg, tids, locs, edges):
sg.plot_graph('ENSG01')
check_subset(sg, tids, edges, locs)
Expand Down

0 comments on commit 14da6a9

Please sign in to comment.