Re: [Tutor] map one file and print it out following the sequence

2011-10-12 Thread Andreas Perstinger

On 2011-10-12 05:31, lina wrote:

I tried to write one (not working one) as below, so many problems here.


Just some quick remarks:


#!/usr/bin/python3

import os.path

LINESTOSKIP=0
CHAINID="CDEFGHI"
INFILENAME="pdbone.pdb"
DICTIONARYFILE="itpone.itp"
mapping={}
valuefromdict={}

def sortfile():
 for chainid in CHAINID:
 sortoneblock(chainid)


def generatedictionary(dictfilename):


You define the function with the parameter "dictfilename" but you'll 
never use it.



 text=fetchonefiledata(DICTIONARYFILE)
 for line in text:
 parts=line.strip().split()
 if len(parts)==8:
 mapping[parts[4]]=parts[0]
 print(mapping)


The if-branch is probably wrongly indented (should be inside the for-loop).


def sortoneblock(cID)
 text=fetchonefiledata(INFILENAME)
 for line in text:
 blocks=line.strip().split()
 if len(blocks)== 11 and  blocks[3] == "CUR" and blocks[4] == "cID":



"cID" is a string-variable but you compare block 4 to the literal string 
"cID". In "pdbone.pdb" you will never find "cID" so this function will 
do nothing. You probably mean "blocks[4] == cID".



 valuefromdict[blocks[2]]=mapping[block[2]]


You never fill up "mapping" because you never call your 
"generatedictionary"-function. Therefore "mapping" is still an empty 
dictionary and this line will raise an exception.



 return


Firstly, the indentation is wrong because you would leave "sortoneblock" 
after the first processed line. Secondly, as you return nothing, you 
don't need this line because you will leave the function anyway.





def fetchonefiledata(infilename):
 text=open("infilename").readlines()


Again, "infilename" is a variable, so no need for the quotes.


 if os.path.splitext(infilename)[1]=".itp"
 return text
 if os.path.splitext(infilename)[1]=".pdb"
 return text[LINESTOSKIP:]


if __name__=="__main__":
 sortfiles()


There is no "sortfiles()" in your script. The function you probably mean 
is called "sortfile()"


Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Keyboard Module

2011-10-12 Thread Alan Gauld

On 12/10/11 02:32, Ryan Strunk wrote:


The keyboard module I currently have access to is a wrapper for the wx
keyboard handler, which is fine, but it prevents me from holding one key and
pressing another.


So use raw wx key events. They include key down,up and press events.


I thought of using Pygame to pull this off, but I gather from my research
that I can't just use certain pieces of Pygame; in order to get the
functionality I want out of the keyboard module, I'll need other modules as
well. I don't want to work specifically in Pygame, because I've heard Pygame
is quite bloated and requires a good deal of overhead. (I wouldn't mind
being proven wrong on this)


Bloated carries the connotation of unnecessary code, but pygame provides 
a lot of functionality. You may not need it all, and using pygame may 
require you to import more than you need. But thats not quite the same 
as saying pygame is bloated.


And its not that huge that it should stop you using it.
If it works, why not?



All of which leads me to my question. Can anyone recommend a keyboard module
which will allow me to work with various facets of the keyboard to execute
functions.


Since you mentioned wx I assume thats the GUI you are using.
If not you can also investigate Tkinter which likewise traps keyboard 
events and might be considered slightly easier to use.


HTH,

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] map one file and print it out following the sequence

2011-10-12 Thread lina
On Wed, Oct 12, 2011 at 3:29 PM, Andreas Perstinger <
andreas.perstin...@gmx.net> wrote:

> On 2011-10-12 05:31, lina wrote:
>
>> I tried to write one (not working one) as below, so many problems here.
>>
>
> Just some quick remarks:


Thanks,

Now the newly-improved one as following: but still the "sort" parts did not
work.

#!/usr/bin/python3

import os.path

LINESTOSKIP=0
CHAINID="CDEFGHI"
INFILENAME="pdbone.pdb"
DICTIONARYFILE="itpone.itp"
mapping={}
valuefromdict={}

def sortfile():
for chainid in CHAINID:
sortoneblock(chainid)


def generatedictionary(dictfilename):
text=fetchonefiledata(DICTIONARYFILE)
for line in text:
parts=line.strip().split()
if len(parts)==8:
mapping[parts[4]]=parts[0]
print(mapping)

def sortoneblock(cID):
text=fetchonefiledata(INFILENAME)
for line in text:
blocks=line.strip().split()
if len(blocks)== 11 and  blocks[3] == "CUR" and blocks[4] == cID and
blocks[2] in mapping.keys():
valuefromdict[cID]=mapping[blocks[2]]
print(valuefromdict)



def fetchonefiledata(infilename):
text=open(infilename).readlines()
if os.path.splitext(infilename)[1]==".itp":
return text
if os.path.splitext(infilename)[1]==".pdb":
return text[LINESTOSKIP:]


