Skip to content

Commit

Permalink
Merge pull request #59 from dvklopfenstein/dvk
Browse files Browse the repository at this point in the history
Pytest; get_indexs fnc; summarize_papers; Copyright cleanup; Add QUERY to summary prints
  • Loading branch information
dvklopfenstein authored Oct 25, 2023
2 parents f51f697 + a4ce20f commit 8465321
Show file tree
Hide file tree
Showing 37 changed files with 204 additions and 160 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ jobs:

- name: Test with pytest
run: |
pip install pytest pytest-cov
pip install pytest coverage
make pytest
10 changes: 9 additions & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -11,6 +11,7 @@ title: "pmidcite"
version: 0.0.18
doi: 10.5281/zenodo.5172712
keywords:
- "Google Scholar"
- CitedBy
- PubMed
- PMID
Expand All @@ -19,6 +20,7 @@ keywords:
- "forward snowball"
- "backward snowball"
- "literature review"
- "literature search"
- "citation downloader"
contact:
- email: dvklopfenstein@protonmail.com
Expand All @@ -36,22 +38,28 @@ 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
title: "Commentary to Gusenbauer and Haddaway 2020: Evaluating retrieval qualities of Google Scholar and PubMed"
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
Expand Down
4 changes: 2 additions & 2 deletions doc/example_cfg/.pmidciterc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion src/bin/dnld_pmids.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
6 changes: 3 additions & 3 deletions src/bin/icite.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
13 changes: 4 additions & 9 deletions src/bin/summarize_papers.py
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions src/pmidcite/__init__.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/pmidcite/__version__.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions src/pmidcite/cfg.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
41 changes: 41 additions & 0 deletions src/pmidcite/citation.py
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions src/pmidcite/cli/dnldpubmed.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
44 changes: 24 additions & 20 deletions src/pmidcite/cli/icite.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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)')
Expand Down Expand Up @@ -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',
Expand All @@ -120,21 +123,24 @@ 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):
"""Run iCite/PubMed using command-line interface"""
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Loading

0 comments on commit 8465321

Please sign in to comment.