Re: [Tutor] how to read two files and substitute

2011-05-19 Thread Eike Welk
Hello Lina! On Wednesday 18.05.2011 05:22:50 lina wrote: > May I ask another question: > > where I can get some advanced, terse and powerful python tutorials. > short but powerful and a bit hard to understand at first. The tutorial on Python's website is relatively terse, but it uses a simple

Re: [Tutor] how to read two files and substitute

2011-05-18 Thread Alan Gauld
"lina" wrote where I can get some advanced, terse and powerful python tutorials. short but powerful and a bit hard to understand at first. The Python web site has many tutorials listed: http://wiki.python.org/moin/BeginnersGuide/Programmers Your definition of advanced, terse and powerful ma

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread lina
On Wed, May 18, 2011 at 2:30 AM, Michiel Overtoom wrote: > On 2011-05-17 18:47, lina wrote: > >> A further question:  I don't know how can I get the final output is >> unique? > > Unique in what way? You mean that in file1 (confout.pdb?) there could be > more values for the same key? or should dup

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread lina
May I ask another question: where I can get some advanced, terse and powerful python tutorials. short but powerful and a bit hard to understand at first. Thanks again, On Wed, May 18, 2011 at 1:51 AM, Emile van Sebille wrote: > On 5/17/2011 9:47 AM lina said... >> >> A further question:  I don'

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread Michiel Overtoom
On 2011-05-17 18:47, lina wrote: A further question: I don't know how can I get the final output is unique? Unique in what way? You mean that in file1 (confout.pdb?) there could be more values for the same key? or should duplicate lines in the output be condensed to one line? Maybe if you w

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread Emile van Sebille
On 5/17/2011 9:47 AM lina said... A further question: I don't know how can I get the final output is unique? That'll require some rework. The mapping container replaces mapping[parts[0]] each time it encounters another parts[0]. You can test if you are about to add a new entry or replace an e

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread lina
A further question: I don't know how can I get the final output is unique? #!/bin/python mapping={} for line in open("confout.pdb").readlines(): parts=line.strip().split() if len(parts)>6: mapping[parts[1]]=parts[4]+parts[3] origs=open("dummy.atomID").read().split() print " ".joi

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread lina
Thanks, it works. On Tue, May 17, 2011 at 11:53 PM, Emile van Sebille wrote: > On 5/17/2011 8:31 AM lina said... >> >> Following Michiel's code (a little adjustment was done): >> > > Well. you're almost there.  The error you're getting > is likely due to splitting an empty line, then referencing

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread Emile van Sebille
On 5/17/2011 8:31 AM lina said... Following Michiel's code (a little adjustment was done): Well. you're almost there. The error you're getting is likely due to splitting an empty line, then referencing the [1] and [4] elements. After you split the line into parts, test to confirm that the fi

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread lina
I learn python on and off, tried some examples, I mean tutorial, step by step writing around 80 ones, but seems not a good way of learning. Those tutorials are good, just I am not good at learning. so what I learned can't handle the problem I met. On Tue, May 17, 2011 at 11:19 PM, lina wrote: >

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread lina
$ python atomToResidues.py Traceback (most recent call last): File "atomToResidues.py", line 6, in mapping[parts[1]]=parts[4] IndexError: list index out of range Following Michiel's code (a little adjustment was done): #!/bin/python mapping={} for line in open("confout.pdb").readlines():

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread Emile van Sebille
On 5/17/2011 6:42 AM lina said... Hi, For file1: 5007 O28 CHO 173 35.300 99.430 65.810 1.00 0.0 5008 H29 CHO 173 35.680 100.290 66.150 1.00 0.00 5009 C1 CHO 174 59.060 12.440 58.680 1.00 0.00 5010 C2 CHO 174 59.460 12.480 60.160 1.00

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread Michiel Overtoom
On 2011-05-17 15:42, lina wrote: > I want to get the $4(column 4) value which has the $1 value. for > values in file2 Have you tried to write some code yourself already? Please show it. Anyway, I'd proceed with something like this: mapping={} for line in open("file1").readlines(): parts=

Re: [Tutor] how to read two files and substitute

2011-05-17 Thread Andre Engels
First read file1, and keep the result in a useful data structure (for this simple case it can be nothing more than a dictionary with the value in column 1 as key and the value in column 4 as value, but perhaps it's better to find something else if you want to do more with the data). Then go through

[Tutor] how to read two files and substitute

2011-05-17 Thread lina
Hi, For file1: 5007 O28 CHO 173 35.300 99.430 65.810 1.00 0.0 5008 H29 CHO 173 35.680 100.290 66.150 1.00 0.00 5009 C1 CHO 174 59.060 12.440 58.680 1.00 0.00 5010 C2 CHO 174 59.460 12.480 60.160 1.00 0.00 5011 C3 CHO 174 59.590