def seqingroups(groups,seq):
  'helper for contigsub. takes the list of lists returned by groupelts and an array to check.\
  returns (groupindex,indexingroup,matchlen) of longest match or None if no match'
  if not (groups and seq): return None
  bestmatch=None,None,0
  if any(len(g)<2 for g in groups): raise ValueError('some subgroups have length < 2')
  for i,g in filter(lambda x:x[1][0],enumerate(groups)): # i.e. we're only interested in groups with common elements
    # begin starts at 0 so begin+1 starts at 1. (first elt of each group is the bool indicator)
    begin=0
    while 1:
      try: begin=g.index(seq[0],begin+1)
      except ValueError: break
      jmax=min(len(g)-begin,len(seq))
      for j in range(jmax):
        if g[begin+j]!=seq[j]: break
      else: j+=1 # so matchlen works below
      matchlen=min(j,jmax)
      if matchlen<bestmatch[2]: continue
      bestmatch=[i,begin,matchlen] # note: begin is an offset including the initial bool
  return bestmatch if bestmatch[2] else None