[Tutor] function help

2011-02-07 Thread Ashley F
ok...here's the function I've written so far.
 
def padWithGaps(seq):
    for letter in seq:
   letter="-"
   line=len(seq)
   dashline=line*letter
    return dashline
 
def replace(someString,position,letter):
    first=someString[0:position]
    second=letter
    third=someString[position+1:len(someString)]
    newString=first+second+third
    return newString
 
##findScore("MPFVS","MS-V-") would return a score of 2
def findScore(first,second):
    count=0
    for position in range(0,len(first)):
 if first[position]==second[position]:
 count=count+1
 position=position+1
    return count
 
#shorter is a 3 amino acid sequence
##longer is any length sequence greater than 3
###i=first amino acid; j=second amino acid; k=third amino acid
def findAlignment(shorter,longer):
 for i in range(0,len(longer)-2):
 for j in range(1,len(longer)-1):
  for k in range(2,len(longer)):
   dashline=padWithGaps(longer)
   nextLine=replace(dashline,i,shorter[0])
   nextNext=replace(nextLine,j,shorter[1])
   alignment=replace(nextNext,k,shorter[2])
   score=findScore(longer,alignment)
   don't know what to do here
  print longer
  print alignment
  print "Score = " + str(score)
 
I don't know what to do at the end of my loop but what I'm trying to do in 
pseudocode is:
 "if that alignment has the best score seen so far
  save the score and the alignment
print the best score and the best alignment"


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


[Tutor] nested loops

2011-02-07 Thread Ashley F
I am trying to write a function...(it's kind of like a long way to do BLAST but 
only comparing 2 sequences)
 
I have 3 loops nested...Within those loops, I obtain a "best fit score" so to 
speak.
 
I can get the program to run...but the loops run all the way to the end.  I 
can't figure out how to print the best score found...and the alignment that 
went with it. (therefore, my results will only be correct if my last alignment 
is the highest scoring one--which it usually isn't)
 
To try to clear this up...
The part of my pseudocode that I'm having trouble putting into actual code in 
python is:
"if that alignment has the best score seen so far
 save the score and that alignment"


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