aboutsummaryrefslogtreecommitdiff
path: root/uploader/publications/misc.py
blob: fca6f712f43af52d878a44b863c5512969e280a9 (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
"""Miscellaneous functions dealing with publications."""


def publications_differences(
        filedata: tuple[dict, ...],
        dbdata: tuple[dict, ...],
        pubmedid2pubidmap: tuple[dict, ...]
) -> tuple[dict, ...]:
    """Compute the 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"]))):
        if filerow["PubMed_ID"] == dbrow["PubMed_ID"]:
            continue

        newpubmed = filerow["PubMed_ID"]
        diff = diff + ({
            **dbrow,
            "PubMed_ID": newpubmed,
            "PublicationId": pubmedid2pubidmap.get(newpubmed)},)

    return diff