Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 5th, 2008, 10:45 AM
drjekil drjekil is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 2 drjekil User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 25 sec
Reputation Power: 0
Question Need python user need help!

I am working with a text filelooks like this:
#NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
1lghB A i 79.8 H H -24.58
1lghB V i 79.6 H H -22.06
1lghB H i 71.9 H H -19.94
i need to compare those lines which has a value between 10 to 22 and presents in the following way
True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets represents amino acids)
1 1:1 2:0 3:0 and so on for rest of the amino acids.


I have given 2 examples below to make it clear a bit:

ex.1:
#NAME AA TOPO ACCESS DSSP STRIDE Z-COORD
1lghB A i 79.8 H H -24.58 #for that line amino acid is A and z-COORED value is more than 22,so output should be look like

True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets represents amino acids)
-1 1:1 2:0 3 4:0 so on upto 20 bcz there r 20 amino acids.and A presents in the 1st position.every line represents one amino acid with value,so output will show in which position is it(here A is in 1st position thats why its value 1:1 and all the other position o like 2:0,3:0,4:0 and if its Z-COORED value between 10-22 then true false value 1,otherwise -1.

another ex:

1lghB H i 71.9 H H -19.94 # for that line amino acid is H and it has value between 10-22.so output should looks like:

True/false A C D E F G H I K L M N P Q R S T V X Y W(here alfabets represents 20 amino acids)

1 1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0,every position is zero up to 20 bcz H presents in the 7th position.so it will be 1.

so for every line, output will in 21 coulum,1st coulum for true false value,others r for 20 amino acids.true false value will be either 1 or -1,and within other 20 coulum one value will be n:1,others will be n:0.n=0,1,2,3..20.

here is my code:
from string import *;
import sys,os,re



f = open(" /1bccC.txt")
matches=[]
zcoord = []
aminoacids=[]
for line in f.readlines():
# print line
lines=line.strip()
items=line.split()
# print item
zcoord.append([items[1],items[6]])
aminoacids.append(items[1])




for i in range(0,len(zcoord),1):
if zcoord[i][0] == 'Z-COORD':
print "Hello"
else:

zcoord = float(zcoord[i][1])


if zcoord > 10 and zcoord < 22: # Sets T/F flag

matches.append([1,zcoord[i][0]])
else:

matches.append([-1,zcoord[i][0]])




for i in range(0,len(matches),1):

if matches[a][1]=='1' :
#print matches[a]
print " 1 1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='C':
print " 1 1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='D':

print " 1 1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='E':

print " 1 1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='F':

print " 1 1:0 2:0 3:0 4:0 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='G':

print " 1 1:0 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='H':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='I':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='K':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='L':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:1 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='M':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:1 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='N':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='P':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='Q':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='R':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:1 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='S':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:1 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='T':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:1 18:0 19:0 20:0 21:0"
elif matches[a][1]=='V':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:1 19:0 20:0 21:0"
elif matches[a][1]=='X':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:1 20:0 21:0"
elif matches[a][1]=='Y':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:1 21:0"
elif matches[a][1]=='W':

print " 1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:1"


else:

if matches[a][1]=='A' :

print "-1 1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='C':
print "-1 1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='D':

print "-1 1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='E':

print "-1 1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='F':

print "-1 1:0 2:0 3:0 4:0 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='G':

print "-1 1:0 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='H':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='I' :

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='K':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='L':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:1 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='M':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:1 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='N':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='P':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='Q':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='R':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:1 16:0 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='S':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:1 17:0 18:0 19:0 20:0 21:0"
elif matches[a][1]=='T':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:1 18:0 19:0 20:0 21:0"
elif matches[a][1]=='V':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:1 19:0 20:0 21:0"
elif matches[a][1]=='X':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:1 20:0 21:0"
elif matches[a][1]=='Y':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:1 21:0"
elif matches[a][1]=='W':

print "-1 1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:1"
but its only printing:
print "#T/F A C D E F G H I K L M N P Q R S T V X Y W"

waiting for ur opinion.
Thanks in advance.
Comments on this post
Schol-R-LEA disagrees: Holy crap. If this is for a job, I hope you're getting paid by the line.

Reply With Quote
  #2  
Old May 5th, 2008, 02:23 PM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is offline
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,038 Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 3 Weeks 3 Days 8 h 32 m 33 sec
Reputation Power: 330
First thing first: let's get this in a readable format:

Python Code:
Original - Python Code
  1. from string import  *;
  2. import sys,os,re
  3.  
  4.  
  5. f = open(" /1bccC.txt")
  6. matches=[]   
  7. zcoord = []
  8. aminoacids=[]
  9. for line in f.readlines():
  10. #    print line
  11.     lines=line.strip()
  12.     items=line.split()
  13. #    print item
  14.     zcoord.append([items[1],items[6]])
  15.     aminoacids.append(items[1])
  16.  
  17. for i in range(0,len(zcoord),1):
  18.     if zcoord[i][0] == 'Z-COORD':
  19.         print "Hello"
  20.     else:
  21.         zcoord = float(zcoord[i][1])
  22.         if zcoord > 10 and zcoord < 22: # Sets T/F flag
  23.             matches.append([1,zcoord[i][0]])
  24.         else:
  25.             matches.append([-1,zcoord[i][0]])
  26.            
  27. for i in range(0,len(matches),1):
  28.     if matches[a][1]=='1' :
  29.         #print matches[a]
  30.         print " 1  1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  31.     elif matches[a][1]=='C':
  32.         print " 1  1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  33.     elif matches[a][1]=='D':
  34.         print " 1  1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  35.     elif matches[a][1]=='E':
  36.         print " 1  1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  37.     elif matches[a][1]=='F':
  38.         print " 1  1:0 2:0 3:0 4:0 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  39.     elif matches[a][1]=='G':
  40.         print " 1  1:0 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  41.     elif matches[a][1]=='H':
  42.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  43.     elif matches[a][1]=='I':
  44.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  45.     elif matches[a][1]=='K':
  46.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  47.     elif matches[a][1]=='L':
  48.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:1 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  49.     elif matches[a][1]=='M':
  50.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:1 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  51.     elif matches[a][1]=='N':
  52.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  53.     elif matches[a][1]=='P':
  54.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  55.     elif matches[a][1]=='Q':
  56.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  57.     elif matches[a][1]=='R':
  58.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:1 16:0 17:0 18:0 19:0 20:0 21:0"
  59.     elif matches[a][1]=='S':
  60.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:1 17:0 18:0 19:0 20:0 21:0"
  61.     elif matches[a][1]=='T':
  62.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:1 18:0 19:0 20:0 21:0"
  63.     elif matches[a][1]=='V':
  64.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:1 19:0 20:0 21:0"
  65.     elif matches[a][1]=='X':
  66.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:1 20:0 21:0"
  67.     elif matches[a][1]=='Y':
  68.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:1 21:0"
  69.     elif matches[a][1]=='W':
  70.         print " 1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:1"
  71.     else:
  72.         if matches[a][1]=='A' :
  73.             print "-1  1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  74.         elif matches[a][1]=='C':
  75.             print "-1  1:0 2:1 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  76.         elif matches[a][1]=='D':
  77.             print "-1  1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  78.         elif matches[a][1]=='E':
  79.             print "-1  1:0 2:0 3:0 4:1 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  80.         elif matches[a][1]=='F':
  81.             print "-1  1:0 2:0 3:0 4:0 5:1 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  82.         elif matches[a][1]=='G':
  83.             print "-1  1:0 2:0 3:0 4:0 5:0 6:1 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  84.         elif matches[a][1]=='H':
  85.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:1 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  86.         elif matches[a][1]=='I' :
  87.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:1 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  88.         elif matches[a][1]=='K':
  89.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:1 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  90.         elif matches[a][1]=='L':
  91.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:1 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  92.         elif matches[a][1]=='M':
  93.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:1 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  94.         elif matches[a][1]=='N':
  95.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:1 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  96.         elif matches[a][1]=='P':
  97.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:1 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  98.         elif matches[a][1]=='Q':
  99.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:1 15:0 16:0 17:0 18:0 19:0 20:0 21:0"
  100.         elif matches[a][1]=='R':
  101.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:1 16:0 17:0 18:0 19:0 20:0 21:0"
  102.         elif matches[a][1]=='S':
  103.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:1 17:0 18:0 19:0 20:0 21:0"
  104.         elif matches[a][1]=='T':
  105.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:1 18:0 19:0 20:0 21:0"
  106.         elif matches[a][1]=='V':
  107.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:1 19:0 20:0 21:0"
  108.         elif matches[a][1]=='X':
  109.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:1 20:0 21:0"
  110.         elif matches[a][1]=='Y':
  111.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:1 21:0"
  112.         elif matches[a][1]=='W':
  113.             print "-1  1:0 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:1"


Unfortunately, that doesn't help much; the there's a lot of unneeded repetition in this, and the code would be rather hard to debug or maintain as a result. Most of what you're doing is essentially a table lookup - you have the value in matches[a][1], and you need to find a corresponding result to print out.

Fortunately for you, Python has just the tool for doing that: dictionaries.

A dictionary let's you set up a pair of values, where one is a key and the other is the value that is keyed to it. So if you have a value of 'A' always corresponds to "-1 1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0", and a value of "D" that corresponds to "-1 1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0", then you can set up a dictionary
Code:
lookup = {"A" : "-1  1:1 2:0 3:0 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0", 
             "D" : "-1  1:0 2:0 3:1 4:0 5:0 6:0 7:0 8:0 9:0 10:0 11:0 12:0 13:0 14:0 15:0 16:0 17:0 18:0 19:0 20:0 21:0"}


To look up the value, you would you would then use
Code:
value = lookup.get("D")

Which will get the value for "D".

This doesn't address the actual question, but this approach would probably save a good deal of trouble.

I'm puzzled by the program logic, though, and it seems that there is a missing if: statement somewhere - or is the else: after the first set of values supposed to go with the for: loop (meaning it supposed to be a set of matches for the last line only)?

I'm assuming that you're a biologist rather than a coder, correct? If so, don't feel too bad about it, it's the sort of thing that takes a certain amount of experience in programming to know.
__________________
Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
#define KINSEY (rand() % 7) λ Scheme is the Red Pill
Scheme in ShortUnderstanding the C/C++ Preprocessor
Taming PythonA Highly Opinionated Review of Programming Languages for the Novice, v1.1

FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov

Last edited by Schol-R-LEA : May 5th, 2008 at 02:26 PM.

Reply With Quote
  #3  
Old May 5th, 2008, 06:34 PM
bvdet bvdet is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 20 bvdet User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 39 m 4 sec
Reputation Power: 0
This is similar to a post on another forum. I'll use list method index to print the amino acid position. The print format doesn't make much sense to me, but what the heck.

Python Code:
Original - Python Code
  1. # string of letters represent the acids, I count 21
  2. acids = 'ACDEFGHIKLMNPQRSTVXYW'
  3. # zcoord is True when in the range defined by num_range
  4. num_range = [10,22]
  5.  
  6. fn = 'amino_acids_data.txt'
  7. f = open(fn)
  8.  
  9. # save the header which identifies each element in
  10. headerList = [item.strip() for item in f.readline()[1:].split()]
  11. # save a list of stripped lines from data file
  12. lineList = [item.strip() for item in f]
  13. f.close()