def get_ids(lines, field, bad_ids=None, debug=False):
 result = defaultdict(list)
 for line in lines:
  if line.startswith('>'):
   fields = map(strip, line[1:].split())
   label = fields[0]
   if (not ('_' in label)):
    continue
   (lib, id_) = label.rsplit('_', 1)
   if (bad_ids and (label in bad_ids)):
    if debug:
     print ('Excluded bad id: %s' % label)
   else:
    result[lib].append(fields[field])
 return result

def get_ids ( lines , field , bad_ids = None , debug = False ) : result = defaultdict ( list ) for line in lines : if line . startswith ( '>' ) : fields = map ( strip , line [ 1 : ] . split ( ) ) label = fields [ 0 ] if ( not ( '_' in label ) ) : continue ( lib , id_ ) = label . rsplit ( '_' , 1 ) if ( bad_ids and ( label in bad_ids ) ) : if debug : print ( 'Excluded bad id: %s' % label ) else : result [ lib ] . append ( fields [ field ] ) return result
make dict of lib:ids .