if __name__=="__main__":
generatedictionary(DICTIONARYFILE)
sortfile()

   The result is:

 $ python3 map-to-itp.py
{'O4': '2', 'C19': '3', 'C21': '1'}
{'C': '3'}
{'C': '2'}
{'C': '1'}

for print(mapping) part, {'O4': '2', 'C19': '3', 'C21': '1'} the value
doesn't keep the 1, 2, 3 order any more.

Thanks for further suggestions.

The relevant files I put it here:

https://docs.google.com/leaf?id=0B93SVRfpVVg3NzkyOGU2ZTUtZTFjNC00ZjE4LThhNmQtOWY1YWFkOWI0NWEw&hl=en_GB
https://docs.google.com/leaf?id=0B93SVRfpVVg3YTEwZjhiOTItN2I2Yi00NTEyLTljODAtYTc2ODI4Njk1YzZl&hl=en_GB
https://docs.google.com/leaf?id=0B93SVRfpVVg3M2Y1MWZiMmEtOTE2Mi00M2VjLTljNjAtYWNlMjhiNzEyODY1&hl=en_GB



>
>  #!/usr/bin/python3
>>
>> import os.path
>>
>> LINESTOSKIP=0
>> CHAINID="CDEFGHI"
>> INFILENAME="pdbone.pdb"
>> DICTIONARYFILE="itpone.itp"
>> mapping={}
>> valuefromdict={}
>>
>> def sortfile():
>> for chainid in CHAINID:
>> sortoneblock(chainid)
>>
>>
>> def generatedictionary(**dictfilename):
>>
>
> You define the function with the parameter "dictfilename" but you'll never
> use it.
>
>
>  text=fetchonefiledata(**DICTIONARYFILE)
>> for line in text:
>> parts=line.strip().split()
>> if len(parts)==8:
>> mapping[parts[4]]=parts[0]
>> print(mapping)
>>
>
> The if-branch is probably wrongly indented (should be inside the for-loop).
>
>
>  def sortoneblock(cID)
>> text=fetchonefiledata(**INFILENAME)
>> for line in text:
>> blocks=line.strip().split()
>> if len(blocks)== 11 and  blocks[3] == "CUR" and blocks[4] ==
>> "cID":
>>
>
>
> "cID" is a string-variable but you compare block 4 to the literal string
> "cID". In "pdbone.pdb" you will never find "cID" so this function will do
> nothing. You probably mean "blocks[4] == cID".
>
>
>  valuefromdict[blocks[2]]=**mapping[block[2]]
>>
>
> You never fill up "mapping" because you never call your
> "generatedictionary"-function. Therefore "mapping" is still an empty
> dictionary and this line will raise an exception.
>
>  return
>>
>
> Firstly, the indentation is wrong because you would leave "sortoneblock"
> after the first processed line. Secondly, as you return nothing, you don't
> need this line because you will leave the function anyway.
>
>
>
>>
>> def fetchonefiledata(infilename):
>> text=open("infilename").**readlines()
>>
>
> Again, "infilename" is a variable, so no need for the quotes.
>
>
>  if os.path.splitext(infilename)[**1]=".itp"
>> return text
>> if os.path.splitext(infilename)[**1]=".pdb"
>> return text[LINESTOSKIP:]
>>
>>
>> if __name__=="__main__":
>> sortfiles()
>>
>
> There is no "sortfiles()" in your script. The function you probably mean is
> called "sortfile()"
>
> Bye, Andreas
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] map one file and print it out following the sequence

2011-10-12 Thread Andreas Perstinger

On 2011-10-12 10:27, lina wrote:

  $ python3 map-to-itp.py
{'O4': '2', 'C19': '3', 'C21': '1'}
{'C': '3'}
{'C': '2'}
{'C': '1'}

for print(mapping) part, {'O4': '2', 'C19': '3', 'C21': '1'} the value
doesn't keep the 1, 2, 3 order any more.


That's fine, because "mapping" is a dictionary which has no order. From 
the tutorial 
(http://docs.python.org/py3k/tutorial/datastructures.html#dictionaries):
"It is best to think of a dictionary as an unordered set of key: value 
pairs, with the requirement that the keys are unique (within one 
dictionary)."


What you want (as far as I understand it) is sorting the lines in 
"pdbone.pdb" based on the positions in file "itpone.itp". The connection 
between both files is the column with the values "O4", "C19", "C21", ... 
(= your keys). You've already succesfully built a dictionary in which 
you saved the position for every key.


For the sorting you could now build a list of tuples of all lines in 
"pdbone.pdb" you want to sort where the first element in the tuple is 
the position and the second the line itself. Then you can easily sort 
this temporary list and write the new ordered lines back to the file:


def sortoneblock(cID):
text = fetchonefiledata(INFILENAME)
temp = []# create an empty temporary list

for line in text:
blocks = line.strip().split()
if len(blocks) == 11 and blocks[3] == "CUR" and blocks[4] == 
cID and blocks[2] in mapping.keys():


temp.append((mapping[blocks[2]], line))  # add a tuple to 
the list which has the following format: (position from the dictionary, 
complete line)


# the following line just shows you, what we have done so far. You 
can delete it without consequences.


for line in temp: print(line)

temp.sort() # this sorts the list based on the position

# the following line prints the sorted list (just the original line 
without the position elements). If you want to write the result back to 
the file you have to exchange "print()"


