| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Public domain notice for all NCBI EDirect scripts is located at: |
| 4 |
# https://www.ncbi.nlm.nih.gov/books/NBK179288/#chapter6.Public_Domain_Notice |
| 5 |
|
| 6 |
# Converts PubmedArticle XML to APA format citation |
| 7 |
|
| 8 |
# efetch -db pubmed -id 19212835 -format xml | pma2apa |
| 9 |
|
| 10 |
# Last, K. S., Bailhache, T., Kramer, C., Kyriacou, C. P., Rosato, E., & Olive, P. J. (2009). |
| 11 |
# Tidal, daily, and lunar-day activity cycles in the marine polychaete Nereis virens. |
| 12 |
# Chronobiology international, 26(2), 167-183. doi:10.1080/07420520902774524 |
| 13 |
|
| 14 |
xml=false |
| 15 |
asc=false |
| 16 |
|
| 17 |
# check for XML and ASCII output flags |
| 18 |
while [ $# -gt 0 ] |
| 19 |
do |
| 20 |
case "$1" in |
| 21 |
xml | -xml ) |
| 22 |
shift |
| 23 |
xml=true |
| 24 |
;; |
| 25 |
apa | -apa ) |
| 26 |
shift |
| 27 |
xml=false |
| 28 |
;; |
| 29 |
ascii | -ascii ) |
| 30 |
shift |
| 31 |
asc=true |
| 32 |
;; |
| 33 |
* ) |
| 34 |
exec >&2 |
| 35 |
echo "$0: Unrecognized argument $1" |
| 36 |
exit 1 |
| 37 |
;; |
| 38 |
esac |
| 39 |
done |
| 40 |
|
| 41 |
# conversion function |
| 42 |
ConvertXMLtoAPA() { |
| 43 |
|
| 44 |
transmute -mixed -normalize pubmed | |
| 45 |
xtract -set Set -rec Rec -pattern PubmedArticle \ |
| 46 |
-wrp PMID -element MedlineCitation/PMID \ |
| 47 |
-wrp Year -year "PubDate/*" \ |
| 48 |
-wrp Title -element ArticleTitle \ |
| 49 |
-wrp Count -num Author \ |
| 50 |
-group PubmedArticle \ |
| 51 |
-block PubmedData/ArticleIdList/ArticleId -if "@IdType" -equals doi \ |
| 52 |
-wrp DOI -element ArticleId \ |
| 53 |
-group PubmedArticle -pkg RF \ |
| 54 |
-wrp Journal -jour Journal/Title \ |
| 55 |
-wrp Volume -element JournalIssue/Volume \ |
| 56 |
-wrp Issue -element JournalIssue/Issue \ |
| 57 |
-block PubmedArticle -if StartPage -and EndPage \ |
| 58 |
-wrp Pages -sep "-" -element StartPage,EndPage \ |
| 59 |
-else -wrp Pages -element Pagination/MedlinePgn \ |
| 60 |
-group Author -NUM "+" -pkg Auth \ |
| 61 |
-wrp Num -element "&NUM" \ |
| 62 |
-wrp Last -element LastName \ |
| 63 |
-wrp Inits -letters Initials | |
| 64 |
xtract -set Set -rec Rec -pattern Rec \ |
| 65 |
-pfx "(" -sfx ")." -YEAR Year -rst \ |
| 66 |
-pfx "doi:" -DOI DOI -rst \ |
| 67 |
-wrp Count -element Count \ |
| 68 |
-wrp PMID -element PMID \ |
| 69 |
-wrp Year -element "&YEAR" \ |
| 70 |
-wrp Title -element Title \ |
| 71 |
-wrp DOI -element "&DOI" \ |
| 72 |
-group RF -pkg Citation \ |
| 73 |
-sep "" -tab "" -element Journal \ |
| 74 |
-pfx ", " -element Volume \ |
| 75 |
-pfx "(" -sfx ")" -element Issue \ |
| 76 |
-pfx ", " -sfx "" -element Pages -rst -lbl "." \ |
| 77 |
-group Auth -INITS "()" -pkg Auth \ |
| 78 |
-rst -sep ". " -tab "" -sfx "." -INITS Inits \ |
| 79 |
-rst -wrp Num -element Num \ |
| 80 |
-wrp Last -element Last \ |
| 81 |
-wrp Inits -element "&INITS" | |
| 82 |
xtract -set APASet -rec APAFormat -pattern Rec -COUNT Count \ |
| 83 |
-wrp PMID -element PMID \ |
| 84 |
-division Rec -pkg Authors \ |
| 85 |
-group Auth -NUM "+" -block Auth \ |
| 86 |
-block Auth -if Num -eq 1 \ |
| 87 |
-rst -sep ", " -tab "" -element Last,Inits \ |
| 88 |
-block Auth -if Num -gt 1 -and "&NUM" -lt "&COUNT" \ |
| 89 |
-rst -pfx ", " -sep ", " -tab "" -element Last,Inits \ |
| 90 |
-block Auth -if "&COUNT" -gt 1 -and Num -eq "&COUNT" \ |
| 91 |
-rst -pfx ", & " -sep ", " -tab "" -element Last,Inits \ |
| 92 |
-division Rec \ |
| 93 |
-wrp Year -element Year \ |
| 94 |
-wrp Title -element Title \ |
| 95 |
-wrp Citation -element Citation \ |
| 96 |
-wrp DOI -element DOI |
| 97 |
} |
| 98 |
|
| 99 |
if [ "$xml" = true ] && [ "$asc" = true ] |
| 100 |
then |
| 101 |
ConvertXMLtoAPA | |
| 102 |
transmute -accent -strict -format |
| 103 |
elif [ "$xml" = true ] |
| 104 |
then |
| 105 |
ConvertXMLtoAPA | |
| 106 |
transmute -strict -format |
| 107 |
elif [ "$asc" = true ] |
| 108 |
then |
| 109 |
ConvertXMLtoAPA | |
| 110 |
transmute -accent -strict -format | |
| 111 |
xtract -pattern APAFormat \ |
| 112 |
-element PMID -tab " " -sep " " \ |
| 113 |
-element Authors Year Title Citation DOI |
| 114 |
else |
| 115 |
ConvertXMLtoAPA | |
| 116 |
transmute -strict -format | |
| 117 |
xtract -pattern APAFormat \ |
| 118 |
-element PMID -tab " " -sep " " \ |
| 119 |
-element Authors Year Title Citation DOI |
| 120 |
fi |