Skip to content

Instantly share code, notes, and snippets.

@IdoBar
Forked from tbrittoborges/prepared_gtf_to_igv.sh
Created September 26, 2024 04:27
Show Gist options
  • Save IdoBar/565ba822982c8562721e488bbb7fc7a6 to your computer and use it in GitHub Desktop.
Save IdoBar/565ba822982c8562721e488bbb7fc7a6 to your computer and use it in GitHub Desktop.
Sort and index gtf file for vizualization. Requires htslib.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $0 <input_gtf_file>"
exit 1
fi
input_gtf="$1"
output_prefix="output"
sorted_gtf="${output_prefix}.sorted.gtf"
sorted_gtf_gz="${sorted_gtf}.gz"
module load htslib
# Sort the input GTF file
sort -k1,1 -k4,4n -s "$input_gtf" > "$sorted_gtf"
# Compress the sorted GTF file
bgzip -c "$sorted_gtf" > "$sorted_gtf_gz"
# Index the compressed GTF file
tabix "$sorted_gtf_gz"
# Remove intermediate files
rm "$sorted_gtf"
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment