Skip to content

Instantly share code, notes, and snippets.

@fabiolib
Last active October 7, 2022 02:52
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fabiolib/ffb21853e3eb3780150074aeffc54901 to your computer and use it in GitHub Desktop.
Save fabiolib/ffb21853e3eb3780150074aeffc54901 to your computer and use it in GitHub Desktop.
Short bash script to convert STAR SJ.out.tab into BED format similar to TopHat junctions.bed
#!/bin/bash
##run from results directory
##Output BED file is sorted for indexing and loading into IGV
##awk for converting SJ.out.tab to bed12 format
##based on code originally published by frymor at http://seqanswers.com/forums/showthread.php?t=62896
for sj in */*SJ.out.tab
do
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
done
echo "Complete"
@Jokendo-collab
Copy link

Hi, did this script work for you?

@fabiolib
Copy link
Author

For my purposes at least, yes. I was using the generated bed file as an input to the dSpliceType tool or to load into IGV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment