-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnpmarker.sh
executable file
·327 lines (287 loc) · 8.49 KB
/
snpmarker.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
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
#!/bin/sh
#
# Program: snpmarker.sh
#
# Purpose:
#
# Script for loading SNP_ConsensusSnp_Marker table
# with dbSNP determined snp to marker associations
# and MGI determined snp to marker associations.
#
# Usage: snpmarker.sh [-a] [-r] [-c] [-l]
# where:
# -a is an option to archive output directory
# -r is an option to archive logs directory
# -c is an option to clean output directory
# -l is an option to clean logs directory
#
# Approximate times:
#
# History
#
# lec 01/21/2013
# - TR10788/testing on linux server (TR11248 scrum project)
#
# sc 04/20/2012
# - TR10788
# - updated for postgres, this includes removing
# - rm bcp in/out of mgd..MRK_Location_Cache to snp..MRK_Location_Cache
# - bcpin.csh instead of bcpin.csh
# - rm all sybase specific stuff
# lec 09/01/2011
# - TR10805
# - bcpout/in for MRK_Location_Cache uses default bcp settings
# that is, do *not* use NL/DL
# - make sure the MRK_Location_Cache is synced up with
# mgd..MRK_Location_Cache
#
# sc 07/27/2006 - converted to bourne shell
# lec 06/30/2006 - modified for mgiconfig
# sc 03/2006 - convert to snp database add load of snp MRK_Location_Cache
# sc 01/2006 - process multiple snpmrkwithin.bcp files
# dbm 09/28/2005 - Added snpmrklocus.py & snpmrkwithin.py
# sc 08/17/2005 - created
#
#
# Establish bcp file delimiters
#
# bcp file row delimiter
NL="\n"
# bcp file column delimiter
DL="|"
# name of the snp schema
SCHEMA='snp'
export SCHEMA
#
# Set up a log file for the shell script in case there is an error
# during configuration and initialization.
#
cd `dirname $0`
LOG=`pwd`/snpmarker.log
rm -f ${LOG}
#
# Verify the argument(s) to the shell script.
#
ARC_OUTPUT=no
ARC_LOGS=no
CLEAN_OUTPUT=no
CLEAN_LOGS=no
usage="Usage: snpmarker.sh [-a] [-r] [-c] [-l]"
#
# report usage if there are unrecognized arguments
#
set -- `getopt arcl $*`
if [ $? != 0 ]
then
echo ${usage} | tee -a ${LOG}
exit 1
fi
#
# determine which options on command line
#
for i in $*
do
case $i in
-a) ARC_OUTPUT=yes; shift;;
-r) ARC_LOGS=yes; shift;;
-c) CLEAN_OUTPUT=yes; shift;;
-l) CLEAN_LOGS=yes; shift;;
--) shift; break;;
esac
done
#
# Establish the configuration file name, if readable source it
#
CONFIG_LOAD=`pwd`/Configuration
if [ ! -r ${CONFIG_LOAD} ]
then
echo "Cannot read configuration file: ${CONFIG_LOAD}" | tee -a ${LOG}
exit 1
fi
. ${CONFIG_LOAD}
# set PGPASSWORD in the environment
PGPASSWORD=`cat ${PGPASSFILE} | grep ${MGD_DBUSER} | cut -d':' -f5`
#
# Source the DLA library functions.
#
if [ "${DLAJOBSTREAMFUNC}" != "" ]
then
if [ -r ${DLAJOBSTREAMFUNC} ]
then
. ${DLAJOBSTREAMFUNC}
else
echo "Cannot source DLA functions script: ${DLAJOBSTREAMFUNC}" | tee -a ${LOG}
exit 1
fi
else
echo "Environment variable DLAJOBSTREAMFUNC has not been defined." | tee -a ${LOG}
exit 1
fi
#
# archive/clean the logs/output directories?
#
if [ ${ARC_OUTPUT} = "yes" ]
then
date | tee -a ${LOG}
echo "archiving output directory" | tee -a ${LOG}
createArchive ${ARCHIVEDIR}/output ${CACHEDATADIR}
STAT=$?
if [ ${STAT} -ne 0 ]
then
echo "createArchive for output directory failed" | tee -a ${LOG}
exit 1
fi
fi
if [ ${CLEAN_OUTPUT} = "yes" ]
then
date | tee -a ${LOG}
echo "cleaning output directory" | tee -a ${LOG}
cleanDir ${CACHEDATADIR}
STAT=$?
if [ ${STAT} -ne 0 ]
then
echo "cleanDir for output directory failed" | tee -a ${LOG}
exit 1
fi
fi
if [ ${ARC_LOGS} = "yes" ]
then
date | tee -a ${LOG}
echo "archiving logs directory" | tee -a ${LOG}
createArchive ${ARCHIVEDIR}/logs ${CACHELOGSDIR}
STAT=$?
if [ ${STAT} -ne 0 ]
then
echo "createArchive for logs directory failed" | tee -a ${LOG}
exit 1
fi
fi
if [ ${CLEAN_LOGS} = "yes" ]
then
date | tee -a ${LOG}
echo "cleaning logs directory" | tee -a ${LOG}
cleanDir ${CACHELOGSDIR}
STAT=$?
if [ ${STAT} -ne 0 ]
then
echo "cleanDir for logs directory failed" | tee -a ${LOG}
exit 1
fi
fi
#
# Start using the load log now that we have archived/cleaned
#
date > ${SNPMARKER_LOG}
cd ${CACHEDATADIR}
#
# Load dbSNP marker relationships
#
#date | tee -a ${SNPMARKER_LOG}
#echo "Calling snpmarker.py" | tee -a ${SNPMARKER_LOG}
#${PYTHON} ${SNPCACHELOAD}/snpmarker.py >> ${SNPMARKER_LOG} 2>&1
#STAT=$?
#if [ ${STAT} -ne 0 ]
#then
# echo "snpmarker.py failed" | tee -a ${SNPMARKER_LOG}
# exit 1
#fi
#
# copy in SNP_ConsensusSnp_Marker, truncating and dropping/recreating indexes
#
# Note: we can't drop the index of the primary key because it is constraint
# on the primary key
date | tee -a ${SNPMARKER_LOG}
echo "Truncate and drop indexes on SNP_ConsensusSnp_Marker; drop constraints" | tee -a ${LOG}
${SNP_DBSCHEMADIR}/table/SNP_ConsensusSnp_Marker_truncate.object >> ${SNPMARKER_LOG} 2>&1
#${SNP_DBSCHEMADIR}/index/SNP_ConsensusSnp_Marker_drop.object >> ${SNPMARKER_LOG} 2>&1
${SNP_DBSCHEMADIR}/key/SNP_ConsensusSnp_Marker_drop.object >> ${SNPMARKER_LOG} 2>&1
${SNP_DBSCHEMADIR}/key/SNP_ConsensusSnp_drop.object >> ${SNPMARKER_LOG} 2>&1
${SNP_DBSCHEMADIR}/key/SNP_Coord_Cache_drop.object >> ${SNPMARKER_LOG} 2>&1
#date | tee -a ${SNPMARKER_LOG}
#echo "copy in ${SNP_MRK_TABLE}" | tee -a ${SNPMARKER_LOG}
#echo "" | tee -a ${SNPMARKER_LOG}
#${PG_DBUTILS}/bin/bcpin.csh ${MGD_DBSERVER} ${MGD_DBNAME} ${SNP_MRK_TABLE} ${CACHEDATADIR} ${SNP_MRK_FILE} ${DL} 'notused' ${SCHEMA} >> ${SNPMARKER_LOG} 2>&1
#STAT=$?
#echo "snpmarker.sh exit code from bulkLoadPostres ${STAT}"
#if [ ${STAT} -ne 0 ]
#then
# echo "bcpin.csh failed" | tee -a ${SNPMARKER_LOG}
# exit 1
#fi
# constraints will be added back at the end
#date | tee -a ${SNPMARKER_LOG}
#echo "Create index on SNP_ConsensusSnp_Marker" | tee -a ${LOG}
#echo "" | tee -a ${SNPMARKER_LOG}
#${SNP_DBSCHEMADIR}/index/SNP_ConsensusSnp_Marker_create.object >> ${SNPMARKER_LOG} 2>&1
#
# Load MGI snp/marker distance relationships
#
# Only run the following steps if the dbSNP and MGI coordinates are
# synchronized (same mouse genome build).
#
# 5/14 still get unexpected end of file even when this value is 'no'
echo "IN_SYNC: ${IN_SYNC}"
if [ ${IN_SYNC} = "yes" ]
then
#
# Update dbSNP locus-region function class to upstream/downstream
#
#date | tee -a ${SNPMARKER_LOG}
#echo "Calling snpmrklocus.py" | tee -a ${SNPMARKER_LOG}
#echo "" | tee -a ${SNPMARKER_LOG}
#${PYTHON} ${SNPCACHELOAD}/snpmrklocus.py >> ${SNPMARKER_LOG} 2>&1
#STAT=$?
#if [ ${STAT} -ne 0 ]
#then
# echo "${SNPCACHELOAD}/snpmrklocus.py failed" | tee -a ${SNPMARKER_LOG}
# exit 1
#fi
#
# load MGI snp to marker relationships
#
date | tee -a ${SNPMARKER_LOG}
echo "Calling snpmrkwithin.py" | tee -a ${SNPMARKER_LOG}
echo "" | tee -a ${SNPMARKER_LOG}
${PYTHON} ${SNPCACHELOAD}/snpmrkwithin.py >> ${SNPMARKER_LOG} 2>&1
STAT=$?
if [ ${STAT} -ne 0 ]
then
echo "${SNPCACHELOAD}/snpmrkwithin.py failed" | tee -a ${SNPMARKER_LOG}
exit 1
fi
date | tee -a ${SNPMARKER_LOG}
echo "dropping indexes on SNP_ConsensusSnp_Marker" | tee -a ${LOG}
echo "" | tee -a ${SNPMARKER_LOG}
${SNP_DBSCHEMADIR}/index/SNP_ConsensusSnp_Marker_drop.object
echo "" | tee -a ${LOG}
# SNP_MRK_TABLE bcp in each file
cd ${CACHEDATADIR}
for i in `ls ${SNP_MRK_WITHIN_FILE}*`
do
date | tee -a ${SNPMARKER_LOG}
echo "Load ${i} into ${SNP_MRK_TABLE} table" | tee -a ${SNPMARKER_LOG}
echo "" | tee -a ${SNPMARKER_LOG}
${PG_DBUTILS}/bin/bcpin.csh ${MGD_DBSERVER} ${MGD_DBNAME} ${SNP_MRK_TABLE} ${CACHEDATADIR} ${i} ${DL} 'notused' ${SCHEMA} >> ${SNPMARKER_LOG} 2>&1
STAT=$?
if [ ${STAT} -ne 0 ]
then
echo "${PG_DBUTILS}/bin/bcpin.csh failed" | tee -a ${SNPMARKER_LOG}
exit 1
fi
done
# SNP_MRK_TABLE CREATE indexes
date | tee -a ${SNPMARKER_LOG}
echo "Create index on SNP_ConsensusSnp_Marker" | tee -a ${SNPMARKER_LOG}
echo "" | tee -a ${SNPMARKER_LOG}
${SNP_DBSCHEMADIR}/index/SNP_ConsensusSnp_Marker_create.object
fi
#
# re-create keys at the end
#
date | tee -a ${SNPMARKER_LOG}
echo "Create constraints on SNP_ConsensusSnp_Marker" | tee -a ${LOG}
echo "" | tee -a ${SNPMARKER_LOG}
${SNP_DBSCHEMADIR}/key/SNP_ConsensusSnp_Marker_create.object >> ${SNPMARKER_LOG} 2>&1
${SNP_DBSCHEMADIR}/key/SNP_ConsensusSnp_create.object >> ${SNPMARKER_LOG} 2>&1
${SNP_DBSCHEMADIR}/key/SNP_Coord_Cache_create.object >> ${SNPMARKER_LOG} 2>&1
date | tee -a ${SNPMARKER_LOG}