-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextract_accession_numbers
202 lines (158 loc) · 5.59 KB
/
extract_accession_numbers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
# Extract accession numbers from database search results
# Author: Helge Knüttel
# Date: 2020-2022
# Some sensible settings. Taken from https://kvz.io/bash-best-practices.html
set -o errexit # exit when a command fails
set -o pipefail # catch failing commands in a pipe
set -o nounset # exit when script tries to use undeclared variables
# set -o xtrace # Trace what gets executed. Useful for debugging.
# Help text
PrintHelp() {
cat << "EOF"
Extract accession numbers from database search results.
Input is read from STDIN. Output is written to STDOUT.
Options
--format Export format. Mandatory option.
Export formats
Known export formats are:
pubmed Export from PubMed as format 'PubMed' (formerly 'MEDLINE')
ovid_medline Export from Ovid MEDLINE as:
- Format: Citavi, Endnote or ReferenceManager
- Fields: Complete Reference
ovid_embase Export from Ovid Embase as:
- Format: Citavi, Endnote or ReferenceManager
- Fields: Complete Reference
ovid_ris Export from Ovid Embase or Ovid MEDLINE as:
- Format: RIS
- Fields: Complete Reference
cochrane_reviews_endnote_ris
Export from Cochrane Library (Reviews) as format 'RIS (EndNote)'
cochrane_reviews_refman_ris
Export from Cochrane Library (Reviews) as format 'RIS (Reference Manager)'
cochrane_reviews_plain_text
Export from Cochrane Library (Reviews) as format 'Plain text'
cochrane_protocols_endnote_ris
Export from Cochrane Library (Protocols) as format 'RIS (EndNote)'
cochrane_protocols_refman_ris
Export from Cochrane Library (Protocols) as format 'RIS (Reference Manager)'
cochrane_protocols_plain_text
Export from Cochrane Library (Protocols) as format 'Plain text'
cochrane_trials_endnote_ris
Export from Cochrane Library (Trials) as format 'RIS (EndNote)'
cochrane_trials_refman_ris
Export from Cochrane Library (Trials) as format 'RIS (Reference Manager)'
cochrane_trials_plain_text
Export from Cochrane Library (Trials) as format 'Plain text'
cochrane_clinical_answers_endnote_ris
Export from Cochrane Library (Clinical Answers) as format 'RIS (EndNote)'
wos_endnote Export from Web of Science Core Collection as:
Endnote Desktop --> Record content: Full Record (.ciw-file)
wos_other Export from Web of Science Core Collection as:
Other file format --> Record content: Full Record;
File Format: Other reference software (.txt-file)
ebscohost_psycinfo_ris
Export from EBSCOhost PsycInfo as format 'RIS (e.g. CITAVI, EasyBib, EndNote, ProCite, Reference Manager, Zotero)'
ebscohost_cinahl_ris
Export from EBSCOhost CINAHL as format 'RIS (e.g. CITAVI, EasyBib, EndNote, ProCite, Reference Manager, Zotero)'
ictrp
Export from WHO ICTRP as format 'XML'
clinicaltrials_gov_txt
Export from ClinicalTrials.gov as format 'txt'
clinicaltrials_gov_tsv
Export from ClinicalTrials.gov as format 'TSV'
clinicaltrials_gov_xml
Export from ClinicalTrials.gov as format 'XML'
Examples
cat ovid_embase_export.cgi | extract_accession_numbers --format ovid_embase | wc -l
EOF
}
# Read command line arguments
if [ $# -eq 0 ]
then
echo "ERROR: Mandatory argument(s) missing. Try '${0} --help'" >&2
exit 1
fi
while [ $# -gt 0 ]
do
case "$1" in
--format )
shift
if [ $# -gt 0 ]
then
export_format="$1"
shift
else
echo "ERROR: Missing --format argument" >&2
exit 1
fi
;;
-h|--help )
PrintHelp
exit 0
;;
* )
# unknown argument
unknown_arg=$1
echo "ERROR: Unknown argument ${unknown_arg}" >&2
exit 1
;;
esac
done
case "$export_format" in
pubmed )
grep "^PMID- " - | sed -e 's/^PMID- //'
;;
ovid_medline|ovid_embase )
grep "^UI - " - | sed -e 's/^UI - //' -e 's/\r//g'
;;
ovid_ris )
grep "^ID - " - | sed -e 's/^ID - //' -e 's/\r//g'
;;
cochrane_reviews_endnote_ris|cochrane_reviews_refman_ris )
grep "^AN - " - | sed -e 's/^AN - //' -e 's/\r//g'
;;
cochrane_reviews_plain_text )
grep "^ID: " - | sed -e 's/^ID: //' -e 's/\r//g'
;;
cochrane_protocols_endnote_ris|cochrane_protocols_refman_ris )
grep "^AN - " - | sed -e 's/^AN - //' -e 's/\r//g'
;;
cochrane_protocols_plain_text )
grep "^ID: " - | sed -e 's/^ID: //' -e 's/\r//g'
;;
cochrane_trials_endnote_ris|cochrane_trials_refman_ris )
grep "^AN - " - | sed -e 's/^AN - //' -e 's/\r//g'
;;
cochrane_trials_plain_text )
grep "^ID: " - | sed -e 's/^ID: //' -e 's/\r//g'
;;
cochrane_clinical_answers_endnote_ris )
grep "^DO - " - | sed -e 's/^DO - //' -e 's/\r$//g'
;;
wos_endnote|wos_other )
grep "^UT " - | sed -e 's/^UT //' -e 's/\r//g'
;;
ebscohost_psycinfo_ris )
grep "^AN - " - | sed -e 's/^AN - //' -e 's/\r//g'
;;
ebscohost_cinahl_ris )
grep "^ID - " - | sed -e 's/^ID - //' -e 's/\r//g'
;;
ictrp )
grep "^ <TrialID>" - | sed -e 's/^ <TrialID>//' -e 's/\s*$//'
;;
clinicaltrials_gov_txt )
grep "^ NCT Number:" - | sed -e 's/^ NCT Number:\s\+//' -e 's/\s*$//'
;;
clinicaltrials_gov_tsv )
cut -f2 - | tail -n+2
;;
clinicaltrials_gov_xml )
grep "^ <nct_id>" - | sed -e 's/^ <nct_id>//' -e 's/<\/nct_id>\s*$//'
;;
* )
echo "ERROR: Unknown export format ${export_format}" >&2
exit 1
;;
esac