| 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 # | 
|  | 23 # More tools by the Translational Research IT (TraIT) project can be | 
|  | 24 # found in the following repository: | 
|  | 25 # http://toolshed.dtls.nl/ | 
|  | 26 | 
| 6 | 27 | 
| 0 | 28 exon_level="true" | 
|  | 29 filename="" | 
|  | 30 | 
|  | 31 # Parse parameters | 
|  | 32 while getopts e:f: option | 
|  | 33 do | 
|  | 34 	case "${option}" | 
|  | 35 	in | 
|  | 36 		e) exon_level=${OPTARG};; | 
|  | 37 		f) filename=$OPTARG;; | 
|  | 38 	esac | 
|  | 39 done | 
|  | 40 | 
|  | 41 # Convert the file | 
|  | 42 if [ $filename == "" ]; then | 
|  | 43 	echo "Usage:" | 
|  | 44 	echo "  -e [true, false]   true = entry for every exon; false = line for genes first exon" | 
|  | 45 	echo "  -f                 FILENAME from featureCounts" | 
|  | 46 else | 
|  | 47 	while read line; do | 
|  | 48 		first=${line:0:1} | 
|  | 49 		if [ $first != "#" ]; then | 
|  | 50 			columns=($line) | 
|  | 51 			uid=${columns[@]:0:1} | 
|  | 52 			if [ $uid != "Geneid" ]; then | 
|  | 53 				chr=${columns[@]:1:1} | 
|  | 54 				start=${columns[@]:2:1} | 
|  | 55 				stop=${columns[@]:3:1} | 
|  | 56 				direction=${columns[@]:4:1} | 
|  | 57 				length=${columns[@]:5:1} | 
|  | 58 				count=${columns[@]:6:1} | 
|  | 59 | 
|  | 60 				chr_splitted=($(echo $chr | tr ";" "\n")) | 
|  | 61 				start_splitted=($(echo $start | tr ";" "\n")) | 
|  | 62 				stop_splitted=($(echo $stop | tr ";" "\n")) | 
|  | 63 				strand_splitted=($(echo $direction | tr ";" "\n")) | 
|  | 64 | 
|  | 65 				if [ $exon_level == "true" ]; then | 
|  | 66 					n=${#chr_splitted[@]} | 
|  | 67 				else | 
|  | 68 					n=1 | 
|  | 69 				fi | 
|  | 70 | 
|  | 71 				for (( i=0; i<$n; i++ )) | 
|  | 72 				do | 
|  | 73 					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} | 
|  | 74 				done | 
|  | 75 			fi | 
|  | 76 		fi | 
|  | 77 	done < $filename | 
|  | 78 fi |