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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
|
#!/bin/sh
# ===========================================================================
#
# PUBLIC DOMAIN NOTICE
# National Center for Biotechnology Information (NCBI)
#
# This software/database is a "United States Government Work" under the
# terms of the United States Copyright Act. It was written as part of
# the author's official duties as a United States Government employee and
# thus cannot be copyrighted. This software/database is freely available
# to the public for use. The National Library of Medicine and the U.S.
# Government do not place any restriction on its use or reproduction.
# We would, however, appreciate having the NCBI and the author cited in
# any work or product based on this material.
#
# Although all reasonable efforts have been taken to ensure the accuracy
# and reliability of the software and data, the NLM and the U.S.
# Government do not and cannot warrant the performance or results that
# may be obtained by using this software or data. The NLM and the U.S.
# Government disclaim all warranties, express or implied, including
# warranties of performance, merchantability or fitness for any particular
# purpose.
#
# ===========================================================================
#
# File Name: efetch
#
# Author: Jonathan Kans, Aaron Ucko
#
# Version Creation Date: 04/08/2020
#
# ==========================================================================
pth=$( dirname "$0" )
case "$pth" in
/* )
;; # already absolute
* )
pth=$(cd "$pth" && pwd)
;;
esac
case ":$PATH:" in
*:"$pth":* )
;;
* )
PATH="$PATH:$pth"
export PATH
;;
esac
# handle common flags - dot command is equivalent of "source"
if [ ! -f "$pth"/ecommon.sh ]
then
echo "ERROR: Unable to find '$pth/ecommon.sh' file" >&2
exit 1
fi
. "$pth"/ecommon.sh
# initialize specific flags
internal=false
isDocsum=false
isPreview=false
format=""
mode=""
style=""
chunk=1
force=0
min=0
max=0
seq_start=0
seq_stop=0
strand=0
complexity=0
extend=-1
extrafeat=-1
showgaps=""
json=false
# read command-line arguments
while [ $# -gt 0 ]
do
case "$1" in
-internal )
internal=true
shift
;;
-newmode | -oldmode )
shift
;;
-db )
shift
if [ $# -gt 0 ]
then
if [ -n "$db" ]
then
if [ "$db" = "$1" ]
then
echo "${INVT} WARNING: ${LOUD} Redundant -db '$1' argument${INIT}" >&2
else
echo "${INVT} ERROR: ${LOUD} Colliding -db '$db' and '$1' arguments${INIT}" >&2
# exit 1
fi
fi
db="$1"
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -db argument${INIT}" >&2
exit 1
fi
;;
-id )
shift
if [ $# -gt 0 ]
then
ids="$1"
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -id argument${INIT}" >&2
exit 1
fi
while [ $# -gt 0 ]
do
case "$1" in
-* )
break
;;
* )
# concatenate run of UIDs with commas
ids="$ids,$1"
shift
;;
esac
done
;;
-format )
shift
if [ $# -gt 0 ]
then
if [ -n "$format" ]
then
if [ "$isDocsum" = true ] && [ "$format" = "docsum" ]
then
echo "${INVT} WARNING: ${LOUD} esummary does not need redundant -format docsum argument${INIT}" >&2
elif [ "$format" = "$1" ]
then
echo "${INVT} WARNING: ${LOUD} Redundant -format '$1' argument${INIT}" >&2
else
echo "${INVT} ERROR: ${LOUD} Colliding -format '$format' and '$1' arguments${INIT}" >&2
# exit 1
fi
fi
format="$1"
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -format argument${INIT}" >&2
exit 1
fi
;;
-docsum )
# esummary is implemented as efetch -docsum "$@"
if [ -n "$format" ]
then
if [ "$format" = "docsum" ]
then
echo "${INVT} WARNING: ${LOUD} Superflouous -docsum argument${INIT}" >&2
else
echo "${INVT} ERROR: ${LOUD} Colliding -docsum and -format '$format' arguments${INIT}" >&2
# exit 1
fi
fi
format="docsum"
isDocsum=true
shift
;;
-mode )
shift
if [ $# -gt 0 ]
then
mode="$1"
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -mode argument${INIT}" >&2
exit 1
fi
;;
-style )
shift
if [ $# -gt 0 ]
then
style="$1"
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -style argument${INIT}" >&2
exit 1
fi
;;
-seq_start )
shift
if [ $# -gt 0 ]
then
# 1-based
seq_start=$(( $1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -seq_start argument${INIT}" >&2
exit 1
fi
;;
-chr_start )
shift
if [ $# -gt 0 ]
then
# 0-based
seq_start=$(( $1 + 1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -chr_start argument${INIT}" >&2
exit 1
fi
;;
-seq_stop )
shift
if [ $# -gt 0 ]
then
# 1-based
seq_stop=$(( $1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -seq_stop argument${INIT}" >&2
exit 1
fi
;;
-chr_stop )
shift
if [ $# -gt 0 ]
then
# 0-based
seq_stop=$(( $1 + 1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -chr_stop argument${INIT}" >&2
exit 1
fi
;;
-strand )
shift
if [ $# -gt 0 ]
then
case "$1" in
forward | plus | 1 | "\+" )
strand=1
;;
revcomp | reverse | minus | 2 | "\-" )
strand=2
;;
* )
echo "${INVT} ERROR: ${LOUD} Unrecognized -strand argument '$strand'${INIT}" >&2
exit 1
;;
esac
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -strand argument${INIT}" >&2
exit 1
fi
;;
-forward | -plus )
strand=1
shift
;;
-revcomp | -reverse | -minus )
strand=2
shift
;;
-h | -help | --help | help )
if [ "$isDocsum" = true ]
then
echo "esummary $version"
echo ""
cat "$pth/help/esummary-help.txt"
echo ""
else
echo "efetch $version"
echo ""
cat "$pth/help/efetch-help.txt"
echo ""
fi
exit 0
;;
-chunk )
shift
if [ $# -gt 0 ]
then
# override calculated chunk value (undocumented)
force=$(( $1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -chunk argument${INIT}" >&2
exit 1
fi
;;
-start )
shift
if [ $# -gt 0 ]
then
min=$(( $1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -start argument${INIT}" >&2
exit 1
fi
;;
-stop )
shift
if [ $# -gt 0 ]
then
max=$(( $1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -stop argument${INIT}" >&2
exit 1
fi
;;
-complexity )
shift
if [ $# -gt 0 ]
then
complexity=$(( $1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -complexity argument${INIT}" >&2
exit 1
fi
;;
-extend )
shift
if [ $# -gt 0 ]
then
extend=$(( $1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -extend argument${INIT}" >&2
exit 1
fi
;;
-extrafeat )
shift
if [ $# -gt 0 ]
then
extrafeat=$(( $1 ))
shift
else
echo "${INVT} ERROR: ${LOUD} Missing -extrafeat argument${INIT}" >&2
exit 1
fi
;;
-showgaps | -show-gaps )
showgaps="on"
shift
;;
-json )
json=true
shift
;;
-* )
ParseCommonArgs "$@"
if [ "$argsConsumed" -gt 0 ]
then
shift "$argsConsumed"
else
echo "${INVT} ERROR: ${LOUD} Unrecognized option $1${INIT}" >&2
exit 1
fi
;;
* )
# allows while loop to check for multiple flags
break
;;
esac
done
FinishSetup
# check for ENTREZ_DIRECT message or piped UIDs unless database and UIDs provided in command line
if [ -z "$db" ]
then
ParseStdin
elif [ -z "$ids" ] && [ -z "$input" ]
then
ParseStdin
fi
# needHistory allows reuse of GenerateUidList
if [ -z "$ids$rest$qury$input" ]
then
needHistory=true
fi
# reality check for -db against piped dbase
if [ -n "$dbase" ] && [ -n "$db" ]
then
if [ "$dbase" = "$db" ]
then
echo "${INVT} WARNING: ${LOUD} Redundant -db '$db' argument${INIT}" >&2
else
echo "${INVT} ERROR: ${LOUD} Colliding '$dbase' database and -db '$db' argument${INIT}" >&2
# exit 1
fi
fi
# take database from dbase value or -db argument
if [ -z "$dbase" ]
then
dbase="$db"
fi
# check for missing required arguments
if [ -z "$dbase" ]
then
echo "${INVT} ERROR: ${LOUD} Missing -db argument${INIT}" >&2
exit 1
fi
# check for PubMed preview server
if [ "$dbase" = "pubmed" ]
then
isPreview=true
if [ "$quick" = true ]
then
isPreview=false
fi
fi
# convert spaces between UIDs to commas
ids=$( echo "$ids" | sed -e "s/ /,/g; s/,,*/,/g" )
# database and format class flags
isSequence=false
isFasta=false
case "$dbase" in
nucleotide | nuccore | protein )
isSequence=true
;;
esac
case "$format" in
*fasta* )
isFasta=true
;;
esac
# adjust for -db pubmed
if [ "$dbase" = "pubmed" ]
then
if [ -z "$format" ] || [ "$format" = "native" ]
then
format="full"
mode="xml"
fi
fi
# adjust for -db clinvar
is_variationid=false
if [ "$dbase" = "clinvar" ] && [ "$format" = "variationid" ]
then
format="vcv"
is_variationid=true
fi
# adjust for -db sra
if [ "$dbase" = "sra" ]
then
if [ -z "$format" ]
then
format="runinfo"
elif [ "$format" = "native" ]
then
format="full"
fi
fi
# special cases for format, mode, and style
case "$format:$mode:$isSequence" in
xml::* )
format="full"
mode="xml"
;;
accn:*:true )
format="acc"
;;
asn:* )
format="asn.1"
;;
esac
case "$style" in
normal | none | contig )
style=""
;;
master )
style="master"
;;
conwithfeat | conwithfeats | contigwithfeat | gbconwithfeat | gbconwithfeats )
style="conwithfeat"
;;
withpart | withparts | gbwithpart | gbwithparts )
# accept from old scripts - same result as style master
style="withparts"
;;
"" )
;;
* )
echo "${INVT} ERROR: ${LOUD} Unrecognized -style argument '$style'${INIT}" >&2
exit 1
;;
esac
case "$format:$mode" in
gbc: | gpc: )
mode="xml"
;;
"" )
format="native"
;;
docsum:json )
;;
docsum:* )
mode="xml"
;;
esac
if [ "$format" = "" ]
then
format="native"
fi
if [ "$mode" = "" ]
then
mode="text"
fi
# do not treat TinySeq XML as FASTA
if [ "$format" = "fasta" ] && [ "$mode" = "xml" ]
then
isFasta=false
fi
# input reality checks
if [ "$needHistory" = true ]
then
if [ -t 0 ]
then
echo "${INVT} ERROR: ${LOUD} ENTREZ_DIRECT message not piped from stdin${INIT}" >&2
exit 1
fi
if [ "$empty" = true ]
then
# silently exit if explicit count of "0"
exit 0
fi
if [ -z "$web_env" ]
then
echo "${INVT} ERROR: ${LOUD} WebEnv value not found in efetch input${INIT}" >&2
exit 1
fi
if [ -z "$qry_key" ]
then
echo "${INVT} ERROR: ${LOUD} QueryKey value not found in efetch input${INIT}" >&2
exit 1
fi
if [ "$num" -lt 1 ]
then
# silently exit if no results to fetch
exit 0
fi
fi
# -id 0 looks up default record for each database
GetZero() {
case "$dbase" in
annotinfo ) ids="122134" ;;
assembly ) ids="443538" ;;
biocollections ) ids="7370" ;;
bioproject ) ids="146229" ;;
biosample ) ids="3737421" ;;
biosystems ) ids="1223165" ;;
blastdbinfo ) ids="998664" ;;
books ) ids="1371014" ;;
cdd ) ids="274590" ;;
clinvar ) ids="10510" ;;
clone ) ids="18646800" ;;
dbvar ) ids="6173073" ;;
gap ) ids="872875" ;;
gapplus ) ids="136686" ;;
gds ) ids="200022309" ;;
gencoll ) ids="398148" ;;
gene ) ids="3667" ;;
genome ) ids="52" ;;
geoprofiles ) ids="16029743" ;;
grasp ) ids="2852486" ;;
gtr ) ids="559277" ;;
homologene ) ids="510" ;;
ipg ) ids="422234" ;;
medgen ) ids="162753" ;;
mesh ) ids="68007328" ;;
ncbisearch ) ids="3158" ;;
nlmcatalog ) ids="0404511" ;;
nuccore ) ids="1322283" ;;
nucleotide ) ids="1322283" ;;
omim ) ids="176730" ;;
orgtrack ) ids="319950" ;;
pcassay ) ids="1901" ;;
pccompound ) ids="16132302" ;;
pcsubstance ) ids="126522451" ;;
pmc ) ids="209839" ;;
popset ) ids="27228303" ;;
protein ) ids="4557671" ;;
proteinclusters ) ids="2945638" ;;
pubmed ) ids="2539356" ;;
seqannot ) ids="9561" ;;
snp ) ids="137853337" ;;
sra ) ids="190091" ;;
structure ) ids="61024" ;;
taxonomy ) ids="562" ;;
unigene ) ids="1132160" ;;
esac
}
if [ "$ids" = "0" ]
then
GetZero
fi
# lookup accessions in -id argument or piped from stdin
if [ "$dbase" != "clinvar" ] || [ "$format" != "vcv" ]
then
LookupSpecialAccessions
fi
# reality checks and adjustments on sequence variables
if [ "$isSequence" = true ]
then
if [ "$extend" -gt 0 ]
then
seq_start=$(( $seq_start - $extend ))
seq_stop=$(( $seq_stop + $extend ))
fi
else
if [ "$seq_start" -ne 0 ]
then
echo "${INVT} ERROR: ${LOUD} Only sequence formats may use -seq_start${INIT}" >&2
exit 1
fi
if [ "$seq_stop" -ne 0 ]
then
echo "${INVT} ERROR: ${LOUD} Only sequence formats may use -seq_stop${INIT}" >&2
exit 1
fi
if [ "$strand" -ne 0 ]
then
echo "${INVT} ERROR: ${LOUD} Only sequence formats may use -strand${INIT}" >&2
exit 1
fi
if [ "$complexity" -ne 0 ]
then
echo "${INVT} ERROR: ${LOUD} Only sequence formats may use -complexity${INIT}" >&2
exit 1
fi
if [ "$extrafeat" -ne -1 ]
then
echo "${INVT} ERROR: ${LOUD} Only sequence formats may use -extrafeat${INIT}" >&2
exit 1
fi
if [ -n "$showgaps" ]
then
echo "${INVT} ERROR: ${LOUD} Only sequence formats may use -showgaps${INIT}" >&2
exit 1
fi
fi
if [ "$isSequence" = true ]
then
if [ "$seq_start" -gt 0 ] && [ "$seq_stop" -gt 0 ]
then
if [ "$seq_start" -gt "$seq_stop" ]
then
tmp="$seq_start"
seq_start="$seq_stop"
seq_stop="$tmp"
if [ "$strand" -eq 0 ]
then
strand=2
fi
fi
else
seq_start=""
seq_stop=""
fi
if [ "$strand" -lt 1 ]
then
strand=""
fi
if [ "$complexity" -lt 1 ]
then
complexity=""
fi
if [ "$extrafeat" -lt 1 ]
then
extrafeat=""
fi
else
# otherwise clear all sequence-related flags, will be ignored by AddIfNotEmpty
seq_start=""
seq_stop=""
strand=""
complexity=""
extrafeat=""
showgaps=""
fi
# determine size of individual requests
case "$format:$dbase:$mode:$isSequence" in
uid:pubmed:* ) chunk=5000 ;;
uid:* ) chunk=25000 ;;
acc:*:true ) chunk=10000 ;;
url:* ) chunk=50 ;;
docsum:gtr:json:* ) chunk=50 ;;
docsum:*:json:* ) chunk=500 ;;
fasta:* ) chunk=50 ;;
bioc:* ) chunk=100 ;;
ipg:* ) chunk=100 ;;
json:snp:* ) chunk=10 ;;
*:sra:* ) chunk=100 ;;
*:*:true ) chunk=100 ;;
* ) chunk=1000 ;;
esac
if [ "$style" = "master" ] || [ "$style" = "withparts" ] || [ "$style" = "conwithfeat" ]
then
chunk=1
fi
if [ "$force" -gt 0 ]
then
chunk="$force"
fi
# limit uid list between min and max
LimitUidList() {
db="$1"
res=$( GenerateUidList "$db" )
if [ "$min" -gt 0 ] && [ "$max" -gt 0 ]
then
res=$( echo "$res" | sed -ne "${min},${max}p" )
elif [ "$min" -gt 0 ]
then
res=$( echo "$res" | head -n "${max}" )
elif [ "$max" -gt 0 ]
then
res=$( echo "$res" | tail -n +"${min}" )
fi
echo "$res"
}
# -format uid
if [ "$format" = "uid" ]
then
res=$( LimitUidList "$dbase" )
echo "$res"
exit 0
fi
# -format url
if [ "$format" = "url" ]
then
res=$( LimitUidList "$dbase" )
echo "$res" |
join-into-groups-of "$chunk" |
while read uids
do
echo "https://www.ncbi.nlm.nih.gov/$dbase/$uids"
done
exit 0
fi
# -format urls
if [ "$format" = "urls" ]
then
res=$( LimitUidList "$dbase" )
echo "$res" |
while read uid
do
echo "https://www.ncbi.nlm.nih.gov/$dbase/$uid"
done
exit 0
fi
# -format xids
if [ "$format" = "xids" ]
then
echo "<ENTREZ_DIRECT>"
if [ -n "$dbase" ]
then
echo " <Db>${dbase}</Db>"
fi
# instantiate UIDs within ENTREZ_DIRECT message
res=$( LimitUidList "$dbase" )
nm=$( echo "$res" | wc -l | tr -d ' ' )
if [ -n "$nm" ]
then
echo " <Count>${nm}</Count>"
fi
echo "$res" |
while read uid
do
echo " <Id>${uid}</Id>"
done
if [ -n "$err" ]
then
echo " <Error>${err}</Error>"
fi
echo "</ENTREZ_DIRECT>"
exit 0
fi
# -format docsum
if [ "$format" = "docsum" ]
then
if [ "$needHistory" = false ]
then
res=$( LimitUidList "$dbase" )
echo "$res" |
join-into-groups-of "$chunk" |
while read uids
do
RunWithCommonArgs nquire -url "$base" esummary.fcgi \
-db "$dbase" -id "$uids" -version "2.0" -retmode "$mode"
done
else
GenerateHistoryChunks "$chunk" "$min" "$max" |
while read fr chnk
do
RunWithCommonArgs nquire -url "$base" esummary.fcgi \
-query_key "$qry_key" -WebEnv "$web_env" -retstart "$fr" -retmax "$chnk" \
-db "$dbase" -version "2.0" -retmode "$mode"
done
fi |
if [ "$mode" = "json" ]
then
grep '.'
elif [ "$raw" = true ]
then
# transmute -mixed -format indent -doctype ""
grep '.'
elif [ "$json" = true ]
then
transmute -x2j
elif [ "$dbase" = "sra" ]
then
transmute -mixed -normalize "$dbase" |
sed -e 's/<!DOCTYPE eSummaryResult PUBLIC/<!DOCTYPE DocumentSummarySet PUBLIC/g; s/<eSummaryResult>//g; s/<\/eSummaryResult>//g' |
transmute -mixed -compress -format indent -doctype "" -self
else
transmute -mixed -normalize "$dbase" |
sed -e 's/<!DOCTYPE eSummaryResult PUBLIC/<!DOCTYPE DocumentSummarySet PUBLIC/g; s/<eSummaryResult>//g; s/<\/eSummaryResult>//g' |
transmute -mixed -compress -format indent -doctype ""
fi
exit 0
fi
# -format bioc
biocbase="https://www.ncbi.nlm.nih.gov/research/pubtator-api/publications/export/biocxml"
idtype=""
prefix=""
if [ "$format" = "bioc" ]
then
if [ "$dbase" = "pubmed" ]
then
idtype="-pmids"
elif [ "$dbase" = "pmc" ]
then
idtype="-pmcids"
prefix="PMC"
else
echo "${INVT} ERROR: ${LOUD} BioC format must use -db pubmed or pmc${INIT}" >&2
exit 1
fi
GenerateUidList "$dbase" |
while read uid
do
echo "$prefix${uid#PMC}"
done |
join-into-groups-of "$chunk" |
while read uids
do
nquire -get $biocbase $idtype $uids |
if [ "$raw" = true ]
then
# transmute -format indent -doctype ""
grep '.'
elif [ "$json" = true ]
then
transmute -x2j
else
transmute -normalize bioc | transmute -format indent -doctype ""
fi
done
exit 0
fi
# helper function adds sequence-specific arguments (if set)
RunWithFetchArgs() {
AddIfNotEmpty -style "$style" \
AddIfNotEmpty -seq_start "$seq_start" \
AddIfNotEmpty -seq_stop "$seq_stop" \
AddIfNotEmpty -strand "$strand" \
AddIfNotEmpty -complexity "$complexity" \
AddIfNotEmpty -extrafeat "$extrafeat" \
AddIfNotEmpty -show-gaps "$showgaps" \
FlagIfNotEmpty -is_variationid "$is_variationid" \
RunWithCommonArgs "$@"
}
# -immediate flag for full sequence records
if [ "$isFasta" = false ] && [ "$isSequence" = false ]
then
immediate=false
express=false
fi
if [ "$immediate" = true ]
then
express=true
fi
if [ -n "$format" ] && [ "$express" = true ]
then
chunk=5
if [ "$immediate" = true ]
then
chunk=1
fi
GenerateUidList "$dbase" |
join-into-groups-of "$chunk" |
while read uid
do
if [ -n "$style" ]
then
nquire -url "$base" efetch.fcgi \
-db "$dbase" -id "$uid" -rettype "$format" -retmode "$mode" -style "$style"
else
nquire -url "$base" efetch.fcgi \
-db "$dbase" -id "$uid" -rettype "$format" -retmode "$mode"
fi
done
exit 0
fi
# other -format choices
if [ -n "$format" ]
then
if [ "$needHistory" = false ]
then
res=$( LimitUidList "$dbase" )
echo "$res" |
join-into-groups-of "$chunk" |
while read uids
do
RunWithFetchArgs nquire -url "$base" efetch.fcgi \
-db "$dbase" -id "$uids" -rettype "$format" -retmode "$mode"
done
else
GenerateHistoryChunks "$chunk" "$min" "$max" |
while read fr chnk
do
RunWithFetchArgs nquire -url "$base" efetch.fcgi \
-query_key "$qry_key" -WebEnv "$web_env" -retstart "$fr" -retmax "$chnk" \
-db "$dbase" -rettype "$format" -retmode "$mode"
done
fi |
if [ "$format" = "json" ] || [ "$mode" = "json" ] || [ "$raw" = true ]
then
grep '.'
elif [ "$json" = true ]
then
transmute -x2j
elif [ "$isFasta" = true ]
then
grep '.'
elif [ "$format" = "full" ] && [ "$mode" = "xml" ]
then
if [ "$dbase" = "pubmed" ] && [ "$isPreview" = true ]
then
# first pass to convert SOLR server's &#x...; hex encodings with html.UnescapeString
transmute -normalize "$dbase" |
transmute -normalize "$dbase" |
transmute -format indent -combine -doctype ""
elif [ "$dbase" = "pubmed" ]
then
transmute -normalize "$dbase" |
transmute -format indent -combine -doctype ""
elif [ "$dbase" = "sra" ]
then
transmute -normalize "$dbase" |
transmute -format indent -combine -doctype "" -self
elif [ "$dbase" = "pmc" ]
then
grep '.'
elif [ "$dbase" = "pccompound" ] || [ "$dbase" = "pcsubstance" ]
then
transmute -mixed -normalize "$dbase"
else
transmute -format indent -combine -doctype ""
fi
elif [ "$dbase" = "sra" ] && [ "$format" = "runinfo" ]
then
sed '2,${/Run,ReleaseDate,LoadDate/d;}'
else
grep ''
fi
exit 0
fi
# warn if no format recognized
echo "${INVT} ERROR: ${LOUD} Unrecognized format${INIT}" >&2
exit 1
|