def strip_fasta(fname, substr='_'): good = False name = '' rmlist = [] def callback(): if good: return '%s (removed %s)' % (name, len(rmlist)) else: return '%s [x] (removed %s)' % (name, len(rmlist)) for line in eta_open_iter(fname, callback=callback): if line[0] == '>': name = line[1:].strip().split(' ')[0] if substr in name: good = False rmlist.append(name) else: good = True if good: sys.stdout.write(line) sys.stderr.write('Removed:\n') for n in rmlist: sys.stderr.write('%s\n' % n)
def tag_fasta(fname, prefix='', suffix=''): name = '' for line in eta_open_iter(fname, callback=lambda: name): if line[0] == '>': spl = line[1:].strip().split(' ', 1) name = '%s%s%s' % (prefix, spl[0], suffix) if len(spl) > 1: comment = ' %s' % spl[1] else: comment = '' sys.stdout.write('>%s%s\n' % (name, comment)) else: sys.stdout.write(line)
def tag_fasta(fname, prefix='', suffix=''): name = '' for line in eta_open_iter(fname, callback=lambda: name): if line[0] == '>': spl = line[1:].strip().split(' ',1) name = '%s%s%s' % (prefix, spl[0], suffix) if len(spl) > 1: comment = ' %s' % spl[1] else: comment = '' sys.stdout.write('>%s%s\n' % (name, comment)) else: sys.stdout.write(line)