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

Updates to MST #148

Merged
merged 338 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
338 commits
Select commit Hold shift + click to select a range
c64a2c5
Change cudf list conversion
nickjcroucher Mar 10, 2021
b84a269
Update printClusters flags
nickjcroucher Mar 10, 2021
cf1d85b
Allow for saving of cugraph objects
nickjcroucher Mar 10, 2021
81b7033
Fix missing function reference
nickjcroucher Mar 10, 2021
1f708d6
Change vertex list to set for difference
nickjcroucher Mar 10, 2021
79b754f
GPU graphs for non-lineage mode
nickjcroucher Mar 10, 2021
6566544
Change node index extraction
nickjcroucher Mar 10, 2021
bec01e5
Restore missing nodes to GPU graph
nickjcroucher Mar 11, 2021
d216576
Add missing nodes
nickjcroucher Mar 11, 2021
a369c9d
Use range list in place of integer
nickjcroucher Mar 11, 2021
d51d8fd
Fix range list
nickjcroucher Mar 11, 2021
a4c3210
Remove pandas intermediate for data frame
nickjcroucher Mar 11, 2021
ca28aa5
Fix data frame name
nickjcroucher Mar 11, 2021
702c6b9
Add in isolated vertices in GPU graph
nickjcroucher Mar 11, 2021
8c14b5e
Change max to int conversion
nickjcroucher Mar 11, 2021
414efff
Change max calculation
nickjcroucher Mar 11, 2021
6938b53
Change max format
nickjcroucher Mar 11, 2021
90ebda6
Add message checking on maximum
nickjcroucher Mar 11, 2021
4915c67
Change int to float
nickjcroucher Mar 11, 2021
7a0e404
Add warning for missing nodes
nickjcroucher Mar 11, 2021
19a4248
Test DF structure
nickjcroucher Mar 11, 2021
6de7509
Change warning message print format
nickjcroucher Mar 11, 2021
bf278b0
Change cudf definition
nickjcroucher Mar 11, 2021
2d08c72
Add reference extraction for GPU graphs
nickjcroucher Mar 11, 2021
21dc84b
Change ktruss command
nickjcroucher Mar 11, 2021
f64c422
Change ktruss processing
nickjcroucher Mar 11, 2021
f88a0c2
Change components processing
nickjcroucher Mar 11, 2021
77133cb
Change components options
nickjcroucher Mar 11, 2021
9dcaefd
Format Gtruss for graph input
nickjcroucher Mar 11, 2021
5eb7e69
Try option 1 for ktruss
nickjcroucher Mar 11, 2021
b2897b6
Raise ktruss k to 5
nickjcroucher Mar 11, 2021
9b58655
Change ktruss formats
nickjcroucher Mar 11, 2021
98dba61
Print network summaries
nickjcroucher Mar 11, 2021
24713ee
Fix grammar
nickjcroucher Mar 11, 2021
65d8cb4
Test Louvain
nickjcroucher Mar 11, 2021
2be9513
Test Leiden
nickjcroucher Mar 11, 2021
cf012fb
Process Leiden output
nickjcroucher Mar 11, 2021
74bb8ee
Process Leiden both outputs
nickjcroucher Mar 11, 2021
a694176
Change grouping variable
nickjcroucher Mar 11, 2021
0c0789d
Test grouping code
nickjcroucher Mar 11, 2021
e0d6f87
Fi grouping code
nickjcroucher Mar 12, 2021
b9319dc
Change iloc selection
nickjcroucher Mar 12, 2021
5b3d183
Change selection processing
nickjcroucher Mar 12, 2021
b29d82c
Remove column select
nickjcroucher Mar 12, 2021
1b5fd31
Change list conversion
nickjcroucher Mar 12, 2021
85ac6f5
Add reference graph construction
nickjcroucher Mar 12, 2021
17a0997
Add missing bracket
nickjcroucher Mar 12, 2021
2e1f3ee
Add edge list
nickjcroucher Mar 12, 2021
e5cb974
Change column names
nickjcroucher Mar 12, 2021
eecf239
Remove weights from reference graph
nickjcroucher Mar 12, 2021
7fe3277
Add self loops for reference graph
nickjcroucher Mar 12, 2021
d6a3442
Change column names
nickjcroucher Mar 12, 2021
fc9d0a5
Change df concatenation
nickjcroucher Mar 12, 2021
366630b
Print ref graph
nickjcroucher Mar 12, 2021
76671a3
Add resolution parameter to Leiden method
nickjcroucher Mar 12, 2021
1a646b6
Add GPU graph loading
nickjcroucher Mar 12, 2021
f22cf55
Change GPU graph writing
nickjcroucher Mar 12, 2021
accafd3
Change CSV compression
nickjcroucher Mar 12, 2021
a2bb284
Change output file name
nickjcroucher Mar 12, 2021
2729a11
Add suffix to output file
nickjcroucher Mar 12, 2021
9466ae6
Correct suffix to output file
nickjcroucher Mar 12, 2021
80533f8
Fix dist order with lineage mode
johnlees Mar 12, 2021
ce8135e
docstring typo
johnlees Mar 12, 2021
cca4a7c
Add GPU summaries
nickjcroucher Mar 12, 2021
4a53fd2
Remove surplus bracket
nickjcroucher Mar 12, 2021
3c7d1d2
Change sum of degree
nickjcroucher Mar 12, 2021
b75dcce
Load cugraph libraries
nickjcroucher Mar 12, 2021
8ccddf4
Print degree for debug
nickjcroucher Mar 12, 2021
81bfb5e
Change access to degree
nickjcroucher Mar 12, 2021
3368c6b
Add missing bracket
nickjcroucher Mar 12, 2021
ff07201
Change degree print statement
nickjcroucher Mar 12, 2021
628ad32
Convert to pandas
nickjcroucher Mar 12, 2021
8e36694
Change iteration over components
nickjcroucher Mar 12, 2021
f19adfc
Print details of components
nickjcroucher Mar 12, 2021
14a14f9
Convert series value to int
nickjcroucher Mar 12, 2021
38298f2
Extract single value for size
nickjcroucher Mar 12, 2021
fb6ba09
Change column name
nickjcroucher Mar 12, 2021
2973f6e
Print component betweenness
nickjcroucher Mar 12, 2021
49e4fc9
Find maximum betweenness
nickjcroucher Mar 12, 2021
2461855
Change column name
nickjcroucher Mar 12, 2021
69edec7
Betweeness access change
nickjcroucher Mar 12, 2021
00d84d5
Change summary stat recording
nickjcroucher Mar 12, 2021
438c269
Tidy up debug messages
nickjcroucher Mar 12, 2021
0382024
Transitivity calculation details
nickjcroucher Mar 12, 2021
583fa13
Change printing of debug
nickjcroucher Mar 12, 2021
e5bb57a
Print counts
nickjcroucher Mar 12, 2021
bdf8a83
Enable GPUs for refinement
nickjcroucher Mar 13, 2021
2e1c802
Change kwarg to arg in optimise
nickjcroucher Mar 13, 2021
4e68b7b
Change default arguments
nickjcroucher Mar 13, 2021
a2ce789
Cascade use_gpu argument through functions
nickjcroucher Mar 13, 2021
9748785
Change refine arguments
nickjcroucher Mar 13, 2021
e7ff375
Communicate GPU use
nickjcroucher Mar 13, 2021
9eba438
Improve graph reconstruction in refinement
nickjcroucher Mar 13, 2021
ca2992b
Load CUDA libraries
nickjcroucher Mar 13, 2021
64e6284
Add debug message
nickjcroucher Mar 13, 2021
181a328
Fix column names
nickjcroucher Mar 13, 2021
900ed24
Make column names consistent
nickjcroucher Mar 13, 2021
5601a2b
Updating networks with CUDA
nickjcroucher Mar 13, 2021
15c106a
Change betweeness processing
nickjcroucher Mar 13, 2021
f950cd8
Add GPU options to assign
nickjcroucher Mar 13, 2021
a6a037e
Change function argument order
nickjcroucher Mar 13, 2021
2b65e61
Change argument typo
nickjcroucher Mar 13, 2021
9cc9ad6
Add CUDA load for querying
nickjcroucher Mar 14, 2021
4035062
Fix graph suffix for GPU
nickjcroucher Mar 14, 2021
01dcf37
Quote column name
nickjcroucher Mar 14, 2021
cbeebaf
Define graph name
nickjcroucher Mar 14, 2021
aee03b1
Change cudf column names on loading
nickjcroucher Mar 14, 2021
a0fce56
Add weights to column names
nickjcroucher Mar 14, 2021
43d13a7
Print formatted DF
nickjcroucher Mar 14, 2021
2ea95f4
Remove Pandas index from CSV
nickjcroucher Mar 14, 2021
41868b9
Update graph loading message
nickjcroucher Mar 14, 2021
39e80a7
Update graph loading message again
nickjcroucher Mar 14, 2021
c12d08a
Change gpu option
nickjcroucher Mar 14, 2021
04ee820
Change name of tuples
nickjcroucher Mar 14, 2021
655025b
Change printClusters to use GPU
nickjcroucher Mar 14, 2021
50cc317
Edit component assignments
nickjcroucher Mar 14, 2021
dc9a702
Print node count
nickjcroucher Mar 14, 2021
067149c
Return updated graph from function
nickjcroucher Mar 14, 2021
bde7dd8
Update to be consistent with changes to network function
nickjcroucher Mar 14, 2021
0aa02c6
Remove debug messages
nickjcroucher Mar 14, 2021
20283b4
Merge remote-tracking branch 'origin/dist_order_redux' into mst_dev
nickjcroucher Mar 15, 2021
60306b8
Merge in master
nickjcroucher Mar 15, 2021
eca9b50
Ensure consistency across function arguments
nickjcroucher Mar 15, 2021
d7fb652
Add omitted sys exit when missing distance file
nickjcroucher Mar 15, 2021
593b26f
Update file name formatting
nickjcroucher Mar 15, 2021
69724c0
Edit whitespace
nickjcroucher Mar 15, 2021
470fec0
Edit whitespace
nickjcroucher Mar 15, 2021
9f600de
Edit whitespace
nickjcroucher Mar 15, 2021
9570244
Fix qList variable name
nickjcroucher Mar 15, 2021
95fb235
Remove debug message
nickjcroucher Mar 15, 2021
f323ccf
Edit whitespace
nickjcroucher Mar 15, 2021
5333e88
Remove debug message
nickjcroucher Mar 15, 2021
78a295f
Change comment wording
nickjcroucher Mar 15, 2021
6eacd4b
Reorder column indices
nickjcroucher Mar 15, 2021
083722b
Change column indices
nickjcroucher Mar 15, 2021
bbdf53b
Edit whitespace
nickjcroucher Mar 15, 2021
c7daea2
Update assign arguments
nickjcroucher Mar 15, 2021
e18ed35
Make CUDA library imports global
nickjcroucher Mar 15, 2021
fcf2858
Only import GPU libraries once
nickjcroucher Mar 15, 2021
090994f
Add reference isolate to assign command
nickjcroucher Mar 15, 2021
89f97ce
Changes to command line phrasing
nickjcroucher Mar 16, 2021
059d804
Change GPU library loading
nickjcroucher Mar 16, 2021
c9b07e8
Merge branch 'mst_dev' of https://github.com/johnlees/PopPUNK into ms…
nickjcroucher Mar 16, 2021
7f110c8
Update web test
nickjcroucher Mar 16, 2021
a87c94d
Change distance QC routine
nickjcroucher Mar 16, 2021
46a9a9a
Update distance QC functions
nickjcroucher Mar 16, 2021
40a6e4f
Select reference isolate where not supplied
nickjcroucher Mar 16, 2021
845acb0
Change missing nodes to error
nickjcroucher Mar 16, 2021
bb2f9e1
Use function for checking network vertex count
nickjcroucher Mar 16, 2021
dbcb4f6
Tidy up obsolete text
nickjcroucher Mar 16, 2021
f61ccd0
Add self_loop function
nickjcroucher Mar 16, 2021
55507b4
Remove condition on adding edges
nickjcroucher Mar 16, 2021
acbeeea
Add copy function for models
nickjcroucher Mar 16, 2021
90144c0
Fix file and cluster name processing
nickjcroucher Mar 16, 2021
1b40461
Change network loading functions
nickjcroucher Mar 16, 2021
ae777f4
Update import of old networks to use cugraph
nickjcroucher Mar 17, 2021
616c31e
Fix processing of distance matrix
nickjcroucher Mar 17, 2021
03ab3f8
Avoid overwrite on qcDistMat
nickjcroucher Mar 17, 2021
ef450c6
Start checking reference graph connectivity
nickjcroucher Mar 17, 2021
08f58ff
Enable qcDistMat to create output directory
nickjcroucher Mar 17, 2021
6094b2b
Change vertex count error message
nickjcroucher Mar 17, 2021
93c872d
Change column naming in cugraph
nickjcroucher Mar 17, 2021
0f77ade
Get column names
nickjcroucher Mar 17, 2021
90aee39
Rename in place
nickjcroucher Mar 17, 2021
b037593
Compare cudfs
nickjcroucher Mar 17, 2021
ce8fccb
View reference cudf
nickjcroucher Mar 17, 2021
fe24179
View overall cudf
nickjcroucher Mar 17, 2021
b8d03b2
Concat cudf
nickjcroucher Mar 17, 2021
a8e7e33
Merge cudf
nickjcroucher Mar 17, 2021
86b8d85
Filter merged cudf
nickjcroucher Mar 17, 2021
c34a51f
Summarise merged cudf
nickjcroucher Mar 17, 2021
b4d1fbd
Change bool in while loop
nickjcroucher Mar 17, 2021
8c93ac3
Rename bool variable
nickjcroucher Mar 17, 2021
af08e6a
Change cudf tallying
nickjcroucher Mar 17, 2021
3af73ca
identify column names
nickjcroucher Mar 17, 2021
2f7d1f5
Rename columns
nickjcroucher Mar 17, 2021
049aba5
Fix loop control
nickjcroucher Mar 17, 2021
ce67074
Remove some debug messages
nickjcroucher Mar 17, 2021
a80f206
Print counting information
nickjcroucher Mar 17, 2021
ab52160
Print counting information
nickjcroucher Mar 17, 2021
490a227
Print as list
nickjcroucher Mar 17, 2021
7683bf9
Print as unique list
nickjcroucher Mar 17, 2021
659ccff
Find overall max
nickjcroucher Mar 17, 2021
80bbd67
Test reference connectivity
nickjcroucher Mar 17, 2021
51e442e
use debug mode
nickjcroucher Mar 17, 2021
0e69d8c
Change group by variable
nickjcroucher Mar 17, 2021
c981792
Correct group variable selection
nickjcroucher Mar 17, 2021
906b534
Add extra debug print statement
nickjcroucher Mar 17, 2021
ee510c4
Change ref selection
nickjcroucher Mar 17, 2021
2b981e2
Extend debug mode
nickjcroucher Mar 17, 2021
23e6b60
Further debug
nickjcroucher Mar 17, 2021
2151ec8
Changes to debug message
nickjcroucher Mar 17, 2021
a57a1b8
Update reference indices
nickjcroucher Mar 17, 2021
920a66b
Change series to set conversion
nickjcroucher Mar 17, 2021
8c9cf4d
Change set processing
nickjcroucher Mar 17, 2021
4f646b3
Change filtering conditions
nickjcroucher Mar 17, 2021
4669728
Change definition of reference set
nickjcroucher Mar 17, 2021
25b8ccc
Change definition of reference set
nickjcroucher Mar 17, 2021
294f3fa
Change definition of reference set
nickjcroucher Mar 17, 2021
ba946b1
Debug series filtering
nickjcroucher Mar 17, 2021
cebdf3a
Extract series values
nickjcroucher Mar 17, 2021
f86e814
Change extraction of values from series
nickjcroucher Mar 17, 2021
26bbc0a
Comment code for impending review
nickjcroucher Mar 17, 2021
a9d8fb0
Remove unnecessary loop
nickjcroucher Mar 17, 2021
92d0f0c
Change vertex selection for SSSP
nickjcroucher Mar 17, 2021
01bbe77
Reconstruct reference graph where necessary
nickjcroucher Mar 17, 2021
ad66e9c
Debug for missing nodes
nickjcroucher Mar 17, 2021
7d49d86
Remove debug message
nickjcroucher Mar 17, 2021
512c127
Add missing nodes with cugraph
nickjcroucher Mar 17, 2021
c504f96
Add missing nodes with cugraph
nickjcroucher Mar 17, 2021
8b5ed90
Add missing nodes with cugraph
nickjcroucher Mar 17, 2021
624bce8
Add missing nodes with cugraph
nickjcroucher Mar 17, 2021
f032f26
Change cugraph node count retrieval
nickjcroucher Mar 17, 2021
5dc2b0e
Change int format
nickjcroucher Mar 17, 2021
7602dd3
Change save function definition
nickjcroucher Mar 17, 2021
bdb0141
Change GPU score calculation
nickjcroucher Mar 17, 2021
4b78c1e
Update cytoscape viz test
nickjcroucher Mar 17, 2021
35abac0
Changes to messages and function arguments
nickjcroucher Mar 18, 2021
6a7e806
Disambiguation of term 'reference'
nickjcroucher Mar 18, 2021
a94fe2d
Check type isolate is in QC filtered set
nickjcroucher Mar 22, 2021
348e502
Add type isolate to reference set
nickjcroucher Mar 22, 2021
5041a91
Fixes to conditional statements
nickjcroucher Mar 22, 2021
7901e42
Fixes to function arguments
nickjcroucher Mar 22, 2021
7742e83
Change cudf memory management
nickjcroucher Mar 22, 2021
77e9d64
Add no-plot mode for models
nickjcroucher Mar 22, 2021
2c7d014
Extend no-plot mode for models
nickjcroucher Mar 22, 2021
c450710
Move model processing flags to optimisation arg group
nickjcroucher Mar 22, 2021
f823964
Update new lines
nickjcroucher Mar 22, 2021
a5c4f02
Edit whitespace
nickjcroucher Mar 22, 2021
e6abfb4
Edit whitespace
nickjcroucher Mar 22, 2021
78ee9c2
Edit whitespace
nickjcroucher Mar 22, 2021
5b362fb
Reinsert library loading warning
nickjcroucher Mar 22, 2021
03f11a8
Change model plotting behaviour
nickjcroucher Mar 22, 2021
3e5160e
Add cudf and cugraph
nickjcroucher Mar 22, 2021
13e565f
Change list command to append
nickjcroucher Mar 22, 2021
ed7e549
Merge branch 'master' into mst_dev
johnlees Mar 22, 2021
841256d
Merge changes from VLKC PR
johnlees Mar 22, 2021
771ae57
Limit betweenness calculation with GPU
nickjcroucher Mar 22, 2021
c8093c8
Merge branch 'mst_dev' of https://github.com/johnlees/PopPUNK into ms…
nickjcroucher Mar 22, 2021
ca8c429
Set from numpy ndarray
nickjcroucher Mar 22, 2021
b526a2f
Convert ndarray to list
nickjcroucher Mar 22, 2021
414c27b
Convert ndarray to list
nickjcroucher Mar 22, 2021
0cef59d
Remove debug message
nickjcroucher Mar 22, 2021
d6667a1
Remove nvidia packages from CI
johnlees Mar 23, 2021
b5e03eb
Remove whitespace
johnlees Mar 23, 2021
62e69d2
Remove cudf/cugraph err message
johnlees Mar 23, 2021
a1c6692
trailing whitespace
johnlees Mar 23, 2021
1a11b21
Change cugraph betweenness calculation
nickjcroucher Mar 23, 2021
f98bd0f
Remove multiprocessing block from 2d network refine w/ GPU
johnlees Mar 23, 2021
e1879a8
Fix web test
johnlees Mar 23, 2021
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
8 changes: 5 additions & 3 deletions PopPUNK/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def distHistogram(dists, rank, outPrefix):
"_rank_" + str(rank) + "_histogram.png")
plt.close()

