I have a file with sample data like this:
1 90042011 90042031 AGTGCCACCAGGTGGGGCCG 90042017 2 5008 T:5006 C:2 90184334 90184354 GAGGCCACAAGAGGGCACAA 90184337 2 5008 C:5007 T:1 ß@ 5
1 90042011 90042031 AGTGCCACCAGGTGGGGCCG 90042017 2 5008 T:5006 C:2 90184334 90184354 GAGGCCACAAGAGGGCACAA 90184336 2 5008 A:5007 G:1 ßß 2
1 90042011 90042031 AGTGCCACCAGGTGGGGCCG 90042030 2 5008 C:5007 A:1 90184334 90184354 GAGGCCACAAGAGGGCACAA 90184337 2 5008 C:5007 T:1 @@ 1
1 90042011 90042031 AGTGCCACCAGGTGGGGCCG 90042030 2 5008 C:5007 A:1 90184334 90184354 GAGGCCACAAGAGGGCACAA 90184336 2 5008 A:5007 G:1 @ß 3
1 90042011 90042031 AGTGCCACCAGGTGGGGCCG 90042029 2 5008 G:5006 T:2 90184334 90184354 GAGGCCACAAGAGGGCACAA 90184337 2 5008 C:5007 T:1 @@ 1
1 90042011 90042031 AGTGCCACCAGGTGGGGCCG 90042029 2 5008 G:5006 T:2 90184334 90184354 GAGGCCACAAGAGGGCACAA 90184336 2 5008 A:5007 G:1 @ß 3
1 94853396 94853416 GCCGCCACTAGATGGTGCTA 94853398 2 5008 T:5007 C:1 94969254 94969274 CAGTCCTCTAGAGGGAGCCC 94969266 2 5008 G:5006 A:2 ß@ 5
2 103584283 103584303 TGGGCCACTAGGAGGCACTG 103584300 2 5008 C:5006 T:2 103841436 103841456 CATGCCACAAGAGGGCATCA 103841456 2 5008 A:5006 G:2 @ß 3
2 103584283 103584303 TGGGCCACTAGGAGGCACTG 103584300 2 5008 C:5006 T:2 103841436 103841456 CATGCCACAAGAGGGCATCA 103841445 2 5008 C:5006 T:2 @@ 1
2 103584283 103584303 TGGGCCACTAGGAGGCACTG 103584284 2 5008 A:5007 G:1 103841436 103841456 CATGCCACAAGAGGGCATCA 103841456 2 5008 A:5006 G:2 ßß 2
2 103584283 103584303 TGGGCCACTAGGAGGCACTG 103584284 2 5008 A:5007 G:1 103841436 103841456 CATGCCACAAGAGGGCATCA 103841445 2 5008 C:5006 T:2 ß@ 5
As seen, some lines have repeating values for $2
and $3
, line 1-6 and line 8-11 in this case.
$20
of my file contains codes of two characters representing each line, in the format "@@","ßß", "@ß","@N","ß@","ßN","N@","Nß" or "NN". Each line can have one of these 9 possible codes.
I want to write a script, which splits the characters of $20
(@,ß or N) of the lines which are repeated (1-6 & 8-11 here), and reduces them into one line in the following manner:
Count the number of @, ß or N in the first and second positions respectively of the repeated lines. For the first and second characters of each repeated line, if:
- @ occurs most, print @
- ß occurs most, print ß
- N occurs most, print N
- @ occurs equal to ß, print N
- @ occurs equal to N, print @
- ß occurs equal to N, print ß
In this sample dataset with repeated lines, the output file generated should be something like this, only columns $1
, $2
, $3
, $4
, $11
,$12
,$13
, and a new column with the new "@","ß","N" codes after said counting is reported:
1 90042011 90042031 AGTGCCACCAGGTGGGGCCG 90184334 90184354 GAGGCCACAAGAGGGCACAA @N
1 94853396 94853416 GCCGCCACTAGATGGTGCTA 94969254 94969274 CAGTCCTCTAGAGGGAGCCC ß@
2 103584283 103584303 TGGGCCACTAGGAGGCACTG 103841436 103841456 CATGCCACAAGAGGGCATCA NN
In the first repeated case(1-6), for the first character @ occurs four times and ß occurs twice and for the second character @ and ß occur equal number of times, so the final code is @N. In the second repeated case(8-11), @ and ß for both character positions occur equally, so the final code is NN.