diff --git a/src/pmidcite/icite/entry.py b/src/pmidcite/icite/entry.py index 387f763..8c14aef 100644 --- a/src/pmidcite/icite/entry.py +++ b/src/pmidcite/icite/entry.py @@ -83,6 +83,10 @@ def from_jsondct(cls, icite_dct, nih_group_num): cls_dct['num_refs'] = len(icite_dct['references']) return cls(icite_dct['pmid'], cls_dct) + def get_authors(self): + """Get the list of authors from NIH's iCite for this paper""" + return self.dct.get('authors') + def get_au1_lastname(self): """Get the last name of the first author""" aus = self.dct['authors'] diff --git a/src/pmidcite/icite/paper.py b/src/pmidcite/icite/paper.py index 5d8a536..e5b0d55 100644 --- a/src/pmidcite/icite/paper.py +++ b/src/pmidcite/icite/paper.py @@ -50,18 +50,22 @@ def get_icite(self): """Get NIHiCiteEntry for this paper""" return self.pmid2icite[self.pmid] + def get_authors(self): + """Get authors for this paper""" + return self.pmid2icite[self.pmid].get_authors() + def str_line(self): """Return a string summarizing the the paper described herein""" txt = str(self.icite) if not self.pmid2note: return txt if self.pmid in self.pmid2note: - return '{TXT} {NOTE}'.format(TXT=txt, NOTE=self.pmid2note[self.pmid]) + return f'{txt} {self.pmid2note[self.pmid]}' return txt def prt_top(self, prt=stdout): """Print TOP paper""" - prt.write('TOP {iCite}\n'.format(iCite=self.str_line())) + prt.write(f'TOP {self.str_line()}\n') @staticmethod def prt_keys(prt=stdout): @@ -74,23 +78,21 @@ def prt_keys(prt=stdout): def prt_summary(self, prt=stdout, sortby_cites='nih_group', sortby_refs='nih_group'): """Print summary of paper""" if self.hdr: - prt.write('NAME: {NAME}\n'.format(NAME=self.hdr)) - prt.write('TOP {iCite}\n'.format(iCite=self.str_line())) + prt.write(f'NAME: {self.hdr}\n') + prt.write(f'TOP {self.str_line()}\n') # Citations by clinical papers if self.cited_by_clin: - prt.write('Cited by {N} Clinical papers:\n'.format(N=len(self.cited_by_clin))) + prt.write(f'Cited by {len(self.cited_by_clin)} Clinical papers:\n') self._prt_list(self.cited_by_clin, 'CLI', prt, sortby_cites) # Citations if self.cited_by: - prt.write('{N} of {M} citations downloaded:\n'.format( - N=len(self.cited_by), - M=self.icite.dct['citation_count'])) + prt.write(f'{len(self.cited_by)} of {self.icite.dct["citation_count"]} ' + 'citations downloaded:\n') self._prt_list(self.cited_by, 'CIT', prt, sortby_cites) # References if self.references: - prt.write('{N} of {M} References downloaded:\n'.format( - N=len(self.references), - M=self.icite.dct['num_refs'])) + prt.write(f'{len(self.references)} of {self.icite.dct["num_refs"]} ' + 'References downloaded:\n') self._prt_list(self.references, 'REF', prt, sortby_refs) def get_sorted(self, icites, sortby=None): @@ -109,13 +111,12 @@ def _prt_list(self, icites, desc, prt, sortby=None): s_pmid2note = self.pmid2note for icite in icites: if icite.pmid in s_pmid2note: - prt.write('{DESC} {iCite} {note}\n'.format( - DESC=desc, iCite=str(icite), note=s_pmid2note[icite.pmid])) + prt.write(f'{desc} {str(icite)} {s_pmid2note[icite.pmid]}\n') else: - prt.write('{DESC} {iCite}\n'.format(DESC=desc, iCite=str(icite))) + prt.write('{desc} {str(icite.}\n') return for icite in icites: - prt.write('{DESC} {iCite}\n'.format(DESC=desc, iCite=str(icite))) + prt.write('{desc} {str(icite)}\n') def _init_pmids(self, name): """Load citation/reference PMIDs, if the 'top' paper has NIH iCite data""" @@ -128,15 +129,5 @@ def __str__(self): """Get the line containing data downloaded from NIH iCite for only the featured paper""" return self.str_line() - ## TBD: - ## def __eq__(self, rhs): - ## if self.pmid != rhs.pmid: - ## return False - ## if self.cited_by != rhs.cited_by: - ## print('LHS:', self.cited_by) - ## print('RHS:', rhs.cited_by) - ## return False - ## return True - # Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/tests/test_selfcite.py b/src/tests/test_selfcite.py index a7d393f..9e39e30 100755 --- a/src/tests/test_selfcite.py +++ b/src/tests/test_selfcite.py @@ -1,20 +1,18 @@ #!/usr/bin/env python3 -"""Test self-citing functions""" +"""Test getting all authors for a bunch of papers""" from pmidcite.cfg import Cfg -from pmidcite.icite.entry import NIHiCiteEntry -#from pmidcite.cli.entry_keyset import get_details_cites_refs from pmidcite.icite.downloader import get_downloader def test_selfcite(): - """Test self-citing functions""" - authors = [ - 'Nasserdine Papa Mze', - 'Cécile Fernand-Laurent', - 'Solen Daugabel', - 'Olfa Zanzouri', - 'Stéphanie Marque Juillet', - ] + """Test getting all authors for a bunch of papers""" + #authors = [ + # 'Nasserdine Papa Mze', + # 'Cécile Fernand-Laurent', + # 'Solen Daugabel', + # 'Olfa Zanzouri', + # 'Stéphanie Marque Juillet', + #] ref_pmids = [ 30753724, # TOP 30753724 H.M.c 40 2 2019 10 1 22 au[41](Lambert Assoumou) 30517632, # TOP 30517632 H.M.. 21 2 2019 5 0 35 au[17](Paula C Aulicino) @@ -31,28 +29,20 @@ def test_selfcite(): ] cfg = Cfg() - - details_cites_refs = set(NIHiCiteEntry.associated_pmid_keys) - print(f'details_cites_refs: {details_cites_refs}') - groupobj = cfg.get_nihgrouper() - print(groupobj) - dnldr = get_downloader(groupobj) - print(dnldr) - pmid2icitepaper = dnldr.get_pmid2paper(ref_pmids, None) # Get PMID and pmidcite.icite.paper.NIHiCitePaper - # TODO: Improve researcher experience here + pmid2icitepaper = dnldr.get_pmid2paper(ref_pmids, None) for pmid, icitepaper in pmid2icitepaper.items(): - entry = icitepaper.get_icite() - authors = entry.dct['authors'] - print(entry) - for author in authors: - print(f'{pmid:8} {author}') - - print() - print(entry.dct.keys()) + for author in icitepaper.get_authors(): + print(f'PAPER: {pmid:8} {author}') + + # Even simpler: + # Get pmidcite.icite.paper.NIHiCiteEntry for each PMID in the references + for icitepaper in dnldr.get_icites(ref_pmids): + for author in icitepaper.get_authors(): + print(f'iCite: {icitepaper.pmid:8} {author}') if __name__ == '__main__':