aboutsummaryrefslogtreecommitdiff
path: root/uploader/phenotypes/misc.py
blob: cbe3b7f8eaf8545f657994d7694a6f3a60b6c6ac (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Miscellaneous functions handling phenotypes and phenotypes data."""
import logging

logger = logging.getLogger(__name__)


def phenotypes_data_differences(
        filedata: tuple[dict, ...], dbdata: tuple[dict, ...]
) -> tuple[dict, ...]:
    """Compute differences between file data and db data"""
    diff = tuple()
    for filerow, dbrow in zip(
            sorted(filedata, key=lambda item: (item["phenotype_id"], item["xref_id"])),
            sorted(dbdata, key=lambda item: (item["PhenotypeId"], item["xref_id"]))):
        for samplename, value in filerow["data"].items():
            if value != dbrow["data"].get(samplename, {}).get("value"):
                diff = diff + ({
                    "PhenotypeId": filerow["phenotype_id"],
                    "xref_id": filerow["xref_id"],
                    "DataId": dbrow["DataId"],
                    "StrainId": dbrow["data"].get(samplename, {}).get("StrainId"),
                    "StrainName": samplename,
                    "value": value
                },)

    return diff