#!/bin/tcsh -f #(ie run the tshell on this but don't read the .cshrc or .tcshrc) set ver = "version = 1.13 of bibtex2pmcid 2009 Dec 19" # 2009 Dec 19, 1.13: rename version line variable to be ver # 2008 Jul 25, 1.12: switch to Monica Romiti's method, no PMC add # 2008 Jul 24, 1.11: handle ERROR 503, don't delete pmcid # 2008 Jul 24, 1.10: handle ERROR 503 - email to pubmedcentral # 2008 Jul 24, 1.09: Add 'PMC' to the PMCID name, clean up, tighten # 2008 Jul 24, 1.08: improve documentation # 2008 Jun 29, 1.06: PMCID twice! # 2008 Jun 29, 1.05: blank separates pmid from pmcid # 2008 Jun 29, 1.04: no blank on end of pmid line # 2008 Jun 29, 1.03: handle empty pmid string # 2008 Mar 25, 1.02: official documentation and " on pmcid # 2008 Mar 25, 1.01: functional! # 2008 Mar 25, 1.00: origin # switch lines to turn on (1) or off (2) verbose mode: set verbosemode = 1 set verbosemode = 0 if ($#argv == 0) then echo "$ver" echo 'bibtex2pmcid [input bibtex file]' echo 'Incorporate PubMedCentral numbers into a BibTeX database file.' echo 'Read the input file and identify lines that contain a' echo 'PubMed ID line with this format:' echo '' echo 'pmid = "15130839",' echo '' echo 'Then the corresponding PubMedCentral number is identified' echo 'using pmid2pmcid and incorporated by adding another line:' echo '' echo 'pmid = "15130839"' echo 'pmcid = "1852464",' echo '' echo 'The rest of the file is just copied to the output while' echo 'pmid and pmcid lines that are empty (as "") are removed.' echo '' echo 'The results are given to standard output.' echo '' echo 'PMCID is required by NIH:' echo 'Policy No. 118 3/10/08 Public Access Policy' echo 'http://web.ncifcrf.gov/campus/administrative/policies/100admin/118.asp' echo '' echo 'The pmid2pmcid script is required by this program.' echo 'See also: pmid2pmcid, yvp.' echo '' echo '---' echo '' echo 'Dr. Thomas D. Schneider' echo 'National Institutes of Health' echo 'National Cancer Institute' echo 'Center for Cancer Research Nanobiology Program' echo 'Molecular Information Theory Group' echo 'Frederick, Maryland 21702-1201' echo 'toms@ncifcrf.gov' echo 'permanent email: toms@alum.mit.edu' echo 'http://www.ccrnp.ncifcrf.gov/~toms/' exit endif # if ($verbosemode) then # echo "===== input file: $1 =====" # cat $1 # echo "==========================" # endif set tmp = /tmp/`whoami`1.bibtex2pmcid cat $1 |\ sed 's/^/BEGINALINE/' |\ cat > $tmp set number = 0 set okpmc = 0 foreach line ("`cat $tmp`") @ number = "$number" + 1 if (`echo "$line" | grep 'pmid = "'` == '') then # process lines which are not pmid if (`echo "$line" | grep 'pmcid = "'` != '') then # drop ALL pmcid lines - will rebuild if possible below # UNLESS service unavailable. if ($okpmc == $number) then # keep this pmcid UNLESS it is empty if (`echo "$line" | grep 'pmcid = "",'` == '') then echo "$line" |sed 's/BEGINALINE//' endif endif else echo "$line" |sed 's/BEGINALINE//' endif else # process lines with pmid on them. if ($verbosemode) then # echo "$line" echo "===== $line" |sed 's/BEGINALINE//' endif if (`echo "$line" | grep 'pmcid'` == '') then set p1 = `echo "$line"| sed 's,BEGINALINE,,'` set PMID = `echo "$p1"| sed 's,pmid = ",,'|sed 's/",//'` if ("$PMID" != '') then # The PMID line will be removed if it is empty ... fine! # Report the PMID line: echo "${line}" |sed 's/BEGINALINE//' set PMCID = `pmid2pmcid $PMID` if (`echo "$PMCID" | grep ERROR` != '') then # error 503 is "normal", stop for other errors if (`echo "$PMCID" | grep "ERROR 503"` == '') then echo "$PMCID" echo "HALTING" exit endif # If there was an error, then the NEXT PMCID at line # $number+1 should be KEPT (unless it is empty). @ okpmc = $number + 1 else if ($verbosemode) then echo "===== for PMID: $PMID ====== at line $number" if ("$PMCID" == '') then echo "===== NO PMCID FOUND at line $number" else echo "===== got PMCID: $PMCID ====== at line $number" endif endif if ("$PMCID" == '') then # no output # set new = "" else # set new = 'pmcid = "PMC'$PMCID'",' set new = 'pmcid = "'$PMCID'",' echo "${new}" |sed 's/BEGINALINE//' endif endif endif else if ($verbosemode) then echo "===== The line already has a PMCID ===== at line $number" endif endif endif end exit ******************************************************************************** Example entries: @article{Schneider2002, author = "T. D. Schneider", title = "{Consensus sequence Zen}", journal = "Appl Bioinformatics", volume = "1", pages = "111--119", year = "2002"} @article{Schneider2002, author = "T. D. Schneider", title = "{Consensus sequence Zen}", journal = "Appl Bioinformatics", volume = "1", pages = "111--119", pmid = "15130839", year = "2002"} @article{Schneider2002, author = "T. D. Schneider", title = "{Consensus sequence Zen}", journal = "Appl Bioinformatics", volume = "1", pages = "111--119", pmid = "15130839", pmcid = 1852464, year = "2002"}