def drawMST(mst, outPrefix, isolate_clustering, overwrite):
def drawMST(mst, outPrefix, isolate_clustering, clustering_name, overwrite):
"""Plot a layout of the minimum spanning tree

Args:
Expand All @@ -424,6 +424,8 @@ def drawMST(mst, outPrefix, isolate_clustering, overwrite):
Output prefix for save files
isolate_clustering (dict)
Dictionary of ID: cluster, used for colouring vertices
clustering_name (str)
Name of clustering scheme to be used for colouring
overwrite (bool)
Overwrite existing output files
"""
Expand All @@ -446,12 +448,12 @@ def drawMST(mst, outPrefix, isolate_clustering, overwrite):
output=graph1_file_name, output_size=(3000, 3000))
if overwrite or not os.path.isfile(graph2_file_name):
cluster_fill = {}
for cluster in set(isolate_clustering['Cluster'].values()):
for cluster in set(isolate_clustering[clustering_name].values()):
cluster_fill[cluster] = list(np.random.rand(3)) + [0.9]
plot_color = mst.new_vertex_property('vector<double>')
mst.vertex_properties['plot_color'] = plot_color
for v in mst.vertices():
plot_color[v] = cluster_fill[isolate_clustering['Cluster'][mst.vp.id[v]]]
plot_color[v] = cluster_fill[isolate_clustering[clustering_name][mst.vp.id[v]]]

