Maybe replace all your code with something like this:

seqlist <- [r.processed_seq for r in db().select(db.plugin_seq.processed_seq
)]
oligolist <- [r.oligo_processed_seq for r in db().select(db.oligo_seq.
oligo_processed_seq)]
for m in oligolist:
    for n in range(1, (len(seqlist) + 1) if seqlist else 0)
        [matching code]

No need to do the selects twice or for any "if" statements -- just use list 
comprehensions. If there are no records, the lists will be empty and the 
for loops will just get bypassed. A few additional points:

   - If you just need to check whether a table includes records, use 
   db(db.mytable).isempty()
   - Even if you just select a single field, each element in the object 
   returned by the select is still a row object, not an individual field 
   value. The lists you built, therefore, contained full row objects (each one 
   containing a single field), not individual sequence strings. If you want 
   the field values, you still have to access them as usual via row.myfield. 
   Notice how this is done in the list comprehensions above.
   - range(1, n) will return the values 1 through (n-1), so if you want the 
   last value to be the length of the sequence, you need to add 1. My guess is 
   you don't want that, though, because Python subscripts start at 0 -- you 
   probably just want range(len(seqlist)).

Also, I'm not sure I understand what you're trying to do with the matching, 
but my guess is it can be made easier using regular expressions: 
http://docs.python.org/library/re.html.

Anthony

On Thursday, July 19, 2012 7:30:00 AM UTC-4, praveen krishna wrote:
>
> Hii,
>      I want to match two string which are in two different lists,I want to 
> view the stings which are matched for example      string 1       
>  ASDFFFASVSDSDDDGGGG
>                                                                           
>                                                                             
>                           string 2            DFFFAS
>      I am trying with the following code it is generating some output as I 
> can 'loading...' while executing the program but nothing is displayed
>        def match_oligos(): 
>      if db(db.plugin_seq.id>0).select(): 
>          if db(db.oligo_seq.id>0).select():
>                 seqlist=[]
>                 oligolist=[]
>                 message=[]
>                 for r in db(db.plugin_seq.id
> >0).select(db.plugin_seq.processed_seq):
>                      seqlist.append(r)
>                 for o in db(db.oligo_seq.id
> >0).select(db.oligo_seq.oligo_processed_seq):
>                      oligolist.append(o)  
>                 for m in oligolist:
>                      for n in range(1,len(seqlist)):
>                          k=n+len(m)
>                          if m==seqlist[n:k]:
>                             message.append('\nMatch found in : ' + str(m) 
> + ' at position: '+str(n))                              
>                 return UL([LI(item) for item in message])
>

-- 



Reply via email to