for line in temp: print(line[1])

Bye, Andreas
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Parsing /etc/passwd

2011-10-12 Thread Gerhardus Geldenhuis
Hi
I wrote the following code:
  f = open('/etc/passwd', 'r')
  users = f.read()
  userelements = re.findall(r'(\w+):(\w+):(\w+):(\w+):(\w+):(\w+):(\w+)',
users)
  print userelements

  for user in userelements:
(username, encrypwd, uid, gid, gecos, homedir, usershell) = user  #
unpack the tuple into 7 vars
print username


but I get no results so my parsing must be wrong but I am not sure why.

Incidentally while googling I found the module
http://docs.python.org/library/pwd.html which I will eventually use but I am
first curious to fix and understand the problem before I throw away this
code.

Regards

-- 
Gerhardus Geldenhuis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing /etc/passwd

2011-10-12 Thread Hugo Arts
On Wed, Oct 12, 2011 at 3:41 PM, Gerhardus Geldenhuis
 wrote:
> Hi
> I wrote the following code:
>   f = open('/etc/passwd', 'r')
>   users = f.read()
>   userelements = re.findall(r'(\w+):(\w+):(\w+):(\w+):(\w+):(\w+):(\w+)',
> users)
>   print userelements
>   for user in userelements:
>     (username, encrypwd, uid, gid, gecos, homedir, usershell) = user  #
> unpack the tuple into 7 vars
>     print username
>
> but I get no results so my parsing must be wrong but I am not sure why.
> Incidentally while googling I found the
> module http://docs.python.org/library/pwd.html which I will eventually use
> but I am first curious to fix and understand the problem before I throw away
> this code.
> Regards
>

the homedir and usershell parts are paths. Paths will contain slashes.
The \w character class captures only [A-Za-z0-9_],  that is, letters,
numbers, and the underscore. That means slashes will not match, and so
the entire match fails.

On another note, the structure of the /etc/passwd file is pretty
simple, I don't think you need regexes. Simply use split:

users = f.readlines()
for user in users:
(username, encrypwd, uid, gid, gecos, homedir, usershell) = user.split(':')

HTH,
Hugo
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing /etc/passwd

2011-10-12 Thread Gerhardus Geldenhuis
Fantastic,
Thanks Hugo that makes 100% sense now! Testing both regex for including /
and doing split and when done throwing both away and using the default
module.

Regards

On Wed, Oct 12, 2011 at 2:49 PM, Hugo Arts  wrote:

> On Wed, Oct 12, 2011 at 3:41 PM, Gerhardus Geldenhuis
>  wrote:
> > Hi
> > I wrote the following code:
> >   f = open('/etc/passwd', 'r')
> >   users = f.read()
> >   userelements = re.findall(r'(\w+):(\w+):(\w+):(\w+):(\w+):(\w+):(\w+)',
> > users)
> >   print userelements
> >   for user in userelements:
> > (username, encrypwd, uid, gid, gecos, homedir, usershell) = user  #
> > unpack the tuple into 7 vars
> > print username
> >
> > but I get no results so my parsing must be wrong but I am not sure why.
> > Incidentally while googling I found the
> > module http://docs.python.org/library/pwd.html which I will eventually
> use
> > but I am first curious to fix and understand the problem before I throw
> away
> > this code.
> > Regards
> >
>
> the homedir and usershell parts are paths. Paths will contain slashes.
> The \w character class captures only [A-Za-z0-9_],  that is, letters,
> numbers, and the underscore. That means slashes will not match, and so
> the entire match fails.
>
> On another note, the structure of the /etc/passwd file is pretty
> simple, I don't think you need regexes. Simply use split:
>
> users = f.readlines()
> for user in users:
>(username, encrypwd, uid, gid, gecos, homedir, usershell) =
> user.split(':')
>
> HTH,
> Hugo
>



-- 
Gerhardus Geldenhuis
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] map one file and print it out following the sequence

2011-10-12 Thread lina
On Wed, Oct 12, 2011 at 8:50 PM, Andreas Perstinger <
andreas.perstin...@gmx.net> wrote:

