|
0
|
1 #!/bin/bash
|
|
|
2
|
|
6
|
3 # featurecounts2bed - converts featureCounts output to BED format
|
|
|
4
|
|
|
5 # Copyright 2013-2014, Youri Hoogstrate
|
|
|
6
|
|
|
7 # This program is free software: you can redistribute it and/or modify
|
|
|
8 # it under the terms of the GNU General Public License as published by
|
|
|
9 # the Free Software Foundation, either version 3 of the License, or
|
|
|
10 # (at your option) any later version.
|
|
|
11
|
|
|
12 # This program is distributed in the hope that it will be useful,
|
|
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
15 # GNU General Public License at <http://www.gnu.org/licenses/> for
|
|
|
16 # more details.
|
|
|
17
|
|
0
|
18 # This tool has been written by Youri Hoogstrate from the Erasmus
|
|
|
19 # Medical Center (Rotterdam, Netherlands) on behalf of the Translational
|
|
|
20 # Research IT (TraIT) project:
|
|
|
21 # http://www.ctmm.nl/en/programmas/infrastructuren/traitprojecttranslationeleresearch
|
|
|
22
|
|
6
|
23
|
|
0
|
24 exon_level="true"
|
|
|
25 filename=""
|
|
|
26
|
|
|
27 # Parse parameters
|
|
|
28 while getopts e:f: option
|
|
|
29 do
|
|
|
30 case "${option}"
|
|
|
31 in
|
|
|
32 e) exon_level=${OPTARG};;
|
|
|
33 f) filename=$OPTARG;;
|
|
|
34 esac
|
|
|
35 done
|
|
|
36
|
|
|
37 # Convert the file
|
|
|
38 if [ $filename == "" ]; then
|
|
|
39 echo "Usage:"
|
|
|
40 echo " -e [true, false] true = entry for every exon; false = line for genes first exon"
|
|
|
41 echo " -f FILENAME from featureCounts"
|
|
|
42 else
|
|
|
43 while read line; do
|
|
|
44 first=${line:0:1}
|
|
|
45 if [ $first != "#" ]; then
|
|
|
46 columns=($line)
|
|
|
47 uid=${columns[@]:0:1}
|
|
|
48 if [ $uid != "Geneid" ]; then
|
|
|
49 chr=${columns[@]:1:1}
|
|
|
50 start=${columns[@]:2:1}
|
|
|
51 stop=${columns[@]:3:1}
|
|
|
52 direction=${columns[@]:4:1}
|
|
|
53 length=${columns[@]:5:1}
|
|
|
54 count=${columns[@]:6:1}
|
|
|
55
|
|
|
56 chr_splitted=($(echo $chr | tr ";" "\n"))
|
|
|
57 start_splitted=($(echo $start | tr ";" "\n"))
|
|
|
58 stop_splitted=($(echo $stop | tr ";" "\n"))
|
|
|
59 strand_splitted=($(echo $direction | tr ";" "\n"))
|
|
|
60
|
|
|
61 if [ $exon_level == "true" ]; then
|
|
|
62 n=${#chr_splitted[@]}
|
|
|
63 else
|
|
|
64 n=1
|
|
|
65 fi
|
|
|
66
|
|
|
67 for (( i=0; i<$n; i++ ))
|
|
|
68 do
|
|
|
69 echo ${chr_splitted[@]:$i:1}" "${start_splitted[@]:$i:1}" "${stop_splitted[@]:$i:1}" "$uid" ("$((${stop_splitted[@]:$i:1}-${start_splitted[@]:$i:1}))"/"$length"nt) "$count" "${strand_splitted[@]:$i:1}
|
|
|
70 done
|
|
|
71 fi
|
|
|
72 fi
|
|
|
73 done < $filename
|
|
|
74 fi
|