From 3bce1c9f3a687069738267e74ca8c093f629544d Mon Sep 17 00:00:00 2001 From: anmol thapar Date: Tue, 7 Jan 2025 10:49:10 +0000 Subject: [PATCH 1/3] Add info_csv parameter to createMicroreact for conditional map and timeline handling --- PopPUNK/data/microreact_example.pkl | Bin 38827 -> 39577 bytes PopPUNK/plot.py | 14 +++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/PopPUNK/data/microreact_example.pkl b/PopPUNK/data/microreact_example.pkl index ec31f47ad7510451aba0ad7b1160e5a01856a051..648127a34d8c159f490f4b16f0d07da9f69069b3 100644 GIT binary patch delta 846 zcmY*X!DGV3NQtV;-ZP|$;i>_Ly7;woO&-4&Avf)Xk-&2*cd>7l#FWQ4FD zS11J8HbH;EgLv@fr}z*4g4MH|HMv#2s;+wPRe%4n{Povz_#yc6>D$k6>1-TkP;~FR zQ+E%eSmjnLY1{;(1T5@T1#`HWGL>p5xQM&4QaTYiSY{lqrCOB*OQ^k5hXc?@Oq*Wy zf~7*`?jwd0j8PP{vRQ3ZKrC$K`Uy5OI2n#r!gj@b=K4DXhsathe7GZ3^96l;lz;lFxs0haQrT| pDh9fn(WmF#1S*Hy4Uf!420kVY(9yp0K?ZB!T Date: Tue, 7 Jan 2025 12:09:44 +0000 Subject: [PATCH 2/3] Bump version to 2.7.3 and refactor createMicroreact to use update_maps_timelines for handling maps and timelines based on info_csv --- PopPUNK/__init__.py | 2 +- PopPUNK/plot.py | 37 ++++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/PopPUNK/__init__.py b/PopPUNK/__init__.py index d7f9d184..c6757346 100644 --- a/PopPUNK/__init__.py +++ b/PopPUNK/__init__.py @@ -3,7 +3,7 @@ '''PopPUNK (POPulation Partitioning Using Nucleotide Kmers)''' -__version__ = '2.7.2' +__version__ = '2.7.3' # Minimum sketchlib version SKETCHLIB_MAJOR = 2 diff --git a/PopPUNK/plot.py b/PopPUNK/plot.py index f9ccf58b..4ffafe48 100644 --- a/PopPUNK/plot.py +++ b/PopPUNK/plot.py @@ -846,6 +846,8 @@ def createMicroreact(prefix, microreact_files, api_key=None, info_csv=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 @@ -861,17 +863,9 @@ def createMicroreact(prefix, microreact_files, api_key=None, info_csv=None): json_pickle = pickle.load(example_pickle) json_pickle["meta"]["name"] = description_string - # remove maps and timelines if not present in csv columns - if info_csv is None: - json_pickle["maps"] = {} - json_pickle["timelines"] = {} - else: - info_df = pd.read_csv(info_csv) - if 'latitude' not in info_df.columns or 'longitude' not in info_df.columns: - json_pickle["maps"] = {} - if 'date' not in info_df.columns: - json_pickle["timelines"] = {} - + # 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() @@ -910,6 +904,27 @@ def createMicroreact(prefix, microreact_files, api_key=None, info_csv=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 From ce87e8e5e57e837c47f7098e94ec499ad791eba6 Mon Sep 17 00:00:00 2001 From: anmol thapar Date: Tue, 7 Jan 2025 12:24:05 +0000 Subject: [PATCH 3/3] Remove unused pandas import from createMicroreact function --- PopPUNK/plot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/PopPUNK/plot.py b/PopPUNK/plot.py index 4ffafe48..2328c160 100644 --- a/PopPUNK/plot.py +++ b/PopPUNK/plot.py @@ -854,7 +854,6 @@ def createMicroreact(prefix, microreact_files, api_key=None, info_csv=None): import requests import json from datetime import datetime - import pandas as pd microreact_api_new_url = "https://microreact.org/api/projects/create" description_string = "PopPUNK run on " + datetime.now().strftime("%Y-%b-%d %H:%M")