> On 2011-10-12 10:27, lina wrote:
>
>>  $ python3 map-to-itp.py
>> {'O4': '2', 'C19': '3', 'C21': '1'}
>> {'C': '3'}
>> {'C': '2'}
>> {'C': '1'}
>>
>> for print(mapping) part, {'O4': '2', 'C19': '3', 'C21': '1'} the value
>> doesn't keep the 1, 2, 3 order any more.
>>
>
> That's fine, because "mapping" is a dictionary which has no order. From the
> tutorial (http://docs.python.org/py3k/**tutorial/datastructures.html#**
> dictionaries
> ):
> "It is best to think of a dictionary as an unordered set of key: value
> pairs, with the requirement that the keys are unique (within one
> dictionary)."
>
> What you want (as far as I understand it) is sorting the lines in
> "pdbone.pdb" based on the positions in file "itpone.itp". The connection
> between both files is the column with the values "O4", "C19", "C21", ... (=
> your keys). You've already succesfully built a dictionary in which you saved
> the position for every key.
>
> For the sorting you could now build a list of tuples of all lines in
> "pdbone.pdb" you want to sort where the first element in the tuple is the
> position and the second the line itself. Then you can easily sort this
> temporary list and write the new ordered lines back to the file:
>
> def sortoneblock(cID):
>text = fetchonefiledata(INFILENAME)
>temp = []# create an empty temporary list
>
>for line in text:
>blocks = line.strip().split()
>if len(blocks) == 11 and blocks[3] == "CUR" and blocks[4] == cID and
> blocks[2] in mapping.keys():
>
>temp.append((mapping[blocks[2]**], line))  # add a tuple to the
> list which has the following format: (position from the dictionary, complete
> line)
>
># the following line just shows you, what we have done so far. You can
> delete it without consequences.
>
>for line in temp: print(line)
>
>temp.sort() # this sorts the list based on the position
>
># the following line prints the sorted list (just the original line
> without the position elements). If you want to write the result back to the
> file you have to exchange "print()"
>
I do have problems to write each blocks (differentiated by chainID)  back
one by one, but this will leave it at the end. at present I still have
following problems
Q1: why the D E F G H I stopped being processed.

>
>for line in temp: print(line[1])

Thanks.

$ python3 map-to-itp.py
{'O4': '2', 'C19': '3', 'C21': '1'}
C
ATOM832  C21 CUR C  85  32.823  27.366   0.801  1.00
0.00
ATOM831  O4  CUR C  85  31.865  28.248   0.183  1.00
0.00
ATOM827  C19 CUR C  85  31.891  29.624   0.280  1.00
0.00

D
E
F
G
H
I




#!/usr/bin/python3

import os.path

LINESTOSKIP=0
CHAINID="CDEFGHI"
INFILENAME="pdbone.pdb"
DICTIONARYFILE="itpone.itp"
mapping={}
valuefromdict={}

def sortfile():
for chainid in CHAINID:
print(chainid)
sortoneblock(chainid)



def sortoneblock(cID):
text=fetchonefiledata(INFILENAME) ## Q2: How to avoid read this file
every time. actually it only need read once.
temp = []
for line in text:
blocks=line.strip().split()
if len(blocks)== 11 and  blocks[3] == "CUR" and blocks[4] == cID and
blocks[2] in mapping.keys():
temp.append((mapping[blocks[2]],line))
temp.sort()
for line in temp:
print(line[1].strip())


def generatedictionary(dictfilename):
text=fetchonefiledata(DICTIONARYFILE)
for line in text:
parts=line.strip().split()
if len(parts)==8:
mapping[parts[4]]=parts[0]
print(mapping)



def fetchonefiledata(infilename):
text=open(infilename).readlines()
if os.path.splitext(infilename)[1]==".itp":
return text
if os.path.splitext(infilename)[1]==".pdb":
return text[LINESTOSKIP:]


if __name__=="__main__":
generatedictionary(DICTIONARYFILE)
sortfile()

 Thanks.



>
>
> Bye, Andreas
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Parsing /etc/passwd

2011-10-12 Thread Peter Otten
Hugo Arts wrote:

>> f = open('/etc/passwd', 'r')
> users = f.readlines()
> for user in users:
  ...

You can iterate over the file directly:

for user in f:
...

The version using readlines() reads the whole file into a list of lines 
where the alternative just has to remember the current line. 

While it doesn't matter much for small files iterating over the file 
directly will save a lot of memory if the input file is large.

Therefore avoiding readlines() is a good habit to get into.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] map one file and print it out following the sequence

2011-10-12 Thread Dave Angel

On 10/12/2011 09:57 AM, lina wrote:


I do have problems to write each blocks (differentiated by chainID)  back
one by one, but this will leave it at the end. at present I still have
following problems
Q1: why the D E F G H I stopped being processed.

In what sense do you mean stopped?  There are no records in pdbone.pdb 
that have column 4 equal to any of the remaining CID values, D, E, F, etc.


So they don't print anything.  You can see that 3 of them matched cID of "C"


for line in temp: print(line[1])

Thanks.

$ python3 map-to-itp.py
{'O4': '2', 'C19': '3', 'C21': '1'}
C
ATOM832  C21 CUR C  85  32.823  27.366   0.801  1.00
0.00
ATOM831  O4  CUR C  85  31.865  28.248   0.183  1.00
0.00
ATOM827  C19 CUR C  85  31.891  29.624   0.280  1.00
0.00

D
E
F
G
H
I




#!/usr/bin/python3

import os.path

