Regex to remove new lines up to a specific character

后端 未结 5 1200
情歌与酒
情歌与酒 2021-01-27 14:41

I have a series of strings in a file of the format:

>HEADER_Text1
Information here, yada yada yada
Some more information here, yada yada yada
Even some more i         


        
5条回答
  •  猫巷女王i
    2021-01-27 15:18

    As noted in the comments, your best bet is to use an existing FASTA parser. Why not?

    Here's how I would join lines based on the leading greater-than:

    def joinup(f):
        buf = []
        for line in f:
            if line.startswith('>'):
                if buf:
                    yield " ".join(buf)
                yield line.rstrip()
                buf = []
            else:
                buf.append(line.rstrip())
        yield " ".join(buf)
    
    for joined_line in joinup(open("...")):
        # blah blah...
    

提交回复
热议问题