<br><br><div class="gmail_quote">On Thu, Apr 23, 2009 at 3:59 PM, Francesco Pietra <span dir="ltr"><<a href="mailto:chiendarret@gmail.com">chiendarret@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
hi:<br>
with script<br>
<br>
data = open('134-176_rectified_edited.pdb', 'r')<br>
outp = open('134-176_renumbered.pdb', 'w')<br>
<br>
for L in data:<br>
if L[3] == 'M':<br>
L = L[:24] + "%4d" % (int(L[24-28])+133) + L[28:]<br>
outp.write(L)<br>
<br>
<br>
i wanted to modify lines of the type:<br>
ATOM 1 HH31 ACE 1 1.573 1.961 0.769 1.00 0.00 H<br>
<br>
to add 133 to column 25, getting 134 there, and so on for next lines 2<br>
-> 135, 3 -> 136, etc.<br>
<br>
<br>
i must have heavily messed things because the file was not even read:<br>
<br>
$ python renumber.py 134-176_rectified.pdb<br>
Traceback (most recent call last):<br>
File "renumber.py", line 6, in <module><br>
L = L[:24] + "%4d" % (int(L[24-28])+133) + L[28:]<br>
ValueError: invalid literal for int() with base 10: ''<br>
<br>
<br>
<br>
thanks for having an expert look<br>
<br>
chiendarret<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br>I wrote this function the other day for something similar I needed to do, you may find it useful:<br><br>def chunk_line(line, steps):<br> """Return a list of chunks from a string, with sizes as specified by the<br>
list steps.<br><br> >>> line = '1121231234'<br> >>> steps = [1,2,3,4]<br> >>> chunk_line(line, steps)<br> ['1', '12', '123', '1234']<br> """<br>
result = []<br> for step in steps:<br> result.append(line[:step])<br> line = line[step:]<br> return result<br><br><br>