Skip to content

Instantly share code, notes, and snippets.

@mfansler
Last active December 19, 2023 15:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mfansler/b82d5e00f8399bfbf6809e037f8647d6 to your computer and use it in GitHub Desktop.
Save mfansler/b82d5e00f8399bfbf6809e037f8647d6 to your computer and use it in GitHub Desktop.
GTF file compressed indexing for IGV compatibility
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo -e "Incorrect number of parameters! Usage:\n index-gtf.sh <file.gtf(.gz)>" >&2
exit 1
fi
gtf="$1"
if [[ $gtf =~ \.gz$ ]]; then
output=${gtf%.gtf.gz}.sorted.gtf.gz
zcat $gtf | awk '!( $0 ~ /^#/ )' | sort --parallel=4 -S4G -k1,1 -k4,4n | bgzip -c > $output
else
output=${gtf%.gtf}.sorted.gtf.gz
cat $gtf | awk '!( $0 ~ /^#/ )' | sort --parallel=4 -S4G -k1,1 -k4,4n | bgzip -c > $output
fi
tabix $output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment