about summary refs log tree commit diff
path: root/uploader/publications/misc.py
blob: f0ff9c7313fcc1f1cda989d9efeb70f0aedbff2f (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: dict[int, int]
) -> tuple[dict, ...]:
    """Compute the differences between file data and db data"""
    diff: tuple[dict, ...] = 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