diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 34cd6d3..926ecad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,5 +29,5 @@ jobs: - name: Test with pytest run: | - pip install pytest pytest-cov + pip install pytest coverage make pytest diff --git a/CITATION.cff b/CITATION.cff index dd5a087..c580bd9 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -1,5 +1,5 @@ cff-version: 1.2.0 -message: "If you use this software, please cite it as below." +message: "If you use this project, please cite it as below." authors: - family-names: "Klopfenstein" given-names: "DV" @@ -11,6 +11,7 @@ title: "pmidcite" version: 0.0.18 doi: 10.5281/zenodo.5172712 keywords: + - "Google Scholar" - CitedBy - PubMed - PMID @@ -19,6 +20,7 @@ keywords: - "forward snowball" - "backward snowball" - "literature review" + - "literature search" - "citation downloader" contact: - email: dvklopfenstein@protonmail.com @@ -36,6 +38,7 @@ preferred-citation: given-names: "Will" doi: "10.1002/jrsm.1456" journal: "Research Synthesis Methods" + publisher: "Wiley" month: 3 start: 126 # First page number end: 135 # Last page number @@ -43,15 +46,20 @@ preferred-citation: issue: 2 volume: 12 year: 2021 + pmid:33031632 + eprint:33031632 + eprinttype:pubmed keywords: - CitedBy - PubMed - PMID + - "Google Scholar" - "forward citation" - "backward citation" - "forward snowball" - "backward snowball" - "literature review" + - "literature search" - "citation downloader" contact: - email: dvklopfenstein@protonmail.com diff --git a/doc/example_cfg/.pmidciterc b/doc/example_cfg/.pmidciterc index db689c6..e44eb9c 100644 --- a/doc/example_cfg/.pmidciterc +++ b/doc/example_cfg/.pmidciterc @@ -49,10 +49,10 @@ tool = scripts # # # PMID 33031632 is a new (-1) research (R) paper discussing humans (H) # # with 2 citations and 18 references that is authored by 2 (au[02]) people with -# # the first author being DV Klopfenstein. +# # the first author being DV Klopfenstein, PhD. # # # $ icite 33031632 -# TOP 33031632 R. H.... -1 i 2021 2 0 18 au[02](D V Klopfenstein) Commentary ... +# TOP 33031632 R. H.... -1 i 2021 2 0 18 au[02](D V Klopfenstein, PhD) Commentary ... # # Thousands of NIH citation files may be downloaded for a literature search # on a single subject. It is not necessary to save the NIH citation data and I diff --git a/makefile b/makefile index 39724e9..adb5590 100644 --- a/makefile +++ b/makefile @@ -45,7 +45,8 @@ pylint: pytest: make clobber_tmp - python3 --version; python3 -m pytest --cov=pmidcite -v src/tests | tee pytest.log + coverage run -m pytest -v src/tests --log-file=pytest.log + #python3 --version; python3 -m pytest --cov=pmidcite -v src/tests | tee pytest.log #### python3 -m pytest $(TESTS) ver: @@ -76,7 +77,7 @@ vim_md: build: # python3 -m pip install -U pip # python3 -m pip install --user --upgrade setuptools wheel - make clean_dist + make clean_build $(PYTHON) setup.py sdist $(PYTHON) setup.py bdist_wheel --universal ls -lh dist @@ -95,7 +96,7 @@ upgrade: $(PYTHON) -m pip install --upgrade setuptools wheel twine $(PYTHON) -m pip install --upgrade distutils -clean_dist: +clean_build: rm -rf dist build pyc: @@ -121,11 +122,11 @@ clean: rm -rf notebooks/icite rm -rf src/tests/icite make clobber_tmp - make clean_dist + make clean_build clobber_tmp: rm -rf ./icite rm -rf ./src/tests/icite clobber: - make -f makefile clobber_tmp clean_dist + make -f makefile clobber_tmp clean_build diff --git a/setup.py b/setup.py index fe5ad83..53ae595 100755 --- a/setup.py +++ b/setup.py @@ -51,7 +51,7 @@ def get_long_description(): entry_points={ 'console_scripts':[ 'icite=pmidcite.scripts.icite:main', - 'summarize_papers=pmidcite.scripts.icite:summarize_papers', + 'sumpaps=pmidcite.scripts.summarize_papers:main', ], }, # https://pypi.org/classifiers/ diff --git a/src/bin/dnld_pmids.py b/src/bin/dnld_pmids.py index cabf549..226e99a 100755 --- a/src/bin/dnld_pmids.py +++ b/src/bin/dnld_pmids.py @@ -32,7 +32,7 @@ def main(): # $ src/bin/dnld_pmids.py -2 # obj = PubMedQueryToICite(force_dnld=True) - dnld_idx = obj.get_index(sys.argv) + dnld_idx = obj.get_index(sys.argv, queries) obj.run(queries, dnld_idx) diff --git a/src/bin/icite.py b/src/bin/icite.py index b95500a..3290e05 100755 --- a/src/bin/icite.py +++ b/src/bin/icite.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 """Given a PubMed ID (PMID), return a list of citing publications""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from pmidcite.cli.icite import NIHiCiteCli # get_argparser from pmidcite.cfg import get_cfgparser @@ -16,4 +16,4 @@ def main(): if __name__ == '__main__': main() -# Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/bin/summarize_papers.py b/src/bin/summarize_papers.py index ea1762f..035e3e2 100755 --- a/src/bin/summarize_papers.py +++ b/src/bin/summarize_papers.py @@ -1,18 +1,13 @@ #!/usr/bin/env python3 """Summarize NIH citation data for requested papers from the commandline or in files""" -__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" -from pmidcite.cli.summarize_papers import SummarizePapersCli # get_argparser -from pmidcite.cfg import get_cfgparser +from pmidcite.scripts.summarize_papers import main -def main(): - """Summarize NIH citation data for requested papers from the commandline or in files""" - SummarizePapersCli(get_cfgparser(prt=None)).cli() - if __name__ == '__main__': main() -# Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/__init__.py b/src/pmidcite/__init__.py index 7570c50..4790bca 100644 --- a/src/pmidcite/__init__.py +++ b/src/pmidcite/__init__.py @@ -1,7 +1,7 @@ """Code to access NIH's iCite API""" -__copyright__ = 'Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved' -__author__ = 'DV Klopfenstein, PhD, PhD' +__copyright__ = 'Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved' +__author__ = 'DV Klopfenstein, PhD.' -# Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved +# Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved diff --git a/src/pmidcite/__version__.py b/src/pmidcite/__version__.py index 7b7a606..120a12c 100644 --- a/src/pmidcite/__version__.py +++ b/src/pmidcite/__version__.py @@ -1,7 +1,7 @@ """Version of pmidcite project""" -__copyright__ = 'Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved' -__author__ = ' DV Klopfenstein, PhD, PhD' +__copyright__ = 'Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved' +__author__ = ' DV Klopfenstein, PhD. __version__ = '0.0.45' -# Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved +# Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved diff --git a/src/pmidcite/cfg.py b/src/pmidcite/cfg.py index d2d3583..d25ef73 100644 --- a/src/pmidcite/cfg.py +++ b/src/pmidcite/cfg.py @@ -1,7 +1,7 @@ """Manage pmidcite Configuration""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from os import environ from os import getcwd @@ -229,4 +229,4 @@ def _init_cfgfilename(self, prt=None): -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/citation.py b/src/pmidcite/citation.py new file mode 100644 index 0000000..9b20e75 --- /dev/null +++ b/src/pmidcite/citation.py @@ -0,0 +1,41 @@ +"""Cite the pmidcite project""" + +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" + + +CITATION = """ +If you use pmidcite in your research or literature search, +please cite the publication in any papers, pre-prints or reports. +The proper citation information for pmidcite appears below. + +Reference: +========== + +Klopfenstein, D.V., & Dampier, W. (2021). +Commentary to Gusenbauer and Haddaway 2020: Evaluating retrieval qualities of Google Scholar and PubMed. +Research Synthesis Methods, 12(2), 126–135. https://doi.org/10.1002/jrsm.1456 + + +bibtex: +======= + +@article{Klopfenstein_2021, + author = {Klopfenstein, DV and Dampier, Will}, + doi = {10.1002/jrsm.1456}, + pmid = {33031632}, + eprint = {33031632}, + eprinttype = {pubmed}, + url = {https://onlinelibrary.wiley.com/doi/10.1002/jrsm.1456} + journal = {Research Synthesis Methods}, + publisher = {{Wiley}}, + month = {mar}, + number = {2}, + pages = {126--135}, + title = {{Commentary to Gusenbauer and Haddaway 2020: Evaluating retrieval qualities of Google Scholar and PubMed}}, + volume = {12}, + year = {2021} +} +""" + +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/cli/dnldpubmed.py b/src/pmidcite/cli/dnldpubmed.py index d44533f..bf5f2ad 100644 --- a/src/pmidcite/cli/dnldpubmed.py +++ b/src/pmidcite/cli/dnldpubmed.py @@ -1,7 +1,7 @@ """Given PMIDs, download PubMed entries into a text file""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" import argparse @@ -65,4 +65,4 @@ def _get_pmids(args, argparser): return pmids -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/cli/icite.py b/src/pmidcite/cli/icite.py index 4bf039f..631636a 100644 --- a/src/pmidcite/cli/icite.py +++ b/src/pmidcite/cli/icite.py @@ -1,12 +1,14 @@ """Manage args for NIH iCite run for one PubMed ID (PMID)""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from sys import stdout -import argparse +from sys import exit as sys_exit +from argparse import ArgumentParser from pmidcite.eutils.cmds.pubmed import PubMed +from pmidcite.citation import CITATION from pmidcite.cfgini import prt_rcfile from pmidcite.cli.utils import get_outfile from pmidcite.cli.utils import get_pmids @@ -29,7 +31,7 @@ def __init__(self, cfg): def get_argparser(self): """Argument parser for Python wrapper of NIH's iCite given PubMed IDs""" - parser = argparse.ArgumentParser( + parser = ArgumentParser( description="Run NIH's iCite given PubMed IDs", add_help=False) cfg = self.cfg @@ -42,6 +44,9 @@ def get_argparser(self): parser.add_argument( '-h', '--help', action='store_true', help='print this help message and exit (also --help)') + parser.add_argument( + '--cite', action='store_true', + help='publication citation for the pmidcite project') parser.add_argument( 'pmids', metavar='PMID', type=int, nargs='*', help='PubMed IDs (PMIDs)') @@ -91,17 +96,15 @@ def get_argparser(self): help='Download PubMed entry containing title, abstract, authors, journal, MeSH, etc.') self.cfg.get_nihgrouper().add_arguments(parser) # - directories ---------------------------------------------------------------------- - # pylint: disable=line-too-long parser.add_argument( '--dir_icite_py', default=dflt_dir_icite_py, - help='Write PMID iCite information into directory which contains temporary working files (default={D})'.format( - D=dflt_dir_icite_py)) + help=f'Write PMID iCite information into directory which contains temporary working files (default={dflt_dir_icite_py})') parser.add_argument( '--dir_icite', default=dflt_dir_icite, - help='Write PMID icite reports into directory (default={D})'.format(D=dflt_dir_icite)) + help=f'Write PMID icite reports into directory (default={dflt_dir_icite})') parser.add_argument( '--dir_pubmed_txt', default=dflt_dir_pubmed_txt, - help='Write PubMed entry into directory (default={D})'.format(D=dflt_dir_pubmed_txt)) + help=f'Write PubMed entry into directory (default={dflt_dir_pubmed_txt})') # ------------------------------------------------------------------------------------ parser.add_argument( '--md', action='store_true', @@ -120,7 +123,7 @@ def cli(self): """Run iCite/PubMed using command-line interface""" argparser = self.get_argparser() args = self._get_args(argparser) - ##print('ICITE ARGS ../pmidcite/src/pmidcite/cli/icite.py', args) + ## print('ICITE ARGS ../pmidcite/src/pmidcite/cli/icite.py', args) self._run(args, argparser) def _run(self, args, argparser): @@ -128,13 +131,16 @@ def _run(self, args, argparser): if args.help: argparser.print_help() print('\nHelp message printed because: -h or --help == True') - exit() + sys_exit() + if args.cite: + print(CITATION) + sys_exit() self.prt_info(args) # Get a list of researcher-specified PMIDs pmids = get_pmids(args.pmids, args.infile) if pmids: if len(pmids) > 10: - print('PROCESSING {N:,} PMIDs'.format(N=len(pmids))) + print(f'PROCESSING {len(pmids):,} PMIDs') dnldr = self._get_downloader(args) pmid2icitepaper = dnldr.get_pmid2paper(pmids, None) ## print('XXXXXXXXXXXXXXXXXXXXXXXXXXXX pmid2icitepaper', pmid2icitepaper) @@ -193,7 +199,6 @@ def _get_args(self, argparser): args.load_references = True return args - # pylint: disable=too-many-arguments def run_icite(self, pmid2icitepaper_all, dnldr, args, argparser): """Run iCite/PubMed""" pmid2icitepaper_cur = self.run_icite_pre(pmid2icitepaper_all, args, argparser) @@ -225,7 +230,7 @@ def _prt_infiles(infiles): """Print input files""" if infiles: for fin in infiles: - print('**ERROR: NO PMIDs found in: {F}'.format(F=fin)) + print(f'**ERROR: NO PMIDs found in: {fin}') @staticmethod def run_icite_wr(pmid2icitepaper, args, dnldr): @@ -246,19 +251,18 @@ def run_icite_wr(pmid2icitepaper, args, dnldr): def _wr_papers(self, pmid2icitepaper, dnldr, print_header): """Write one icite report per PMID into dir_icite/PMID.txt""" for pmid, paper in pmid2icitepaper.items(): - fout_txt = self.cfg.get_fullname_icite('{PMID}.txt'.format(PMID=pmid)) - with open(fout_txt, 'w') as prt: + fout_txt = self.cfg.get_fullname_icite(f'{pmid}.txt') + with open(fout_txt, 'w', encoding='utf8') as prt: if print_header: prt_hdr(prt) dnldr.prt_papers({pmid:paper}, prt) - print(' WROTE: {TXT}'.format(TXT=fout_txt)) + print(f' WROTE: {fout_txt}') @staticmethod def _prt_no_icite(pmids): if not pmids: return - print('**NOTE: No NIH iCite papers found for: {Ps}'.format( - Ps=' '.join(str(p) for p in pmids))) + print('**NOTE: No NIH iCite papers found for: {" ".join(str(p) for p in pmids)}') -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/cli/readpmids.py b/src/pmidcite/cli/readpmids.py index 45adff9..d28bd4e 100644 --- a/src/pmidcite/cli/readpmids.py +++ b/src/pmidcite/cli/readpmids.py @@ -65,11 +65,11 @@ def cli(self): dct = get_outfile(args.outfile, None, args.force_write) outfile = self._get_outfile(args, dct) if pmids: - self._wr_icite(outfile, pmids, args) + self._wr_icite_pmids(outfile, pmids, args) else: print('XXX', outfile, pmids) - def _wr_icite(self, outfile, pmids, args): + def _wr_icite_pmids(self, outfile, pmids, args): """Write an iCite report for the provided PMIDs""" grouperobj = NihGrouper(args.min1, args.min2, args.min3, args.min4) details_cites_refs = get_details_cites_refs( @@ -121,9 +121,9 @@ def rd_pmidtxts(fins_pmidcite): pmids.append(pmid) seen.add(pmid) else: - print(' MISSING: {FILE}'.format(FILE=fin)) + print(f' MISSING: {fin}') if len(fins_pmidcite) != 1: - print('{N:6} PMIDs READ'.format(N=len(pmids))) + print(f'{len(pmids):6} PMIDs READ') return pmids diff --git a/src/pmidcite/cli/summarize_papers.py b/src/pmidcite/cli/summarize_papers.py index 1c9a7b8..7195643 100644 --- a/src/pmidcite/cli/summarize_papers.py +++ b/src/pmidcite/cli/summarize_papers.py @@ -7,8 +7,8 @@ from pmidcite.summarize_papers import SummarizePapers from pmidcite.icite.top_cit_ref import TopCitRef -__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" class SummarizePapersCli: @@ -80,4 +80,4 @@ def _summarize_papers(files, nih_grouper, top_cit_refs): print(sumpap.str_oneline()) -# Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/cli/utils.py b/src/pmidcite/cli/utils.py index b21b474..c2190c3 100644 --- a/src/pmidcite/cli/utils.py +++ b/src/pmidcite/cli/utils.py @@ -1,7 +1,7 @@ """Read a file created by pmidcite and write simple text file of PMIDs""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from os.path import exists from os.path import split @@ -143,4 +143,4 @@ def prt_loc_rcfile(cfg, prt=stdout): -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/eutils/cmds/efetch.py b/src/pmidcite/eutils/cmds/efetch.py index cc833ad..0ae174c 100644 --- a/src/pmidcite/eutils/cmds/efetch.py +++ b/src/pmidcite/eutils/cmds/efetch.py @@ -1,9 +1,9 @@ """Fetch items and write""" # https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.EFetch -__author__ = 'DV Klopfenstein, PhD, PhD' -__copyright__ = "Copyright (C) 2016-present DV Klopfenstein, PhD, PhD. All rights reserved." -__license__ = "GPL" +__author__ = 'DV Klopfenstein, PhD.' +__copyright__ = "Copyright (C) 2016-present DV Klopfenstein, PhD. All rights reserved." +__license__ = "GNU AGPLv3" import sys import re @@ -73,4 +73,4 @@ def efetch_txt(self, start, retmax, database, webenv, querykey): sys.stdout.write(" querykey: {}\n".format(querykey)) -# Copyright (C) 2016-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2016-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/eutils/cmds/query_ids.py b/src/pmidcite/eutils/cmds/query_ids.py index f67fa1a..ef3b64b 100644 --- a/src/pmidcite/eutils/cmds/query_ids.py +++ b/src/pmidcite/eutils/cmds/query_ids.py @@ -1,8 +1,8 @@ """Text query finds database UIDs for later use in ESummary, EFetch or ELink""" # https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.ESearch -__copyright__ = "Copyright (C) 2020-present DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = 'DV Klopfenstein, PhD, PhD' +__copyright__ = "Copyright (C) 2020-present DV Klopfenstein, PhD. All rights reserved." +__author__ = 'DV Klopfenstein, PhD.' import sys from pmidcite.eutils.cmds.base import EntrezUtilities @@ -122,4 +122,4 @@ def query(self, database, query, **esearch): return None -# Copyright (C) 2020-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2020-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/eutils/pubmed/rdwr.py b/src/pmidcite/eutils/pubmed/rdwr.py index 768c19e..076987c 100755 --- a/src/pmidcite/eutils/pubmed/rdwr.py +++ b/src/pmidcite/eutils/pubmed/rdwr.py @@ -1,7 +1,7 @@ """Write Python module for downloaded abstracts.""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" import sys import os @@ -454,4 +454,4 @@ def _extract_fldvals(self, line): self.fldvals[-1][1].append(line_body) - # Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved. + # Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/icite/dnldr/pmid_dnlder.py b/src/pmidcite/icite/dnldr/pmid_dnlder.py index a285e50..ccd05b5 100644 --- a/src/pmidcite/icite/dnldr/pmid_dnlder.py +++ b/src/pmidcite/icite/dnldr/pmid_dnlder.py @@ -1,8 +1,8 @@ """Given a PubMed ID (PMID), download a list of publications which cite and reference it""" # https://icite.od.nih.gov/api -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from os.path import exists from os.path import join @@ -100,4 +100,4 @@ def _load_icites(self, pmids, pmid2py): return nihentries_loaded -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/icite/dnldr/pmid_dnlder_base.py b/src/pmidcite/icite/dnldr/pmid_dnlder_base.py index 670b540..e03d6af 100644 --- a/src/pmidcite/icite/dnldr/pmid_dnlder_base.py +++ b/src/pmidcite/icite/dnldr/pmid_dnlder_base.py @@ -28,41 +28,24 @@ def __init__(self, details_cites_refs=None, nih_grouper=None): def get_icites(self, pmids): """Citation data should be downloaded or loaded by derived classes""" - # pylint: disable=unreachable,no-self-use,useless-return raise RuntimeError("**FATAL NIHiCiteDownloaderBase:get_icites(pmids)") - return [] + ## return [] def get_icite(self, pmid): """Citation data should be downloaded or loaded by derived classes""" - # pylint: disable=unreachable,no-self-use raise RuntimeError("**FATAL NIHiCiteDownloaderBase:get_icite(pmid)") - return False - - def wr_papers(self, fout_txt, pmid2icitepaper, force_overwrite=False, mode='w'): - """Run iCite for user-provided PMIDs and write to a file""" - if not pmid2icitepaper: - return - pmids_all = pmid2icitepaper.keys() - pmids_new = pmids_all - if mode == 'a': - pmids_new = self._get_new_pmids(fout_txt, pmids_all) - if pmids_new: - if self._do_write(fout_txt, force_overwrite): - ## print('STARTING ', mode) - with open(fout_txt, mode) as prt: - self.prt_papers(pmid2icitepaper, prt) - print('{WR}: {TXT}'.format( - WR=self._msg_wrote(mode, pmids_all, pmids_new), TXT=fout_txt)) + ## return False def prt_api_msgs(self): """Print error messages captured by API, if there are any""" if self.api.msgs: + # pylint: disable=consider-using-f-string print('\n{MSG}'.format(MSG='\n'.join(self.api.msgs))) @staticmethod def prt_top(paper, prt=stdout): """Print one detailed line summarizing the paper""" - prt.write('TOP {iCite}\n'.format(iCite=paper.str_line())) + prt.write(f'TOP {paper.str_line()}\n') def prt_papers(self, pmid2icitepaper, prt=stdout): """Print papers, including citation counts, cite_by and references list""" @@ -70,7 +53,7 @@ def prt_papers(self, pmid2icitepaper, prt=stdout): if paper is not None: self.prt_paper(paper, pmid, pmid, prt) else: - print('**WARNING: NO iCite ENTRY FOUND FOR: {PMID}'.format(PMID=pmid)) + print(f'**WARNING: NO iCite ENTRY FOUND FOR: {pmid}') def prt_paper(self, paper, pmid, name, prt=stdout): """Print one paper, including citation counts, cite_by and references list""" @@ -81,24 +64,18 @@ def prt_paper(self, paper, pmid, name, prt=stdout): else: self.prt_top(paper, prt) else: - prt.write('No iCite results found: {PMID} {NAME}\n\n'.format( - PMID=pmid, NAME=name if name is not None else '')) + prt.write(f'No iCite results found: {pmid} {name if name is not None else ""}\n\n') @staticmethod def _msg_wrote(mode, pmids_req, pmids_new): """Get the 'WROTE' or 'APPENDED' message""" if mode == 'w': - return '{N:6,} WROTE'.format(N=len(pmids_req)) + return f'{len(pmids_req):6,} WROTE' if mode == 'a': - if pmids_new: - return '{N:,} of {M:,} APPENDED'.format( - N=len(pmids_new), - M=len(pmids_req)) - return '{N:,} of {M:,} FOUND'.format( - N=len(pmids_new), - M=len(pmids_req)) + n_of_m = f'{len(pmids_new):,} of {len(pmids_req):,}' + return f'{n_of_m} APPENDED' if pmids_new else f'{n_of_m} FOUND' # return '{N:,} FOUND'.format(M=len(pmids_req)) - raise RuntimeError('UNRECOGNIZED WRITE MODE({M})'.format(M=mode)) + raise RuntimeError(f'UNRECOGNIZED WRITE MODE({mode})') @staticmethod def _get_new_pmids(pmidcite_txt, pmids): @@ -112,10 +89,10 @@ def wr_name2pmid(self, fout_txt, name2pmid): """Run iCite for user-provided PMIDs and write to a file""" name2ntpaper = self._run_icite_name2pmid(name2pmid, pmid2note=None) if name2ntpaper: - with open(fout_txt, 'w') as prt: + with open(fout_txt, 'w', encoding='utf-8') as prt: for name, ntpaper in name2ntpaper.items(): self.prt_paper(ntpaper.paper, ntpaper.pmid, name, prt) - print(' WROTE: {TXT}'.format(TXT=fout_txt)) + print(f' WROTE: {fout_txt}') def _run_icite_name2pmid(self, name2pmid, pmid2note): """Get a NIHiCitePaper object for each user-specified PMID""" @@ -194,13 +171,10 @@ def _geticitepaper(self, pmid_top, header, pmid2note): for nihentry in self.get_icites(assoc_pmids): pmid2icite[nihentry.pmid] = nihentry return NIHiCitePaper(pmid_top, pmid2icite, header, pmid2note) - note = '' - if pmid2note and pmid_top in pmid2note: - note = pmid2note[pmid_top] - print('No NIH iCite results found: {PMID} {HDR} {NOTE}'.format( - PMID=pmid_top, - HDR=header if header else '', - NOTE=note)) + ## note = '' + ## if pmid2note and pmid_top in pmid2note: + ## note = pmid2note[pmid_top] + print('No NIH iCite results found: {pmid_top} {header if header else ""} {note}') return None ## TBD: NIHiCitePaper(pmid_top, self.dir_dnld, header, note) @staticmethod @@ -208,7 +182,7 @@ def _do_write(fout_txt, force_overwrite): """Ask for a yes-no answer from the user on STDIN""" if not exists(fout_txt) or force_overwrite: return True - prompt_user = '\nover-write {TXT} (yes/no)? '.format(TXT=fout_txt) + prompt_user = f'\nover-write {fout_txt} (yes/no)? ' return input(prompt_user).lower()[:1] == 'y' @staticmethod @@ -229,5 +203,23 @@ def _init_details_cites_refs(details_cites_refs): raise RuntimeError(msg.format(V=details_cites_refs)) return set(details_cites_refs).intersection(NIHiCiteEntry.associated_pmid_keys) + # pylint: disable=too-many-arguments + def wr_papers(self, fout_txt, pmid2icitepaper, force_overwrite=False, mode='w', query=None): + """Run iCite for user-provided PMIDs and write to a file""" + if not pmid2icitepaper: + return + pmids_all = pmid2icitepaper.keys() + pmids_new = pmids_all + if mode == 'a': + pmids_new = self._get_new_pmids(fout_txt, pmids_all) + if pmids_new: + if self._do_write(fout_txt, force_overwrite): + ## print('STARTING ', mode) + with open(fout_txt, mode, encoding='utf-8') as prt: + if query is not None: + prt.write(f'QUERY: {query}\n') + self.prt_papers(pmid2icitepaper, prt) + print(f'{self._msg_wrote(mode, pmids_all, pmids_new)}: {fout_txt}') + # Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/icite/dnldr/pmid_dnlder_only.py b/src/pmidcite/icite/dnldr/pmid_dnlder_only.py index c72da62..1d5aa31 100644 --- a/src/pmidcite/icite/dnldr/pmid_dnlder_only.py +++ b/src/pmidcite/icite/dnldr/pmid_dnlder_only.py @@ -1,8 +1,8 @@ """Given a PubMed ID (PMID), download a list of publications which cite and reference it""" # https://icite.od.nih.gov/api -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from pmidcite.icite.dnldr.pmid_dnlder_base import NIHiCiteDownloaderBase from pmidcite.icite.entry import NIHiCiteEntry @@ -38,4 +38,4 @@ def get_icite(self, pmid): return None -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/icite/dnldr/pmid_loader.py b/src/pmidcite/icite/dnldr/pmid_loader.py index c521a18..468304b 100644 --- a/src/pmidcite/icite/dnldr/pmid_loader.py +++ b/src/pmidcite/icite/dnldr/pmid_loader.py @@ -1,7 +1,7 @@ """Given a PubMed ID (PMID), return a list of publications which cite it""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from sys import stdout from os.path import join @@ -85,4 +85,4 @@ def _get_pmids_linked(self, icites_top): ## return pmids_linked -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/icite/entry.py b/src/pmidcite/icite/entry.py index daa7fa9..f9478dc 100644 --- a/src/pmidcite/icite/entry.py +++ b/src/pmidcite/icite/entry.py @@ -1,8 +1,8 @@ """Holds NIH iCite data for one PubMed ID (PMID)""" # https://icite.od.nih.gov/api -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from sys import stdout @@ -228,4 +228,4 @@ def __lt__(self, rhs): return self.pmid < rhs.pmid -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/icite/nih_grouper.py b/src/pmidcite/icite/nih_grouper.py index f12236a..a4e497e 100644 --- a/src/pmidcite/icite/nih_grouper.py +++ b/src/pmidcite/icite/nih_grouper.py @@ -1,7 +1,7 @@ """Groups papers using the NIH percentile""" -__copyright__ = "Copyright (C) 2021-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2021-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from collections import namedtuple @@ -95,4 +95,4 @@ def __str__(self): self.min1, self.min2, self.min3, self.min4) -# Copyright (C) 2021-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2021-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/icite/top_cit_ref.py b/src/pmidcite/icite/top_cit_ref.py index 0c9b3a7..a2d8749 100644 --- a/src/pmidcite/icite/top_cit_ref.py +++ b/src/pmidcite/icite/top_cit_ref.py @@ -1,7 +1,7 @@ """Manage paper labels: TOP CIT CLI REF""" -__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" class TopCitRef: @@ -44,4 +44,4 @@ def adjust_args(self, args_paper_labels): return ret -# Copyright (C) 2022-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2022-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/pubmedqueryicite.py b/src/pmidcite/pubmedqueryicite.py index 7a8fa25..87aecf5 100644 --- a/src/pmidcite/pubmedqueryicite.py +++ b/src/pmidcite/pubmedqueryicite.py @@ -1,7 +1,7 @@ """Run PubMed user query and download PMIDs. Run iCite on PMIDs. Write text file.""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" import sys from collections import namedtuple @@ -85,10 +85,10 @@ def querypubmed_runicite(self, filename, query, details_cites_refs=None): # 3) Run NIH's iCite on the PMIDs and write the results into a file if pmids: # return pmid2paper - return self._wr_icite(fout_icite, pmids, details_cites_refs) + return self._wr_icite_query(fout_icite, pmids, query, details_cites_refs) return {} - def _wr_icite(self, fout_icite, pmids, details_cites_refs): + def _wr_icite_query(self, fout_icite, pmids, query, details_cites_refs): """Run PMIDs in iCite and print results into a file""" cfg = self.cfg dnldr = get_downloader( @@ -100,7 +100,7 @@ def _wr_icite(self, fout_icite, pmids, details_cites_refs): ## print('PMIDCITE PPPPPPPPPPPPPPPPP dnldr.get_pmid2paper {N} PMIDs'.format(N=len(pmids))) pmid2paper = dnldr.get_pmid2paper(pmids, self.pmid2note) ## print('PMIDCITE PPPPPPPPPPPPPPPPP dnldr.wr_papers{N} PMIDs'.format(N=len(pmids))) - dnldr.wr_papers(fout_icite, pmid2icitepaper=pmid2paper, force_overwrite=True) + dnldr.wr_papers(fout_icite, pmid2icitepaper=pmid2paper, force_overwrite=True, query=query) return pmid2paper def get_nts_g_list(self, lst): @@ -121,8 +121,10 @@ def get_index(argv, queries=None): # If no argument was provided, run the last query in the list if len(argv) == 1: return [-1] - if argv[1] in {'all', '--all'} and queries is not None: - return list(range(len(queries))) + if argv[1] in {'all', '--all'}: + if queries is not None: + return list(range(len(queries))) + raise DeprecationWarning('FUNCTION get_index PARAMATER queries IS None') if 'h' in argv[1] and queries: for idx, item in enumerate(queries): print(f'{idx:3} {item}') @@ -130,4 +132,4 @@ def get_index(argv, queries=None): return [int(n) for n in argv[1:] if n.lstrip('-').isdigit()] -# Copyright (C) 2019-present DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/scripts/icite.py b/src/pmidcite/scripts/icite.py index 6141e9a..a4239ea 100755 --- a/src/pmidcite/scripts/icite.py +++ b/src/pmidcite/scripts/icite.py @@ -1,7 +1,7 @@ """Given a PubMed ID (PMID), return a list of citing publications""" -__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from pmidcite.cli.icite import NIHiCiteCli # get_argparser from pmidcite.cfg import get_cfgparser @@ -12,4 +12,4 @@ def main(): NIHiCiteCli(get_cfgparser(prt=None)).cli() -# Copyright (C) 2019-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2019-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/scripts/summarize_papers.py b/src/pmidcite/scripts/summarize_papers.py index 6c87c8a..c3e677e 100755 --- a/src/pmidcite/scripts/summarize_papers.py +++ b/src/pmidcite/scripts/summarize_papers.py @@ -1,7 +1,7 @@ """Summarize NIH citation data for requested papers from the commandline or in files""" -__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" from pmidcite.cli.summarize_papers import SummarizePapersCli # get_argparser from pmidcite.cfg import get_cfgparser @@ -12,4 +12,4 @@ def main(): SummarizePapersCli(get_cfgparser(prt=None)).cli() -# Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/pmidcite/summarize_papers.py b/src/pmidcite/summarize_papers.py index 4cc933e..2a1ec92 100644 --- a/src/pmidcite/summarize_papers.py +++ b/src/pmidcite/summarize_papers.py @@ -3,8 +3,8 @@ from collections import namedtuple from collections import defaultdict -__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" class SummarizePapers: @@ -100,4 +100,4 @@ def from_file(cls, filename, nih_grouper=None, top_cit_ref=None): return obj -# Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/tests/args_dflt.py b/src/tests/args_dflt.py index 10cef8f..1b7c00e 100644 --- a/src/tests/args_dflt.py +++ b/src/tests/args_dflt.py @@ -3,4 +3,4 @@ from argparse import Namespace # pylint: disable=line-too-long -ARGS = Namespace(O=False, append_outfile=None, dir_icite='./log/icite', dir_icite_py='None', dir_pubmed_txt='None', force_download=False, force_write=False, generate_rcfile=False, print_rcfile=False, help=False, infile=None, load_citations=False, load_references=False, md=False, min1=2.1, min2=15.7, min3=70.0, min4=97.5, no_references=False, outfile=None, pmids=[1], print_header=False, print_keys=False, pubmed=False, verbose=False) +ARGS = Namespace(O=False, cite=False, append_outfile=None, dir_icite='./log/icite', dir_icite_py='None', dir_pubmed_txt='None', force_download=False, force_write=False, generate_rcfile=False, print_rcfile=False, help=False, infile=None, load_citations=False, load_references=False, md=False, min1=2.1, min2=15.7, min3=70.0, min4=97.5, no_references=False, outfile=None, pmids=[1], print_header=False, print_keys=False, pubmed=False, verbose=False) diff --git a/src/tests/test_database_list.py b/src/tests/test_database_list.py index 4de4e7e..240cf69 100755 --- a/src/tests/test_database_list.py +++ b/src/tests/test_database_list.py @@ -24,6 +24,7 @@ def test_database_list(einfo_each_db=False): def _prt_einfo_db(dbs): """Print the list of databases""" + assert dbs is not None, 'ERROR getting database list from NCBI E-Utils' for idx, database in enumerate(dbs): print(' {I}) {DB}'.format(I=idx, DB=database)) diff --git a/src/tests/test_dnld_pmids.py b/src/tests/test_dnld_pmids.py index 6c90b22..6185512 100755 --- a/src/tests/test_dnld_pmids.py +++ b/src/tests/test_dnld_pmids.py @@ -42,7 +42,7 @@ def main(): obj = PubMedQueryToICite(force_dnld=True, prt_icitepy=None) obj.cfg.set_dir_pmids(DIR_REPO) obj.cfg.set_dir_icite(DIR_REPO) - dnld_idx = obj.get_index(sys.argv) + dnld_idx = obj.get_index(sys.argv, queries) obj.run(queries, dnld_idx) assert exists(filename) print('**PASSED: DIR=repo\n') diff --git a/src/tests/test_speed_api_dnld.py b/src/tests/test_speed_api_dnld.py index e73f613..9afa1a3 100755 --- a/src/tests/test_speed_api_dnld.py +++ b/src/tests/test_speed_api_dnld.py @@ -62,4 +62,4 @@ def _init_dnldr(force_dnld): if __name__ == '__main__': test_speed_api_dnld() -# Copyright (C) 2021-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2021-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/tests/test_speed_dnld_load.py b/src/tests/test_speed_dnld_load.py index 71a06c9..9058a4e 100755 --- a/src/tests/test_speed_dnld_load.py +++ b/src/tests/test_speed_dnld_load.py @@ -84,4 +84,4 @@ def _run_download(dnldr, pmids): if __name__ == '__main__': test_speed_dnld_load() -# Copyright (C) 2021-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2021-present, DV Klopfenstein, PhD. All rights reserved. diff --git a/src/tests/test_topcitref_args.py b/src/tests/test_topcitref_args.py index bd7a16d..da26087 100755 --- a/src/tests/test_topcitref_args.py +++ b/src/tests/test_topcitref_args.py @@ -3,8 +3,8 @@ from pmidcite.icite.top_cit_ref import TopCitRef -__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved." -__author__ = "DV Klopfenstein, PhD, PhD" +__copyright__ = "Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved." +__author__ = "DV Klopfenstein, PhD" ADJ = TopCitRef().adjust_args @@ -33,4 +33,4 @@ def _chk(num, args, exp): if __name__ == '__main__': test_topcitref_args() -# Copyright (C) 2022-present, DV Klopfenstein, PhD, PhD. All rights reserved. +# Copyright (C) 2022-present, DV Klopfenstein, PhD. All rights reserved.