Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Short bash script to convert STAR into BED format similar to TopHat junctions.bed
##run from results directory
##Output BED file is sorted for indexing and loading into IGV
##awk for converting to bed12 format
##based on code originally published by frymor at
for sj in */*
echo ${sj}
echo "Converting..."
awk \
{'if($4=="2") print ""$1"\t"$2-$9-1"\t"$3+$9"\tJUNC000"NR"\t"$8"\t-\t"$2-$9-1"\t"$3+$9"\t255,0,0\t2\t"$9","$9"\t","0,"$3-$2+$9+1; \
else \
if($4=="1") print ""$1"\t"$2-$9-1"\t"$3+$9"\tJUNC000"NR"\t"$8"\t+\t"$2-$9-1"\t"$3+$9"\t0,0,255\t2\t"$9","$9"\t","0,"$3-$2+$9+1'} \
${sj} > ${sj%.*}.bed12
echo "Sorting..."
sort -V -o ${sj%.*}.sort.bed ${sj%.*}.bed12
echo "Complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment