Skip to content

Commit

Permalink
Merge pull request #342 from bacpop/update-microreact-json
Browse files Browse the repository at this point in the history
Update sample microreact.pkl to include maps & timelines
  • Loading branch information
johnlees authored Jan 7, 2025
2 parents 377f2f1 + ce87e8e commit 09e9c3d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 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

0 comments on commit 09e9c3d

Please sign in to comment.