| 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 PubMed DocumentSummary XML to Pubmed-entry text ASN.1 |
| 7 |
|
| 8 |
# efetch -db pubmed -id 2539356,1937004 -format docsum | ds2pme |
| 9 |
|
| 10 |
# can produce XML intermediate for archiving |
| 11 |
xml=false |
| 12 |
|
| 13 |
# check for XML output flags |
| 14 |
while [ $# -gt 0 ] |
| 15 |
do |
| 16 |
case "$1" in |
| 17 |
xml | -xml ) |
| 18 |
# do not convert to ASN.1 |
| 19 |
shift |
| 20 |
xml=true |
| 21 |
;; |
| 22 |
asn | -asn ) |
| 23 |
# convert to ASN.1 (default) |
| 24 |
shift |
| 25 |
xml=false |
| 26 |
;; |
| 27 |
* ) |
| 28 |
exec >&2 |
| 29 |
echo "$0: Unrecognized argument $1" |
| 30 |
exit 1 |
| 31 |
;; |
| 32 |
esac |
| 33 |
done |
| 34 |
|
| 35 |
# conversion function |
| 36 |
ConvertXMLtoASN() { |
| 37 |
|
| 38 |
transmute -mixed -normalize pubmed | |
| 39 |
xtract -strict -rec PM -pattern DocumentSummary -PS "()" \ |
| 40 |
-wrp PMID -element DocumentSummary/Id \ |
| 41 |
-group DocumentSummary/PubStatus -PS PubStatus \ |
| 42 |
-group DocumentSummary/History/PubMedPubDate \ |
| 43 |
-if PubStatus -equals entrez -pkg EMDATE/em_std \ |
| 44 |
-wrp year_ -element Date[1:4] \ |
| 45 |
-wrp month_ -trim Date[6:7] \ |
| 46 |
-wrp day_ -trim Date[9:10] \ |
| 47 |
-group DocumentSummary/Title -pkg TITL \ |
| 48 |
-wrp name -prose Title \ |
| 49 |
-group Authors -pkg AUTH/authors/names_std \ |
| 50 |
-branch Author \ |
| 51 |
-block Author -pkg "_" \ |
| 52 |
-subset Author \ |
| 53 |
-wrp name_ml -author Name \ |
| 54 |
-subset Affiliation \ |
| 55 |
-wrp affil_str -prose Affiliation \ |
| 56 |
-group DocumentSummary -pkg JOUR \ |
| 57 |
-block DocumentSummary -pkg JTAS/title \ |
| 58 |
-wrp iso-jta -element Source \ |
| 59 |
-wrp ml-jta -element Source \ |
| 60 |
-wrp issn -first ISSN,ESSN \ |
| 61 |
-wrp name -element FullJournalName \ |
| 62 |
-branch DocumentSummary -pkg IMP/imp \ |
| 63 |
-block PubDate -pkg date_std \ |
| 64 |
-wrp year_ -year PubDate \ |
| 65 |
-wrp month_ -month PubDate \ |
| 66 |
-block DocumentSummary \ |
| 67 |
-wrp volume -element Volume \ |
| 68 |
-wrp issue -element Issue \ |
| 69 |
-wrp pages -element Pages \ |
| 70 |
-wrp language -element Lang \ |
| 71 |
-wrp pubstatus_ -element "&PS" \ |
| 72 |
-group ArticleIds -pkg IDS/ids \ |
| 73 |
-block ArticleId -if IdType -equals pubmed \ |
| 74 |
-wrp pubmed_ -element Value \ |
| 75 |
-block ArticleId -if IdType -equals pmc \ |
| 76 |
-pfx "<other><db>pmc</db><tag_str>" \ |
| 77 |
-sfx "</tag_str></other>" -element Value \ |
| 78 |
-block ArticleId -if IdType -equals doi \ |
| 79 |
-wrp doi -element Value | |
| 80 |
xtract -rec Pubmed-entry -pattern PM \ |
| 81 |
-PS PS/pubstatus_ \ |
| 82 |
-wrp pmid_ -element PMID \ |
| 83 |
-division PM -pkg medent \ |
| 84 |
-group EMDATE/em_std -element "*" \ |
| 85 |
-group PM -pkg cit \ |
| 86 |
-branch TITL/name -pkg title -element "*" \ |
| 87 |
-branch AUTH/authors -element "*" \ |
| 88 |
-branch JOUR -pkg from_journal \ |
| 89 |
-block JTAS/title -element "*" \ |
| 90 |
-block IMP/imp -element "*" \ |
| 91 |
-branch IDS/ids -element "*" \ |
| 92 |
-group ABST/abstract -element "*" |
| 93 |
} |
| 94 |
|
| 95 |
if [ "$xml" = true ] |
| 96 |
then |
| 97 |
ConvertXMLtoASN |
| 98 |
else |
| 99 |
ConvertXMLtoASN | xtract -pattern Pubmed-entry -element "." |
| 100 |
fi |