• Tidak ada hasil yang ditemukan

PDF Chulalongkorn University awk run awk

N/A
N/A
Protected

Academic year: 2024

Membagikan "PDF Chulalongkorn University awk run awk"

Copied!
15
0
0

Teks penuh

(1)

1 1

1

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

Topics (2

nd

week )

-การเขียนโปรแกรมภาษา UNIX เบื้องตนสําหรับการอานอินพุท และเขียนเอาทพุทจากขอมูล PDB

-เขียนโปรแกรมแปลงขอมูลทางโครงสรางจากรูปแบบอื่นๆ ใหอยู

ในรูป PDB format

-การเขียนโปรแกรมวิเคราะหทางโครงสรางโมเลกุลจากระบบพิกัด ของอะตอม

- ปฏิบัติการ 2

2 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

โปรแกรมภาษา awk เบื้องตน

- เปนโปรแกรมภาษาชนิดหนึ่งที่ทํางานภายใตระบบ unix - ผูใชสามารถกําหนด variables, numeric functions, string functions, and logical operators

- run โดยไมตอง compile

- รับอินพุทได 2 แบบคือเปน text file หรือ program instruction คําสั่ง run โปรแกรมภาษา awk

> awk ‘cmds’ file

> awk -f prog inputf

(2)

2 2

3

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

คําสั่งและความหมายของภาษา awk ที่สําคัญ

คําสั่ง ความหมาย

$1 $2 $3 ลําดับที่ 1 2 3 ของfields หรือ column ในไฟลอินพุท {….} ภายใน { } ประกอบดวย คําสั่ง เชน print, x = 4 เปนตน (….) ภายฝน ( ) รับคําสั่งแบบมีเงื่อนไขหรือรูปแบบ เชน if-then

..else , while เปนตน {print ..} คําสั่งพิมพ

{printf (…)} คําสั่งพิมพที่กําหนดรูปแบบ NF นับจํานวน fields ในแตละบรรทัด

NR นับจํานวนบรรทัด

BEGIN {…} ทํางานใน {…} กอนอานไฟลอินพุท END {….} ทํางานใน {…} หลังอานไฟลอินพุท

# comment line, ไมไดสั่งทําอะไรในบรรทัดนี้

4 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

Operator ความหมาย

+ , - , * , / บวก ลบ คูณ หาร

< นอยกวา

<= นอยกวาหรือเทากับ

== เทากับ

!= ไมเทากับ

>= มากกวาหรือเทากับ

> มากกวา

~ เทากับหรือเหมือนกับ (สําหรับเปรียบเทียบ string)

!~ ไมเทากับหรือไมเหมือนกับ (สําหรับเปรียบเทียบ string)

|| หรือ

&& และ

++, -- increment , decrement

(3)

3 3

5

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

ตัวอยาง

- awk ‘x=x+1; {print x}’ filename - awk ‘x=x+1 {print x}’ filename

- awk 'x=length($1), y=length($2) {print x,y}' filename - awk 'END {print NR}' filename

- awk ‘NT ==10 {print}’ filename - awk 'NF>7 {print $0}' filename - awk '{print NF}’ filename

- grep "ATOM " filename |awk '{print $1 $2 $3 $4}' - grep "ATOM " filename |awk '{print $1, $2, $3, $4}'

- grep "ATOM " filename |awk '{printf"%6s %5d %-4s %3s\n", $1, $2, $3, $4}‘

- awk 'BEGIN {x=0} {x=x+$7; print x}’ filename

-awk 'BEGIN {x=0} {x=x+$7} END{print x/NR}’ filename

6 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

จงวิเคราะหคําสั่งตอไปนี้

- awk ‘ {print $3, $7}’ filename - awk ‘NR <= 100 {print $0}’ filename

- awk 'BEGIN {x=0; y=0; z=0} {x=x+$7; y=y+$8; z=z+$9} END{print x/NR,y/NR,z/NR }’ filename

(4)

4 4

7

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

รูปแบบการพิมพแบบ printf printf Format [ Argument ... ]

Control characters

ความหมาย

%c Ascii character

%d Decimal integer

%e Scientific notation , d.dddddd[e+-]dd

%s string

%x Unsigned hexadecimal number

Escape sequences

ความหมาย

\b Backspace

