Sort chr bp file

= Sort chr_bp file = Example input file (first column format is required): chr_bp	Mapping	strand	case-w/var	case-wo/var	freq-cases chr1_2340200	PEX10	-	95	4	0.940594 chr1_2444414	PANK4	-	69	1	0.663462 chr1_7723957	CAMTA1	+	74	1	0.711538 chr1_9009406	CA6	+	63	1	0.605769 chr1_9009444	CA6	+	77	0	0.733333 chr1_9324670	H6PD	+	66	4	0.653465 chr1_10473196	PGD	+	53	0	0.504762 chr1_12339619	VPS13D	+	52	0	0.495238

myfile=$1  # replace $1 with your filename. e.g. "datafile.txt"

cut -f 1 $myfile > f1_${myfile} cat f1_${myfile} > tmp1_${myfile} perl -0777 -i -pe "s/chr//g" tmp1_${myfile} perl -0777 -i -pe "s/_/\t/g" tmp1_${myfile} perl -0777 -i -pe "s/X/23/g" tmp1_${myfile} perl -0777 -i -pe "s/Y/24/g" tmp1_${myfile} paste f1_${myfile} tmp1_${myfile}  $myfile > tmp2_${myfile} cut -f -3,5- tmp2_${myfile} > tmp3_${myfile} cat tmp3_${myfile} | sort -k 2 -n -k 3 -n > $myfile.sorted.txt cut -f -3 $myfile.sorted.txt > tmp4_${myfile} perl -0777 -i -pe "s/\t23\t/\tX\t/g" tmp4_${myfile} perl -0777 -i -pe "s/\t24\t/\tY\t/g" tmp4_${myfile} cut -f 4- $myfile.sorted.txt > tmp5_${myfile} paste tmp4_${myfile}  tmp5_${myfile}   > $myfile.sorted.txt rm -f tmp* rm -f f1_${myfile}