how two join and arrange two files together
amrita at iisermohali.ac.in
amrita at iisermohali.ac.in
Sat Jul 18 03:39:09 EDT 2009
I tried to join these two files together using command.......
from itertools import izip
from os.path import exists
def parafiles(*files):
vec = (open(f) for f in files if exists(f))
data = izip(*vec)
[f.close() for f in vec]
return data
for data in parafiles('/home/amrita/alachems/chem1.txt',
'/home/amrita/secstr/secstr.txt'):
print ' '.join(d.strip() for d in data)
it just joined the column of two files.
> On Sat, Jul 18, 2009 at 12:09 AM, <amrita at iisermohali.ac.in> wrote:
>>
>> Hi,
>>
>> I have two files having entries like:--
>> fileA
>> 8 Â ALA H = 7.85 N = 123.95 CA = 54.67 HA = 2.98 C = 179.39
>> 15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C = 177.18
>> 23 ALA H = 8.78 N = 120.16 CA = 55.84 HA = 4.14 C = 179.93
>> and
>> fileB
>> ChainA: ALA8 Â Â -67.217297 Â Â Â -37.131330
>> ChainA: ALA21 Â -69.822977 Â Â Â -48.871282
>> ChainA: ALA23 Â -59.148095 Â Â Â -46.540043
>> ChainA: ALA33 Â -65.459303 Â Â Â -43.269718
>>
>> i want to join thses two files in such a way that the output file will
>> contain column of both the files and the enties of similar position of
>> ALA
>> will be together.so the output file should look something like:----
>> fileC
>> 8 Â ALA H = 7.85 N = 123.95 CA = 54.67 HA = 2.98 C = 179.39 ChainA:
>> ALA8 Â Â -67.217297 Â Â Â -37.131330
>> 15 ALA H = 8.05 N = 119.31 CA = 52.18 HA = 4.52 C = 177.18
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
>> Â Â Â Â Â ChainA:
>> ALA21 Â -69.822977 Â Â Â -48.871282
>> 23 ALA H = 8.78 N = 120.16 CA = 55.84 HA = 4.14 C = 179.93 ChainA:
>> ALA23 Â -59.148095 Â Â Â -46.540043
>> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â
>> Â Â Â Â Â ChainA:
>> ALA33 Â -65.459303 Â Â Â -43.269718
>
> This mailinglist is not a collection of free code monkeys. Show us
> you've at least /tried/ to write this yourself, and tell us where
> you're running into problems or what error you're getting.
>
> See also http://catb.org/esr/faqs/smart-questions.html
>
> Additionally, you might consider asking on the Indian Python
> mailinglist instead:
> http://mail.python.org/mailman/listinfo/bangpypers
>
> - Chris
>
Amrita Kumari
Research Fellow
IISER Mohali
Chandigarh
INDIA
More information about the Python-list
mailing list