LINESTOSKIP=0
CHAINID="CDEFGHI"
INFILENAME="pdbone.pdb"
DICTIONARYFILE="itpone.itp"
mapping={}
valuefromdict={}

def sortfile():
 for chainid in CHAINID:
 print(chainid)
 sortoneblock(chainid)



def sortoneblock(cID):
 text=fetchonefiledata(INFILENAME) ## Q2: How to avoid read this file
every time. actually it only need read once.
Simple.  Move this line into sortfile (before the for loop), and pass 
text as an argument when it calls sortoneblock(cID, text)
Naturally, you'd then add the parameter to sortoneblock(cID, text).  
Once you try to create the output file, you'll also be adding the open() 
call for that into sortfile(), and passing its file object into 
sortoneblock(cID, text, outfile)

 temp = []
 for line in text:
 blocks=line.strip().split()
 if len(blocks)== 11 and  blocks[3] == "CUR" and blocks[4] == cID and
blocks[2] in mapping.keys():
 temp.append((mapping[blocks[2]],line))
 temp.sort()
 for line in temp:
 print(line[1].strip())


def generatedictionary(dictfilename):
 text=fetchonefiledata(DICTIONARYFILE)
 for line in text:
 parts=line.strip().split()
 if len(parts)==8:
 mapping[parts[4]]=parts[0]
 print(mapping)



def fetchonefiledata(infilename):
 text=open(infilename).readlines()
 if os.path.splitext(infilename)[1]==".itp":
 return text
 if os.path.splitext(infilename)[1]==".pdb":
 return text[LINESTOSKIP:]


if __name__=="__main__":
 generatedictionary(DICTIONARYFILE)
 sortfile()

  Thanks.



I think your final version of sortfile() might look something like:

def sortfile(infilename=INFILENAME, outfilename=OUTFILENAME):
infile = open(infilename, "r")
intext = infile.readlines()
outfile = open(OUTFILENAME, "w")
for chainid in CHAINID:
print("chain id = ",chainid)
 sortoneblock(chainid, intext, outfile)
infile.close()
outfile.close()


--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I am trying to print list elements but i am getting 'none'

2011-10-12 Thread Prasad, Ramit
>for item in list:
>print item

Or you could do this inline with:
print ' '.join( myList ) # Change ' ' to be the separator you desire if you 
want something other than a space between elements?

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] extract specific column

2011-10-12 Thread Anna Olofsson


Hi,





I'm a beginner at python and I'm trying to extract a specific column from a txt 
file ( see attached file). 





In the attached file I want to extract the entire column 







pph2_prob (i.e. column 16). But I want to get all the values from that 
column without the headline  







pph2_prob.

How do I accomplish that? 

Best,
Anna

  #o_snp_id  o_acc o_pos  o_aa1   o_aa2   snp_id  
 acc   pos  aa1 aa2 nt1 nt2 
prediction  based_oneffect  pph2_class  
 pph2_probpph2_FPRpph2_TPRpph2_FDR  site
  regionPHATdScore  Score1  Score2Nobs   Nstruct
 Nfilt  PDB_id  PDB_pos PDB_ch   ident  length  NormAcc SecStr  MapRegdVol  
 dProp  B-fact   H-bonds AveNHet MinDHet AveNInt
 MinDInt AveNSit MinDSitTransv  CodPos  CpG  
MinDJnc PfamHit  IdPmax  IdPSNP  IdQmin
Comments
BSND_M1I  Q8WZ551   M   I   
BSND_M1I  Q8WZ551 M   I   G   T 
 probably damaging alignment   
deleterious  0.999   0.00692 0.111   0.0222 
 2.055   2.148   0.093   10  0  


 1   2   0  
 0   17.5
BSND_M1K  Q8WZ551   M   K   
BSND_M1K  Q8WZ551 M   K   T   A 
 probably damaging alignment   
deleterious  0.999   0.00692 0.111   0.0222 
 2.505   2.148   -0.357  10  0  


 1   1   0  
 0   17.5
BSND_M1L  Q8WZ551   M   L   
BSND_M1L  Q8WZ551 M   L   A   T 
 probably damaging alignment   
deleterious  0.997   0.0208  0.332   0.0665 
 1.832.148   0.318   10  0  


 1   0   0  
 0   17.5
BSND_M1R  Q8WZ551   M   R   
BSND_M1R  Q8WZ551 M   R   T   G 
 probably damaging alignment   
deleterious  0.999   0.00692 0.111   0.0222 
 2.505   2.148   -0.357  10  0  


 1   1   0  
 0   17.5
BSND_M1T  Q8WZ551   M   T   
BSND_M1T  Q8WZ551 M   T   T   C 
 probably damaging alignment   
deleterious  0.999   0.00692 0.111   0.0222 
 2.505   2.148   -0.357  10  0  


 0   1   2  
 0   17.5

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] extract specific column

2011-10-12 Thread Anna Olofsson

Hi,





I'm a beginner at python and I'm trying to extract a specific column from a txt 
file ( see attached file). 





In the attached file I want to extract the entire column 







