0

I have a *.pdb file, which looks like this :-

  CRYST1   78.428   78.428   78.428  90.00  90.00  90.00 P 1           1
  ATOM      1  CI1 JPIPP   1      41.874  78.965  24.633  1.00  0.00      PI   C
  ATOM      2  CI2 JPIPP   1      41.978  79.560  26.065  1.00  0.00      PI   C
  ATOM      3  CI3 JPIPP   1      40.811  80.549  26.148  1.00  0.00      PI   C
  ATOM      4  CI4 JPIPP   1      39.498  79.850  25.983  1.00  0.00      PI   C
  ATOM      5  O4P JPIPP   1      38.376  80.788  26.069  1.00  0.00      PI   O
  ATOM      6  P4  JPIPP   1      37.130  80.601  27.002  1.00  0.00      PI   P
  ATOM      7  O41 JPIPP   1      37.214  81.710  27.969  1.00  0.00      PI   O
  ATOM      8  O42 JPIPP   1      35.998  80.809  26.128  1.00  0.00      PI   O
  ATOM      9  O43 JPIPP   1      37.088  79.268  27.654  1.00  0.00      PI   O
  ATOM     37  HT3 ILE P  10      13.930  68.062  46.163  1.00  0.00      P1
  ATOM     38  CA  ILE P  10      15.421  69.513  46.954  1.00  0.00      P1   C
  ATOM     39  HA  ILE P  10      14.944  69.690  47.906  1.00  0.00      P1   H
  ATOM     40  CB  ILE P  10      16.432  68.520  47.458  1.00  0.00      P1   C

I intend to change the value of 10th column to "1" if my 3rd column P4 or CA. I tried this to achieve this task using awk and failed. Awk doesn't allow me retain the format.

I found an answer which suggested the usage "gawk" and successfully retains the format. I tried to change the solution but sadly it dint work. Please help to sort out this issue.

  gawk '
   # NR==FNR { pdb[NR]=$0; next }
    {
    split(pdb[FNR],flds,FS,seps)

    if ( flds[3] == "CA" || flds[3] == "P4" 
    flds[10]=1

    for (i=1;i in flds;i++)
    printf "%s%s", flds[i], seps[i]
    print ""
    }
    ' NVT20ns.pdb > test.pdb
2
  • you have missing values (row with HT3) and last four rows seems to have 4th column values with space ILE P... your full input files might have other such inconsistencies..
    – Sundeep
    Sep 12, 2016 at 15:52
  • @spasic Yes, I agree there are missing values, also IL3 <space> P is consistent with rest of PDB file. I have tried to present a general form here. So, Is it impossible ?
    – Grayrigel
    Sep 12, 2016 at 16:01

1 Answer 1

0
$ perl -pe 's/ILE P/ILEP/; s/^(\s*(\S+\s+){9})\S+/${1}1/ if /^(\s*(\S+\s+){2})(P4|CA)/; s/ILEP/ILE P/' ip.txt 
  CRYST1   78.428   78.428   78.428  90.00  90.00  90.00 P 1           1
  ATOM      1  CI1 JPIPP   1      41.874  78.965  24.633  1.00  0.00      PI   C
  ATOM      2  CI2 JPIPP   1      41.978  79.560  26.065  1.00  0.00      PI   C
  ATOM      3  CI3 JPIPP   1      40.811  80.549  26.148  1.00  0.00      PI   C
  ATOM      4  CI4 JPIPP   1      39.498  79.850  25.983  1.00  0.00      PI   C
  ATOM      5  O4P JPIPP   1      38.376  80.788  26.069  1.00  0.00      PI   O
  ATOM      6  P4  JPIPP   1      37.130  80.601  27.002  1.00  1      PI   P
  ATOM      7  O41 JPIPP   1      37.214  81.710  27.969  1.00  0.00      PI   O
  ATOM      8  O42 JPIPP   1      35.998  80.809  26.128  1.00  0.00      PI   O
  ATOM      9  O43 JPIPP   1      37.088  79.268  27.654  1.00  0.00      PI   O
  ATOM     37  HT3 ILE P  10      13.930  68.062  46.163  1.00  0.00      P1
  ATOM     38  CA  ILE P  10      15.421  69.513  46.954  1.00  1      P1   C
  ATOM     39  HA  ILE P  10      14.944  69.690  47.906  1.00  0.00      P1   H
  ATOM     40  CB  ILE P  10      16.432  68.520  47.458  1.00  0.00      P1   C
  • has pre-process and post-process to deal with ILE P in 4th column
  • s/^(\s*(\S+\s+){9})\S+/${1}1/ will change 10th column value to 1
  • /^(\s*(\S+\s+){2})(P4|CA)/ will match P4 or CA in 3rd column
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .