blob: c4346d2555f8b19756e78e517c70fd6756e4e18f (
plain)
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
|
#!/bin/sh
# Public domain notice for all NCBI EDirect scripts is located at:
# https://www.ncbi.nlm.nih.gov/IEB/ToolBox/CPP_DOC/lxr/source/scripts/projects/blast/LICENSE
doall=false
dofresh=false
flag="none"
while [ $# -gt 0 ]
do
case "$1" in
-strict )
flag="strict"
shift
;;
-mixed )
flag="mixed"
shift
;;
-path )
shift
;;
-all )
doall=true
shift
;;
-fresh )
dofresh=true
shift
;;
-* )
exec >&2
echo "$0: Unrecognized option $1"
exit 1
;;
* )
break
;;
esac
done
if [ "$#" -gt 0 ]
then
argument="$1"
target=$(cd "$argument" && pwd)
target=${target%/}
case "$target" in
*/Archive ) ;;
* ) target=$target/Archive ;;
esac
else
if [ -z "${EDIRECT_PUBMED_MASTER}" ]
then
echo "Must supply path to archive files or set EDIRECT_PUBMED_MASTER environment variable"
exit 1
else
MASTER="${EDIRECT_PUBMED_MASTER}"
MASTER=${MASTER%/}
target="$MASTER/Archive"
fi
fi
osname=`uname -s | sed -e 's/_NT-.*$/_NT/; s/^MINGW[0-9]*/CYGWIN/'`
if [ "$osname" = "CYGWIN_NT" -a -x /bin/cygpath ]
then
target=`cygpath -w "$target"`
fi
target=${target%/}
HEAD=$(cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE PubmedArticleSet PUBLIC "-//NLM//DTD PubMedArticle, 1st January 2019//EN" "https://dtd.nlm.nih.gov/ncbi/pubmed/out/pubmed_190101.dtd">
<PubmedArticleSet>
EOF
)
TAIL=$(cat <<EOF
</PubmedArticleSet>
EOF
)
if [ "$doall" = true ]
then
mx=$(
for dr in "$target"/*
do
if [ -d "$dr" ]
then
bs=$(basename "$dr")
echo "$bs"
fi
done |
sort -n | tail -n 1
)
maximum=$(((mx + 1) * 1000000))
fr=0
chunk_size=250000
to=$((chunk_size - 1))
loop_max=$((maximum / chunk_size))
echo "$HEAD"
seq 1 $loop_max | while read n
do
seq -f "%0.f" $fr $to | rchive -gzip -fetch "$target"
fr=$((fr + chunk_size))
to=$((to + chunk_size))
perl -e "select(undef, undef, undef, 0.1)"
done
echo "$TAIL"
elif [ "$dofresh" = true ]
then
mx=$(
for dr in "$target"/*
do
if [ -d "$dr" ]
then
bs=$(basename "$dr")
echo "$bs"
fi
done |
sort -n | tail -n 1
)
maximum=$(((mx + 1) * 1000000))
fr=0
chunk_size=250000
to=$((chunk_size - 1))
loop_max=$((maximum / chunk_size))
seq 1 $loop_max | while read n
do
base=$(printf pubmed%03d $n)
if [ -f "$base.xml.gz" ]
then
fr=$((fr + chunk_size))
to=$((to + chunk_size))
continue
fi
if [ -f "$base.xml" ]
then
continue
fi
echo "$base XML"
seconds_start=$(date "+%s")
seq -f "%0.f" $fr $to | rchive -gzip -fetch "$target" -head "<PubmedArticleSet>" -tail "</PubmedArticleSet>" > "$base.xml"
fr=$((fr + chunk_size))
to=$((to + chunk_size))
seconds_end=$(date "+%s")
seconds=$((seconds_end - seconds_start))
echo "$seconds seconds"
fsize=$(wc -c < "$base.xml")
if [ "$fsize" -le 300 ]
then
rm "$base.xml.gz"
exit 0
fi
perl -e "select(undef, undef, undef, 0.1)"
done
else
echo "$HEAD"
rchive -gzip -flag "$flag" -fetch "$target"
echo "$TAIL"
fi
|