Skip to content

Instantly share code, notes, and snippets.

@Tabea-K
Created June 9, 2016 09:16
Show Gist options
  • Select an option

  • Save Tabea-K/813b436784548af1cea44590c236f8de to your computer and use it in GitHub Desktop.

Select an option

Save Tabea-K/813b436784548af1cea44590c236f8de to your computer and use it in GitHub Desktop.
Sorts a BED file karyotypically. After sorting, it checks if the input and output files have the same content.
#!/usr/bin/env bash
#
# Sorts a BED file karyotypically
# File created by Tabea Kischka at Thu Jun 9 11:15:44 CEST 2016
INFILE="$1"
OUTFILE="$2"
cat "$INFILE" | sed 's/chrM/chr0/' | sort -k1,1V -k2,2n -k3,3n | sed 's/chr0/chrM/' > "$OUTFILE"
echo "Done with sorting."
echo "Now checking if both files are still the same."
INFILEMD5=$(sort "$INFILE" | md5)
OUTFILEMD5=$(sort "$OUTFILE" | md5)
if [ "$INFILEMD5" = "$OUTFILEMD5" ]
then
echo "Sorting went fine!"
else
echo "Sorting failed!"
mv "$OUTFILE" "${OUTFILE}.failed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment