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??
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??
Without writing the code for you, here's an outline of what your code needs to do:
So the main Perl concepts that you need to learn are:
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).
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.
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="<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
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Basically, what you're asking is how to access the coordinate section of a PDB file. Lots of answers to this question.