\n New line

\t Tab

8 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

การคนหาคํา

คําสั่ง ความหมาย

/string/ คนหาคําที่ระบุไวระหวางเครื่องหมาย slash (/)

!/string/ คนหาคําที่ไมใชคําระบุไวระหวางเครื่องหมาย slash สัญญลักษณเพิ่มเติมสําหรับการคนหาคํา

+, ?, |, ( ) , {m}, {m,} , [string], etc.

- awk '/ATO/' filename - awk '!/ATO/' filename - awk '/ATO?/' filename - awk '/ATOM |HETA/' filename -awk '/ C[A-Z]/‘ filename

-grep "ATOM " filename |awk '($3 ~/C/){print $0}'

(5)

5 5

9

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

ตัวอยางโปรแกรม awk

BEGIN {}

{ no = no+1

printf"ATOM %5d %-4s%3s %s %4d %8.3f%8.3f%8.3f\n",no,$3,$4,$5,$6,$7,$8,$9 }

END{}

อานและพิมพในรูปแบบ pdb format

10 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

Conditional Statements

if Requires the following syntax:

if ( Expression ) { Statement } [ else Action ] while Requires the following syntax:

while ( Expression ) { Statement }

(6)

6 6

11

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

BEGIN {}

{

if($3=="CA")

{ni = ni+1; id[ni] = $6; res[ni] = $4;}

} END{

for (nj = 1; nj <= ni; nj++) printf("%3d %s ",id[nj],res[nj]) }

จงวิเคราะหคําสั่งตอไปนี้

โปรแกรมอาน pdb file และใหแสดงเฉพาะลําดับกรดของโปรตีน

12 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

BEGIN {}

{

if ($5 < 35)

{ d5 = $5+85 ; chn ="A" } if ($5 >34 && $5 < 69) { d5 = $5+51 ; chn ="B"}

if ($5 >68 && $5 < 103) { d5 = $5+17 ; chn ="C"}

if ($5 >102 && $5 < 137) { d5 = $5-17 ; chn ="D"}

printf("ATOM %6d %-4s%3s %1s%4d %8.3f%8.3f%8.3f\n",$2,$3,$4,chn,d5,$6,$7,$8);

} END {}

จงวิเคราะหคําสั่งตอไปนี้

โปรแกรมกําหนด chain id ตามเลขลําดับกรดอะมิโนของโปรตีน

(7)

7 7

13

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

BEGIN {}

$1!="TER"{

if($3 >= "C" && $3 <="CZZ") { mass=12.011 } if($3 >= "N" && $3 <="NZZ") { mass=14.0067 } if($3>= "O" && $3 <="OZZ") { mass=15.9994 } if($3>= "S" && $3 <="SZZ") { mass=32.066 } if($3>= "F" && $3 <="FEZ") { mass=55.847 } if($3>= "H" && $3 <="HZZ") { mass=1.008 }

x=x+($7*mass) y=y+($8*mass) z=z+($9*mass) sum=sum+mass }

END { printf("center of mass is %8.3f%8.3f%8.3f\n",x/sum,y/sum,z/sum);}

จงวิเคราะหคําสั่งตอไปนี้

โปรแกรมอาน pdb file และคํานวณจุดศูนยกลาง มวล

14 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