pph2_prob (i.e. column 16). But I want to get all the values from that 
column without the headline  







pph2_prob.

How do I accomplish that? 

Best,
Anna
  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] extract specific column

2011-10-12 Thread Wayne Werner
On Wed, Oct 12, 2011 at 12:21 PM, Anna Olofsson <
olofsson_anna...@hotmail.com> wrote:

>  Hi,
>
> I'm a beginner at python and I'm trying to extract a specific column from a
> txt file ( see attached file).
>
> In the attached file I want to extract the entire column* pph2_prob *(i.e.
> column 16). But I want to get all the values from that column without the
> headline * pph2_prob.
>
> *How do I accomplish that?
>

Hi Anna,

We're more than happy to help, but we also would love to see what you've
done so far. What have you tried so far? Can you get the entire column
*with* the headline?

When you show the effort that you've taken, you'll find people are much more
inclined to help - very few people here will do your work for you, but most
of us are perfectly willing to point you in the right direction!

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] extract specific column

2011-10-12 Thread Matt Williams

On 12/10/2011 18:21, Anna Olofsson wrote:

Hi,

I'm a beginner at python and I'm trying to extract a specific column 
from a txt file ( see attached file).


In the attached file I want to extract the entire column/pph2_prob 
/(i.e. column 16). But I want to get all the values from that column 
without the headline /pph2_prob.


/How do I accomplish that?

Best,
Anna




Dear Anna,

Using the CSV module should work.

Something along the lines of (untested):

inLines = CSV.DictReader("/path/to/myfile.csv")
data = []
for a in inLines:
data.append(a)

for line in data:
print line["/pph2_prob/"]


Once you've got that working you just need to put the results in a file, 
instead of printing them.


On a practical note (and there may be many reasons why not to), it might 
be easier to open in a spreadsheet and take the data from there


HTH,

Matt
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] extract specific column

2011-10-12 Thread Anna Olofsson



From: olofsson_anna...@hotmail.com
To: tutor@python.org
Subject: FW: [Tutor] extract specific column
Date: Wed, 12 Oct 2011 21:59:34 +0200








The thing is, I don't know where to start. I know how to open the attached 
file, but I don't know how to work inside the file. Is this a csv file? Do I 
need to use a split function? In what way should I look at the file? As a 
string? As lines?

Best,
Anna
From: waynejwer...@gmail.com
Date: Wed, 12 Oct 2011 14:54:42 -0500
Subject: Re: [Tutor] extract specific column
To: olofsson_anna...@hotmail.com
CC: tutor@python.org

On Wed, Oct 12, 2011 at 12:21 PM, Anna Olofsson  
wrote:







Hi,





I'm a beginner at python and I'm trying to extract a specific column from a txt 
file ( see attached file). 





In the attached file I want to extract the entire column 







pph2_prob (i.e. column 16). But I want to get all the values from that 
column without the headline  







pph2_prob.

How do I accomplish that? 

Hi Anna,
We're more than happy to help, but we also would love to see what you've done 
so far. What have you tried so far? Can you get the entire column *with* the 
headline?


When you show the effort that you've taken, you'll find people are much more 
inclined to help - very few people here will do your work for you, but most of 
us are perfectly willing to point you in the right direction!


HTH,Wayne   
  #o_snp_id  o_acc o_pos  o_aa1   o_aa2   snp_id  
 acc   pos  aa1 aa2 nt1 nt2 
prediction  based_oneffect  pph2_class  
 pph2_probpph2_FPRpph2_TPRpph2_FDR  site
  regionPHATdScore  Score1  Score2Nobs   Nstruct
 Nfilt  PDB_id  PDB_pos PDB_ch   ident  length  NormAcc SecStr  MapRegdVol  
 dProp  B-fact   H-bonds AveNHet MinDHet AveNInt
 MinDInt AveNSit MinDSitTransv  CodPos  CpG  
MinDJnc PfamHit  IdPmax  IdPSNP  IdQmin
Comments
BSND_M1I  Q8WZ551   M   I   
BSND_M1I  Q8WZ551 M   I   G   T 
 probably damaging alignment   
deleterious  0.999   0.00692 0.111   0.0222 
 2.055   2.148   0.093   10  0  


 1   2   0  
 0   17.5
BSND_M1K  Q8WZ551   M   K   
BSND_M1K  Q8WZ551 M   K   T   A 
 probably damaging alignment   
deleterious  0.999   0.00692 0.111   0.0222 
 2.505   2.148   -0.357  10  0  


 1   1   0  
 0   17.5
BSND_M1L  Q8WZ551   M   L   
BSND_M1L  Q8WZ551 M   L   A   T 
 probably damaging alignment   
deleterious  0.997   0.0208  0.332   0.0665 
 1.832.148   0.318   10  0  


 1   0   0  
 0   17.5
BSND_M1R  Q8WZ551   M   R   
BSND_M1R  Q8WZ551 M   R   T   G 
 probably damaging alignment   
deleterious  0.999   0.00692 0.111   0.0222 
 2.505   2.148   -0.357  10  0  


 1   1   0  
 0   17.5
