Skip to content

Commit

Permalink
Updates from master branch
Browse files Browse the repository at this point in the history
Update from master branch
  • Loading branch information
nickjcroucher authored May 24, 2024
2 parents 986a43d + 27982a5 commit 1319225
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 30 deletions.
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
59 changes: 31 additions & 28 deletions PopPUNK/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,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 @@ -380,15 +380,6 @@ def generate_visualisations(query_db,
#* *#
#**********************************#

# Either use strain definitions, lineage assignments or external clustering
isolateClustering = {}
# Use external clustering if specified
if external_clustering:
cluster_file = external_clustering
isolateClustering = readIsolateTypeFromCsv(cluster_file,
mode = 'external',
return_dict = True)

# identify existing model and cluster files
if model_dir is not None:
model_prefix = model_dir
Expand All @@ -403,30 +394,42 @@ def generate_visualisations(query_db,
sys.stderr.write('Unable to locate previous model fit in ' + model_prefix + '\n')
sys.exit(1)

# Load previous clusters
if previous_clustering is not None:
prev_clustering = previous_clustering
mode = "clusters"
suffix = "_clusters.csv"
if prev_clustering.endswith('_lineages.csv'):
mode = "lineages"
# Either use strain definitions, lineage assignments or external clustering
isolateClustering = {}
# Use external clustering if specified
if external_clustering:
mode = 'external'
cluster_file = external_clustering
if cluster_file.endswith('_lineages.csv'):
suffix = "_lineages.csv"
else:
suffix = "_clusters.csv"
else:
# Identify type of clustering based on model
mode = "clusters"
suffix = "_clusters.csv"
if model.type == "lineage":
mode = "lineages"
suffix = "_lineages.csv"
prev_clustering = os.path.join(model_prefix, os.path.basename(model_prefix) + suffix)
isolateClustering = readIsolateTypeFromCsv(prev_clustering,
# Load previous clusters
if previous_clustering is not None:
cluster_file = previous_clustering
mode = "clusters"
suffix = "_clusters.csv"
if cluster_file.endswith('_lineages.csv'):
mode = "lineages"
suffix = "_lineages.csv"
else:
# Identify type of clustering based on model
mode = "clusters"
suffix = "_clusters.csv"
if model.type == "lineage":
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)

# 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 Expand Up @@ -471,7 +474,7 @@ def generate_visualisations(query_db,
if display_cluster not in isolateClustering.keys():
clustering_name = list(isolateClustering.keys())[0]
sys.stderr.write('Unable to find clustering column ' + display_cluster + ' in file ' +
prev_clustering + '; instead using ' + clustering_name + '\n')
cluster_file + '; instead using ' + clustering_name + '\n')
else:
clustering_name = display_cluster
else:
Expand Down
4 changes: 3 additions & 1 deletion test/clean_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def deleteDir(dirname):
"batch2",
"batch3",
"batch12",
"batch123"
"batch123",
"strain_1_lineage_db",
"strain_2_lineage_db"
]
for outDir in outputDirs:
deleteDir(outDir)
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 @@ -119,6 +119,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

0 comments on commit 1319225

Please sign in to comment.