[Tutor] how to read two files and substitute
lina
lina.lastname at gmail.com
Tue May 17 17:19:41 CEST 2011
$ python atomToResidues.py
Traceback (most recent call last):
File "atomToResidues.py", line 6, in <module>
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():
parts=line.strip().split()
mapping[parts[1]]=parts[4]
origs=open("dummy.atomID").read().split()
print " ".join([mapping[orig] for orig in origs])
On Tue, May 17, 2011 at 11:12 PM, lina <lina.lastname at gmail.com> wrote:
> Thanks all first,
>
> I wrote a .bash, but not work.
>
> for python one, I am not confident in writing one. I will try Michiel one now.
>
>
>
> On Tue, May 17, 2011 at 10:19 PM, Emile van Sebille <emile at fenx.com> wrote:
>> 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 0.00
>>> 5011 C3 CHO 174 59.590 11.120 60.830 1.00 0.00
>>> 5012 C4 CHO 174 60.780 10.430 60.160 1.00 0.00
>>>
>>> For file2:
>>>
>>> 5008 5010 5011
>>>
>>> I want to get the $4(column 4) value which has the $1 value. for
>>> values in file2
>>>
>>> such as the results is 173 174 174
>>>
>>> Thanks for any suggestions,
>>>
>>
>>
>> It'll help us help you if you show how far along you've come. Otherwise,
>> most of us will presume this is a homework assignment, and we'd rather help
>> you learn python than do your homework for you.
>>
>> In short, you'll read the lines from the file, test each line to see if it
>> starts with one of the targets, then spilt the fields from the line and
>> select the fourth field. Accumulate those and return the result.
>>
>> Post your code when you follow up please.
>>
>> Emile
>>
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
>
> --
> Best Regards,
>
> lina
>
--
Best Regards,
lina
More information about the Tutor
mailing list