BSND_M1T  Q8WZ551   M

[Tutor] FW: extract specific column

2011-10-12 Thread Anna Olofsson

The thing is, I don't know where to start. I know how to open the attached 
file, but I don't know how to work inside the file. Is this a csv file? Do I 
need to use a split function? In what way should I look at the file? As a 
string? As lines?

Best,
Anna
From: waynejwer...@gmail.com
Date: Wed, 12 Oct 2011 14:54:42 -0500
Subject: Re: [Tutor] extract specific column
To: olofsson_anna...@hotmail.com
CC: tutor@python.org

On Wed, Oct 12, 2011 at 12:21 PM, Anna Olofsson  
wrote:







Hi,





I'm a beginner at python and I'm trying to extract a specific column from a txt 
file ( see attached file). 





In the attached file I want to extract the entire column 







pph2_prob (i.e. column 16). But I want to get all the values from that 
column without the headline  







pph2_prob.

How do I accomplish that? 

Hi Anna,
We're more than happy to help, but we also would love to see what you've done 
so far. What have you tried so far? Can you get the entire column *with* the 
headline?


When you show the effort that you've taken, you'll find people are much more 
inclined to help - very few people here will do your work for you, but most of 
us are perfectly willing to point you in the right direction!


HTH,Wayne ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] extract specific column

2011-10-12 Thread Dave Angel

On 10/12/2011 03:59 PM, Anna Olofsson wrote:


(PLEASE don't top-post.  And don't start multiple similar threads a 
couple of hours apart. Send your message as text without tons of blank 
lines, and don't assume the attachments will make it.  In my case, I 
haven't a clue to what the file looks like.)

From: olofsson_anna...@hotmail.com
To: tutor@python.org
Subject: FW: [Tutor] extract specific column
Date: Wed, 12 Oct 2011 21:59:34 +0200



The thing is, I don't know where to start. I know how to open the attached 
file, but I don't know how to work inside the file. Is this a csv file? Do I 
need to use a split function? In what way should I look at the file? As a 
string? As lines?

If you included about 5 lines of the file in your message, we might have 
a clue.  When I saw the original message, I was going to respond with a 
message about using [col, col+1], which would give you one character 
from each line.



--

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] FW: extract specific column

2011-10-12 Thread Steven D'Aprano

Anna Olofsson wrote:

The thing is, I don't know where to start. I know how to open the
attached file, but I don't know how to work inside the file. Is this
a csv file? Do I need to use a split function? In what way should I
look at the file? As a string? As lines?



It looks like a CSV file. Try opening it in Excel or OpenOffice 
spreadsheet and check that they are happy opening it as CSV. You'll 
probably need to play with the settings when you do, e.g. change the 
separator to tab instead of comma, etc. If you can open the file in 
Excel and get sensible results, you should be able to do the same thing 
with Python and the csv module.


You can learn more about the csv module here:

http://effbot.org/librarybook/csv.htm
http://www.doughellmann.com/PyMOTW/csv/

After taking a quick glance at the file you provided, it looks to me 
like fixed width fields (padded with spaces) in a tab-separated format. 
So you might have to do some post-processing to get rid of the spaces. 
That's pretty easy: any time you extract a value, just call 
value.strip() to remove the spaces before doing anything else with it.




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Retrieve data from log file

2011-10-12 Thread Abe Miranda
Hi there,

I'm sorry to ask this, I tried and example that was posted in 2009 but I
couldn't make it work. I'm trying to parse a log file and retrieve what I
just need.

Hope you can help me with this, this is part of the log file:

[2011-10-11 20:43:54:307] INFO   [QuoteCompareDaoWSImpl:  24] Se va a
invocar el ws de qualitas para comparar cotizaciones
[2011-10-11 20:43:55:899] DEBUG  [BaseQualitasDaoWS:  79]
[http-80-3] wscall - hours:0.0 minutes:0.0 seconds:1.0
[2011-10-11 21:09:42:604] DEBUG  [QuoteCompareDaoWSImpl:  25]
[http-80-3]Se va a invocar el ws de qualitas para comparar cotizaciones
[2011-10-11 21:09:42:708] DEBUG  [BaseQualitasDaoWS:  71]
[http-80-3] -request: 



 

 

 
3519
 

 


[2011-10-12 21:02:43:380] DEBUG  [BaseQualitasDaoWS:  78]
[http-80-1][clientThread-Thread-3] -response: 

  

  
  
  
  
  3519
  0
  0
  


  7650
  2002
  VOLKSWAGEN DERBY STD., 05
OCUP.
  1
  1
  4
  
  
  
125
2

1091.24
  
  
20
2
0
279.26
  
  
50
2
0
310.0
  
  
8560
2
0
260.0
  
  
120
2
0
0.0
  
  
0
N
  


  2011-10-12
  2011-10-06
  2011-10-09
  0
  17065
  S
  1109
  1109
  1109
  14
  
  
  0.0
  