gt.graph_draw(mst, pos=pos, vertex_fill_color=mst.vertex_properties['plot_color'],
output=graph2_file_name, output_size=(3000, 3000))
Expand Down
18 changes: 16 additions & 2 deletions PopPUNK/sparse_mst.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def get_options():
iGroup.add_argument('--distances', required=True, help='Prefix of input pickle of pre-calculated distances (required)')
iGroup.add_argument('--rank-fit', required=True, help='Location of rank fit, a sparse matrix (*_rank*_fit.npz)')
iGroup.add_argument('--previous-clustering', help='CSV file with cluster definitions')
iGroup.add_argument('--display-cluster', default=None, help='Column of clustering CSV to use for plotting')

# output options
oGroup = parser.add_argument_group('Output options')
Expand Down Expand Up @@ -116,7 +117,7 @@ def main():
if not args.no_plot:
if args.previous_clustering != None:
mode = "clusters"
if re.match(r"_lineages\.csv$", args.previous_clustering):
if args.previous_clustering.endswith('_lineages.csv'):
mode = "lineages"
isolateClustering = readIsolateTypeFromCsv(args.previous_clustering,
mode = mode,
Expand All @@ -127,7 +128,20 @@ def main():
for v in mst.vertices:
isolateClustering['Cluster'][mst.vp.id[v]] = '0'

drawMST(mst, args.output, isolateClustering, True)
# Check selecting clustering type is in CSV
clustering_name = 'Cluster'
if args.display_cluster != None and args.previous_clustering != None:
if args.display_cluster not in isolateClustering.keys():
sys.stderr.write('Unable to find clustering column ' + args.display_cluster + ' in file ' +
args.previous_clustering + '\n')
sys.exit()
nickjcroucher marked this conversation as resolved.
Show resolved Hide resolved
else:
clustering_name = args.display_cluster
else:
clustering_name = list(isolateClustering.keys())[0]

# Draw MST
drawMST(mst, args.output, isolateClustering, clustering_name, True)

sys.exit(0)

60 changes: 40 additions & 20 deletions PopPUNK/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ def get_options():
'to clusters [default = reference database directory]',
type = str)
iGroup.add_argument('--previous-clustering',
help='Directory containing previous cluster definitions '
help='File containing previous cluster definitions '
nickjcroucher marked this conversation as resolved.
Show resolved Hide resolved
'and network [default = use that in the directory '
'containing the model]',
type = str)
iGroup.add_argument('--previous-query-clustering',
help='Directory containing previous cluster definitions '
help='File containing previous cluster definitions '
'from poppunk_assign [default = use that in the directory '
'containing the model]',
'of the query database]',
type = str)
iGroup.add_argument('--display-cluster',
help='Column of clustering CSV to use for plotting',
default=None)

