-
Notifications
You must be signed in to change notification settings - Fork 1
/
splicing2win
executable file
·188 lines (180 loc) · 6.37 KB
/
splicing2win
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
#!/bin/bash
#PBS -l nodes=1:ppn=4
GENOME="mm9"
WIN=50
#### usage ####
usage() {
echo Program: "splicing2win (determine flanking window to splicing sites)"
echo Author: BRIC, University of Copenhagen, Denmark
echo Version: 1.0
echo Contact: pundhir@binf.ku.dk
echo "Usage: splicing2win -i <file> [OPTIONS]"
echo "Options:"
echo " -i <file> [splicing results from spliceR (can be stdin)]"
echo "[OPTIONS]"
echo " -b [input file is in BED format (default: spliceR)]"
echo " -w <int> [widow size flanking each end of a splicing event (default: 50)]"
echo " -h [help]"
echo
exit 0
}
#### parse options ####
while getopts i:bw:g:h ARG; do
case "$ARG" in
i) INFILE=$OPTARG;;
b) BED=1;;
w) WIN=$OPTARG;;
g) GENOME=$OPTARG;;
h) HELP=1;;
esac
done
## usage, if necessary file and directories are given/exist
if [ -z "$INFILE" -o "$HELP" ]; then
usage
fi
## create temporary file if input is from stdin
if [ "$INFILE" == "stdin" ]; then
TMP=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
while read LINE; do
echo ${LINE}
done | perl -ane '$line=""; foreach(@F) { $line.="$_\t"; } $line=~s/\t$//g; print "$line\n";' > $TMP
INFILE=$TMP
fi
## retrieve name of input file
NAME=$(echo $INFILE | perl -ane '$_=~s/^.*\///g; print $_;')
## create BED file containing exact position of splicing based on their type and strand orientation
if [ -z "$BED" ]; then
grep -v spliceR $INFILE | perl -ane '
#@NAME=("ESI", "MEE", "MESI", "ISI", "A5", "A3");
## BUG in spliceR (switches between A5 and A3)
@NAME=("ESI", "MEE", "MESI", "ISI", "A3", "A5");
$k=0;
for($i=27; $i<=38; $i+=2) {
@start=split(/[\;\,]+/,$F[$i]);
@end=split(/[\;\,]+/,$F[$i+1]);
for($j=0; $j<scalar(@start); $j++) {
print "$F[3]\t$start[$j]\t$end[$j]\t$NAME[$k]\t$F[14]\t$F[39]\t$F[0]\n";
}
$k++;
}' | grep -wv NA
else
cat $INFILE
fi | perl -ane '
$WIN='$WIN';
#print "#$_";
if($F[5]=~/\-/) {
if($F[3]=~/ESI/ || $F[3]=~/exon/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tESI_5p\t$F[4]\t$F[5]\t$F[6]\n";
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tESI_3p\t$F[4]\t$F[5]\t$F[6]\n";
$mid=sprintf("%0.0f", ($F[1]+$F[2])/2);
$start=$mid-$WIN;
$end=$mid+$WIN;
print "$F[0]\t$start\t$end\tESI_mid\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/MEE/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tMEE_5p\t$F[4]\t$F[5]\t$F[6]\n";
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tMEE_3p\t$F[4]\t$F[5]\t$F[6]\n";
$mid=sprintf("%0.0f", ($F[1]+$F[2])/2);
$start=$mid-$WIN;
$end=$mid+$WIN;
print "$F[0]\t$start\t$end\tMEE_mid\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/MESI/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tMESI_5p\t$F[4]\t$F[5]\t$F[6]\n";
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tMESI_3p\t$F[4]\t$F[5]\t$F[6]\n";
$mid=sprintf("%0.0f", ($F[1]+$F[2])/2);
$start=$mid-$WIN;
$end=$mid+$WIN;
print "$F[0]\t$start\t$end\tMESI_mid\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/ISI/ || $F[3]=~/intron/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tISI_5p\t$F[4]\t$F[5]\t$F[6]\n";
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tISI_3p\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/A5/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tA5\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/A3/) {
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tA3\t$F[4]\t$F[5]\t$F[6]\n";
}
}
else {
if($F[3]=~/ESI/ || $F[3]=~/exon/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tESI_3p\t$F[4]\t$F[5]\t$F[6]\n";
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tESI_5p\t$F[4]\t$F[5]\t$F[6]\n";
$mid=sprintf("%0.0f", ($F[1]+$F[2])/2);
$start=$mid-$WIN;
$end=$mid+$WIN;
print "$F[0]\t$start\t$end\tESI_mid\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/MEE/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tMEE_3p\t$F[4]\t$F[5]\t$F[6]\n";
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tMEE_5p\t$F[4]\t$F[5]\t$F[6]\n";
$mid=sprintf("%0.0f", ($F[1]+$F[2])/2);
$start=$mid-$WIN;
$end=$mid+$WIN;
print "$F[0]\t$start\t$end\tMEE_mid\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/MESI/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tMESI_3p\t$F[4]\t$F[5]\t$F[6]\n";
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tMESI_5p\t$F[4]\t$F[5]\t$F[6]\n";
$mid=sprintf("%0.0f", ($F[1]+$F[2])/2);
$start=$mid-$WIN;
$end=$mid+$WIN;
print "$F[0]\t$start\t$end\tMESI_mid\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/ISI/ || $F[3]=~/intron/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tISI_3p\t$F[4]\t$F[5]\t$F[6]\n";
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tISI_5p\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/A5/) {
$start=$F[1]-$WIN;
$end=$F[1]+$WIN;
print "$F[0]\t$start\t$end\tA5\t$F[4]\t$F[5]\t$F[6]\n";
}
elsif($F[3]=~/A3/) {
$start=$F[2]-$WIN;
$end=$F[2]+$WIN;
print "$F[0]\t$start\t$end\tA3\t$F[4]\t$F[5]\t$F[6]\n";
}
}' | perl -ane '$line=""; foreach(@F) { $line.="$_\t"; } $line=~s/\t$//g; print "$line\n";'
## remove temporary file
if [ ! -z "$TMP" ]; then
rm $TMP
fi