Column matching and group setting in tab demited file

Please help me with commands for the following file operations

File description
5 columns in total , sorted by column 1 value

First formatting,

1) Records with duplicate column 1 values are to be ignored. Just consider the first occurrence of such a record.
2) Records with (column 2 - column 3) > 0 are to be ignored during calculation.
3) Records with blank column 5 are to be ignored.

column 4 has three formats ending in 10 or 01.

1> it starts with '-', number of '-' will equal number of characters before 10/01, if so extract sub-string without the 10/01 and also trim the last character.
eg. for ----RTYY10, extract RTY. Assign r=blank,a=RTY ,,,if 10, grp1=a grp2=r...if 01, grp1=r grp2=a.

2> it ends in '-' , if so extract sub-string before '-'
eg for RETY-01, extract RETY. set r=RETY,,a=blank if 10, if 10, grp1=a grp2=r...if 01, grp1=r grp2=a.

3> 4 characters in total without '-' ending in 10/01. if so, extract the first 2 characters.
eg. for RY10 extract RY....Assign r= R, a=Y...if 10, grp1=a grp2=r...if 01, grp1=r grp2=a.

For each record (line) in the file, compare column 5 with grp1 and grp2. If it matches either grp1 or grp2, print grp1 or grp2 in a new column for that record.
When grp1 or grp2 is blank, and the value of column 5 does not match either of them, then assign the record to to grp1 or grp2 whichever is blank. If both grp1 and grp2 have values other than blank, and if column 5 does not match with either of them, then that record needs to be ignored.

I have attached sample input and output. Help please !!

adding data

homework?

No. Its a file I`m analysing.