1
0
  
  
0
14
  
  
12
1100.0
  
  
0
X01109
  
  
69
79
  
  
0

  
  
0
62
  
  
2
0.0
  
  
0

  


  1940.5
  400
  46.57
  262.58
  2649.65
  15


  2011-10-06
  2011-10-09
  1940.5
  400
  46.57
  262.58
  2649.65
  291.07


  
 &
[2011-10-12 21:02:43:383] DEBUG  [BaseQualitasDaoWS:  86]
[http-80-1][clientThread-Thread-3] -wscall - hours:0.0 minutes:0.0
seconds:3.0 &
[2011-10-12 21:02:43:462] DEBUG  [RestController   :  81]
[http-80-1][clientThread-Thread-3] - hours:0.0 minutes:0.0 seconds:16.0&


It repeats itself for every transaction and I need to extract from this
lines:

[2011-10-12 21:02:43:383] DEBUG  [BaseQualitasDaoWS:  86]
[http-80-1][clientThread-Thread-3] -wscall - hours:0.0 minutes:0.0
seconds:3.0 &
[2011-10-12 21:02:43:462] DEBUG  [RestController   :  81]
[http-80-1][clientThread-Thread-3] - hours:0.0 minutes:0.0 seconds:16.0&

this information:

2011-10-12 21:02:43:383   clientThread-Thread-3   hours:0.0 minutes:0.0
seconds:3.0
2011-10-12 21:02:43:462   clientThread-Thread-3   hours:0.0 minutes:0.0
seconds:16.0

Can this be done?

Thanks!

Abe
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Generic For Loop

2011-10-12 Thread Max S.
I've been doing some research into C++, and I've noticed the for loops.  Is
there a way to use the C++ version of the loops instead of the Python one?
For example, I believe that the Python syntax would be:

for a=1, a < 11, a += 1:
print(a)
print("Loop ended.")

if the 'for' keyword did it's function as in C++, Actionscript, or most
other programming languages.  Is there a way to do this?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Generic For Loop

2011-10-12 Thread bob gailer

On 10/12/2011 8:41 PM, Max S. wrote:
I've been doing some research into C++, and I've noticed the for 
loops.  Is there a way to use the C++ version of the loops instead of 
the Python one?  For example, I believe that the Python syntax would be:

for a=1, a < 11, a += 1:
print(a)
print("Loop ended.")
if the 'for' keyword did it's function as in C++, Actionscript, or 
most other programming languages.  Is there a way to do this?


for i in range(1, 11, 1): # the final 1 can be omitted, as it is the 
default value.

  loop body

OR

i = 1
while i < 11:
  i += 1
  loop body

Your choice - that's all know of - and the for is easier to read and 
write than the while.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Generic For Loop

2011-10-12 Thread Max S.
Thanks!

On Wed, Oct 12, 2011 at 8:56 PM, bob gailer  wrote:

>  On 10/12/2011 8:41 PM, Max S. wrote:
>
>> I've been doing some research into C++, and I've noticed the for loops.
>>  Is there a way to use the C++ version of the loops instead of the Python
>> one?  For example, I believe that the Python syntax would be:
>> for a=1, a < 11, a += 1:
>>print(a)
>> print("Loop ended.")
>> if the 'for' keyword did it's function as in C++, Actionscript, or most
>> other programming languages.  Is there a way to do this?
>>
>
> for i in range(1, 11, 1): # the final 1 can be omitted, as it is the
> default value.
>  loop body
>
> OR
>
> i = 1
> while i < 11:
>  i += 1
>  loop body
>
> Your choice - that's all know of - and the for is easier to read and write
> than the while.
>
> --
> Bob Gailer
> 919-636-4239
> Chapel Hill NC
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Generic For Loop

2011-10-12 Thread Alan Gauld

On 13/10/11 01:41, Max S. wrote:

I've been doing some research into C++, and I've noticed the for loops.


If you are trying to program in Python you should probably research 
Python rather than C++. Any tutorial will provide information about for 
loops...



Is there a way to use the C++ version of the loops instead of the Python
one?  For example, I believe that the Python syntax would be:
for a=1, a < 11, a += 1:
 print(a)
print("Loop ended.")


for a in range(1,11): print( a )


if the 'for' keyword did it's function as in C++, Actionscript, or most
other programming languages.  Is there a way to do this?


Of course, however...

Its generally better to think of the Python for lop as being a foreach 
loop. It iterates over a collection.


The C style for loop is a much more primitive loop and is really just a 
piece of syntactic sugar to implement a while loop:


a = 1
while a < 11:
   a += 1
   # loop body here

Because it is just a loosely disguised while loop you can put 
arbitrarily complex expressions into it and to replicate those in Python 
you need to use the while loop. But generally that kind of obfuscation 
in C++ is better avoided anyway.


The Python style loop is much more powerful than C's in its ability to 
iterate over lists, dictionaries, strings, files and any other iterable 
object. C++ introduces iterators as a library class to address this and 
enable foreach style processing, but at the expense of loop speed.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor