コード例 #1
0
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)
コード例 #2
0
ファイル: tag_fasta.py プロジェクト: xuwei684/ngsutils
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)
コード例 #3
0
ファイル: tag_fasta.py プロジェクト: ZhangQiuxue/ngsutils
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)
コード例 #4
0
ファイル: strip_fasta.py プロジェクト: ZhangQiuxue/ngsutils
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)