diff --git a/PopPUNK/__init__.py b/PopPUNK/__init__.py index 7fe643a0..a3f1eb11 100644 --- a/PopPUNK/__init__.py +++ b/PopPUNK/__init__.py @@ -3,7 +3,7 @@ '''PopPUNK (POPulation Partitioning Using Nucleotide Kmers)''' -__version__ = '2.6.4' +__version__ = '2.6.5' # Minimum sketchlib version SKETCHLIB_MAJOR = 2 diff --git a/PopPUNK/visualise.py b/PopPUNK/visualise.py index b0f8f274..6d42bbd1 100644 --- a/PopPUNK/visualise.py +++ b/PopPUNK/visualise.py @@ -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) @@ -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 @@ -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, @@ -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: diff --git a/test/clean_test.py b/test/clean_test.py index 1acd576e..95690aba 100755 --- a/test/clean_test.py +++ b/test/clean_test.py @@ -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) diff --git a/test/example_set.tar.bz2 b/test/example_set.tar.bz2 index b535807c..5315e5fb 100644 Binary files a/test/example_set.tar.bz2 and b/test/example_set.tar.bz2 differ diff --git a/test/run_test.py b/test/run_test.py index 12399557..471b86b8 100755 --- a/test/run_test.py +++ b/test/run_test.py @@ -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)