Beispiel #1
0
def bsai(files, verbose = verbose):
    '''Check for bsaI compatibility, uniqueness etc and finally print a list of
primers with six nucleotides appended'''

    #CHECK EACH PRIMER FILE SEPERATELY
    for f in files:
      sw('\nFILE {0}:\n\n'.format(f))
      primers = readfiles([f])

      #CHECK BSAI SITES IN ONE FILE AT A TIME
      sw('checking for bsai sites:\n')
      overhangs = bsai_overhangs(primers)
      olist =[ o[1] for o in overhangs]
      overhangs_rc = [str(zutils.reverse_complement(oh) ).upper() 
                      for oh in olist]

      print 'len overhang set: {0} '.format(len(set(olist)))
      print 'len overhang union rc: {0} '.format(len(set(olist+overhangs_rc)))
      assert( len(set(olist)) * 2 == len(set(olist+overhangs_rc)))
    
      print 'Checking for palindromes... '
      print sorted(olist+overhangs_rc)
      print 'none exist!'

      pseqs = primer_seqs(primers)
      ntot = len(primers);  np = len(pseqs)

      #DO ANY PRIMERS LACK A BSAI SITE?
      fails = [(k,v) 
               for k,v in pseqs.iteritems() 
               if v.upper()[:6] != 'GGTCTC']
      if len(fails) == 0: sw('SUCCESS\n')
      else:sw('FAILURE'+'{0}\n'.format(fails)); return(1)

      #CHECK LINKER PAIRING
      sw('\nchecking overhangs:\n')
      #EVERY LINKER IS PAIRED ONCE (VECTOR BACKBONE IS PRIMED)
      if verbose: sw('\n'.join([o[1] for o in overhangs])+'\n')     
      if len(set([o[1] for o in overhangs])) == np / 2.:
          sw('SUCCESS\nevery primer appears paired:\n')
          sw('{0}\n'.format('\n'.join([' <--> '.join(['{0:5}'.format(elt[0]) for elt in list(g)] )
                                       for k , g in it.groupby(
                              sorted(overhangs, key = lambda x:x[1]),
                              key = lambda x: x[1])])))
      
      #TWO LINKERS ARE UNPAIRED (NO VECTOR PRIMERS)
      elif len(set([o[1] for o in overhangs])) ==np / 2. + 1:
          sw('SUCCESS\nevery primer appears paired:\n')
          sw('{0}\n'.format('\n'.join(\
                      sort_good([

                                  ' <--> '.join(\
                                      sort_good(['{0:5}'.format(elt[0]) 
                                       for elt in list(g)]
                                      ))
                                  
                                  for k , g in it.groupby( sorted(overhangs, key = lambda x:x[1]),
                                                           key = lambda x: x[1])]))))

      #SOMETHING WEIRD IS GOING ON
      else:
          sw('FAILURE\n')
          grps =dict([(k,list(g))  for k , g in it.groupby(
                      sorted(overhangs, key = lambda x:x[1]),
                      key = lambda x: x[1])])
          sw('{0}\n'.format(
                  '\n'.join( '{0} share {1}'.format(
                          (', '.join([e[0] for e in elt[1]])),
                          elt[0]) 
                             for elt in grps.iteritems() 
                             if len(elt[1]) > 2)))
          #IF THIS IS BEING RUN INTERACTIVELY, CRY FOUL!
          if __name__ != '__main__': raise Exception()
          return(1)
      
      sw('\nEverything appears to be OK\n')

    #NOW READ ALL OF THE FILES AT ONCE AND PRINT
    primers = readfiles(files)  

    sw('printing primers:\n')
    sw('\n'.join(sorted(['{0}; {1}; '.format(*p) for p in bsai_print_final(primers)])))
Beispiel #2
0
def bsai_overhangs(primers):
    '''Given a dict of pcr products with primers, grab the 4 nt BsaI overhangs'''
    return list(it.chain(*[((p['fname'],p['fwd'][7:11].upper()), 
                       (p['rname'],''.join(zutils.reverse_complement(\
                            p['rev'][7:11].upper()))))
                      for p in primers.values()]))