-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge_pdbml_nextgen_worker.sh
executable file
·224 lines (153 loc) · 5.5 KB
/
merge_pdbml_nextgen_worker.sh
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
#!/bin/bash
source ./scripts/env.sh
WORK_DIR=
FILE_LIST=
TOTAL=
VALIDATE=false
ARGV=`getopt --long -o "d:l:n:t:v" "$@"`
eval set -- "$ARGV"
while true ; do
case "$1" in
-d)
WORK_DIR=$2
shift
;;
-l)
FILE_LIST=$2
shift
;;
-n)
PROC_INFO=$2
shift
;;
-t)
TOTAL=$2
shift
;;
-v)
VALIDATE=true
;;
*)
break
;;
esac
shift
done
if ! [[ $PROC_INFO =~ .*of.* ]] ; then
echo "Invalid thread id ($PROC_INFO)."
exit 1
fi
xml_pretty() {
if [ $has_xmllint_command != "false" ] ; then
xmllint --format $1 > $1~ && mv -f $1~ $1 || rm -f $1~
fi
}
MAXPROCS=`echo $PROC_INFO | cut -d 'f' -f 2`
PROC_ID=`echo $PROC_INFO | cut -d 'o' -f 1`
PROC_ID=$(($PROC_ID - 1))
# TOTAL=`wc -l < $FILE_LIST`
proc_id=0
while read pdbml_gz_file
do
proc_id_mod=$(($proc_id % $MAXPROCS))
if [ $proc_id_mod = $PROC_ID ] ; then
if [ ! -e $pdbml_gz_file ] ; then
let proc_id++
continue
fi
pdb_id=`basename $pdbml_gz_file -noatom.xml.gz`
pdbml_nextgen_gz_file=$NEXTGEN/${pdb_id:1:2}/$NEXTGEN_FILE_PREFIX$pdb_id/$NEXTGEN_FILE_PREFIX$pdb_id$NEXTGEN_FILE_SUFFIX.xml.gz
pdbml_sifts_file=$WORK_DIR/$pdb_id-noatom-sifts.xml
div_dir=$WORK_DIR/${pdb_id:1:2}
err_file=$WORK_DIR/merge_pdbml_nextgen_$pdb_id.err
lock_file=$WORK_DIR/$pdb_id.lock
if [ ! -e $pdbml_nextgen_gz_file ] ; then
if [ ! -e $div_dir/$pdb_id-noatom-sifts.xml.gz ] ; then
mk_div_dir $div_dir
cp $pdbml_gz_file $div_dir/$pdb_id-noatom-sifts.xml.gz
fi
elif [ ! -e $lock_file ] && ( ( [ ! -e $pdbml_sifts_file ] && [ ! -e $div_dir/`basename $pdbml_sifts_file`.gz ] ) || [ -e $err_file ] ) ; then
touch $lock_file
pdbml_file=${pdbml_gz_file%.*} # remove the last '.gz'
gunzip -c $pdbml_gz_file > $pdbml_file || exit 1
pdbml_nextgen_file=${pdbml_nextgen_gz_file%.*} # remove the last '.gz'
gunzip -c $pdbml_nextgen_gz_file > $pdbml_nextgen_file || exit 1
xsltproc -o $pdbml_sifts_file --stringparam nextgen_file ../$pdbml_nextgen_file $MERGE_PDBML_NEXTGEN_XSL $pdbml_file 2> $err_file && rm -f $err_file $pdbml_file $pdbml_nextgen_file || ( rm -f $pdbml_file $pdbml_nextgen_file $pdbml_sifts_file $sifts_xml_file ; cat $err_file )
#java -jar $SAXON -s:$pdbml_file -xsl:$MERGE_PDBML_NEXTGEN_XSL -o:$pdbml_sifts_file nextgen_file=../$pdbml_nextgen_file 2> $err_file && rm -f $err_file $pdbml_file $pdbml_nextgen_file || ( rm -f $pdbml_file $pdbml_nextgen_file $pdbml_sifts_file $sifts_xml_file ; cat $err_file )
if [ -e $pdbml_sifts_file ] ; then
xml_pretty $pdbml_sifts_file
mk_div_dir $div_dir
if [ $VALIDATE = 'true' ] ; then
java -classpath $XSD2PGSCHEMA xmlvalidator --xsd $PDBML_XSD --xml $pdbml_sifts_file > /dev/null 2> $err_file
if [ $? = 0 ] && [ -s $pdbml_sifts_file ] ; then
rm -f $err_file
gzip_in_div_dir $pdbml_sifts_file $div_dir
else
cat $err_file
fi
elif [ -s $pdbml_sifts_file ] ; then
gzip_in_div_dir $pdbml_sifts_file $div_dir
fi
else
mk_div_dir $div_dir
cp $pdbml_gz_file $div_dir/$pdb_id-noatom-sifts.xml.gz
fi
rm -f $lock_file
fi
if [ $proc_id_mod -eq 0 ] ; then
echo -e -n "\rDone "$((proc_id + 1)) of $TOTAL ...
fi
fi
let proc_id++
done < $FILE_LIST
proc_id=0
while read pdbml_gz_file
do
proc_id_mod=$(($proc_id % $MAXPROCS))
if [ $proc_id_mod = $PROC_ID ] ; then
if [ ! -e $pdbml_gz_file ] ; then
let proc_id++
continue
fi
pdb_id=`basename $pdbml_gz_file -noatom.xml.gz`
pdbml_nextgen_gz_file=$NEXTGEN/${pdb_id:1:2}/$NEXTGEN_FILE_PREFIX$pdb_id/$NEXTGEN_FILE_PREFIX$pdb_id$NEXTGEN_FILE_SUFFIX.xml.gz
pdbml_sifts_file=$WORK_DIR/$pdb_id-noatom-sifts.xml
div_dir=$WORK_DIR/${pdb_id:1:2}
err_file=$WORK_DIR/merge_pdbml_nextgen_$pdb_id.err
lock_file=$WORK_DIR/$pdb_id.lock
if [ ! -e $pdbml_nextgen_gz_file ] ; then
if [ ! -e $div_dir/$pdb_id-noatom-sifts.xml.gz ] ; then
mk_div_dir $div_dir
cp $pdbml_gz_file $div_dir/$pdb_id-noatom-sifts.xml.gz
fi
elif [ -e $lock_file ] && ( ( [ ! -e $pdbml_sifts_file ] && [ ! -e $div_dir/`basename $pdbml_sifts_file`.gz ] ) || [ -e $err_file ] ) ; then
touch $lock_file
pdbml_file=${pdbml_gz_file%.*} # remove the last '.gz'
gunzip -c $pdbml_gz_file > $pdbml_file || exit 1
pdbml_nextgen_file=${pdbml_nextgen_gz_file%.*} # remove the last '.gz'
gunzip -c $pdbml_nextgen_gz_file > $pdbml_nextgen_file || exit 1
xsltproc -o $pdbml_sifts_file --stringparam nextgen_file ../$pdbml_nextgen_file $MERGE_PDBML_NEXTGEN_XSL $pdbml_file 2> $err_file && rm -f $err_file $pdbml_file $pdbml_nextgen_file || ( rm -f $pdbml_file $pdbml_nextgen_file $pdbml_sifts_file $sifts_xml_file ; cat $err_file )
#java -jar $SAXON -s:$pdbml_file -xsl:$MERGE_PDBML_NEXTGEN_XSL -o:$pdbml_sifts_file nextgen_file=../$pdbml_nextgen_file 2> $err_file && rm -f $err_file $pdbml_file $pdbml_nextgen_file || ( rm -f $pdbml_file $pdbml_nextgen_file $pdbml_sifts_file $sifts_xml_file ; cat $err_file )
if [ -e $pdbml_sifts_file ] ; then
xml_pretty $pdbml_sifts_file
mk_div_dir $div_dir
if [ $VALIDATE = 'true' ] ; then
java -classpath $XSD2PGSCHEMA xmlvalidator --xsd $PDBML_XSD --xml $pdbml_sifts_file > /dev/null 2> $err_file
if [ $? = 0 ] && [ -s $pdbml_sifts_file ] ; then
rm -f $err_file
gzip_in_div_dir $pdbml_sifts_file $div_dir
else
cat $err_file
fi
elif [ -s $pdbml_sifts_file ] ; then
gzip_in_div_dir $pdbml_sifts_file $div_dir
fi
else
mk_div_dir $div_dir
cp $pdbml_gz_file $div_dir/$pdb_id-noatom-sifts.xml.gz
fi
rm -f $lock_file
fi
fi
let proc_id++
done < $FILE_LIST~