Debian Codegraph @

pm-collect

raw
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 if [ "$#" -eq 0 ]
7 then
8 echo "Must supply path for archive files"
9 exit 1
10 fi
11
12 archive="$1"
13 shift
14
15 archive=${archive%/}
16
17 if [ "$#" -eq 0 ]
18 then
19 echo "Must supply path for current files"
20 exit 1
21 fi
22
23 target="$1"
24 shift
25
26 target=${target%/}
27
28 find "$target" -name "*.xml" -delete
29 find "$target" -name "*.xml.gz" -delete
30
31 fr=0
32 chunk_size=250000
33 if [ -n "${EDIRECT_CHUNK_SIZE}" ]
34 then
35 chunk_size="${EDIRECT_CHUNK_SIZE}"
36 fi
37 to=$((chunk_size - 1))
38 loop_max=$((50000000 / chunk_size))
39 seq 1 $loop_max | while read n
40 do
41 base=$(printf pubmed%03d $n)
42 if [ -f "$target/$base.xml.gz" ]
43 then
44 fr=$((fr + chunk_size))
45 to=$((to + chunk_size))
46 continue
47 fi
48 echo "$base.xml"
49 seq -f "%0.f" $fr $to | rchive -stream "$archive" -head "<PubmedArticleSet>" -tail "</PubmedArticleSet>" > "$target/$base.xml.gz"
50 fr=$((fr + chunk_size))
51 to=$((to + chunk_size))
52 fsize=$(wc -c < "$target/$base.xml.gz")
53 if [ "$fsize" -le 300 ]
54 then
55 rm -f "$target/$base.xml.gz"
56 exit 0
57 fi
58 sleep 1
59 done