Guest User

Untitled

a guest
Nov 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. SNP Id Geno
  2. 1 a AB
  3. 2 a AB
  4. 3 a BB
  5. . . .
  6. . . .
  7. . . .
  8. 1 b AB
  9. 2 b BB
  10. 3 b AB
  11. . . .
  12. . . .
  13. . . .
  14. 1 c AA
  15. 2 c AB
  16. 3 c AA
  17. . . .
  18. . . .
  19. . . .
  20.  
  21. SNP Genoa Genob Genoc . . .
  22. 1 AB AB AA
  23. 2 AB BB AB
  24. 3 BB AB AA
  25. . . . .
  26. . . . .
  27. . . . .
  28.  
  29. sed 'G;s/^SNP.*/SNP/
  30. /^1 /s/ ([^ ]*) .*SNP[^[:cntrl:]]*/& Geno1/
  31. s/^([0-9]*) [^ ]*( [AB]*)n(.*n1 [AB ]*)/32/
  32. s/^([0-9]*) [^ ]*( [AB]*)(n)(.*)/4312/
  33. h
  34. $!d' file1 > file2
  35.  
  36. awk '{if ($1==1) h=h" Geno"$2
  37. if ($1!="SNP") g[$1]=g[$1]" "$3}
  38. END {print "SNP"h; for (i in g) print i g[i]}' file1 > file2
  39.  
  40. awk '{g[$1] = g[$1] " " $3}
  41. END {for (i in g) print i g[i]}' < file1 > file2
  42.  
  43. awk '! ($1 in g) {snp[n++] = $1}
  44. {g[$1] = g[$1] " " $3}
  45. END {for (i = 0; i < n; i++) print snp[i] g[snp[i]]}' < file1 > file2
  46.  
  47. awk 'NR == 1 {header = $1; prefix = $3; next}
  48. first == "" {first = "" $1}
  49. $1 == first {header = header " " prefix $2}
  50. ! ($1 in g) {snp[n++] = $1}
  51. {g[$1] = g[$1] " " $3}
  52. END {
  53. print header
  54. for (i = 0; i < n; i++) print snp[i] g[snp[i]]
  55. }' < file1 > file2
  56.  
  57. perl -lane '
  58. next if $. == 1; # skip header
  59. $A[@A] = $F[1] if /^1h/; # populate new header
  60. push @{$h{$F[0]}}, $F[2]}{$,="t"; # OFS = tab
  61. print q/SNP/, map { "Geno$_" } @A; # new header print
  62. print $_, @{$h{$_}} for sort { $a <=> $b } keys %h; # result
  63. ' gene.data
  64.  
  65. sed -e '
  66. 1d; # monospace lines
  67. s/[[:blank:]]{1,}/t/g;s/^[[:blank:]]*//;s/[[:blank:]]*$//
  68. H;g
  69. # 1 2 3 4
  70. s/(n(.*n){0,1})1[[:blank:]]([^[:space:]]{1,})([[:blank:]][^[:space:]]{1,})$/tGeno31n14/
  71. /(n[^[:space:]]{1,}[[:blank:]])[^[:space:]]{1,}[[:blank:]]([^[:space:]]{1,})$/s//12/
  72. y/n_/_n/
  73. s/_([0-9]{1,})([^_]*)_(.*_){0,1}1([[:blank:]][^_]*)/_124_3/
  74. y/n_/_n/
  75. h;$!d
  76. s/n*$//
  77. s/n(n)/1/
  78. s/^[[:blank:]]/SNP&/
  79. ' gene.data
  80.  
  81. SNP Genoa Genob Genoc
  82. 1 AB AB AA
  83. 2 AB BB AB
  84. 3 BB AB AA
Add Comment
Please, Sign In to add comment