def get_publications( sup_cur: db.Cursor, permitted_people: Dict[int, Person] ) -> Mapping[str, Publication]: print("Gathering publications") authorships = db.get_pubmed_authorships(sup_cur) pubs = db.get_pubmed_publications(sup_cur) publications = {} for pmid, xml in pubs.items(): if pmid not in authorships: continue try: pub = Publication.from_pubmed(xml) assert pub and pub.pmid == pmid for author in authorships[pmid]: if author in permitted_people: pub.add_author(author) publications[pmid] = pub except Exception: traceback.print_exc() print(f"Skipping publication {pmid}") return publications
def add_developers(sup_cur: db.Cursor) -> None: pmids = set(tools.MetabolomicsToolsWiki.pmids()) total = len(pmids) if total == 0: return publications = db.get_pubmed_publications(sup_cur, pmids) pmids = pmids.intersection(publications.keys()) print(f"Found {len(pmids)} of {total} tools-related publications in the " "Supplemental database.") if len(pmids) == 0: return for pmid in pmids: author_list = parse_author_list(publications[pmid]) for author in author_list: forename = author.findtext("ForeName", "").strip() lastname = author.findtext("LastName", "").strip() if not forename: print(f"PMID {pmid}: missing forename of author {lastname}") continue if not lastname: print(f"PMID {pmid}: missing surname of author {forename}") continue matches = list(db.get_person(sup_cur, forename, lastname)) if len(matches) > 1: print(f"PMID {pmid}: WARNING! Found {len(matches)} people " f" named {forename} {lastname}: {matches}") continue if matches: pid = matches[0] print(f"PMID {pmid}: found {forename} {lastname}: {pid}") else: pid = db.add_person(sup_cur, forename, lastname, "", "") if not pid: print(f"PMID {pmid}: WARNING failed to add person: " f"{forename} {lastname}") continue print(f"PMID {pmid}: added {forename} {lastname}: {pid}") affiliation_list = author.findall(".//Affiliation") for element in affiliation_list: affiliation = element.text if affiliation is None or affiliation.strip() == '': continue print(f"PMID {pmid}: affiliation for {forename} {lastname}" f": {affiliation.strip()}") return
def get_authors_pmid(sup_cur: db.Cursor, pmid: str) -> List[Dict[str, str]]: try: authors = [] pubs = db.get_pubmed_publications(sup_cur, pmids=[pmid]) if pmid not in pubs: print(f'PMID {pmid}: Could not find PubMed data') return [] author_list = prefill.parse_author_list(pubs[pmid]) for author in author_list: forename = author.findtext('ForeName', '').strip() surname = author.findtext('LastName', '').strip() auth = {'name': f'{forename} {surname}'.strip()} authors.append(auth) return authors except Exception: traceback.print_exc() print(f'Error parsing PubMed Data for tool with PMID {pmid}') return []