[Solved] Converting the data into matrix with 0's and 1's

I have a file that contains 2 columns tag,pos
cat input_file

tag	pos
atg	10
ata	16
agt	15
agg	19
atg	17
agg	14

I have used following command to sort the file based on second column

sort -k 2 input_file
tag	pos 
atg	10
agg	14
agt	15
ata	16	
agg	19
atg	17

i want to convert it into a matrix as below with 5 as an interval and #1 and #0 representing the presence or absence of that tag within that interval

output_file

	atg	agg	agt	ata
10-15	1	1	1	0
15-20	1	1	0	1

The first row in the output matrix is 10-15 because in the sorted file it starts from 10

First extract a unique sorted master list of tags, using both files.

then, pass both file through a transform so values between 10 and 14 (15 must be a typo?, ranges are 5 and 6 wide?) are converted to "10-14", etc., sort them all by range and tag, run through uniq -c, and now you have your counts in "ct tag range" form and range, tag order. Using the master list of tags, build the lines for each range present in tag order. If you know all the tags and ranges ahead of time, you can also use associative vectors keyed on "tag+range" to accumulate values and then spit out the totals without sorting, using awk, bash, ksh.

Thank you for your suggestions i got it working