# output options
oGroup = parser.add_argument_group('Output options')
Expand Down Expand Up @@ -150,6 +153,7 @@ def generate_visualisations(query_db,
overwrite,
core_only,
accessory_only,
display_cluster,
web):

from .models import loadClusterFit
Expand Down Expand Up @@ -295,34 +299,37 @@ def generate_visualisations(query_db,
sys.exit(1)

# Load previous clusters
mode = "clusters"
suffix = "_clusters.csv"
if model.type == "lineage":
mode = "lineages"
suffix = "_lineages.csv"
if model.indiv_fitted:
sys.stderr.write("Note: Individual (core/accessory) fits found, but "
"visualisation only supports combined boundary fit\n")

# Set directories of previous fit
if previous_clustering is not None:
prev_clustering = previous_clustering
mode = "clusters"
suffix = "_clusters.csv"
if prev_clustering.endswith('_lineages.csv'):
mode = "lineages"
suffix = "_lineages.csv"
else:
prev_clustering = os.path.dirname(model_file)
cluster_file = prev_clustering + '/' + os.path.basename(prev_clustering) + suffix
isolateClustering = readIsolateTypeFromCsv(cluster_file,
# Identify type of clustering based on model
mode = "clusters"
suffix = "_clusters.csv"
if model.type == "lineage":
mode = "lineages"
suffix = "_lineages.csv"
if model.indiv_fitted:
sys.stderr.write("Note: Individual (core/accessory) fits found, but "
"visualisation only supports combined boundary fit\n")
prev_clustering = os.path.dirname(model_file) + '/' + os.path.basename(model_file) + suffix
isolateClustering = readIsolateTypeFromCsv(prev_clustering,
mode = mode,
return_dict = True)

# Join clusters with query clusters if required
if not self:
if previous_query_clustering is not None:
prev_query_clustering = previous_query_clustering + '/' + os.path.basename(previous_query_clustering)
prev_query_clustering = previous_query_clustering
else:
prev_query_clustering = query_db
prev_query_clustering = os.path.dirname(query_db) + '/' + os.path.basename(query_db) + suffix

queryIsolateClustering = readIsolateTypeFromCsv(
prev_query_clustering + suffix,
prev_query_clustering,
mode = mode,
return_dict = True)
isolateClustering = joinClusterDicts(isolateClustering, queryIsolateClustering)
Expand All @@ -348,7 +355,19 @@ def generate_visualisations(query_db,
weights_type=mst_distances,
summarise=False)
mst_graph = generate_minimum_spanning_tree(G)
drawMST(mst_graph, output, isolateClustering, overwrite)
# Check selecting clustering type is in CSV
clustering_name = 'Cluster'
if display_cluster != None:
if display_cluster not in isolateClustering.keys():
sys.stderr.write('Unable to find clustering column ' + display_cluster + ' in file ' +
prev_clustering + '\n')
sys.exit()
else:
clustering_name = display_cluster
else:
clustering_name = list(isolateClustering.keys())[0]
# Draw MST
drawMST(mst_graph, output, isolateClustering, clustering_name, overwrite)
mst_tree = mst_to_phylogeny(mst_graph, isolateNameToLabel(combined_seq))
else:
mst_tree = existing_tree
Expand Down Expand Up @@ -443,6 +462,7 @@ def main():
args.overwrite,
args.core_only,
args.accessory_only,
args.display_cluster,
web = False)

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion test/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
subprocess.run("python ../poppunk_visualise-runner.py --ref-db example_db --output example_viz --grapetree", shell=True, check=True)
subprocess.run("python ../poppunk_visualise-runner.py --ref-db example_db --output example_viz_subset --microreact --include-files subset.txt", shell=True, check=True)
subprocess.run("python ../poppunk_visualise-runner.py --ref-db example_db --query-db example_query --output example_viz_query --microreact", shell=True, check=True)
subprocess.run("python ../poppunk_visualise-runner.py --ref-db example_db --previous-clustering example_lineages --model-dir example_lineages --output example_lineage_viz --microreact", shell=True, check=True)
subprocess.run("python ../poppunk_visualise-runner.py --ref-db example_db --previous-clustering example_lineages/example_dbscan_clusters.csv --model-dir example_lineages --output example_lineage_viz --microreact", shell=True, check=True)
subprocess.run("python ../poppunk_visualise-runner.py --distances example_query/example_query.dists --ref-db example_db --model-dir example_lineages --query-db example_lineage_query --output example_viz_query_lineages --microreact", shell=True, check=True)

# MST
Expand Down