Advertisement
Guest User

hg38.awk

a guest
Apr 6th, 2020
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.71 KB | None | 0 0
  1. #!/usr/bin/awk -f
  2.  
  3. NR == FNR && FNR == 1 {
  4.     headers = $0
  5.     empty_row = ""
  6.     for (i = 0; i < NF; i++) {
  7.         empty_row = "\t-" empty_row
  8.     }
  9.     next
  10. }
  11.  
  12. # In file2 where we found hg38
  13. # We transform "hg38:Chr11:8823729," to "chr11:8823729"
  14. # And use that as a key in the array `found`
  15. NR == FNR && $4 ~ /^hg38:/ {
  16.     extra = $4
  17.     sub(/hg38:/, "", extra)
  18.     sub(/Chr/, "chr", extra)
  19.     sub(/,$/, "", extra)
  20.     found[extra] = $0
  21. }
  22.  
  23. # First line of file1
  24. # Print the existing headers and an additional column
  25. NR != FNR && FNR == 1 {
  26.     print $0 "\t" headers
  27.     next
  28. }
  29.  
  30. # Subsequent lines of file1
  31. NR != FNR {
  32.     printf $0
  33.     key = $1 ":" $2
  34.     if (key in found) {
  35.         print "\t" found[key]
  36.     } else {
  37.         print empty_row
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement