Skip to content

Commit

Permalink
Quicker network plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjcroucher committed Oct 17, 2024
1 parent f40a828 commit 9cc6c13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 5 additions & 2 deletions PopPUNK/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def drawMST(mst, outPrefix, isolate_clustering, clustering_name, overwrite):
output=graph2_file_name, output_size=(3000, 3000))

def outputsForCytoscape(G, G_mst, isolate_names, clustering, outPrefix, epiCsv, queryList = None,
suffix = None, writeCsv = True):
suffix = None, writeCsv = True, use_partial_query_graph = False):
"""Write outputs for cytoscape. A graphml of the network, and CSV with metadata
Args:
Expand All @@ -536,6 +536,8 @@ def outputsForCytoscape(G, G_mst, isolate_names, clustering, outPrefix, epiCsv,
(default = None)
writeCsv (bool)
Whether to print CSV file to accompany network
use_partial_query_graph (bool)
Whether to optimise output for outputting only partial graphs
"""

# Avoid circular import
Expand All @@ -553,7 +555,8 @@ def outputsForCytoscape(G, G_mst, isolate_names, clustering, outPrefix, epiCsv,
suffix = '_cytoscape'
else:
suffix = suffix + '_cytoscape'
save_network(G, prefix = outPrefix, suffix = suffix, use_graphml = True)
if not use_partial_query_graph:
save_network(G, prefix = outPrefix, suffix = suffix, use_graphml = True)

# Save each component too (useful for very large graphs)
component_assignments, component_hist = gt.label_components(G)
Expand Down
8 changes: 5 additions & 3 deletions PopPUNK/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def generate_visualisations(query_db,
#* *#
#******************************#

if (tree == "nj" or tree == "both") or rank_fit == None:
if (tree == "nj" or tree == "both") or (model.type == 'lineage' and rank_fit == None):

# Either calculate or read distances
if recalculate_distances:
Expand Down Expand Up @@ -699,7 +699,7 @@ def generate_visualisations(query_db,
if gpu_graph:
genomeNetwork = cugraph_to_graph_tool(genomeNetwork, isolateNameToLabel(all_seq))
# Hard delete from network to remove samples (mask doesn't work neatly)
if include_files is not None:
if include_files is not None and not use_partial_query_graph:
genomeNetwork = remove_nodes_from_graph(genomeNetwork, all_seq, viz_subset, use_gpu = gpu_graph)
elif rank_fit is not None:
genomeNetwork = sparse_mat_to_network(sparse_mat, combined_seq, use_gpu = gpu_graph)
Expand All @@ -710,12 +710,14 @@ def generate_visualisations(query_db,
# for full network
node_labels = viz_subset if (use_partial_query_graph is not None or include_files is not None) \
else combined_seq
sys.stderr.write('Preparing outputs for cytoscape\n')
outputsForCytoscape(genomeNetwork,
mst_graph,
node_labels,
isolateClustering,
output,
info_csv)
info_csv,
use_partial_query_graph)
if model.type == 'lineage':
sys.stderr.write("Note: Only support for output of cytoscape graph at lowest rank\n")

Expand Down

0 comments on commit 9cc6c13

Please sign in to comment.