Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output external clusterings with visualisations #307

Merged
merged 9 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PopPUNK/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

'''PopPUNK (POPulation Partitioning Using Nucleotide Kmers)'''

__version__ = '2.6.4'
__version__ = '2.6.5'

# Minimum sketchlib version
SKETCHLIB_MAJOR = 2
Expand Down
23 changes: 12 additions & 11 deletions PopPUNK/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def generate_visualisations(query_db,
sys.stderr.write("Must specify at least one type of visualisation to output\n")
sys.exit(1)
if cytoscape and not (microreact or phandango or grapetree):
if rank_fit == None and not os.path.isfile(network_file):
if rank_fit == None and (network_file == None or not os.path.isfile(network_file)):
sys.stderr.write("For cytoscape, specify either a network file to visualise "
"with --network-file or a lineage model with --rank-fit\n")
sys.exit(1)
Expand Down Expand Up @@ -396,13 +396,13 @@ def generate_visualisations(query_db,
isolateClustering = {}
# Use external clustering if specified
if external_clustering:
mode = 'external'
cluster_file = external_clustering
isolateClustering = readIsolateTypeFromCsv(cluster_file,
mode = 'external',
return_dict = True)

if cluster_file.endswith('_lineages.csv'):
suffix = "_lineages.csv"
else:
suffix = "_clusters.csv"
else:

# Load previous clusters
if previous_clustering is not None:
cluster_file = previous_clustering
Expand All @@ -419,14 +419,15 @@ def generate_visualisations(query_db,
mode = "lineages"
suffix = "_lineages.csv"
cluster_file = os.path.join(model_prefix, os.path.basename(model_prefix) + suffix)
isolateClustering = readIsolateTypeFromCsv(cluster_file,
mode = mode,
return_dict = True)

isolateClustering = readIsolateTypeFromCsv(cluster_file,
mode = mode,
nickjcroucher marked this conversation as resolved.
Show resolved Hide resolved
return_dict = True)

# Add individual refinement clusters if they exist
if model.indiv_fitted:
for type, suffix in zip(['Core','Accessory'],['_core_clusters.csv','_accessory_clusters.csv']):
indiv_clustering = os.path.join(model_prefix, os.path.basename(model_prefix) + suffix)
for type, indiv_suffix in zip(['Core','Accessory'],['_core_clusters.csv','_accessory_clusters.csv']):
indiv_clustering = os.path.join(model_prefix, os.path.basename(model_prefix) + indiv_suffix)
if os.path.isfile(indiv_clustering):
indiv_isolateClustering = readIsolateTypeFromCsv(indiv_clustering,
mode = mode,
Expand Down
Binary file modified test/example_set.tar.bz2
Binary file not shown.
6 changes: 6 additions & 0 deletions test/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
sys.stderr.write('Failed to query lineages from strain database\n')
sys.exit(1)

# beebop test
subprocess.run(python_cmd + " ../poppunk-runner.py --create-db --r-files rfile12.txt --output batch12 --overwrite", shell=True, check=True)
subprocess.run(python_cmd + " ../poppunk-runner.py --fit-model bgmm --D 2 --ref-db batch12 --overwrite", shell=True, check=True)
subprocess.run(python_cmd + " ../poppunk_assign-runner.py --db batch12 --query rfile3.txt --output batch3 --external-clustering batch12_external_clusters.csv --overwrite", shell=True, check=True)
subprocess.run(python_cmd + " ../poppunk_visualise-runner.py --ref-db batch12 --query-db batch3 --output batch123_viz --external-clustering batch12_external_clusters.csv --previous-query-clustering batch3/batch3_external_clusters.csv --cytoscape --rapidnj rapidnj --network-file ./batch12/batch12_graph.gt --overwrite", shell=True, check=True)

# citations
sys.stderr.write("Printing citations\n")
subprocess.run(python_cmd + " ../poppunk-runner.py --citation --fit-model bgmm --ref-db example_db --K 4", shell=True, check=True)
Expand Down
Loading