Re: [Tutor] Text Processing Query

2013-03-14 Thread Prasad, Ramit
Spyros Charonis wrote: > Hello Pythoners, > > I am trying to extract certain fields from a file that whose text looks like > this: > > COMPND   2 MOLECULE: POTASSIUM CHANNEL SUBFAMILY K MEMBER 4; > COMPND   3 CHAIN: A, B; > > COMPND  10 MOL_ID: 2; > COMPND  11 MOLECULE: ANTIBODY FAB FRAGMENT LI

Re: [Tutor] Text Processing Query

2013-03-14 Thread Spyros Charonis
Yes, the elif line need to have **flag_FAB ==1** as is conidition instead of **flag_FAB=1**. So: for line in scanfile: if line[0:6]=='COMPND' and 'FAB' in line: flag_FAB = 1 elif line[0:6]=='COMPND' and 'CHAIN' in line and flag_FAB == 1: print line flag_FAB = 0 On Th

Re: [Tutor] Text Processing Query

2013-03-14 Thread Mark Lawrence
On 14/03/2013 11:28, taserian wrote: Top posting fixed On Thu, Mar 14, 2013 at 6:56 AM, Spyros Charonis mailto:s.charo...@gmail.com>> wrote: Hello Pythoners, I am trying to extract certain fields from a file that whose text looks like this: COMPND 2 MOLECULE: POTASSIUM CHA

Re: [Tutor] Text Processing Query

2013-03-14 Thread Mitya Sirenef
On 03/14/2013 07:28 AM, taserian wrote: Since the identifier and the item that you want to keep are on different lines, you'll need to set a "flag". > > with open(filename) as file: > > scanfile=file.readlines() > > flag = 0 > > for line in scanfile: > > if line[0:6]=='COMPND' and 'FAB FRAGMENT

Re: [Tutor] Text Processing Query

2013-03-14 Thread Bod Soutar
On 14 March 2013 10:56, Spyros Charonis wrote: > Hello Pythoners, > > I am trying to extract certain fields from a file that whose text looks like > this: > > COMPND 2 MOLECULE: POTASSIUM CHANNEL SUBFAMILY K MEMBER 4; > COMPND 3 CHAIN: A, B; > COMPND 10 MOL_ID: 2; > COMPND 11 MOLECULE: ANTIB

Re: [Tutor] Text Processing Query

2013-03-14 Thread taserian
Since the identifier and the item that you want to keep are on different lines, you'll need to set a "flag". with open(filename) as file: scanfile=file.readlines() flag = 0 for line in scanfile: if line[0:6]=='COMPND' and 'FAB FRAGMENT' in line: flag = 1 elif line[

[Tutor] Text Processing Query

2013-03-14 Thread Spyros Charonis
Hello Pythoners, I am trying to extract certain fields from a file that whose text looks like this: COMPND 2 MOLECULE: POTASSIUM CHANNEL SUBFAMILY K MEMBER 4; COMPND 3 CHAIN: A, B; COMPND 10 MOL_ID: 2; COMPND 11 MOLECULE: ANTIBODY FAB FRAGMENT LIGHT CHAIN; COMPND 12 CHAIN: D, F; COMPN