Skip to content

Commit 23452cb

Browse files
committed
Replace string with variable
1 parent 468f76e commit 23452cb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

locidex/merge.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ def read_samplesheet(sample_key_file):
206206
return sampledict
207207

208208
def validate_profiles(mlst, sample_id, file_name):
209+
data_key = "data"
210+
profile_key = "profile"
209211
# Extract the profile from the json_data
210-
profile = mlst.get("data", {}).get("profile", {})
212+
profile = mlst.get(data_key, {}).get(profile_key, {})
211213
# Check for multiple keys in the JSON file and define error message
212214
keys = sorted(profile.keys())
213215
original_key = keys[0] if keys else None
@@ -225,16 +227,16 @@ def validate_profiles(mlst, sample_id, file_name):
225227
if not match_status:
226228
MLST_message = f"No key in the MLST JSON file ({file_name}) matches the specified sample ID '{sample_id}'. The first key '{original_key}' has been forcefully changed to '{sample_id}' and all other keys have been removed."
227229
# Retain only the specified sample ID
228-
mlst["data"]["profile"] = {sample_id: profile.pop(original_key)}
230+
mlst[data_key][profile_key] = {sample_id: profile.pop(original_key)}
229231
else:
230232
MLST_message = f"MLST JSON file ({file_name}) contains multiple keys: {keys}. The MLST JSON file has been modified to retain only the '{sample_id}' entry"
231233
# Retain only the specified sample_id in the profile
232-
mlst["data"]["profile"] = {sample_id: profile[sample_id]}
234+
mlst[data_key][profile_key] = {sample_id: profile[sample_id]}
233235
elif not match_status:
234236
MLST_message = f"{sample_id} ID and JSON key in {file_name} DO NOT MATCH. The '{original_key}' key in {file_name} has been forcefully changed to '{sample_id}': User should manually check input files to ensure correctness."
235237
# Update the JSON file with the new sample ID
236-
mlst["data"]["profile"] = {sample_id: profile.pop(original_key)}
237-
mlst["data"]["sample_name"] = sample_id
238+
mlst[data_key][profile_key] = {sample_id: profile.pop(original_key)}
239+
mlst[data_key]["sample_name"] = sample_id
238240

239241
# Create a report for all the samples that have their profiles modified in the output profile.tsv
240242
if MLST_message:

0 commit comments

Comments
 (0)