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

Update sample microreact.pkl to include maps & timelines #342

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading