Skip to content

Commit

Permalink
Merge branch 'network_relabelling' of https://github.com/bacpop/PopPUNK
Browse files Browse the repository at this point in the history
… into network_relabelling
  • Loading branch information
nickjcroucher committed Jan 9, 2025
2 parents 8d9771a + 6c3ebfb commit 13be252
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 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.7.2'
__version__ = '2.7.3'

# Minimum sketchlib version
SKETCHLIB_MAJOR = 2
Expand Down
Binary file modified PopPUNK/data/microreact_example.pkl
Binary file not shown.
30 changes: 28 additions & 2 deletions PopPUNK/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ def outputsForMicroreact(combined_list, clustering, nj_tree, mst_tree, accMat, p

return outfiles

def createMicroreact(prefix, microreact_files, api_key=None):
def createMicroreact(prefix, microreact_files, api_key=None, info_csv=None):
"""Creates a .microreact file, and instance via the API
Args:
Expand All @@ -846,6 +846,8 @@ def createMicroreact(prefix, microreact_files, api_key=None):
List of Microreact files [clusters, dot, tree, mst_tree]
api_key (str)
API key for your account
info_csv (str)
CSV file containing additional information for Microreact
"""
import pkg_resources
import pickle
Expand All @@ -859,7 +861,10 @@ def createMicroreact(prefix, microreact_files, api_key=None):
with pkg_resources.resource_stream(__name__, 'data/microreact_example.pkl') as example_pickle:
json_pickle = pickle.load(example_pickle)
json_pickle["meta"]["name"] = description_string


# Update maps and timelines
update_maps_timelines(json_pickle, info_csv)

# Read data in
with open(microreact_files[0]) as cluster_file:
csv_string = cluster_file.read()
Expand Down Expand Up @@ -898,6 +903,27 @@ def createMicroreact(prefix, microreact_files, api_key=None):

return url

def update_maps_timelines(micoreact_sample_json, info_csv=None):
"""
Update the maps and timelines in the Microreact JSON file.
Removes maps and timelines if the required columns are not present in the info CSV.
Args:
micoreact_sample_json (dict)
Microreact JSON file
info_csv (str)
CSV file containing additional information for Microreact
"""
if info_csv is None:
micoreact_sample_json["maps"] = {}
micoreact_sample_json["timelines"] = {}
else:
info_df = pd.read_csv(info_csv)
if 'latitude' not in info_df.columns or 'longitude' not in info_df.columns:
micoreact_sample_json["maps"] = {}
if 'year' not in info_df.columns:
micoreact_sample_json["timelines"] = {}

def outputsForPhandango(combined_list, clustering, nj_tree, mst_tree, outPrefix, epiCsv,
queryList = None, overwrite = False):
"""Generate files for Phandango
Expand Down
2 changes: 1 addition & 1 deletion PopPUNK/visualise.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ def generate_visualisations(query_db,
n_threads=threads,
use_gpu=gpu_graph,
device_id=deviceid)
url = createMicroreact(output, microreact_files, api_key)
url = createMicroreact(output, microreact_files, api_key, info_csv)
if url != None:
sys.stderr.write("Microreact: " + url + "\n")
else:
Expand Down
13 changes: 13 additions & 0 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,18 @@ used to assign new queries.
If you want to change cluster names or assign queries to your own cluster definitions
you can use the ``--external-clustering`` argument instead.

"No non-zero Jaccard distances" Error
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
When running ``--create-db`` or ``poppunk_assign`` as::

No non-zero Jaccard distances
Fitting k-mer gradient failed, for:SampleAvs.SampleB

Means that ``SampleA`` and ``SampleB`` are not the same species or are highly contaminated,
and so share no k-mers with eachother. This may cause PopPUNK to hang, crash, or finish but not generate
output files.

To fix this error, check that genomes for ``SampleA`` and ``SampleB``
are the correct species (e.g. using `BLAST <https://blast.ncbi.nlm.nih.gov/Blast.cgi>`_ or `Kraken2 <https://github.com/DerrickWood/kraken2>`_); if not, remove them from your input file and re-run your analysis.


0 comments on commit 13be252

Please sign in to comment.