-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path40_make_BamMap.sh
executable file
·47 lines (38 loc) · 1.58 KB
/
40_make_BamMap.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
#!/bin/bash
# author: Matthew Wyczalkowski [email protected]
# Check success of downloads and generate BamMap file. Also writes merged BamMap,
# and instructions for user
source gdc-import.config.sh
CMD="cat $UUID | bash src/make_BamMap3.sh -H -O $DATA_ROOT -S $CATALOG_MASTER -s $FILE_SYSTEM $@ - | sort >> $BAMMAP"
echo "Running: $CMD"
eval $CMD
# Evaluate return value for chain of pipes; see https://stackoverflow.com/questions/90418/exit-shell-script-based-on-process-exit-code
rcs=${PIPESTATUS[*]};
for rc in ${rcs}; do
if [[ $rc != 0 ]]; then
>&2 echo Errors / warnings processing BamMap
>&2 echo Partly written to $BAMMAP
>&2 echo Stopping. Will not merge with Master BamMap.
exit $rc;
fi;
done
# If no errors, write merged BamMap, which is BAMMAP and BAMMAP_MASTER concatenated and sorted
# The output filename will be $BAMMAP.merged
# If master BAMMAP not defined, exit with no error; if defined but not exist, exit with error
if [ -z $BAMMAP_MASTER ]; then
>&2 echo Master BamMap not defined. Stopping.
>&2 echo Download BamMap written to $BAMMAP
exit 0
fi
if [ ! -e $BAMMAP_MASTER ]; then
>&2 echo Error: Master BamMap defined but does not exist. Exiting
>&2 echo Master BamMap: $BAMMAP_MASTER
exit 1
fi
BMM="${BAMMAP}.merged"
grep "^#" $BAMMAP | head -n 1 > $BMM
cat $BAMMAP_MASTER $BAMMAP | grep -v "^#" | sort -u >> $BMM
>&2 echo Success. Download BamMap written to $BAMMAP
>&2 echo Merged with BamMap $BAMMAP_MASTER
>&2 echo Written to $BMM
>&2 echo Please examine merged master file and replace original master as appropriate