Insert string into string
chiendarret at gmail.com
Sat Jul 26 23:40:00 CEST 2008
I am posting ex novo as it became confusing to me. I take the
opportunity to ask advice for a second problem.
For file xxx.pdb, insert letter "A" into each line that starts with
"ATOM". "A" should be inserted at position 22, i.e., one space after
"LEU", leaving all other characters at the same position as in the
ATOM 1 N LEU 1 146.615 40.494 103.776 1.00 73.04 1SG 2
In all lines starting with "ATOM", "LEU" is constant as to position
only (18-20), i.e., "LEU" may be replaced by
three different uppercase letters. Therefore, the most direct
indication would be position 22. If specifying line starting with
"ATOM" makes complication, forget about that as most lines begin with
"ATOM" so that hand correction will be easy.
f = open("xxx.pdb", "w")
for line in sys.stdin:
line = line[:22] + "A" + line[23:]
destroys the xxxx.pdb file and python exits witha non zero exit status.
The same occurs with script
f = open("hASIC1a.B99990003.pdb", "w")
f.write(' line = line[:22] + "A" + line[23:]')
I must have misunderstood the suggestion I received on previous posting.
File xxx.pdb above has 426 lines stating with "ATOM", this serial
number occupying positions 7-11, right justified (Thus 1, as in the
line example above, means first line). A second, similar file yyy.pdb
has to be concatenated to xxx.pdb. Before that it should be added of
"A" as above and renumbered at position 7-11, starting from 428 (there
is an intermediate line to add). How should a script look like for
this string insertion into string with recursive +1?
More information about the Python-list