{ dy[NR,1] = $3 } END{

ni = 1 sum=0.0 mf=0.0

while (ni <= NR) {

# printf("%8.3f \n ",dy[ni,1]) sum=sum+dy[ni,1]

ni = ni + 1 } mean=sum/NR ni = 1

while (ni <= NR) {

mf = mf + (dy[ni,1]-mean)^2 ni = ni + 1 }

จงวิเคราะหคําสั่งตอไปนี้

โปรแกรมคํานวณ RMSD (root

mean square deviation)

(8)

8 8

15

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

Arithmetic Functions

atan2(y, x) arctangent of y/x.

cos(x) cosine of x; xis in radians.

sin(x) sin of x; xis in radians.

exp(x) the exponential function of x.

log(x) the natural logarithm of x.

sqrt(x) the square root of x.

int(x) the value of xtruncated to an integer.

rand( ) a random number n, with 0 <= n< 1.

srand( [Expr] ) Sets the seed value for the rand function to the value of the Exprparameter, or use the time of day if the Exprparameter is omitted.

16 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

'pdb' : PDB, 'mmod' : Macromodel, 'xyz' : Tinker, 'cc1' : ChemDraw3D 'mol' : MDL MOL-file, 'sdf' : MDL SD-file 'xplor' : X-PLOR/CNS map, 'ccp4' : CCP4 map, 'callback' : PyMOL Callback object (PyOpenGL) 'cgo' : compressed graphics object (list of floats) 'trj' : AMBER trajectory (use load_traj command for more control) 'top' : AMBER topology file 'rst' : AMBER restart file 'cex' : Metaphorics CEX format 'pse' : PyMOL Session file 'pqr' : PQR (a modified PDB file with charges and radii) 'mol2' : MOL2

ขอมูลทางโครงสรางในรูปแบบหรือ format ตางๆ

(9)

9 9

17

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

10

C 11.635 17.706 0.037 C 22.809 25.984 5.183 C 14.219 10.489 19.076 C 6.133 5.132 11.896 C 7.868 12.181 12.591 C 17.953 13.912 24.403 C 11.071 1.975 0.301 C 21.729 20.017 19.770 C 4.386 24.409 14.994 C 9.856 15.263 11.916

xyz format

18 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

BEGIN {}

{

if($1=="C") { no = no+1

printf"ATOM %5d %-4sATM 1

%8.3f%8.3f%8.3f\n",no,$1,$2,$3,$4;

}

if($1=="10") { s = s+1

no = 0

printf"MODEL %3d \n",s;

}}

END{}

โปรแกรมแปลงจาก xyz เปน pdb format

(10)

10 10

19

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

for i in *.xyz do

awk -f 2pdb.awk $i > $i.pdb done

สคริปแปลง xyz เปน pdb file ในกรณีที่มีไฟลเปนจํานวนมาก

20 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

042043 0 0 0 0 0 0 0 0 0 V2000

-0000.674000002.2016-0000.0475 C 0 0 0 0 0 0 0 0 0 0 0 0 -0001.895300001.6429-0000.0845 C 0 0 0 0 0 0 0 0 0 0 0 0 -0001.996200000.1839-0000.0097 C 0 0 0 0 0 0 0 0 0 0 0 0 -0000.8596-0000.550800000.0983 O 0 0 0 0 0 0 0 0 0 0 0 0 00000.386900000.005400000.1318 C 0 0 0 0 0 0 0 0 0 0 0 0 00000.523900001.347900000.0654 C 0 0 0 0 0 0 0 0 0 0 0 0 -0003.0906-0000.3727-0000.0433 O 0 0 0 0 0 0 0 0 0 0 0 0 00001.863000001.958100000.1135 C 0 0 0 0 0 0 0 0 0 0 0 0 00002.936400001.156000000.2355 C 0 0 0 0 0 0 0 0 0 0 0 0 00002.7987-0000.311700000.3123 C 0 0 0 0 0 0 0 0 0 0 0 0

mol format

(11)

11 11

21

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

BEGIN {}

{

if($1=="C") { no = no+1

printf"ATOM %5d %-4sATM 1

%8.3f%8.3f%8.3f\n",no,$1,$2,$3,$4;

}

if($1=="10") { s = s+1

no = 0

printf"MODEL %3d \n",s;

}}

END{}

- ใหแกไขโปรแกรมที่แปลงจาก xyz Æ pdb

ใหเปน mol Æ pdb

22 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

for i in *.xyz do

awk -f 2pdb.awk $i > $i.pdb done

ในกรณี multiple files ใหแกไขสคริปแปลง xyz เปน pdb file

(12)

12 12

23

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

BEGIN {}

{if($1!="TER") { nat = nat+1;

atn[nat]=$3;ren[nat]$4;idr[nat] = $6; x[nat]=$7 ; y[nat]=$8; z[nat]=$9 }}

END {

{for (ni = 1; ni <= nat; ni++) { if(atn[ni]=="CA")

{nb = nb+1; id[nb] = idr[ni]; res[nb] = ren[ni];xat[nb]=x[ni]; yat[nb]=y[ni]; zat[nb]=z[ni] } if(atn[ni]=="FE")

{xfe=x[ni]; yfe=y[ni]; zfe=z[ni]}

}}

{for (nj = 1; nj <= nb; nj++) { x1=xat[nj];y1=yat[nj];z1=zat[nj];

dx=x1-xfe;dy=y1-yfe;dz=z1-zfe dist[nj]= sqrt(dx*dx + dy*dy + dz*dz) print "distance CA-FE : " id[nj],dist[nj]}

}

โปรแกรมวัดระยะหางระหวางอะตอม

24 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

รายละเอียดเพิ่มเติมเกี่ยวกับ PDB format

(13)

13 13

25

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

ε

N O

N

η α

β γ ζ δ

δ ε

ε ζ

N C C

C O H H

C

O C NH2 H

H

H H

α β γ ε1 δ ε2

N C C

C O H H

C

O C NH2 H

H

H H

α β γ ε1 δ ε2

Naming convention of atoms

26 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

Greek-Eng Examples α=Alpha=A CA, HA β=Beta=B CB, HB

γ=Gamma=G CG, HG, OG, SG δ=Delta=D CD, HD, OD, ND, SD ε=Epsilon=E CE, HE, OE, NE, SE ξ=Zeta=Z CZ, HZ, OZ, NZ η=Eta=H CH, HH, OH, NH

Atom notation

(14)

14 14

27

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

N C C

C O H H

C O C NH2 H

H

H H

α β γ δ

ε1 ε2

N C C

C O H H

C O C NH2 H

H

H H

α β γ δ

ε1 ε2

ATOM 8 N GLN A 2 40.448 7.444 11.438 ATOM 9 CA GLN A 2 39.939 6.415 12.343 ATOM 10 C GLN A 2 38.829 6.989 13.237 ATOM 11 O GLN A 2 38.947 8.080 13.803 ATOM 12 CB GLN A 2 41.045 5.894 13.208 ATOM 13 CG GLN A 2 40.630 4.836 14.200 ATOM 14 CD GLN A 2 41.824 4.393 15.014 ATOM 15 OE1 GLN A 2 42.177 5.018 15.998 ATOM 16 NE2 GLN A 2 42.569 3.353 14.712

Example

Glutamine

28 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

ATOM 39 N TRP A 6 32.115 6.209 20.712 ATOM 40 CA TRP A 6 31.509 6.765 21.920 ATOM 41 C TRP A 6 30.374 7.747 21.627 ATOM 42 O TRP A 6 29.416 7.951 22.380 ATOM 43 CB TRP A 6 32.599 7.452 22.709 ATOM 44 CG TRP A 6 33.732 6.509 23.070 ATOM 45 CD1 TRP A 6 34.880 6.448 22.338 ATOM 46 CD2 TRP A 6 33.723 5.616 24.084 ATOM 47 NE1 TRP A 6 35.619 5.497 22.875 ATOM 48 CE2 TRP A 6 34.957 4.978 23.914 ATOM 49 CE3 TRP A 6 32.851 5.268 25.104 ATOM 50 CZ2 TRP A 6 35.352 3.959 24.768 ATOM 51 CZ3 TRP A 6 33.250 4.250 25.964 ATOM 52 CH2 TRP A 6 34.479 3.601 25.803

ε

N O

N

η α

β γ ζ δ

δ ε

ε

Example

ζ

Tryptophan

(15)

15 15

29

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

PS

ATOM 191 N ASP A 25 26.997 3.522 8.604 ATOM 192 CA ASP A 25 26.320 2.350 9.110 ATOM 193 C ASP A 25 26.682 0.960 8.579 ATOM 194 O ASP A 25 26.035 0.418 7.696 ATOM 195 CB ASP A 25 24.834 2.615 8.929 ATOM 196 CG ASP A 25 23.891 1.734 9.727 ATOM 197 OD1 ASP A 25 24.287 0.792 10.396 ATOM 198 OD2 ASP A 25 22.708 1.992 9.697

N C C

C O H H

C

H H

O - O

Aspartic acid

30 Chulalongkorn

ChulalongkornUniversityUniversity

Computational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit CellComputational Chemistry Unit Cell

Chulalongkorn

ChulalongkornUniversityUniversity

PS

Assignment 1. แบบฝกหัด

2. แกไขโปรแกรมคํานวณน้ําหนักโมเลกุลของโปรตีน

Referensi

Dokumen terkait