comparison featurecounts2bed.sh @ 0:cada2d2f0a7c draft

Uploaded
author yhoogstrate
date Wed, 26 Mar 2014 09:12:30 -0400
parents
children fae19d64e9de
comparison
equal deleted inserted replaced
-1:000000000000 0:cada2d2f0a7c
1 #!/bin/bash
2
3 # This tool has been written by Youri Hoogstrate from the Erasmus
4 # Medical Center (Rotterdam, Netherlands) on behalf of the Translational
5 # Research IT (TraIT) project:
6 # http://www.ctmm.nl/en/programmas/infrastructuren/traitprojecttranslationeleresearch
7 #
8 # More tools by the Translational Research IT (TraIT) project can be
9 # found in the following repository:
10 # http://toolshed.dtls.nl/
11
12 exon_level="true"
13 filename=""
14
15 # Parse parameters
16 while getopts e:f: option
17 do
18 case "${option}"
19 in
20 e) exon_level=${OPTARG};;
21 f) filename=$OPTARG;;
22 esac
23 done
24
25 # Convert the file
26 if [ $filename == "" ]; then
27 echo "Usage:"
28 echo " -e [true, false] true = entry for every exon; false = line for genes first exon"
29 echo " -f FILENAME from featureCounts"
30 else
31 while read line; do
32 first=${line:0:1}
33 if [ $first != "#" ]; then
34 columns=($line)
35 uid=${columns[@]:0:1}
36 if [ $uid != "Geneid" ]; then
37 chr=${columns[@]:1:1}
38 start=${columns[@]:2:1}
39 stop=${columns[@]:3:1}
40 direction=${columns[@]:4:1}
41 length=${columns[@]:5:1}
42 count=${columns[@]:6:1}
43
44 chr_splitted=($(echo $chr | tr ";" "\n"))
45 start_splitted=($(echo $start | tr ";" "\n"))
46 stop_splitted=($(echo $stop | tr ";" "\n"))
47 strand_splitted=($(echo $direction | tr ";" "\n"))
48
49 if [ $exon_level == "true" ]; then
50 n=${#chr_splitted[@]}
51 else
52 n=1
53 fi
54
55 for (( i=0; i<$n; i++ ))
56 do
57 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}
58 done
59 fi
60 fi
61 done < $filename
62 fi