Question: Change X Coordinate Of A Pdb File
0
gravatar for Kanika
7.5 years ago by
Kanika10
Kanika10 wrote:

I am new to perl and this may seem a vague question. I have a PDB file and I just want to add 10 to all X coordinates of the file. can anyone please help me with the code??

pdb perl coordinates • 2.2k views
ADD COMMENTlink modified 5.3 years ago by Biostar ♦♦ 20 • written 7.5 years ago by Kanika10

Basically, what you're asking is how to access the coordinate section of a PDB file. Lots of answers to this question: http://biostar.stackexchange.com/questions/7024/how-to-extract-just-the-coordinate-values-from-a-pdb-file-using-perl-only.

ADD REPLYlink written 7.5 years ago by Neilfws48k
2
gravatar for Neilfws
7.5 years ago by
Neilfws48k
Sydney, Australia
Neilfws48k wrote:

Without writing the code for you, here's an outline of what your code needs to do:

  1. Open PDB file for reading
  2. Read each line consecutively
  3. If line DOES NOT begin with "ATOM" or "HETATM", print it
  4. If line DOES begin with ATOM or HETATM:
  5. extract the number in the column that corresponds to X coordinate
  6. add 10 to it
  7. print out line, substituting new X value
  8. Close PDB file

So the main Perl concepts that you need to learn are:

  • how to open, close and read a file; then print lines from it
  • how to match regular expressions to a line
  • how to split space-delimited lines into arrays
  • basic arithmetic on variables ("add 10 to x")

A lot of this is covered by answers to a previous question. But really, it's probably better to use an existing parser which will have considered the difficult cases (see Bosco's comment).

ADD COMMENTlink modified 7.5 years ago • written 7.5 years ago by Neilfws48k

alas, space-delimited arrays fails with PDB files, several gotchas: - there's a column for insertions, alternate conformations - chain id's can sometimes be a space or a letter/number - there are no defined spaces between the x,y,z coordinates. there are accidental spaces if not all significant figures are used

to parse pdb, you must read specific positions on the line.

ADD REPLYlink written 7.5 years ago by Bosco Ho90

All true, answer amended accordingly.

ADD REPLYlink written 7.5 years ago by Neilfws48k
0
gravatar for Pierre Lindenbaum
7.5 years ago by
France/Nantes/Institut du Thorax - INSERM UMR1087
Pierre Lindenbaum113k wrote:

if you're using a XML-PDB file, you can use the following xslt stylesheet to add 10 to all the elements Cartn_x:


<xsl:stylesheet xmlns:xsl="&lt;a href="http://www.w3.org/1999/XSL/Transform" "="" rel="nofollow">http://www.w3.org/1999/XSL/Transform'
        xmlns:PDBx="http://pdbml.pdb.org/schema/pdbx-v32.xsd"
        version='1.0'
        >
<xsl:output method="xml"/>

<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="PDBx:Cartn_x">
<PDBx:Cartn_x>
<xsl:value-of select="10 + number(.)"/>
</PDBx:Cartn_x>
</xsl:template>

<xsl:template match="*|@*|text()">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

Usage :

xsltproc stylesheet.xsl pdb.xml
ADD COMMENTlink written 7.5 years ago by Pierre Lindenbaum113k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1816 users visited in the last hour