|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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. |
|
#2
|
|||||
|
|||||
|
First thing first: let's get this in a readable format:
Python Code:
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 Short • Understanding the C/C++ Preprocessor Taming Python • A 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. |
|
#3
|
|||
|
|||
|
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:
|