-
Notifications
You must be signed in to change notification settings - Fork 1
/
doEverything.sh
executable file
·157 lines (126 loc) · 4.06 KB
/
doEverything.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
#! /bin/bash
# doEverything.sh
submit(){
qsub -cwd -V -S /bin/bash "$@"
}
set -e -o pipefail # quit when any section of any pipe, or single command, fails
if [ "$1" == "" ] || [ "$2" == "" ]; then
echo -e "Usage: $0 fileOfPeakDensityAndCounts.txt TSSfile.bed6" "[blacklistfile]"
echo -e "\tfileOfPeakDensityAndCounts.txt should contain one sample per line in the following format:"
echo -e "\tColumn 1: /path/to/peak/file"
echo -e "\tColumn 2: /path/to/density/file"
echo -e "\tColumn 3: Total mapped tags"
echo -e "\tBlacklist file is optional"
exit 1
fi
sampleFile=$1
tssFile=$2
if [ ! -f "$sampleFile" ]; then
echo -e "Unable to find file \"$sampleFile\"."
exit
fi
if [ ! -f "$tssFile" ]; then
echo -e "Unable to find file \"$tssFile\"."
exit
fi
#Check for optional blacklist file, set blacklist to /dev/null if not supplied
if [ ! -z "$3" ]; then
blacklist=$3
if [ ! -f "$blacklist" ]; then
echo -e "Unable to find file \"$blacklist\"."
exit
fi
else
blacklist=/dev/null
fi
#Get the number of samples
NUMFILES=$(cat $sampleFile | wc -l)
PID=$$
SAMPLE_NAMES=sampleNames_${PID}.txt
RAW_COUNTS=rawCounts_${PID}.txt
cut -f3 $sampleFile > $RAW_COUNTS
cat "$sampleFile" | while read peakPath restOfLine
do
basename "$peakPath" | cut -f1 -d '.' >> $SAMPLE_NAMES
done
paste $SAMPLE_NAMES $RAW_COUNTS > totalTagCountsPerSample.txt
rm -f $RAW_COUNTS $SAMPLE_NAMES
#qsub -cwd -N RunML -S run_master_list_simple__receiveInputFileOfFilenames.sh $peakfileNames
# Hmmm, need to check exit status....
PATH=$(dirname $0):$PATH
PATH=$(dirname $0)/bin:$PATH
if ! which bedops 2>&1 >/dev/null ; then
echo "Bedops must be installed and available on the PATH" >&2
exit 2
fi
SETUP_JOB=".setupdhs"
DENS_JOB=".densitydhs"
FINISH_JOB=".finishdhs"
submit -N "$SETUP_JOB" <<__SETUP__
set -x
date
run_master_list_simple__receiveInputFileOfFilenames.sh "$sampleFile" multi-tissue.master.bed "$blacklist"
date
__SETUP__
submit -hold_jid "$SETUP_JOB" -N "$DENS_JOB" <<__DENSITY__
set -x
date
getTagDensitiesInMasterListDHSs_pseudoParallel_receiveFileOfFilenames.sh $sampleFile $blacklist
date
__DENSITY__
submit -hold_jid "$DENS_JOB" -N "$FINISH_JOB" <<__FINISH__
set -x
date
makeMasterFileWithTagSumVectors.sh
date
getPromoterDHSs.sh \
$tssFile masterDHSsAndTagCounts.bed4 \
10000 2500 20 100 \
promOutfile.bed13
date
awk 'BEGIN{OFS="\t"}{if(\$13!="NA"){print \$5,\$6,\$7,\$4,".",\$8,\$1,\$2,\$3;}}' \
promOutfile.bed13 \
| tr '\t' '@' \
| sort -k 1b,1 \
| uniq \
| tr '@' '\t' \
| sort-bed - \
> promDHSsAndTheirTSSs.bed9
date
cut -f1-4 promDHSsAndTheirTSSs.bed9 \
| tr '\t' '@' \
| sort -k 1b,1 \
| uniq \
| tr '@' '\t' \
| sort-bed - \
> promDHSsWithGeneNames.bed4
date
bedmap --exact --delim "\t" --echo --echo-map-id \
promDHSsWithGeneNames.bed4 \
masterDHSsAndTagCounts.bed4 \
> promDHSsWithGeneNamesAndTagCounts.bed5
date
cut -f1-3 promDHSsWithGeneNamesAndTagCounts.bed5 \
| uniq \
| bedops -n -1 masterDHSsAndTagCounts.bed4 - \
> nonprom_temp.bed4
date
closest-features --shortest --dist nonprom_temp.bed4 \
promDHSsAndTheirTSSs.bed9 \
| awk -F "|" '{dist=\$3;if(dist<0){dist=-dist;}if(dist>=1000){print \$1;}}' \
> nonPromoterDHSsAndTheirTagCounts_eachAtLeast1kbFromPromDHS.bed4
date
bedmap --range 500000 --skip-unmapped --echo --echo-map \
promDHSsWithGeneNamesAndTagCounts.bed5 \
nonPromoterDHSsAndTheirTagCounts_eachAtLeast1kbFromPromDHS.bed4 \
> inputForCorrelationCalculations_500kb.bed
date
calcCorrelations.sh \
inputForCorrelationCalculations_500kb.bed \
0.7 \
corrs_promsFirst_all_celltypes_500kb.bed8 \
corrs_promsFirst_above0.7_celltypes_500kb.bed8 \
corrs_distalsFirst_all_celltypes_500kb.bed8 \
corrs_distalsFirst_above0.7_celltypes_500kb.bed8
date
__FINISH__