aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorBonfaceKilz2022-01-26 11:13:43 +0300
committerBonfaceKilz2022-01-26 11:34:07 +0300
commitea146928a397d8a813ccd169e1e532fd623f8998 (patch)
tree7b5e5888b89905634af2a19f16236ad188a74bf9 /wqflask
parentb8a3ac8a4d60e74f893a6714b8440ad6758a7fbd (diff)
downloadgenenetwork2-ea146928a397d8a813ccd169e1e532fd623f8998.tar.gz
wqflask: Ignore diffs with |ε| < 0.001
* wqflask/wqflask/metadata_edits.py (update_phenotype): Filter out values with |ε| < 0.001 when generating the diff file.
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/metadata_edits.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/wqflask/wqflask/metadata_edits.py b/wqflask/wqflask/metadata_edits.py
index dc738f88..c1121774 100644
--- a/wqflask/wqflask/metadata_edits.py
+++ b/wqflask/wqflask/metadata_edits.py
@@ -257,9 +257,29 @@ def update_phenotype(dataset_id: str, name: str):
r = run_cmd(cmd=("csvdiff "
f"'{uploaded_file_name}' '{new_file_name}' "
"--format json"))
+ json_data = json.loads(r.get("output"))
+
+ # Only consider values where |ε| < 0.001; otherwise, use the
+ # old value in "Original".
+ _modifications = []
+ for m in json_data.get("Modifications"):
+ _original = m.get("Original").split(",")
+ _current = m.get("Current").split(",")
+ for i, (x, y) in enumerate(zip(_original, _current)):
+ if (x.replace('.', '').isdigit()
+ and y.replace('.', '').isdigit()
+ and abs(float(x) - float(y)) < 0.001):
+ _current[i] = x
+ if not (__o:=",".join(_original)) == (__c:=",".join(_current)):
+ _modifications.append(
+ {
+ "Original": __o,
+ "Current": __c,
+ })
+ json_data['Modifications'] = _modifications
# Edge case where the csv file has not been edited!
- if not any(json.loads(r.get("output")).values()):
+ if not any(json_data.values()):
flash(f"You have not modified the csv file you downloaded!",
"warning")
return redirect(f"/datasets/{dataset_id}/traits/{name}"
@@ -267,7 +287,7 @@ def update_phenotype(dataset_id: str, name: str):
diff_output = (f"{TMPDIR}/sample-data/diffs/"
f"{_file_name}.json")
with open(diff_output, "w") as f:
- dict_ = json.loads(r.get("output"))
+ dict_ = json_data
dict_.update({
"trait_name": str(name),
"phenotype_id": str(phenotype_id),